akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>

int main() {
	int N, D, X[10][10], i, j, k, count = 0, cal;

	scanf("%d %d", &N, &D);
	for (i = 0; i < N; i++) {
		for (j = 0; j < D; j++) {
			scanf("%d", &X[i][j]);
		}
	}

	for (i = 0; i < N; i++) {
		for (j = i + 1; j < N; j++) {
			cal = 0;
			for (k = 0; k < D; k++) {
				cal = cal + (int)(pow((double)(X[i][k] - X[j][k]), 2.0));
			}
			for (k = 1; k <= cal; k++) {
				if (k * k == cal) {
					count++;
				}
			}
		}
	}

	printf("%d", count);

	return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

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

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

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

  int x; cin >> x;
  cout << (1999 - x) / 200 + 1 << endl;

}








Measured memory_bytes: 3620
implicit none

integer :: n
integer, allocatable :: a(:)
integer :: nd, i
integer :: iswp, icomb
logical :: flg_swp

read *, n
allocate(a(n))
read *, (a(i), i=1,n)

! Sort (comb11)
icomb = n
flg_swp = .false.
do while (icomb > 1 .or. flg_swp)
   icomb = (icomb * 10) / 13
   if (icomb < 1) then
      icomb = 1
   else if (icomb == 9 .or. icomb == 10) then 
      icomb = 11
   endif
   flg_swp = .false.
   do i = 1, n-icomb
      if (a(i) > a(i+icomb)) then
         iswp = a(i) 
         a(i) = a(i+icomb)
         a(i+icomb) = iswp
         flg_swp = .true.
      endif
   enddo
enddo

nd = 0
do i = 1, n
   if (mod(i,2) == 1) then
      nd = nd + a(n-i+1)
   else
      nd = nd - a(n-i+1)
   endif
enddo

write(6,'(i0)') nd

end

Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextIntArray()
	B := sc.NextIntArray()
	C := sc.NextIntArray()

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

	total := 0
	for i := 0; i < len(B); i++ {

		k := B[i]
		a := BinarySearch1(A, k)
		b := BinarySearch2(C, k)
		//println(B[i], a, b)

		if b == N {
			b = 0
		} else {
			b = N - b
		}
		total += a * b
	}
	fmt.Println(total)

}
func BinarySearch1(A []int, k int) int {
	l := 0
	r := len(A)
	for r-l > 1 {
		c := (r + l) / 2
		if A[c] < k {
			l = c
		} else if A[c] >= k {
			r = c
		}
	}
	if A[l] >= k {
		return 0
	}
	return l + 1
}

func BinarySearch2(A []int, k int) int {
	l := -1
	r := len(A) - 1
	for r-l > 1 {
		c := (r + l) / 2
		if A[c] <= k {
			l = c
		} else if A[c] > k {
			r = c
		} else {
			l = c
			break
		}
	}
	if A[r] <= k {
		return len(A)
	}
	return r
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 10752
import itertools

N,K = map(int, input().split())

XY = [[int(x) for x in input().split()] for _ in range(N)]
XY.sort()
X,Y = zip(*XY)

min_area = 5*10**18

for left,right in itertools.combinations(range(N),2):
  width = X[right] - X[left]
  pts = sorted(XY[left:right+1], key = lambda xy: xy[1])
  for D in range(len(pts)):
    if D + K - 1 >= len(pts):
      break
    y_max = pts[D+K-1][1]
    y_min = pts[D][1]
    area = (y_max - y_min) * width
    if area < min_area:
      min_area = area
    
print(min_area)


Measured memory_bytes: 3064
#include<stdio.h>
#include<list>
int main(){
    int n,val;
    char command[11]={};
    std::list<int> A;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s",command);
        if(command[0]=='i'){
            scanf("%d",&val);
            A.push_front(val);
        }
        else if(command[6]=='F'){
            scanf("%d",&val);
            A.pop_front();
        }
        else if(command[6]=='L'){
            scanf("%d",&val);
            A.pop_back();
        }
        else{
            scanf("%d",&val);
            for(std::list<int>::iterator it=A.begin();it!=A.end();it++){
                if(*it==val){
                    A.erase(it);
                    break;
                }    
            }
        }
    }
    for(std::list<int>::iterator it=A.begin();it!=A.end();it++){
        if(it==A.begin()){
            printf("%d",*it);    
        }
        else{
            printf(" ");
            printf("%d",*it);
        }
    }printf("\n");
    return 0;
    
}


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

int phrase[5]={5, 7, 5, 7, 7};

int main(void){
	int n, tmp, ans, len[41];
	char str[11];

	while(1){
		scanf("%d", &n);
		if(n == 0) break;
		for(int i=0; i<n; i++){
			scanf("%s", str);
			len[i] = strlen(str);
		}

		int j = tmp = ans =  0;
		for(int i=0; i<n; i++){
			tmp += len[i];
			if(tmp < phrase[j]){
				continue;
			} else if(tmp > phrase[j]){
				tmp =0; ans++; i = ans-1; j=0;
			} else{
				j++;
				tmp =0;
				if(j>=5){
					printf("%d\n", ans+1);
					break;
				}
			}
		}
	}//endwhile

	return 0;
}


Measured memory_bytes: 2032
/*
    By Milind Lalwani - BahuMajaNu
       NIT - Tiruchirappalli
Don’t Chase Quaffle If you see the snitch. 
*/
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define p 1000000007
#define test int t; cin >> t; while(t--)
#define For(i,l,n) for(i=l;i<n;i++)
#define Rof(i,l,n) for(i=l;i>n;i--)
#define pb push_back
#define vi vector <int>
#define mp make_pair
#define vp vector < pair <int,int> > 
#define um unordered_map
#define vb vector <bool>
#define di deque <int>
#define dp deque < pair <int,int> >
//                    BFS
/* 
vb vis(n+1,true);
    For(i,1,n+1){
        if(vis[i]){
            queue <int> q;
            q.push(i);
            int s;
            while(!q.empty()){
                s=q.front();
                q.pop();
                if(vis[s]){
                    vis[s]=false;        
                    for(auto j:g[s]){
                        if(vis[j])
                            q.push(j);
                    }
                }
            }
        }
    }
*/
using namespace std;
int i,j,k,l,m,n;
/*int bs(vi &a,int b){
    if(b<=a[0])
        return -1;
    if(b>a.back())
        return a.size()-1;
    int s=0,e=a.size(),mid=(s+e)/2;
    while(s<e){
        mid=(s+e)/2;
        if(a[mid]<b && a[mid+1]>=b)
            return mid;
        if(a[mid]<=b)
            e=mid;
        else
            s=mid;
    }
    return s;
}*/
int main() {
    std::ios::sync_with_stdio(false) ; cin.tie(NULL);
    string s;
    cin >> s;
    s[3]='8';
    cout << s;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

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

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int d[3] = {-1,0,1};
int main(){
    int n;cin>>n;
    cout<<800*n-200*(n/15);
}



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

int main(){
    string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string input;
    string output;
    int n,i,j;

    cin >> n;
    cin >> input;


    for(i=0;i<input.size();i++){
        for(j=0;j<s.size();j++){
            if(s[j]==input[i]) break;
        }
        output.push_back(s[(j+n)%26]);
    }

    cout << output << "\n";

    return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int n; string s; cin >> n >> s;
    vector<int> SW(n+1), SB(n+1);
    SW[0] = 0, SB[0] = 0;
    rep(i, n){
        SW[i+1] = SW[i]; SB[i+1] = SB[i];
        if(s[i] == '.') SB[i+1]++;
        else SW[i+1]++;
    }

    int res = INF;
    rep(i, n+1){
        chmin(res, SW[i]+(SB[n]-SB[i]));
    }
    cout << res << ln;
}

Measured memory_bytes: 2180
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        int c = inp.nextInt();
        int abc[] = {a, b, c};
        Arrays.sort(abc);
        String ab = abc[2] + "" + abc[1];
        int cc = abc[0];
        System.out.println(Integer.parseInt(ab) + cc);
        inp.close();
    }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    int H, W;
    cin >> H >> W;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            string s;
            cin >> s;
            if (s == "snuke") {
                cout << char('A' + j) << i + 1 << endl;
            }
        }
    }

    return 0;
}


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

int main(){
  int A, B, K;
  set<int> st;
  cin >> A >> B >> K;
  for(int i=A;i<=B && i-A<=K-1;i++) st.insert(i);
  for(int i=B;i>=A && B+1-i<=K;i--) st.insert(i);

  for(auto itr = st.begin();itr!=st.end();++itr){
    cout << *itr << endl;
  }
  return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n,a,b;
	cin>>n>>a>>b;

	cout<<max(0LL,((n-1)*b+a)-((n-1)*a+b)+1)<<endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
num_list = [ int(v) for v in input().split() ]
cut_list = []
status = 0
for i in range(n-1):
    if status == 0:
        if num_list[i+1] > num_list[i]:
            status = 1
        elif num_list[i+1] < num_list[i]:
            status = -1
    elif status == 1:
        if num_list[i+1] < num_list[i]:
            cut_list.append(i)
            status = 0
    elif status == -1:
        if num_list[i+1] > num_list[i]:
            cut_list.append(i)
            status = 0

print(len(cut_list)+1)

Measured memory_bytes: 62832
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let n = read::<usize>();
    let mut v = read_vec::<f64>();
    loop {
        v.sort_by(|v1, v2| v1.partial_cmp(v2).unwrap());
        let a = v.remove(0);
        let b = v.remove(0);
        v.push((a + b) / 2.0);

        if v.len() == 1 {
            break;
        }
    }
    println!("{}", v[0]);
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
using ll = long long;

ll n;
ll a[100005];
ll b[100005];
ll ans = 0;

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

    for (int i = n; i >= 1; i--) {
        ll x = min(a[i], b[i]);
        b[i] -= x;
        a[i] -= x;
        ans += x;

        x = min(b[i - 1], a[i]);
        b[i - 1] -= x;
        a[i] -= x;
        ans += x;
    }

    ll x = min(a[0], b[0]);
    ans += x;

    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef long long LL;

const int N = 100010;

char str[N];

int main()
{
    scanf("%s", str + 1);

    int len = strlen(str + 1);
    for(int i = 1; i <= len; i++)
        if(i & 1) cout << str[i];

    return 0;
}


Measured memory_bytes: 384
// Problem : Teleporter
// Contest : Virtual Judge - AtCoder
// URL : https://vjudge.net/problem/AtCoder-abc167_d
// Memory Limit : 1048 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testc   \
    int tcc;    \
    cin >> tcc; \
    for (int tc = 1; tc <= tcc; tc++)
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while (!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
#define int ll

signed main() {
	fast_io;
	ll n,k; cin>>n>>k; vi v(n);
	lp(i,0,n){
		cin>>v[i];
		v[i]--;
	}
	map<int,int> mp;
	mp[0]=0;
	//at city 0 on using tele 0 times
	int cur=0,times=0;
	for(int i=0;k;i++){
		cur=v[cur],times++,k--;
		if(mp.find(cur)!=mp.end()){
			break;
		}
		mp[cur]=times;
	}
	if(k==0){
		cout<<cur+1;
		return 0;
	}
	int cycle_len=times-mp[cur];
	debug(cur,cycle_len,k);
	//reached cur
	k%=cycle_len;
	while(k){
		cur=v[cur],k--;
	}
	cout<<cur+1;
}
// code!=think
// least efficient code to get ac


Measured memory_bytes: 14800
n,m=gets.split.map &:to_i
h=Hash.new(0)
n.times do
  x,y=gets.split.map &:to_i
  h[x]+=y
end
a=h.to_a
a.sort!{|x,y|x[0]<=>y[0]}
c=0
a.each do |e|
  c+=e[1]
  if c>=m
    puts e[0]
    break
  end
end

Measured memory_bytes: 9592
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
const ll INF = 1e18+1;

// N人の A[i] * F[j] の最大値が成績


//A[i]がx回修行すると、x

/*
K 14

1 1 2 3 3 4 5 5 5 6 9 こっからどうやっ

      0 0 0 1

0 0 0 1 1 1 2 5 5 6 9 

左と右比較

0 0 1 2 2 3 4 4 4 5 8

0 0 1 1 1 3 4 4 4 5 7

12だったら
1 1 2 3 3 4 5 5 5 6 9
          2
      1
        1
    1       3 4 4   6   
1 1 1 1 1 2 3 4 4 6 6

2 2 3 3 4 6 7 8 8 9 9

プライオリティキューに積投げてその値以下になるまでA[i]を引いて、
またプライオリティキューに突っ込む
Kが0にならなきゃいいのではないでしょーうか

にぶたん?->良く思いついた!!!
           大小,可否関係が一方向に定まるなら使える

R = max(x * y)を達成できるかどうか
それ以上小さくなると達成できない

大きくなるほど達成しやすくなる

達成できるかがO(N)判定できれば良い
f(R)


*/

int N; ll K;

bool f(ll R, ll sum, vector<ll> A, vector<ll> F) {
    /*priority_queue<pair<ll, ll> > que;
    for (int i = 0; i < N; i++) {
        que.push(make_pair(A[i] * F[N - i - 1], F[i]));
    }
    ll k = K;
    while (k > 0 && que.top().first > R) {
        pair<ll, ll> p = que.top(); que.pop();
        if (p.first > R) {
            ll tmp = (p.first - R + p.second-1) / p.second;
            k -= tmp;
            p.first -= tmp * p.second;
        }
    }
    if (que.top().first <= R) return true;
    return false;*/
    vector<ll> B(N,0);
    for (int i = 0; i < N; i++) {
        ll tmp = min(A[i],R / F[i] );
        if (sum < tmp) {
            B[i] = sum;
            sum = 0;
            break;
        } 
        sum -= tmp;
        B[i] = (R + F[i] - 1) / F[i];
    }
    if (sum == 0) return true;
    return false;

}



int main() {

    cin >> N;
    cin >> K;
    vector<ll> A(N), F(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> F[i];
    }
    sort(A.begin(),A.end());
    sort(F.begin(),F.end(),greater<ll>());

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

    if (K >= sum) {
        cout << 0 << endl;
        return 0;
    }

    ll lb = 0;
    ll rb = 1e12;
    while (rb - lb > 1) {
        ll mid = (rb + lb) / 2;
        if (f(mid,sum-K,A,F)) rb = mid;
        else lb = mid;
    }

    cout << rb << endl;






    
    
}

Measured memory_bytes: 8116
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse = True)

ans = 0

i = 0  # 何人目のフレンドリーさがプラスされるか
nokori = N - 1 # 残り入れなければならない人数
while nokori > 0:
    if i == 0:  # 最もフレンドリーな人は初めに入れる
        ans += A[i]
        nokori -= 1
    else:
        if nokori == 1:
            ans += A[i]
            nokori -= 1
        else:
            ans += 2 * A[i]
            nokori -= 2
    i += 1

print(ans)


Measured memory_bytes: 31444
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 200005
using namespace std;
struct P{
	int l,r;
}a[N];
struct trie{
	int mx,add;
}t[N<<2];
int n,m;
bool cmp(P a,P b){
	return a.l<b.l;
}
void pwd(int k,int l,int r){
	if(l==r) return;
	l=k<<1,r=k<<1|1;
	if(t[k].add){
		t[l].add+=t[k].add;
		t[r].add+=t[k].add;
		t[l].mx+=t[k].add;
		t[r].mx+=t[k].add;
		t[k].add=0;
	}
}
void update(int k,int l,int r,int L,int R,int val){
	pwd(k,l,r);
	if(L<=l&&R>=r){
		t[k].add+=val;
		t[k].mx+=val;
		return;
	}
	int mid=l+r>>1;
	if(L<=mid) update(k<<1,l,mid,L,R,val);
	if(R>mid) update(k<<1|1,mid+1,r,L,R,val);
	t[k].mx=max(t[k<<1].mx,t[k<<1|1].mx);
}
void build(int k,int l,int r){
	if(l==r){
		t[k].mx=l-m;
		return;
	}
	int mid=l+r>>1;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
	t[k].mx=max(t[k<<1].mx,t[k<<1|1].mx);
}
int main(){
	scanf("%d%d",&n,&m);
	m++;
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i].l,&a[i].r);
	sort(a+1,a+n+1,cmp);
	build(1,0,m);
	int ans=0;
	for(int i=0,p=0;i<=m;i++){
		update(1,0,m,0,i,1);
		while(p<n&&a[p+1].l==i) p++,update(1,0,m,0,a[p].r,1);
		ans=max(ans,t[1].mx-i);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 7936
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin>>n;
  string s1;cin>>s1;
  string s2;cin>>s2;
  
  REP(i,n){
    cout<<s1[i];
    cout<<s2[i];
  } 
  cout<<endl;
  return 0;
}

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

#define ll long long
#define pb push_back
#define INF 1'000'000'007
#define cases int t;cin>>t;while(t--)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define ff first
#define ss second

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	ll n;
	cin>>n;
	double p[n];
	rep(i,0,n){
		cin>>p[i];
	}
	double dp[n+1][n+1];
	dp[0][0]=1;
	rep(i,0,n+1){
		rep(j,0,n+1){
			if(i==0&&j==0)
				continue;
			if(i==0){
				dp[i][j]=0;
			}
			else if(j==0){
				dp[i][j]=dp[i-1][j]*(1-p[i-1]);
			}
			else if(i>j){
				dp[i][j]=dp[i-1][j-1]*p[i-1]+dp[i-1][j]*(1-p[i-1]);
			}
			else if(i==j){
				dp[i][j]=dp[i-1][j-1]*p[i-1];
			}
		}
	}
	double x=0;
	rep(i,(n+1)/2,n+1){
		x+=dp[n][i];
	}
	cout<<setprecision(12)<<fixed<<x;
	
	
	
	return 0;
}

Measured memory_bytes: 49940
def linearSearch(A, n, key):
    i = 0
    A.append(key)
    while A[i] != key:
        i += 1
    del A[n]
    return i != n


if __name__ == '__main__':
    n = int(input())
    S = list(map(int, input().split()))
    q = int(input())
    T = list(map(int, input().split()))
    cnt = 0

    for i in range(q):
        if linearSearch(S, n,T[i]):
            cnt += 1

    print(cnt)

Measured memory_bytes: 8572
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int on[101][10];
int gain[101][11];
void solve() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) for(int j = 0; j < 10; j++) cin >> on[i][j];
  for(int i = 0; i < n; i++) for(int j = 0; j <= 10; j++) cin >> gain[i][j];
  int ret = -2e9;
  for(int mask = 1; mask < 1024; mask++) {
    int curr = 0;
    for(int i = 0; i < n; i++) {
      int amt = 0;
      for(int j = 0; j < 10; j++) {
        if(on[i][j] && (mask&(1<<j))) amt++;
      }
      curr += gain[i][amt];
    }
    ret = max(ret, curr);
  }
  cout << ret << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


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

int main(){
    long N,i,temp1,temp2,C=0,ans=0;
    cin>>N>>temp1;
    for(i=1;i<N;i++){
        cin>>temp2;
        if(temp1>=temp2){
            C++;
        }else{
            if(C>ans){
                ans=C;
            }
            C=0;
        }
        temp1=temp2;
    }
    if(C>ans){
        ans=C;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int, input().split()))
mod=10**9+7
x=[0]*(n+1) # 分布

x[0]=3
ans=1

for i in range(n):
    if a[i]==0 and x[0]>0:
        ans*=x[0]
        ans%=mod
        x[0]-=1
        x[1]+=1
    
    elif a[i]==0 and x[0]==0:
        print(0)
        exit()
    
    else:
        if x[a[i]]>0:
            ans*=x[a[i]]
            ans%=mod
            x[a[i]]-=1
            x[a[i]+1]+=1
        
        else:
            print(0)
            exit()
        

print(ans)


    
    
        



Measured memory_bytes: 53100
N,x = map(int,input().split())
a_ = list(map(int,input().split()))
a_.sort()

if x == sum(a_):
  print(N)
else:
  sum_a = 0
  for i in range(N):
    if x >= sum_a + a_[i]:
      sum_a += a_[i]
    else:
      break
  print(i)
  
  

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

int	main() {
	int N;
	cin >>N;
	string S1, S2;
	cin >>S1 >>S2;
	long S=1;
	if (S1.at(0)==S2.at(0))
		S=3;
	else
		S=6;
	for (int i=1; i<N; i++) {
		if (S1.at(i-1)==S2.at(i-1)) {
			S *=2;
			S %=1000000007;
		} else {
			if(S1.at(i-1)!=S1.at(i)) {
				if (S1.at(i)!=S2.at(i)) {
					S *=3;
					S %=1000000007;
				}
			}
		}
	}
	cout <<S <<endl;
	return 0;
};


Measured memory_bytes: 256
#coding: utf-8

def getMatrix(raw_input):
    mlist = []
    for i in range(0, len(raw_input)-1):
        for j in range(i+1, len(raw_input)):
            mlist.append(abs(raw_input[i] - raw_input[j]))
            
    return mlist

def getProduct(mlist):
    plist = []
    for i in range(0, len(mlist)-1):
        for j in range(i+1, len(mlist)):
            plist.append(mlist[i]+mlist[j])
    
    return plist

if __name__ == "__main__":
    raw_input = [int(x) for x in input().split(" ")]
    print(min(getProduct(getMatrix(raw_input))))
    


Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
    int N, p;
    char c;
    int i;
    int ctr = 0;
    
    
    scanf("%d%c", &N, &c);
    
    
    for(i=1; i<=N; i++)
    {
        scanf("%d%c", &p, &c);
        
        if(i != p)
            ctr++;
    }
    
    
    if(ctr <= 2)
        printf("YES\n");
    else
        printf("NO\n");
        
    
    //system("pause");
    
    return 0;
}


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

#define _GLIBCXX_DEBAC
using namespace std;


int main() {
	string s,t;
	cin >> s>>t;
	int ans = 0;
	if (s[0] == t[0]) ans += 1;
	if (s[1] == t[1]) ans += 1;
	if (s[2] == t[2]) ans += 1;
	cout << ans;
		return 0;
}









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

int main()
{
  int n;
  cin >> n;
  int a[n-1];
  int b[n-1];
  for(int c=0;c < n;c++){
    cin >> a[c];
    b[c] = 0;
  }
  int button = 1;
  int ans = 0;
  b[0] = 0;
  do{
    //cout << button<<"\n";
    button = a[button-1];
    if(b[button-1] != 0){
      ans = -1;
      break;
    }
    b[button-1] = 1;
    ans = ans+1;
  }while(button != 2);
  cout << ans;
  return 0;
  
}

Measured memory_bytes: 1024
n = int(input())
l = []
for i in range(n):
    l.append(list(map(str,input().split())))
x = str(input())

cnt = 1
for i in range(n):
    if l[i][0] == x:
        cnt = i+1
ans = 0

for i in range(cnt,n):
    ans += int(l[i][1])

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <iterator>

using namespace std;

typedef long long ll;
#define mems(p) memset(p,-1,sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

ll a[200000], b[200000];

int main() {
	fast();
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i] >> b[i];
	}
	sort(a,a+n);
	sort(b,b+n);
	if (n%2 == 0) {
		ll s1 = a[n/2], s2 = a[n/2 - 1];
		ll sum = s1 + s2;

		s1 = b[n/2], s2 = b[n/2 - 1];
		ll sum2 = s1 + s2;

		//cout << "sum " << sum << " sum2" << sum2 << nl;

		cout << sum2 - sum + 1 << nl;
	} else {
		ll s1 = a[n/2], s2 = b[n/2];
		cout << s2 - s1 + 1 << nl;
	}
}

Measured memory_bytes: 6744
N = int(input())
seq = input()

left = 0
right = N-1
c = 0

while True:
  if right <= left:
    break
  if seq[left] == "R":
    left += 1
    continue
  if seq[right] == "W":
    right -= 1
    continue
  left += 1
  right -= 1
  c += 1

print(c)


Measured memory_bytes: 9508
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	vector<int>A(3);
	for (int i = 0; i < 3; i++) cin >> A.at(i);
	sort(A.begin(), A.end());
	int ans = 3;
	if (A.at(0) == A.at(1))ans--;
	if (A.at(1) == A.at(2))ans--;
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int hp = scanner.nextInt();
        int attack = scanner.nextInt();
        System.out.println(divideCeil(hp, attack));
    }

    static int divideCeil(int numerator, int denominator) {
        double a = numerator;
        double b = denominator;
        return (int) Math.ceil(a / b);
    }
}

Measured memory_bytes: 21844
import java.util.*;

class Main {
	
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int rept = in.nextInt();
		while(rept-- > 0){
			int x1 = in.nextInt(), y1 = in.nextInt(), x2 = x1 + in.nextInt(), y2 = y1 + in.nextInt();
			int n = in.nextInt();
			int ans = 0;
			while(n-- > 0){
				int x = in.nextInt(), y = in.nextInt();
				if(x1<=x && x<=x2 && y1<=y && y<=y2) ans++;
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
import sys
input = sys.stdin.readline
class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]

n,q = map(int,input().split())
U = Unionfind(n)
for i in range(q):
    t,u,v = map(int,input().split())
    if t == 0:
        U.union(u,v)
    else:
        print(int(U.same(u,v)))

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

using ll = long long;
using pii = pair<int, int>;

const int MXCOORD = 100000;

int main(int argc, char **argv)
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  int n; cin >> n;
  vector<pii> pts;
  vector<set<pii>> xpts(MXCOORD+1);
  vector<set<pii>> ypts(MXCOORD+1);

  for(int i=0; i<n; i++) {
    int x, y; cin >> x >> y;
    xpts[x].insert({x, y});
    ypts[y].insert({x, y});
    pts.push_back({x, y});
  }

  map<pair<int, int>, bool> done;

  ll res = 0;
  for(int i=0; i<n; i++) {
    if(!(xpts[pts[i].first].size() > 1 && ypts[pts[i].second].size() > 1)) continue;
    if(done[pts[i]]) continue;

    set<pair<int, int>> ptset;
    queue<pii> q;
    q.push({pts[i]});
    done[pts[i]]= true;

    while(q.size()) {
      pii p = q.front(); q.pop();
      ptset.insert(p);
      for(auto t : xpts[p.first]) {
        if(done[t]) continue;
        q.push(t);
        done[t] = true;
      }
      for(auto t : ypts[p.second]) {
        if(done[t]) continue;
        q.push(t);
        done[t] = true;
      }

      xpts[p.first].clear();
      ypts[p.second].clear();
    }

    set<int> xset, yset;
    for(auto p : ptset) {
      xset.insert(p.first);
      yset.insert(p.second);
    }

    res += 1LL*xset.size()*yset.size() - ptset.size();
  }

  cout << res << endl;

  return 0;
}

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

int main() {
	int a, b;
	cin >> a;
	cin >> b;
	if (a*b % 2 == 0) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}

}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int x1, x2, x3, x4, x5; cin >> x1 >> x2 >> x3 >> x4 >> x5;
	if (x1 == 0){cout << 1 << endl;}
	if (x2 == 0) { cout << 2 << endl; }
	if (x3 == 0) { cout << 3 << endl; }
	if (x4 == 0) { cout << 4 << endl; }
	if (x5 == 0) { cout << 5 << endl; }
}

Measured memory_bytes: 3560
#include<iostream>
#include<stdio.h>
int cnt=0;
void inSort(int A[],int n,int g){
  int i,j,v;
  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0 && A[j]>v){
      A[j+g]=A[j];
      j-=g;
      ++cnt;
    }
    A[j+g]=v;
  }
}
void shSort(int A[],int n){
  int i,j,k,l,G[20];

  int m=0; for(i=1;i<=n;i=i*3+1) G[m++]=i;

  for(i=m-1;0<=i;i--) inSort(A,n,G[i]);

  printf("%d\n%d",m,G[m-1]);
  for(i=m-2;0<=i;i--) printf(" %d",G[i]);
  printf("\n%d\n",cnt);
  for(i=0;i<n;i++) printf("%d\n",A[i]);
}
int main(){
  int i,n,A[1000000];
  std::cin>>n;
  for(i=0;i<n;i++) std::cin>>A[i];
  shSort(A,n);
  return 0;
}

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

class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String strTateYoko = br.readLine();
		String[] tateYoko = strTateYoko.split(" ");
		Integer tate = Integer.parseInt(tateYoko[0]);
		Integer yoko = Integer.parseInt(tateYoko[1]);
		System.out.println(tate*yoko + " " + (tate*2+yoko*2));
	}

}

Measured memory_bytes: 16904
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
const ll INF = 1e17;
const int MOD = 1e9 + 7;

ll N[4];
ll ans;


int main(void) {
	cin >> N[0]>>N[1]>>N[2]>>N[3];
	sort(N, N + 4);
	if (N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9)ct("YES");
	else ct("NO");


	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int loop = scan.nextInt();
        int array = scan.nextInt();
        String huruf = scan.next();
        String haraf = huruf.substring(array-1, array).toLowerCase();
        System.out.println(huruf.substring(0, array-1)+haraf+huruf.substring(array, loop));
    }
}


Measured memory_bytes: 26888
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
    string s;
    cin >> s;
    if(s=="Sunny") cout << "Cloudy" << endl;
    else if(s=="Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
}


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

int main() {
  int64_t A,V,B,W,T;
  cin >> A >> V >> B >> W >> T;
  if(A<B){
    if(V<=W){
    cout << "NO" << endl;
    return 0;
    }
    if((A+V*T)>=(B+W*T)){
      cout << "YES" << endl;
      return 0;
    }
    cout << "NO" << endl;
    return 0;
  }
  
  if(V<=W){
    cout << "NO" << endl;
    return 0;
  }
  if((A-V*T)<=(B-W*T)){
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  ll x;
  cin >> x;
  x = abs(x);
  ll k,d;
  cin >> k >> d;
  if(k < (x+d-1)/d){//原点にたどり着けない場合
    cout << x-k*d << endl;
  }
  if(k >= (x+d-1)/d){
    if(k%2 == 0){
      cout << min(x%(2*d),2*d-x%(2*d)) << endl;
    }
    if(k%2 == 1){
      x += d;
      cout << min(x%(2*d),2*d-x%(2*d)) << endl;
    }
  }
}


Measured memory_bytes: 3628
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	string s, t = "CODEFESTIVAL2016";
	cin>>s;
	int res = 0;
	rep(i, s.size()) res += s[i]!=t[i];
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
N=int(input())
a=[int(input()) for x in range(N)]

max=sum(a)
if(max%10!=0):
        ans=max
else:
        ans=10000000
        for i in a:
                if(i%10!=0 and i<ans):
                        ans=i
        ans=max-ans if(ans!=10000000) else 0
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n, m;
    cin >> n >> m;
    vector<bool> flg(n, false);
    flg[0] = true;
    vector<int> cnt(n, 1);
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        if (flg[x]) flg[y] = true;
        ++cnt[y];
        --cnt[x];
        if (cnt[x] == 0) flg[x] = false;
    } 
    int ans = 0;
    rep(i, n) {
        if (flg[i]) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3684
using System;

namespace ABC122_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var ans = string.Empty;
            if (s == "A") ans = "T";
            if (s == "T") ans = "A";
            if (s == "C") ans = "G";
            if (s == "G") ans = "C";
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
import math

A,B,H,M = list(map(int, input().split()))

jikan = (H/12 + M/(60 *12)) * 360
hun = (M/60) * 360

kakudo = jikan - hun

ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(kakudo * math.pi / 180))
print(ans)

Measured memory_bytes: 62180
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		String[] S=sc.next().split("");

		int W= sc.nextInt();

		int ptr=0;

		StringBuilder ans=new StringBuilder();
		while(ptr<=S.length-1) {

			String buf=S[ptr];

			ans.append(buf);

			ptr+=W;

		}

		pln(ans.toString());
	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

	static int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  string S;
  string T;
  cin>>S;
  cin>>T;
  T.pop_back();
  if(S == T){
    cout<<"Yes"<<'\n';
  }else{
    cout<<"No"<<'\n';
  }
}

Measured memory_bytes: 3620
n, k = map(int, input().split())
A = list(map(int, input().split()))

visit = [-1] * n   #到達しているかどうかを管理

D = [1]  # 循環するもののindexを格納

tmp = A[0]  #初期位置
ct = 1

while visit[tmp - 1] == -1:
    D.append(tmp)
    visit[tmp - 1] = ct  #到達済に変更
    if k == ct:
        print(tmp)
        exit()
    ct += 1
    tmp = A[tmp - 1]

#循環している場合の残りの処理
k -= visit[tmp - 1]
k %= (ct - visit[tmp - 1])
print(D[visit[tmp - 1] + k])

Measured memory_bytes: 32280
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

const int INF = 1001001001;

void Main() {
  Cin(int, n);

  int maxa = 0, minb = INF;
  for (int i = 0; i < n; ++i) {
    Cin(int, a, b);
    if (a > maxa) {
      maxa = a;
      minb = b;
    }
  }

  cout << maxa + minb << endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

ll dp[65][200010]={};

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,k;cin>>n>>k;
  rep(i,0,n){
    int x;cin>>x;
    dp[0][i]=--x;
  }

  rep(i,1,64){
    rep(j,0,n){
      dp[i][j]=dp[i-1][dp[i-1][j]];
    }
  }

  ll now=0;
  rep(i,0,64){
    if(k&(1ll<<i)){
      now=dp[i][now];
    }
  }
  cout<<now+1<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 103624
#include <iostream>
using namespace std;
int main(){
	string s1, s2;
	int n;
	cin>>n;
	while(n--){
		string m1, m2, m;
		int k=0;
		cin>>s1>>s2;
		if(s1.length()>80 || s2.length()>80){
			cout<<"overflow"<<endl;
		}
		else{
			if(s1.length()<s2.length()){
				string memo=s1;
				s1=s2;
				s2=memo;
			}
			int c1=s1.length(), c2=s2.length();
			for(int i=s2.length()-1; i>=0; i--){
				k+=s1[i+c1-c2]-'0'+s2[i]-'0';
				m=to_string(k%10)+m;
				k=k/10;
			}
			for(int i=c1-c2-1; i>=0; i--){
				k+=s1[i]-'0';
				m=to_string(k%10)+m;
				k=k/10;
			}
			if(k==1)
				m=to_string(k)+m;
			if(m.length()>80)
				cout<<"overflow"<<endl;
			else
				cout<<m<<endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3232