akhauriyash/Code-Regression huggingface dataset:
def main(N,A,B):
    # type: (int, int, int) -> None
    sumDigit = lambda x: sum(map(int,list(str(x)))) # type: Callable[[int],int]
    print(sum([x for x in range(1,N+1) if A <= sumDigit(x) <= B]))
    return

if __name__ == '__main__':
    N,A,B,*_ = map(int,input().split())
    main(N,A,B)


Measured memory_bytes: 3296
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int32_t N,K;
std::pair<int64_t, int64_t> P[50];
int64_t arr[50];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>K;
	for (int32_t i = 0; i < N; i++)
	{
		in >> P[i].first>>P[i].second;
	}
	int64_t min = 5000000000000000000;
	for (int32_t xm = 0; xm < N; xm++)
		for (int32_t xma = 0; xma < N; xma++)
			for (int32_t ymin = 0; ymin < N; ymin++)
	{
		;
		auto iter = arr;
		for (int32_t i = 0; i < N; i++)
		{
			if (P[xm].first <= P[i].first && P[i].first <= P[xma].first && P[ymin].second <= P[i].second) {
				*iter++ = P[i].second;
			}
		}
		if (iter - arr < K) {
			continue;
		}
		std::sort(arr, iter);
		min = std::min((P[xma].first - P[xm].first) * (arr[K-1] - P[ymin].second),min);
	}
	out << min << endl;
	return 0;
}
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
const int N = 1e5, M = 7 + 1e9;
int n;
ll dp[N][2];
vector<int> g[N];
ll DFS(int u, int p, bool c){  
	ll &ret = dp[u][c];
	if(~ret)
		return ret;
	ret = 1;
	f(i, 0, g[u].size()){
		if(g[u][i] != p){
			ll val = DFS(g[u][i], u, 0);
			if(c == 0)
				val += DFS(g[u][i], u, 1);
			val %= M;
			ret *= val;
			ret %= M;
		}
	}
	return ret;
}
int main()
{
	memset(dp, -1, sizeof dp);
	cin >> n;
	for(int i=0, u, v; i<n-1; ++i){
		cin >> u >> v;
		u--, v--;
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	cout << (DFS(0, -1, 0) + DFS(0, -1, 1))%M;
}

Measured memory_bytes: 17024
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
#define mod 1000000007
ll t,n,m,i,j,k,l,arr[sz],brr[sz],crr[sz],d,r;
vector<ll>v;
int main()
{
    scanf("%lld %lld %lld",&l,&r,&d);
    t=(l-1)/d;
    n=r/d;
    printf("%lld\n",n-t);

    return 0;
}



Measured memory_bytes: 3824
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		int m = 55555;
		BitSet p = new BitSet(55556);
		
		for(int i = 2 ; i <= m ;i++) {
			for(int j = 2 ; j <= Math.sqrt(i) ; j++) {
				if(i % j == 0) {
					p.set(i);
				}
			}
		}
		List <Integer> L = new ArrayList<Integer>();
		
		for(int i = 2 ; i <= m ;i++) {
			if(!p.get(i)) {
				L.add(i);
			}
		}
		int []prime = new int [L.size()];
		int []num = new int [5];
		int N = L.size();
		
		for(int i = 0 ;i < N;i++) {
			prime[i] = L.get(i);
			num[(prime[i]%5)]++;
 		}
	
		int max = 0; 
		int index = 0;
		
		int cnt = 0;
		for(int i = 0 ; i < N ;i++) {
			if(prime[i] % 5 == 1) {
				System.out.println(prime[i]);
				cnt++;
			}
			if(cnt == n) {
				return;
			}
		}
	}

}


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

int main() {
    int n;
    cin >> n;
    cout << 0 << endl;
    string s1;
    cin >> s1;
    if (s1 == "Vacant") return 0;

    int l = 0, r = n;
    while (true) {
        int m = (l + r) / 2;
        cout << m << endl;

        string s;
        cin >> s;
        if (s == "Vacant") return 0;

        if (m % 2 == 1 && s != s1 || m % 2 == 0 && s == s1)
            l = m + 1;
        else
            r = m;
    }

    return 0;
}


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

bool circular(string s) {
  int N = s.size();
  bool ok = true;
  for (int i = 0; i < N; i++) {
    if (s.at(i) != s.at(N-1-i)) {
      ok = false;
      break;
    }
  }
  return ok;
}  

int main() {
  string S;
  cin >> S;
  int N = S.size();
  
  string s1 = "";
  for (int i = 0; i < (N-1) / 2; i++) {
    s1.push_back(S.at(i));
  }
  
  string s2 = "";
  for (int i = (N+1) / 2; i < N; i++) {
    s2.push_back(S.at(i));
  }
  
  if (circular(S) && circular(s1) && circular(s2)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;	//Scannerクラス：Java標準入力を取得する

class Main{	//秒数を入力して時間：分：秒の形式に変換し、出力する
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {	//Scanerクラスを変数scで使えるようにする
            int secs = sc.nextInt();		//秒数を入力
            int hh = secs / (60 * 60);		//時間単位に換算
            int hs = secs % (60 * 60);		//あまりの秒数を算出
            int mm = hs / 60;				//分単位に換算
            int ss = hs % 60;				//あまりの秒数を算出
            System.out.println(String.format("%d:%d:%d", hh, mm, ss));		//時間：分：秒を表示
        }
    }
}



Measured memory_bytes: 26384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
long long N;  cin >> N;
vector<long long> A(N + 1), B(N); 
for (int i = 0; i < N + 1; i++) {
    cin >> A[i];
}
for (int i = 0; i < N; i++) {
    cin >> B[i];
}

long long ans = 0;
long long rem_neibour = A[0];
for (int i = 0; i < N; i++) {
    long long rem = rem_neibour + A[i + 1];
    long long tmp = min(rem, B[i]);
    ans += tmp;
    if (rem_neibour > tmp) rem_neibour = A[i + 1]; 
    else rem_neibour = rem - tmp;
}    

cout << ans << endl;

}

Measured memory_bytes: 1792
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] A = new char[H][W];
		int[] hh = new int[H];
		int[] ww = new int[W];
		for( int i=0; i<H; i++ ){
			int a = 0;
			String S = sc.next();
			for( int k=0; k<W; k++ ){
				A[i][k] = S.charAt(k);
				if( A[i][k]=='#' ){
					a = 1;
				}
			}
			if( a==0 ){
				hh[i] = 1;
			}
		}
		for( int i=0; i<W; i++ ){
			int a = 0;
			for( int k=0; k<H; k++ ){
				if( A[k][i]=='#' ){
					a = 1;
				}
			}
			if( a==0 ){
				ww[i] = 1;
			}
		}
		for( int i=0; i<H; i++ ){
			if( hh[i]==1 ){
				continue;
			}
			String ans = "A";
			for( int k=0; k<W; k++ ){
				if( ww[k]==1 ){
					continue;
				}
				String ss = String.valueOf(A[i][k]);
				ans += ss;
			}
			System.out.println(ans.substring(1));
		}
	}
}


Measured memory_bytes: 26324
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
          
      for(int i=111;i<=999;i=i+111){
        if(i>=N){System.out.print(i);break;}
      }

	}
}

Measured memory_bytes: 23252
n, k = [int(x) for x in input().split()]
count = 0
a = int(n / k)
count += (a + a * (a-1) * 3 + a * (a-1) * (a-2))
if k % 2 == 0:
    b = int(n / (int(k / 2))) - a
    count += (b + b * (b-1) * 3 + b * (b-1) * (b-2))
print(count)


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

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

using namespace std;

const int INF=1<<29;

const int V_MAX=202;
const int E_MAX=2*100+100*100;

template<class T>
struct graph{
	int n,m,head[V_MAX],next[2*E_MAX],to[2*E_MAX];
	T capa[2*E_MAX],flow[2*E_MAX];

	void init(int N){
		n=N;
		m=0;
		rep(u,n) head[u]=-1;
	}

	void add_directed_edge(int u,int v,T ca){
		next[m]=head[u]; head[u]=m; to[m]=v; capa[m]=ca; flow[m]=0; m++;
		next[m]=head[v]; head[v]=m; to[m]=u; capa[m]= 0; flow[m]=0; m++;
	}
};

int layer[V_MAX],now[V_MAX];

template<class T>
bool make_layer(const graph<T> &G,int s,int t){
	int n=G.n;
	rep(u,n) layer[u]=(u==s?0:-1);

	int head=0,tail=0;
	static int Q[V_MAX]; Q[tail++]=s;
	while(head<tail && layer[t]==-1){
		int u=Q[head++];

		for(int e=G.head[u];e!=-1;e=G.next[e]){
			int v=G.to[e];
			T capa=G.capa[e],flow=G.flow[e];

			if(capa-flow>0 && layer[v]==-1){
				layer[v]=layer[u]+1;
				Q[tail++]=v;
			}
		}
	}

	return layer[t]!=-1;
}

template<class T>
T augment(graph<T> &G,int u,int t,T water){
	if(u==t) return water;

	for(int &e=now[u];e!=-1;e=G.next[e]){
		int v=G.to[e];
		T capa=G.capa[e],flow=G.flow[e];

		if(capa-flow>0 && layer[v]>layer[u]){
			T w=augment(G,v,t,min(water,capa-flow));
			if(w>0){
				G.flow[ e ]+=w;
				G.flow[e^1]-=w;
				return w;
			}
		}
	}
	return 0;
}

template<class T>
T Dinic(graph<T> &G,int s,int t){
	int n=G.n;
	T ans=0;
	while(make_layer(G,s,t)){
		rep(u,n) now[u]=G.head[u];
		for(T water=1;water>0;ans+=water) water=augment(G,s,t,INF);
	}
	return ans;
}

int main(){
	for(int n,m,L;~scanf("%d%d%d",&n,&m,&L);){
		static int d[100][100];
		rep(u,n) rep(v,n) d[u][v]=(u==v?0:INF);
		rep(i,m){
			int u,v,cost; scanf("%d%d%d",&u,&v,&cost); u--; v--;
			d[u][v]=d[v][u]=cost;
		}

		int ini[100],cap[100];
		rep(u,n) scanf("%d",ini+u);
		rep(u,n) scanf("%d",cap+u);

		rep(k,n) rep(i,n) rep(j,n) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);

		int s=2*n,t=2*n+1;
		static graph<int> G;
		G.init(2*n+2);
		rep(u,n){
			G.add_directed_edge(s,2*u,ini[u]);
			G.add_directed_edge(2*u+1,t,cap[u]);
			rep(v,n) if(d[u][v]<L) G.add_directed_edge(2*u,2*v+1,INF);
		}
		printf("%d\n",Dinic(G,s,t));
	}

	return 0;
}

Measured memory_bytes: 1388
n = int(input())
#s = input()
da = list(map(int,input().split()))
#a,b = map(int,input().split())

da.sort()

ju = True
for i in range(n-1):
    if da[i] == da[i+1]:
        ju = False
        break
if ju:
    print('YES')
else:
    print('NO')

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

int main() {
  int n, count;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  bool judge = true;
  count = -1;
  while(judge) {
    count++;
    for(int i = 0; i < n; i++) {
      if(a[i] % 2 == 0) {
        a[i] = a[i] / 2;
      } else  {
		judge = false;
        break;
      }
    }
  }
  cout << count;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(26, 1e5);
    while(n--) {
        string s;
        cin >> s;
        vector<int> b(26, 0);
        for(char c : s) {
            b[c - 'a']++;
        }
        for(int i = 0; i < 26; i++) {
            a[i] = min(a[i], b[i]);
        }
    }
    string ans = "";
    for(int i = 0; i < 26; i++) {
        // cout << a[i] << endl;
        ans += string(a[i], 'a' + i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from decimal import Decimal 		# a = Decimal(a)	# use this for math questions
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def primeFactorization(x):
	d = defaultdict(int)
	d[1] = 0
	while(x%2 == 0):
		x //= 2
		d[2] += 1
	for i in range(3,int(sqrt(x))+1,2):
		while(x%i == 0):
			d[i] += 1
			x //= i
	if(x > 2):
		d[x] += 1
	return d

def Sieve(x):
	checkPrime = [1 for i in range(x+1)]
	zz = 2
	L = []
	while(zz**2 <= x):
		if(checkPrime[zz] == 1):
			for i in range(zz*2,x+1,zz):
				checkPrime[i] = 0
		zz += 1
	for i in range(2,x):
		if(checkPrime[i] == 1):
			L.append(i)
	return L
	# return checkPrime

# print(len(Sieve(int(sqrt(10**7))+1)))


def solve(x):
	check = [0]*(x+1)
	for i in range(1,x+1):
		j = 1
		while(i*j < x+1):
			check[i*j] += 1
			j += 1
	ans = 0
	# print(check)
	for i in range(1,x+1):
		ans += i * check[i]
	return ans

N = int(stdin.readline())
ans = solve(N)
print(ans)



Measured memory_bytes: 156420
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
  int n,k=0;
  cin >>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n-2;i++){
    if(a[i]<a[i+1]&&a[i+1]<a[i+2]) k++;
    else if(a[i+2]<a[i+1]&&a[i+1]<a[i]) k++;
  }
  
  
  cout << k << endl;
}

Measured memory_bytes: 256
import numpy as np

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

xy45 = [[xy[i][0] - xy[i][1], xy[i][0] + xy[i][1]] for i in range(N)]
xy45 = np.array(xy45)

print(max(max(xy45[:, 0]) - min(xy45[:, 0]), max(xy45[:, 1]) - min(xy45[:, 1])))


Measured memory_bytes: 96532
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  const string color = "RGBY";
  int H, W, d;
  cin >> H >> W >> d;
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      int py = ((x - y) + 1000 * d) / d % 2;
      int px = ((x + y) + 1000 * d) / d % 2;
      cout << color[py * 2 + px];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
public static void main(String[] args) {
		
Scanner keyboard = new Scanner(System.in); 
		
String S = keyboard.next();
String ans = "No";
		
for(int i = 0; i<3; i++){
    if(S.charAt(i) == '7' ){
    ans = "Yes";
    }
} 

	System.out.println(ans);
	keyboard.close();	

	}
}


Measured memory_bytes: 35564
from sys import stdin, stdout


def solve():
    n,k = [int(i) for i in stdin.readline().split()]
    A = [int(i) for i in stdin.readline().split()]
    dp = [False for _ in range(k + 1)]
    for i in range(1, k+1):
        for j in range(n):
            if A[j] > i: break
            if not dp[i - A[j]]: 
                dp[i] = True
                break
    return "First" if dp[k] else "Second"
print(solve())


Measured memory_bytes: 45040
#include <iostream>



int strlen (char *str) {
  int len = 0;
  while (*str != '\0') {
    str++;
    len++;
  }
  return len;
}

bool strcmp(char *s, char *p, int size) {
  for (int i = 0; i < size; i ++) {
    if (s[i] != p[i]) return false;
  }
  return true;
}



int main() {
  char *s = new char[202], p[100];
  int s_len, p_len, i;
  char temp, terminal='\0';
  int flag = 0;

  std::cin >> s >> p;
  s_len = strlen(s);
  p_len = strlen(p);

  for (i = 0; p[i] != '\0'; i ++) {
    s[i + s_len] = s[i];
  }
  s[i + s_len] = '\0';
  s_len += p_len;


  for (i = 0; i < s_len; i ++) {
    temp = s[p_len];
    s[p_len] = terminal;

    if (strcmp(s, p, p_len)) {
      flag = 1;
      break;
    }
    s[p_len] = temp;
    s++;
  }

  if (flag == 1) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

#define MAX 3000000 
char s[MAX + 10];
int wSum[MAX + 10];
int eSum[MAX + 10];

signed main() {
	ios::sync_with_stdio(false);
	int n,i;
	cin >> n;
	rep(i, n) cin >> s[i];
	rep(i, n) {
		if (s[i] == 'W')
			wSum[i + 1] = wSum[i] + 1;
		else
			wSum[i + 1] = wSum[i];

		if (s[i] == 'E')
			eSum[i + 1] = eSum[i] + 1;
		else
			eSum[i + 1] = eSum[i];
	}
	int mini = INF;
	rep(i, n) {
		mini = min(mini, wSum[i] + eSum[n] - eSum[i + 1]);
	}
	cout << mini << '\n';
	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    double N;
    cin >> N;

    cout << ll(sqrt(N)) * ll(sqrt(N)) << endl;

    return 0;
}

Measured memory_bytes: 3708
#124-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
S=S()
fb,fw=0,0
for i in range(len(S)):
    if i%2==0:
        if S[i]=='0':
            fw+=1
        else:
            fb+=1
    else:
        if S[i]=='0':
            fb+=1
        else:
            fw+=1
print(min(fb,fw))

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

int main() {
    int n;
    cin >> n;
    int x;
    if (n % 1000 == 0) x = 0;
    else x = 1000 - n % 1000;
    cout << x << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v)              \
  cerr << #v ":[ ";          \
  for (auto macro_vi : v)    \
  {                          \
    cerr << macro_vi << " "; \
  }                          \
  cerr << "]" << endl;
#define ddump(v)                     \
  cerr << #v ":" << endl;            \
  for (auto macro_row : v)           \
  {                                  \
    cerr << "[";                     \
    for (auto macro__vi : macro_row) \
    {                                \
      cerr << macro__vi << " ";      \
    }                                \
    cerr << "]" << endl;             \
  }
#define damp(m)                                                   \
  for (auto macro_pair : m)                                       \
  {                                                               \
    cerr << macro_pair.first << ":" << macro_pair.second << endl; \
  }
#define dpair(p) cerr << #p ":" \
                      << "(" << p.first << "," << p.second << ")" << endl;
// iterate
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define itr(macro_v, i) macro_v.begin() + i
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  vector<int> v(0);
  cin >> n;
  rep(i, n)
  {
    char c;
    cin >> c;
    v.push_back(c - '0');
  }
  int cnt = 0;
  for (int x = 0; x <= 999; x++)
  {
    int x1 = (x / 100) % 10, x2 = (x / 10) % 10, x3 = (x / 1) % 10;
    vector<int> odr{x1, x2, x3};
    int pos = 0;
    bool ok = true;
    for (auto x : odr)
    {
      while (pos < v.size() and v[pos] != x)
        pos++;
      if (pos == v.size())
      {
        ok = false;
        break;
      }
      else
        pos++;
    }
    if (ok)
    {
      cnt++;
    }
    else
    {
      continue;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 60;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

int n;
vector<vector<int>> g(10);
bool visited[10] = {};

int dfs(int x, int cnt) {
  if (cnt == n) return 1;

  int ret = 0;
  for (auto nx: g[x]) {
    if (visited[nx]) continue;
    visited[nx] = true;
    ret += dfs(nx, cnt+1);
    visited[nx] = false;
  }
  return ret;
}

int main() {
  int m; cin>>n>>m;
  rep(i, m) {
    int a, b; cin>>a>>b;
    --a; --b;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  visited[0] = true;
  print(dfs(0, 1));

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

	cout << (W >= S ? "unsafe" : "safe") << endl;

	return 0;
}

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

#define MAX_STR 1000

void print(char *str, int first, int last);
void reverse(char *str, int first, int last);
void replace(char *str, int first, int last, char *new_str);

int main(void)
{
    int i;

    char str[MAX_STR + 1];
    scanf("%s", str);

    int num_op;
    scanf("%d", &num_op);

    char op[8];
    int first, last;
    for (i = 1; i <= num_op; i++) {
        scanf("%s %d %d", op, &first, &last);

        if (strcmp(op, "print") == 0) {
            print(str, first, last);
        } else if (strcmp(op, "reverse") == 0) {
            reverse(str, first, last);
        } else {
            char new_str[1001];
            scanf("%s", new_str);
            replace(str, first, last, new_str);
        }
    }

    return 0;
}

void print(char *str, int first, int last)
{
    int i;
    for (i = first; i <= last; i++) {
        printf("%c", str[i]);
    }
    printf("\n");
}

void reverse(char *str, int first, int last)
{
    char tmp[MAX_STR];
    int i;
    for (i = first; i <= last; i++) {
        tmp[i] = str[last + first - i];
    }
    for (i = first; i <= last; i++) {
        str[i] = tmp[i];
    }
}

void replace(char *str, int first, int last, char *new_str)
{
    int i;
    for (i = 0; i < last - first + 1; i++) {
        str[first + i] = new_str[i];
    }
}

Measured memory_bytes: 576
#include<bits/stdc++.h>
 
using namespace std;
int main(){
  
 int n,k;
  cin>>n>>k;
  int a[n];
  int sum;
  for(int i=0;i<n;i++)
    cin>>a[i];
  
  int dp[n];
  for(int i=0;i<n;i++)
{
    dp[i]=INT_MAX;
}
  dp[0]=0;
  if(n==1)
    {cout<<"0";
    return 0;}
  dp[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++)
  {
    
    for(int j=1;j<=k;j++)
    {
      
      
      if(j>i)
        break;
      
      
       
      dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
      
      
      
    }
    
  }
                
                cout<<dp[n-1];
  
  return 0;
}

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

#define ll   	long long
#define pb	    push_back
#define F   	first
#define S	    second
#define B   	begin()
#define E	    end()
#define FASTIO   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


using namespace std ;



int main()
{
    FASTIO
    int a , b ;
    cin >> a >> b ;
    if ( a >= 13 )
        cout << b ;
    else if ( a >= 6 && a <= 12 )
        cout << b/2 ;
    else
        cout << 0 ;
    return 0 ;
}



Measured memory_bytes: 3648
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
const int mod=1e9+7;
const int N=3e5;
int modp(int a,int b)
{
	if(b==0)return 1;
	int u=modp(a,b/2);
	u=(u*u)%mod;
	if(b&1)return (a*u)%mod;
	return u;
}
int inv(int n)
{
	return modp(n,mod-2);
}
int f[N];
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int n=in();int m=in();int k=in();
	f[0]=1;
	for(int i=1;i<=n*m;i++)
	f[i]=(f[i-1]*i)%mod;
	
	int base=f[n*m-2];
	base*=inv(f[k-2]);base%=mod;base*=inv(f[n*m-2-(k-2)]);base%=mod;
	
	int ans=0,a;
	for(int i=0;i<n;i++)
	{
		a=i*(n-i);a%=mod;
		a*=(m*m);a%=mod;ans+=a;ans%=mod;
	}
	for(int i=0;i<m;i++)
	{
		a=i*(m-i);a%=mod;
		a*=(n*n);a%=mod;ans+=a;ans%=mod;
	}
	
	cout<<(ans*base)%mod;
	
	
}

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

using namespace std;

typedef long long ll;
ll a,b,n;
ll get(ll a,ll b){
	ll d= b-a;
	return (d-1)/2;
}
int main(){
	cin >> n >> a >> b;
	ll d = b - a;
	if (d&1){
		cout << min(get(a,b)+a,get(n-b+1,n-a+1)+n-b+1);
	}else{
		cout << d/2;
	}
	
} 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
/* -- template -- */

int main() {
    int N, K, S; cin >> N >> K >> S;
    if(S != INF)
        rep(i, N) {
            if(i < K) cout << S << ' ';
            else cout << INF << ' ';
        }
    else
        rep(i, N) {
            if(i < K) cout << S << ' ';
            else cout << 1 << ' ';
        }
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priotity_queue
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ld PI=abs(acos(-1)); 
int n,a[100010],b[100010],c[100010];
	
int main(){
	cin >> n;
	REP(i,0,n) cin >> a[i];
	REP(i,0,n) cin >> b[i];
	REP(i,0,n) cin >> c[i];
	sort(a,a+n); sort(b,b+n); sort(c,c+n);
	
	ll s[100010]={};
	REP(i,0,n){
		int j=lower_bound(a,a+n,b[i])-a;
		s[i+1]=s[i]+j;
	}
	
	ll sum=0;
	REP(i,0,n){
		int j=lower_bound(b,b+n,c[i])-b;
		sum+=s[j];
	}
	
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 2176
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
  int N;
  cin >> N;
  cout << N*N << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#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++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

ll dp[1 << 17][2];
void solve() {
	int n; cin >> n;
	vector<ll> a(n); rep(i, n)cin >> a[i];
	rep(i, n + 1)rep(j, 2)dp[i][j] = -INF;
	dp[0][0] = 0;
	rep(i, n) {
		dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + a[i]);
		dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] - a[i]);
		dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] - a[i]);
		dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + a[i]);
	}
	cout << dp[n][0] << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}

Measured memory_bytes: 2560
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;


public class Main {
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
    public static long mod = (long) (1e9+7);
    public final static int MAX = (int)1e5;
  // static Scanner sc = new Scanner(System.in);
   static List<Integer>[] edge;
	public static void main(String[] args) {
	   
	 FastReader sc = new FastReader();
	   char[] s = sc.next().toCharArray();
	   long sum = 0;
	   for(int i=0;i<s.length;++i) sum+=s[i]-'0';
	   out.print(Math.max(sum,9*(s.length-1)+s[0]-'1'));
	   out.close();
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef pair <int, int> pii;

const int INF = 0x3f3f3f3f;
int n, e, f, c[1005][1005];
vector <pii> adj[1005];

int dij(int s, int t, vector <int> &p, vector <int> &d) {
//	cout << "WTFF" << endl;
	fill(p.begin(), p.end(), -1);
	fill(d.begin(), d.end(), INF);
	vector <bool> inq(n + 5);
	p[s] = s, d[s] = 0, inq[s] = 1;
	queue <int> q;
	q.push(s);
	while (!q.empty()) {
		int u = q.front(); q.pop();
		inq[u] = 0;
//		cout << u << ' ' << d[u] << endl;
		for (pii i : adj[u]) {
			if (d[u] + i.se < d[i.fi] && c[u][i.fi] > 0) {
				d[i.fi] = d[u] + i.se;
				p[i.fi] = u;
//				cout << ">> " << i.fi << ' ' << i.se << endl;
				if (!inq[i.fi]) {
					q.push(i.fi);
					inq[i.fi] = 1;
				}
			}
		}
	}
//	for (int i = 0; i <= n; i++) cout << d[i] << ' ';
//	cout << endl;
	if (d[t] != INF) return d[t];
	else return -1;
}

int maxFlow(int s, int t) {
//	cout << "WTF" << endl;
	int rt = 0, cnt = 0, nf;
	vector <int> p, d;
	p.resize(n + 5);
	d.resize(n + 5);
	int t1;
	while (dij(s, t, p, d) != -1) {
		int bt = t;
		nf = INF;
		while (p[bt] != bt) {
			int v = p[bt];
			nf = min(nf, c[v][bt]);
//			cout << v << ' ' << bt << ' ' << d[v] << endl;
			bt = v;
		}
		nf = min(f - cnt, nf);
		rt += d[t] * nf, bt = t, cnt += nf;
//		cout << ">> " << rt << ' ' << d[t] << ' ' << nf << ' ' << cnt << endl;
		while (p[bt] != bt) {
			int v = p[bt];
			c[v][bt] -= nf;
			c[bt][v] += nf;
			bt = v;
		}
		if (cnt == f) break;
	}
	if (cnt == f) return rt;
	else return -1;
}

int main() {
	cin >> n >> e >> f;
	for (int i = 0; i < e; i++) {
		int u, v, cap, w;
		cin >> u >> v >> cap >> w;
		c[u][v] = cap;
		adj[u].pb(mp(v, w));
		adj[v].pb(mp(u, -w));
	}
	c[n - 1][n] = f;
	adj[n - 1].pb(mp(n, 0));
	adj[n].pb(mp(n - 1, 0));
	cout << maxFlow(0, n) << endl;
}



Measured memory_bytes: 3556
#include<iostream>
#include<cstdio>
using namespace std ;
int main()  {
  int a,b,i;
  char op;
  for( ; ; ){
 cin>>a>>op>>b;
 
 if(op=='+'){
      i=a+b;
    }
    if(op=='-'){
	i=a-b;
    }
    if(op=='*'){
        i=a*b;
    }
    if(op=='/'){
	  i=a/b;
    }
    if(op=='?')break;
     cout<<i<<endl;
  }
  return 0;
}

Measured memory_bytes: 3112
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N, *A = map(int, open(0))
    ans = 0
    i = 0
    prev = 0
    while i < N:
        if A[i] == 0:
            prev = 0
        else:
            ans += (A[i]+prev)//2
            prev = (A[i]+prev)%2
        # print(A[i],prev,ans)
        i += 1
    print(ans)

if __name__ == "__main__":
    main()


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

int main() {
  int n;
  cin >> n;
  vector<double> x(n), y(n);
  for (int i{}; i < n; ++i) cin >> x[i];
  for (int i{}; i < n; ++i) cin >> y[i];

  double d[4]{};
  for (int i{}; i < n; ++i) {
    d[0] += abs(x[i] - y[i]);
  }
  for (int i{}; i < n; ++i) {
    d[1] += pow(abs(x[i] - y[i]), 2);
  }
  d[1] = sqrt(d[1]);
  for (int i{}; i < n; ++i) {
    d[2] += pow(abs(x[i] - y[i]), 3);
  }
  d[2] = cbrt(d[2]);
  for (int i{}; i < n; ++i) {
    d[3] = max(d[3], abs(x[i] - y[i]));
  }
  for (int i{}; i < 4; ++i) {
    cout << fixed << setprecision(5) << d[i] << endl;
  }

  return 0;
}



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

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

  int sum = 0;

  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
    sum += T.at(i);
  }

  int M;
  cin >> M;

  for (int i = 0; i < M; i++) {
    int P, X;
    cin >> P >> X;
    cout << sum - T.at(P - 1) + X << "\n";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x;
  cin>>n>>x;
  vector<int>d(n+1);
  d[0]=0;
  for(int i=0; i<n; ++i){
    int x;
    cin>>x;
    d[i+1]=d[i]+x;
  }
  int a=0;
  for(int i=0; i<=n; ++i){
    if(d[i]<=x){
      a++;
    }
  }
  cout<<a<<endl;
  return(0);
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        d = new int[n + 1];
        f = new int[n + 1];
        m = new int[n + 1][n + 1];
        color = new int[n + 1];
        for(int i = 1 ; i <= n ; i ++){
            int u = sc.nextInt();
            int k = sc.nextInt();
            for(int j = 1; j <= k ; j ++){
                int v = sc.nextInt();
                m[u][v] = 1;
            }
        }

        for(int i = 1; i <= n ; i ++){
            if(color[i] == 0){
                dfs2(i);
            }
        }

        for(int i = 1; i <= n ; i ++){
            System.out.println(i + " " + d[i] + " " + f[i]);
        }
    }


    /**
     * 深度优化 栈实现
     * color数组： 0-未访问  1-已访问    2-访问结束
     */
    static Stack<Integer> s = new Stack<>();
    static int[] d;
    static int[] f;
    static int[][] m;
    static int[] color;
    static int time = 0;
    static int n;

    static void dfs2(int u){
        d[u] = ++ time;
        color[u] = 1;
        for(int i = 1; i <= n ; i++){
            if(m[u][i] == 1 && color[i] == 0){
                dfs2(i);
            }
        }
        color[u] = 2;
        f[u] = ++ time;
    }
}



Measured memory_bytes: 28008
#include <stdio.h>
#include <math.h>

int main(void)
{
	float len;
	float ang, angin;
	float x, y;
	
	x = 0;
	y = 0;
	ang = 90;
	while (1){
		scanf("%f,%f", &len, &angin);
		
		if (len == 0 && angin == 0){
			break;
		}
		
		y += (sin(ang / 180 * M_PI) * len);
		x += (cos(ang / 180 * M_PI) * len);
		
		ang -= angin;
	}
	
	printf("%d\n%d\n", (int)x, (int)y);
	
	return (0);
}

Measured memory_bytes: 1052
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions 

#endif


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

    int N; cin >> N;
    vl A(N + 1); REP(i, N + 1) cin >> A[i];
    vl B(N); REP(i, N) cin >> B[i];

    ll ans = 0;
    if (A[0] >= B[0]) {
        ans += B[0];
        A[0] -= B[0];
        B[0] = 0;
    } else { // A[0] < B[0]
        ans += A[0];
        B[0] -= A[0];
        A[0] = 0;
    }
    FOR(i,1,N) {
        if (B[i - 1] > 0) {
            if (A[i] >= B[i-1]) {
                ans += B[i-1];
                A[i] -= B[i-1];
                B[i-1] = 0;
            } else { // A[i] < B[i-1]
                ans += A[i];
                B[i-1] -= A[i];
                A[i] = 0;
            }
        }

        if (A[i] == 0) continue;

        if (A[i] >= B[i]) {
            ans += B[i];
            A[i] -= B[i];
            B[i] = 0;
        } else { // A[i] < B[i]
            ans += A[i];
            B[i] -= A[i];
            A[i] = 0;
        }
    }
    if (A[N] > 0 && B[N-1] > 0) {
        if (A[N] >= B[N-1]) {
            ans += B[N-1];
            A[N] -= B[N-1];
            B[N-1] = 0;
        } else { // A[N] < B[N-1]
            ans += A[N];
            B[N-1] -= A[N];
            A[N] = 0;
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,long double> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

typedef pair<long double,int> Pd;
ll sx,sy,gx,gy;
int n;
ll x[1010],y[1010],r[1010];
vector<P> g[1010];
long double d[1010];

long double calc(int v,int u) {
	long double res;
	res=sqrt(1.*abs(x[u]-x[v])*abs(x[u]-x[v])+abs(y[u]-y[v])*abs(y[u]-y[v]));
	res-=1.*r[u]+r[v];
	if(res<0.0) return 0;
	else return res;
}

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

	cin>>sx>>sy>>gx>>gy>>n;
	x[0]=sx,y[0]=sy;
	x[n+1]=gx,y[n+1]=gy;
	FOR(i,1,n+1) {
		cin>>x[i]>>y[i]>>r[i];
	}
	REP(i,n+2) {
		REP(j,i) {
			long double dist=calc(i,j);
			g[i].pb(P(j,dist));
			g[j].pb(P(i,dist));
		}
	}
	REP(i,1010) d[i]=LINF;
	d[0]=0;
	priority_queue<Pd,vector<Pd>,greater<Pd> > pq;
	pq.push(Pd(0.0,0));
	while(!pq.empty()) {
		Pd p=pq.top();pq.pop();
		int v=p.se;
		if(d[v]<p.fi) continue;
		for(auto e:g[v]) {
			int u=e.fi;
			long double cost=e.se;
			if(d[u]<=d[v]+cost) continue;
			d[u]=d[v]+cost;
			pq.push(Pd(d[u],u));
		}
	}
	printf("%.10Lf\n",d[n+1]);

	return 0;
}


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


def solve(N: int, M: int, A: "List[int]"):
    a_heap = []

    for a in A:
        heapq.heappush(a_heap,(-a,a))

    for i in range(M):
        item = heapq.heappop(a_heap)
        new_p = item[1] // 2
        heapq.heappush(a_heap,(-new_p,new_p))

    print(sum(map(lambda x: x[1],a_heap)))

    return


# 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)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

string s;

int main() {
	cin >> s;
	//inc(i, n) { cin >> a[i]; }
	
	s[3] = '8';
	cout << s << endl;
	
	return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
ll INF = (1LL << 32LL) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    map<ll,ll> mp;
    rep(i,0,N){
        cin >> A[i];
    }
    sort(A.rbegin(), A.rend());
    rep(i,0,N){
        mp[A[i]]++;
    }
    ll ans = 0;
    rep(i,0,N){
        ll cnt = 0;
        if(mp[A[i]] == 0)continue;
        for(ll j = 2;j < INF;j *= 2){
            ll num = j - A[i];
            //cout << num << endl;
            if(num > 0 && mp[num] != 0){
                //cout << num << " " << j << " " << A[i] << endl;
                //cout << num << " ";
                if(num == A[i] && mp[A[i]] == 1)continue;
                mp[A[i]]--;
                cnt ++; 
                mp[num]--;
                break;
            }
        }
        //cout << " " << cnt << endl;
        ans += cnt;
        //cout << A[i] << " " << cnt << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 52736
# 2 6   n m
require 'prime'

n, m = gets.split.map(&:to_i)
divisor = 10**9 + 7

array_prime_division = m.prime_division
array_b = []
array_prime_division.each do |p, b|
  array_b << b
end

ans = 1
array_b.each do |b|
  comb = 1
  (b-1).downto(0) do |j|
    comb = (b+n-1-j) * comb / (b-j)
  end
  comb %= divisor
  ans *= comb % divisor
end

p ans % divisor


Measured memory_bytes: 14388
N = int(input().rstrip())
src = [list(input().split()) for _ in range(N)]
for row in src:
    row[1] = int(row[1])
X = input()

total = 0
for row in src:
  total += row[1]

awake = 0
for row in src:
    if row[0] != X:
      awake += row[1]
    else:
      awake += row[1]
      break
ans = total - awake
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int ans = 0;
        ans = x / 500;
        x %= 500;
        System.out.println(ans * 1000 + (x / 5) * 5);
    }
}


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

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

int N, M;

int main() {
	scanf("%d %d", &N, &M);
	int ans = 0, maxi = 0;
	rep(i, M) {
		int A, B;
		scanf("%d %d", &A, &B);
		if(A < N) {
			ans += N - A;
			maxi = max(N - A, maxi);
		}
	}
	printf("%d\n", ans - maxi);
	return 0;
}

Measured memory_bytes: 3220
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

res = 0
val = 10**5
for i in range(n):
    if (v := abs(a - (t - h[i]*0.006))) < val:
        val = v
        res = i+1
print(res)


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

using namespace std;

int main (){

  int x, y;
  long long ans = 0;
  const long long m = 100000;
  
  cin>>x>>y;
  
  if(x <= 3 ) ans+= (4-x)*m;
  if(y <= 3 ) ans+= (4-y)*m;
  
  if((x == 1) && (y == 1)) ans+=4*m;
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int x, a, b;
    cin >> x >> a >> b;
    if (abs(x-a)< abs(x-b)) cout << "A" << endl;
    else cout << "B" << endl;
    //cout << ans << endl;
}

Measured memory_bytes: 256