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

LIMIT = 10 ** 9

class UnionFind():
    def __init__(self, N):
        self.nodes = [i for i in range(N)]
        self.distance = [0 for _ in range(N)]

    def root(self, x):
        if x != self.nodes[x]:
            root, distance = self.root(self.nodes[x])
            if self.nodes[x] != root:
                self.distance[x] += distance
                self.nodes[x] = root
        return self.nodes[x], self.distance[x]

    def same(self, x, y):
        x_root, _ = self.root(x)
        y_root, _ = self.root(y)
        return x_root == y_root

    # unite(L, R, D)
    def unite(self, x, y, distance):
        if self.same(x, y):
            return self.distance[y] - self.distance[x] == distance
        x_root, _ = self.root(x)
        y_root, _ = self.root(y)
        self.distance[y_root] = self.distance[x] + distance - self.distance[y]
        self.nodes[y_root] = x_root
        return True

is_correct = True
uf = UnionFind(N)
for _ in range(M):
    l, r, d = map(int, input().split())
    is_valid = uf.unite(l-1, r-1, d)
    if not is_valid:
        is_correct = False
        break

distance_dict = {}
for group, distance in zip(uf.nodes, uf.distance):
    if group in distance_dict:
        distance_dict[group]["max"] = max(distance_dict[group]["max"], distance)
        distance_dict[group]["min"] = min(distance_dict[group]["min"], distance)
    else:
        distance_dict[group] = {
            "max": distance,
            "min": distance,
        }

for distances in distance_dict.values():
    if distances["max"] - distances["min"] > LIMIT:
        is_correct = False
        break
print("Yes" if is_correct else "No")


Measured memory_bytes: 43652
import collections
n = int(input())
a = []
for i in range(n):
  s = input()
  b = list(s)
  b.sort()
  b = ''.join(b)
  a.append(b)
c = collections.Counter(a)
ans = 0
for e in c:
  ans += c[e] * (c[e] - 1) // 2
print(ans)

Measured memory_bytes: 24060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  


int main(){
  ll n; cin >> n;
  ll sum=0, limit;
  for(int i=1; sum<n; i++){
    sum += i; limit=i;
  }
  
  for(int i=1; i<=limit; i++){
    if(sum-n==i) continue;
    cout << i << endl;
  }
  
}


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

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#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 UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

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

  char c[10][10];
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      c[i][j] = '.';
    }
  }

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> c[i][j];
    }
  }

  if (c[1][1] == '.') {
    cout << "Impossible" << endl;
    return 0;
  }

  for (int bit = 0; bit < bit(H + W - 2); bit++) {
    bool flag = true;
    int h = 1, w = 1;

    char cc[10][10];
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        cc[i][j] = c[i][j];
      }
    }
    cc[1][1] = '.';

    for (int i = 0; i < H + W - 2; i++) {
      if (bitcheck(bit, i)) {
        h++;
        if (c[h][w] == '.') {
          flag = false;
          break;
        }
      } else {
        w++;
        if (c[h][w] == '.') {
          flag = false;
          break;
        }
      }
      cc[h][w] = '.';
    }

    for (int i = 1; i <= H; i++) {
      if (flag == false) break;
      for (int j = 1; j <= W; j++) {
        if (cc[i][j] == '#') {
          flag = false;
          break;
        }
      }
    }

    if (flag) {
      cout << "Possible" << endl;
      return 0;
    }
  }

  cout << "Impossible" << endl;
  return 0;
}


Measured memory_bytes: 256
S = list(input())

A = int(''.join(S[:2]))
B = int(''.join(S[2:]))

def main():
	if (A > 0 and A <= 12) and (B > 0 and B <= 12):
		print("AMBIGUOUS")
		return
	if B > 0 and B <= 12:
		print("YYMM")
		return
	if A > 0 and A <= 12:
		print("MMYY")
		return
	print("NA")
if __name__ == '__main__':
	main()

Measured memory_bytes: 3060
#include <iostream>
#include <math.h>

using namespace std;

int ctoi(char c) {
  return (c == '0') ? 0 : 1;
}

int main() {
  	char s1, s2, s3;
  	cin >> s1 >> s2 >> s3;
  	cout << ctoi(s1) + ctoi(s2) + ctoi(s3);
}


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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0 ; i < strlen(str) ; i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]){
  long long key, i, h;
  key = getKey(str);
  for ( i = 0 ;; i++){
    h = (h1(key)+i*h2(key))%M;
    if( strcmp(H[h],str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;
  key = getKey(str);
  for ( i = 0; ; i++ ){
    h = (h1(key)+i*h2(key))%M;
    if( strcmp(H[h],str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i, n, h;
  char str[L],com[9];
  for ( i = 0 ; i < M ; i++ ) H[i][0] = '\0';
  scanf("%d",&n);
  for ( i = 0 ; i < n ; i++ ){
    scanf("%s %s",com,str);

    if ( com[0] == 'i' ){
      if (insert(str)){

      }
    } else {
      if (find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 16068
#include <stdio.h>
 
int rot[24][7] = {
    { 0,1,2,3,4,5,6 },{ 0,1,3,5,2,4,6 },{ 0,1,4,2,5,3,6 },{ 0,1,5,4,3,2,6 },
    { 0,2,6,3,4,1,5 },{ 0,2,3,1,6,4,5 },{ 0,2,1,4,3,6,5 },{ 0,2,4,6,1,3,5 },
    { 0,3,1,2,5,6,4 },{ 0,3,2,6,1,5,4 },{ 0,3,5,1,6,2,4 },{ 0,3,6,5,2,1,4 },
    { 0,4,1,5,2,6,3 },{ 0,4,2,1,6,5,3 },{ 0,4,5,6,1,2,3 },{ 0,4,6,2,5,1,3 },
    { 0,5,1,3,4,6,2 },{ 0,5,3,6,1,4,2 },{ 0,5,4,1,6,3,2 },{ 0,5,6,4,3,1,2 },
    { 0,6,2,4,3,5,1 },{ 0,6,3,2,5,4,1 },{ 0,6,5,3,4,2,1 },{ 0,6,4,5,2,3,1 } };
int assign[7];
 
int main()
{
    int i, j;
    int a[7], b[7], dice[7];
 
    for (i = 1; i <= 6; i++) scanf("%d", assign+i);
    for (i = 1; i <= 6; i++) scanf("%d", a+i);
    for (j = 0; j < 24; j++) {
        for (i = 1; i <= 6; i++) dice[i] = rot[j][i];
        for (i = 1; i <= 6; i++) b[i] = assign[dice[i]];
        for (i = 1; ; i++) {
            if (i > 6) { puts("Yes"); return 0; }
            if (a[i] != b[i]) break;
        }
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 2108
#include<stdio.h>

int main(){
	int a;
	int b;
	int c;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	if(a == 1){
		if(b == 1){
			printf("Open\n");
		}else{
			printf("Close\n");
		}
	}else{
		if(c == 1){
			printf("Open\n");
		}else{
			printf("Close\n");
		}
	}
	return 0;

}

Measured memory_bytes: 584
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}


fn main() {
    input!{
        n: usize,
        m: usize,
        a: [i32; n],
    }
    let mut b = a;
    b.sort();
    b.reverse();
    let sum: i32 = b.iter().sum();
    let result: f32 = sum as f32 / (4.0 * m as f32);
    if (b[m-1] as f32) < result {
        println!("No");
    }
    else {
        println!("Yes");
    }
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char c = sc.next().charAt(0);
    System.out.println((c == 'A') ? 'T' : (c == 'T') ? 'A' : (c == 'C') ? 'G' : 'C');
  }
}

Measured memory_bytes: 21716
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

int main() {
    string s;
    cin >> s;
    int a = 0;
    FOR(i, s.length()) {
        if (s[i] == 'o')a++;
    }
    if (a + 15 - s.length()>= 8)cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  cout<<string(s.size(),'x')<<endl;
  return 0;
}


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


int main() {
    string s;
    cin >> s;
    ll sum = 0;

    for(int bit=0; bit < (1<<s.size()-1); ++bit) {
        
        string equ;
        for(int i=0; i<s.size(); ++i) {
            equ += s[i];
            if(bit & (1<<i)) {
                sum += stoll(equ);
                equ.clear();
                // equ += " + ";
            }
        }
        sum += stoll(equ);
        // cout << equ << endl;
    }

    cout << sum << endl;


    




    return 0;
}



Measured memory_bytes: 256
// B. 

#include <sstream>
#include <iostream>
#include <vector>

using namespace std;

typedef long long LL;

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }

int main(int argc, char *argv[])
{
	int t;
	cin >> t;
	for (int tt = 0; tt < t; ++tt) {
		LL a, b, c, d;
		cin >> a >> b >> c >> d;
		bool ans = a >= b && b <= d;
		if (ans && b > c) {
			LL r = a % b;
			LL p = d % b;
			if (p) {
				LL g = gcd(p, b);
				r = b + r - (r / g + 1) * g;
			}
			ans = r <= c;
		}
		cout << (ans ? "Yes" : "No") << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long

signed main(){
  int K,A,B;cin>>K>>A>>B;
  if(K<=A){cout<<1<<endl;return 0;}
  if(A<=B){cout<<-1<<endl;return 0;}
  cout<<((K-A-1)/(A-B)+1)*2+1<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace abc146_a
{
  class Program
  {
    static void Main(string[] args)
    {

      var d = new Dictionary<string, int>() { { "SUN", 7 }, { "MON", 6 }, { "TUE", 5 }, { "WED", 4 }, { "THU", 3 }, { "FRI", 2 }, { "SAT", 1 } };
      Console.WriteLine(d[Console.ReadLine()]);
    }
  }
}

Measured memory_bytes: 11104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int Inf = (1<<30);
ll inf = (1LL<<60);
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() {
	int x, y;
	cin >> x >> y;
	cout << x + y - gcd(x, y) + 1 << endl;
	return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	string s; cin >> s;
	int n = s.size();
	int sum = 0;
	ll ans = 0;
	rep(i,n){
		if(s[i]=='A') sum++;
		else if(s.substr(i,2)=="BC"){
			ans += sum;
			i++;			
		}else{
			sum = 0;
		}
	}
	cout << ans << endl;
}


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

typedef vector<int> veci;
typedef pair<int, int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define INF (1e9 + 7)
#define fi first
#define se second
#define endl '\n'

void solve() {
    int n;
    cin >> n;

    veci xx(n);
    veci yy(n);
    veci hh(n);
    for (int i=0; i<n; ++i) {
        cin >> xx[i] >> yy[i] >> hh[i];
    }

    for (int x = 0; x <= 100; ++x) {
        for (int y = 0; y <= 100; ++y) {
            bool ok = true;
            int p = 0;
            while (p<n && !hh[p]) {
                p += 1;
            }
            int dist = abs(xx[p]-x) + abs(yy[p]-y);
            int hcand = hh[p] + dist;
            for (int k = 0; k < n; ++k) {
                if (k==p)   continue;
                dist = abs(xx[k]-x) + abs(yy[k]-y);
                if (dist>hcand) {
                    if (hh[k]) {
                        ok = false;
                        break;
                    }
                } else {
                    if (dist+hh[k] != hcand) {
                        ok = false;
                        break;
                    }
                }
            }

            if (ok) {
                cout << x << " " << y << " " << hcand << endl;
                return;
            }
        }
    }
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL_TEST
    (void)argc;
    const string strpath = string(argv[0]) + string("-test.in");
    freopen(strpath.c_str(), "r", stdin);
    int tcs;
    cin >> tcs;
    while (tcs-- > 0)
#endif
    solve();
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

const long long MOD = 1000000007;

int keta(int x){
  int y=0;
  while(x>0){
    x/=10;
    y++;
  }
  return y;
}

int main(){
  int n,k;
  int ans=0;
  cin >> n;
  for(int i=1;i<=n;i++){
    k = keta(i);
    if(k%2==1) ans++;
  }
  cout << ans << endl;
    
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{

	int a,b,c,d;
};

int N,M,Q;
int work[10];
int table_index;
int table[92378][10];
Info info[55];

void recursive(int index){

	if(index == 10){

		for(int k = 0; k < 10; k++){

			table[table_index][k] = work[k];
		}
		table_index++;

		return;
	}

	for(int i = work[index-1]; i <= M; i++){

		work[index] = i;
		recursive(index+1);
	}
}


int main(){

	scanf("%d %d %d",&N,&M,&Q);

	for(int i = 0; i < Q; i++){

		scanf("%d %d %d %d",&info[i].a,&info[i].b,&info[i].c,&info[i].d);
		info[i].a--;
		info[i].b--;
	}

	table_index = 0;

	for(int i = 1; i <= M; i++){

		work[0] = i;
		recursive(1);
	}

	int maximum = 0;

	for(int i = 0; i < table_index; i++){
		int tmp = 0;
		for(int k = 0; k < Q; k++){

			if(table[i][info[k].b]-table[i][info[k].a] == info[k].c){

				tmp += info[k].d;
			}
		}
		maximum = max(maximum,tmp);
	}

	printf("%d\n",maximum);

	return 0;
}


Measured memory_bytes: 7396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			int M = in.nextInt();
			int[] a = new int[N];
			int[] b = new int[N];
			int[] c = new int[M];
			int[] d = new int[M];
			for(int i = 0; i < N; i++) {
				a[i] = in.nextInt();
				b[i] = in.nextInt();
			}
			for(int i = 0; i < M; i++) {
				c[i] = in.nextInt();
				d[i] = in.nextInt();
			}

			for(int i = 0; i < N; i++) {
				long min = Long.MAX_VALUE;
				int  ans = 0;
				for(int j = 0; j < M; j++) {
					long tmp = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
					if(tmp < min) {
						min = tmp;
						ans = j + 1;
					}
				}
				out.println(ans);
			}
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

	}
}


Measured memory_bytes: 22740
#include <algorithm>
#include <vector>
#include <string>
#include <ctype.h>
#include <set>
#include <map>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<time.h>
#include<string>
#include<stack>
#include<cmath>
#include<iostream>
#include<cstring>
#include<complex>
#include<bitset>
#include<tr1/unordered_set>
#include<tr1/unordered_map>


#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
//Make sure no overflow problems
//#define int long long
#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define ld long double
const int INF = 1e9+7;
const long long INFLL = (ll)INF * (ll)INF;
const ld EPS = 10e-9;

using namespace std;

#pragma GCC optimize ("Ofast")
static auto _ = [] { std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); std::cerr.tie(0); return 0; } ();

class TrieNode{
    public:
    bool isword;
    char c;
    map<char,TrieNode*> m;
    string word;
    public:
    TrieNode(){}
    TrieNode(char ch){
        c=ch;
        isword=false;
    }
};

void insert(TrieNode* root,string word){
    TrieNode* temp=root;
    for(char c:word){
        if(temp->m.find(c)==temp->m.end())
            temp->m[c]=new TrieNode(c);
        temp=temp->m[c];
    }
    temp->isword=true;
    temp->word=word;
}



int main() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    int i=0,j=n-1;
    int count=0;
	vector<int> r,w;
  for(int i=0;i<n;i++){
    if(s[i]=='W')
      w.push_back(i);
    else
      r.push_back(i);
  }
  int wi=0,ri=r.size()-1;
  while(wi<w.size() && ri>=0 && w[wi]<r[ri]){
    ri--;
    wi++;
    count++;
  }
    cout<<count;
    return 0;
}




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

a=input().split()
b=[]
c=[]
i=0
while i<n:
    b.append(int(a[i]))
    i+=1

answer=str(b[n-1])
while n>1:
    answer=answer+" "+str(b[n-2])
    n=n-1
print(answer)



Measured memory_bytes: 5600
#include "bits/stdc++.h"
using namespace std;

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant

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

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* 
	add utility Algorithm
*/

bool resolver(string& s, int start) {
    if (s.substr(start, 3) == "ABC") return true;
    return false;
}

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;

    string S;
    cin >> S;

    int ans = 0;
    REPinit(i, 0, N - 2) {
        if (resolver(S, i)) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(){
  int n,max = 0,sum = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int p;
    scanf("%d", &p);
    sum += p;
    if (p > max) {
      max = p;
    }
  }
  printf("%d\n",sum-max/2);
}


Measured memory_bytes: 128
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    a = f()
    a = sorted(a, reverse = True)
    print(10*a[0] + a[1] + a[2])

solve()


Measured memory_bytes: 3064
import java.util.*;
public class Main {
	
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		int[][] map = new int[M][2];
		for (int i = 0; i < M; i++) {
			int[] tmp = new int[2];
			tmp[0] = sc.nextInt();
			tmp[1] = sc.nextInt();
			map[i] = tmp; 
		}
		
		int ans = 0;
		boolean next;
		do {
			next = false;
			for (int i = 1; i <= N; i++) {
				
				int count = 0;
				int[] tmp = new int[2];
				
				for (int j = 0; j < M; j++) {
					if (map[j][0] == i || map[j][1] == i) {
						tmp = map[j];
						count++;
					} 
				}
				
				if (count == 1) {
					tmp[0] = -1;
					tmp[1] = -1;
					ans++;
					next = true;
				}
			}
			
		} while (next);
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int N;cin>>N;
    map<int,int> mp;
    for(int i=0;i<N;i++){
        int a;cin>>a;
        mp[a]++;
    }
    int eve=0,ans=0;
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        if(itr->second%2==1)ans++;
        else eve++;
    }
    if(eve%2==0)ans+=eve;
    else ans+=eve-1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4992
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, w = map(int, readline().split())
n = int(readline())
a = list(map(int, readline().split()))
c = [[0] * w for i in range(h)]
cnt = 0
ans = 1
for i in range(h):
    for j in range(w):
        c[i][j] = ans
        cnt += 1
        if cnt == a[ans - 1]:
            ans += 1
            cnt = 0
for i in range(h):
    if i % 2 == 1:
        print(*c[i][::-1])
    else:
        print(*c[i])


Measured memory_bytes: 3916
#include <bits/stdc++.h>
#define SIZE 10
#define PI 3.141592653589793

using namespace std;
typedef long long ll;

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

	int i,j;
	int tmp;
	ll answer=0;
	ll N,K;
	ll prev;
	ll counter=0;

	cin >> N >> K;

	if(N>K){
		answer=min(N%K,abs(N -K*(N/K +1)));
	}else{
		answer=min(N,K-N);
	}
	
	cout << answer << endl;

	return 0;
}



Measured memory_bytes: 3608
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

int main(){
  int e;
  while(~scanf("%d",&e)){
    if(e==0) break;
    int res = INF;

    for(int y=0;y*y<=e;y++){
      for(int z=0;y*y+z*z*z<=e;z++){
	res = min(res,y+z+(e-y*y-z*z*z));
      }
    }
    printf("%d\n",res);
  }
}

Measured memory_bytes: 1184
#include<cstdio>
int main(){
int n;
long long int a[1000000000000000000000000000000000000000000000][1000000000000000000000000000000000000000000000000000][1000000000000000000000000000000000000000000000000000000000000000000000000][100000000000000000000000000000000000000000000000000000000000000000000000000];
scanf("%d", &n);
printf("%d\n", n/3);
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    int sum = 0;
    for (int i = 0; i < n; i++) {
        if (x[i] * 2 < abs(k - x[i]) * 2) {
            sum += x[i] * 2;
        }
        else {
            sum += abs(k - x[i]) * 2;
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 25

typedef struct {
    int parent;
    int left;
    int right;
    
}Tree;

void PreOrder(int);
void InOrder(int);
void PostOrder(int);

Tree data[N];
int n;

int main(){
 int i,id,root;

 scanf("%d",&n);
 for(i=0;i<n;i++){
    data[i].parent=-1;
    data[i].left=-1;
    data[i].right=-1;
 }

 for(i=0;i<n;i++){
     scanf("%d",&id);
     scanf("%d %d",&data[id].left,&data[id].right);
     if(data[id].left!=-1) data[data[id].left].parent=id;
     if(data[id].right!=-1)data[data[id].right].parent=id;
    
 }
 
 for(i=0;i<n;i++){
     if(data[i].parent==-1) root=i;
     
 }
 printf("Preorder\n");
 PreOrder(root);
 printf("\n");
 
 printf("Inorder\n");
 InOrder(root);
 printf("\n");
 
 printf("Postorder\n");
 PostOrder(root);
 printf("\n");
 
 return 0;
 
}

void  PreOrder(int node){
   if(node==-1) return;
   printf(" %d",node);
   PreOrder(data[node].left);
   PreOrder(data[node].right);
}

void InOrder(int node){
   if(node==-1) return;
   InOrder(data[node].left);
   printf(" %d",node);
   InOrder(data[node].right);
}

void PostOrder(int node){
   if(node==-1)  return;
   PostOrder(data[node].left);
   PostOrder(data[node].right);
   printf(" %d",node);
}


Measured memory_bytes: 2052
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int n,N;
vector<int> v;

void init(){
    N=1;
    while(N<n) N*=2;
    v.assign(2*N-1,0); //変更点
}

void init_u(){
    for(int i=N-2;i>=0;i--)
    v[i]=v[2*i+1]+v[2*i+2]; //変更点
}

void update(int k,int a){
    k+=N-1;
    v[k]=a;
    while(k>0){
        k=(k-1)/2;
        v[k]=v[k*2+1]+v[k*2+2]; //変更点
    }
}

//query(a,b,0,0,N);
int query(int a,int b,int k,int l,int r){
    if(r<=a || b<=l) return 0; //変更点
    if(a<=l && r<=b) return v[k];
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return vl+vr; //変更点
}

int main(){
    cin>>n;
    int q; cin>>q;
    string s; cin>>s;
    init();
    rep(i,n-1){
        if(s[i]=='A' && s[i+1]=='C') v[i+N-1]=1;
    }
    init_u();
    rep(i,q){
        int l,r; cin>>l>>r;
        printf("%d\n",query(l-1,r-1,0,0,N));
    }
}

Measured memory_bytes: 2048
n,k=input().split(' ')
n,k=int(n),int(k)
score=int()
r=1/n
for dice in range(1,n+1):
        counter=0
        mul=dice
        while mul<k:
            mul=mul*2
            counter+=1
        score+=r*((.5)**counter)

print(round(score,12))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------


/*------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
------------------------------------------------------------------------------*/
class UnionFind
{
public:
    UnionFind(int size) : m_Nodes(size)
    {
        Init();
    }
 
    void Init()
    {
        for (int i = 0, size = m_Nodes.size(); i < size; ++i)
        {
            m_Nodes[i].Init(i);
        }
    }
 
    int Root(int x)
    {
        const int parent = m_Nodes[x].m_Parent;
        if (parent == x)
        {
            return x;
        }
        else
        {
            return m_Nodes[x].m_Parent = Root(parent);
        }
    }
 
    bool Same(int x, int y)
    {
        return Root(x) == Root(y);
    }
 
    bool Unite(int x, int y)
    {
        x = Root(x);
        y = Root(y);
 
        if (x == y) return false;
 
        if (m_Nodes[x].m_Rank < m_Nodes[y].m_Rank)
        {
            m_Nodes[x].m_Parent = y;
            m_Nodes[y].m_Size += m_Nodes[x].m_Size;
        }
        else
        {
            m_Nodes[y].m_Parent = x;
            m_Nodes[x].m_Size += m_Nodes[y].m_Size;
            if (m_Nodes[x].m_Rank == m_Nodes[y].m_Rank) ++m_Nodes[x].m_Rank;
        }
 
        return true;
    }
 
    int Size(int x)
    {
        return m_Nodes[Root(x)].m_Size;
    }
 
private:
    struct Node
    {
    public:
        void Init(int index)
        {
            m_Parent = index;
            m_Rank = 0;
            m_Size = 1;
        }
 
        int m_Parent = -1;
        int m_Rank = -1;
        int m_Size = -1;
    };
 
    vector<Node> m_Nodes;
};
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    vector<int> p(N);
    rep(i, 0, N)
    {
        cin >> p[i];
        --p[i];
    }
    int x, y;
    rep(i, 0, M)
    {
        cin >> x >> y;
        --x; --y;
        uf.Unite(x, y);
    }
    int ans = 0;
    rep(i, 0, N)
    {
        if (uf.Same(i, p[i]))
        {
            ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
s,t = map(int,input().split())
k,l = map(int,input().split())
m,n = map(int,input().split())
a = (k-m)*s
b = (l-n)*t

if a+b == 0:
    print("infinity")
elif a>0 and a+b>0:
    print(0)
elif a<0 and a+b<0:
    print(0)
else:
    div = abs(a) // abs(a+b)
    if div == abs(a) / abs(a+b):
        print(div*2)
    else:
        print(div*2+1)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

int main() {
    std::string S;
    std::cin >> S;
    
    std::sort(S.begin(), S.end());
    S.erase(std::unique(S.begin(), S.end()), S.end());
    
    bool contained = false;
    for (char s='a'; s<='z'; s++) {
        contained = false;
        for (auto i=S.begin(); i!=S.end(); i++) {
            if (*i == s) {
                contained = true;
            }
        }
        if (!contained) {
            std::cout << s << std::endl;
            break;
        }
    }
    if (contained) std::cout << "None" << std::endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)
#define tl 1'000'000'007

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,key;
    cin >> s >> key;
    int flag;
    int memo=-1;
    REP(i,s.size()-key.size()+1){
        flag= 1;
        REP(j,key.size()){
            if(s[i+j]==key[j] || s[i+j]=='?') continue;
            else{
                flag= 0;
                break;
            }
        }
        if(flag) memo= i;
    }
    if(memo!=-1){
        REP(k,s.size()){
            if(memo<=k && k<memo+key.size()){
                if(memo==k) cout << key;
                continue;
            }
            if(s[k]=='?') cout << 'a';
            else cout << s[k];
        }cout << endl;
    
    }else cout << "UNRESTORABLE" << endl;
    return 0;
}
    

Measured memory_bytes: 256
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *
import fractions
readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors
def is_prime(n):
    i = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += 1
    return True
a, b = readl()
mx = max(a,b)
t = make_divisors(min(a,b))
count = 0
for i in t:
    if mx % i == 0:
        if is_prime(i):
            count += 1
print(count)

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

int main(){
  int n, c = 0;
  cin >> n;

  for(int i=105; i <= n; i++){

    if(i % 2 == 0) continue;

    int jc = 1;
    for(int j=1; j <= i/2; j++){
      if(i % j == 0) jc++;
    }

    if(jc == 8) c++;
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int n, k;
    cin >> n >> k;
    if ((n + 2 - 1) / 2 < k) cout << "NO" << endl;
    else cout << "YES" << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from itertools import permutations
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,C=map(int,input().split())
    D=[tuple(map(int,input().split())) for _ in range(C)]
    c=[tuple(map(int1,input().split())) for _ in range(N)]
    l=[[0]*C for _ in range(3)]
    for i in range(N):
        for j in range(N):
            l[(i+j)%3][c[i][j]]+=1
    ans=INF
    for t in permutations(range(C),3):
        tmp=0
        for i in range(3):
            for j in range(C):
                tmp+=l[i][j]*D[j][t[i]]
        ans=min(ans,tmp)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 48348
/**
*    created: 04.05.2020 07:59:31
**/

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


int main() {
    ll x;
    cin >> x;
    ll a=0, b=0;
    rep(i,200){
        for (int j = -200; j < 200;j++){
            if(/*i*i*i*i*i-j*j*j*j*j*/pow(i,5)-pow(j,5)==x){
                a = i;
                b = j;
                break;
            }
        }
    }
cout << a<<" "<<b << endl;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;
#define MX 10000000000000000

int main(){
  int n;
  cin>>n;
  n++;
  vector<ll>a(n);
  vector<ll>c(n);
  rep(i,n)cin>>a[i];

  c[0]=1;
  rep2(i,1,n){
    if(c[i-1]-a[i-1]<0){
      cout<<-1<<endl;
      return(0);
    }
    if(c[i-1]<MX)c[i]=(c[i-1]-a[i-1])*2;
    else c[i]=MX;
  }

  ll ans=a[n-1],now=a[n-1];
  if(now>c[n-1]){
    cout<<-1<<endl;
    return(0);
  }
  for(int i=n-2;i>=0;i--){
    now=min(now+a[i],c[i]);
    ans+=now;
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 4788
// D - Dice in Line
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
int in(){int x;scanf("%d",&x);return x;}
int N,K;
int S[200000+1];//累積和

int main(){
	cin>>N>>K;
	rp(i,0,N) S[i+1] = S[i] + in() + 1;
	int ans = 0;
	rp(i,0,N-K+1) ans = max(ans, S[i+K]-S[i]);
	printf("%.12f\n",ans/2.0);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e6 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;
int A, B;

vi divisor(int n) {
  vi ret;
  for (int i = 1; i * i <= n; ++i) {
    if (N % i == 0) {
      ret.push_back(i);
      if (i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(all(ret));
  return ret;
}

int gcd(int a, int b) {
  cerr << a << " " << b << endl;
  if (b > a) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}

void input() {
  cin >> A >> B;
  ;
  ;
}
vi yakusuA;
vi yakusuB;
vi kouyakusu;

map<int, int> factorize(int x) {
  map<int, int> res;
  for (int i = 2; i * i <= x; i++) {
    while (x % i == 0) {
      x /= i;
      res[i]++;
    }
  }
  if (x != 1) res[x]++;
  return res;
}
map<int, int> facA, facB;
int ans = 0;
void solve() {
  facA = factorize(A);
  facB = factorize(B);
  facA[1] = 1, facB[1] = 1;

  for (auto x : facA) {
    // debug(x.second);
    if (x.second >= 1) {
      if (facB[x.first] >= 1) {
        ans++;
      }
    }
  }
  // yakusuA = divisor(A);
  // yakusuB = divisor(B);
  // debugv(yakusuA);
  // debugv(yakusuB);
  // for (auto a : yakusuA) {
  //   for (auto b : yakusuB) {
  //     if (a == b) {
  //       kouyakusu.push_back(a);
  //     }
  //   }
  // }
  // kouyakusu.erase(unique(all(kouyakusu)), kouyakusu.end());
  // debug("kouyakusu");
  // debugv(kouyakusu);

  // int ans = 0;
  // debug(ans);
  // rep(i, 0, kouyakusu.size() - 1) {
  //   rep(j, 0, kouyakusu.size() - 1) {
  //     int x = kouyakusu[i];
  //     int y = kouyakusu[j];
  //     debug(x);
  //     debug(y);

  //     if (x == y) continue;
  //     if (gcd(x, y) == 1) {
  //       ans++;
  //       debug(ans);
  //     }
  //   }
  // }
  cout << ans << endl;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#define DEBUG 0

/**
 * File    : C.cpp
 * Author  : Kazune Takahashi
 * Created : 4/6/2019, 9:08:37 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

ll N;
ll A[5];
ll ind = 0;
ll mini;

int main()
{
  cin >> N;
  for (auto i = 0; i < 5; i++)
  {
    cin >> A[i];
  }
  mini = A[0];
  for (auto i = 0; i < 5; i++)
  {
    mini = min(mini, A[i]);
  }
  ll ans = (N + mini - 1) / mini;
  cout << ans + 4 << endl;
}

Measured memory_bytes: 256
n = int(input())
b = list(map(int, input().split()))

ans = 0
for i in range(n):
    if i == 0:
        ans += b[i]
    elif i == n - 1:
        ans += b[-1]
    else:
        ans += min(b[i - 1], b[i])
print(ans)

Measured memory_bytes: 3060
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,M = I()
if N == 1 or M == 1:
    if N == 1 and M == 1:
        print(1)
    else:
        print(max(N,M)-2)
else:
    print((N-2)*(M-2))

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

int main(){
  int kotae=1,i,n,kosuu=0,omoji=0;
  string s;
  cin>>s;
  n=s.length();
  if(s[0]!='A'){
    kotae=0;
  }
  for(i=2;i<n-1;i++){
    if(s[i]=='C'){
      kosuu++;
    }
  }
  for(i=0;i<n;i++){
    if(s[i]-'A'>=0&&s[i]-'A'<=25){
      omoji++;
    }
  }
  if(omoji!=2){
    kotae=0;
  }
  if(kosuu!=1){
    kotae=0;
  }
  if(kotae){
    cout<<"AC";
  }else{
    cout<<"WA";
  }
}


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

int main () {
    int A, B, s = 0;
    cin >> A >> B;

    for (int i = A; i <= B; i++){

        if (i / 1000 == i % 10 * 10 + i % 100 / 10){
            s += 1;
        }
    }

    cout << s << endl;

}

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

int main() {
	string s; cin >> s;
	int ans = 0;
	char cur = s[0];
	for (int i = 1; i < s.size(); i++) {
		if (cur != s[i]) { ans++; cur = s[i]; }
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var r, g, b string
	fmt.Scan(&r, &g, &b)
	s := fmt.Sprintf("%s%s%s", r, g, b)
	i, _ := strconv.Atoi(s)
	if i%4 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

int main(void)
{
  int a, b;
  cin >> a >> b;

  if ((a <= 9) && (b <= 9))
  {
    cout << a * b << "\n";
  }
  else
  {
    cout << -1 << "\n";
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N ()
#define ll long long
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define CM cerr<<(&MOP2-&MOP1)/1024.0/1024.0<<endl
using namespace std;
template <class T> inline T Min(T x, T y){
    return x<y?x:y;
}
template <class T> inline T Max(T x, T y){
    return x>y?x:y;
}
bool MOP1;
priority_queue<double>q;
bool MOP2;
int main(){
	int n;
	double ans=0.0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		double res;
		scanf("%lf",&res);
		q.push(-res);
	}
	for(int i=1;i<n;i++){
		double x=q.top();q.pop();
		double y=q.top();q.pop();
		q.push((x+y)/2.0);
	}
	printf("%lf\n",-q.top());
	return 0;
}
 





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

int main() {
  int h, w; cin >> h >> w;
  vector<string> c(h);
  for (int i=0; i<h; i++){
    cin >> c.at(i);
  }
  for (int i=0; i<h; i++){
    cout <<c.at(i) <<endl;
    cout <<c.at(i) <<endl;
  }
}


Measured memory_bytes: 256