akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

INF = 10**10
n = int(input())
T = [[] for _ in range(n+1)]
for _ in range(n-1):
  a, b = map(int, input().split())
  T[a].append(b)
  T[b].append(a)
k = int(input())
VP = tuple(tuple(map(int, input().split())) for _ in range(k))
P = [-1]*(n+1)
A = [-1]*(n+1)
r, c = VP[0]
for v, p in VP:
  P[v] = p
def dfs1(v, par=-1, color=c%2):
  if P[v] == -1:
    l = -INF
    r = INF
  else:
    l = P[v]
    r = P[v]
  for nv in T[v]:
    if nv == par:
      continue
    nl, nr = dfs1(nv, v, color^1)
    l = max(l, nl-1)
    r = min(r, nr+1)
  if l&1 ^ color:
    l += 1
  if r&1 ^ color:
    r -= 1
  if l > r:
    print("No")
    exit()
  P[v] = (l, r)
  return P[v]
dfs1(r)
def dfs2(v, ini, par=-1):
  l, r = P[v]
  if l == r:
    A[v] = l
  else:
    if l <= ini-1 <= r:
      A[v] = ini-1
    else:
      A[v] = ini+1
  for nv in T[v]:
    if nv == par:
      continue
    dfs2(nv, A[v], v)
dfs2(r, P[r][0])
print("Yes")
print(*A[1:], sep="\n")

Measured memory_bytes: 198532
import sys
from collections import deque
import copy
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
  t=sum(B)
  j=m
  ans=0
  for i in range(n+1):
    while j>0 and t>k:
      j-=1
      t-=B[j]
    if t>k:
      break
    ans=max(ans,i+j)
    if i==n:
      break
    t+=A[i]
  print(ans)


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

#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); i++)
#define FORR(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) FOR (i, 0, n)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T>
void print(const vector<vector<T>> matrix);
template <typename T>
void print(const vector<T> vec);
template <typename Arg>
void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
using ll = long long;

int main() {
    ll N;
    cin >> N;
    vector<ll> vec(N + 2);
    rep (i, N)
        cin >> vec[i + 1];
    ll sum = 0;
    rep (i, N + 1)
        sum += abs(vec[i + 1] - vec[i]);

    rep (i, N) {
        ll orig = abs(vec[i + 2] - vec[i + 1]) + abs(vec[i + 1] - vec[i]);
        ll new_ = abs(vec[i + 2] - vec[i]);
        print(sum + (new_ - orig));
    }

    return 0;
}

//---------------------------------------------
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int a, b, c; cin >> a >> b >> c;
    bool isOK = false;
    for(int i = 1; i <= b; i++){
        if(a*i % b == c) isOK = true;
    }
    if(isOK) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
n = 2019
arr = { 0 => 1 }
s = gets.chop.chars.reverse
digit = 1
sum = 0
s.each do |i|
  sum += (i.to_i * digit) % n
  sum %= n
  digit *= 10 % n
  digit %= n

  arr[sum] = arr[sum].to_i + 1
end
pp arr.values.sum{ |x| x * (x - 1) / 2 }


Measured memory_bytes: 26656
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String s = S.substring(2,S.length()-1);
        int count = 0;
        int memo = 0;
        boolean judge = false;

        if(S.charAt(0) == 'A'){
            for(int i = 0;i < s.length();i++){
                if(s.charAt(i) == 'C'){
                    count++;
                    memo = i+2;
                }
            }
            if(count == 1){
                for(int i = 1;i < S.length();i++){
                    if(i != memo){
                        if(Character.isUpperCase(S.charAt(i))){
                            judge = false;
                            break;
                        }else{
                            judge = true;
                        }
                    }
                    
                }
            }
        }
        if(judge == true){
            System.out.println("AC");
        }else{
            System.out.println("WA");
        }
    }
}

Measured memory_bytes: 21844
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import deque
def resolve():
    m, n = map(int, input().split())
    grid = [input() for _ in range(m)]

    Q = deque()
    dist = [[INF] * n for _ in range(m)]
    for i in range(m):
        for j in range(n):
            if grid[i][j] == '#':
                dist[i][j] = 0
                Q.append((i, j))

    D = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    while Q:
        i, j = Q.popleft()
        for di, dj in D:
            ni, nj = i + di, j + dj
            if not (0 <= ni < m and 0 <= nj < n):
                continue
            if dist[ni][nj] != INF:
                continue
            dist[ni][nj] = dist[i][j] + 1
            Q.append((ni, nj))


    print(max(dist[i][j] for i in range(m) for j in range(n)))
resolve()

Measured memory_bytes: 87004
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int N =sc.nextInt();
    int K=sc.nextInt();
    int m[] =new int[N];
    int d[] =new int[K];
    int n;int x=0;
    for(int i=0;i<K;i++){
      d[i]=sc.nextInt();
      for(int j=0;j<d[i];j++){
        n=sc.nextInt();
        m[n-1]=m[n-1]+1;}
    }
    for(int l=0;l<N;l++){
      if(m[l]==0){x=x+1;}}
    System.out.println(x);
  }
}

Measured memory_bytes: 46216
# https://atcoder.jp/contests/agc019/tasks/agc019_b
from collections import defaultdict

A = input()
n = len(A)
cA = defaultdict(int)

for ch in A:
    cA[ch] += 1

all_num = 1 + n * (n - 1) // 2

for _, v in cA.items():
    all_num -= v * (v - 1) // 2

print(all_num)



Measured memory_bytes: 40924
/*
	筆者:DriverBen
    コメント:
*/
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define ls t[rt].l
#define rs t[rt].r
using namespace std;
const int maxn=500000+100;
int head[maxn];
int p[maxn],in[maxn],a[maxn];
struct edge{
	int to,next;
}e[maxn<<1];
struct segment_tree{
	int l,r,mi;
	segment_tree(){mi=inf;}
}t[maxn<<1];
int size=0,cnt,root,v,res,n,k;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
void addedge(int u,int v){
	e[++size].to=v;e[size].next=head[u];head[u]=size;
}
void build(int l,int r,int &rt){
	if(!rt)rt=++cnt;
	if(l==r)return;
	int m=(l+r)>>1;
	build(l,m,ls);
	build(m+1,r,rs);
}
void query(int l,int r,int rt,int L,int R){
	if(L<=l&&r<=R){
		res=min(res,t[rt].mi);
		return;
	}
	int m=(l+r)>>1;
	if(L<=m)query(l,m,ls,L,R);
    if(m<R)query(m+1,r,rs,L,R);
}
void update(int l,int r,int rt,int pos,int c){
	if(l==r){
		t[rt].mi=c;
		return;
	}
	int m=(l+r)>>1;
	if(pos<=m)update(l,m,ls,pos,c);
	else update(m+1,r,rs,pos,c);
	t[rt].mi=min(t[ls].mi,t[rs].mi);
} 
void topo(){
	priority_queue<int,vector<int>,greater<int> >q;
	for(int i=1;i<=n;++i)if(!in[i])q.push(i);
	while(!q.empty()){
		int u=q.top();
		q.pop();
		a[u]=++v;
		for(int i=head[u];i;i=e[i].next){
			int to=e[i].to;
			in[to]--;
			if(!in[to])q.push(to);
		}
	}
}
int main(){
	n=read();k=read();
	for(int i=1;i<=n;++i)p[read()]=i;
	build(1,n,root);
	for(int i=n;i;--i){
		res=inf;
		query(1,n,1,min(p[i]+1,n),min(p[i]+k-1,n));
		if(res!=inf)addedge(p[i],p[res]),in[p[res]]++;
		res=inf;
		query(1,n,1,max(p[i]-k+1,1),max(p[i]-1,1));
		if(res!=inf)addedge(p[i],p[res]),in[p[res]]++;
		update(1,n,1,p[i],i);
	} 
	topo();
	for(int i=1;i<=n;++i)printf("%d\n",a[i]);
	return 0;
}


Measured memory_bytes: 31088
#include <iostream>
#include <string>
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
using namespace std;

int main() {
    string s;
    cin >> s;
    int counter = 0;
    REP(i,s.size()) {
        if (s[i] == '1') counter++;
    }
    cout << counter << endl;
}

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

const LL mod=1e9+7;
const int N=1e5+10;
LL a[N],b[N],n,m;

int main()
{
    LL pre,now;
    scanf("%lld%lld",&n,&m);
    for(int i=0; i<n; i++)
    {
        scanf("%lld",&now);
        if(i) a[i]=(now-pre)%mod;
        pre=now;
    }
    for(int i=0; i<m; i++)
    {
        scanf("%lld",&now);
        if(i) b[i]=(now-pre)%mod;
        pre=now;
    }
    LL cnt = 1,sum1=0,sum2=0;
    int Left=1,Right=n-1;
    while(Left<=Right)
    {
        sum1=(sum1+a[Left]*cnt%mod*(n-cnt)%mod)%mod;
        if(Right!=Left)
            sum1=(sum1+a[Right]*cnt%mod*(n-cnt)%mod)%mod;
        Right--;
        Left++;
        cnt=(cnt+1)%mod;
    }
    cnt = 1;
    Left = 1;
    Right = m - 1;
    while(Left<=Right)
    {
        sum2=(sum2+b[Left]*cnt%mod*(m-cnt)%mod*sum1%mod)%mod;
        if(Right!=Left) sum2=(sum2+b[Right]*cnt%mod*(m-cnt)%mod*sum1%mod)%mod;
        Right--;
        Left++;
        cnt=(cnt+1)%mod;
    }
    printf("%lld\n",sum2%mod);
    return 0;
}




Measured memory_bytes: 1792
package main

import (
	"fmt"
)

func main() {
	var n int

	fmt.Scan(&n)
	a := make([]int, n)
	dic := make(map[int]int, 0)
	isDistinct := false
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		if _, exist := dic[a[i]]; exist {
			isDistinct = true
		}
		dic[a[i]]++
	}

	if isDistinct {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}


Measured memory_bytes: 15360
#include<bits/stdc++.h>
using namespace std;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,a,b,c,d;
int main() {
    cin>>n>>a>>b>>c>>d;
    for(int m=0;m<=n-1;m++) {
        long long lb=1ll*c*(n-1-m)-1ll*d*m,rb=-1ll*c*m+1ll*(n-1-m)*d;
        if(lb<=b-a&&b-a<=rb) return puts("YES"),0;
    }
    puts("NO");
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
import sys
sys.setrecursionlimit(10 ** 6)


def dfs(n):
    if memo[n] >= 0:
        rst = memo[n]
    else:
        tmp = n
        one = 0
        while tmp > 0:
            one += tmp & 1
            tmp >>= 1
        m = n % one
        rst = 1 if m == 0 else 1 + dfs(m)
        memo[n] = rst
    return rst


N = int(input())
# X = input()
X = list(map(int, list(input())))
one = Counter(X)[1]


if one > 1:
    Sm = 0
    mm = one - 1
    tm = 1
    for i in range(N - 1, -1, -1):
        tm %= mm
        if X[i] == 1:
            Sm += tm
            Sm %= mm
        tm *= 2

Sp = 0
mp = one + 1
tp = 1
for i in range(N - 1, -1, -1):
    tp %= mp
    if X[i] == 1:
        Sp += tp
        Sp %= mp
    tp *= 2


memo = [-1] * (2 * (10 ** 5) + 10)
memo[0] = 0

# x = int(X, 2)
# for i in range(N):
#     ans = dfs(x ^ (1 << ((N - 1) - i)))
#     print(ans)
for i in range(N):
    if one == 1:
        if X[i] == 0:
            m = (Sp + pow(2, N - 1 - i, mp)) % mp
            if m == 0:
                print(1)
            else:
                print(1 + dfs(m))
        else:
            print(0)
        continue

    if X[i] == 0:
        m = (Sp + pow(2, N - 1 - i, mp)) % mp
    else:
        m = (Sm - pow(2, N - 1 - i, mm)) % mm
    
    if m == 0:
        print(1)
    else:
        print(1 + dfs(m))


Measured memory_bytes: 96260
#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define N 300005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
main()
{
    ll n,d;
    cin>>n>>d;
    ll c=0;
    d=d*d;
    for(int i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        x=x*x+y*y;
        if(x<=d)
            c++;
    }
    cout<<c;
}



Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;
const int maxn = 1e5 + 10;
const ll oo = 0x3f3f3f3f3f3f3f3f;
class Point{
public:
	ll x;
	int v;
};
Point p[maxn];
int n;
ll C;
ll ans = 0;
bool cmp(Point p1 , Point p2){
	return p1.x < p2.x;
}

ll sum[maxn];
void solve(){
	sort(p + 1 , p + n + 1 , cmp);
	sum[0] = 0;
	ll cur = 0 , mx = 0;
	for(int i = 1 ; i <= n ; ++ i){
		cur += p[i].v - (p[i].x - p[i - 1].x);
		if(cur > mx) mx = cur;
		sum[i] = mx;
	}
	ans = max(ans , sum[n]);
	ll now = 0;
	for(int i = n ; i >= 1 ; -- i){
		now += p[i].v;
		ans = max(ans , sum[i - 1] - 2 * (C - p[i].x) + now);
	} 
}
int main(){
	ios::sync_with_stdio(0);
	cin >> n >> C;
	for(int i = 1 ; i <= n ; ++ i)
		cin >> p[i].x >> p[i].v;
	solve();
	for(int i = 1 ; i <= n ; ++ i)
		p[i].x = C - p[i].x;
	solve();
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    ll q = 0, h = 0, s = 0, d = 0;
    cin >> q >> h >> s >> d;
    ll n = 0;
    cin >> n;
    ll ans = 0;
    ll two = min(q*8, min(h*4, min(s*2, d)));
    ll one = min(q*4, min(h*2, s));
    while (n > 0) {
        if (n >= 2) {
            ans += two;
            n -= 2;
        }
        else {
            ans += one;
            n -= 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import math

while True:
    n = int(input())
    if n == 0:
        break

    s = list(map(int, input().split()))

    m1 = 0
    m2 = 0
    for x in s:
        m1 += x
        m2 += x * x
    m1 /= n
    m2 /= n

    print("{:.5f}".format((m2 - m1 * m1) ** 0.5))



Measured memory_bytes: 5712
from functools import reduce

MOD = 1000000000 + 7
LETTERS = ["A", "C", "G", "T"]
PROHIBIT = ["AGC", "ACG", "GAC", "AGGC", "AGTC", "ATGC"]

def main():
    n = int(input().strip())

    table = {}

    for first in LETTERS:
        for second in LETTERS:
            for third in LETTERS:
                codon = first+second+third
                if not codon in PROHIBIT:
                    table[codon] = [1]

    for i in range(n-3):
        for codon in table.keys():
            table[codon].append(0)

        for codon in table.keys():
            for append in LETTERS:
                three_letters = codon[1:] + append
                four_letters = codon + append

                if (not four_letters in PROHIBIT) and (not three_letters in PROHIBIT):
                    table[three_letters][i+1] = (table[three_letters][i+1] + table[codon][i]) % MOD

    print(reduce(lambda acc, x: (acc + x[-1]) % MOD, table.values(), 0))

if __name__ == "__main__":
    main()


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

#define MAX 1000000
typedef long long ll;

void ESieve(ll n, vector<bool> &ispr) {
  ispr.assign(n+1, true);
  ispr[0] = ispr[1] = false;
  
  for(int i=0; (ll)i*i<=n; i++) {
    if(ispr[i]) {
      for(int j=2*i; j<=n; j+=i) {
	ispr[j] = false;
      }
    }
  }
}

int main() {
  vector<bool> isPrime;
  ESieve(MAX, isPrime);

  int n;
  while(cin>>n, n) {
    int res = 0;
    for(int i=2; i<=n/2; i++) {
      if(isPrime[i] && isPrime[n-i]) {
	res ++;
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1320
def A(test=None):

    if test:
        pass
    else:
        S = input()
    
    continuous = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            continuous += 1
    
    if continuous > 0:
        answer = 'Bad'
    else:
        answer = 'Good'
        
    print(answer)
    

def main():
    A()


if __name__ == '__main__':
    main()


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


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

	int ans = 0;
	for(int i=0;i<N;i++) {
		int a;
		cin >> a;
		while(a % 2 == 0) {
			ans++;
			a /= 2;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
K = int(input())
L = [[1,2,3,4,5,6,7,8,9]]
M = 9 #(M+1)桁まで考える

for i in range(M):
    X = []
    for n in L[-1]:
        t = n % 10
        if t == 0:
            X.append(n * 10 + t)
            X.append(n * 10 + t + 1)
        elif t == 9:
            X.append(n * 10 + t - 1)
            X.append(n * 10 + t)
        else:
            X.append(n * 10 + t- 1)
            X.append(n * 10 + t)
            X.append(n * 10 + t + 1)
    L.append(X)

L2 = []
for i in range(len(L)):
    L2 += L[i]

L2.sort()
print(L2[K-1])

Measured memory_bytes: 53872
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b; cin >> a >> b;
  cout << (a <= 8 && b <= 8 ? "Yay!" : ":(") << "\n";
  return 0;
}


Measured memory_bytes: 3624
fun main() {
    val s = readLine()!!
    val t = readLine()!!

    (0..s.length - t.length).map { s.subSequence(it, it + t.length) }.map {
        it.zip(t).filter { (a, b) -> a == b }.count()
    }.max().let { println(t.length - it!!) }
}


Measured memory_bytes: 49748
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

char arr[57][57];
int main(){
	Lancer();
	ll x,y,z,res;
	cin >> x >> y>>z;
	x -= z;
	res = x / (y + z);
	cout << res;
	cout << endl;
	return 0;
}


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

int main()
{
    string devide[4] = {
        "dream",
        "dreamer",
        "erase",
        "eraser",
    };
    rep(i, 4) reverse(devide[i].begin(), devide[i].end());
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    bool can = true;
    for (int i = 0; i < s.size();)
    {
        bool can2 = false;
        rep(j, 4)
        {
            string d = devide[j];
            if (s.substr(i, d.size()) == d)
            {
                can2 = true;
                i += d.size();
            }
        }
        if (!can2)
        {
            can = false;
            break;
        }
    }
    if (can)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;


int n,m;
vector<vi> g;


struct st{
    int u,c,rem;
    st(int u,int rem){
        this->u = u;
        this->rem = rem;
    }
};

bool bfs(){
    queue<st> q;
    
    q.push(st(1,2));
    
    while(q.size()){
        if(q.front().u == n)
            return 1;
        
        if(q.front().rem != 0){
            st u = q.front();
            for(int i=0;i<g[ u.u ].size();i++){
                q.push(st(g[u.u][i] , u.rem - 1));
            }
        }
        q.pop();
    }
    
    return 0;
}

int main(){
   //ios::sync_with_stdio(0);
    //freopen("in.in","r",stdin);
    //freopen("out_1.out","w",stdout);
    
    
    cin>>n>>m;
    g.resize(n+1);
    for(int i=0;i<m;i++){
        int u,v;
        scanf("%d %d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    
    
    if(bfs())
        printf("POSSIBLE\n");
    else
        printf("IMPOSSIBLE\n");
}

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

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

const int N=2;
const LL MOD = 1e9 + 7;
int a[32];
void intialize(){
a[0]=a[1]=a[2]=a[4]=a[6]=a[10]=a[12]=a[16]=a[18]=a[22]=a[28]=a[30]=a[14]=1;
a[3]=a[5]=a[8]=a[9]=a[13]=a[20]=a[21]=a[24]=a[25]=2;
a[7]=a[11]=a[17]=a[19]=a[26]=5;
a[15]=14;
a[23]=15;
a[27]=a[29]=4;
a[31]=51;
}




int main()
{
  FastRead;
   int T;
   cin>>T;
   intialize();
   cout<<a[T-1];





   return 0;
}


Measured memory_bytes: 256
import math
import itertools
from functools import lru_cache

N = int(input())

x = [0]*N
y = [0]*N
d = []

@lru_cache(maxsize=1000)
def calc(x1,y1,x2,y2):
        d1 = int((int(x2) - int(x1))** 2)
        d2 = int((int(y2) - int(y1))** 2)
        distance = d1 + d2
        return(math.sqrt(distance))

for i in range(N):
    x[i], y[i] = input().split(' ')

a = list(itertools.permutations(range(N)))

# 順列
for i in range(len(a)):
    b = a[i]
    for j in range(len(b)-1):
            ans = calc(x[b[j]],y[b[j]],x[b[j+1]],y[b[j+1]])
            d.append(ans)

print(sum(d)/len(a))
#print(d/len(a))

Measured memory_bytes: 10680
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e6 + 10 ;
const ll INF = 1e18 + 10 ;
ll fact[N];
ll fastPow(ll a, ll b){
    if ( b == 0 ) return 1 ;
    if ( b == 1 ) return a ;
    ll y = fastPow(a, b / 2) ; 
    if ( b & 1 ){
        return (((y % MOD) * (y % MOD)) % MOD * a) % MOD ;
    }
    else return (y % MOD * y % MOD) % MOD;
}
ll inverse(ll x){
    return fastPow(x, MOD - 2) ; 
}
ll comb(ll n, ll k){
    fact[0] = fact[1] = 1 ; 
    for(ll i = 2; i <= n; i++){
        fact[i] = (fact[i - 1] * i) % MOD;
        fact[i] = fact[i] % MOD ; 
    }
    return (((fact[n] % MOD) * (inverse(fact[k]) % MOD)) % MOD * (inverse(fact[n - k]) % MOD) ) % MOD ;
}
int main(){
    fastio
    ll x , y ; 
    cin >> x >> y ; 
    if ( (x + y) % 3 != 0 ){
        puts("0") ; 
        return 0 ; 
    }
    ll cnt = (x + y) / 3 ;
    x -= cnt , y -= cnt ; 
    if ( x < 0 || y < 0 ) {
        puts("0") ;
        return 0 ; 
    }
    cout << comb(x + y, x) << endl;
    return 0; 
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	int ans = 0;
	map<int,int> cnt;
	rep(_,0,n){
		int a;
		cin >> a;
		++cnt[a];
	}
	while(!cnt.empty()){
		auto it = cnt.end();
		--it;
		pii pa = *it;
		cnt.erase(it);
		int a = pa.first;
		int t = 32 - __builtin_clz(a);
		int tva = 1<<t;
		int b = tva - a;
		if(a == b){
			ans += pa.second/2;
		} else {
			int num = min(pa.second, cnt[b]);
			ans += num;
			cnt[b] -= num;
		}
	}
	cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define INF 2e8
#define all(a) a.begin(), a.end()

int main() {
  int nLen;
  scanf("%d", &nLen);
  vector<int> vcData;
  rep(i, nLen) {
    int nData;
    scanf("%d", &nData);
    vcData.push_back(nData);
  }
  printf("%d\n", *max_element(all(vcData)) - *min_element(all(vcData)));
}


Measured memory_bytes: 256
n,m = (int(i) for i in input().split()) 
a = [int(i) for i in input().split()]
b = []

a.sort(reverse=True)

for i in range(m):
    if i == 0:
        down = a[0]
        a.remove(down)
        b.append(down//2)
    else:
        if a != [] and a[0] >= b[0]:
            down = a[0]
            a.remove(down)
        else:
            down = b[0]
            b.remove(down)
        b.append(down//2)
    
print(sum(a)+sum(b))

Measured memory_bytes: 14252
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val ls = in.map(_.split(' ').map(_.toLong))
  val H = ls(0)(0)
  val W = ls(0)(1)
  
  if(H == 1 || W == 1) println(1)
  else{
    val ret = (H * W + 1) / 2
    println(ret)
  }
}


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

using namespace std;

int n;
vector<int> adj[200010];
int sz[200010], dp[200010], ans[200010];
int f[200010], fi[200010];
const int MOD = 1e9 + 7;

int add() {return 0;}
template<typename... Args>
int add(long long a, Args... args){
    return (a + add(args...)) % MOD;
}

int mul() {return 1;}
template<typename... Args>
int mul(long long a, Args... args){
    return (a * mul(args...)) % MOD;
}


int fp(int a, int b){
    int ret = 1;

    while(b){
        if(b & 1) ret = mul(ret, a);

        a = mul(a, a);
        b >>= 1;
    }

    return ret;
}

int inv(int x){
    return fp(x, MOD - 2);
}

void gen(){
    f[0] = fi[0] = 1;

    for(int i = 1; i <= n; i++){
        f[i] = mul(i, f[i - 1]);
        fi[i] = inv(f[i]);
    }
}

void dfs(int u, int p){
    sz[u] = 1;
    dp[u] = 1;

    for(auto &v : adj[u]){
        if(p == v) continue;

        dfs(v, u);
        sz[u] += sz[v];

        dp[u] = mul(dp[u], dp[v], fi[sz[v]]);
    }

    dp[u] = mul(dp[u], f[sz[u] - 1]);
}

void dfs0(int u, int p, int dpPar){
    ans[u] = mul(dp[u], dpPar, fi[n - sz[u]], f[n - 1], fi[sz[u] - 1]);

    int val = mul(dp[u], dpPar, fi[n - sz[u]]);
    for(auto &v : adj[u]){
        if(v == p) continue;

        dfs0(v, u, mul(val, f[sz[v]], inv(dp[v]), f[n - sz[v] - 1], fi[sz[u] - 1]));
    }
}

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

    gen();

    for(int i = 1; i < n; i++){
        int u, v;
        scanf("%d%d", &u, &v);

        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
    }

    dfs(1, 1);
    dfs0(1, 1, 1);

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

Measured memory_bytes: 17780
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map
#include<cstring>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

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;
}

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        ll tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}
/*
ll Integer_factorization(ll n){
    ll num = 0;
    ll ndash = n;
    if(n == 1) return 1;
    ll a = 2;
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    return num;
}
*/

ll r_fuct[2000];
ll fuct[2000];

//MOD逆元
void conb(ll n,ll k){
    fuct[0] = 1;
    for(int i = 1;i < k+1;i++){
        fuct[i] *= fuct[i-1]%MOD;
        
        ll b = MOD, u = 1, v = 0;
        ll value = fuct[i];
        while (b) {
            ll t = value / b;
            value -= t * b;
            swap(value, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        if (u < 0) u += MOD;
        r_fuct[i] = u;
    }
}

ll factrial(ll n){
    if(n == 0) return 1;
    ll p = factrial(n-1)*n%MOD;
    return p;
}

//MOD逆元
ll farmat(ll n,ll p){    
    if(p == 0) return 1;
    else if(p == 1) return n%MOD;
    ll d = farmat(n,p/2);
    if(p%2 == 0){
        return (d*d)%MOD;
    }else{
        return ((n*d)%MOD*d)%MOD;
    }
}

ll conbination(ll n,ll k){
    ll a = factrial(n);
    ll b = factrial(k);
    ll c = factrial(n-k);
    return (a*farmat(b,MOD-2)%MOD*farmat(c,MOD-2))%MOD;
}

int memo[10000000];

int fib(int i){
    if(i <= 1) return i;
    if(memo[i] != 0) return memo[i];
    return memo[i] = fib(i-1)+fib(i-2);
}

ll dig(ll n){
    ll d = 0;
    while(n != 0){
        n/=10;
        d++;
    }
    return d;
}

void solve() {
    int n;
    cin >> n;
    if((n/100) > (n/10)%10 || ((n/100) >= n%10 && n/100 == (n/10)%10) ) cout << n/100 << n/100 << n/100 << endl;
    else cout << n/100+1 << n/100+1 << n/100+1 << endl;
}




int main() {

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



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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)
int visit[100005];
vector<int> G[100005];
int dfs(int now){
    visit[now] = 1;
    int res = 0;
    for(int i=0;i<G[now].size();i++){
        if(visit[G[now][i]]==-1) res ^= (dfs(G[now][i])+1);
    }
    return res;
}

int main(){
    int N;
    cin >> N;
    REP(i, N-1){
        int x, y;
        cin>>x>>y;x--;y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    memset(visit, -1, sizeof(visit));
    cout << (dfs(0)!=0?"Alice":"Bob") << endl;
    return 0;
}

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

int n, a[100001], s, c = 0;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	s = 1;
	for (int i = 0; i < n; i++) {
		s = a[s];
		c++;
		if (s == 2) {
			break;
		}
	}

	if (s == 2) {
		cout << c << endl;
	}
	else {
		cout << -1 << endl;
	}
}

Measured memory_bytes: 640
#include <cstdio>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int INF = 1e18;
const int M = 1e9 + 7;
//__int128

const int maxn = 3e5;
signed main()
{
#ifndef ONLINE_JUDGE
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    std::vector<int> a(n);
    static int b[maxn];
    for(int i = 0; i < n; ++i) {
    	cin >> a[i];
    	a[i] = -a[i];
    }
    int cnt = -1;
    for(int i = 0; i < n; ++i) {
    	int x = upper_bound(b, b + cnt + 1, a[i]) - b;
    	b[x] = a[i];
    	cnt = max(cnt, x);
    }
    cout << cnt + 1 << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

bool judge (string s) {
  bool res = true;
  int r = s.length() - 1;
  for(int i = 0; i < r; ++i) {
    if(s[i] != s[r]) res = false;
    --r;
  }
  return res;
}

int main(){
  string s;
  cin >> s;
  int n = s.length();
  string left = "";
  string right = "";
  for(int i = 0; i < (n - 1) / 2; ++i) {
    left += s[i];
  }
  for(int i = (n + 2) / 2; i < n; ++i) {
    right += s[i];
  }
  // cout << left << ' ' << right << endl;
  bool ans1 = judge(s);
  bool ans2 = judge(left);
  bool ans3 = judge(right);
  if(ans1 && ans2 && ans3) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2
ll mo = 1000000007;

vector<int>e[101010];
int dist[101010];
int main() {
	memset(dist, -1, sizeof(dist));
	int n, k;
	cin >> n >> k;
	rep(i, 0, n-1) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		e[a].pb(b);
		e[b].pb(a);
	}

	ll ans = k;
	queue<int>q;
	q.push(0);
	dist[0] = 0;
	while (q.size()) {
		int tp = q.front();
		q.pop();
		ll ini = (tp == 0) ? k - 1 : k - 2;
		ll cnt = 0;
		fore(x,e[tp]){
			if (dist[x] == -1) {
				dist[x] = dist[tp] + 1;
				q.push(x);
				ans *= ini - cnt;
				cnt++;
				ans %= mo;
			}
		}
	}
	puts(ans);



	return 0;
}


Measured memory_bytes: 7548
#include<bits/stdc++.h>
using namespace std;
int n;const int N=1e6+10;const int mod=1e9+7;
template<class T>inline void Inc(T&x,int y){x+=y;if(x>=mod) x-=mod;return;}
int f[N];
typedef long long ll;
int main()
{
	cin>>n;f[n]=n,f[n-1]=(ll)n*n%mod;int s=0;
	for(int i=n-2;i>0;--i) Inc(s,f[i+3]),f[i]=((ll)(n-1)*(n-1)%mod+f[i+1]+s+i+1)%mod;
	cout<<f[1]<<endl;
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9;
const LL LINF = INF * INF;

const int mod = 1e9 + 7;

inline int add(int x, int y)
{
	if (x + y >= mod)
		return x + y - mod;
	return x + y;
}

inline int mult(int x, int y)
{
	return x * (LL)y % mod;
}

int n, m;
const int MAX = 1 << 10;
int a[MAX];
int b[MAX];
int row[MAX * MAX];
int column[MAX * MAX];

void bad()
{
	cout << 0 << endl;
	exit(0);
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);

	cin >> n >> m;
	FOR(i, 0, n)
		cin >> a[i];
	FOR(i, 0, m)
		cin >> b[i];

	FOR(i, 1, n * m + 1)
		row[i] = column[i] = -1;
	
	FOR(i, 0, n)
	{
		if (row[a[i]] != -1)
			bad();
		row[a[i]] = i;
	}
	
	FOR(i, 0, m)
	{
		if (column[b[i]] != -1)
			bad();
		column[b[i]] = i;
	}
	
	int ans = 1;
	int zanyati_row = 0, zanyati_column = 0, postavleni = 0;
	RFOR(zara, n * m + 1, 1)
	{
		int co = column[zara];
		int ro = row[zara];
		
		if (co != -1 && ro != -1)
		{
			zanyati_row++;
			zanyati_column++;
			postavleni++;
			continue;
		}
		
		if (co != -1)
		{
			ans = mult(ans, zanyati_row);
			zanyati_column++;
			postavleni++;
			continue;
		}
		
		if (ro != -1)
		{
			ans = mult(ans, zanyati_column);
			zanyati_row++;
			postavleni++;
			continue;
		}
		
		ans = mult(ans, zanyati_row * zanyati_column - postavleni);	
		postavleni++;
	}
	
	cout << ans << endl;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


Measured memory_bytes: 8448
#define pb push_back
#define mp make_pair
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2000000 + 100;
ll arr[N], dp[6001][6001], ans = 0;
int n;
void solve(){
	cin >> n; 
	ans = 2;
	for(int i = 0; i < n; i++) cin >> arr[i], dp[i][n - 1] = 2;
	sort(arr, arr + n);
	for(int j = n - 2; j >= 1; j--){
		int i = j - 1, k = j + 1;
		while(i >= 0 && k <= n - 1){
			if(arr[i] + arr[k] < 2 * arr[j]){
				k++;
			}else if(arr[i] + arr[k] > 2 * arr[j]){
				dp[i--][j] = 2;
			}else{
				dp[i][j] = dp[j][k] + 1;
				ans = max(ans, dp[i][j]);
				i--; k++;
			}
		}
		while(i >= 0){
			dp[i][j] = 2;
			i--;
		}
	}
	cout << ans << endl;
}
int main(){
	int t = 1; 
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 120812
inp = input()

A = int(inp.split(" ")[0])
B = int(inp.split(" ")[1])
K = int(inp.split(" ")[2])

if K > A :
    K = K - A
    A = 0
    if K >= B :
        B = 0
    else :
        B = B - K
else :
    A = A - K

print( A,B )

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n;
    cin >> n;
    vi v(100000);
    for(ll i=1;i<101;i++){
        for(ll j=1;j<101;j++){
            for(ll k=1;k<101;k++){
                v.at(i*i+j*j+k*k+i*j+j*k+k*i)++;
            }
        }
    }
    for(ll i=1;i<=n;i++) cout << v.at(i) << endl;
}

Measured memory_bytes: 3948
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const ll INF= 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

struct edge{
	ll to,cost;
};

int V; //頂点数
vector<edge> G[100010];
ll d[100010]; //頂点sからの最短距離

void dijkstra(int s) {
	//greater<P>を指定することでfirstが小さい順に取り出せる
	priority_queue<P,vector<P>,greater<P>> que;
	fill(d,d + V,INF);
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) {
			continue;
		}
		for(int i = 0;i < G[v].size();i++) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

int main() {
    cin >> V;
    for(int i = 0;i < V - 1;i++) {
        ll A,B,C;
        cin >> A >> B >> C;
        A--;
        B--;
        G[A].push_back(edge{B,C});
        G[B].push_back(edge{A,C});
    }
    vector<int> ret(V);
    ret.at(0) = 0;
    dijkstra(0);
    for(int i = 1;i < V;i++) {
        if(d[i] % 2 == 0) {
            ret.at(i) = 0;
        }
        else {
            ret.at(i) = 1;
        }
    }
    for(int i = 0;i < V;i++) {
        cout << ret.at(i) << endl;
    }
}

Measured memory_bytes: 9088
#include <stdio.h>
#include <stdlib.h>
int partititon(int [],int,int);
int main() {

  int i,j;
  int *A;
  int b;
  int p,r;
  int n;

  scanf("%d",&n);

  A=malloc(sizeof(int)*n+1);

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

  for(i=0;i<n;i++){
    if((i+1)==b){
      printf("[%d] ",A[i+1]);
      continue;
    }
    printf("%d",A[i+1]);
    if((i+1)==n) break;
    printf(" ");
  }


  printf("\n");

  return 0;
}
int partition(int A[],int p, int r) {

  int x;
  int i,j,a;
  int b;

  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x) {
      i++;
      a=A[i];
      A[i]=A[j];
      A[j]=a;
    }
  }
  b=A[i+1];
  A[i+1]=A[r];
  A[r]=b;
  return i+1;
}
  

Measured memory_bytes: 992
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,K;
    cin >> N >> K;

    vector<int> l(N);

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

    sort(l.begin(),l.end());
    reverse(l.begin(),l.end());

    int ans=0;

    for(int i=0;i<K;i++){
        ans += l.at(i);
    }

    cout << ans <<endl;
    
}

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

using namespace std;


#define kotei (1000000000000000000)
int main() {
    uint64_t N,Ai;
	cin >> N;

	uint64_t ans(1);

	for (size_t i = 0; i < N; ++i)
	{
		cin >> Ai;
		if (Ai == 0)
		{
			ans = 0;
			break;
		}
		else if (ans < UINT64_MAX/Ai)
		{
			ans *= Ai;
		}
		else
		{
			ans = UINT64_MAX;
		}

		if (ans > kotei)
		{
			ans = UINT64_MAX;
		}
	}

	if (ans == UINT64_MAX)
		cout << -1 << endl;
	else
		cout << ans << endl;
	return 0;
}



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

using namespace std;

int main()
{
	int N, H, W;

	cin >> N >> H >> W;

	cout << (N - H + 1) * (N - W + 1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
const int N = 505;
int n;
int grid[N][N] = {};
int l[N][N] = {};
int p[N*N];
int xx[5] = {0, 0, -1, 1};
int yy[5] = {-1, 1, 0, 0};
void dfs(int i, int d)
{
    int r = i/n, c = i%n;
    int j;
    FOR0(j, 4)
    {
        int xd = r+xx[j], yd = c+yy[j];
        if(xd >= 0 && xd < n && yd >= 0 && yd < n && d < grid[xd][yd])
        {
            grid[xd][yd] = d;
            int nd = d;
            if(!l[xd][yd]) nd++;
            dfs(xd*n+yd, nd);
        }
    }
}
int main()
{
    she_told_me_dont_worry
    cin>>n;
    int i, j;
    FOR0(i, n*n)
    {
        cin>>p[i];
        p[i]--;
    }
    FOR0(i, n)
        FOR0(j, n)
            grid[i][j] = MIN2(MIN2(i, n-1-i), MIN2(j, n-1-j));
    int ans = 0;
    FOR0(i, n*n)
    {
        int r = p[i]/n, c = p[i]%n;
        l[r][c] = 1;
        ans += grid[r][c];
        dfs(p[i], grid[r][c]);
    }
    cout<<ans<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 26096
<?php
    $X = intval(trim(fgets(STDIN)));
    
    if($X < 600){
        echo "8";
    }elseif($X <800){
        echo "7";
    }elseif($X <1000){
        echo "6";
    }elseif($X <1200){
        echo "5";
    }elseif($X <1400){
        echo "4";
    }elseif($X <1600){
        echo "3";
    }elseif($X <1800){
        echo "2";
    }elseif($X <2000){
        echo "1";
    }

?>

Measured memory_bytes: 16236
# include <iostream>
# include <algorithm>
# include <string>
# include <map>
using namespace std;

int n;
map<string, long long> m;

int main() {
  cin >> n;
  
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    string s; cin >> s; sort(s.begin(), s.end());
    ans += m[s];
    m[s] += 1;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#include<queue>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
using namespace std;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int A,P;
  cin>>A>>P;
  P+=3*A;
  cout<<(int)P/2;
  
  



  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep1(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define N 200005
#define pql priority_queue<ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
using namespace std;
ll ans,n,a,b,c;
string s;
int main() {
	cin>>n>>s;
	rep(i,0,n){
		if(s[i]=='R')a++;
		if(s[i]=='G')b++;
		if(s[i]=='B')c++;
	}
	ans=a*b*c;
	rep(i,0,n) rep(j,i+1,n){
		int k=j-i+j;
		if(k>n-1)continue;
		if(s[j]!=s[k]&&s[i]!=s[j]&&s[i]!=s[k])ans--;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3620