akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define MAX 2000000
#define INF (1<<30)

int H, A[MAX + 1];

void maxHeapify(int i){
  int l = 2 * i;
  int r = 2 * i + 1;
  int largest, tmp;

  if(l <= H && A[l] > A[i]) largest = l;
  else  largest = i;

  if(r <= H && A[r] > A[largest]) largest = r;

  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}

int extract(){
  int max;
  if(H < 1) return -INF;
  max = A[1];
  A[1] = A[H--];
  maxHeapify(1);
  return max;
}

void increaseKey(int i, int key){
  int tmp;

  if(key < A[i])  return;
  A[i] = key;
  while(i > 1 && A[i / 2] < A[i]){
    tmp = A[i];
    A[i] = A[i / 2];
    A[i / 2] = tmp;
    i = i / 2;
  }
}

void insert(int key){
  H++;
  A[H] = -INF;
  increaseKey(H, key);
}

int main(void){
  int key;
  char s[20];

  while(1){
    scanf("%s", s);
    if(s[0] == 'e' && s[1] == 'n')  break;
    if(s[0] == 'i'){
      scanf("%d", &key);
      insert(key);
    }
    else{
      printf("%d\n", extract());
    }
  }
  return 0;
}



Measured memory_bytes: 5616
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int ans = N % 1000;
        if (ans != 0) {
            ans = 1000 - ans;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35600
#include <iostream>
#include <bits/stdc++.h>
#include <iomanip>
#include<math.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
int  main(){
  ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	cout.tie(0);
    ll a,b,n,x;
cin>>a>>b>>n;
    if(n<b){
      x=floor(a*n/b);
      cout<<x<<endl;
    }
    else{
      x=floor(a*(b-1)/b);
      cout<<x<<endl;
    }
  }


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

void diceS(int []);
void diceE(int []);
void diceW(int []);
void diceN(int []);
void diceR(int []);

int main(){
	int d[6],p,n,m;
	string str;
	for(int i=0;i<6;i++) cin >> d[i];
	cin >> p;
	while(p--){
		cin >> n >> m;
		for(int k=0;k<4;k++){
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				if(d[0]==n && d[1]==m){
					cout << d[2] << endl;
					goto LOOP;
				}
				diceS(d);
			}
			diceE(d);
		}
		diceR(d);
		}
		LOOP:;
	}

	return 0;
}

void diceS(int a[6]){
	int w;
	w=a[0];
	a[0]=a[4];
	a[4]=a[5];
	a[5]=a[1];
	a[1]=w;
}


void diceE(int a[6]){
	int w;
	w=a[0];
	a[0]=a[3];
	a[3]=a[5];
	a[5]=a[2];
	a[2]=w;
}

void diceW(int a[6]){
	int w;
	w=a[0];
	a[0]=a[2];
	a[2]=a[5];
	a[5]=a[3];
	a[3]=w;
}

void diceN(int a[6]){
	int w;
	w=a[0];
	a[0]=a[1];
	a[1]=a[5];
	a[5]=a[4];
	a[4]=w;
}

void diceR(int a[6]){
	int w;
	w=a[1];
	a[1]=a[2];
	a[2]=a[4];
	a[4]=a[3];
	a[3]=w;
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int[][][] houses = new int[4][3][10];
		int n = Integer.parseInt(in.readLine());
		for (int i = 0; i < n; i += 1) {
			String[] info = in.readLine().split(" ");
			int b = Integer.parseInt(info[0]);
			int f = Integer.parseInt(info[1]);
			int r = Integer.parseInt(info[2]);
			int v = Integer.parseInt(info[3]);
			houses[b - 1][f - 1][r - 1] += v;
		}
		for (int x = 0; x < 4; x += 1) {
			for (int y = 0; y < 3; y += 1) {
				for (int z = 0; z < 10; z += 1) {
					sb.append(" ");
					sb.append(houses[x][y][z]);
				}
				sb.append(System.getProperty("line.separator"));
			}
			if (x != 3) {
				sb.append("####################"
						+ System.getProperty("line.separator"));
			}
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 19308
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    vector<int> b(n);
    for (int j = 0; j < n + 1; ++j) {
        cin >> a[j];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    long long ans = 0;

    for (int i = 0; i < n; ++i) {
        if (a[i] > b[i]) {
            ans += b[i];
            b[i] = 0;
        } else {
            ans += a[i];
            b[i] -= a[i];
        }
        if (a[i + 1] > b[i]) {
            ans += b[i];
            a[i + 1] -= b[i];
        } else {
            ans += a[i + 1];
            a[i + 1] = 0;
        }
    }

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



Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int a;
	int b;
	
	scanf("%d",&a);
	scanf("%d",&b);
	
	if(a<b){
		printf("a < b\n");
	}
	
	if(b<a){
		printf("a > b\n");
	}
	
	if(a==b){
		printf("a == b\n");
	}
	
	return 0;
}

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

void solve(std::string s) {
  long long gCnt = 0;
  for (auto c : s) {
    if (c == 'g') {
      gCnt++;
    } else {
      gCnt--;
    }
  }

  printf("%lld\n", gCnt / 2);
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  std::string s;
  std::cin >> s;
  solve(s);
  return 0;
}


Measured memory_bytes: 512
import itertools
from collections import defaultdict

N,A,B,C = map(int,input().split())
LIS = []
for i in range(N):
  temp = int(input())
  LIS.append(temp)
M = [0,1,2,3]

X = list(itertools.product(M, repeat=N))
INF = float("inf")
ans = INF
#print(X)
for L in X:
  ts = set(L)
  dic = defaultdict(int)
  #print(ts,L)
  if 1 not in ts or 2 not in ts or 3 not in ts:
    continue
  temp = [-1,0,0,0]
  for i,v in enumerate(L):
    temp[v] += LIS[i]
    dic[v] += 1
  temp = temp[1:]
  temp.sort(reverse = True)
  atemp = abs(temp[0]-A)+abs(temp[1]-B)+abs(temp[2]-C)
  atemp += 10*(dic[1]+dic[2]+dic[3]-3)
  ans = min(atemp,ans)
print(ans)
      

Measured memory_bytes: 83852
import java.util.*;
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String[] input = br.readLine().split(" ");
			int H = Integer.parseInt(input[0]);
			int W = Integer.parseInt(input[1]);			
			if ((H == 0) && (W == 0)){
				break;
			}
			for (int j = 1; j <= W; j++){
				System.out.print("#");
			}
			System.out.println("");
			for (int i = 2; i <= H - 1; i++){
				System.out.print("#");
				for (int j = 2; j <= W - 1; j++){
					System.out.print(".");
				}
				System.out.println("#");
			}
			for (int j = 1; j <= W; j++){
				System.out.print("#");
			}
			System.out.println("");
			System.out.println("");
		}
		
	}
}

Measured memory_bytes: 24660
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(int)n; i++)
using namespace std;
int main(){
  int n;
  
  int64_t c=0, d=0;
  cin >> n;
  int64_t a[n], k[n];
  rep(i, n){ 
    cin >> a[i];
    k[i]=a[i]%1000000007;
    d+=k[i];
  }  
  rep(i, n-1){
    d=d-k[i];
    int64_t e=d%1000000007;
    int64_t b=k[i]*e;
    c+=b;
    c=c%1000000007;
  }
  cout << c << endl;
}
      
      


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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    string s, t;
    cin >> s >> t;
    rep(i, 0, s.size()){
        if(s[i] != t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

using namespace std;

const int N = 505;

char s[N][N];
int f[N][N], dem[N][N];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);

    for (int i = 1; i <= n; i++) scanf("%s", s[i]);

    int ans = 0;

    for (int j = 0; j < m-1; j++) {
        for (int i = 0; i <= n; i++) {
            dem[0][i] = f[0][i] = 0;
        }
        for (int i = 1; i <= n; i++) {
            dem[i][0] = f[i][0] = 0;
            for (int z = 1; z <= n; z++) {
                dem[i][z] = dem[i-1][z-1] + ((s[i][j]==s[z][j+1])?1:0);
                f[i][z] = min(f[i-1][z], f[i][z-1]) + dem[i][z];
            }
        }
        ans += f[n][n];
    }

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


Measured memory_bytes: 1536
N = int(input())
edge = [{} for _ in range(N + 1)]
dist = [-1] * (N + 1)
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    edge[a][b] = c
    edge[b][a] = c

Q, K = map(int, input().split())
dist[K] = 0
dfs_stack = [K]
while dfs_stack:
    s = dfs_stack.pop()
    for t, t_dist in edge[s].items():
        if dist[t] == -1:
            dist[t] = dist[s] + t_dist
            dfs_stack.append(t)

for _ in range(Q):
    x, y = map(int, input().split())
    print(dist[x] + dist[y])

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

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

	int a, b; cin >> a >> b;
	int min8 = (a * 100 + 7) / 8;
	int max8 = ((a + 1) * 100 + 7) / 8 - 1;
	int min10 = (b * 100 + 9) / 10;
	int max10 = ((b + 1) * 100 + 9) / 10 - 1;

	if (min8 < min10) {
		if (max8 < min10) cout << -1;
		else cout << min10;
	}
	else {
		if (max10 < min8) cout << -1;
		else cout << min8;
	}
	return 0;
}

Measured memory_bytes: 3652
n1 = int(input())
txt1 = input().split()
n2 = int(input())
txt2 = input().split()

for i in range(min(n1, n2)):
    c1, c2 = txt1[i], txt2[i]
    if c1 != c2:
        print([0, 1][c1 < c2])
        break
else:
    print([0, 1][n1 < n2])


Measured memory_bytes: 5628
#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,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
const int MAX_N=1e5;

signed main(){
    int X;cin>>X;
    cout<<"ABC"<<X<<endl;
}

Measured memory_bytes: 256
import math
from collections import deque
from collections import defaultdict
import itertools as it

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	if len(res)==0:
		res = [n]
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	data = [2]
	#data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	ans = [x for x in data if x!=0]
	#ans = data[:]
	return ans

n = readInt()
a = readInts()
a.sort()

#max_a = 10**6
max_a = a[-1]
ans = [0]*(max_a+1)

for i in a:
	ans[i]+=1
for i in set(a):
	if ans[i]>0:
		for j in range(i*2,len(ans),i):
			ans[j]+=2

count = 0


print(ans.count(1))

Measured memory_bytes: 40872
#include <stdio.h>
#include <string.h>
#define MOD 2019

long long int power(int s, int t)
{
	long long int ans = 1;
	long long int k = s;
	while(t)
	{
		if(t%2==1) ans*=k, ans%=MOD;
		k*=k, k%=MOD;
		t/=2;
	}
	return ans;
}
long long int inv(int k)
{
	return power(k,1343);
}


char x[200010];
int y[200010];
long long int check[200010];
int main()
{
	scanf("%s",x+1);
	int a = strlen(x+1);
	
	int s = 0;
	for(int i=1;i<=a;i++)
	{
		s*=10;
		s+=(x[i]-'0');
		s%=MOD;
		y[i] = s;
	}
	for(int i=1;i<=a;i++)
	{
		long long int t = y[i] * power(inv(10),i);
		t %= MOD;
		check[t]++;
	}
	check[0]++;
	
	long long int ans = 0;
	for(int i=0;i<MOD;i++)
	{
		ans += check[i]*(check[i]-1)/2;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 2720
#include <bits/stdc++.h>
using namespace std;
long long n,k,w[109],v[109];
long long dp[109][100009];
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>w[i]>>v[i];
    for(int i=0;i<100;i++){
        for(int j=1;j<=100000;j++){
            dp[i][j] = 1000000009;
        }
    }
    dp[0][v[0]] = w[0];
    for(int i=1;i<n;i++){
        for(int j=0;j<=100000;j++){
            if(j-v[i] >= 0) dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
            else dp[i][j] = dp[i-1][j];
        }
    }
    for(int i=100000;i>=0;i--){
        if(dp[n-1][i] <= k){
            cout<<i<<endl;
            exit(0);
        }
    }
}

Measured memory_bytes: 80128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
const int mod = 1e9+7;
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; }

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    map<int, int> mp;
    rep(i,n){
        if(mp[a[i]] != 0){
            cout << "NO" << endl;
            return 0;
        }
        mp[a[i]]++;
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define N 100005
#define P pair<ll,ll>
#define fi first
#define sc second
typedef long long ll;
using namespace std;

ll l[N],r[N];
P a[N];

int main(){
    ll n; ll lmax=0,rmin=1e9,maxlen=0;
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++){
        scanf("%lld%lld",&l[i],&r[i]);
        lmax=max(lmax,l[i]);
        rmin=min(rmin,r[i]);
        maxlen=max(maxlen,r[i]-l[i]+1);
    }
   //cout<<maxlen<<endl;
    ll ans=maxlen+max(rmin-lmax+1,0ll);
    for(ll i=1;i<=n;i++){
        a[i]=P(max(0ll,r[i]-lmax+1),-1*max(0ll,rmin-l[i]+1));
    }
    sort(a+1,a+n+1);
    ll mnsc=-a[1].sc;
    for(ll i=2;i<=n;i++){
        ans=max(ans,a[i].fi+mnsc);
        mnsc=min(mnsc,-a[i].sc);
    }
    printf("%lld\n",ans);
}

/*
a[i]=r[i]-lmax b[i]=rmax-l[i]
maximize min(a[i]) + min(b[i])
*/


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

int main()
{
while(true){	
		int H,W,k=0;
		cin>>H>>W;
		if(H==0&&W==0) break;
		while (k<H)
		{	
			for(int i=0;i<W;i++){
				if(k==0||k==H-1||i==0||i==W-1)cout<<"#";
				else cout<<".";
			}
			cout<<endl;
			k++;
		}
		cout<<endl;
	}
   return 0;
}



Measured memory_bytes: 3076
S = input()
if S == "SAT":
    print (1)
elif S == "FRI":
    print (2)
elif S == "THU":
    print (3)
elif S == "WED":
    print (4)
elif S == "TUE":
    print (5)
elif S == "MON":
    print (6)
else:
    print (7)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define FOR(i, a, b) for (int i=(a); i<(b); ++i)
#define ROF(i, b, a) for (int i=(b); i>(a); --i)
#define CASET int _T; cin >> _T; FOR(caset, 0, _T)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vvb vector<vb>
#define pii pair<int,int>
#define t3i tuple<int,int,int>
#define mii map<int,int>
#define vpii vector<pii>
#define vt3i vector<t3i>
#define sq(x) (x)*(x)
#define inv(x) powa(x, MOD-2)
 
long long INF = 1LL<<60;
long long MOD = 1e9+7;

template <typename A, typename B> istream &operator>>(istream &is, pair<A, B> &pr) {is >> pr.first >> pr.second; return is;}
template <typename A> istream &operator>>(istream &is, vector<A> &v) {for (auto &x : v) is >> x; return is;}
ostream &operator<<(ostream &os, char &c) {os << (char)c; return os;}
ostream &operator<<(ostream &os, const char s[]) {os << (string)s; return os;}
ostream &operator<<(ostream &os, string &s) {for (char &c : s) os << (char)c; return os;}
template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> &pr) {os << '(' << pr.first << ", " << pr.second << ')'; return os;}
ostream &operator<<(ostream &os, vb &v) {
    bool first = true;
    os << '[';
    for (const bool &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
template <class C> ostream &operator<<(ostream &os, C &v) {
    bool first = true;
    os << '[';
    for (auto &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}
bool mini(int &a, int b) { return b < a ? a = b, 1 : 0; }
bool maxi(int &a, int b) { return b > a ? a = b, 1 : 0; }

main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int R, C;
    cin >> R >> C;

    vs grid(R, string(C, ' '));
    cin >> grid;

    int res = 0;
    FOR(sr, 0, R) FOR(sc, 0, C) if (grid[sr][sc] != '#') {
        deque<pii> q = {{sr, sc}};
        vvi dist(R, vi(C, -1));
        dist[sr][sc] = 0;
        while (q.size()) {
            int r, c;
            tie(r, c) = q.front();
            q.pop_front();

            for (pii delta : vpii{{0, 1}, {1, 0}, {0, -1}, {-1, 0}}) {
                int rr = r + delta.first;
                int cc = c + delta.second;
                if (rr < 0 || rr >= R || cc < 0 || cc >= C || grid[rr][cc] == '#' || dist[rr][cc] != -1) continue;
                dist[rr][cc] = dist[r][c] + 1;
                maxi(res, dist[rr][cc]);
                q.push_back({rr, cc});
            }
        }
    }
    cout << res;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
double PI=acos(-1.0);
int n,D,L,R;
double l,r,t;
P lp,rp;

int main(){
  while(1){
    cin>>n>>D;
    if(n==0&&D==0)break;
    lp=P(-D,0);
    rp=P(D,0);
    for(int i=0;i<n;i++){
      cin>>L>>R>>t;
      l=(double)L/180.0*PI*t;
      r=(double)R/180.0*PI*t;
      if(L==R){
        P k=(rp-lp)*P(0,1);
        lp+=k/abs(k)*l;
        rp+=k/abs(k)*r;
        continue;
      }
      P ap=(lp*r-rp*l)/(r-l);
      bool flg=(l*r<0);
      if(abs(l)>abs(r)||flg)l=-l;
      if(abs(l)>abs(r)&&!flg)r=-r;
      if(L!=0)l/=abs(ap-lp);
      if(R!=0)r/=abs(ap-rp);
      if(L!=0)lp=ap+(lp-ap)*P(cos(l),sin(l));
      if(R!=0)rp=ap+(rp-ap)*P(cos(r),sin(r));
    }
    printf("%.8f\n",real(lp+rp)/2.0);
    printf("%.8f\n",imag(lp+rp)/2.0);
  }
  return 0;
}

Measured memory_bytes: 1264
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const ll inF = 0x3f3f3f3f3f3f3f3f;
struct node{
	int w , v;
};
node a[maxn];
ll dp[maxn];
int main(){
	int n , c;cin >> n >> c;
	int w , v , tmp = 0;
	for(int i = 1;i <= n;i++)cin >> a[i].w >> a[i].v , tmp+=a[i].v;
	for(int i = 1;i <= tmp;i++)dp[i] = inF;
	for(int i = 1;i <= n;i++){
		for(int j = tmp;j >= a[i].v;j--){
			dp[j] = min(dp[j] , dp[j-a[i].v] + a[i].w);
		}
	}
	int ans = 0;
	for(int i = tmp;i >= 1;i--){
		if(dp[i] <= c){
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4364
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 100005
using namespace std;
typedef long long ll;
int a[N],op[N],n;
ll f[N][3];
int main(){
	scanf("%d",&n);
	const ll inf=1LL<<60;
	char aa[2];
	for(int i=1;i<=n;i++){
		if(i>1) scanf("%s",aa);
		else aa[0]='+';
		scanf("%d",&a[i]);
		op[i]=aa[0]=='+'?1:-1;
		for(int p=0;p<3;p++) f[i][p]=-inf;
	}
	f[0][2]=f[0][1]=-inf;
	for(int i=1;i<=n;i++){
		f[i][2]=f[i-1][2]+a[i];
		if(op[i]==1){
			f[i][0]=max(f[i-1][0],f[i-1][1])+a[i];
			f[i][1]=f[i-1][1]-a[i];
		}else{
			f[i][0]=-inf;
			f[i][1]=f[i-1][0]-a[i];
			f[i][2]=max(f[i][2],f[i-1][1]+a[i]);
		}
	}
	printf("%lld",max(f[n][0],max(f[n][1],f[n][2])));
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9){
    cout<<"hon";
    return 0;
  }
  if(n%10==0||n%10==1||n%10==6||n%10==8){
    cout<<"pon";
    return 0;
  }
  if(n%10==3){
  cout<<"bon";
    return 0;
  }
  return 0;
	
}

Measured memory_bytes: 3572
import numpy as np
import sys
n = int(input())
a = np.array([int(x) for x in input().split()])
dp = np.zeros((n + 1, 2))
dp[0][1] = -2000000001
for i in range(n):
	dp[i + 1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i])
	dp[i + 1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i])
print(int(dp[n][0]))

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

int main() {
  int k;
  cin >> k;
  
  int x = 7 % k;
  set<int> s;
  int i = 1;
  while(s.count(x) == 0) {
      if (x == 0) {
        cout << i << endl;
        return 0;        
      }
      s.insert(x);
      x = (x * 10 + 7) % k;
      i++;

  }
  cout << -1 << endl;
  return 0;
} 

Measured memory_bytes: 50340
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
#include <deque>
#include <set>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}



int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/


/*
 * 最大公約数計算
 */
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int A,B,C;

	cin >> A >> B >> C;
	if (A == B)
	{
		cout << C << endl;
	}
	else if (B == C)
	{
		cout << A << endl;
	}
	else
	{
		cout << B << endl;
	}
	

	return 0;

}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next(), T = sc.next();
    int num=0;
    for(int i=0; i<S.length(); i++) {
      if(!S.substring(i,i+1).equals(T.substring(i,i+1))) {
        num++;
      }
    }
    System.out.println(num);
  }
}

Measured memory_bytes: 55528
#include<bits/stdc++.h>
using namespace std;
map<int,int> mp;
int main()
{
	int n,i;
	cin>>n;
	int x;
	for(i=0;i<n;i++){
		cin>>x;
		mp[x]++;
		if(mp[x]>=2){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 9600
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void solve() {
	string s; cin >> s;
    int n = (int)s.size();
    bool check = false;
    rep(i, n) {
        if(check) if(s[i] == 'F') {
            cout << "Yes" << endl;
            return;
        }
        if(s[i] == 'C') check = true;
    }
    cout << "No" << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
using Yorukatsu023.Questions;
using Yorukatsu023.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu023.Questions
{
    public class QuestionC : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var nk = inputStream.ReadIntArray();
            var n = nk[0];
            var k = nk[1];

            var exp = 0.0;

            for (int i = 1; i <= n; i++)
            {
                exp += 1 / (Math.Pow(2, GetPow(i, k)));
            }

            exp /= n;

            yield return exp;
        }

        int GetPow(int n, int k)
        {
            var pow = 0;
            while (n < k)
            {
                n *= 2;
                pow++;
            }
            return pow;
        }
    }
}


namespace Yorukatsu023
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionC();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu023.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu023.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define ll int64_t
#define ar array
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (n); ++i) 
using namespace std;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n=5;
    forn(i,n){
        int x;cin>>x;
        if(x==0){
            cout<<i+1<<endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll S, W;
  cin >> S >> W;

  if(S <= W)
    cout << "unsafe" << endl;
  else
    cout << "safe" << endl;
  
  return 0;
}


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

int n;
vector<vector<int> > graph;
vector<bool> visited;
vector<int> deg;

void dfs(int node){
    visited[node] = true;
    for(int i=0;i<int(graph[node].size());i++){
        int nxt = graph[node][i];
        if(!visited[nxt]){
            dfs(nxt);
        }
    }
}

int main(){
    while(cin >> n, n){
        graph.clear();
        graph.resize(26);
        visited.assign(26, false);
        deg.assign(26, 0);
        for(int i=0;i<n;i++){
            string s;
            int from, to;
            cin >> s;
            from = s.front() - 'a';
            to = s.back() - 'a';
            graph[from].push_back(to);
            deg[from]++;
            deg[to]--;
        }
        bool ok = true;
        for(int i=0;i<26;i++){
            if(deg[i] != 0){
                ok = false;
            }
        }
        for(int i=0;i<26;i++){
            if(graph[i].size()>0){
                dfs(i);
                break;
            }
        }
        for(int i=0;i<26;i++){
            if(graph[i].size() > 0 && !visited[i]){
                ok = false;
            }
        }
        cout << (ok ? "OK" : "NG") << endl;
    }
    return 0;
}



Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
#define ROCK 0
#define SCHISSORS 1
#define PAPER 2
int main(){
    int N,K,R,S,P;
    int point[3];
    cin >> N >> K >> point[ROCK] >> point[SCHISSORS] >> point[PAPER];
    int hand2win[N],flag[N]={0};
    char ch;
    for(int i=0; i<N; i++){
        cin >> ch;
        switch (ch){
        case 'r':
        hand2win[i]=PAPER;
        break;

        case 's':
        hand2win[i]=ROCK;
        break;

        case 'p':
        hand2win[i]=SCHISSORS;
        break;
        }
        flag[i]=-1;
    }
    int ans=0;
    for(int i=0; i<N; i++){
        if(hand2win[i]!=flag[i]){
            ans+=point[hand2win[i]];
            if(i<N-K){
                flag[i+K]=hand2win[i];
            }
        }
        
    }
    cout << ans;
    return 0;
}


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

#define int long long

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

int N, K;
int a[220000], idx[220000];

// Binary Indexed Tree(1-indexed)
const int MAX_N = 220000;

struct BIT {
    int bit[MAX_N + 1], n;

    int sum(int i) {
        int s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    void add(int i, int x) {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }
};

signed main() {
    cin >> N >> K;
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
        a[i] -= K;
        a[i] += a[i - 1];
        idx[i] = i;
    }
    stable_sort(idx, idx + N + 1, [](int l, int r) { return a[l] < a[r]; });
    for (int i = 0; i <= N; i++) {
        a[idx[i]] = i + 1;
    }
    BIT bit;
    bit.n = N + 1;
    int ans = 0;
    for (int i = 0; i <= N; i++) {
        ans += bit.sum(a[i]);
        bit.add(a[i], 1);
    }
    cout << ans << endl;
    return 0;
}

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

using i64 = int64_t;

int main(){
    string s1;
    while(cin >> s1, s1 != "."){
        string s2;
        cin >> s2;
        if(s1 == s2){
            cout << "IDENTICAL" << endl;
            continue;
        }
        int n1 = 0, n2 = 0;
        for(auto c: s1){
            if(c == '"')n1++;
        }
        for(auto c: s2){
            if(c == '"')n2++;
        }
        if(n1 != n2){
            cout << "DIFFERENT" << endl;
            continue;
        }
        s1 += "\""; s2 += "\"";
        int s1left = 0, s2left = 0, cnt = 0;
        bool quote = false, ok = true;
        while(s1left < s1.size() && s2left < s2.size()){
            int s1right = s1left, s2right = s2left;
            while(s1right < s1.size() && s1[s1right] != '"')s1right++;
            while(s2right < s2.size() && s2[s2right] != '"')s2right++;
            string t1 = s1.substr(s1left, s1right-s1left), t2 = s2.substr(s2left, s2right-s2left);
            //cerr << t1 << " " << t2 << endl;
            if(quote){
                if(t1 != t2)cnt++;
            }else{
                if(t1 != t2){
                    ok = false;
                    break;
                }
            }
            s1left = s1right+1;
            s2left = s2right+1;
            quote ^= 1;
        }
        //cerr << ok << " " << cnt << endl;
        if(!ok || cnt > 1){
            cout << "DIFFERENT" << endl;
        }else{
            cout << "CLOSE" << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
int main() {
	ll n,m,tmp,ans=0;
	priority_queue<ll>a;
	cin >> n >> m;
	for(ll i=0;i<n;i++){
		cin >> tmp;
		a.push(tmp);
	}
	for(ll i=0;i<m;i++){
		tmp=a.top()/2;
		a.pop();
		a.push(tmp);
	}
	for(ll i=0;i<n;i++){
		ans+=a.top();
		a.pop();
	}
  cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
#define T_ template
#define Tn typename
T_ <Tn T> inline bool cmin(T & a, const T & b) { return a > b ? a = b, 1 : 0;}
T_ <Tn T> inline bool cmax(T & a, const T & b) { return a < b ? a = b, 1 : 0;}
T_ <Tn L, Tn R> ostream & operator << (ostream &out, pair<L, R> t) {
   return out << "(" << t.first << "," << t.second << ")";
}
T_ <Tn T> ostream & operator << (ostream &out, vector<T> t) {
  for (unsigned i = 0; i < t.size(); i++)
    out << (" ("[!i]) << t[i] << (",)"[i == t.size() - 1]);
  return out;
}

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

const int MaxN = 200010;
int n, m; 
char s[MaxN], t[MaxN];

int main() {
  scanf("%s", s + 1); n = strlen(s + 1);
  for (int i = 1; i < n; i++)
    if (s[i] == 'B' && s[i + 1] == 'C') {
      t[++m] = 'D'; ++i;
    } else
      t[++m] = s[i];
  t[m + 1] = '\0';
  ll ans = 0;
  for (int i = 1, j; i <= m; i = j) {
    j = i;
    int u = 0, v = 0;
    while (j <= m) { 
       if (t[j] != 'A' && t[j] != 'D') {
        j++; break;
      }
      if (t[j] == 'A')
        ++u;
      else
        ans += u;
      ++j;
    }
  }
  printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>

using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    int n;
    cin >> n;

    int ans = 0;
    for(int i = 1; i <= n; i+=2){
        int is8 = 0;
        for(int j = 1; j <= i; j++)if(i%j==0)is8++;
        if(is8==8)ans++;
    }
    cout << ans <<  endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)

K = int(input())

for i in [2,5]:
    if K%i==0:
        print(-1)
        exit()
t = 0
for i in range(K):
    t = (t*10+7)%K
    if t == 0:
        print(i+1)
        exit()
print(-1)

Measured memory_bytes: 9148
import sys
import random
import time
import numpy as np
import bisect

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def prob(e1,e2,T):
    if e2 < e1:
        return 1
    else:
        return np.exp((e1-e2)/T)

def solve():
    m = 26
    start = time.time()
    dT = 0.995
    T = 200
    D = ni()
    c = nl()
    s = [nl() for _ in range(D)]
    H = [None]*D
    for i in range(D):
        g = [s[i][j] + 25 * c[j] for j in range(m)]
        y = min(g)
        h = sum(g) - m * y
        g = [(x-y)/h for x in g]
        for j in range(1, m):
            g[j] += g[j-1]
        H[i] = g

    def calc(sche, m=26):
        last = [-1] * m
        ans = 0
        for i in range(D):
            t = sche[i]
            ans += s[i][t]
            last[t] = i
            for j in range(m):
                ans -= c[j] * (i - last[j])
        return ans

    def change(d, q, sc):
        b = sche[d]
        fq, bq = -1, D
        fb, bb = -1, D
        for i in range(d):
            if sche[i] == q:
                fq = i
            if sche[i] == b:
                fb = i
        for i in range(D-1, d, -1):
            if sche[i] == q:
                bq = i
            if sche[i] == b:
                bb = i
        sc += ((bb - d) * (bb - d - 1) // 2 + (d - fb) * (d - fb - 1) // 2) * c[b]
        sc += ((bq - fq) * (bq - fq - 1) // 2) * c[q]
        sc -= s[d][b]
        sc -= ((bq - d) * (bq - d - 1) // 2 + (d - fq) * (d - fq - 1) // 2) * c[q]
        sc -= ((bb - fb) * (bb - fb - 1) // 2) * c[b]
        sc += s[d][q]
        return sc

    sche = [0] * D
    for i in range(D):
        sche[i] = s[i].index(max(s[i]))
    sc = calc(sche)
    bestst = sche[:]
    best = sc

    while time.time() - start < 1.83:
        for _ in range(200):
            d = random.randint(0, D-1)
            q = bisect.bisect(H[d], random.random())
            nsc = change(d, q, sc)
            if best < nsc:
                bestst = sche[:]
                best = nsc
            if random.random() < prob(-sc, -nsc, T):
                sche[d] = q
                sc = nsc
        T *= dT
    prn([1 + x for x in bestst])
    return

solve()

Measured memory_bytes: 27332
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i128>();
    let (mut x, mut k, mut d) = (v[0].abs(), v[1], v[2]);
    if k * d < x {
        println!("{}", x - k * d);
        return;
    }
    let sub = x / d;
    k -= sub;
    x -= sub * d;
    assert!(x >= 0);
    if k % 2 == 0 {
        println!("{}", x.abs());
    } else {
        println!("{}", (d - x).abs());
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2172
#include <iostream>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  int N;
  cin >> N;
  vector<int> m(N+1, 0);

  int boss;
  rep(i, N-1) {
    cin >> boss;
    m[boss]++;
  }

  for(int i=1; i<=N; ++i) cout << m[i] << endl;

  return 0;
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }
  return 0; }
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return 1; }
  return 0; }

ll INF = 1000000007;
ll MAX = 200000;
ll fac[200001];
ll inv[200001],finv[200001];
ll facc[200001];
ll invv[200001],finvv[200001];

void solve(){
  fac[0] = fac[1] = 1;
  inv[1] = 1;
  finv[0] = finv[1] = 1;
  for(int i  =2; i <= MAX; i++){
    fac[i] = fac[i-1] * i %INF;
    inv[i] =INF - inv[INF%i]*(INF/i)%INF;
    finv[i] = finv[i-1]*inv[i]%INF;
  }
}

ll COM(ll n, ll k){
  if(n < k) return 0;
  if(n < 0 || k < 0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%INF)%INF;
}

int main(void){
  ll n,k; cin >> n >> k;
  ll red = n-k;
  solve();
  for(int i = 1; i <= k; i++){
    cout << COM(n-k+1,i)*COM(k-1,i-1)%INF << endl;
  }
  return 0;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<vector<int>> a(n,vector<int>(n));
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>a[i][j];
	vector<lli>  dp(1<<n);
	dp[0]=1;
	for(int i=0;i<n;i++){
		for(int mask=0;mask<(1<<n);mask++){
			if(num1bit(mask)!=i+1)continue;
			for(int j=0;j<n;j++){
				int x=(1<<j)&mask;
				if(((1<<j)&mask&&a[i][j])){
					dp[mask]=add(dp[mask^(1<<j)],dp[mask]);
				}
			}
		}
	}
	cout<<dp[(1<<n)-1]<<endl;


}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int unsigned long long

int gcd(int a,int b){
  if(a < b) swap(a,b);
  if(b == 0) return a;
  return gcd(b,a%b);
}

signed main(){

  int n, m; cin >> n >> m;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  int val = 1;
  for(int i = 0; i < n; i++){
    val = val * a[i] / gcd(val, a[i]);
    if(val > (int)1e20){
      cout << 0 << endl;
      return 0;
    }
  }

  int cnt = 0, t = a[0];
  while(t % 2 == 0){
    cnt++;
    t /= 2;
  }
  for(int i = 0; i < n; i++){
    int cnt2 = 0, t = a[i];
    while(t % 2 == 0){
      cnt2++;
      t /= 2;
    }
    if(cnt != cnt2){
      cout << 0 << endl;
      return 0;
    }
  }

  int left = 0, right = 1e9;
  while(right - left > 1){
    int mid = (left + right) / 2;
    ((double)val * (double)(mid + 0.5) <= (double)m ? left : right) = mid;
  }
  int ans = right;
  if(val > m * 2) ans = 0;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
inp = list(input())
s = []
for i in inp:
    if i == "0":
        s.append(i)
    if i == "1":
        s.append(i)
    if i == "B":
        if s == []:
            continue
        s.pop(-1)
n = ','.join(s)
n = n.replace(",", "")
print(n)


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

int main(void)
{
    string x,y,z;
    stringstream os;
    cin>>x>>y;
    z=x+y;
    os<<z;
    int t;
    os>>t;
    int s=int(sqrt(t*1.0));
    if(s*s==t)
    {
        cout <<"Yes"<<endl;
    }
    else
    {
        cout <<"No"<<endl;
    }
    return 0;
}


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

if K == 0:
    print(N**2)
    exit()

ans = 0
for b in range(1, N+1):
    p = N // b
    r = N % b
    ans += max(0, b-K) * p
    ans += max(0, r-K+1)

print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
const int N = 1e6 + 5;
const int mod = 1e9 + 7; 
using namespace std; 

int n, sum[N], f[N], ans; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin);
#endif
	n = read <int> (), f[0] = sum[0] = 1; 
	for(int res = 0, i = 1; i < n; i++)
	{
		if(i >= 3) res = (res + sum[i - 3]) % mod;
		f[i] = (res + 1) % mod, sum[i] = (sum[i - 1] + f[i]) % mod; 
	}
	f[n] = 1ll * (n - 1) * sum[n - 2] % mod, f[n] = (f[n] + 1) % mod; 
	for(int i = 0; i <= n; i++)
	{
		if(i + 2 <= n) ans = (1ll * f[i] * (n - 1) % mod * (n - 1) + ans) % mod;
		else if(i + 1 <= n) ans = (1ll * f[i] * (n - 1) + ans) % mod;
		else ans = (ans + f[i]) % mod; 
	}
	printf("%d\n", ans); 
	return 0; 
}


Measured memory_bytes: 10920