akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop, heapify, nsmallest

N, M = map(int, input().split())
costs = list(map(int, input().split()))
treemin = [(cost, i) for i, cost in enumerate(costs)] # グループ内での最小値

parent = list(range(N))
rank = [0] * (N)
def getRoot(x):
  if parent[x] == x:
    return x
  else:
    # ルートに繋ぎ変える
    parent[x] = getRoot(parent[x])
    return parent[x]

def unite(x, y):
  global treemin
  xRoot = getRoot(x)
  yRoot = getRoot(y)
  if xRoot == yRoot:
    return
  if rank[xRoot] < rank[yRoot]:
    parent[xRoot] = yRoot
    if treemin[yRoot][0] > treemin[xRoot][0]:
      treemin[yRoot] = treemin[xRoot]
  else:
    parent[yRoot] = xRoot
    if treemin[xRoot][0] > treemin[yRoot][0]:
      treemin[xRoot] = treemin[yRoot]
    if rank[xRoot] == rank[yRoot]:
      rank[xRoot] += 1

for i in range(M):
  x, y = map(int, input().split())
  unite(x, y)

ans = 0
numtree = 0
exclude = set()
for i in range(N):
  if parent[i] == i:
    numtree += 1
    ans += treemin[i][0]
    exclude.add(treemin[i][1])

if N < (numtree-1) * 2:
  print('Impossible')
  exit()
if numtree == 1:
  print(0)
  exit()

heap = []
for i in range(N):
  if i not in exclude:
    heappush(heap, costs[i])

ans += sum(nsmallest(numtree - 2, heap))
print(ans)

Measured memory_bytes: 29100
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}


int N, K;
	
bool check(int x){
	int sum = 0;
	
	for(int i = 1; i <= N; i++){
		if(x <= 0) break;
		sum += x;
		
		x /= 2;
	}
	
	return sum <= K;	
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	cin>>N>>K;
	
	int l = 0, h = K+1, m;
	
	while(l + 1 < h){
		m = (l + h)>>1;
		
		if(check(m)) {
			l = m;
		} else {
			h = m;
		}
	}
	
	cout<<l<<endl;
	
	return 0;
}


Measured memory_bytes: 3180
#include "bits/stdc++.h"

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

using i64 = long long;
using d64 = long double;
using pi = pair<int, int>;
using pli = pair<i64, i64>;
using ti = tuple<int, int, int>;
using tli = tuple<i64, i64, i64>;

#define iterall(cont) cont.begin(), cont.end()
#define prec(n) setprecision(n) << fixed

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

    int N;
    cin>>N;

    vector<int> v(N);
    for(int i=0;i<N;i++) cin>>v[i];

    int res = 0;
    for(int i=0;i<N;i++) {
        for(int j=i+1;j<N;j++) {
            for(int k=j+1;k<N;k++) {
               if(v[i]==v[j]||v[j]==v[k]||v[k]==v[i]) continue;
               auto m = max({v[i], v[j], v[k]});
               if(m < v[i]+v[j]+v[k]-m) {
                   // cout<<i<<" "<<j<<" "<<k<<endl;
                   res++;
               }
            }
        }
    }

    cout<<res<<endl;
    return 0;
}

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

int main() {
  int n,d,x,k;
  cin >> n >> d >> x;
  k = 0;
  vector<int> choco(n);
  for(int i = 0;i<n;i++){
    cin >> choco.at(i);
  }
  
  for(int i = 0;i<n;i++){
    int j = 1;
    while( j <= d){
      k++;
      j += choco.at(i);
    }
  }
  
  cout << k + x << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef std::pair<int, int> ipair;
#define int long long
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define cnt_ones(x) __builtin_popcount(x)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mod 1000000007
#define IOS                                                                    \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

void init() {
  int n;
  cin >> n;
  vector<ipair> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].ff;
    a[i].ss = i + 1;
  }
  sort(all(a));
  for (auto x : a)
    cout << x.ss << " ";
}
int32_t main() {
  IOS;
  init();
  return 0;
}


Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
int a[10010];

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

Measured memory_bytes: 3672
import math

def calc(x, y):
    s = math.fabs((x[1]-x[0])*(y[2]-y[0]) - (x[2]-x[0])*(y[1]-y[0]))/2
    a = ((x[2]-x[1])**2 + (y[2]-y[1])**2)**0.5
    b = ((x[0]-x[2])**2 + (y[0]-y[2])**2)**0.5
    c = ((x[1]-x[0])**2 + (y[1]-y[0])**2)**0.5
    r = a*b*c/(4*s)

    a = [2*(x[1]-x[0]), 2*(x[2]-x[0])]
    b = [2*(y[1]-y[0]), 2*(y[2]-y[0])]
    c = [x[0]**2 - x[1]**2 + y[0]**2 -y[1]**2, x[0]**2 - x[2]**2 + y[0]**2 -y[2]**2]
    x = (b[0]*c[1]-b[1]*c[0])/(a[0]*b[1]-a[1]*b[0])
    y = (c[0]*a[1]-c[1]*a[0])/(a[0]*b[1]-a[1]*b[0])

    return [x,y,r]

for i in range(int(input())):
    list = [float(l) for l in raw_input().split()]
    x,y = [list[0::2],list[1::2]]

    ans = calc(x,y)

    print "%.3f %.3f %.3f" % (ans[0],ans[1],ans[2])

Measured memory_bytes: 5012
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  int sum = 0;
  int sub = 1111;
  rep(i, N) {
    int s; cin >> s;
    sum += s;
    if(s%10 != 0 && s < sub) sub = s;
  }
  if(sum%10 == 0) {
    if(sub == 1111) sum = 0;
    else sum -= sub;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
n=int(input())
c=[[0]*10 for _ in range(10)]
for i in range(n):
	s=str(i+1)
	c[int(s[0])][int(s[-1])]+=1
ans=0
for i in range(10):
	for j in range(10):
		ans+=c[i][j]*c[j][i]
print(ans)


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

#define N 200005

int n, a[N];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
    int cur = 1;
    for (int i = 1; i <= n; i ++) {
		if (a[i] == cur) cur ++;
    }
    if (cur == 1) puts("-1");
    else printf("%d\n", n - cur + 1);
	return 0;
}


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

#define MAXN 200000

int main() {
	char s[MAXN+1];
	long ct[26];
	while (scanf("%s", s)==1) {
		memset(ct, 0, sizeof(ct));
		for (int i=0; s[i]; i++)
			ct[s[i]-'a']++;
		long r = 1;
		for (int i=0; i<26; i++)
			for (int j=i+1; j<26; j++)
				r += ct[i] * ct[j];
		printf("%ld\n", r);
	}
}



Measured memory_bytes: 384
hyo1 = input().split()
N = int((hyo1[0]))
K = int((hyo1[1]))
lis = []

for i in range (N):
    lis.append(i+1)
set_lis = set(lis)

for i in range(K):
    okasi = input()
    hito = list(map(int, input().split()))
    set_hito = set(hito)
    set_lis = (set_lis-set_hito)

print(len(set_lis))

Measured memory_bytes: 9144
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define quickIO()	{cin.tie(0);	cout.sync_with_stdio(false);}
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<(int)n;i++)
#define REP(i,n)	for(int i=0;i<=(int)n;i++)
#define srep(i,a,n)	for(int i=a;i<(int)n;i++)
#define SREP(i,a,n)	for(int i=a;i<=(int)n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll gcd(ll a, ll b) {
	return a%b == 0 ? b : gcd(b, a%b);
}
#define debug(x)	cout<<"case #" << x << ": " << endl
#define DEBUG 0
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ld eps = 1e-15;
const int dx[] = { 1,0,-1,0,0 };
const int dy[] = { 0,1,0,-1,0 };

int main() {
	int n;	cin >> n;
	vint a(n);
	rep(i, n)	cin >> a[i];
	vint dist(n - 1), dist2(n - 2);
	rep(i, n-1)	dist[i] = abs(a[i + 1] - a[i]);
	rep(i, n - 2)	dist2[i] = abs(a[i + 2] - a[i]);
	int sum = 0;
	rep(i, n-1)	sum += dist[i];
	rep(i, n) {
		if (i == 0) {
			cout << sum - dist[0] + abs(a[1]) + abs(a[n - 1]) << endl;
		}
		else if (i == n - 1) {
			cout << sum - dist[n - 2] + abs(a[0]) + abs(a[n - 2]) << endl;
		}
		else {
			cout << sum - dist[i - 1] - dist[i] + dist2[i - 1] + abs(a[0]) + abs(a[n - 1]) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2432
import java.util.*

fun main() {
    val sc = Scanner(System.`in`)

    val n = sc.nextInt()
    val m = sc.nextInt()
    val x = sc.nextInt()

    data class Book(val c: Int, val a: IntArray)

    val books = Array(n) { Book(sc.nextInt(), IntArray(m) { sc.nextInt() }) }

    val ricakido = IntArray(m)
    var min = Int.MAX_VALUE;
    fun calc(list: List<Book>) {
        //println(list)
        ricakido.fill(0)
        var sum = 0
        for (book in list) {
            sum += book.c
            for (i in book.a.indices) {
                ricakido[i] += book.a[i]
            }
        }
        if (ricakido.all { it >= x })
            min = minOf(min, sum)
    }

    fun dp(list: MutableList<Book>, i: Int) {
        if (i != -1) 
            list.add(books[i])
        calc(list)
        for (j in i + 1 until n) {
            dp(list, j)
        }
        if (i != -1) 
            list.removeAt(list.lastIndex)
    }

    dp(mutableListOf(), -1)
    
    if (Int.MAX_VALUE == min)
        println("-1")
    else 
        println(min)
}


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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

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

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}



int main(){
    ll n,k,q;
    cin >> n >> k >> q;
    int a[q];
    int point[n];
    rep(i,q){
        cin >> a[i];
    }

    rep(i,n) point[i]=k-q;

    
    rep(i,q){
        point[a[i]-1]++;
    }

    rep(i,n){
        if(point[i]>0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

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

int main() {
  int n, m, s, t;
  cin >> n >> m;
  vector<vector<int>> v(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[a - 1].push_back(b - 1);
  }
  cin >> s >> t;
  s--;
  t--;

  vector<vector<int>> d(n, vector<int>(3, 1e9));
  queue<pair<int, int>> q;
  d[s][0] = 0;
  q.push({s, 0});
  while (!q.empty()) {
    auto e = q.front();
    int i = e.first, di = e.second;
    q.pop();
    for (auto j : v[i]) {
      if (di + 1 < d[j][(di + 1) % 3]) {
        d[j][(di + 1) % 3] = di + 1;
        q.push({j, di + 1});
      }
    }
  }

  cout << (d[t][0] != int(1e9) ? d[t][0] / 3 : -1) << endl;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;




int main(){
    int N;
    LL L;
    cin >> N >> L;
    vector<LL> A;
    for(int i=0;i<N;i++){
        LL a;
        cin >> a;
        A.pb(a);
    }
    P p=mp(0,-1);
    for(int i=0;i<N-1;i++){
        if(p.fs<A[i]+A[i+1]) p=mp(A[i]+A[i+1],i+1);
    }
    if(p.fs>=L){
        puts("Possible");
        for(int i=1;i<p.sc;i++){
            cout << i << endl;
        }
        for(int i=N-1;i>=p.sc;i--){
            cout << i << endl;
        }
    }
    else puts("Impossible");
    return 0;
}


Measured memory_bytes: 1780
n, x, m = map(int, input().split())

i = 0
a = x
aa = set()
aal = []
s = 0
while a not in aa:
    aa.add(a)
    aal.append(a)
    s += a
    i += 1
    if i == n:
        print(s)
        exit(0)
    a = (a ** 2) % m
    if a == 0:
        print(s)
        exit(0)
st  = aal.index(a)
cont = aal[st:]
nc = len(cont)
n -= st
ans = sum(aal[:st]) + sum(cont) * (n // nc) + sum(cont[:(n % nc)])
print(ans)

Measured memory_bytes: 13556
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    int x = a.length();
    int y = b.length();
    if(a.charAt(x-1)==b.charAt(0) && b.charAt(y-1)==c.charAt(0)){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}


Measured memory_bytes: 21716
#include <stdio.h>
int main(void){
  int t_attack,t_hp;
  int a_attack,a_hp;
  scanf("%d%d%d%d",&t_hp,&t_attack,&a_hp,&a_attack);
  while(1){
    a_hp=a_hp - t_attack;
    if(a_hp<=0)break;
    t_hp=t_hp - a_attack;
    if(t_hp<=0)break;
  }
  if(a_hp<=0)printf("Yes");
  if(t_hp<=0)printf("No");
  return 0;
}


Measured memory_bytes: 1732
#include "bits/stdc++.h"
#define ll long long
#define PI 3.1415926535897932384626433832795l
#define MAX_NUM 1000000000
#define line printf("-----------------\n");
using namespace std;
int SET(int N, int pos) { return N = N | (1 << pos); }
int RESET(int N, int pos) { return N = N & ~(1 << pos); }
bool CHECK(int N, int pos) { return (bool)(N & (1 << pos)); }
template <typename T>
inline T __lcm(T a, T b)
{
    return (a * b) / __gcd(a, b);
}
struct node
{
    ll x, y, i;
};
int dx[] = {0, 1, 0, -1, -1, 1, -1, 1};
int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};


void solve()
{
    ll n,k;
    cin>>n>>k;
    cout<<n-k+1<<endl;
}

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("inputf.txt", "r", stdin);
    //freopen("outputf.txt", "w", stdout);
#endif // ONLINE_JUDGE
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);

    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

int main(void){
    ll n,a,b;
    cin>>n>>a>>b;
    if((b-a)%2==0){
        cout<<(b-a)/2<<endl;
    }
    else{
        ll ans1=a-1+1+(b-a-1)/2;
        ll ans2=n-b+1+(b-a-1)/2;
        cout<<min(ans1,ans2)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include <iomanip>
using namespace std;

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

  vector<vector<int>> point(N, vector<int>(2)); 
  int i;
  for(i=0; i<N; i++)
    {
      cin >> point.at(i).at(0) >> point.at(i).at(1);
    }

  int j;
  double sum=0;
  for(i=0; i<N-1; i++)
    {
      for(j=i+1; j<N; j++)
	{
	  sum += sqrt(pow(point.at(i).at(0)-point.at(j).at(0),2)+pow(point.at(i).at(1)-point.at(j).at(1),2));
	  //cout <<i<<" " <<j<<" " << sum << endl;
	}
    }

  /*
  int div=1;
  for(i=1; i<N+1; i++)
    div*=i;

  if(N!=1)
    div/=N-1;
  */
  sum=sum*2/N;

  cout << setprecision(15);

  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

//////////////////////////////////////////////////////////////


int main() {

	int N;
	cin >> N;
	
	if (N < 3*5*7) {
		cout << 0 << endl;
	}
	else if (N < 3 * 5 * 9) {
		cout << 1 << endl;
	}
	else if (N < 3 * 5 * 11){
		cout << 2 << endl;
	}
	else if (N < 3 * 7 * 9) {
		cout << 3 << endl;
	}
	else if (N < 3 * 5 * 13){
		cout << 4 << endl;
	}
	else {
		cout << 5 << endl;
	}

	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007
#define int long long

signed main(){
    signed n;
    string s;cin>>n>>s;
    for(char c:s){
        int a=((c-'A')+n)%26+'A';
        cout<<(char)a<<flush;
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
    ll x, y, z;
    cin >> x >> y >> z;
    ll c = 0;
    x -= z;
    while (x >= y+z) {
        c++;
        x -= (y+z);
    }
    cout << c << endl;
    return 0;
}


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

long countLunlun(int l, int h, map<pair<int, int>, long> cache) {
  pair<int, int> key = make_pair(l, h);
  if (cache.count(key))
    return cache[key];
  long sum = 0;
  if (l == 1) {
    sum = 1;
  } else {
    if (h > 0)
      sum += countLunlun(l - 1, h - 1, cache);
    sum += countLunlun(l - 1, h, cache);
    if (h < 9)
      sum += countLunlun(l - 1, h + 1, cache);
  }
  cache[key] = sum;
  return sum;
}

long kthLunlun(int k, map<pair<int, int>, long> cache) {
  int l = 1;
  long step = 1;
  int h = 1;
  long x = 1;
  int k2 = k;
  while (1) {
    if (k2 == 0 && l == 1) {
      return x;
    }
    int s = countLunlun(l, h, cache);
    if (k2 < s) {
      l--;
      step /= 10;
      h = h - 1;
      if (h < 0)
        h = 0;
      x += h * step;
      continue;
    }
    k2 -= s;
    h++;
    x += step;
    if (h == 10) {
      h = 1;
      l++;
      step *= 10;
      //k2 = k;
    }
  }
}

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

  map<pair<int, int>, long> cache;
  long answer = kthLunlun(k - 1, cache);

  cout << answer << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<29;
const ll LINF = 1LL<<58;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> H(n);
    int flag[101010] = {0};
    rep(i, n) cin >> H[i];
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (H[a] >= H[b]) {
            flag[b] = 1;
        }
        if (H[b] >= H[a]) {
            flag[a] = 1;
        }
    }
    int ans = 0;
    rep(i, n) {
        if (flag[i] == 0) ans++;
    }
    cout << ans << endl;
    return;
}

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


Measured memory_bytes: 4024
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_imports)]

use std::io::stdin;
use std::str::FromStr;
use std::cmp::min;
use std::process::exit;

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

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut str = String::new();
    stdin().read_line(&mut str).ok();
    str.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_n_vec<T: FromStr>(n: u64) -> Vec<Vec<T>> {
    let mut v_outer = Vec::new();
    for _ in 0..n {
        let v_inner = read_vec();
        v_outer.push(v_inner);
    }
    v_outer
}

fn main() {
    let n: u32 = read();
    println!("{}", (n + (2 - 1)) / 2);
}

Measured memory_bytes: 4352
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    n = ni()
    d = []
    for _ in range(2 * n):
        a, b = ns()
        d.append((a, b, _ // n))

    d.sort(key=lambda x: x[2], reverse=True)
    d.sort()
    pool = []
    r, b = 0, 1
    ans = 0
    for a, b, c in d:
        if c == r:
            pool.append(b)
        else:
            tmp = -1
            for pi in pool:
                if pi < b:
                    tmp = max(tmp, pi)
            if tmp != -1:
                ans += 1
                pool.remove(tmp)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9264
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	//for(int i=0;i<N;i++) {}
	public static void main(String[] args) {
		//String S=sc.next();
		
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		long A=sc.nextLong();
		long B=sc.nextLong();
		long N=sc.nextLong();
		
		
		long t=-1000000009;
		long i=0;
		
		if(N%B==B-1) {
			i=N;
		}else {
			i=N-(N%B+1);
			if(i<=0)i=N;
		}
		
		
		t=Math.max(t, (A*i)/B-A*(i/B));
			
		
		p(t);
		
		
		
		
		
		
		
		
		
		
		
	}
	
	
	
	
	
	
	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


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

int main()
{ int n;
  cin>>n;
  int h[n];
  for( int i =0;i<n;i++)
  {
      cin>>h[i];
  }
   int dp[n];
   dp[0]=0;
   for(int i =1;i<n;i++)
   {dp[i]=INT_MAX;}
   for(int i =1;i<n;i++)
   {
        int op1=INT_MAX,op2=INT_MAX;
        if(i-1>=0)
        {  op1 = dp[i-1];
        if(op1!=INT_MAX)
       { op1+= abs(h[i]-h[i-1]); }
        
        }
        if(i-2>=0)
         {  op2 = dp[i-2];
        if(op2!=INT_MAX)
       { op2+= abs(h[i]-h[i-2]); }
        
        }
         dp[i]=min(op1,op2);
         }


         cout<<dp[n-1]<<endl;


    return 0;

}

Measured memory_bytes: 4304
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    char a,b,c,ans;
    cin>>a>>b>>c;
    if(a=='S'&&b=='S'&&c=='S')cout<<0<<"\n";
    else if(a=='R'&&b=='R'&&c=='R')cout<<3<<"\n";
    else if(a=='R'&&b=='R'||b=='R'&&c=='R')cout<<2<<"\n";
    else cout<<1<<"\n";
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n,k,t,u,v,l;
	cin>>n>>k>>t>>u>>v>>l;
	vector<bool>d(10010,false);
	rep(i,n){
		int a;
		cin>>a;
		d[a]=true;
	}
	double sum=0;
	int T=0;
	int hav=0;
	rep(i,l){
		if(d[i]){
			sum+=1./v;
			if(hav==k){
				T=t*v-1;
			}else if(T){
				T--;
				hav++;
			}else{
				T=t*v-1;
			}
		}else{
			if(T){
				T--;
				sum+=1./v;
			}else if(hav){
				hav--;
				T+=t*v-1;
				sum+=1./v;
			}else sum+=1./u;
			
		}
	}
	printf("%.8f\n",sum);
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

// Convex Hull Trick
// verify: https://atcoder.jp/contests/dp/tasks/dp_z
// 直線 ax+b 追加 O(1)
// x における最小値取得 O(1)
struct ConvexHullTrick {
    struct Line {
        long long a, b;
        long long get(long long x) { return a * x + b; }
    };
    deque<Line> que;
    bool check(Line a, Line b, Line c) {
        return (b.b - c.b) * (b.a - a.a) <= (a.b - b.b) * (c.a - b.a);
    }
    void add(long long a, long long b) {
        Line l{a, b};
        while(que.size() > 1 && check(que[que.size() - 2], que.back(), l))
            que.pop_back();
        que.push_back(l);
    }
    long long query(long long x) {
        if(que.empty()) return INT64_MAX;
        while(que.size() > 1 && que[0].get(x) >= que[1].get(x))
            que.pop_front();
        return que[0].get(x);
    }
};

ll dp[210000];

int main() {
    cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20);

    ll N, C;
    cin >> N >> C;
    vll h(N);
    rep(i, N) cin >> h[i];

    rep(i, 210000) dp[i] = INF;
    dp[0] = 0;
    ConvexHullTrick cht;
    cht.add(-2*h[0], dp[0] + h[0]*h[0]);
    for(ll i = 1; i < N; i++) {
        chmin(dp[i], cht.query(h[i]) + h[i]*h[i] + C);
        cht.add(-2*h[i], dp[i] + h[i]*h[i]);
    }
    cout << dp[N-1] << endl;
}


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

using namespace std;

typedef long long ll;

const int N = 2000;

long double x[N], y[N], r[N];
long double a[N][N];

long double dist(long double x1, long double y1, long double x2, long double y2) {
    return sqrt(pow(x1 - x2, 2.0) + pow(y1 - y2, 2.0));
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> x[0] >> y[0] >> x[1] >> y[1];
    int n;
    cin >> n;
    for (int i = 2; i < n + 2; ++i) {
        cin >> x[i] >> y[i] >> r[i];
    }
    for (int i = 0; i < n + 2; ++i) {
        for (int j = 0; j < n + 2; ++j) {
            a[i][j] = max(0.0L, dist(x[i], y[i], x[j], y[j]) - r[i] - r[j]);
        }
    }
    vector<long double> d(n + 2, 1e10);
    d[0] = 0;
    set<pair<long double, int>> q;
    q.insert({ 0, 0 });
    while (!q.empty()) {
        int v = q.begin()->second;
        q.erase(q.begin());
        for (int j = 0; j < n + 2; ++j) {
            if (d[v] + a[v][j] < d[j]) {
                q.erase({ d[j], j });
                d[j] = d[v] + a[v][j];
                q.insert({ d[j], j });
            }
        }
    }
    cout << fixed << setprecision(30) << d[1];
    return 0;
}

Measured memory_bytes: 32384
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val n = readLine.trim.toInt
  val from = readLine.trim.split(' ').map(_.toInt)
  val to = readLine.trim.split(' ').map(_.toInt)
  val fromSet = new Set(from)
  val toSet = new Set(to)
  val (fromA, fromB) = from.sorted.let{a ⇒ (a.head, a(a.length - 1))}
  if (fromSet.size == 1 || from.forall(f ⇒ toSet.contains(f))) {
    println("Yes")
  }else {
    println("No")
    println(
      from.indices.map(_ ⇒ fromA).mkString(" ")
    )
    println(
      from.indices.map{
        case i if toSet.contains(from(i)) ⇒ fromA
        case _ ⇒ fromB
      }.mkString(" ")
    )
  }

  class Set[T](factors: Array[T])(implicit ordering: Ordering[T]) {
    private val mList: Array[T] = factors.distinct.sorted
    def contains(value:T): Boolean = {
      lowerBound(mList, value) match {
        case Some(i) ⇒ mList(i) == value
        case None ⇒ false
      }
    }
    def size: Int = mList.size


  }
  def lowerBound[T](array: Array[T], target: T)(implicit ordering: Ordering[T]): Option[Int] = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (ordering.compare(array(mid), target) < 0){
        left = mid + 1
      }else {
        right = mid
      }
    }
    if (right == array.length) None
    else Some(right)
  }


  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 158596
import itertools
s = input()
ans=0
for i in list(itertools.product([0,1], repeat=len(s)-1)):
  b = 0
  a = s[0]
  for j in range(len(s)-1):
    if i[j] == 0:
      a+=s[j+1]
    else:
      b+=int(a)
      a=s[j+1]
  b+=int(a)
  ans+=b
print(ans)

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

using namespace std;
const int mod = 1e9 +7;
long long pot(long long a,long long b) {
  long long x=a;
  long long wyn=1;
  while (b!=0) {
   if ( b%2==1) {
     wyn*=x;
     wyn%=mod;
   }
   x*=x;
   x%=mod;
   b/=2;
  }
  return wyn;
}

int main(){
  int h,w;
  long long k;
  cin>>h>>w>>k;
  bool s[h][w];
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      char c;
      cin>>c;
      s[i][j]= (c=='#')? 1:0;
    }
  }
  long long a=0,b=0,wi=0;
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      if ( i<h-1){
        if ( s[i][j]==1 && s[i+1][j]==s[i][j]){
          a++;
        }
      }
      if(j<w-1) {
        if ( s[i][j]==1 && s[i][j+1]==s[i][j]){
          b++;
        }
      }
      if ( s[i][j]==1) wi++;
    }
  }
  long long aa=0,bb=0;
  for(int i=0;i<h;i++) if( s[i][0]==s[i][w-1] && s[i][0]==1) bb++;
  for(int i=0;i<w;i++) if( s[0][i]==s[h-1][i] && s[0][i]==1) aa++;
  if ( aa>0 && bb>0 || k==0) {
    cout<<1<<endl;
    return 0;
  }
  if (aa==0) {
    swap(aa,bb);
    swap(a,b);
  }
  //cout<<a<< " "<<aa<<endl;
  long long od=a;
  od*= pot( wi,k-1);
  od%=mod;
  od*=pot(aa,mod-2);
  od%=mod;
  long long odw=pot(wi,mod-2);
  long long p=aa*odw;
  p%=mod;
  //cout<<p<< " "<<k-1<<endl;
  long long oo=(((pot(p,k)-1)%mod)*pot(p-1,mod-2)-1)%mod;
  //cout<<oo*a<<endl;
  od*=oo;
  od%=mod;
  long long wyn = pot(wi,k-1)+mod;
  wyn-=od;
  wyn%=mod;
  cout<<wyn;
}


Measured memory_bytes: 1280
using System;
using System.Collections.Generic;
             
public static class Program
{
    public static void Main()
    {
        int[] R = GetIntArray();
        int N = R[0];
        int A = R[1];
        int B = R[2];
        Console.WriteLine(Math.Min(A, B).ToString() + " " +  Math.Max((A + B - N), 0).ToString());
    }
    
    private static string ReadLine()
    {
    	return Console.In.ReadLine();
    }
    
    public static int[] GetIntArray()
    {
    	List<int> temp = new List<int>();
    	foreach (string c in ReadLine().Split(' '))
            temp.Add(int.Parse(c));
        return temp.ToArray();
    }
    
    public static int GetInt()
    {
    	return int.Parse(ReadLine());
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
    int n;
    double pm,z,z1 = 0;
    cin >> n;
    int x[n],y[n];
    for(int i = 0;i<n;i++){
        cin >> x[i];
    }
    for(int j = 0;j<n;j++){
        cin >> y[j];
    }
    double P;
    for(int p = 1;p<4;p++){
        P = 0;
        for(int k = 0;k<n;k++){
            z = fabs(x[k]-y[k]);
            P += (double)pow(z,p);
        }
        P =(double) pow(P,1.0/p);
        printf("%lf\n",P);
    }
    for(int i = 0;i<n;i++){
        z = (double)fabs(x[i]-y[i]);
        if(z>z1){
                z1 = z;
            }
    }
    printf("%lf\n",z1);
    return 0;
}


Measured memory_bytes: 3348
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

x, y = map(int, input().split())

a=(2*x-y)/3
b=(2*y-x)/3

if a==int(a) and b==int(b) and a>=0 and b>=0:
    #print(a+b,b)
    kosu=cmb(int(a+b), int(b))
    print(kosu%(10**9+7))
else:    
    print(0)

Measured memory_bytes: 102028
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<vector>
using namespace std;

int main(){
	int N,T,t[200005];
	scanf("%d%d",&N,&T);
	int ans = 0,remain = 0;
	for(int i = 1;i <= N;i++){
		scanf("%d",&t[i]);
		ans += (t[i] + T);
		ans -= max(t[i],remain);
		remain = t[i] + T;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define N 2502
using namespace std;
int n,m,p,dis[N];
struct node{
	int u,v,w;
}e[5002];
vector<int>s[N];
int vis[N][N];
void dfs(int st,int x){
	vis[st][x]=1;
	for(int i=0;i<s[x].size();i++){
		int to=s[x][i];
		if(vis[st][to])continue;
		dfs(st,to);
	}
}
int Bellman_ford(){
	memset(dis,-125,sizeof(dis));
	dis[1]=0;
	for(int i=1;i<=n;i++){
		int f=0;
		for(int j=1;j<=m;j++)
		if(vis[1][e[j].u]&&vis[e[j].v][n]&&dis[e[j].u]+e[j].w>dis[e[j].v])
		dis[e[j].v]=dis[e[j].u]+e[j].w,f=1;
		if(!f)break;
		if(i==n)return -1;
	}
	return max(0,dis[n]);
}
int main(){
	scanf("%d%d%d",&n,&m,&p);
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w),e[i].w-=p;
		s[e[i].u].push_back(e[i].v);
	}
	for(int i=1;i<=n;i++)dfs(i,i);
	printf("%d\n",Bellman_ford());
	return 0;
}

Measured memory_bytes: 25088
n,m=map(int,input().split())
ps=[list(input().split()) for i in range(m)]
pen=[0]*n
rig=[0]*n

for i in range(m):
  if ps[i][1] == "AC":
    rig[int(ps[i][0])-1]=1
  else:
    if rig[int(ps[i][0])-1] == 0:
      pen[int(ps[i][0])-1]+=1

cnt1,cnt2=0,0
for i in range(n):
  if rig[i]==1:
    cnt1+=rig[i]
    cnt2+=pen[i]
    
print(str(cnt1)+" "+str(cnt2))


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

typedef long long ll;

int main() {
    while (true) {
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0) return 0;
        int ans = 0;
        for (int i = 1; i <= n - 2; i++) {
            for (int j = i + 1; j <= n - 1; j++) {
                for (int k = j + 1; k <= n; k++) {
                    if (i + j + k == x) ans++;
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <climits>
#include <set>
#include <queue>

#define DEBUG(x) cout << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {

	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";

    return out;

}

bool is_row_white(vector<char>& v) {
	for (int i = 0; i < v.size(); ++i) {
		if (v[i] != '.')
			return false;
	}
	return true;
}

bool is_column_white(vector<vector<char>>& v, int col) {
	for (int i = 0; i < v.size(); ++i) {
		if (v[i][col] != '.')
			return false;
	}
	return true;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int h, w;
	cin >> h >> w;

	vector<vector<char>> grid(h, vector<char>(w));
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			cin >> grid[i][j];
		}
	}

	vector<int> white_row_indices, white_col_indices;
	for (int i = 0; i < h; ++i) {
		if (is_row_white(grid[i])) {
			white_row_indices.push_back(i);
		}
	}

	for (int i = 0; i < w; ++i) {
		if (is_column_white(grid, i)) {
			white_col_indices.push_back(i);
		}
	}

	for (int i = 0; i < white_row_indices.size(); ++i) {
		for (int j = 0; j < w; ++j) {
			grid[white_row_indices[i]][j] = ' ';
		}
	}
	for (int i = 0; i < white_col_indices.size(); ++i) {
		for (int j = 0; j < h; ++j) {
			grid[j][white_col_indices[i]] = ' ';
		}
	}

	bool skip_line;
	for (int i = 0; i < h; ++i) {
		skip_line = false;
		for (int j = 0; j < w; ++j) {
			if (grid[i][j] != ' ') {
				cout << grid[i][j];
				skip_line = true;
			}
		}
		if (skip_line)
			cout << "\n";
	}

	return 0;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    
    int antennas[6] = {};
    
    for(int i = 0;i < 6;i++){
        
        do{
            
            scanf("%d",&antennas[i]);
            
        }while(antennas[i] < 0 || antennas[i] > 123);
    }
    
    for(int i = 0;i < 4;i++){
        
        for(int j = i + 1;j < 5;j++){
            
            if((antennas[j] - antennas[i]) > antennas[5]){
                
                printf(":(");
                return 0;
            }
        }
    }
    
    printf("Yay!");
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;
//



     signed main(){
 int a[3];
 cin>>a[0]>>a[1]>>a[2];
 cout<<max({a[0],a[1],a[2]})-min({a[0],a[1],a[2]})<<endl;
     }


 


 






    





      

        


Measured memory_bytes: 3640
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
s = gets.chomp.split('/').map(&:to_i)

h = "Heisei"
t = "TBD"
if s[0] < 2019
  puts h
elsif s[0] > 2019
  puts t
else
  if s[1] <= 4
    puts h
  elsif s[1] > 4
    puts t
  end
end

Measured memory_bytes: 2556
N,E,r=map(int,input().split())
G=[]
for i in range(E):
    s,t,d=map(int,input().split())
    G.append([d,s,t])
def bellman_ford(G,s):
    INF=10**9
    d=[INF]*N
    d[s]=0
    j=0
    while(True):
        update=False
        for i in range(E):
            cost,fro,to=G[i]
            if d[fro]!=INF and d[to]>d[fro]+cost:
                d[to]=d[fro]+cost
                update=True
                if j==N-1:
                    return True,0#負の閉路あり
        j+=1
        if not(update):
            break
    return False,d#負の閉路なし、ｓからの最短距離ｄ
bool,d=bellman_ford(G,r)
if bool:
    print("NEGATIVE CYCLE")
else:
    for i in range(N):
        if d[i]==10**9:
            print("INF")
        else:
            print(d[i])



Measured memory_bytes: 6124
#include<bits/stdc++.h>
using namespace std;
queue<long long> yui;
int main()
{
    int k;
    cin>>k;
    for(int i=1;i<10;i++) yui.push(i);
    while(--k)
    {
        long long x=yui.front();
        int y=x%10;
        yui.pop();
        for(int i=max(0,y-1);i<=min(9,y+1);i++)
        yui.push(x*10+i);
    }
    cout<<yui.front();
}

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

int main()
{
	int A, B, X;
	cin >> A >> B >> X;

	int cost = 0;
	if (B * 2 <= A) {
		cost = (X / 500)*B;
		if (X % 500 != 0) {
			cost = cost + B;
		}
	}
	else {
		cost = (X / 1000)*A;
		if (X % 1000 != 0) {
			if (X % 1000 <= 500 && A > B) {
				cost = cost + B;
			}
			else {
				cost = cost + A;
			}
		}
	}
	cout << cost << endl;
	return 0;
}


Measured memory_bytes: 3108
/* 参考 */
/* https://drken1215.hatenablog.com/entry/2020/03/08/020200 */

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()

int main(){
    int n, p;
    string s;
    cin >> n  >> p >> s;

    if(p == 2 || p == 5) {
        ll ans = 0;
        REP(i, n) {
            if((s[n - 1 - i] - '0') % p == 0) {
                ans += n - i;
            }
        }

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

    vector<long long> val(p, 0);    /* あまりが0 - p-1になる数 */
    ll ten_ruijo_amari = 1;
    ll cur = 0;
    val[cur]++;

    REP(i, n) {
        cur = (cur + (s[n - 1 - i] - '0') * ten_ruijo_amari) % p;
        ten_ruijo_amari = (ten_ruijo_amari * 10) % p;
        val[cur]++;
    }

    ll ans = 0;
    REP(i, p) ans += val[i] * (val[i] - 1) / 2;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
s=SI()
for i in range(len(s)):
    if s[i]=="?":
        print("D",end="")
    else:
        print(s[i],end="")

Measured memory_bytes: 9576
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int main()
{
  lint n;
  cin >> n;
  std::vector<lint> a(n);
  REP(i,n) cin >> a[i];

  lint head = 0,tail = n-1,cnt = 0;
  while(head != tail){
    if(cnt <= 0){
      cnt += a[head];
      head++;
    }
    else{
      cnt -= a[tail];
      tail--;
    }
  }
  if(cnt < 0) cnt += a[head];
  else cnt -= a[head];
  /*
  if(n%2 == 1){
    if(cnt < 0) cnt += a[n/2];
    else cnt -= a[n/2];
  }*/

  cout << abs(cnt) << "\n";
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;

int main(){

	pair<double,int> info;
	pair<double,int> data[3][8];
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 8; j++){
			cin>>data[i][j].second>>data[i][j].first;
		}
	}
	for(int i = 0; i < 3; i++)
		sort(data[i],data[i]+8);

	pair<double,int> lose[18];
	int idx=0;
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 8; j++){
			if(j<=1){
				cout<<data[i][j].second<<" "<<data[i][j].first<<endl;
			}
			else{
				lose[idx].first=data[i][j].first;
				lose[idx].second=data[i][j].second;
				idx++;
			}
		}
	}
	sort(lose,lose+18);
	for(int i = 0; i < 2; i++){
		cout<<lose[i].second<<" "<<lose[i].first<<endl;
	}
	

	return 0;
}

Measured memory_bytes: 0