akhauriyash/Code-Regression huggingface dataset:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np
import bisect



def main():
	n,m,v,p=map(int,input().split())
	A=list(map(int,input().split()))
	A.sort(reverse=True)
	teki=A[p-1]
	
	ans=0
	cnt=1
	d=0
	
	for i in range(p,n):
		if A[i]+m<teki:break
		d+=cnt*(A[i-1]-A[i])
		if d>m*(n-v):break
		cnt+=1
		ans+=1
	print(p+ans)
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 12992
#include <iostream>

using namespace std;

int main(){
  int n,l;
  cin >> n >> l;
  
  int sum = n * l;
  for(int i=0; i < n; i++){
    sum += i;
  }
  
  int s = l;
  int e = l+n-1;
  
  if(s*e <= 0) cout << sum << endl;
  else if (s > 0) cout << sum - s << endl;
  else cout << sum - e  << endl;
  
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int N;
string s, t;
int mincost[16][1<<16];
int sbit, tbit;

struct State {
  int now, cost, bit;
  State(){}
  State(int now, int cost, int bit):now(now), cost(cost), bit(bit){}
  bool operator < (const State &st) const {
    return cost > st.cost;
  }
};

int dijkstra(int pos) {
  fill(mincost[0], mincost[16], inf);
  mincost[pos][sbit] = 0;
  priority_queue<State> que;
  que.emplace(pos, 0, sbit);
  while(!que.empty()) {
    State st = que.top(); que.pop();
    int now = st.now, cost = st.cost, bit = st.bit;
    //cout << now << " "<< cost << endl;
    //rep(i, N) cout << (int)((bit>>i)&1);
    //cout << endl;
    if(bit == tbit) return cost;
    if(mincost[now][bit] < cost) continue;
    rep(i, N) if(i != now) {
      int ncost = cost + abs(i-now);
      if(ncost < mincost[i][bit]) {
	mincost[i][bit] = ncost;
	que.emplace(i, ncost, bit);
      }
      if(((bit>>i)&1) == ((bit>>now)&1)) continue;
      int nbit = bit^(1<<i)^(1<<now);
      //rep(i, N) cout << (int)((bit>>i)&1);cout<<endl;
      //cout<<now<<" "<<i<<endl;
      //cout << (int)((bit>>i)&1) << " "<<(int)((bit>>now)&1) << endl;
      //cout<<(int)(((bit>>i)&1) == ((bit>>now)&1)) << endl;
      //rep(i, N) cout << (int)((nbit>>i)&1);cout<<endl;
      //assert(__builtin_popcount(nbit) == __builtin_popcount(bit));
      if(ncost < mincost[i][nbit]) {
	mincost[i][nbit] = ncost;
	que.emplace(i, ncost, nbit);
      }
    }
  }
  return inf;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> N, N) {
    cin >> s >> t;
    sbit = tbit = 0;
    rep(i, N) if(s[i] == 'B') sbit |= 1<<i;
    rep(i, N) if(t[i] == 'B') tbit |= 1<<i;
    int ans = inf;
    rep(i, N) {
      chmin(ans, dijkstra(i));
      //cout<<ans<<endl;//exit(0);
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 21180
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
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; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}

const vector<int> dx = {1,1,1,0,-1,-1,-1,0};
const vector<int> dy = {1,0,-1,-1,-1,0,1,1};

int main(){
  int H,W;
  cin >>H>>W;
  vector<string> s(H);
  rep(i,H) cin >>s.at(i);

  rep(i,H){
    rep(j,W){
      if(s.at(i).at(j) == '#'){
        continue;
      }else{
        int  num =0;
        rep(d,8){
          const int dy2 = i + dy.at(d);
          const int dx2 = j + dx.at(d);
          if(dy2 < 0 or dy2 >=H) continue;
          if(dx2 < 0 or dx2 >=W) continue;
          if(s.at(dy2).at(dx2) == '#') num++;
        }
        s.at(i).at(j) = char(num+'0');
      }
    }
  }

  rep(i,H) cout << s.at(i) << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <vector>
#include <iostream>
#include <string.h>
#include <cstring>
#include <algorithm>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

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

int main(){
	int n, m, x;
	int cnt_0 = 0;
	int cnt_n = 0;
	cin >> n >> m >> x;
	vector<int> a(m);
	REP(i, m){
		cin >> a[i];
		if(0 < a[i] && a[i] < x){
			cnt_0 += 1;
		}else if(x < a[i] && a[i] < n){
			cnt_n += 1;
		}
	}
	if (cnt_0 < cnt_n){
		cout << cnt_0 << "\n";
	}else {
		cout << cnt_n << "\n";
	}

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

	double ms, ml;

	while(cin >> ms >> ml) {
		if(ms<35.50)
			ms=0;
		else if(ms<37.50)
			ms=1;
		else if(ms<40.00)
			ms=2;
		else if(ms<43.00)
			ms=3;
		else if(ms<50.00)
			ms=4;
		else if(ms<55.00)
			ms=5;
		else if(ms<70.00)
			ms=6;
		else
			ms=7;
		if(ml<71.00)
			ml=0;
		else if(ml<77.00)
			ml=1;
		else if(ml<83.00)
			ml=2;
		else if(ml<89.00)
			ml=3;
		else if(ml<105.00)
			ml=4;
		else if(ml<116.00)
			ml=5;
		else if(ml<148.00)
			ml=6;
		else
			ml=7;

		if(ms<ml)
			ms=ml;

		switch((int)ms) {
			case 0:
				cout << "AAA" << endl;
				break;
			case 1:
				cout << "AA" << endl;
				break;
			case 2:
				cout << "A" << endl;
				break;
			case 3:
				cout << "B" << endl;
				break;
			case 4:
				cout << "C" << endl;
				break;
			case 5:
				cout << "D" << endl;
				break;
			case 6:
				cout << "E" << endl;
				break;
			case 7:
				cout << "NA" << endl;
				break;
		}

	}
	
	return 0;

}

Measured memory_bytes: 0
#!usr/bin/env python3
import math
import sys
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LIR(n):
    return [LI() for i in range(n)]

class SegmentTree:
    def __init__(self, size, f=lambda x,y : x+y, default=0):
        self.size = 2**(size-1).bit_length()
        self.default = default
        self.dat = [default]*(self.size*2)
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] = x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

    def get(self, a, b=None):
        if b is None:
            b = a + 1
        l, r = a + self.size, b + self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres)
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res

def solve():
    n,d,a = LI()
    g = LIR(n)
    g.sort()
    X = [i for (i,_) in g]
    s = SegmentTree(n)
    ans = 0
    for i in range(n):
        x = g[i][0]
        j = bisect.bisect_left(X,x-2*d)
        h = g[i][1]-s.get(j,i+1)
        if h <= 0:
            continue
        k = math.ceil(h/a)
        ans += k
        s.update(i,k*a)
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 133460
import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline


def array(size, init=0):
    return [[init for j in range(size[1])] for i in range(size[0])]


def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())


def nitti(x, y):
    count = 0
    for i in range(len(x)):
        if x[i] == y[i]:
            count += 1
    return count


S = input()
T = input()


lt = len(T)
res = 0
for i in range(0, len(S)-len(T)+1):
    res = max(res, nitti(S[i:(i+lt-1)], T))
    #print(i, S[i:(i+lt-1)], T)


print(lt-res-1)

Measured memory_bytes: 27136
#pragma warning(disable:4996)
#include <stdio.h>

int main()
{
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d); while (true)
    {
        c -= b;
        if (c <= 0)
        {
            printf("Yes"); break;
        }
        a -= d;
        if (a <= 0)
        {
            printf("No"); break;
        }
    }
	return 0;
}

Measured memory_bytes: 1732
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=min(a)+min(b)

for i in range(M):
    x,y,c=map(int,input().split())
    temp=a[x-1]+b[y-1]-c
    ans=min(ans,temp)

print(ans)

Measured memory_bytes: 18608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = ni(sc);
		int[] b = ni(sc);
		int k = sc.nextInt();
		long max = 0;
		for(int i=0;i<(1<<10);i++) {
			if (Integer.bitCount(i) > k) {
				continue;
			}
			int[] borrow = new int[11];
			int[] c = new int[10];
			for(int j=0;j<10;j++) {
				if (a[j] - borrow[j] >= b[j]) {
					c[j] = a[j] - borrow[j] - b[j];
					borrow[j+1] = 0;
				}else{
					c[j] = a[j] - borrow[j] + 10 - b[j];
					borrow[j+1] = (i&(1<<j)) > 0 ? 0 : 1;
				}
			}
			long ans = 0;
			for(int j=9;j>=0;j--) {
				ans *= 10;
				ans += c[j];
			}
			max = Math.max(max,ans);
		}
		System.out.println(max);
	}

	public static int[] ni(Scanner sc) {
		int[] a = new int[10];
		char[] c = sc.next().toCharArray();
		for(int i=0;i<c.length;i++) {
			a[i] = c[c.length-1-i] - '0';
		}
		return a;
	}

}

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

int main() {
  const int n = 5;
  vector<int> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  int k;
  cin >> k;
  cout << (arr[4] - arr[0] > k ? ":(" : "Yay!") << endl;
}


Measured memory_bytes: 256
H,W = list(map(int,input().split()))
board =[[' ' for i in range(W)] for j in range(H)]
for i in range(H):
    line = input()
    for j in range(W):
        board[i][j] = line[j]

count = 0
index = 0
while count < H:
    line = board[index]
    isWhite = True
    for i in range(len(line)):
        if line[i] == '#':
            isWhite = False
    if isWhite:
        board.pop(index)
    else:
        index += 1
    count += 1

count = 0
index = 0
while count < W:
    isWhite = True
    for i in range(len(board)):
        if board[i][index] == '#':
            isWhite = False
    if isWhite:
        for j in range(len(board)):
            board[j].pop(index)
    else:
        index += 1
    count += 1

for i in range(len(board)):
    line = board[i]
    lineString = ''
    for j in range(len(line)):
        lineString += line[j]
    print(lineString)

Measured memory_bytes: 9120
using System;
class Program{
	static int[] s,f=new int[3];
	static bool[] b;
	static long ans=long.MaxValue;
	static long[,] h;
	static void Main(){
		s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		h=new long[3,s[1]+1];
		long[][] arr=new long[s[1]+1][];
		for(int i=1;i<=s[1];i++){
			arr[i]=Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);
		}
		for(int i=0;i<s[0];i++){
			int[] q=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
			for(int j=0;j<s[0];j++){
				for(int k=1;k<=s[1];k++){
					h[(i+j)%3,k]+=arr[q[j]][k];
				}
			}
		}
		b=new bool[s[1]];
		fu1(0);
		Console.WriteLine("{0}",ans);
	}
	static void fu1(int a){
		for(int i=0;i<s[1];i++){
			if(!b[i]){
				f[a]=i+1;
				if(a==2){
					long o=h[0,f[0]]+h[1,f[1]]+h[2,f[2]];
					ans=Math.Min(ans,o);
				}
				else{
					b[i]=true;
					fu1(a+1);
					b[i]=false;
				}
			}
		}
	}
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n,m;
ll a[100100];

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

  cin>>n>>m;
  rep(i,n)cin>>a[i];

  ll crt=0;
  vector<ll> pos,neg;
  rep(i,n){
    crt+=abs(a[i]-i);
    pos.push_back(max(a[i],i));
    neg.push_back(min(a[i],i));
  }
  sort(all(pos));
  sort(all(neg)); reverse(all(neg));

  rep(i,m)crt+=max(0LL,-pos[i]+neg[i])*2;
  cout<<crt<<endl;

  return 0;
}



Measured memory_bytes: 5568
import math
n,m = map(int, input().split())
s = input()
t = input()

ans = int((n*m)/math.gcd(n,m))
g = math.gcd(n,m)
for i in range(g):
  if s[i*(n//g)] != t[i*(m//g)]:
    print (-1)
    exit()
print (ans)

Measured memory_bytes: 9224
import java.util.*;

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

		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();

		int[] t = new int[n + 1];
		for (int i = 0; i < n - 1; i++) {
			// 2文字切り出して"AC"なら+1
			t[i + 1] = t[i] + (s.substring(i, i + 2).equals("AC") ? 1 : 0);
		}
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			l--;
			r--;
			int ans = t[r] - t[l];
			System.out.println(ans);
		}

		sc.close();
	}
}


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

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

	bool res = true;
	if(s.at(2) != s.at(3)) res = false;
	if(s.at(4) != s.at(5)) res = false;

	if(res) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


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

ball_list = [1 for i in range(N)]
flag_list = [False for i in range(N)]
flag_list[0] = True

for i in range(M):
    x,y = list(map(int,input().split()))
    if flag_list[x-1]:
        flag_list[y-1]=True
        if ball_list[x-1]==1:
            flag_list[x-1]=False
    ball_list[x-1]-=1
    ball_list[y-1]+=1
count=0    
for i in range(N):
    if flag_list[i]:
        count+=1

print(count)

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

input()
numbers = tuple(map(int, input().split()))

evenNumberToCount = dict()

oddNumberToCount = dict()

for i, n in enumerate(numbers):
    if i % 2 == 0:
        evenNumberToCount[n] = evenNumberToCount.get(n, 0) + 1
    else:
        oddNumberToCount[n] = oddNumberToCount.get(n, 0) + 1

evenCountToNumber = list()
for n, i in evenNumberToCount.items():
    evenCountToNumber.append((i, n))
evenCountToNumber.sort(reverse=True)

oddCountToNumber = list()
for n, i in oddNumberToCount.items():
    oddCountToNumber.append((i, n))
oddCountToNumber.sort(reverse=True)

if oddCountToNumber[0][1] == evenCountToNumber[0][1]:
    if len(numbers) // 2 == oddCountToNumber[0][0] == evenCountToNumber[0][0]:
        print(len(numbers) // 2)
    elif oddCountToNumber[0][0] < evenCountToNumber[0][0]:
        print(len(numbers) - oddCountToNumber[1][0] - evenCountToNumber[0][0])
    elif oddCountToNumber[0][0] > evenCountToNumber[0][0]:
        print(len(numbers) - oddCountToNumber[0][0] - evenCountToNumber[1][0])
    else:
        first = len(numbers) - oddCountToNumber[0][0] - evenCountToNumber[1][0]
        second = len(numbers) - oddCountToNumber[1][0] - evenCountToNumber[0][0]
        print(min(first, second))
else:
    print(len(numbers) - oddCountToNumber[0][0] - evenCountToNumber[0][0])


Measured memory_bytes: 20380
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for_each(begin(A), end(A), [](auto& x) { cin >> x; });

  ll ans = 100100100100100;
  for (ll i = 0; i < 100; i++) {
    ll sum = 0;
    for (const auto& x : A) {
      sum += (x - i) * (x - i);
    }
    ans = min(ans, sum);
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map<int,pair<int,long long> > mp;
long long a[200005];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	long long N;
	cin>>N;
	for(long long i=0;i<N;i++)
	{
		cin>>a[i];
		mp[a[i]].first++;
		long long r=mp[a[i]].first;
		mp[a[i]].second=r*(r-1)/2;
	}
	long long res=0;
	map<int,pair<int,long long> >::iterator it=mp.begin();
	for(;it!=mp.end();it++)
	{
		res+=it->second.second;
	}
	for(long long i=0;i<N;i++)
	{
		pair<int,long long> orin=mp[a[i]];
		mp[a[i]].first--;
		long long v=mp[a[i]].first;
		mp[a[i]].second=v*(v-1)/2;
		long long ans=res-(orin.second-mp[a[i]].second);
		cout<<ans<<endl;
		mp[a[i]]=orin;
	}
	return 0;
}

Measured memory_bytes: 11136
def exchange(n, s, d):
  v = [n] * (n + 1)
  r = [(1, 1)] + [(a, b) for a, b in zip(s, d) if a < b]

  for i in range(len(v) - 1):
    for a, b in r:
      if i + a < len(v):
        v[i + a] = max(v[i] - a + b, v[i + a])

  return v[-1]


def main():
  n = int(input())
  a = list(map(int, input().split()))
  b = list(map(int, input().split()))

  n = exchange(n, a, b)
  n = exchange(n, b, a)

  print(n)


if __name__ == '__main__':
  main()


Measured memory_bytes: 230296
using Printf

function f(a,b,θ)
    c = b*tan(θ)
    if c > a
        return (1+(c-a)/c)*b*a*a/2
    else
        return c*b*a/2
    end
end

function solve()
    A,B,X = parse.(Float32,split(readline()))
    lo = .0; hi = π/2
    for _ in 1:50
        θ = (lo+hi)/2
        f(A,B,θ) <= X ? lo=θ : hi=θ
    end
    @printf("%.9f\n", rad2deg(π/2-lo))
end
solve()

Measured memory_bytes: 211960
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[list(map(int,input().split())) for i in range(n)]
ans=0
cal=0
for j in range(n):
  for k in range(m):
    cal+=a[j][k]*b[k]
  if cal+c>0:
    ans+=1
  cal=0
print(ans)


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

int main(){
  int n,weight;

  cin >> n >> weight;

  int v[n],w[n];

  int dp[n+1][weight+1];

  for(int i=0; i<n; i++){
    cin >> v[i] >> w[i];
  }

  for(int i=0; i<weight+1; i++){
    dp[0][i] = 0;
  }

  for(int i=1; i<n+1; i++){
    for(int j=0; j<weight+1; j++){
      if(j<w[i-1]){
        dp[i][j] = dp[i-1][j];
      }

      else{
        dp[i][j] = max(dp[i-1][j] , dp[i-1][j-w[i-1]] + v[i-1]);
      }
    }
  }

  cout << dp[n][weight] << endl;

  return 0;
}

Measured memory_bytes: 7048
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

char dat3[3][4] = {
"aa.",
"..b",
"..b"};
char dat4[4][5] = {
"aabc",
"ddbc",
"efgg",
"efhh"};
char dat5[5][6] = {
"aabbc",
"d.e.c",
"dfe..",
"gf.hh",
"giijj"};
char dat6[6][7] = {
"ab..cc",
"ab..dd",
"eefg..",
"hhfg..",
"..iijk",
"..lljk"};
char dat7[7][8] = {
"aa.bb.c",
"..d..ec",
"f.d..e.",
"fgg.h..",
"...ihjj",
"k..i.ll",
"kmmnn.."};

char ret[1005][1005];
int n;
int main()
{
	scanf("%d", &n);
	if(n == 1 || n == 2) {
		printf("-1\n");
		return 0;
	}
	rep(i, n) rep(j, n) ret[i][j] = '.';
	if(n % 3 == 0) {
		for(int cur = 0; cur < n; cur += 3) rep(i, 3) rep(j, 3)
		ret[cur + i][cur + j] = dat3[i][j];
	} else {
		int cur = n;
		while(cur >= 9) {
			cur -= 6;
			rep(i, 6) rep(j, 6) ret[cur + i][cur + j] = dat6[i][j];
		}
		if(cur == 8) {
			rep(i, 4) rep(j, 4) ret[i][j] = ret[4 + i][4 + j] = dat4[i][j];
		} else {
			if(cur == 7) rep(i, 7) rep(j, 7) ret[i][j] = dat7[i][j];
			else if(cur == 5) rep(i, 5) rep(j, 5) ret[i][j] = dat5[i][j];
			else if(cur == 4) rep(i, 4) rep(j, 4) ret[i][j] = dat4[i][j];
		}
	}
	rep(i, n) printf("%s\n", ret[i]);
	return 0;
}

Measured memory_bytes: 2176
n = int(input())

ans = 0
count = 0

a, b, c = 1, 1, 1

while a <= n:

    # print("A : {0}".format(a))
    # print("追加パターン : {0}".format( (n // a) ))

    if a == 1 :
        ans =  ans + ( (n // a) - 1)
    else :

        if n // a == 1 :
            ans = ans + 1
        else :

            if n % a == 0 :
                ans = ans + ( (n // a) - 1)
            else :
                ans = ans + ( (n // a) )

            



    # if n % a == 0 :
    #     ans = ans + ( (n / a) - 1 )
    # else :
    #     ans = ans + ( (n // a) - 1 )

    # ans = ans + (n / a) - 1

    # print("A : {0}".format(a))

    # while a * b < n:

    #     print("B : {0}".format(b))

    #     ans += 1

    #     b += 1
    #     c = 1

    a += 1
    b, c = 1, 1

# print("計算実行回数 : {0}".format(count))
print(ans - 1)

Measured memory_bytes: 9120
class priorityQueue {
  constructor() {
    this.keys = [];
    Number.prototype.parentIdx = function() { return Math.ceil(this/2 - 1); };
    Number.prototype.leftIdx = function() { return this * 2 + 1; };
    Number.prototype.rightIdx = function() { return this * 2 + 2; };
  }

  insert(key) { this.heapIncrease(this.keys.push(key) - 1); }

  heapIncrease(idx) {
    const keys = this.keys;
    for (let i=idx, p=idx.parentIdx(); i > 0 && keys[i] > keys[p]; i=p, p=i.parentIdx()) {
      keys[p] = [keys[i], keys[i] = keys[p]][0];
    }
  }

  extract() {
    const res = this.keys[0];
    this.keys[0] = this.keys.pop();
    this.maxHeapify(0);
    return res;
  }

  maxHeapify(idx) {
    const keys = this.keys, n = keys.length;
    const innerMaxHeapify = (i) => {
      let left, right, largest = i;
      left = i.leftIdx();
      right = i.rightIdx();
      if (left < n && Number(keys[left]) > Number(keys[largest])) largest = left;
      if (right < n && Number(keys[right]) > Number(keys[largest])) largest = right;
      if (largest != i) {
        keys[largest] = [keys[i], keys[i] = keys[largest]][0];
        innerMaxHeapify(largest);
      }
    };
    innerMaxHeapify(idx);
  }
}

(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  lines.pop();
  const queue = new priorityQueue();
  let str = '';
  lines.forEach(function(cmd) {
    switch(cmd.charAt(0)) {
      case 'i': queue.insert(Number(cmd.split(' ')[1])); break;
      case 'e': str += `${queue.extract()|0}\n`; break;
    }
  });
  process.stdout.write(str);
})();




Measured memory_bytes: 203968
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int y = scanner.nextInt()/1000;
        boolean b = true;
        for (int i=0;i<=n;i++){
            for (int j=0;j<=n-i&&b;j++){
                if (9*i+4*j+n==y){
                    System.out.println(i+" "+j+" "+(n-i-j));
                    b = false;
                }
            }
        }
        if (b){
            System.out.println("-1 -1 -1");
        }




    }

}


Measured memory_bytes: 23124
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<math.h>
#include <cstdio>
#include<iomanip>
#include <stdio.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int inf = 10e9 + 7;
using namespace std;

signed main() {
	int n, m;
	cin >> n >> m;
	if (abs(n - m) <= 1)puts("Brown");
	else puts("Alice");
}	

Measured memory_bytes: 256
#include "cstdio"
#include "cstring"
#include "cstdlib"
#include "cmath"
#include "iostream"
#include "algorithm"
using namespace std;
int main(int argc, char const *argv[])
{
    char s[12];
    cin >> s;
    if (s[0] == s[1]) printf("No\n");
    else if (s[0] == s[2]) printf("No\n");
    else if (s[1] == s[2]) printf("No\n");
    else printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353
using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

llint n;
llint h[5005], p[5005];
P a[5005];
llint dp[5005][5005];

int main(void)
{

	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> h[i] >> p[i];
		a[i] = P(h[i]+p[i], i);
	}
	sort(a+1, a+n+1);
	
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			dp[i][j] = inf;
		}
	}
	dp[0][0] = 0;
	
	for(int i = 0; i < n; i++){
		llint id = a[i+1].second;
		for(int j = 0; j <= n; j++){
			chmin(dp[i+1][j], dp[i][j]);
			if(h[id] >= dp[i][j]) chmin(dp[i+1][j+1], dp[i][j]+p[id]);
		}
	}
	
	for(int i = n; i >= 0; i--){
		if(dp[n][i] < inf/2){
			cout << i << endl;
			return 0;
		}
	}
	
	return 0;
}


Measured memory_bytes: 195968
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n;
  cin >> n;
  vector <ll> v(n);
  vector<vi> bit(62, vi(2));
  for(ll& x : v){
    cin >> x;
    for(int i = 0; i < 61; i++){
      if((1ll << i) & x) bit[i][1]++;
      else bit[i][0]++;
    }
  }
  int res = 0;
  for(ll x : v){
    for(int i = 0; i < 61; i++){
      if((1ll << i) & x){
        res = add(res, mul((1ll << i) % mod, bit[i][0]));
        bit[i][1]--;
      }
      else{
        res = add(res, mul((1ll << i) % mod, bit[i][1]));
        bit[i][0]--;
      }
    }
  }
  cout << res;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,count = 0;
  cin>>n;
  int h[n];
  for(int i=0;i<n;++i){
    cin>>h[i];
  }
  for(int i=0;i<n;++i){
    int f=0;
    if(i!=0){
    for(int j=0;j<i;++j){
      if(h[i]<h[j]){
        f=1;
      }
    }
  }
    if(f==0){
      count++;
    }
  }
  cout<<count;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	while(true){
		int aizu_ckn = 0, ckn = 0;
		int q1,q2,b,c1,c2;
		cin>>q1;
		if(q1==0)
			break;
		cin>>b>>c1>>c2>>q2;

		aizu_ckn=b/c1;
		if(aizu_ckn>q2)
			aizu_ckn=q2;
		b-=aizu_ckn*c1;
		if(aizu_ckn+ckn<q1){
			ckn=q1-aizu_ckn;
			b-=ckn*c2;
			if( b<0 ){
				if(c1<=c2){
					cout<<"NA\n";
					continue;
				}
				int change=-b/(c1-c2)+1;
				aizu_ckn-=change;
				if(aizu_ckn<1){
					cout<<"NA\n";
					continue;
				}
				ckn+=change;
				b+=change*(c1-c2);
			}
		}
		if(b>0)
			ckn+=b/c2;

		if( b<0||aizu_ckn<1 )
			cout<<"NA\n";
		else
			cout<<aizu_ckn<<' '<<ckn<<endl;
	}
	return 0;
}

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


int main(){

  int i;
  char x;
  int ans;

  cin >> i;
  cin >> x;
  ans = i;
  while(1){
    if(x == '='){
      cout << ans << endl;
      break;
    }
    cin >> i ;
    if(x == '+') ans += i;
    if(x == '-') ans -= i;
    if(x == '*') ans *= i;
    if(x == '/') ans /= i;
    cin >> x;
  }

  return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<vector>
#define LL long long
LL W, H;
LL SW, SH[100010];
std::vector<LL> PW, PH;
LL ans;
int main() {
	std::cin >> W >> H;
	for (int i = 0; i < W; i++) {
		LL tmp;
		std::cin >> tmp;
		SW += tmp;
		PW.emplace_back(tmp);
	}
	for (int i = 0; i < H; i++) {
		LL tmp;
		std::cin >> tmp;
		PH.push_back(tmp);
	}
	std::sort(PW.begin(), PW.end());
	std::sort(PH.begin(), PH.end());
	for (int i = 1; i <= H; i++) {
		SH[i] += SH[i - 1] + PH[i - 1];
	}
	ans += SW + SH[H];
	for (int i = 0; i < W; i++) {
		auto it = std::upper_bound(PH.begin(),PH.end(),PW[i]);
		LL K = it - PH.begin();
		ans += SH[K] + PW[i] * (H - K);
	}
	std::cout << ans << std::endl;
	return 0;
}

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

int main(){

    int h[10];
    int i,j,maxh;
    int max[3];
    
    for(i=0;i<3;i++)max[i]=0;
    
    for(i=0;i<10;i++){
        cin>>h[i];
    }
    
    for(i=0;i<10;i++){
        if(h[i]>max[0]){
            maxh=i;
            max[0]=h[i];
        }
    }
    for(i=maxh;i<10;i++){
        h[i]=h[i+1];
    }
    
    for(i=0;i<9;i++){
        if(h[i]>max[1]){
            maxh=i;
            max[1]=h[i];
        }
    }
    for(i=maxh;i<9;i++){
        h[i]=h[i+1];
    }
    
    for(i=0;i<8;i++){
        if(h[i]>max[2]){
            maxh=i;
            max[2]=h[i];
        }
    }
    for(i=maxh;i<8;i++){
        h[i]=h[i+1];
    }
    for(i=0;i<3;i++){
        cout<<max[i]<<endl;
    }
    
    return 0;
    
}

Measured memory_bytes: 3100
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int main(){
  string a,b;
  cin >> a >> b;
  if (a[0]==b[2]&& a[1]==b[1]&& a[2]==b[0]) {
  cout << "YES" << endl;
  } else {
  cout << "NO" << endl;
  
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int ta[10];
bool dfs(int h,int a,int b){
	if(h==10)return true;
	int now=ta[h];
	bool ret=0;
	if(now>a)ret=dfs(h+1,now,b);
	if(now>b)ret=dfs(h+1,a,now);
	return ret;
}

int main(){
	int n;
	cin>>n;
for(int i=0;i<n;i++){
for(int i=0;i<10;i++)cin>>ta[i];
(dfs(0,0,0))?cout<<"YES"<<endl:cout<<"NO"<<endl;
}
	return 0;
}

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

using namespace std;
using ll = long long;

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22)
        cout << "bust" << endl;
    else
        cout << "win" << endl;

    return 0;
}

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

using namespace std;

int N;
long long int K;
vector<int> A;
vector<int> F;


long long int search(long long int left, long long int right) {

    if (left == right) {
        return left;
    }

    long long int mid = floor((left + right) / 2.0l);
    long long int total_fix = 0.0l;

    for(int i = 0; i < A.size(); i++) {
        if (A[i] * F[i] > mid) {
            total_fix += A[i] - floor(mid / F[i]);
        }
    }

    if (total_fix > K) {
        return search(min(mid + 1, right), right);
    }
    else {
        return search(left, mid);
    }
}


int main(int argc, char** argv) {
    cin >> N >> K;
    A.resize(N);
    F.resize(N);

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

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

    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<int>());
    long long int ans = search(0, 1e12l);
    cout << ans << endl;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
typedef long long ll;
#define FOR(i,n) for(int i=0;i<n;i++)

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main(){
  int n;
  cin >> n;
  vector<pair<int,int> > p(n);
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    p[i] = make_pair(i+1,a);
  }
  //for(int i=0;i<n;i++){
    //cout << p[i].first << p[i].second << "\n";
  //}
  sort(p.begin(), p.end(), compare_by_b);
    //for(int i=0;i<n;i++){
    //cout << p[i].first << p[i].second << "\n";
  //}
  for(int i=0;i<n;i++){
    cout << p[i].first << " ";
  }
  return 0;
}


Measured memory_bytes: 1536
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());
function main(chunk){
    
    var map = {};
    for(var i=65;i<65+26;i++){
        map[String.fromCharCode((i+3-65)%26+65)] = String.fromCharCode(i);
    }
    
    var ans = "";
    for(var i=0;i<chunk.length;i++){
        ans += map[chunk[i]];
    }
    console.log(ans);
    
}

Measured memory_bytes: 15492
card = [input().split() for i in range(3)]
N = int(input())
idx = [0, 1, 2]
# カードに穴を開ける
for i in range(N):
    tmp = str(input())
    for i in idx:
        if tmp in card[i]:
            card[i][card[i].index(tmp)] = "x"

# ビンゴの数を数える
is_True = False
d = {0: 0, 1: 0, 2: 0}
diago_r = {0: 0, 1: 0, 2: 0}
diago_l = {2: 0, 1: 0, 0: 0}


# １回目チェック
for j in idx:  # 段
    if card[j].count("x") == 3:
        is_True = True
        break
# ２回目チェック
for j in idx:  # 段
    for k in idx:  # 列
        if card[j][k] == "x":
            d[k] += 1
            if j == 0 and (k == 0 or k == 2):
                if k == 0:
                    diago_r[0] += 1
                else:
                    diago_l[2] += 1
            elif j == 1 and k == 1:
                diago_r[1] += 1
                diago_l[1] += 1
            elif j == 2 and (k == 0 or k == 2):
                if k == 0:
                    diago_l[0] += 1
                else:
                    diago_r[2] += 1

if is_True:
    pass
else:
    for a in d.values():
        if a == 3:
            is_True = True
        elif diago_r[0] == diago_r[1] == diago_r[2] == 1:
            is_True = True
        elif diago_l[0] == diago_l[1] == diago_l[2] == 1:
            is_True = True

if is_True:
    print("Yes")
else:
    print("No")


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

inline int read()
{
	int x=0;int f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int main(int argc, char const *argv[])
{
	string a,b;
	cin>>a>>b;
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	reverse(b.begin(), b.end());
	if (a<b)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
row = input()
row = list(row)
row = list(map(int, row))
Flag = False
for i in range(2):
    for j in range(2):
        for k in range(2):
            sum = row[0]
            if i == 0:
                op1 = "+"
                sum += row[1]
            else:
                op1 = "-"
                sum -= row[1]
            if j == 0:
                op2 = "+"
                sum += row[2]
            else:
                op2 = "-"
                sum -= row[2]   
            if k == 0:
                op3 = "+"
                sum += row[3]
            else:
                op3 = "-"
                sum -= row[3]  
            if sum == 7:
                Flag = True
                break
        if Flag:
            break
    if Flag:
        break

print(row[0],op1,row[1],op2,row[2],op3,row[3],"=7", sep="")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
using ll = long long;
int MOD = 1e9 + 7;
using namespace std;
ll GCD(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    else
    {
        return GCD(y, x % y);
    }
}
ll LCM(ll x, ll y)
{
    return x / GCD(x, y) * y;
}
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
//使い方　インスタンス化(頂点数)　uniteつなぐ(双方向注意) same判定
int main()
{
    string s;
    cin >> s;
    ll k;
    cin >> k;
    vector<int> reg(s.size());
    for (int i = 0; i < s.size();i++){
        reg[i] = 'z' - s[i] + 1;
    }
    for (int i = 0; i < s.size()-1; i++)
    {
        if(reg[i]==26)
            continue;
        if(reg[i]<=k){
            s[i] = 'a';
            k -= reg[i];
        }
        if(k==0)
            break;
    }
    k %= 26;
    for (int i = 0; i < s.size()-1;i++){
        cout << s[i];
    }
    if(k>0){
        ll x = (s[s.size() - 1] -'a'+ k) % 26+'a';
        cout << (char)(x) << endl;
    }else{
       // cout << "jkldfj" << endl;
        cout << s[s.size() - 1] << endl;
    }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define lowbit(x) (x&-x)
const ll INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const double EPS=1e-7;
const int N=1e6+10;
const ll mod=998244353;
const ll MOD=998244353;
inline ll read()  
{  ll f=1,x=0;char ch=getchar();
   for(;ch>'9'||ch<'0';ch=getchar())if(ch=='-') f=-1;
   for(;ch<='9'&&ch>='0';ch=getchar())x=(x<<3)+(x<<1)+(ch^48);
   return x*f;
}
ll n;
ll a[N];
void solve()
{  cin>>n;
   ll ans=0;
   for(int i=1;i<=n;i++)cin>>a[i];
   for(int i=2;i<=n;i++)
   {  if(a[i]<a[i-1])ans=ans+a[i-1]-a[i],a[i]=a[i-1];
   }
   printf("%lld\n",ans);
}
int main()
{  int t=1;
   while(t--)  
   {  
      solve();
   }
}

Measured memory_bytes: 5208
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s;
int main() {
  cin >> s;
  
  int mn = 19999;
  for (int i = 2; i < s.size(); ++i) {
    int a = s[i - 2] - '0';
    int b = s[i - 1] - '0';
    int c = s[i] - '0';

    int p = a * 100 + b * 10 + c;
    mn = min(mn, abs(p - 753)); 
  }
  cout << mn << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    long long X; cin>>X;
    long long sum=0;
    if(X/500!=0){
        sum+=(X/500)*1000;
        X-=(X/500)*500;
    }
    if(X/5!=0)
        sum+=(X/5)*5;
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

template <class T>
T gcd(T m, T n) {
  if (n > m) {
    std::swap(m, n);
  }
  if (n <= 0) {
    return m;
  }
  return gcd(n, m % n);
}

template <class T>
T lcm(T a, T b) {
  return a * b / gcd(a, b);
}

template <class T>
std::pair<T, T> gcdlcm(T a, T b) {
  T const g = gcd(a, b);
  T const l = a * b / g;
  return std::make_pair(g, l);
}

int64_t solve(int64_t n, int64_t m, std::string s, std::string t) {
  if (s[0] != t[0]) {
    return -1;
  }
  auto const gl = gcdlcm(n, m);
  auto const g = gl.first;
  auto const l = gl.second;
  auto const sa = n / g;
  auto const ta = m / g;
  auto i = sa;
  auto j = ta;
  while (i < s.size() && j < t.size()) {
    if (s[i] != t[j]) {
      return -1;
    }
    i += sa;
    j += ta;
  }
  return l;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t n;
  std::cin >> n;
  int64_t m;
  std::cin >> m;
  std::string s;
  std::cin >> s;
  std::string t;
  std::cin >> t;
  auto const res = solve(n, m, s, t);
  std::cout << res << std::endl;
  return 0;
}


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

const int VMAX = 10000 + 1;
const int MAX = 1000;
int s;
int W[MAX];
int B[MAX], T[VMAX];

int solve(int n) {
  int ans {0};
  bool V[MAX];

  for (int i = 0; i < n; i++) {
    B[i] = W[i];
    V[i] = false;
  }

  sort(B, B+n);
  for (int i = 0; i < n; i++) T[B[i]] = i;

  for (int i = 0; i < n; i++) {
    int currrent_index = i;
    int S = 0;
    int m = VMAX;
    int an = 0;
    if ( V[i] ) continue;
    while (true) {
      V[currrent_index] = true;
      an++;
      int v = W[currrent_index];
      m = min(m, v);
      S += v;
      currrent_index = T[v];
      if (V[currrent_index]) break;
    }
    ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
  }
  return ans;
}

int main() {
  int n {0};
  cin >> n;
  s = VMAX;
  for (int i = 0; i < n; i++) {
    cin >> W[i];
    s = min(s, W[i]);
  }
  int ans = solve(n);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3164
/*{{{*/
#include <bits/stdc++.h>
#define st first
#define nd second
#ifdef LOCAL
int c_;
#define cout (c_?cerr:cout)
#define debug(...) {cerr<<(!c_?"\033[96;1m":"");\
++c_;__VA_ARGS__;--c_;cerr<<(!c_?"\033[0m":"");}
#else
#define debug(...) {}
#endif
#define st first
#define nd second
#define dump_range(...) debug(cerr<<#__VA_ARGS__<<": ";print_range(__VA_ARGS__))
#define all(...) (__VA_ARGS__).begin(), (__VA_ARGS__).end()
#define dump(...) debug(print(#__VA_ARGS__,'=',__VA_ARGS__))
using namespace std; using ll = long long;
template< typename... t > using V = vector< t... >;
void print(){cout << '\n';}
template< typename t, typename... v >
void print(const t& a, const v&... b)
{cout << a << (sizeof...(b)?" ":"");print(b...);}
int argc_; char** argv_;
template< typename t > 
void print_range(t a, const t& b)
{while (a != b) cout << (*a++) << ' '; cout << '\n';}
/*thread_local mt19937 gen;
inline ll arg(int v, ll def = 0)
{return v < argc_? atoll(argv_[v]) : def;}
template< typename t >
t rng(t min, t max) 
{return uniform_int_distribution< t >{min, max}(gen);}*/
/*}}}*/

int main(int argc, char** argv)
{
    argc_ = argc; argv_ = argv;
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //gen = mt19937(arg(1));
    
    int a, b, c; cin >> a >> b >> c;

    c = min(a + b + 1, c);

    print(c + b);
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);
    vector<int> x(M), y(M), c(M);
    REP(i, A) cin >> a[i];
    REP(i, B) cin >> b[i];
    REP(i, M) cin >> x[i] >> y[i] >> c[i];

    int ans = 1e9;
    REP(i, M) {
        int tmp = a[x[i]-1] + b[y[i]-1] - c[i];
        if(ans > tmp) ans = tmp;
    }

    sort(ALL(a));
    sort(ALL(b));
    if(ans > a[0] + b[0]) ans = a[0] + b[0];
    cout << ans << endl;

    return 0;
}

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

using namespace std;

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define double long double
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define deb(x) cout << x << endl
#define done(x) {cout << x << endl;return;}
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;


const int N = 2e5 + 5;


int powm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = (res*a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}


int divide(int a, int b) {
    return (a % mod) * powm(b, mod - 2) % mod;
}


void solve() {
  
  int n,k,pos=0,ans=1,prev1=-1,prev2=-1,sign=1;
  cin>>n>>k;
  vi a(n);
  rep(i,0,n)
    cin>>a[i], pos|=(a[i]>0);
  if(k==n||!pos){
    if(k&1)
    sort(all(a), greater<>());
    else
     sort(all(a));
    rep(i,0,k)
      ans=ans*abs(a[i])%mod, sign^=(a[i]<0);
    cout<<(sign?ans:(mod-ans)%mod);
    return;
  }
  priority_queue<pii> pq;
  rep(i,0,n)
    pq.push({abs(a[i]),i});
  rep(i,0,k){
    pii p = pq.top();
    pq.pop();
    ans=ans*p.fi%mod;
    if(a[p.se]<0)
      sign^=1,prev2=p.fi;
    else if(a[p.se]>0)
       prev1=p.fi;
    else{
      cout<<0;
      return;
    }
  }
  vpii x;
  if(!sign){
    while(sz(pq)&&(prev1!=-1||prev2!=-1)){
      pii p = pq.top();
      pq.pop();
      if(a[p.se]<0){
        if(prev1!=-1)
          x.pb({p.fi,prev1});
        prev1=-1;
      }else if(a[p.se]>0){
        if(prev2!=-1)
        x.pb({p.fi,prev2});
        prev2=-1;
      }else if(!sz(x)){
         cout<<0<<endl;
         return;
      }
     }
  }
  if(sz(x)==1)
    ans=divide(ans,x[0].se)*x[0].fi%mod;
  else if(sz(x)==2){
     int in = x[1].fi*x[0].se>x[0].fi*x[1].se;
     ans=divide(ans,x[in].se)*x[in].fi%mod;
  }
  cout<<ans<<endl;
    
  
   
          
}


signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(15);
    int t = 1;
    //cin >> t;

    while (t--)
        solve();
#ifdef aa
    cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}





int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}


int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}


Measured memory_bytes: 8908