akhauriyash/Code-Regression huggingface dataset:
input = list(map(int,input().split()))

a = [input[0], input[1]]
b = [input[2], input[3]]

if a[0] > b[0]:
    a, b = b, a

if a[1] <= b[0]:
    print(0)
elif b[1] <= a[1]:
    print(b[1] - b[0])
else:
    print(a[1] - b[0])

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

        System.out.println((long)A*B/gcd(A, B));
    }

    private static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a%b);
    }
}


Measured memory_bytes: 21844
//nikkei2019qual_d.cpp
//Thu Jun  4 22:03:55 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n,m;
	cin >> n >> m;

	vector<int> g[n];
	set<int> par[n];
	for (int i=0;i<n-1+m;i++){
		int a,b;
		cin >> a >> b;
		a--;b--;
		g[a].push_back(b);
		par[b].insert(a);
	}

	int root = -1;
	for (int i=0;i<n;i++){
		if (par[i].size()==0){
			root = i;
			break;
		}
	}

	queue<int> q;
	q.push(root);
	int ans[n];
	fill(ans,ans+n,-1);
	while (!q.empty()){
		int tmp = q.front();q.pop();
		for (int i=0;i<g[tmp].size();i++){
			int next = g[tmp][i];
			if (par[next].size()>1){
				par[next].erase(tmp);
			}else{
				ans[next] = tmp;
				q.push(next);
			}
		}
	}

	for (int i=0;i<n;i++){
		cout << ans[i]+1 << endl;
	}

}

Measured memory_bytes: 16000
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctype.h>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
// const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int x, t;
    cin >> x >> t;
    cout << max(0, x - t) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np

# N お札の枚数 Y お年玉の金額
n, y = map(int, input().split())

ok = False
for i in range(n+1):
    for j in range(n-i+1):
        k = n - i - j
        money = (10000 * i) + (5000 * j) + (1000 * k)
        if (money == y):
            ok = True
            break
    if  ok:
        break

if ok:
    print(i, j, k)
else:
    print("-1 -1 -1")   

Measured memory_bytes: 12396
import sys
n = int(input())
class Node:
  def __init__(self):
    self.p = -1 # parent
    self.l = -1 # left most child
    self.r = -1 # right sibling

T = [Node() for _ in range(n)]
sys.setrecursionlimit(1500)

for i in range(n):
    v,l,r = map(int,input().split())
    T[v].r = r
    if r != -1:
      T[r].p = v
    T[v].l = l
    if l != -1:
      T[l].p = v

for i in range(n):
  #print(i,T[i].p,T[i].l,T[i].r)
  if T[i].p == -1 : r = i

ret = []
def preorder(v):
  if v == -1: return
  ret.append(v)
  preorder(T[v].l)
  preorder(T[v].r)

def inorder(v):
  if v == -1: return
  inorder(T[v].l)
  ret.append(v)
  inorder(T[v].r)

def postorder(v):
  if v == -1: return
  postorder(T[v].l)
  postorder(T[v].r)
  ret.append(v)

ret = []
preorder(r)
print("Preorder")
print(""," ".join(map(str,ret)))
ret = []
inorder(r)
print("Inorder")
print(""," ".join(map(str,ret)))
ret = []
postorder(r)
print("Postorder")
print(""," ".join(map(str,ret)))




Measured memory_bytes: 5616
from fractions import gcd
a,b = map(int,input().split())

def pfact(m):
	pf = {}
	for i in range(2,int(m**0.5)+1):
		while m%i == 0:
			pf[i] = pf.get(i,0) + 1
			m //= i
	if m>1 : pf[m]=1
	return pf


"""
最大公約数を素因数分解すればいけそう？
"""

target = gcd(a,b)
pftarg = pfact(target).items()
print(len(pftarg)+1)

Measured memory_bytes: 5600
#include <iostream>
#include <algorithm>
using namespace std;
int a = 0;
int b = 0;
int c = 0;
int d = 0;

void l(int n){
  if(n == 1) a++;
  if(n == 2) b++;
  if(n == 3) c++;
  if(n == 4) d++;
  return;
}

int main(void){
  for(int i = 0; i < 3; i++){
    int e, f;
    cin >> e >> f;
    l(e);
    l(f);
  }
  int array[4];
  array[0] = a;
  array[1] = b;
  array[2] = c;
  array[3] = d;
  sort(array, array + 4);
  if(array[0] == 1 && array[1] == 1 && array[2] == 2 && array[3] == 2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int main(){
  long long k;
  cin >> k;
  if(k % 2 == 0){
    cout << "-1" << endl;
  }
  else{
    long long x = 7;
    long long ans = 0;
    
    while(ans <= 100000000){
      x = x % k;
      ans ++;
      if(x== 0){
        break;
      }
      x *= 10;
      x += 7;
    }
    if(ans >= 100000000){
      cout << "-1" << endl;
    }
    else{
      cout << ans << endl;
    }
  }
}
    

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t,u;
  cin>>s>>t>>u;
  if(s.at(s.size()-1)==t.at(0)&&t.at(t.size()-1)==u.at(0)){cout<<"YES";}
  else{cout<<"NO";}
}

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

using namespace std;
typedef long long ll;

int main(){
	int n; 
	cin >> n;
	vector<int>A(n);
	for(int i = 0; i < n; i++) cin >> A[i];
	ll ans = 0;
	for(int j = 0; j < n; j++){
		ans += A[j] - 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef vector<vector<P>> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<ll> vec;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    rep(i,100000){
        int a,b;
        char g;
        cin>>a>>g>>b;
        if(g=='?') break;
        if(g=='+') cout<<a+b<<endl;
        if(g=='-') cout<<a-b<<endl;
        if(g=='*') cout<<a*b<<endl;
        if(g=='/') cout<<a/b<<endl;
    }

}


Measured memory_bytes: 3212
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main() {
	log.SetFlags(log.Lshortfile)
	nextReader = NewScanner()
	x1 := nextInt()
	y1 := nextInt()
	x2 := nextInt()
	y2 := nextInt()
	log.Println(x1, y1, x2, y2)
	x := x2 - x1
	y := y2 - y1
	fmt.Println(x2-y, y2+x, x1-y, y1+x)
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return p[i].b < p[i].b
}

var nextReader func() string

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b){
  if(b==0)return a;
  return gcd(b,a%b);
}
int sieve(long long max) {
    long long ans=max;
    int count=1;
    for (long long i = 2; i*i <= max; ++i)
        if(ans%i==0){
          count++;
          while(ans%i==0)ans/=i;
        }
    if(ans!=1)count++;
    return count;
}
int main(){
  long long A,B;cin>>A>>B;
  long long C=gcd(A,B);
  cout<<sieve(C)<<endl;
}

Measured memory_bytes: 3572
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    vector<int>V;
    int n;
    for(int i=0;i<2;i++){
        scanf("%d",&n);
        while(n--){
            int h,m;
            scanf("%d%d",&h,&m);
            V.push_back(h*60+m);
        }
    }
    sort(V.begin(),V.end());
    V.erase(unique(V.begin(),V.end()),V.end());
    for(int i=0;i<V.size();i++){
        if(i!=0)printf(" ");
        int h=V[i]/60,m=V[i]%60;
        printf("%d:%02d",h,m);
    }
    puts("");

    return 0;
}

Measured memory_bytes: 1080
#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
	int x,id,rk;
}a[100005],b[100005];
int n,i,ok=1,cnt=0,vis[100005],j;
bool cmp(node a,node b){return a.x<b.x;}
bool cmp2(node a,node b){return a.id<b.id;}
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i].x),a[i].id=i;
	for(i=1;i<=n;i++)scanf("%d",&b[i].x),b[i].id=i;
	sort(a+1,a+n+1,cmp);sort(b+1,b+n+1,cmp);
	ok=0;
	for(i=1;i<=n;i++)
	{
		a[i].rk=i;
		if(a[i].x>b[i].x)
		{
			printf("No\n");
			return 0;
		}
		if(a[i].x<=b[i-1].x)ok=1;
	}
	sort(a+1,a+n+1,cmp2);
	for(i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			cnt++;
			for(j=i;!vis[j];j=a[b[j].id].rk)vis[j]=1;
		}
	}
	if(cnt>1)ok=1;
	if(ok)printf("Yes\n");
	else printf("No\n"); 
	return 0;	
} 

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;
    cin >> n;
    int ret = 0;
    vector<string> s(n);
    int acnt = 0, bcnt = 0, cnt = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
        int sz = s[i].size();
        for (int j = 0; j < sz - 1; j++)
        {
            if (s[i].substr(j, 2) == "AB")
            {
                ret++;
                s[i][j] = s[i][j + 1] = '*';
            }
        }
        if (s[i][0] == 'B' && s[i][sz - 1] == 'A')
        {
            cnt++;
        }
        else
        {
            if (s[i][0] == 'B')
                bcnt++;
            if (s[i][sz - 1] == 'A')
                acnt++;
        }
    }
    if (cnt == 0)
    {
        ret += min(acnt, bcnt);
    }
    else
    {
        ret += cnt - 1;
        if (acnt)
        {
            ret++;
            acnt--;
        }
        if (bcnt)
        {
            bcnt--;
            ret++;
        }
        ret += min(acnt, bcnt);
    }

    cout << ret << endl;
}


Measured memory_bytes: 768
import Data.List
main = getLine >>= switchAP >>= putStrLn

switchAP :: String -> IO String
switchAP x = return $ switchAP' x

switchAP' = replace "x" "apple".replace "apple" "peach".replace "peach" "x"

replace old new = joinWith new.split old

joinWith a b = concat (intersperse a b)

split :: Eq a => [a] -> [a] -> [[a]]
split _ [] = []
split delim str =
    let (firstline, remainder) = spanList (not.isPrefixOf delim) str
        in 
        firstline : case remainder of
                                   [] -> []
                                   x -> if x == delim
                                        then [] : []
                                        else split delim 
                                                 (drop (length delim) x)
spanList :: ([a] -> Bool) -> [a] -> ([a], [a])
spanList _ [] = ([],[])
spanList func list@(x:xs) =
    if func list
       then (x:ys,zs)
       else ([],list)
    where (ys,zs) = spanList func xs

Measured memory_bytes: 3796
#include <iostream>
using namespace std;
 
 
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
string result;
if (((A==B)&&(A!=C))||((A==C)&&(B!=C))||((C==B)&&(A!=C))){
  result = "Yes";
}
else{
  result = "No";
}
cout << result << endl;
}
 

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


int main(){

    int x,y;
    cin >> x >>y;

    if(x == 2 || y == 2){
        cout << "No" << endl;
        return 0;
    }

    if(x == 4 || x == 6 || x == 9 || x == 11){
        if (y == 4 || y == 6 || y == 9 || y == 11){
                cout << "Yes" << endl;
                return 0;
        }else{
                cout << "No" << endl;
                return 0;
        }
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <math.h>
#include <map>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <algorithm>
#include <string>
using namespace std;

int main() {
    vector<char> S(4);
    for (int i = 0; i < 4; i++) {
        cin >> S.at(i);
    }
    int A = (S.at(0) - '0') * 10 + S.at(1) - '0';
    int B = (S.at(2) - '0') * 10 + S.at(3) - '0';
    if (A <= 12 || B <= 12) {
        if ((B <= 12 && A > 12 && B != 0) || (A == 0 && B <= 12 && B != 0)) {
            cout << "YYMM" << endl;
        }
        else if ((A <= 12 && B > 12 && A != 0) || (B == 0 && A <= 12 && A != 0)) {
            cout << "MMYY" << endl;
        }
        else if (A <= 12 && B <= 12 && A != 0 && B != 0) {
            cout << "AMBIGUOUS" << endl;
        }
        else cout << "NA" << endl;
    }
    else cout << "NA" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        br.readLine();
        char[] str = br.readLine().toCharArray();
        int sz = str.length;
        
        // pre
        int hash = 'R'+'G'+'B';
        HashMap<Character, Integer> index = new HashMap<>();
        index.put('R', 0);
        index.put('G', 1);
        index.put('B', 2);
        int[][] counts = new int[3][sz+1];
        
        for(int i = 0; i < sz; ++i){
            counts[0][i+1] += counts[0][i];
            counts[1][i+1] += counts[1][i];
            counts[2][i+1] += counts[2][i];
            char curr = str[i];
            if(curr == 'R')
                counts[0][i+1] += 1;
            if(curr == 'G')
                counts[1][i+1] += 1;
            if(curr == 'B')
                counts[2][i+1] += 1;
        }
        
        int inner = 0;
        int outer = 0;
        int id = 0;
        long res = 0;
        for(int i = 0; i < sz; ++i){
            char iVal = str[i];
            for(int j = i+1; j < sz; ++j){
                char jVal = str[j];
                if(jVal == iVal)
                    continue;
                id = index.get((char)(hash-iVal-jVal));
                inner = 0;
                outer = 0;
                // search in outer part
                if(2*j-i < sz)
                    outer = counts[id][sz] - counts[id][2*j-i+1];
                // search in inner part
                if(j-i > 1)
                    inner = counts[id][Math.min(sz,2*j-i)] - counts[id][j+1];
                // early break if no third char in rest of segment
                if(counts[id][sz]-counts[id][j] == 0)
                    break;
                res += inner + outer;
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 34224
import java.util.Scanner;

/**
 * Created by zzt on 17-5-6.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int curA = scanner.nextInt();
        int curB = scanner.nextInt();
        int curC = scanner.nextInt();
        int time = 0;

        if (curA == curB && curA == curC && curA % 2 == 0) {
            System.out.println(-1);
            return;
        }
        int tempA = 0, tempB = 0, tempC = 0;
        while (curA % 2 == 0 && curB % 2 == 0 && curC % 2 == 0) {
            tempA = curB / 2 + curC / 2;
            tempB = curA / 2 + curC / 2;
            tempC = curA / 2 + curB / 2;
            curA = tempA;
            curB = tempB;
            curC = tempC;
            time++;
        }
        System.out.println(time);
    }
}

Measured memory_bytes: 21844
from collections import deque
n,q=map(int,input().split())
num=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    num[a-1].append(b)
    num[b-1].append(a)
ans=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x
queue=deque()
queue.append(0)
seen=[False]*n
for i in range(n):
    if len(queue)==0:
        break
    num1=queue.popleft()
    seen[num1]=True
    num2=num[num1]
    for j in range(len(num2)):
        if seen[num2[j]-1]==False:
            ans[num2[j]-1]+=ans[num1]
            queue.append(num2[j]-1)
for i in ans:
    print(i)


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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    long a = Long.parseLong(str[0]);
    long b = Long.parseLong(str[1]);
    long k = Long.parseLong(str[2]);
    if(a>=k){
      a -= k;
    } else if(b>=k-a){
      b = b-(k-a);
      a = 0;
    } else {
      a = 0;
      b = 0;
    }
    System.out.println(a + " " + b);
  }
}

Measured memory_bytes: 21204
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		if (a < b) {
			System.out.print(a + " ");
		} else {
			System.out.print(b + " ");
		}

		if (a + b <= n) {
			System.out.println(0);
		} else {
			System.out.println(a + b - n);
		}
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K,M;cin>>N>>K;vector<int>p(N);
  cin>>p.at(0);
  for(int i=1;i<N;i++){cin>>p.at(i);p.at(i)+=p.at(i-1);}
  M=p.at(K-1);
  for(int i=0;i<N-K;i++)M=max(M,p.at(i+K)-p.at(i));
  double X=M+K;
  printf("%lf\n",0.50000*X);
}

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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  for(;A>0&&C>0;){
    C=C-B;
    A=A-D;
  }
  
  if(C<=0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#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 Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#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)

vector<int>E[100];
set<int>st[100];
map<pair<int, int>,int>mp;
ll po(ll a,int n){
	ll ret = 1;
	for (int i = 0; i < n; i++)ret *= a;
	return ret;
}

ll modpow(ll a, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a;
		a = a * a;
		n >>= 1;
	}
	return res;
}

void dfs(int now,int go,int pa,set<int>path,int num){
	if (now == go) {
		fore(x, path)st[num].insert(x);
		return;
	}
	fore(x, E[now]) {
		if (x != pa) {
			path.insert(mp[{min(now,x),max(now,x)}]);
			dfs(x, go, now, path, num);
			path.erase(mp[{min(now,x),max(now,x)}]);
		}
	}
	return;
}

vector<vector<int>>dp;

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

	int N;
	cin >> N;
	for (int i = 0; i < N-1; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		E[a].pb(b);
		E[b].pb(a);
		mp[{min(a,b),max(a,b)}] = i;
	}


	int M;
	cin >> M;
	for (int i = 0; i < M; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		set<int>path;
		dfs(u, v, -1, path, i);
	}


	dp.resize(1 << M);
	for (int i = 1; i < (1 << M); i++) {
		int rec;
		for (int j = 0; j < M; j++) {
			if ((i >> j) & 1) {
				rec = j;
				break;
			}
		}
		vector<int>tmp;
		fore(x, dp[i - (1 << rec)])tmp.pb(x);
		fore(x, st[rec])tmp.pb(x);
		sort(all(tmp));
		tmp.erase(unique(all(tmp)), tmp.end());
		dp[i] = tmp;
	}


	ll ans = po(2, N - 1);
	ll sub = 0;
	for (int i = 1; i < (1 << M); i++) {
		int bitcnt = 0;
		for (int j = 0; j < M; j++)bitcnt += ((i >> j) & 1);
		ll mul = (bitcnt % 2 == 0) ? -1 : 1;
		sub += mul * modpow(2,N-1-dp[i].size());
	}
	ans -= sub;
	puts(ans);


	return 0;
}

Measured memory_bytes: 233472
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   int n,k;
  cin>>n>>k;
  int a[n];
  for(int i = 0 ; i < n ; i++) cin>>a[i];
  sort(a,a+n);
  int sum = 0;
  for(int i = 0 ; i < k ; i++)
    sum += a[i];
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3140
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
using namespace std;

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  int ans=0;
  int D,E,F;
  int sum=A+B+C;
   D=max(A,max(B,C));
   E=min(A,min(B,C));
   F=sum-D-E;
  while(D!=E||E!=F||F!=D){
    while(D-E>=2){
      E+=2;
      sum+=2;
       D=max(D,max(E,F));
       E=min(D,min(E,F));
       F=sum-D-E;
       ans+=1;
    }
    if(D==E&&E==F){
      cout<<ans<<endl;
      return 0;
    }
    E+=1;
    F+=1;
    sum+=2;
    D=max(D,max(E,F));
    E=min(D,min(E,F));
    F=sum-D-E;
    ans+=1;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;

ll n,x,y;

il ll solve(ll x,ll y,bool tp){
	if(!tp){
		 if(x%y==0) return x*3;
		 return x+x/y*(y<<1)+y+x%y+solve(x%y,y-x%y,1); 
	}else{
		if(x%y==0) return x*3-y;
		return x+x/y*(y<<1)+x%y+solve(x%y,y-x%y,1);
	}
}

int main(){
	scanf("%lld%lld",&n,&x);
	y=n-x;
	if(x%y==0) return printf("%lld\n",3*x),0;
	ll ans=x+x/y*(y<<1)+y+x%y;
	x%=y,y-=x;
	while(x){
		if(x%y==0){
			ans+=x*3-y;
			break;
		}
		if(y%x==0){
			ans+=y<<1;
			break;
		}
		if(x>y){
			ans+=x+x/y*(y<<1)+x%y;
			x%=y,y-=x;
		}else{
			ans+=y/x*(x<<1);
			y%=x;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

template <class T>void Sort(vector<T> & a) { sort(a.begin(), a.end()); }
template <class T>void ReSort(vector<T>& a) { sort(a.rbegin(), a.rend()); }
template <class T>void Reverse(vector<T>& a) { reverse(a.begin(), a.end()); }
template <class T>void Unique(vector<T>& a) { a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T>T Sum(vector<T> a, T init = 0) { return accumulate(a.begin(), a.end(), init); }

//INPUT//
void CINPUT() {}
template<class H, class ...T> void CINPUT(H&& h, T&& ...t) { cin >> h; CINPUT(forward<T>(t)...); }
#define in(...) int __VA_ARGS__; CINPUT(__VA_ARGS__);
#define In(T,...) T __VA_ARGS__; CINPUT(VA_ARGS__);
#define Vin(T,name,n) int n; cin>>n; vector<T> name(n); rep(i,n)cin>>name[i];
#define VIn(T,name,n) vector<T> name(n); rep(i,n)cin>>name[i];

//OUTPUT//
void print() { cout << endl; }
template <class H> void print(H&& h) { cout << h << endl; }
template <class H, class... T> void print(H&& h, T&& ... t) { cout << h << " "; print(forward<T>(t)...); }
template<class T>void out(T n) { cout << n << endl; }
template<class T>void out(vector<T> a, string sep = " ", string end = "\n") { for (int i = 0; i < (int)a.size(); ++i)cout << a[i] << (i == (int)a.size() - 1 ? end : sep); }
void yes(bool f) { puts(f ? "yes" : "no"); }
void Yes(bool f) { puts(f ? "Yes" : "No"); }
void YES(bool f) { puts(f ? "YES" : "NO"); }
void poss(bool f) { puts(f ? "possible" : "impossible"); }
void Poss(bool f) { puts(f ? "Possible" : "Impossible"); }
void POSS(bool f) { puts(f ? "POSSIBLE" : "IMPOSSIBLE"); }

int main() {
	in(a, b);
	out((a + b + 1) / 2);
}

Measured memory_bytes: 256
/*
 * @Author: BilyHurington
 * @Date: 2020-03-08 20:04:16
 * @LastEditors: BilyHurington
 * @LastEditTime: 2020-03-08 20:06:39
 */
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
int n,m,k,a[100010],b[100010];
int main(){
    int minna=2e9,minnb=2e9;
    scanf("%d %d %d",&n,&m,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]),minna=min(minna,a[i]);
    for(int i=1;i<=m;i++) scanf("%d",&b[i]),minnb=min(minnb,b[i]);
    int x,y,z;
    int ans=minna+minnb;
    for(int i=1;i<=k;i++){
        scanf("%d %d %d",&x,&y,&z);
        ans=min(ans,a[x]+b[y]-z);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
    int n,i;
    scanf("%d",&n);
    int a[n],b[n];
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    for(i=0;i<n;i++) b[a[i]-1] = i+1;
    for(i=0;i<n;i++) printf("%d ",b[i]);
}


Measured memory_bytes: 1536
#include <iostream>

using namespace std;

unsigned long long numAtack(unsigned long long h) {
    if (h == 1) {
        return 1;
    }
    else {
        return 2 * numAtack(h / 2) + 1;
    }
}

int main() {
    unsigned long long h;
    cin >> h;
    cout << numAtack(h) << endl;
    
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;



int main() {
	int h,w; cin>>h>>w;
	vector<vector<int>> a(10);
	rep(i,0,10){
		a[i].resize(10);
		rep(j,0,10) cin>>a[i][j];
	}
	rep(k,0,10)rep(i,0,10)rep(j,0,10){
		if(a[i][j]>a[i][k]+a[k][j])a[i][j]=a[i][k]+a[k][j];
	}
	ll ans=0;
	rep(i,0,h*w){
		int p; scanf("%d",&p);
		if(p>=0) ans+=a[p][1];
	}
	printf("%d",ans);
	return 0;
}


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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = 2e15+7;
const ll mod = 1e9+7;
const int MAX_N = 5e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;

ll inv[MAX_N],fac[MAX_N];

template <class T = ll> T in(){T x;cin >> x;return (x);}
inline ll GCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
inline ll LCM(ll a,ll b){return a*b/GCD(a,b);}
inline ll POW(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;}
inline void _nCr(){fac[0]=1;for(int i=1;i<MAX_N;i++){fac[i]=fac[i-1]*i%mod;}for(int i=0;i<MAX_N;i++){inv[i]=POW(fac[i],mod-2);}}
inline ll nCr(ll n,ll r){return (fac[n]*inv[r]%mod)*inv[n-r]%mod;}
inline void PRI(ll n){bool a[n+1];for(int i=0;i<n+1;i++){a[i]=1;}for(int i=2;i<n+1;i++){if(a[i]){prime.pb(i);ll b=i;while(b<=n){a[b]=0;b+=i;}}}}

class UnionFind {
private:
	int par[MAX_N];
	int rank[MAX_N];
public:
	void init(int n);
	int find(int x);
	void unite(int x,int y);
	bool same(int x,int y);
};

void UnionFind::init(int n) {
	for (int i = 0;i < n;i++) {
		par[i] = i;
		rank[i] = 0;
	}
}

int UnionFind::find(int x) {
	if (par[x] == x) return x;
	else return par[x] = find(par[x]);
}

void UnionFind::unite(int x,int y) {
	x = find(x);
	y = find(y);
	if (rank[x] < rank[y]) par[x] = y;
	else {
		par[y] = x;
		if (rank[x] == rank[y]) rank[x]++;
	}
}

bool UnionFind::same(int x,int y) {
	x = find(x);
	y = find(y);
	return x == y;
}

int main() {
	ll n;
	cin >> n;
	ll a[n];
	REP(i,n) cin >> a[i];
	ll spos = INF;
	ll ans = 0;
	for (int i = n-1;i >= 0;i--) {
		if (spos < i-a[i]) {cout << -1 << endl;return 0;}
		else if (spos > i-a[i]) {
			spos = i-a[i];
			ans += a[i];
			if (spos < 0) {cout << -1 << endl;return 0;}
		}
	}
	cout << ans << endl;
}

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

#define ll long long
#define MAXN 410

using namespace std;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    ll arr[n], pre[n];
    for(int i = 0; i < n; i++) {
        cin >> arr[i];

        pre[i] = (i ? pre[i - 1] : 0) + arr[i];
    }
    
    ll dp[n][n];
    for(int len = 0; len < n; len++) {
        for(int l = 0; l < n - len; l++) {
            int r = l + len;
            if(len == 0) {
                dp[l][r] = 0;
                continue;
            }

            dp[l][r] = LLONG_MAX;
            for(int k = l; k < r; k++)
                dp[l][r] = min(dp[l][r], dp[l][k] + dp[k + 1][r] + pre[r] - (l ? pre[l - 1] : 0));
        }
    }
    
    cout << dp[0][n - 1] << endl;
    return 0;
}


Measured memory_bytes: 4836
#include <iostream>
using namespace std;
#define rep(i,s,n)for(int i = s;i<n;i++)
int A[100];
int N;

void sort(const int *a) {
	int D;
	rep(i, 0, N) {
		rep(j, i + 1, N) {
			if (A[i] < A[j]) {
				int D = A[i];
				A[i] = A[j];
				A[j] = D;
			}
		}
	}
}
int main() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];

	sort(A);
	int sum = 0;
	rep(i, 0, N) {
		sum += ((i % 2 == 0) ? A[i] : -A[i]);
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

#define MAX_SUM 900

int main()
{
	unsigned long long*** DP = new unsigned long long**[9];
	for (int i=0; i<9; i++) {
		DP[i] = new unsigned long long*[901];
		for (int j=0; j<MAX_SUM+1; j++) DP[i][j] = new unsigned long long[901];
	}
	
	for (int j=0; j<MAX_SUM+1; j++) {
		for (int k=0; k<MAX_SUM+1; k++) DP[0][j][k] = (j<=k && k<=100) ? 1 : 0;
	}
	
	for (int i=1; i<9; i++) {
		for (int j=0; j<MAX_SUM+1; j++) {
			for (int k=0; k<MAX_SUM+1; k++) {
				unsigned long long sum = 0;
				for (int m=j; m<MAX_SUM+1 && m<=(k-1)/2; m++) sum += DP[i-1][m+1][k-m];
				DP[i][j][k] = sum;
			}
		}
	}
	
	int n, s;
	while (std::cin >> n >> s) {
		//std::cout << n << " " << s << std::endl;
		if (n == 0 && s == 0) break;
		if (s>MAX_SUM) std::cout << 0 << std::endl;
		else std::cout << DP[n-1][0][s] << std::endl;
	}
	
	for (int i=0; i<9; i++) {
		for (int j=0; j<MAX_SUM+1; j++) delete[] DP[i][j];
		delete[] DP[i];
		
	}
	
	return 0;
}



Measured memory_bytes: 59932
#include <iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

const int MAX_N = 110;
const int MAX_V = 100100;

// 入力
int N;
long long W, weight[MAX_N], value[MAX_N]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[MAX_N][MAX_V];

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // 初期化
    for (int i = 0; i < MAX_N; ++i) for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF;

    // 初期条件
    dp[0][0] = 0;

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {

            // i 番目の品物を選ぶ場合
            if (sum_v - value[i] >= 0) chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);

            // i 番目の品物を選ばない場合
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    // 最適値の出力
    long long res = 0;
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
        if (dp[N][sum_v] <= W) res = sum_v;
    }
    cout << res << endl;
}

Measured memory_bytes: 86272
/*
         ▄▀▀▀▄
    ▄███▀░◐░░░▌
        ▌░░░░░▐
         ▌░░░░▐
        ▌░░░░░▐▄▄
        ▌░░░░▄▀▒▒▀▀▀▀▄
       ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
       ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
        ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
          ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
               ▌▌░▌▌
               ▌▌░▌▌
             ▄▄▌▌▄▌▌ */
    #include <iostream>
    #include <set>
    #include <vector>
    #include <map>
    #include <algorithm>
    #include <cmath>
    #include <numeric>
    #include <cstdlib>
    #include <queue>
    #include <stack>
    #include <cstring>
    #include <ctime>

    #define pb push_back
    #define re return
    #define fi first
    #define se second
    #define ll long long

    using namespace std;



    int main()
    {
        ll h, x=1;
        ll ans=0;
        cin >> h;
        while(h!=1){
            ans+=x;
            x*=2;
            h/=2;
        }
        cout << x+ans;

    }


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int i,n,j,min;
  int cnt=0;
  char temp,a[36][3],b[36][3],c[3];
     
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    scanf("%s",c);
    a[i][0]=b[i][0]=c[0];
    a[i][1]=b[i][1]=c[1];
  }

  for(i=0;i<n;i++)
  {
    for(j=0;j<n-1-i;j++)
    {
      if(a[j][1]-a[j+1][1]>0)
      {
        temp=a[j][1];
        a[j][1]=a[j+1][1];
        a[j+1][1]=temp;
  
        temp=a[j][0];
        a[j][0]=a[j+1][0];
        a[j+1][0]=temp;
      }
    }
  }
  
  for(i=0;i<n;i++)
  {
    min=i;
    for(j=i;j<n;j++)
    {
      if(b[j][1]-b[min][1]<0)
      {
        min=j;
      }
    }

    temp=b[i][1];
    b[i][1]=b[min][1];
    b[min][1]=temp;
    temp=b[i][0];
    b[i][0]=b[min][0];
    b[min][0]=temp;
  }
  
  for(i=0;i<n;i++)
  {
    if(i!=n-1)
    {
      printf("%c%c ",a[i][0],a[i][1]);
    }
    else
      printf("%c%c\n",a[i][0],a[i][1]);
  }
  
  printf("Stable\n");
  
  for(i=0;i<n;i++)
  {
    if(i!=n-1)
    {
      printf("%c%c ",b[i][0],b[i][1]);
    }
    else
      printf("%c%c\n",b[i][0],b[i][1]);
  
      if(a[i][0]==b[i][0])
      {
        cnt++;
      }
    }
  
  if(cnt!=n)
  {
    printf("Not stable\n");
  }
  else
    printf("Stable\n");

  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


constexpr lint mod = 1e9 + 7;
inline lint emod(lint a, lint p = mod) { return (a % p + p) % p; }
inline lint invm(lint a, lint p = mod) { a %= p; return a == 1 ? 1 : -p / a * invm(p % a) % p; }

V<lint> fact, ifact;
void init_table(int n) {
  fact.assign(n + 1, 1), ifact.assign(n + 1, 1);
  for (int i = 2; i < n + 1; ++i) fact[i] = i * fact[i - 1] % mod;
  ifact[n] = invm(fact[n]);
  for (int i = n; i > 2; --i) ifact[i - 1] = i * ifact[i] % mod;
}

lint comb(lint n, lint r) {
  if (r < 0 or r > n) return 0;
  return fact[n] * ifact[r] % mod * ifact[n - r] % mod;
}

lint mulcomb(lint n, lint r) {
  if (n < 1 or r < 0) return 0;
  return fact[r + n - 1] * ifact[r] % mod * ifact[n - 1] % mod;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  lint n, k; cin >> n >> k;
  init_table(n + k);
  cout << emod(mulcomb(k, n - k)) << '\n';
}


Measured memory_bytes: 3244
#include <iostream>

using namespace std;

int main() {
    
    int n;
    string s;
    cin>>n>>s;
    for(int i=0;i<s.length();i++)
    {
        int x=s[i]-'A';
        x=(x+n)%26;
        cout<<(char)('A'+x);
    }
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

const int INF = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> keys;
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    int s = 0;
    rep(j, 0, b) {
      int c;
      cin >> c;
      c--;
      s |= 1 << c;
    }
    keys.emplace_back(s, a);
  }

  vector<int> dp(1 << n, INF);
  dp[0] = 0;
  rep(s, 0, 1 << n) {
    rep(i, 0, m) {
      int t = s | keys[i].first;
      int cost = dp[s] + keys[i].second;
      chmin(dp[t], cost);
    }
  }

  int ans = dp[dp.size()-1];
  if (ans == INF)
    ans = -1;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  vi A(3);
  rep(i,0,3) cin>>A[i];
  sort(ALL(A));
  cout<<A[0]+A[1]<<endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
//#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007
//#define N 12
#define sz 1000*1000

 int main(){

 ll w,a,b;
  cin>>w>>a>>b;

  if(abs(a-b) <= w)
      cout<<"0"<<endl;
  else
     cout<<abs(a-b)-w<<endl;

 return 0;
 }

Measured memory_bytes: 3604
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T>
vector<T> make_vec(size_t s, T val) { return vector<T>(s, val); }
template<class... Size>
auto make_vec(size_t s, Size... tail) {
	return vector<decltype(make_vec(tail...))>(s, make_vec(tail...));
}

template <class T>
ostream &operator<<(ostream &os, const set<T> &st) {
	for (const auto &e : st) os << e << " ";
	return os;
}

template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template <class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
	for (const auto &e : mp) os << e << " ";
	return os;
}

template<class T>
inline bool chmin(T &a, T b) { return a > b && (a = b, true); }

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, Q;
	cin >> N >> Q;

	// t = x - D_i と x = X_j (S_j <= t <= T_j) が交わるD_iの範囲を計算しておく
	vector <pair<pair<int, int>, int>> stx(N);
	for (int i = 0; i < N; i++) {
		int s, t, x;
		cin >> s >> t >> x;
		stx[i] = { { max(0, s - x), t - x }, x };
	}
	sort(stx.begin(), stx.end());

	set<pair<int,int>> st;
	vector<int> ans(Q, INF);
	auto first = stx.begin();
	auto last = stx.end();
	for (int i = 0; i < Q; i++) {

		int d;
		cin >> d;

		// add
		last = upper_bound(stx.begin(), stx.end(), make_pair(make_pair(d, INF), INF));
		for (auto itr = first; itr != last; itr++) st.emplace(itr->second, itr->first.second);
		first = last;

		//erase
		vector<pair<int, int>> memo;
		for (const auto &e : st) {
			if (d < e.second) {
				chmin(ans[i], e.first);
				break;
			}
			else memo.emplace_back(e);
		}
		for (const auto e : memo) st.erase(e);

	}

	for (const auto &e : ans) cout << (e == INF ? - 1 : e) << "\n";

	return 0;
}

Measured memory_bytes: 15000
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

ans = 0
for b in B:
    lower_A = bisect.bisect_left(A, b)  # b以上の値が初めて現れるインデックスが得られる
    upper_C = bisect.bisect_right(C, b)  # bより真に大きい値が初めて現れるインデックスが得られる
    ans += lower_A * (N-upper_C)

print(ans)


Measured memory_bytes: 22720
#include<stdio.h>
#include <stdlib.h>

int main(){

int N,M;
while(1){
scanf("%d %d",&N,&M);if(N==0&&M==0)break;
int n[102]={},m[102]={};
int ns=0,ms=0;
for(int i=0;i<N;i++){
scanf("%d",&n[i]);ns+=n[i];}

for(int i=0;i<M;i++){
scanf("%d",&m[i]);ms+=m[i];}

for(int i=0;i<N;i++)
for(int j=N-1;j>i;j--)
if(n[j]<n[j-1]){int t=n[j];n[j]=n[j-1];n[j-1]=t;}

for(int i=0;i<M;i++)
for(int j=M-1;j>i;j--)
if(m[j]<m[j-1]){int t=m[j];m[j]=m[j-1];m[j-1]=t;}
int d=ms-ns;

//if(d<0)d*=-1;
int x=n[N-1],y=m[M-1];bool f=false;
for(int i=0;i<N;i++){
for(int j=0;j<M;j++)
if(ms+n[i]-m[j]==ns+m[j]-n[i]&&x+y>=n[i]+m[j]){x=n[i];y=m[j];f=true;}

//if(f==true)break;
}

if(f==true)printf("%d %d\n",x,y);
else printf("-1\n");
}

return 0;
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 2e5 + 50;
const int mod = 1e9 + 7;
const int inf = 1e17;
int dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); 
  char x;
  cin >> x;
  if(x == 'A'){
  	cout << 'T';
  }else if(x == 'T'){
  	cout << 'A';
  }if(x == 'C'){
  	cout << 'G';
  }else if(x == 'G'){
  	cout << 'C';
  }
}

Measured memory_bytes: 256
while True:
    H,W = (int(x) for x in input().split())
    if H == 0 and W == 0:
        break
    
    for i in range(H):
        if i == 0 or i == H-1:
            for j in range(W):
                print('#',end ='')
            print()
            
        else:
            for j in range(W):
                if j == 0 or j == W-1:
                    print('#',end='')
                else:
                    print('.',end='')
            print()
    print()


Measured memory_bytes: 7008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
string s, t, u; ll a, b, c;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	char str; cin >> str;
	cout << (char) ((str - 'a' + 1) + 'a') << endl;


}

Measured memory_bytes: 256