akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iostream>
#include<string>
#include<sstream>
#include<set>
#include<map>
#include<vector>
#include<algorithm>
#include<queue>
#include<utility>
using namespace std;

#define i64 long long int

bool chk(string s) {
	int len = s.size();
	if (s[0]!='A') return false;
	int fnd = -1;
	for(int i=2;i<len-1;i++)
		if(s[i]=='C') fnd = i;
	if (fnd<0) return false;
	for(int i=1;i<len;i++)
		if (i!=fnd && s[i]<'a') return false;
	return true;
}

int main() {
	string s; cin>>s;
	puts(chk(s)? "AC" : "WA");
	
	return 0;
}	



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

bool ck[1000001];

int main()
{
	int n,s[2];
	while(scanf("%d%d%d", &n,&s[0],&s[1]), (n||s[0]||s[1]))
	{
		int ans=n;
		memset(ck, 0, sizeof(ck));
		ck[0]=1;
		
		for(int i=0; i<=n; i++)
		{
			if(ck[i]==0) continue;
			for(int j=0; j<2; j++)
			{
				int p=i+s[j];
				if(p>n) continue;
				if(ck[p]==0)
				{
					ck[p]=1;
					ans--;
				}
			}
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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;
}
///////////////////////////////////////////////////////////////

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

    vector<int> dist(K,INF);
    dist[1] = 1;
    deque<int> deq;
    deq.emplace_front(1);
    while (!deq.empty()) {
        int n = deq.front(); deq.pop_front();
        int k = n*10%K;
        if (chmin(dist[k],dist[n])) deq.emplace_front(k);
        k = (n+1)%K;
        if (chmin(dist[k],dist[n]+1)) deq.emplace_back(k);
    }

    cout << dist[0] << endl;
} 


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

int main() {
    int a;
    int b;
    int sum_a_b = 0;
    int sum_b_a = 0;
    cin >> a >> b;
/*    cout << a << b << endl;*/
    for (int i=0; i <= b ; ++i) {
      sum_a_b = sum_a_b + a * pow(10,i-1) ;
/*    cout << "i:" << i ;
    cout << "sum_a_b:" << sum_a_b << endl;
*/
    }
/*    cout << "sum_a_b:" << sum_a_b << endl;
*/
    for (int i=0; i <= a ; ++i) {
      sum_b_a = sum_b_a + b * pow(10,i-1) ;
    }
    if (a > b) {
      cout << sum_b_a << endl;
    }
    else { cout << sum_a_b << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

main(){
  int x,y,z,i;
    scanf("%d %d",&x,&y);
    while(1){
    z = x % y;
    if(z!=0){
      x=y;
      y=z;
    }
    if(z==0) break;
  }
  if(z==0) printf("%d\n",y);
  return 0;
}

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

int n,l;
string s[233];

int main(){
	cin >> n >> l;
	for(int i = 1; i <= n; i++) cin>>s[i];
	sort(s+1,s+1+n);
	for(int i = 1; i <= n; i++) cout<<s[i];
	return 0; 
}

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

int main(){
  int N;
  cin>>N;
  vector<int>L(N);
  rep(i,N)cin>>L[i];
  sort(L.begin(),L.end());
  
  int tmp;
  int ans=0;
  rep(i,N-2){
    for (int j=i+1;j<N-1;++j){
      tmp=lower_bound(L.begin(),L.end(),L[i]+L[j])-L.begin();
      ans+=tmp-j-1;
    }
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i

abc = "abcdefghijklmnop"

combs = [["", 0]]

n.times do
  poyo = []
  combs.each do |x|
    xs = x[0]
    k = x[1]

    k.times do |y|
      poyo << [xs + abc[y], k]
    end

    poyo << [xs + abc[k], k + 1]
  end

  combs = poyo
end

combs.each do |x|
  puts x[0]
end


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

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

  vector<int> d(N);

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

  sort( d.begin(), d.end() );

  int a = 1;

  for( int i = 0; i < N - 1; i++ ){
    if ( d.at(i) < d.at(i + 1) ){
      a += 1;
    }
  }

  cout << a << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

//Range Minimum Query
struct segment {
    int n;
    vector<vi> dat;
    // n_は範囲
    segment(int n_) { // nはn_以上の2^?
        n = 1<<(32-__builtin_clz(n_));
        if(n == 2*n_) n >>= 1;
        dat.assign(2*n-1, vi(26));
    }
    inline int chld(int i) {return 2*i+1;}
    inline int chrd(int i) {return 2*i+2;}
    //更新の手順
    inline void theorem(int i, int c) {
        dat[i][c] = dat[chld(i)][c] + dat[chrd(i)][c];
    }
    // k番目の値をaに変更
    void update(int k, int c, int x) {
        // 葉の節点
        k += n-1;
        dat[k][c] += x;
        // 登りながら更新
        while(k>0) {
            k = (k-1)/2;
            theorem(k, c);
        }
    }
    //kは節点の番号, [l, r)に節点が対応
    // (a, b, 0, 0, .n)で呼ぶ
    set<int> query_(int a, int b, int k, int l, int r) {
        if(a>=r || l>=b) return set<int>();
        if(a<=l && r<=b) {
            set<int> se;
            rep(i, 26) {
                if(dat[k][i]) se.insert(i);
            }
            return se;
        }
        else {
            int chl = k*2+1;
            int chr = k*2+2;
            set<int> vl = query_(a, b, chl, l, (l+r)/2);
            set<int> res = query_(a, b, chr, (l+r)/2, r);
            for(int x:vl) {
                res.insert(x);
            }
            return res;
        }
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    segment seg(n);
    rep(i, n) seg.update(i, s[i]-'a', 1);

    int q;
    cin >> q;
    while(q--) {
        int t;
        cin >> t;
        if(t == 1) {
            int i;
            char c;
            cin >> i >> c;
            seg.update(i-1, c-'a', 1);
            seg.update(i-1, s[i-1]-'a', -1);
            s[i-1] = c;
        } else {
            int l, r;
            cin >> l >> r;
            cout << (int)seg.query_(l-1, r, 0, 0, seg.n).size() << endl;
        }
    }
}

Measured memory_bytes: 143172
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cassert>
#include <numeric>
#include <queue>
#include <unordered_set>

using namespace std;

inline int32_t count1(uint64_t b) {
    int n = 0;
    while (b > 0) {
        if ((b & 1) > 0) {
            ++n;
        }
        b = b >> 1;
    }

    return n;
}

int64_t solve(const vector<uint64_t>& f, const vector<vector<int64_t>>& p) {
    auto num_cell = 10;

    int64_t m = numeric_limits<int64_t>::min();
    for (uint64_t c = 1; c < 1 << num_cell; ++c) {
        int64_t benefit = 0;
        for (int i = 0; i < f.size(); ++i) {
            auto num_dup = count1(c & f[i]);
            benefit += p[i][num_dup];
        }

        m = max(benefit, m);
    }

    return m;
}

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

    vector<uint64_t> f(n);
    for (auto&& ff : f) {
        for (int i = 0; i < 10; ++i) {
            int c;
            cin >> c;
            if (c > 0) {
                ff += 1;
            }
            ff = ff << 1;
        }
        // revert the last shift
        ff = ff >> 1;
    }

    vector<vector<int64_t>> p(n);
    for (auto&& pp : p) {
        pp.resize(11);
        for (int i = 0; i < 11; ++i) {
            cin >> pp[i];
        }
    }

    cout << solve(f, p) << endl;

    return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		
		while(stdIn.hasNext()){
			double a = stdIn.nextDouble();
			double b = stdIn.nextDouble();
			double c = stdIn.nextDouble();
			double d = stdIn.nextDouble();
			double e = stdIn.nextDouble();
			double f = stdIn.nextDouble();
			
			double y = (f*a - c*d)/(e*a - b*d);
			double x = (c - b*y)/a;
			System.out.printf("%.3f ",x);
			System.out.printf("%.3f\n",y);
		}
	}
}

Measured memory_bytes: 20476
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000000
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;
typedef long long ll;

int main() {
  int N;
  scanf("%d", &N);
  vi R(N);
  vector<double> O(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> R[i];
  }
  double width = R[0] * 2;
  O[0] = R[0];
  for (int i = 1; i < N; i++) {
    if (width <= R[i] * 2) {
      width = R[i] * 2;
      O[i] = R[i];
    }
    for (int j = 0; j < i; j++) {
      double w = sqrt( 1.0 - pow((double)(R[j] - R[i]) / (R[j] + R[i]), 2.0) ) * (R[j] + R[i]) + O[j] + R[i];
      width = max(width, w);
      O[i] = max(O[i], w - R[i]);
    }
  }
  printf("%.9f\n", width);
}

Measured memory_bytes: 1264
#include<stdio.h>
#include<math.h>
#define max(a,b) ((a)>(b)?(a):(b))

int w[100];
int m, n;

int func(int h) {
	int i=0, sum = 0,count=0;
	while(i<n && count < m){
		if (h >= sum + w[i]) 
			sum += w[i++];
		else {
			sum = 0;
			count++;
        }
	}
	return i == n && count < m;
}

int binsearch_func(int low, int hight) {
	int i;
	for (i = 0; i < 100; i++) {
		int mid = (low + hight) / 2;
		int midval = func(mid);

		if (midval)hight = mid;
		else low = mid;
	}
	return max(low,hight);
}

int main(void)
{
	int sum;
	int i;
	while (1) {
		scanf("%d %d", &m, &n);
		if (m == 0 && n == 0)break;
		sum = 0;
		for (i = 0; i < n; i++) {
			scanf("%d",&w[i]);
			sum += w[i];
		}
		printf("%d\n", binsearch_func(0, 10000000));
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define N 4000000 + 5
#define rep(i, l, r) for(int i = l; i <= r; ++i)
int n, x, sum;
bitset <N> dp;
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int main(){
    n = read();
    dp[0] = 1;
    rep(i, 1, n) x = read(), dp |= (dp << x), sum += x;
    rep(i, (sum + 1) / 2, sum) if(dp[i]){ printf("%d", i); break;}
    return 0;
}

Measured memory_bytes: 1664
//
//  main.cpp
//  C-snuke_the_wizard
//
//  Created by david chong on 8/21/19.
//  Copyright © 2019 david chong. All rights reserved.
//

#include <iostream>
#include <vector>
#include <map>

using namespace std;

// thanks Aram! <3 <3 <3
int elegantSolution(vector<char> & charVec, vector<char> & squareVec, vector<char> & dirVec) {
    
    char lhs, rhs, c, d, lastChar, lastD, myIdx;
    
    
    int leftIdx = 0;
    int rightIdx = charVec.size()-1;
    
    lhs = charVec.front();
    rhs = charVec.back();
    
    for(int i = squareVec.size()-1; i >= 0; i--) {
        c = squareVec[i];
        d = dirVec[i];
        
        if(c == charVec[leftIdx] && d == 'L') {
            leftIdx++;
        } else if(0 < leftIdx && charVec[leftIdx-1] == c && d == 'R') {
            leftIdx--;
        }
        
        if(c == charVec[rightIdx] && d == 'R') {
            rightIdx--;
        } else if( (rightIdx < charVec.size()-1) && charVec[rightIdx+1] == c && d == 'L') {
            rightIdx++;
        }
        
        if(leftIdx > rightIdx) {
            break;
        }
        
//        printf("%i:%i   %i\n", leftIdx, rightIdx, (rightIdx+1)-leftIdx);
    }
    
    //    printf("%i:%i \t %i \t %i\n", leftIdx, rightIdx, (rightIdx+1)-leftIdx, doubleHeadCount);
    
    //    printf("*** %i\n", charVec.size());
    
    
    int result = 0;
    
    if(rightIdx > leftIdx) {
        result = (rightIdx+1) - leftIdx;
    }
    
    return result;
}

int main(int argc, const char * argv[]) {
    
    //    freopen("input.in", "r", stdin);
//        freopen("test_03.txt", "r", stdin);
//        freopen("test_18.txt", "r", stdin);
    
    int n, q;
    
    string str;
    
    cin >> n >> q;
    
    vector<char> charVec(n);
    vector<char> squareVec(q);
    vector<char> dirVec(q);
    
    cin >> str;
    
    
    
    for(int i = 0; i < str.size(); i++) {
        charVec[i] = str[i];
    }
    
    
    //    cout << lhs << " " << rhs << endl;
    
    for(int j = 0; j < q; j++) {
        //        cin >> c >> d;
        //        printf("%c %c\n", c, d);
        cin >> squareVec[j] >> dirVec[j];
    }
    
    
    cout << elegantSolution(charVec, squareVec, dirVec) << endl;
    
    //    cout << solve(inVec, myMap, squareVec, dirVec, lhs, rhs) << endl;
    
    
    return 0;
}


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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; read(n);
	set<int> s;
	rep(i, 0, n) {
		int t; read(t);
		s.insert(t);
	}
	int a = *prev(s.end());
	s.erase(prev(s.end()));

	vector<int> b;

	auto it = s.lower_bound(a / 2);
	if (it != s.end())
		b.push_back(*it);
	if (it != s.begin())
		b.push_back(*prev(it));

	if (b.size() == 1)
		write(a, b[0]);
	else {
		int b1 = b[0], b2 = b[1];
		int v1 = min(b1, a - b1), v2 = min(b2, a - b2);
		if (v1 > v2) write(a, b1);
		else write(a, b2);
	}
}


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && a == c) {
    cout << 1 << endl;
  }
  else if (a == b && a != c) {
    cout << 2 << endl;
  }
  else if (a != b && b == c) {
    cout << 2 << endl;
  }
  else if (a != b && a == c) {
    cout << 2 << endl;
  }
  else {
    cout << 3 << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();

		int menseki = H * W;
		int nuri = (h * W) + (w * H) - (h * w);	

        System.out.println(menseki - nuri);
    }
}


Measured memory_bytes: 23636
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def bfs(dist, black, H, W):
    q = deque(black)

    res = 0
    while q:
        h, w = q.pop()

        for dh, dw in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            nh = h + dh
            nw = w + dw
            if 0 <= nh < H and 0 <= nw < W:
                if dist[nh][nw] == -1:
                    dist[nh][nw] = dist[h][w] + 1
                    if res < dist[nh][nw]:
                        res = dist[nh][nw]
                    q.appendleft((nh, nw))

    return res


def main():
    H, W = map(int, input().split())
    A = [input() for _ in range(H)]
    black = []
    dist = [[-1] * W for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#":
                black.append((h, w))
                dist[h][w] = 0

    ans = bfs(dist, black, H, W)
    print(ans)


if __name__ == "__main__":
    main()


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


int main() {
  ll X;
  cin >> X;
  vector<ll> nums(238);
  for (ll i = -118; i <= 119; i++) nums[i + 118] = pow(i, 5);

  int a = -1000, b = -1000;
  for (ll i = -118; i <= 119; i++) {
    for (ll j = -118; j <= 119; j++) {
      if (nums[i + 118] - nums[j + 118] == X) {
        a = i; b = j;
        break;
      }
    }
    if (a > -1000) break;
  }
  
  cout << a << ' ' << b << endl;
  return 0;
}


Measured memory_bytes: 4012
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<cctype>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<fstream>
#include<iomanip>
#include<queue>
#include<set>
#include<stack>
#include<string>
using namespace std;
#define PI 3.1415926535897932384626433832795028
#define eps 1e-8
#define inf 2000000000
typedef long long LL;

double ans = 0;
double dis[25][25];
double num[25][3];
int vis[25] = {0}, n, m;

void dfs(int rank, int cur) {
	if (rank == m) {
		double sum = 0;
		int pre[25], p = 0;
		for (int i = 0; i < n; i++) {
			if (vis[i]) {
				pre[p++] = i;
			}
		}
		for (int i = 0; i < p; i++) {
			for (int j = i + 1; j < p; j++) {
				sum += dis[pre[i]][pre[j]];
			}
		}
		/*for (int i = 0; i < p; i++) {
			printf(" %d", pre[p]);
		}
		printf("\n");*/
		ans = max(ans, sum);
		return;
	}
	for (int i = cur; i < n; i++) {
		if (!vis[i]) {
			vis[i] = 1;
			dfs(rank+1, i+1);
			vis[i] = 0;
		}
	}
}

int main() {
	while (cin >> n >> m) {
		for (int i = 0; i < n; i++)
			cin >> num[i][0] >> num[i][1] >> num[i][2];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i == j) {
					dis[i][j] = 0;
					continue;
				}
				dis[i][j] = (num[i][0]-num[j][0])*(num[i][0]-num[j][0])+(num[i][1]-num[j][1])*(num[i][1]-num[j][1])+(num[i][2]-num[j][2])*(num[i][2]-num[j][2]);
			}
		}
		dfs(0, 0);
		printf("%lf\n", ans);
	}
	return 0;
}

Measured memory_bytes: 936
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//FizzBuzz
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int m = sc.nextInt();
			int n = sc.nextInt();
			if((m|n)==0)break;
			List<Integer> p = new ArrayList<Integer>();
			for(int i=1;i<=m;i++)p.add(i);
			int k = 1;
			int pos = 0;
			while(n--!=0){
				String s = sc.next();
				if(p.size()==1)continue;
				String c = k+"";
				if(k%15==0)c="FizzBuzz";
				else if(k%5==0)c="Buzz";
				else if(k%3==0)c="Fizz";
				if(c.equals(s))pos=(pos+1)%p.size();
				else {
					p.remove(pos);
					pos %= p.size();
				}
				k++;
			}
			boolean h = true;
			for(int x:p){
				if(!h)System.out.print(" ");
				h = false;
				System.out.print(x);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int k = sc.nextInt();
        int t = sc.nextInt();
        int max = 0;
        for (int i = 0; i < t; i++) {
            int a = sc.nextInt();
            max = Math.max(max, a);
        }

        if (k - max < max) {
            System.out.println(max - (k - max) - 1);
        } else {
            System.out.println(0);
        }
    }
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;

const int N = 1e6;
const int LOG = 61;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLMOD = 998244353;
const ll LLINF = 1e18;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, d;
    cin >> n >> d;
    cout << n / (2 * d + 1) + (n % (2 * d + 1) != 0) << "\n";

}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)
#define fi first
#define se second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  string s, t;
  cin >> s >> t;

  int orig_s = sz(s);
  s += s;
  unordered_map<char, vec<int>> cnt;
  rep(i, 0, sz(s)) cnt[s[i]].pb(i);

  ll loop = 0;
  int index = -1;
  rep(i, 0, sz(t)) {
    char c = t[i];
    if (sz(cnt[c]) == 0) {
      put(-1);
      return 0;
    }

    index = *upper_bound(all(cnt[c]), index);
    if (index >= orig_s) {
      loop++;
      index -= orig_s;
    }
  }

  put(loop * orig_s + index + 1);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[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;
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main() {
	ll n; cin>>n;
	if(n==1) return cout<<0<<endl,0;
	ll ans=0LL;
	ll g=n;
	ll last=2LL;
	for(ll i=2; i*i<=n; i++){
		ll cnt=1LL, tmp=0LL;
		while(n%i==0){
			n/=i; tmp++;
			if(tmp==cnt){
				ans++;
				tmp=0LL; cnt++;
			}
		}
		last=i;
	}
	if(n>last) ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <string>

using namespace std;

struct Date {
    int year, month, day;
    Date(int year=0, int month=1, int day=1) : year(year), month(month), day(day) {}
    bool operator<(const Date &o) const {
        if (year == o.year) {
            if (month == o.month) {
                return day < o.day;
            }
            return month < o.month;
        }
        return year < o.year;
    }
};

int main() {
    int year, month, day;
    Date meiji_start(1868, 9, 8), meiji_end(1912, 7, 29),
         taisho_start(1912, 7, 30), taisho_end(1926, 12, 24),
         showa_start(1926, 12, 25), showa_end(1989, 1, 7),
         heisei_start(1989, 1, 8);

    while (cin >> year >> month >> day) {
        Date date(year, month, day);
        if (date < meiji_start) {
            cout << "pre-meiji" << endl;
        } else if (date < taisho_start) {
            cout << "meiji " << date.year - meiji_start.year   + 1 << ' ' << date.month << ' ' << date.day << endl;
        } else if (date < showa_start) {
            cout << "taisho " << date.year - taisho_start.year + 1 << ' ' << date.month << ' ' << date.day << endl;
        } else if (date < heisei_start) {
            cout << "showa " << date.year - showa_start.year   + 1 << ' ' << date.month << ' ' << date.day << endl;
        } else {
            cout << "heisei " << date.year - heisei_start.year + 1 << ' ' << date.month << ' ' << date.day << endl;
        }
    }

    return 0;
}

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

using namespace std;

int main(){
  string S, T;
  cin >> S >> T;
  int Ssize = S.size();
  int Tsize = T.size();
  int count = 0;
  for(int i = 0; i < Tsize; i++){
    if(T.at(i) != S.at(i)) count++;
  }
  for(int i = 0; i < Ssize - Tsize; i++){
    int tmp_count = 0;
    for(int j = 0; j < Tsize; j++){
      if(T.at(j) != S.at(i+j)) tmp_count++;
    }
    if(tmp_count < count ) count = tmp_count;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3604
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy
from collections import defaultdict

def main():
  h, w, m = map(int, input().strip().split())
  fieldh = numpy.zeros(h, dtype=numpy.int)
  fieldw = numpy.zeros(w, dtype=numpy.int)
  field = defaultdict(int)
  for _ in range(m):
    ih, iw = map(int, input().strip().split())
    fieldh[ih-1] += 1
    fieldw[iw-1] += 1
    field[ih-1, iw-1] = 1
    
  max_h = numpy.max(fieldh)
  max_w = numpy.max(fieldw)
  argsort_h = [ ih for ih in range(h) if fieldh[ih] == max_h ]
  argsort_w = [ iw for iw in range(w) if fieldw[iw] == max_w ]
  
  max_cnt = 0
  for ih in argsort_h:
    for iw in argsort_w:
      if field[ih, iw] == 0:
        max_cnt = max(max_cnt, fieldh[ih]+fieldw[iw])
        print(max_cnt)
        return 
      else:
        max_cnt = max(max_cnt, fieldh[ih]+fieldw[iw]-1)
  print(max_cnt)

if __name__=='__main__':
  main()



Measured memory_bytes: 103324
# -*- coding: utf-8 -*-
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(1, n - 1):
    if p[i + 1] > p[i - 1]:
        if p[i + 1] > p[i] and p[i] > p[i - 1]:
            cnt += 1
    else:
        if p[i - 1] > p[i] and p[i] > p[i + 1]:
            cnt += 1

print(cnt)

Measured memory_bytes: 38384
n = int(input())

Cards = ["S 1", "S 2", "S 3", "S 4", "S 5", "S 6", "S 7", "S 8", "S 9", "S 10", "S 11", "S 12", "S 13",
         "H 1", "H 2", "H 3", "H 4", "H 5", "H 6", "H 7", "H 8", "H 9", "H 10", "H 11", "H 12", "H 13",
         "C 1", "C 2", "C 3", "C 4", "C 5", "C 6", "C 7", "C 8", "C 9", "C 10", "C 11", "C 12", "C 13",
         "D 1", "D 2", "D 3", "D 4", "D 5", "D 6", "D 7", "D 8", "D 9", "D 10", "D 11", "D 12", "D 13",
        ]

for i in range(n):
    c = input()
    Cards.remove(c)
for c in Cards:
    print(c)




Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
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 long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    string n;
    cin>>n;
    
    if(n[0]== '9' || n[1] == '9')cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}



Measured memory_bytes: 256
N = int(input())

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

Alist.sort()
Alist = Alist[::-1]

if N%2==0:
    n = int((N-2)/2 + 1)
    ans = 2 * sum(Alist[:n]) - Alist[0]
    print(ans)

else:
    n = int((N-1)/2 + 1)
    ans = 2 * sum(Alist[:n]) - Alist[0] - Alist[n-1]
    print(ans)


Measured memory_bytes: 31604
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}


int main()
{
  string s ;
  cin >> s ;
  string t = "CODEFESTIVAL2016" ;
  int cnt = 0 ;
  
  REP(i,16){
    if(s.at(i)!=t.at(i)){
      cnt++ ;
    }
  }
  
  cout << cnt <<endl ;
  


  return 0 ;
}




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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repp(i, n) rep(i, n)
#define reppp(i, n) repp(i, n)
#define rrepp(i, n) rrep(i, n)
#define repss(i, n) reps(i, n)
#define repcc(i, n) repc(i, n)
#define repii(i, a, b) repi(i, a, b)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int n, k; cin >> n >> k;
  if (n > k) cout << 0 << '\n';
  else cout << 1 << '\n';
}



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

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int h, n; cin >> h >> n;
	vector<int> a(n), b(n);
	REP(i, n) cin >> a[i] >> b[i];

	vector<int> dp(h + 1, INT_MAX);
	dp[0] = 0;
	for (int i = 1; i <= h; i++) REP(j, n)
		dp[i] = min(dp[i], dp[max(0, i-a[j])] + b[j]);
	cout << dp[h] << '\n';
    return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> A(N), B(N);
  rep(i, N) cin >> A[i] >> B[i];
  sort(all(A));
  sort(all(B));
  double l, r;
  if(N % 2 == 0) {
    l = (A[N/2-1]+A[N/2])/2.0;
    r = (B[N/2-1]+B[N/2])/2.0;
    cout << (ll)((r-l)*2.0)+1 << endl;
  } else {
    l = A[N/2];
    r = B[N/2];
    cout << (ll)(r-l)+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 6356
s = input()
t = input()

l_s = len(s)
l_t = len(t)

ans = l_t
for i in range(0, l_s - len(t) + 1):
	cnt = 0
	for j in range(l_t):
		if t[j] == s[i:i + l_t][j]:
			cnt += 1
	ans = min(ans, l_t - cnt)
print(ans)




Measured memory_bytes: 9012
use proconio::input;

fn main() {
    input! {
        a: String,
        b: String,
    }
    let b: Vec<char> = b.chars().collect();
 	let mut count = 0;
    for (i, c) in a.chars().enumerate() {
       if b[i] != c {
         count += 1;
       }
    }
    println!("{}", count);
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#define ll long long
using namespace std;

int main(){
	ll n, a;
	ll x[51];
	// ll dp[55][55][2505];
	// dp[i][j][k] 
	// i番目のカードの中からj個選んだ際に合計がkになる場合の数
	cin >> n >> a;
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i];
	}
	vector<vector<vector<ll> > > dp;
	dp = vector<vector<vector<ll > > >(n+1, vector<vector<ll > >(n+1, vector<ll >(n*a+10, 0)));  
	dp[0][0][0] = 1;
	for (int i = 0; i <= n; ++i)
	{
		for (int j = 0; j <= i ; ++j)
		{
			for (int k = 0; k <= n*a ; ++k)
			{
				if (i-1>=0 && j-1 >= 0 && k-x[i-1]>= 0)
				{
					dp[i][j][k] += dp[i-1][j-1][k-x[i-1]];
				}
				if(i-1 >= 0){
					dp[i][j][k] += dp[i-1][j][k];
				}
				// cout << i << " " << j << " " << k << " " << dp[i][j][k] << endl; 
			}
		}
	}

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


Measured memory_bytes: 52352
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <limits>
#include <set>
#define MAX 100000
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;
typedef long long int lli;

int main(void)
{
	int N, M, X; cin >> N >> M >> X;
	vector<int> A(M);
	rep(i, 0, M)cin >> A[i];
	int j = 0;
	while (A[j] <= X)j++;
	int ans = min(j, M - j);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 main(){
	int n,m;
	while(1){
	cin>>n>>m;
	if(n==0)return 0;
	double e=double(m);
	double ans=100000.0;
	for(int i=0;i<=n;i++){
		int x=double(i),y=double(n-i); 
		chmin(ans,fabs(sqrt(x*x+y*y)-e));
	}
     cout<<ans<<endl;
	}
}



Measured memory_bytes: 3256
H, W, K = gets.split.map(&:to_i)
C = H.times.map { gets.chomp }

ans = 0

(1 << H).times do |y_mask|
  (1 << W).times do |x_mask|
    cnt = 0

    H.times do |y|
      next if y_mask[y] == 1

      W.times do |x|
        next if x_mask[x] == 1
        next if C[y][x] == '.'

        cnt += 1
      end
    end

    ans += 1 if cnt == K
  end
end

puts ans


Measured memory_bytes: 14264
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
signed main(){
  int a;
  cin>>a;
  vector<double> b(a);
  fo(i,a)
    cin>>b[i];
  double c=0,d=1;
  fo(i,a)
    c+=d/b[i];
  double e=d/c;
  cout<<setprecision(13)<<e<<endl;
}

Measured memory_bytes: 256
#include <numeric>
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define ll long long
#define inf  1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
using P = pair<double, int>;
struct Edge {
    int to;
    double cost;
};

int V = 100;
constexpr int MAX_V = 1001000;
constexpr double INF = 1e17;
vector<Edge> G[MAX_V];
double d[MAX_V];

void dijkstra(long long k){
    priority_queue<P,vector<P>,greater<P>>que;
    fill(d,d+V,INF);
    d[k]=0;
    que.push(P(0,k));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size(); i++){
            Edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}
double dis(double x1, double y1, double x2, double y2){
    const double dx = x1 - x2;
    const double dy = y1 - y2;
    return sqrt(dx * dx + dy * dy);
}

signed main(){
    double xs, ys;
    cin >> xs >> ys;
    
    double xt, yt;
    cin >> xt >> yt;
    
    int N;
    cin >> N;
    V = N + 2;
    
    vector<double> x(N), y(N), r(N);
    for(int i = 0; i < N; ++i){
        cin >> x[i] >> y[i] >> r[i];
    }
    
    for(int i = 0; i < N; ++i){
        const double d1 = dis(xs, ys, x[i], y[i]) - r[i];
        G[0].push_back(Edge{i+1, max<double>(0, d1)});
        const double d2 = dis(xt, yt, x[i], y[i]) - r[i];
        G[N+1].push_back(Edge{i+1, max<double>(0, d2)});
    }
    
    const double dst = dis(xs, ys, xt, yt);
    G[0].push_back(Edge{N+1, max<double>(0, dst)});
    G[N+1].push_back(Edge{0, max<double>(0, dst)});
    
    for(int i = 0; i < N; ++i){
        const double d1 = dis(xs, ys, x[i], y[i]) - r[i];
        G[i+1].push_back(Edge{0, max<double>(0, d1)});
        const double d2 = dis(xt, yt, x[i], y[i]) - r[i];
        G[i+1].push_back(Edge{N+1, max<double>(0, d2)});
        for(int j = 0; j < N; ++j){
            if(i == j) continue;
            const double d0 = dis(x[i], y[i], x[j], y[j]) - r[i] - r[j];
            G[i+1].push_back(Edge{j+1, max<double>(0, d0)});
        }
    }
    
    dijkstra(0);
    cout<<setprecision(10)<<d[N+1]<<endl;
    return 0;
}

Measured memory_bytes: 47472
s=input()
n=len(s)
dp=0,1
for i in range(n):
  si=int(s[i])
  a=min(dp[0]+si,dp[1]+10-si)
  b=min(dp[0]+si+1,dp[1]+10-(si+1))
  dp=a,b
print(dp[0])

Measured memory_bytes: 75868
import java.util.*;
public class Main{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] a=new int[n*2];
    for(int i=0;i<n*2;i++)
    {
        a[i]=sc.nextInt();
    }
    int ans=0;
    for(int j=0;j<=(n*2)-6;j++)
    {
      if(a[j]==a[j+1])
      {
         if(a[j+2]==a[j+3])
         {
           if(a[j+4]==a[j+5])
           {
               ans=1;
           }
         }
      }
    }
    if(ans==1)
      	System.out.println("Yes");
    else
      System.out.println("No");
      
  }
}

Measured memory_bytes: 36012
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }


using namespace std;
const int N = 100000+10;
char s[N];
int n;
int main(){
    scanf("%s", s+1);
    n = strlen(s+1);
    int ans = n;
    for (int i = 1; i < n; i++) {
        if (s[i] != s[i+1]) {
            ans = min(ans, max(i, n-i));
        }
    }

    cout << ans << endl;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int main() {
  int n; cin >> n;
  int ptr, res;
  int a[100000];
  for(int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a+n);
  while(ptr < n) {
    int cc = a[ptr], f = 0;
    while(ptr<n && a[ptr] == cc) f++, ptr++;
    res += f % 2;
  }
  printf("%d\n", res);

  return 0;
}

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

int main(){
    double x1, y1, x2, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    printf("%lf\n", sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)));
}


Measured memory_bytes: 2060
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m = map(int,input().split())
bridges = []
ans = 0
for i in range(m):
    a,b = map(int,input().split())
    bridges.append((a-1,b-1))
for i in range(m):
    uf = UnionFind(n)
    for j in range(m):
        if j != i:
            a,b = bridges[j]
            uf.union(a,b)
    if uf.group_count() != 1:
        ans += 1
print(ans)

Measured memory_bytes: 40944
#include <iostream>

using namespace std;
using ll = long long;

int main()
{
    string S;
    int w;

    cin >> S;
    cin >> w;

    string r = "";
    for (int i = 0; i < S.length(); i+=w) {
        r += S[i];
    }

    cout << r << endl;



    return 0;
}

Measured memory_bytes: 256