akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n , a[N] , dp[N] , k;
int calc(int i){
    if(i == n - 1)
        return 0;
    if(i >= n)
        return 1e9 + 10;
    int &ret = dp[i];
    if(ret != -1)return ret;
    ret = 1e9 + 10;
    for(int j = 1 ; j <= k ; j++)
        ret = min( calc(i + j) + abs(a[i] - a[i + j]) , ret ); 
    return ret;
}
int main(){
    scanf("%d%d", &n , &k);
    for(int i = 0 ; i < n ; i++){
        scanf("%d", &a[i]);
    }
    memset(dp , -1 , sizeof dp);
    cout<<calc(0);
    return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define maxn 100005
#define endl '\n'
using namespace std;
int arr[maxn],brr[maxn],pre[maxn];
struct sqrtd {
	int next,cnt;
}table[maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
		cin >> arr[i];
	for(int i=1;i<n;i++)
		brr[i] = arr[i+1] - arr[i] , pre[i] = brr[i] + pre[i-1];
	n--;
	
	int L;
	cin >> L;
	
	int box = sqrt(n);
	for(int i=1;i<=n;i++) {
		int tem_cnt = 0 , bound = min((i/box+1)*box,n);
		int j , sum = 0;
		for(j=i;j<=bound;) {
			sum = 0;
			do {
				sum += brr[j++];
			} while(j <= bound && sum + brr[j] <= L);
			tem_cnt++;
		}
		if(j > bound && j <= n && sum + brr[j] <= L) {
			int l = j , r = n , m;
			while(true) {
				if(r-l<3) {
					for(m=l;m<=r && pre[m]-pre[j-1]+sum <= L;m++);
					break;
				}
				m = (l+r)>>1;
				if(pre[m]-pre[j-1]+sum <= L)
					l = m;
				else
					r = m-1;
			}
			j = m;
		}
		table[i] = {j,tem_cnt};
	}
	
	int q;
	cin >> q;
	while(q--) {
		int l,r;
		cin >> l >> r;
		if(l > r)	swap(l,r);
		r--;
		int ans = 0;
		while(l <= r && l/box != r/box) {
			ans += table[l].cnt;
			l = table[l].next;
		}
		if(l <= r && l/box == r/box) {
			while(l <= r) {
				int sum = 0;
				do {
					sum += brr[l++];
				} while(l <= r && sum + brr[l] <= L);
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

int main(){
    int n, minj,cnt;
    int a[100];
    cin >> n;
    cnt = 0;
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<n; i++){
        minj = i;
        for(int j=i; j<n; j++){
            if(a[j] < a[minj]) minj = j;
        };
        if(a[i] != a[minj]){
            swap(a[i],a[minj]);
            cnt += 1;
        };
    };
    for(int i=0; i<n-1; i++){
        cout << a[i] << " ";
    };
    cout << a[n-1] << endl << cnt << endl;
    return 0;
}


Measured memory_bytes: 3116
import java.util.*;
public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int p = sc.nextInt();
      int[] a = new int[n];
      int cnt = 0;
      for(int i = 0;i < n;i++){
        a[i] = sc.nextInt()%2;
        if(a[i]==1) cnt++;
      }
      if(cnt==0){
        if(p==1)System.out.println(0);
        else System.out.println((long)Math.pow(2,n));
      }
      else System.out.println((long)Math.pow(2,n-1));
    }
}


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

int main(){
  string w;
  cin>>w;
  
  int count[26]={0};
  for(int i=0;i<w.size();i++){
    count[w[i]-'a']++;
  }
  
  bool flag=true;
  for(int i=0;i<26;i++){
    if(count[i]%2!=0)flag=false;
  }
  
  if(flag)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

#define INF 1000000000

using namespace std;

class UnionFind {
public:
    UnionFind(int n) : parent_(n), rank_(n) {
        for (int i = 0; i < n; ++i) {
            parent_[i] = i;
            rank_[i] = 0;
        }
    }

    int find(int x) {
        if (parent_[x] == x)
            return x;
        else
            return parent_[x] = find(parent_[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);

        if (x == y) return;

        if (rank_[x] < rank_[y]) {
            parent_[x] = y;
        } else {
            parent_[y] = x;
            if (rank_[x] == rank_[y]) rank_[x]++;
        }
    }

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

    vector<int> parent_, rank_;
};

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

    vector<int> p(N);
    REP(i, N)
    cin >> p[i];

    UnionFind uf(N);
    REP(i, M) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        uf.unite(x, y);
    }

    unordered_map<int, unordered_set<int>> sets;

    REP(i, N) { sets[uf.find(i)].insert(i); }

    int ok = 0;
    REP(i, N)
    ok += sets[uf.find(i)].find(p[i] - 1) != sets[uf.find(i)].end();

    cout << ok << endl;

    return 0;
}


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

int main()
{
	bool is_prime[1000000];
	
	is_prime[0]=is_prime[1]=false;
	
	for(int i=2;i<1000000;i++){
		is_prime[i]=true;
	}
	
	for(int i=2;i*i<1000000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<1000000;j+=i){
				is_prime[j]=false;
			}
		}
	}
	
	int n_prime[1000000];
	
	int cnt=0;
	for(int i=0;i<1000000;i++){
		if(is_prime[i]){
			cnt++;
		}
		
		n_prime[i]=cnt;
	}
	
	while(true){
		int n;
		cin>>n;
		if(cin.eof())
			break;
		
		cout<<n_prime[n]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 7980
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;

int main() {
  int n, q, t;
  string name;
  // 標準ライブラリから queue を使用
  queue<pair<string, int> > Q;  // プロセスのキュー

  cin >> n >> q;

  // 全てのプロセスをキューに順番に追加する
  for ( int i = 0; i < n; i++ ) {
    cin >> name >> t;
    Q.push(make_pair(name, t));
  }

  pair<string, int> u;
  int elaps = 0, a;

  // シミュレーション
  while ( !Q.empty() ) {
    u = Q.front(); Q.pop();
    a = min(u.second, q);  // q または必要な時間 u.second だけ処理を行う
    u.second -= a;  // 残りの必要時間を計算
    elaps += a;  // 経過時間を加算
    if ( u.second > 0 )
      Q.push(u);  // 処理が完了していなければキューに追加
    else
      cout << u.first << " " << elaps << endl;
  }

  return 0;
}


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

using ll = long long;

int main() {
    string s;
    cin >> s;
    rep(i, s.size() - 1) {
        if (s[i] == s[i + 1]) {
            cout << i + 1 << " " << i + 2 << "\n";
            return 0;
        }
        if (i < s.size() - 1 && s[i] == s[i + 2]) {
            cout << i + 1 << " " << i + 3 << "\n";
            return 0;
        }
    }
    cout << "-1 -1\n";
}

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

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int ret=0;
	int a,b,c; cin>>a>>b>>c;
	set<iii> st; st.insert({a,{b,c}});
	while(a%2==0&&b%2==0&&c%2==0) {
		int d=(b+c)/2, e=(c+a)/2, f=(a+b)/2;
		iii cur={d,{e,f}};
		if(st.find(cur)!=st.end()) {
			cout << -1 << endl;
			return 0;
		}
		st.insert(cur);
		ret++;
		a=d, b=e, c=f;
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
int INF = INT_MAX / 2;
double EPS = 1e-10;

int f(vector<int> a) {
	int n = a.size(), ans = 0;
	for (;;) {
		int i;
		for (i = 0; i < n; i++)
			if (a[i]) {
				int j;
				for (j = i; j < n && a[j]; j++)
					a[j]--;
				ans += min(3, j - i);
				break;
			}
		if (i == n) break;
	}
	return ans;
}

int main() {
	string S; cin >> S;
	vector<int> alpha(26), num(10);
	for (int i = 0; i < S.length(); i++) {
		char c = S[i];
		if ('a'<=c && c<='z') alpha[c - 'a']++;
		if ('0'<=c && c<='9') num[c - '0']++;
	}
	cout << f(alpha) + f(num) << endl;
}

Measured memory_bytes: 1200
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

const int MAX_N = 65;
const long long MAX_VAL = (long long)10000000000000000 + 1000;

long long a[MAX_N];
long long mod[MAX_N];
int N;
long long last[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;
    for (int i = 1; i <= N; i++) {
        std::cin >> a[i];
    }

    long long sum = 0;
    bool is0 = true;
    for (int i = 1; i <= N; i++) {
        mod[i] = a[i] % (N + 1);
        sum += a[i];
        if (N - 1 < a[i]) {
            is0 = false;
        }
    }

    if (is0) {
        std::cout << 0 << std::endl;
        return 0;
    }

    long long ret = MAX_VAL * MAX_N;
    for (int i = 1; i <= N; i++) {
        long long sum_tmp = 0;
        for (int j = 1; j <= N; j++) {
            last[j] = N - 1 + mod[j] - mod[i];
            while (N - 1 < last[j]) {
                last[j] -= (N + 1);
            }
            sum_tmp += last[j];
        }
        if (sum_tmp < sum) {
            ret = std::min(ret, std::max(sum - sum_tmp, (long long)0));
        }
        //std::cout << i << " " << sum_tmp << std::endl;
        //ret = std::min(ret, std::max(sum - sum_tmp, (long long)0));
    }

    std::cout << ret << std::endl;
    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
long long x,y;
long long pow2(int k){
    long long ret = 1;
    while(k--) ret *= 2;
    return ret;
}
int main(void){
    scanf("%lld %lld",&x,&y);
    
    int l;
    for(l = 1; x*pow2(l) <= y; l++);
    
    printf("%d",l);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1e9+7
using namespace std;
typedef long long ll;
const double pi=acos(-1);

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(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans=max({a*c,b*d,b*c,a*d});
    cout << ans << endl;
}

Measured memory_bytes: 3624
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	a := nextInts(n)

	ans := 0
	for i := 0; i < n; i++ {
		// 同じ数字のカードでペアを作る
		ans += a[i] / 2
		// カードが残っていて，次の数字があればそれとペアを組ませる
		if a[i]%2 == 1 && i+1 < n && a[i+1] > 0 {
			ans++
			a[i+1]--
		}
	}

	puts(ans)
}


Measured memory_bytes: 3200
export class Main {
  static main(input): string {
    const [n, l]: number[] = input.split("\n")[0].split(" ").map(a => parseInt(a));
    if (l < 0 && 0 <= n + l - 1) {
      let result = 0;
      for (let i = 1; i <= n; ++i) {
        result += i + l - 1;
      }
      return `${result}`;
    } else if (l < 0) {
      let result = 0;
      for (let i = 1; i < n; ++i) {
        result += i + l - 1;
      }
      return `${result}`;
    } else {
      let result = 0;
      for (let i = 2; i <= n; ++i) {
        result += i + l - 1;
      }
      return `${result}`;
    }
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

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

typedef unsigned uint;
typedef long long INT;
typedef unsigned long long UINT;
const int INF = 1001001001;
const INT INFLL = 1001001001001001001LL;

 int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
INT lin() { INT x; scanf("%lld", &x); return x; }

int main(){
    int a, b, c;
    double fa, fb, fc;
    char S[128], sa[128], sb[128], sc[128];
    // int N = in();
    // int K = in();
    // scanf("%s", S);

    int N = in();
    int M = in();

    int nRem = N;
    for (int i = 0; i < M; ++i) {
        nRem -= in();
    }

    printf("%d", nRem >= 0 ? nRem : -1);



    return 0;
}







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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;

ll a, b, c;

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

	cin >> a >> b >> c;

	cout << max(c - (a - b), 0LL) << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pa pair<int,int>
#define ld long double
#define BOOST ios_base::sync_with_stdio(false)
#define pb push_back
#define st first
#define nd second
using namespace std;
const ll inf =1e18+9;
const int MAX=1e5+5;
pair<ll,ll>tab[MAX];
ll dp[MAX];
int main()
{

    int n,w;
    scanf("%d%d",&n,&w);
    for (int i=1;i<=100000;i++)
    {
        dp[i]=inf;
    }
    dp[0]=0;
    for (int i=1;i<=n;i++)
    {
        ll a,b;
        scanf("%lld%lld",&a,&b);
        tab[i].st=a;
        tab[i].nd=b;
    }

     for (int i=1;i<=n;i++)
     {
         for (int j=100001;j>=0;j--)
         {
             if (dp[j]!=inf && j+tab[i].second<=100000)
             {
                 dp[j+tab[i].second]=min(dp[j+tab[i].second],dp[j]+tab[i].first);
             }
         }
     }
     int l=0;
     for (int i=1;i<=100000;i++)
     {
         if (dp[i]<=w)
         {
             l=i;
         }
     }
     printf("%d",l);


    return 0;
}


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

typedef long long ll;
typedef pair<int,int> ii;

int eval(string &s) {
	stringstream ss(s);
	int ret; ss>>ret; return ret;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	int ret=1000;
	for (int i=0; i<s.size()-2; i++) {
		string cur=s.substr(i,3);
		ret=min(ret,abs(eval(cur)-753));
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){r(1)(r(2).readFileSync("/dev/stdin","UTF-8"))},function(e,t){e.exports=function(e){for(var t=e.split("\n"),r=Number(t[0]),n=t[1].split(" "),o=0,u=0;u<r;u++){o+=1/n[u]}console.log(1/o)}},function(e,t){e.exports=require("fs")}]);

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

int main() {
  int N,i,AC,WA,TLE,RE;
  string S;
  cin>>N;
  AC=WA=TLE=RE=0;
  for(i=0;i<N;i++) {
    cin>>S;
    if (S=="AC")AC++;
    else if(S=="WA")WA++;
    else if(S=="TLE")TLE++;
    else RE++;
  }
  cout<<"AC x "<<AC<<endl;
  cout<<"WA x "<<WA<<endl;
  cout<<"TLE x "<<TLE<<endl;
  cout<<"RE x "<<RE<<endl;
  return 0;
}


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

public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int a = fs.nextInt();
        int b = fs.nextInt();
        int x = fs.nextInt();

        if(x > a*a*b/2) {
            System.out.println(Math.toDegrees(Math.atan((double)2*(a*a*b-x)/(a*a*a))));
        }else {
            System.out.println(Math.toDegrees(Math.atan((double)a*b*b/(2*x))));
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
 
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
 
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
 
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
 
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }
 
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
 
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
 
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
pair<int, int>p[111111];
int main() {
	int n;
	cin >> n;
	rep(i, n)cin >> p[i].first >> p[i].second;
	sort(p, p + n);
	rep(i, n)cout << p[i].first << " " << p[i].second << endl;
	return 0;
}


Measured memory_bytes: 3860
N = int(input())
w_list = [input() for _ in range(N)]

end = None
for w in w_list:
  if end == None:
    end = w[-1]
    continue
  if w_list.count(w) > 1:
    print('No')
    break
  if w[0] != end:
    print('No')
    break
  end = w[-1]
else:
  print('Yes')

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{
  int a[100],i,n,ans;
  cin>>n;
  for(i=0;i<n;i++){cin>>a[i];}
  sort(a,a+n);
  ans=a[n-1]-a[0];
  cout<<ans<<endl;
  return 0;
  
  
}

Measured memory_bytes: 3604
public class Main {

    public static void main(String[] args) {
     try{
         java.util.Scanner s1 = new java.util.Scanner(System.in);
         int n=s1.nextInt();
         int m=s1.nextInt();
         int k=s1.nextInt();
         for(int i=0;i<=n;i++)
         {
             for(int j=0;j<=m;j++)
             {
                 if((i*m+j*n-2*i*j)==k)
                 {
                     System.out.println("Yes");
                     return;
                 }
             }
         }
         System.out.println("No");
     }
     catch(Exception e)
     {}
   }
}


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

int main(){
    int N, K, i, j, x, cnt;
    double ans=0, a[100000];

    scanf("%d %d", &N, &K);

    for(i=1; i<=N; i++){
        cnt=0;
        x=i;
        while(x < K){
            x = x*2;
            cnt++;
        }

        a[i-1] = ((double)1 / (double)N) * pow(0.5, (double)cnt);
    }
    
    for(i=0; i<N; i++){
        ans += a[i];
    }

    printf("%.9lf\n", ans);

    return 0;
}

Measured memory_bytes: 896
N,K=map(int,input().split())
p = sorted([[int(_) for _ in input().split()] for i in range(N)])
a=10**20
for xi in range(N-K+1):
  for xj in range(xi+K-1,N):
    q = sorted(y for x,y in p[xi:xj+1])
    for yi in range(xj-(xi+K-1)+1):
      yj = yi+K-1 #Is the number always K?
      if q[yi]<=p[xi][1] and p[xj][1]<=q[yj]:
        a = min(a, (p[xi][0]-p[xj][0])*(q[yi]-q[yj]))
print(a)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    int n; cin >> n;
    long double sum = 0;
    rep(i, n){
        long double x; cin >> x;
        string u; cin >> u;
        if(u == "JPY") sum += x;
        else sum += x * 380000.0;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) = agc043b()

fun agc043b() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.map { Character.getNumericValue(it) - 1 }.toIntArray()

    val reduceIndexed = aList
        .reduceIndexed { index, acc, a -> if ((n - 1) and index == index) acc xor a else acc }
    val isAnswerEven = reduceIndexed % 2 == 0

    if (!isAnswerEven) return println(1)

    if (aList.contains(1)) return println(0)

    val answer = if (reduceIndexed % 4 == 0) 0 else 2

    println(answer)
}


Measured memory_bytes: 50204
#include<iostream>
#include<cmath>
#include<cstring>

using namespace std;

int main()
{
	char ary[101][101];
	int row,col, i,j;
	cin>>row>>col;
	for(i=0;i<row;i++)cin>>ary[i];
	for(i=0;i<row;i++)
	{
		cout<<ary[i]<<endl;
		cout<<ary[i]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>

#define INF 1e17+9;
#define rep(i,n) for(int i=0;i<n;i++)

const long long MOD = 1e9+7;
const double PI=acos(-1);

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> A(n+1,0);
	
	A[0]=0;
	for(int i=1;i<=n;i++){
		cin >> A[i];
	}
	A.push_back(0);
	
	long long dist=0;
	for(int i=1;i<A.size();i++){
		dist+=abs(A[i]-A[i-1]);
	}
	
	for(int i=1;i<A.size()-1;i++){
		long long temp=dist;
		temp-=abs(A[i]-A[i-1]);
		temp-=abs(A[i+1]-A[i]);
		temp+=abs(A[i+1]-A[i-1]);
		cout << temp << endl;
	}
	
	return 0;
}



Measured memory_bytes: 1656
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
const int64 INF = 1LL << 60;
inline int64 ABS(int64 A, int64 B){ return(max(A - B, B - A)); }

int n;
int idx[15], dist[15], cost[15];

int64 weight[1 << 15];
int64 dp[15][1 << 15];
pair< int, int > previdx[15][1 << 15];

int main()
{
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> idx[i] >> dist[i] >> cost[i];
  }
  for(int i = 1; i < 1 << n; i++) {
    for(int j = 0; j < n; j++) {
      if((i >> j) & 1) weight[i] += cost[j];
    }
    weight[i] *= 20;
  }
  fill_n( *previdx, 15 * (1 << 15), make_pair(-1, -1));
  fill_n( *dp, 15 * (1 << 15), INF);
  for(int i = 0; i < n; i++) {
    dp[i][1 << i] = 0;
  }
  for(int i = 1; i < 1 << n; i++) {
    for(int j = 0; j < n; j++) {
      if(!((i >> j) & 1)) continue;
      if(dp[j][i] == INF) continue;
      for(int k = 0; k < n; k++) {
        if((i >> k) & 1) continue;
        int64 Cost = dp[j][i] + ABS(dist[j], dist[k]) * (70LL + weight[i]);
        if(dp[k][i|(1 << k)] >= Cost) {
          dp[k][i|(1 << k)] = Cost;
          previdx[k][i|(1 << k)] = make_pair(j, i);
        }
      }
    }
  }

  pair< int64, int > ret = make_pair(INF, -1);
  int mask = (1 << n) - 1;
  for(int i = 0; i < n; i++) {
    ret = min(ret, make_pair(dp[i][(1 << n) - 1], i));
  }
  stack< int > Que;
  while(ret.second >= 0) {
    Que.push(idx[ret.second]);
    pair< int, int > p =  previdx[ret.second][mask];
    ret.second = p.first;
    mask = p.second;
  }
  bool first = false;
  while(!Que.empty()) {
    if(first++) cout << " ";
    cout << Que.top();
    Que.pop();
  }
  cout << endl;

}

Measured memory_bytes: 9136
#include <stdio.h>

int yukuri(int,int);

int main(){
  int a,b,kouyaku;
  scanf("%d%d",&a,&b);
  kouyaku=yukuri(a,b);
  printf("%d\n",kouyaku);
  return 0;
}

int yukuri(int a,int b){
  int kouyaku;
  while(0!=b){
    kouyaku=a%b;
    a=b;
    b=kouyaku;
  }
  return a;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
int main() {
 	int n;
  	cin >> n;
  	for (int c = 1; ; c++) {
    	if (c * (c + 1) / 2 >= n) {
         	int bad = (c * (c + 1)) / 2 - n;
          	assert(0 <= bad && bad <= c);
          	for (int p = 1; p <= c; p++) {
              if (p == bad) continue;
              cout << p << '\n';
            }
          	return 0;
          
        }
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define f first
#define se second
#define pb push_back
#define pf push_front
#define eb emplace_back
#define emp emplace
#define ins insert
#define sz(s) (int)s.size()
#define rep(i,a,b) for( int i=a;i<b;i++)
#define repr(i,a,b) for( int i=a;i>=b;i--)
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(n,m) memset(n,m,sizeof(n))
#define ii pair<int,int>
#define iii tuple<int, int, int>
#define si set<int>
#define vi vector<int>
#define vii vector<ii>
#define mi map<int,int>
#define lb lower_bound
#define ub upper_bound
#define present(s,x) (s.find(x) != s.end())
#define ford(container, it) for(auto it:container)
#define fors(container, it, a, b) for(auto it = a; it != b; it++)
#define Raag4924 ios_base::sync_with_stdio(0);
#define fastio cin.tie(0);cout.tie(0);
#define mod 987654319
#define EPSILON 1e-9
#define PI acos(-1)
#define inf 1e17
#define int long long
#define debug(a) cerr<<#a<<": ";for(auto i:a)cerr<<i<<" ";cerr<<'\n';
#define trace(a) cerr<<#a<<": "<<a<<"\n"
#define gcd(a,b) __gcd(a,b)
using namespace std;
int add(int a, int b, int c){int res=a+b;return(res>=c?res-c:res);}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
int mul(int a, int b, int c){int res=(int)a*b;return(res>=c?res%c:res);}
template<typename T>T power(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template<typename T>T mdpower(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
/*------------------------------------------------------------------------------------------------------------------*/

int32_t main()
{
    Raag4924
    fastio
 
  
  
    int n,k;
    cin>>n>>k;

    int arr[n+1];
    for(int i=1;i<=n;i++)
    cin>>arr[i];

    int dp[n+1];
    dp[1] =0;
    
    for(int i=2;i<=n;i++)
    {
        dp[i] = INT_MAX;
      for(int j = i-1,count=0;j>=1 and count<k;j--,count++)
      {
            dp[i] = min(dp[i],abs(arr[i]-arr[j])+dp[j]);
      }
      
    }

    cout<<dp[n]<<"\n";


 
 






 
#ifndef LOCAL_DEFINE
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}


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

int a[10001];

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

	int cnt = 0;
	for(int i = 0; i < n; i++){
		while(a[i] % 2 == 0){
			if(a[i] % 2 == 0){
				cnt++;
				a[i] = a[i] / 2;
			}
		}
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,x;
	cin>>a>>b>>c>>x;
	int st=0;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				if(500*i+100*j+50*k==x){
					st++;
				}
			}
		}
	}
	cout<<st<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
      	int y = sc.nextInt();
      	int num = 0;
      	for(int cnt = x * 2;cnt >= 0;cnt -= 2){
        	if(cnt + num == y){
            	System.out.println("Yes");
              	System.exit(0);
            }
          	num += 4;
        }
      	System.out.println("No");
	}
}

Measured memory_bytes: 35896
import numpy as np
from collections import Counter
import collections
round = lambda x:(x*2+1)//2
a = list(map(float,input().split()))
a = np.array(a)
b = a[0]+a[1]
c = a[2] + a[3]
if b > c:
  print('Left')
elif b < c :
  print('Right')
else :
  print('Balanced')

Measured memory_bytes: 19744
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var A = F;
		Console.WriteLine(N % 500 <= A ? "Yes" : "No");
	}
}


Measured memory_bytes: 11092
N, K, S = map(int, input().split())
if K == 0: A = [735477] * N; print(*A); exit(0)
if N == K: A = [S] * K; print(*A); exit(0)
if N == 1: print(S); exit(0)
if N == 2:
    if (S % 2 == 0): print(int(S / 2), int(S / 2)); exit(0)
    if (S % 2 == 1): print(int(S / 2), int(S / 2 + 1)); exit(0)
if S == 1:
    A = [1] * K
    for i in range(N - len(A)): A.append(735477)
    print(*A)
    exit(0)
if S % 2 == 0:
    A = [int(S / 2)] * (K + 1)
    for i in range(N - len(A)): A.append(735477)
    print(*A)
else:
    if(K % 2 == 0):
        A = [int(S / 2), int(S / 2) + 1] * int(K / 2)
        A.append(int(S / 2))
        for i in range(N - len(A)): A.append(735477)
        print(*A)
    else:
        A = [int(S / 2), int(S / 2) + 1] * int(K / 2 + 1)
        for i in range(N - len(A)): A.append(735477)
        print(*A)


Measured memory_bytes: 6644
#                         author:  kagemeka 
#                         created: 2019-11-08 14:51:29(JST)
## internal modules
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## external modules
# import scipy.special   # if use comb function on AtCoder, 
# import scipy.misc      # select scipy.misc.comb (old version) 

def main():
    n, *a = (int(x) for x in sys.stdin.read().split())
    
    for i in range(n):
        a[i] -= (i + 1)

    a.sort()
    if n % 2 != 0:
        b = a[n // 2]
    else:
        if a.count(a[n // 2]) >= a.count(a[n // 2 - 1]):
            b = a[n // 2]
        else:
            b = a[n // 2 - 1]
    
    ans = sum([abs(a[i] - b) for i in range(n)])
    print(ans)


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 25180
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  int N, M;
  cin >> N >> M;
  cout << pow(2, M) * ((N - M)*100 + (1900 * M)) << endl;
  return 0;
}


Measured memory_bytes: 4208
#include<iostream>
#include<map>

using namespace std;

int main(){

  char from, tra, to;

  map <char, int> M;

  M['A'] = 1;
  M['B'] = 0;
  M['C'] = 0;

  while(cin >> from >> tra >> to){
    int temp = M[from];
    M[from] = M[to];
    M[to] = temp;
  }

  for(char i = 'A'; i <= 'C'; i++){
    if(M[i] == 1){
      cout << i << endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7

def main():
    S = cin.string()
    ans = 0
    N = len(S) - 1
    for i in range(1 << N):
        t = ["."] * N
        for j in range(N):
            if i >> j & 1:
                t[j] = "+"
        tmp = int(S[0])
        for j in range(N):
            if t[j] == "+":
                ans += tmp
                tmp = int(S[j + 1])
            else:
                tmp *= 10
                tmp += int(S[j + 1])
        ans += tmp
    print(ans)
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 41968
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

int N; 
string S, T;
cin >> N >> S >> T;

rep(i, 0, N) cout << S[i] << T[i];

cout << endl;

}

// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



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

signed main(){
    int N,M;cin>>N>>M;
    vector<int>A(N,0);
    REP(i,2*M){
        int a;cin>>a;
        A[a-1]++;
    }
    REP(i,N){
        cout<<A[i]<<endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include<string>
using namespace std;
int main()
{
	string S;
	cin >> S;
	if (S.size() == 2) {
		cout << S;
	}
	else {
		reverse(S.begin(), S.end());
		cout << S<<endl;
	}
	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

bitset<20000> dp[2];
const int X = 10000;
const int Y = 10000;
int32_t main(){
	IOS
	string s;
	int x, y;
	cin >> s >> x >> y;
	x += X, y += Y;
	dp[0].set(X);
	dp[1].set(Y);
	int update = 0, n = s.length(), idx = 0, c = 0;
	for(int i = 0; i < n ; i++ ){
		if( s[i] == 'F' ) ++c;
		else{
			if( !update ){
				dp[idx] = dp[idx] << c;
				update = 1;
			}else{
				dp[idx] = ( dp[idx] << c ) | ( dp[idx] >> c );
			}
			c = 0;
			idx ^= 1;
		}
	}
	if( c > 0 ){
		if( !update ) dp[idx] = dp[idx] << c;
		else dp[idx] = ( dp[idx] << c ) | ( dp[idx] >> c );
	}
	cout << ( dp[0][x] && dp[1][y] ? "Yes" : "No" ) << endl;
	
 }
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 3676
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True

def bfs(graph, initial):
    n = len(graph) - 1
    dist = [-1] * (n + 1)
    q = deque([initial])
    visited = [False] * (n + 1)
    visited[initial] = True

    while len(q) != 0:
        edge = q.popleft()
        nxt = graph[edge]

        for i, e in enumerate(nxt):
            if visited[e] is False:
                q.append(e)
                dist[e] = edge
                visited[e] = True

    return dist


def main():
    N, M = MI()
    graph = [[] for i in range(N+1)]

    for i in range(M):
        x, y = MI()
        graph[x].append(y)
        graph[y].append(x)

    ret = bfs(graph, 1)

    for i in range(2, len(ret)):
        if ret[i] == -1:
            print('No')
            return

    print('Yes')
    for i in range(2, len(ret)):
        print(ret[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 93500
//https://atcoder.jp/contests/abc155/tasks/abc155_b
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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 (b<a) { a=b; return 1; } return 0;}
int main() {
    ll N; cin>>N;
    vector<ll> an(N);
    for(auto&& a:an){
        cin>>a;
    }    
    bool ans=true;
    for(const auto& a:an){
        if(a%2==0){
            if(a%3==0 || a%5==0){

            }else{
                ans=false;
            }
        }
    }
    cout<<(ans?"APPROVED":"DENIED")<<endl;
    return 0;
}

Measured memory_bytes: 384
S = input()
d = {}

#それぞれの文字の数を数える
for s in S:
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

#dの長さが2出ないとき(文字の種類が2種類じゃないとき)
if len(d) != 2:
    print("No")
    exit()

#それぞれの文字の数が2かどうか
for s in S :
    if d[s] != 2:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

    if(A%3 && B%3 && (A+B)%3) cout << "Impossible" << endl;
    else cout << "Possible" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    n -= k;
    --k;
    cout << 1+(n+k-1)/k << endl;
    return 0;
}

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

int main()
{
    long long n,m;
    cin>>n>>m;
    if(n*2>=m)
    {
        long long sum=m/2;
         sum=min(sum,n);
        cout<<sum<<endl;
    }
    else if(n*2<m)
    {
        long long sum=n;
        m-=(n*2);
        sum+=(m/4);
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-20;
const long INF = 1e10;

char mp[52][52];
bool flag[52][52];
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

int main(){
	int w,h;
	while(cin>>w>>h){
		if(w==0&&h==0)break;
		REP(i,52)REP(j,52)mp[i][j]='#';
		REP(i,h)REP(j,w)cin>>mp[i+1][j+1];
		CLR(flag);
		int bsum=0,wsum=0;
		REP(i,h)REP(j,w){
			if(flag[i+1][j+1]||mp[i+1][j+1]!='.')continue;
			queue<PII>q;
			q.push(MP(i+1,j+1));
			bool b=false,w=false;
			int cnt=1;
			flag[i+1][j+1]=true;
			while(!q.empty()){
				PII npos=q.front();q.pop();
				int x=npos.first,y=npos.second;
				REP(k,4){
					if(mp[x+dx[k]][y+dy[k]]=='W')w=true;
					else if(mp[x+dx[k]][y+dy[k]]=='B')b=true;
					else if(mp[x+dx[k]][y+dy[k]]=='.'&&!flag[x+dx[k]][y+dy[k]]){
						flag[x+dx[k]][y+dy[k]]=true;cnt++;
						q.push(MP(x+dx[k],y+dy[k]));
					}
				}
			}
			if(b&&!w)bsum+=cnt;
			else if(!b&&w)wsum+=cnt;
		}
		cout<<bsum<<" "<<wsum<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
#define int long  long
#define double long double
int t,n,ac,wa,tle,re;
string s;
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    t=1;
  //  cin>>t;
    while(t--)
    {
        ac=wa=tle=re=0;
        cin>>n;
        for(int i=0;i<n;i++)
        {
            cin>>s;
            if(s=="AC") ac++;
            else if(s=="TLE") tle++;
            else if(s=="WA") wa++;
            else re++;
        }
        cout<<"AC x "<<ac<<endl;
        cout<<"WA x "<<wa<<endl;
        cout<<"TLE x "<<tle<<endl;
        cout<<"RE x "<<re<<endl;
    }
}


Measured memory_bytes: 3660