akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
typedef long long ll;
const int mod=998244353;
map<pair<ll,int>,ll> mp;
char s[105];
ll f[105][105],d[105][105][105];
int n,top,a[105][105];
ll solve(ll S,int n){
	if(n==1) return S+1;
	if(mp.find(make_pair(S,n))!=mp.end()) return mp[make_pair(S,n)];
	top++;
	int tt=top;
	for(int i=1;i<=n;i++) a[tt][i]=(S>>(i-1))&1;
	for(int i=1;i<=n;i++) d[tt][i][i]=a[tt][i]+1,d[tt][i+1][i]=1;
	for(int len=2;len<=n;len++){
		for(int l=1;l+len-1<=n;l++){
			int r=l+len-1;
			ll id=0,iid=0;
			for(int j=0;j<len;j++) id|=(1LL<<j)*a[tt][l+j],iid|=(1LL<<(len-j-1))*a[tt][l+j];
			if(mp.find(make_pair(id,len))!=mp.end()){
				d[tt][l][r]=mp[make_pair(id,len)];continue;
			}
			d[tt][l][r]=d[tt][l+1][r]*d[tt][l][l]%mod;
			for(int j=1;j+j<=len;j++){
				ll now=(1LL<<j)-1;
				for(int k=l;k+j-1<=r;k+=j){
					ll cur=0;
					for(int pos=0;pos<j;pos++) cur|=(1LL<<pos)*a[tt][pos+k];
					now&=cur;
					if(k>l) d[tt][l][r]=(d[tt][l][r]+d[tt][k+j][r]*solve(now,j))%mod;
				}
			}
			mp[make_pair(id,len)]=mp[make_pair(iid,len)]=d[tt][l][r];
		}
	}
	top--;
	return d[tt][1][n];
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++) f[i][i]=s[i]=='1'?2:1,f[i+1][i]=1;
	for(int len=2;len<=n;len++){
		for(int l=1;l+len-1<=n;l++){
			int r=l+len-1;
			f[l][r]=f[l+1][r]*f[l][l]%mod;
			for(int j=1;j+j<=len;j++){
				ll now=(1LL<<j)-1;
				for(int k=l;k+j-1<=r;k+=j){
					ll cur=0;
					for(int pos=0;pos<j;pos++) cur|=(1LL<<pos)*(s[pos+k]-'0');
					now&=cur;
					if(k>l) f[l][r]=(f[l][r]+f[k+j][r]*solve(now,j))%mod;
				}
			}
		}
	}
	printf("%lld\n",f[1][n]);
	return 0;
}

Measured memory_bytes: 6528
import sys
sys.setrecursionlimit(100000)

import numpy as np

def main():
    n, m, x = map(int, input().split())
    c, a = [None]*n, [None]*n
    for i in range(n):
        c[i], *a[i] = map(int, input().split())
    
    def dfs(i, cost, A):
        if i == n-1:
            global ans
            if all([ai >= x for ai in A]) and cost < ans:
                ans = cost
            return
        i += 1
        dfs(i, cost, A[:])
        dfs(i, cost+c[i], A[:]+a[i])
    
    dfs(-1, 0, np.array([0]*m))
    if ans == 10**7:
        print(-1)
    else:
        print(ans)
        

if __name__ == "__main__":
    ans = 10**7
    main()

Measured memory_bytes: 27212
from math import ceil, floor

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

if N>=B-1:
    x = B-1
    ans = floor((A*x)/B) - A*floor(x/B)
else:
    x = N
    ans = floor((A*x)/B) - A*floor(x/B)

print(ans)

Measured memory_bytes: 9120
#include <iostream>

long long a,b;
int k;
int main(){
  std::cin>>a>>b>>k;
  for(int i=0;i<k;++i){
    if(i%2==0){
      if(a%2==1)
        a-=1;
      b+=a/2;
      a/=2;
    }
    else{
      if(b%2==1)
        b-=1;
      a+=b/2;
      b/=2;
    }
  }
  std::cout<<a<<' '<<b<<std::endl; 
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main(){
  int n,m,i,d[100010],a;
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++)scanf("%d",&d[i]);
  a=d[0];
  for(i=1;i<n;i++)a=gcd(a,d[i]);
  for(i=0;i<n;i++){
    if(d[i]<m)continue;
    if((d[i]-m)%a==0)break;
  }
  printf("%s\n",i-n?"POSSIBLE":"IMPOSSIBLE");
  return 0;
}



Measured memory_bytes: 512
package main

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

const mod = 998244353
const facNum = 300001

func main() {
	sc := newScanner(os.Stdin)
	R := sc.i()
	fmt.Println(float64(R) * 2 * math.Pi)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

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

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}

// vs: sorted slice int value
func lowerBound(vs []int, v int) (index int) {
	n := len(vs) / 2
	m := len(vs)
	for m != n {
		if vs[n] < v {
			n = (m-n+1)/2 + n
			//m = m
		} else {
			m = n
			n = n / 2
		}
	}
	return n
}

func IntSlice(n, init int) []int {
	r := make([]int, n)
	for i := range r {
		r[i] = init
	}
	return r
}


Measured memory_bytes: 1756
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <bitset>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <assert.h>
#include <algorithm>

using namespace std;
#define ll long long

bool checkvalid( int m) {
	if (m > 12 || m <= 0) return false;
	return true;
}

int main()
{	
	string s;
	cin >> s;
	int t1 = (s[0] - '0') * 10 + (s[1] - '0');
	int t2 = (s[2] - '0') * 10 + (s[3] - '0');
	bool check1 = checkvalid(t1);
	bool check2 = checkvalid(t2);
	if (check1 && check2) cout << "AMBIGUOUS" << endl;
	if (!check1 && !check2) cout << "NA" << endl;
	if (check1 && !check2) cout << "MMYY" << endl;
	if (!check1 && check2) cout << "YYMM" << endl;

	return 0;
}

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

#define i0 i == 0
#define j0 j == 0
#define ie i == h - 1
#define je j == w - 1
#define ia i == (h - 1) / 2
#define ja j == (w - 1) / 2

int main() {
	int w, h;
	char c;
	cin >> w >> h >> c;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if ((i0 && (j0 || je)) || (ie && (j0 || je))) cout << '+' << flush;
			else if (i0 || ie) cout << '-' << flush;
			else if (j0 || je) cout << '|' << flush;
			else if (ia && ja) cout << c << flush;
			else cout << '.' << flush;
			if (je) cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3100
import numpy as np

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

A = np.array(A)

bingo =np.array( [0] *9 )

N = int(input())
for i in range(N):
    b =int(input())
    for i in range(9):
        if A[i] == b:
            bingo[i] =1


if (bingo[0]+bingo[1]+bingo[2]==3) or (bingo[3]+bingo[4]+bingo[5]==3) or (bingo[6]+bingo[7]+bingo[8]==3):
    print("Yes")
elif (bingo[0]+bingo[3]+bingo[6]==3) or (bingo[1]+bingo[4]+bingo[7]==3) or (bingo[2]+bingo[5]+bingo[8]==3):
    print("Yes")
elif (bingo[0]+bingo[4]+bingo[8]==3) or (bingo[2]+bingo[4]+bingo[6]==3):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 21000
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        BigDecimal a = sc.nextBigDecimal();
        BigDecimal b = sc.nextBigDecimal();
        BigDecimal c = a.multiply(b);
        System.out.println(c.setScale(0, BigDecimal.ROUND_DOWN));
    }
}

Measured memory_bytes: 28992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> A(Q);
  rep(i,Q) {
    int x;
    cin >> x;
    --x;
    A[i] = x;
  }
  vector<int> point(N, K-Q);
  rep(i,Q) {
    point[A[i]]++;
  }
  rep(i,N) {
    if (point[i] > 0) cout << "Yes\n";
    else cout << "No\n";
  }
  return 0;
}


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

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int A[200000];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  long long sum = 0;
  rep(i, N) cin >> A[i];
  rep(i, N) sum += A[i];
  long long s = 0;
  long long m = (1LL<<60);
  rep(i, N-1) {
    s += A[i];
    m = min(m, abs(s - (sum - s)));
  }
  cout << m << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	long long k, a, b; cin >> k >> a >> b;
	if (a >= k)cout << "1\n";
	else if (a - b <= 0)cout << "-1\n";
	else {
		long long p = k - a;
		a -= b;
		if (p%a != 0)p += a - (p % a);
		cout << p / a * 2 + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  cout << 10*max(max(A,B),C)+A+B+C-max(max(A,B),C) << endl;
}

Measured memory_bytes: 256
import sys

N, Y = map(int,input().split())

x = Y // 10000

for i in range(x+1):
    y = (Y - i*10000) // 5000
    for j in range(y+1):
        zan = Y - i*10000 - j*5000
        if zan < 0:
            continue
        else:
            z = zan//1000
            if (zan % 1000 == 0) and (N==i+j+z):
                print(i,j,z)
                sys.exit()
print(-1,-1,-1)


Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;
const int MAX=200001;

bool judge(int x,vector<char> &A){
    string S=to_string(x);
    REP(i,S.size()){
        REP(j,A.size()){
            if(S[i]==A[j])return false;
        }
    }
    return true;
}

signed main(){
    int N,K;cin>>N>>K;
    vector<char> A(K);
    REP(i,K)cin>>A[i];
    for(int i=N;;i++){
        if(judge(i,A)){
            cout<<i<<endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

VI adj[101010];
bool visited[101010];

unordered_map<long, long> mp;

int unvisited(int st, int n) {
    REPI(i,st,n) {
        if (!visited[i]) return i;
    }
    return -1;
}

long p(long a, long b) {
    return a * 1e9 + b;
}

long pos[101010];

void dfs(int i) {
    if (visited[i]) return;
    visited[i] = true;
    for (int k: adj[i]) {
        long a = pos[i] + mp[p(i,k)];
        if (pos[k] != 1e12) {
            if (pos[k] != a) {
                cout << "No" << endl;
                exit(0);
            }
        }
        pos[k] = a;
        dfs(k);
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    long l, r, d;
    REP(i,m) {
        cin >> l >> r >> d;
        l--;
        r--;
        mp[p(l,r)] = d;
        mp[p(r,l)] = -d;
        adj[r].push_back(l);
        adj[l].push_back(r);
    }
    
    int st = 0;
    for (int i = 0; i < 101010; i++) pos[i] = 1e12;
    while ((st = unvisited(st,n)) != -1) {
        pos[st] = 0;
        dfs(st);
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 31220
n, k = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

cum = [0]
for i in range(1, n+1):
    cum.append(cum[i-1] + (p[i-1]+1)/2)

res = 0
for i in range(0, n-k+1):
    val = cum[i+k] - cum[i]
    if res < val:
        res = val

print(res)


Measured memory_bytes: 25188
import math
from functools import reduce
MOD = 10**9+7
N, A, B = [int(i) for i in input().split(' ')]


def combination_mod(n,r):
    a = reduce(lambda x, y : x * y % MOD, range(n, n-r, -1))
    b = reduce(lambda x, y: x * y % MOD, range(1,r+1))
    return a * pow(b, MOD-2 ,MOD) % MOD

ans = pow(2,N,MOD) -combination_mod(N,A) - combination_mod(N,B) - 1
ans %= MOD
print(ans)



Measured memory_bytes: 3572
def euclid(a,b):
  if b==0:return a
  return euclid(b,a%b)

a,b,k=[int(s)for s in input().split()]
g=euclid(a,b) if a>b else euclid(b,a)
d=[]
for i in range(g):
  if g%(i+1)==0:d.append(i+1)

print(d[-k])

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<ll> rui(n+1);
    rep(i, n) {
        ll a;
        cin >> a;
        rui[i+1] = rui[i] + a;
    }
    
    map<ll, ll> mp;
    ll ans = 0;
    rep(i, n+1) {
        ans += mp[rui[i]];
        mp[rui[i]]++;
    }

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

Measured memory_bytes: 14336
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100010];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(a,a+n);
        int s=0,t=a[0],cnt=1;
        for(int i=1;i<n;i++)
        {
            if(a[i]!=t)
            {
                if(cnt%2==1)
                    s++;
                t=a[i];
                cnt=1;
            }
            else
                cnt++;
        }
        if(cnt%2==1)
            s++;
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 


int main(){

	int n;
	cin>>n;

	long long res=0;
	long long a;
	long long sum=0;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a==0) res+=sum/2,sum=0;
		else sum+=a;
	}

	res+=sum/2;
	cout<<res<<endl;



}

Measured memory_bytes: 256
def solve():
  N, K = map(int, input().split())
  H = [int(i) for i in input().split()]
  dp = [0 for i in range(N)]
  for i in range(1, N):
    dp[i] = min((dp[j] + abs(H[j] - H[i])) for j in range(max(i - K, 0), i))
  return dp[N - 1]

print(solve())


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

using namespace std;
typedef long long ll;

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

  int n,x;cin>>n>>x;
  int a[n+1];
  ll res=0;
  for(int i=0;i<n;i++) cin>>a[i];
  if(a[0]>x){
      res+= a[0]-x;
      ll last=x;
      for(int i=1;i<n;i++){
          if(last+a[i]>x){
              res+=last+a[i]-x;
              last=x-last;
          }
          else last=a[i];
      }
  }
  else{
      ll last=a[0];
      for(int i=1;i<n;i++){
          if(last+a[i]>x){
              res+=last+a[i]-x;
              last=x-last;
          }
          else last=a[i];
          //cout<<last<<" "<<res<<endl;
      }
  }
    cout<<res<<endl;
}

Measured memory_bytes: 640
a_1 = list(map(int,input().split()))
a_2 = list(map(int,input().split()))
a_3 = list(map(int,input().split()))
n = int(input())
b_n = [int(input()) for i in range(n)]

for b in b_n:
    for i in range(3):
        if a_1[i] == b:
            a_1[i] = 0
        if a_2[i] == b:
            a_2[i] = 0
        if a_3[i] == b:
            a_3[i] = 0
            
            
#print(a_1,a_2,a_3)
flag = "No"
if a_1[0] == 0 and a_1[1] == 0 and a_1[2] == 0:
    flag = "Yes"
if a_2[0] == 0 and a_2[1] == 0 and a_2[2] == 0:
    flag = "Yes"
if a_3[0] == 0 and a_3[1] == 0 and a_3[2] == 0:
    flag = "Yes"

for i in range(3):
    if a_1[i] == 0 and a_2[i] == 0 and a_3[i] == 0:
        flag = "Yes"
       
     
if a_1[0] == 0 and a_2[1] == 0 and a_3[2] == 0:
    flag = "Yes"
if a_3[0] == 0 and a_2[1] == 0 and a_1[2] == 0:
    flag = "Yes"

print(flag)

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int L = a + b;
    int R = c + d;

    if (L > R) {
        cout << "Left" << endl;
    } else if (L == R){
        cout << "Balanced" << endl;
    } else {
        cout << "Right" << endl;
    }
}

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

int main() {
	int k;
	string s;
	cin >> k >> s;
	if(s.length()<=k)
	cout << s << endl;
	else
	{
	    string temp = s.substr(0,k);
	    temp += "...";
	    cout << temp << endl;
	}
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
        using namespace std;
        #define endl              "\n"
        #define int               long long
        #define mem1(x)           memset(x, -1, sizeof (x))
        #define M                 1000000007
        #define MM                998244353
        #define ff                first
        #define pb                push_back
        #define pii               pair<int,int>
        #define rep(i,a,b)        for(long long i=a;i<b;i++)
        #define ss                second
        #define mii               map<int,int>
        #define psi               pair<string,int>
        #define pis               pair<int,string>
        #define GCD(x,y)          (__gcd((x), (y)))
        #define LCM(x,y)          (((x)/__gcd((x), (y)))*(y))
        #define mem0(x)           memset(x, 0, sizeof (x))
        #define all(x)            (x).begin(),(x).end()
        #define IOS ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
        int powmod(int a, int l, int md) {int res = 1; while (l) {if (l & 1)res = res * a % md; l /= 2; a = a * a % md;} return res;}
         
         
        void solve()
        {
            int n,m,l,s=0;
            cin >> n>>m>>l;


            for(m;m<=l;m++){

            	if(m%n==0){
            		cout<<"OK"<<endl;
            		s++;
            		break;
            	}



            }

            if(s==0)
             cout<<"NG"<<endl;


           
        }
         
        signed main() {
            IOS;
        
            //sieve();
            int t = 1;
            //cin >> t;
            while (t--) solve();
            return 0;
        }

Measured memory_bytes: 3656
import math
import sys
N, K = map(int, input().split())
a_lis = list(map(int, input().split()))

if N == K:
    print(1)
    sys.exit()

if a_lis.index(1) + 1 <= K or N - a_lis.index(1) <= K:
    if K == 2:
        print(N - 1)
        sys.exit()
    print(math.ceil((N - K) / (K - 1)) + 1)
    sys.exit()
else:
    if K == 2:
        print(N - 1)
        sys.exit()
    print(math.ceil((N - K) / (K - 1)) + 1)

Measured memory_bytes: 13812
//  B - Popular Vote
// https://atcoder.jp/contests/abc161/tasks/abc161_b
#include <iostream>
#include <bits/stdc++.h>
#include <map>
#include <queue>
#include <set>
#include <string> 
#include <vector>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, int> PLI;
typedef pair<int, int> PII;

#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x , val) memset(x , val , sizeof(x));

const ll mxsize = 2e5 + 5;
const ll linf = 1e9;
const long double inf = 10000000000.0;

#define fastIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

const ll mod = 998244353;
 
/******************************************** CODE STARTS FROM HERE *************************************************/ 

int main()
{
    fastIO;
    ll n , m;
    cin >> n >> m;
    vector < ll > arr(n);
    ll i;
    fo(i , n)
    {
        cin >> arr[i];
    }
    //sort(arr.begin() , arr.end() , greater < ll >());
    // for(auto x : arr)
    // {
    //     cout << x << " ";
    // }
    // cout << endl;
    ll sum = accumulate(arr.begin() , arr.end() , 0ll);
    // cout << sum << endl;
    ll cnt = 0;
    for(auto x : arr)
    {
        if(x * 4 * m >= sum) cnt++;
    }
    if(cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() { 
    int n, m;
    cin >> n >> m;

    int a[n];
    for(int i = 0; i < n; ++i) a[i] = -1;
    int s, c;
    for(int i = 0; i < m; ++i) {
        cin >> s >> c;
        if(a[s-1] == -1) a[s-1] = c;
        else {
            if(a[s-1] != c) {
                cout << -1 << '\n';
                return 0;
            } 
        }
    }

    if(n == 1) {
        cout << ((a[0] == -1)?0:a[0]) << '\n';
    } else if(n == 2) {
        if(a[0] == 0){
            cout << -1 << '\n';
            return 0;
        }
        if(a[0] == -1) a[0] = 1;
        if(a[1] == -1) a[1] = 0;
        cout << a[0] << a[1] << '\n';
    } else {
        if(a[0] == 0){
            cout << -1 << '\n';
            return 0;
        }
        if(a[0] == -1) a[0] = 1;
        if(a[1] == -1) a[1] = 0;
        if(a[2] == -1) a[2] = 0;
        cout << a[0] << a[1] << a[2] << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
// using namespace atcoder;
using ll = long long;
using P = pair<int, int>;
const int mod = 1e9 + 7;
// --------------------------------------------------------------------------------
void solve()
{
    string s;
    cin >> s;
    if (s == "Sunny")
        cout << "Cloudy" << endl;
    if (s == "Cloudy")
        cout << "Rainy" << endl;
    if (s == "Rainy")
        cout << "Sunny" << endl;
}
// --------------------------------------------------------------------------------
int main()
{
    // srand((unsigned)time(NULL));
    // int bt = clock();
    solve();
    // double et = 1.0 * (clock() - bt) / CLOCKS_PER_SEC;
    // printf("Execution Time: %.4lf sec\n", et);
    return 0;
}

Measured memory_bytes: 3596
use std::io;

macro_rules! get {
    ($t: ty) => {
        {
            let mut x = String::new();
            io::stdin().read_line(&mut x).ok();
            x = x.trim_right().to_owned();
            x.parse::<$t>().unwrap()
        }
    };
    ($($t: ty), *) => {
        {
            let mut x = String::new();
            io::stdin().read_line(&mut x).ok();
            x = x.trim_right().to_owned();
            let mut inter = x.split_whitespace();
            (
                $(inter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
}

macro_rules! insert_vec {
    ($t: ty) => {
        {
            let mut x = String::new();
            io::stdin().read_line(&mut x).ok();
            x = x.trim_right().to_owned();
            x.split_whitespace().map(|x| x.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

macro_rules! word_chars_vec {
    () => {
        {
            let mut x = String::new();
            io::stdin().read_line(&mut x).ok();
            x = x.trim_right().to_owned();
            x.chars().collect::<Vec<_>>()
        }        
    };
}

macro_rules! two_vec {
    ($t: ty; $e: expr) => {
        {
            (0..$e).map(|_| insert_vec!($t)).collect::<Vec<_>>()
        }
    };
}


fn main () {
    let (w, h, x, y) = get!(f64, f64, f64, f64);
    let s = w * h / 2.0;
    let p = if x + x == w && y + y == h { 1 } else { 0 };
    println!("{:.6} {}", s, p )
}


Measured memory_bytes: 4352
n, k = [ int(v) for v in input().split() ]
mod_list = [6,4,2,0,9,7,5,3,1,10,8]
g = mod_list.index(k)
corumn_list = [ None for i in range(5) ]

for i in range(11):
    for j in range(1,6):
        if (7*i+j) % 11 == g and corumn_list[j-1] is None:
            corumn_list[j-1] = i

m = (n-3)%11
ans = (5*((n-3)//11)+sum([m >= i  for i in corumn_list]))
print(ans)

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

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int N = A % B;
	bool finished = false;
	for (int i = 0; i < B; i++) {
		if (N == C) {
			cout << "YES" << endl;
			finished = true;
			break;
		}
		else
			N = (N + A) % B;
		if (N == A % B && i != 0 && finished == false) {
			cout << "NO" << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void) {
	int i, l, c=0;
	char s[111];
	
	scanf("%s", s);
	
	l=strlen(s);
	
	for(i=0;i<l;i++){
		if(s[i]=='C')
		c++;
		
		if(c!=0){
			if(s[i]=='F'){
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#define pb(x) push_back(x)
using namespace std;

const int N=200005;

int n,m;
struct tree{int mx,tag;}t[N*4];
vector<int> vec[N];

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

void pushdown(int d)
{
    int w=t[d].tag;t[d].tag=0;
    t[d*2].mx+=w;t[d*2].tag+=w;
    t[d*2+1].mx+=w;t[d*2+1].tag+=w;
}

void build(int d,int l,int r)
{
    if (l==r) {t[d].mx=-(m-l+1);return;}
    int mid=(l+r)/2;
    build(d*2,l,mid);build(d*2+1,mid+1,r);
    t[d].mx=max(t[d*2].mx,t[d*2+1].mx);
}

void ins(int d,int l,int r,int x,int y)
{
    if (l<r) pushdown(d);
    if (l==x&&r==y) {t[d].mx++;t[d].tag++;return;}
    int mid=(l+r)/2;
    if (y<=mid) ins(d*2,l,mid,x,y);
    else if (x>mid) ins(d*2+1,mid+1,r,x,y);
    else ins(d*2,l,mid,x,mid),ins(d*2+1,mid+1,r,mid+1,y);
    t[d].mx=max(t[d*2].mx,t[d*2+1].mx);
}

int query(int d,int l,int r,int x,int y)
{
    if (l<r) pushdown(d);
    if (l==x&&r==y) return t[d].mx;
    int mid=(l+r)/2;
    if (y<=mid) return query(d*2,l,mid,x,y);
    else if (x>mid) return query(d*2+1,mid+1,r,x,y);
    else return max(query(d*2,l,mid,x,mid),query(d*2+1,mid+1,r,mid+1,y));
}

int main()
{
    n=read();m=read();
    for (int i=1;i<=n;i++)
    {
        int x=read(),y=read();
        vec[x].pb(y);
    }
    build(1,0,m+1);
    int ans=n-m;
    for (int i=0;i<m;i++)
    {
        for (int j=0;j<vec[i].size();j++) ins(1,0,m+1,0,vec[i][j]);
        ans=max(ans,query(1,0,m+1,i+2,m+1)-i);
    }
    printf("%d",ans);
    return 0;
}

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

using namespace std;

int main() {
    int N, hR, nR;
    cin >> N >> hR;

    if (N >= 10){
        nR = hR;
    } else {
        nR = hR + 100*(10-N);
    }

    cout << nR << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
using namespace std;
typedef long long unsigned int ll;

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

int main() {

	string S, T;
	cin >> S >> T;
	vector<char> S_v(S.length());
	vector<char> T_v(T.length());
	for (int i = 0; i < S.length(); i++) {
		S_v[i] = S[i];
		T_v[i] = T[i];

	}

	for (int i = 0; i < S.length(); i++) {

		if (S_v == T_v) {
			cout << "Yes";
			return 0;
		}
		S_v.insert(S_v.begin(), S_v.back());
		S_v.pop_back();
	}
	cout << "No";
	return 0;
}

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

int N, M;

int main() {
  std::cin >> N >> M;
  for(int i = 0; i < M; ++i) {
    int A; std::cin >> A;
    N -= A;
  }
  if(N < 0) N = -1;
  std::cout << N << std::endl;
  return 0;
}


Measured memory_bytes: 3624
//
//  main.cpp
//  ITP1_2-A
//
//  Created by Saicj on 2015/07/13.
//  Copyright (c) 2015??´ saicj. All rights reserved.
//

#include <iostream>

int main()
{

    int a,b;
    
    std::cin >> a >> b;
    
    if (a > b) {
        std::cout << "a > b" << "\n";
    }else if (a < b){
        std::cout << "a < b" << "\n";
    }else{
        std::cout << "a == b" << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 1124
#include<bits/stdc++.h>
using namespace std;
inline double pi(){
	return M_PI;
} 
inline double COS(double tmp){
	double k=tmp*pi()/180.00;
	return cos(k);
}
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	long double ss=double((30.00*c+(d/60.00)*30.00)-6.00*d);
	if(2*ss>360)ss=360-ss;
	cout<<fixed<<setprecision(20)<<sqrt(a*a+b*b-(2*a*b*COS(ss)));
	return 0;
}

Measured memory_bytes: 4160
X, N = map(int, input().split())
l = list(map(int, input().split()))
min_abs = 51
ans = 0
for i in range(102):
    if i in l:
        continue
    if abs(i - X) < min_abs:
        min_abs = abs(i - X)
        ans = i
print(ans)

Measured memory_bytes: 9184
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		String S = sc.next();
		char[] chars = S.toCharArray();
		int counter = 0;
		for (int i = 0; i < chars.length / 2; i++) {
			char forward = chars[i];
			char back = chars[chars.length - i - 1];
			if (forward != back) counter++;
		}
		System.out.println(counter);
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 23764
#include<stdio.h>
int insertionSort(int[], int, int);
void shellSort(int[],int);

int main(){
  int n, i;
  int A[1000000];

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

  shellSort(A, n);

  for( i = 0 ; i < n ; i++ ){
    printf("%d\n",A[i]);
  }

  return 0;
}

int insertionSort(int A[], int n, int g){
  int i, j, cnt=0, v;
  for( i = g ; i < n ; i++ ){
    v = A[i];
    j = i - g;
    while( j >= 0 && A[j] > v ){
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
  }
  return cnt;
}

void shellSort(int A[], int n){
  int i=0, m, cnt=0, a=1;
  int G[100];

  while(1){
    if( a > n ) break;
    G[i++] = a;
    a = 3 * a + 1;
  }
  m = i;

  printf("%d\n",m);
  for( i = m-1 ; i > 0 ; i-- ){
    printf("%d ",G[i]);
  }
  printf("%d\n",G[0]);

  for( i = m-1 ; i >= 0 ; i-- ){
    cnt += insertionSort(A, n, G[i]);
  }
  printf("%d\n",cnt);
}



Measured memory_bytes: 5700
A,B,C,X,Y = map(int,input().split())
moneys = []

for i in range(0,2*max(X,Y)+1,2):
  if X-i//2 >= 0 and Y-i//2 >= 0:
    moneys.append((X-i//2)*A + (Y-i//2)*B + C*i)
  elif X-i//2 >= 0 and Y-i//2 < 0:
    moneys.append((X-i//2)*A + C*i)
  elif X-i//2 < 0 and Y-i//2 >= 0:
    moneys.append((Y-i//2)*B + C*i)
  else:
    moneys.append(C*i)
    
print(min(moneys))

Measured memory_bytes: 12788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int,Int> p;

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

    if(S == "ABC"){
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<long long, long long> P;
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    vector<ll> dp(n + 1);
    rep(i, n)
    {
        cin >> dp[i + 1];
        dp[i + 1] += dp[i];
    }
    ll ans = 1LL<<62;
    // しゃくとりで前計算
    // [0,r)
    vector<P> before(n + 1);
    int l = 0;
    int r = 1;
    for(r = 1;r<n;r++){
        while (l + 1 < r && abs(dp[l] - dp[0] - (dp[r] - dp[l])) > abs(dp[l + 1] - dp[0] - (dp[r] - dp[l + 1])))
        {
            l++;
        }
        P p;
        p.first = max(dp[l] - dp[0], dp[r] - dp[l]);
        p.second = min(dp[l] - dp[0], dp[r] - dp[l]);
        before[r] = p;
    }
    // [l,n)
    r = 1;
    vector<P> later(n+1);
    for (l = 0; l < n; l++)
    {
        while(r+1<n && abs(dp[r]-dp[l] - (dp[n]-dp[r]))>abs(dp[r+1]-dp[l] - (dp[n]-dp[r+1]))){
            r++;
        }
        P p;
        p.first = max(dp[r] - dp[l], dp[n] - dp[r]);
        p.second = min(dp[r] - dp[l], dp[n] - dp[r]);
        later[l] = p;
    }
    for(int i = 2;i<n-1;i++){
        ll mx = max(before[i].first,later[i].first);
        ll mn = min(before[i].second,later[i].second);
        ans = min(ans,mx-mn);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long LL;

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

  LL base = 1;
  LL minus = 1;
  for(int i=0; i<n; i++) {
    base *= 3;
    int a;
    cin >> a;
    if(a % 2 == 0) minus *= 2;

  }
  cout << base - minus << endl;
  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    ll sumA = 0;
    rep(i,n) sumA ^= a[i];
    rep(i,n){
        cout << (a[i]^sumA) << endl;
    }
    return 0;
}

Measured memory_bytes: 4048
def main():
    N = int(input())
    A = list(map(int, input().split()))
    i = 0
    prev = -1
    count = 0
    while i < N:
        if prev == A[i]:
            prev = -1
            count += 1
        else:
            prev = A[i]
        i += 1
    return count

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3060
from pprint import pprint as pp
import collections
import math
import itertools

K, = map(int, input().split())
A = tuple(map(int, input().split()))

old_a = A[-1]
x_max = 2 // A[-1]
x_min = 2 // A[-1]
for a in reversed(A):
  #pp((a, old_a, x_min, x_max))
  if a >= (old_a * (x_max +1)):
    x_max = -1
    break
  x_max = (old_a * (x_max+1)-1) // a
  x_min = math.ceil(old_a * x_min / a)
  if x_max < x_min:
    x_max = -1
    break
  old_a = a
#pp((old_a, x_min, x_max))
if x_max == -1:
  print(-1)
else:
  print(old_a * x_min, (old_a * (x_max+1))-1)


Measured memory_bytes: 15040
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, A, B, C; cin >> N >> A >> B >> C;
  map<char, ll> x; x['A'] = A; x['B'] = B; x['C'] = C;
  vector<string> S(N);
  for(int i = 0; i < N; i++) cin >> S.at(i);
  if(x.at(S.at(0).at(0)) + x.at(S.at(0).at(1)) == 0) {
    cout << "No" << endl;
    return 0;
  }
  if(A + B + C == 1) {
    vector<char> c(N);
    for(int i = 0; i < N; i++) {
      if(x.at(S.at(i).at(0)) < x.at(S.at(i).at(1))) {
        x.at(S.at(i).at(0))++; x.at(S.at(i).at(1))--; c.at(i) = S.at(i).at(0);
      } else {
        x.at(S.at(i).at(1))++; x.at(S.at(i).at(0))--; c.at(i) = S.at(i).at(1);
      }
      if(x.at('A') < 0 || x.at('B') < 0 || x.at('C') < 0) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
    for(int i = 0; i < N; i++) cout << c.at(i) << endl;
  } else {
    vector<char> c(N);
    for(int i = 0; i < N; i++) {
      if(x.at(S.at(i).at(0)) == 0 && x.at(S.at(i).at(1)) > 0) {
          x.at(S.at(i).at(0))++; x.at(S.at(i).at(1))--; c.at(i) = S.at(i).at(0);
      } else if(x.at(S.at(i).at(1)) == 0 && x.at(S.at(i).at(0)) > 0) {
        x.at(S.at(i).at(1))++; x.at(S.at(i).at(0))--; c.at(i) = S.at(i).at(1);
      } else if(A + B + C == 2 && (i + 1 < N && x.at(S.at(i).at(0)) == 1 && x.at(S.at(i).at(1)) == 1)) {
        if((S.at(i).at(0) == S.at(i + 1).at(0)) || (S.at(i).at(0) == S.at(i + 1).at(1))) {
          x.at(S.at(i).at(0))++; x.at(S.at(i).at(1))--; c.at(i) = S.at(i).at(0);
        } else if((S.at(i).at(1) == S.at(i + 1).at(0)) || (S.at(i).at(1) == S.at(i + 1).at(1))) {
          x.at(S.at(i).at(1))++; x.at(S.at(i).at(0))--; c.at(i) = S.at(i).at(1);
        }
      } else {
        if(x.at(S.at(i).at(0)) < x.at(S.at(i).at(1))) {
        x.at(S.at(i).at(0))++; x.at(S.at(i).at(1))--; c.at(i) = S.at(i).at(0);
        } else {
          x.at(S.at(i).at(1))++; x.at(S.at(i).at(0))--; c.at(i) = S.at(i).at(1);
        }
      }
      if(x.at('A') < 0 || x.at('B') < 0 || x.at('C') < 0) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
    for(int i = 0; i < N; i++) cout << c.at(i) << endl;
  }
}


Measured memory_bytes: 6436
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod(ll a){
  return (a % 1000000007);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll n,a,b; cin >> n >> a >> b;
  
  if((b-a) % 2 == 0) cout << (b-a)/2 << endl;
  else{
    ll x; ll t = (b-a-1)/2;
    if(a-1 <= n-b) x = a;
    else x = n-b+1;
    
    cout << x+t << endl;
  }
  
      
}

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

#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
typedef long long ll;
/////////////////////

int const N = 341;

int w[N][N], d[N][N], n;
ll ans;

void bad(){
	printf("-1\n");
	exit(0);
}

void solve(){
	memcpy(d, w, sizeof(w));
	fo(0, n){
		fi(0, n){
			fj(0, n){
				d[i][j] = min(d[i][j], d[i][o] + d[o][j]);
			}
		}
	}
	fi(0, n) fj(0, n) if(d[i][j] != w[i][j]) bad();
	fi(0, n) fj(i+1, n) ans += d[i][j];
	fi(0, n) fj(i+1, n){
		bool f = true;
		fo(0, n){
			if(o == i || o == j) continue;
			if(d[i][j] == d[i][o] + d[o][j]){
				f = false;
			}
		}
		if(!f) ans -= d[i][j];
	}
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%d",&n);
	fi(0, n) fj(0, n) scanf("%d",&w[i][j]);

	solve();

	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 1152
N , K =  list(map(int,input().split()))


K_2 = bin(K)[2:]
max_kouho = [K_2,("1"* (len(K_2) -1) if len(K_2)>1 else "0") ]



for i in range(1,len(K_2)-1):
    if K_2[i] == "1"  and K_2.find("0") >-1:
        max_kouho.append(
            (K_2[:i]+"0"+ ("1" * 100) )[:len(K_2)] )
#print(max_kouho)

AB  = [ list(map(int,input().split())) for _ in range(N)]

if K==0:
    ans =0
    for a,b in (AB):
        if a==0:
            ans +=b
    print(ans)
    exit()
dp = {key:0 for key in max_kouho}
for a,b in AB:
    #use
    for key in max_kouho:
        if int(key,2) |a ==int(key,2):
            dp[key]+=b
    #print(bin(a),b,dp)

print(max(dp[key] for key in max_kouho ))

Measured memory_bytes: 29428
function main(lines) {
    const a = lines[0].charAt(0)

    if ('a'.charAt(0) <= a && a <= 'z'.charAt(0))
	    console.log('a')
    if ('A'.charAt(0) <= a && a <= 'Z'.charAt(0))
	    console.log('A')
}


main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"))


Measured memory_bytes: 29664
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>
#include <stack>

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n;i>s;i--)
#define rep_re(i,s,n)for(ll i = n;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

int main(void) {
	int N, K;
	string S;
	cin >> N >> K >> S;

	int score = 0;
	for (int i = 1; i < S.size(); i++) {
		if (S[i - 1] == S[i]) score++;
	}

	int ans = min(score + 2 * K, N - 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    string s;
    std::deque<string> words;
    for (int i=0;i<n;i++) {
        cin>>s;
        words.emplace_back(s);
    }
    sort(words.begin(),words.end());
    int count=1;
    string tmp=words[0];
    for (int j=1;j<n;j++) {
        if (tmp!=words[j]) {
            count++;
        }
        tmp=words[j];
    }
    cout<<count<<endl;
}

Measured memory_bytes: 10068
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int N;
int F[110][12];
int P[110][12];

int change(int n){
	int b = 0;
	int base = 1;
	while(n>0){
		b += (n%2)*base;
		n = n/2;
		base *= 10;
	}
	return b;
}

int main(){
	//string t = to_string(change(512)); 
	//cout << t[2] << endl;
	while(cin >> N && N > 0){
		for(int i=0;i<N;i++){
			for(int j=0;j<10;j++){
				cin >> F[i][j];
			}
		}
		for(int i=0;i<N;i++){
			for(int j=0;j<11;j++){
				cin >> P[i][j];
			}
		}
		long long  ans = -(1<<30);
		for(int i=1;i<1024;i++){
			long long  ansnow = 0;
			string s = to_string(change(i));
			while(s.size()<10){
				s = '0' + s;
			}
			int open[12] = {0};
			for(int j=0;j<10;j++){
				char sj = s[j];
				int n = atoi(&sj);
				if(n==1) open[j] = 1;
				else open[j] = 0;
			}
			for(int j=0;j<N;j++){
				int count = 0;
				for(int k=0;k<10;k++){//店iと被る数
					if(open[k] == 1 && F[j][k] == 1) count++;
				}
				ansnow += P[j][count];
			}
			if(ansnow>ans) ans = ansnow;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    ll Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;
    ll ans = 0;
    if ((D < S * 2) && (D < H * 4) && (D < Q * 8))
    {
        ans += D * (N / 2);
        N %= 2;
    }
    ans += min({Q * 4, H * 2, S}) * N;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
//typedef std::pair<std::string,double> P;


#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9+7;
vector<pair<int, int> > vp;
 
struct Less {
    bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
        return x.first > y.first;
    }
};

ll GCD(ll a, ll b){
    if(b==0) return a;
    return GCD(b, a%b);
}


//グラフの隣接リスト
VI g[200010];
//頂点の入次数を管理
int h[100010];
ll N, H;
string s;
ll a[110], b[100010];
vector<string> field;
int main(void) {
    int N; cin >> N;
    vector<int> v;
    for(int i=0; i<N; ++i){
        int a; cin >> a;
        v.push_back(a);
    }
    vector<int> v2 = v;
    vector<int> ans;
    bool f = true;
    bool update = true;
    while(v2.size()!=0){
        update = false;
        for(int i=v2.size()-1; i>=0; --i){
            for(int j=v2.size(); j>=1; --j){
                if(v2[i] == j && i+1 == j){
                    ans.push_back(v2[i]);
                    v2.erase(v2.begin()+i);
                    update = true;
                    break;
                }
                if(i == 0 && j==1){
                    f = false;
                }
            }
            if(update) break;
        }
        if(!f) break;
    }
    reverse(ans.begin(), ans.end());
    if(f){
        for(auto e: ans) cout << e << endl;
    }else{
        cout << -1 << endl;
    }
	return 0;
}


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

  

int main() {
  int N;
  cin>>N;
  
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  
  int ima=1;
  for(int i=0;i<N;i++){
    if(vec.at(i)==ima) ima+=1;
  }
  
  if(ima==1) cout<<-1<<endl;
  else cout<<N-(ima-1)<<endl;
   

    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n, m;
  cin >> n >> m;
  vector< int > p(n);
  vector< int > g(n);
  for (int i=0; i<n; ++i) {
    cin >> p[i];
    p[i]--;
    g[i] = i;
  }
  for (int i=0; i<m; ++i) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    //if (x>y) swap(x, y);
    int x_top = x, y_top = y;
    while (g[x_top] != x_top) x_top = g[x_top];
    while (g[y_top] != y_top) y_top = g[y_top];
    x_top = min(x_top, y_top);
    if (g[y]==y && y!=x_top) {
      g[y] = x_top;
    }
    if (g[x]==x && x!=x_top) {
      g[x] = x_top;
    }
    while (g[y] != y) {
      int next = g[y];
      g[y] = x_top;
      y = next;
    }
    if (y != x_top) g[y] = x_top;
    while (g[x] != x) {
      int next = g[x];
      g[x] = x_top;
      x = next;
    }
    if (x != x_top) g[x] = x_top;
  }
  for (int i=0; i<n; ++i) {
    if (g[i]==i) continue;
    int i_top = i;
    while (g[i_top] != i_top) i_top = g[i_top];
    g[i] = i_top;
  }
  //for (int i=0; i<n; ++i) cerr << g[i] << " ";
  //cerr << endl;
  vector< vector< int > > same(n);
  for (int i=0; i<n; ++i) {
    if (g[i] == i) same[i].push_back(i);
    else {
      int i_top = g[i];
      while (g[i_top] != i_top) i_top = g[i_top];
      same[i_top].push_back(i);
    }
  }
  int ans = 0;
  for (int i=0; i<n; ++i) {
    vector< int > l;
    for (int j=0; j<same[i].size(); ++j) l.push_back(p[same[i][j]]);
    sort(l.begin(), l.end());
    sort(same[i].begin(), same[i].end());
    int li=0, si=0;
    while (li < l.size() && si < same[i].size()) {
      if (l[li] == same[i][si]) {
        ans++;
        li++; si++;
      } else if (l[li] < same[i][si]) li++;
      else si++;
    }
  }
  cout << ans << endl;
  return 0;
}


/*
1 1 1 1 1 1 1 1 1 10
*/


Measured memory_bytes: 6528