akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")

const long int  mod = 7 + 10e9;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    int h,w;
    cin>>h>>w;
    vector<vector<char>>x;
    int i,j;
    char ans;
    for(i=0;i<h;i++){
        vector<char>y;
        for(j=0;j<w;j++){     
            cin>>ans;
            y.push_back(ans);
        }
        x.push_back(y);
    }
    int dp[h][w]={0};
    for(i=0;i<h;i++)
        for(j=0;j<w;j++)
            dp[i][j]=0;
    dp[0][0]=1;
    for(i=1;i<w;i++){
        if(x[0][i]=='.')
            dp[0][i]=1;
        else
            break;
    }
    for(i=1;i<h;i++){
        if(x[i][0]=='.')
            dp[i][0]=1;
        else
            break;  
    }
    for(i=1;i<h;i++){
        for(j=1;j<w;j++){
            if(x[i][j]=='.')
                dp[i][j]+=(dp[i-1][j]+dp[i][j-1])%1000000007;
            else
                continue;
        }
    }
    cout<<dp[h-1][w-1]<<"\n";
    return 0;
}

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

int a[10];
int b[10],c[10],lb,lc;
int vis[10];
int n,m,t;

bool dfs(int s,int e)
{
    int cnt = 0;
    if(s==e) return true;

    if(!lb || b[lb-1] < a[s])
    {
        cnt++;
        b[lb++] = a[s];
        if(dfs(s+1,e)) return true;
        lb--;
        b[lb] = 0;
    }
    if(!lc || c[lc-1] < a[s])
    {
        cnt++;
        c[lc++] = a[s];
        if(dfs(s+1,e)) return true;
        lc--;
        c[lc] = 0;
    }
    return false;
}

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&a[i]);
        lb = 0, lc = 0;
        if(dfs(0,10)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 1008
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define FF first
#define SS second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define PLL pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define LP lower_bound
#define UP upper_bound
#define MP make_pair
#define rep1 for(i=1;i<=n;i++)
#define VLL vector<ll>
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define UMP unordered_map
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
    fastio
    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r, t,u,w,x,y,z;
    string str, ss, str1;
    cin>>k;
    cin>>a>>b;
    for(i=k;i<b+10000;i+=k)
    {
        if(i>=a && i<=b)
        {
            cout<<"OK";
            return 0;
        }
    }
    cout<<"NG";
}

Measured memory_bytes: 3652
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  ll N;
  cin >> N;
  int pos[N + 1];
  for(int i = 0; i < N; i++){
    int a;
    cin >> a;
    pos[a] = i;
  }

  ll ans = 0LL;
  set<ll> S;
  S.insert(-1LL);
  S.insert(N);
  for(int i = 1; i <= N; i++){
    int a = pos[i];
    S.insert(a);
    auto itr = S.find(a);
    auto itrl = itr; itrl--;
    auto itrr = itr; itrr++;
    //cout << *itrl << " " << *itr << " " << *itrr << endl;
    ans += (ll)i * (*itr - *itrl) * (*itrr - *itr);
  }

  cout << ans << endl;
  return 0;
}


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

int A, B;
long s[100010], t[100010];
int bina(long key){
    int ok=-1, ng=A;
    while(ng-ok>1){
        int mid=(ok+ng)/2;
        if(s[mid]>key) ng=mid;
        else ok=mid;
    }
    return ng;
}
int binb(long key){
    int ok=-1, ng=B;
    while(ng-ok>1){
        int mid=(ok+ng)/2;
        if(t[mid]>key) ng=mid;
        else ok=mid;
    }
    return ng;
}
int main() {
	int Q; cin >> A >> B >> Q;
	for(int i=0; i<A; ++i) cin >> s[i];
	for(int i=0; i<B; ++i) cin >> t[i];
	for(int i=0; i<Q; ++i){
	    long x;
	    cin >> x;
	    long ans=1e18;
	    int aa=bina(x), bb=binb(x);
	    if(aa>0 && bb>0) ans=min(ans, x-min(s[aa-1], t[bb-1]));
	    if(aa>0 && bb<B) ans=min(ans, t[bb]-s[aa-1]+min(x-s[aa-1], t[bb]-x));
	    if(aa<A && bb>0) ans=min(ans, s[aa]-t[bb-1]+min(x-t[bb-1], s[aa]-x));
	    if(aa<A && bb<B) ans=min(ans, max(s[aa], t[bb])-x);
	    cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
int main()
{
    ll N;
    cin >> N;
    vector<ll> D(N);
    map<ll, ll> A;
    rep(i,N){
        cin >> D.at(i);
        A[D.at(i)]++;
    }
    ll M;
    cin >> M;
    vector<ll> T(M);
    rep(i,M){
        cin >> T.at(i);
        if(A.count(T.at(i))){
            A[T.at(i)]--;
            if(A[T.at(i)]<0){
                cout << "NO" << endl;
                return 0;
            }
        }
        else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 15872
N,M = list(map(int, input().split()))
data = []
for _ in range(N):
    data.append(list(map(int, input().split())))
data.sort(key=lambda d: d[0])
total = 0
for i in range(N):
    M -= data[i][1]
    total += data[i][1] * data[i][0]
    if M <= 0:
        total -= data[i][0] * -M
        break
print(total)

Measured memory_bytes: 29024
from collections import Counter

N = int(input())
alpha = [chr(i) for i in range(97, 97+26)]
temp = ['a']
result = ['a']
if N >= 2:
  for n in range(2,N+1):
    result = []
    for i in temp:
      temp_list = list(i)
      type = len(Counter(temp_list))
      for j in range(type+1):
        a = i + alpha[j]
        result.append(a)
    temp = result.copy()
print('\n'.join(result))

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

int N, temp, ans;

int main() {
    cin >> N;
    int a[N];
    for (int i=0; i<N; i++) cin >> a[i];
    for (int i=0; i<N; i++) {
        for (int j=i; j>0; j--) {
            if (a[j] < a[j-1]) {
                temp = a[j]; a[j] = a[j-1]; a[j-1] = temp; ans+=1;
            }
        }
    }
    cout << a[0];
    for (int k=1; k<N; k++) cout << " " << a[k];
    cout << endl << ans <<endl;
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

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

const char newl = '\n';

int main() {
    int n;
    cin >> n;
    vector<pair<ll,ll>> a(n);
    vector<vector<ll>> dp(n+1,vector<ll>(n+1,0));
    for (int i = 0;i < n;++i) cin >> a[i].first;
    for (int i = 0;i < n;++i) a[i].second = i;
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    for (int i = 0;i < n;++i) {
        for (int j = 0;j < i+1;++j) dp[i+1][j+1] = dp[i][j]+a[i].first*abs(j-a[i].second);
        for (int j = 0;j < i+1;++j) dp[i+1][j] = max(dp[i+1][j],dp[i][j]+a[i].first*abs(n-1+j-i-a[i].second));
    }
    cout << *max_element(dp[n].begin(),dp[n].end()) << endl;
}

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

#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pi;
typedef vector<int> vi;
void print_pair(pi a){
  cerr<<"("<<a.first<<", "<<a.second<<") ";
}
template<int T1, int T2>
void print_2d(int a[T1][T2], int x, int y){
  For(i, x){
    For(j, y){
      cerr<<a[i][j]<<" ";
    }
    cerr<<endl;
  }
}
template<class T>
void print_array(T a[],size_t n){
  cerr<<"array:";
  REP(n-1)cerr<<a[i]<<",";
  cerr<<a[n-1]<<endl;
}

ll N,X,A[100];

int main(){
  cin>>N>>X;
  REP(N)cin>>A[i];
  sort(A,A+N);
  ll sum=0;
  int i,ans=0;
  for (i = 0; sum<=X&&i<N ; i++) {
    sum+=A[i];
    ans++;
  }
  if(i<N){
    cout<<ans-1<<endl;
  }else{
    if(sum==X)cout<<ans<<endl;
    else cout<<ans-1<<endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,k;
vector<int>n;
int main()
{
    cin>>a;
    for(int i=0; i<a; i++)
    {
        cin>>k;
        if((i+a+1)%2)n.push_back(k);
        else n.insert(n.begin(),k);
    }
    for(int i=0; i<a; i++)cout<<n[i]<<" ";
}

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

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

  int x,y;
  if (a<b) {
    x=a;y=b;
  } else {
    x=b;y=a;
  }

  string ans="",item=to_string(x);
  for (int i=0;i<y;i++) ans+=item;

  cout << ans<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int n,b;
int main(){
	cin>>n;
	long long int a = sqrt(n);
	for(;;){
		if(n%a==0){b=n/a;break;}
		a--;
	}
	cout << to_string(b).length() << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] t = new int[n];
		for(int i = 0;i < n ;i++) {
			t[i] = sc.nextInt();
		}
		int m = sc.nextInt();
		int[] p = new int[m];
		int[] x = new int[m];
		for(int k = 0;k < m ;k++) {
			p[k] = sc.nextInt();
			x[k] = sc.nextInt();
		}
		int[] sum = new int[m];
		for(int i = 0;i <m;i++) {
			for(int k =0; k < n;k++) {
				if(p[i]-1 == k)sum[i] +=x[i];
				else sum[i] += t[k];
			}
			System.out.println(sum[i]);
		}
	}

}


Measured memory_bytes: 23892
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define MOD 1000000007
#define N 4003

int n;
string s;

ll dp[N][N];
void solve() {
  dp[n-1][1] = 1;
  replr(i, 1, n-2) {
    repl(k, 1, n-i) {
      ll r = dp[i][k-1];
      if(s[i-1] == '<') {
        if(s[i] == '<') {
          r += dp[i+1][k-1];
        } else {
          r += dp[i+1][n-i-k];
        }
      } else {
        if(s[i] == '<') {
          r += dp[i+1][n-i-k];
        } else {
          r += dp[i+1][k-1];
        }
      }
      dp[i][k] = r % MOD;
    }
  }
}

int main() {
  cin >> n >> s;
  ll ans = 0;
  rep(i, n+1) rep(j, n+1) dp[i][j] = 0;
  solve();
  rep(k, n) {
    ans += dp[1][k+1];
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 94208
#include <bits/stdc++.h>
#define MAXN 100000
using namespace std;
int par[MAXN];
int rank[MAXN];

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

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

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

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

int main() {
  int n, q;
  cin >> n >> q;
  init(n);
  for (int i=0; i<q; i++) {
    int com, x, y;
    cin >> com >> x >> y;
    switch (com) {
    case 0:
      unite(x,y);
      break;
    case 1:
      printf("%d\n", same(x,y));
      break;
    default:
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3292
let () =
  Scanf.scanf "%d %d %d" @@ fun n a b ->
  let p = Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x)) in
  Array.fold_left (fun (d, y) x -> (d + min b (a * (x-y)), x)) (0, p.(0)) p
  |> fst |> Printf.printf "%d\n"

Measured memory_bytes: 5120
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end(),greater<int>());
  
  int alice = 0;
  int bob = 0;
  
  rep(i,n){
    if(i%2 == 0){
      alice += a[i];
    }else{
      bob += a[i];
    }
  }
  
  cout << alice - bob;
  return 0;
}

Measured memory_bytes: 256
#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() {
  int n;
  cin>>n;
  vector<string> w(n);
  rep(i,n){
    cin>>w[i];
  }
  bool ans=true;
  map<string,int> k;
  rep(i,n){
    if(k.count(w[i])){
      ans=false;
    }
    k[w[i]]=0;
  }
  rep(i,n-1){
    string las, fir;
    las=w[i].substr(w[i].size()-1,1);
    fir=w[i+1].substr(0,1);
    if(las!=fir){
      ans=false;
    }
  }
  if(ans){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	d=a/b;
	r=a%b;
	f=(double)a/b;
	printf("%d %d %lf\n",d,r,f);
	
	return 0;
}

Measured memory_bytes: 636
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        long K = sc.nextLong();
        
        int ans = 1;
        for(int i = 0; i < S.length(); i++){
            if( S.charAt(i) !=  '1' ){
                ans = S.charAt(i) - '0';
                break;
            }
            
            if( (i+1) == K ) break;
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 23636
#include<stdio.h>

int main()
{
	int a,b,c,d,x;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a<b){
		x=a;

	}
	else{
		x=b;
	}
	if(c<d){
		x=x+c;
	}
	else{
		x=x+d;
	}
	printf("%d\n",x);



}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
	int N,a[4],i,b,c,j,k;
	while(1){
		scanf("%d",&N);
		if(N==0000){
			return 0;
		}
		c=0;
		b=0;
	while(N!=6174){
		a[3]=N%10;
		a[2]=(N%100-a[3])/10;
		a[1]=(N%1000-a[2]*10-a[3])/100;
		a[0]=(N-a[3]-a[2]*10-a[1]*100)/1000;
		for(j=0;j<4;j++){
			for(i=0;i<3;i++){
				if(a[i]<=a[i+1]){
					k=a[i];
					a[i]=a[i+1];
					a[i+1]=k;
				}
			}
		}
		N=(a[0]*1000+a[1]*100+a[2]*10+a[3])-(a[3]*1000+a[2]*100+a[1]*10+a[0]);
		if(N==0){
			b=1;
			break;
		}
		c++;
	}
		if(b==1){
			printf("NA\n");
		}else{
			printf("%d\n",c);
			}
	}
}
	

Measured memory_bytes: 608
import math
import sys
N = int(input())
mylist = list(map(int, input().split()))
mylist.sort(reverse = True)
#print(mylist)
if mylist[-1] == 0:
    print(0)
    sys.exit()
else:
    myans = 1
    for m in mylist:
        myans *= m
        if myans > 10**18:
            print(-1)
            sys.exit()
    print(myans)

Measured memory_bytes: 22160
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
typedef long long ll;

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

  vector<pair<ll, ll>> v;
  for (ll i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;
    v.push_back({a, b});
  }

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

  ll ans = 0;
  ll current = m;
  for (auto x : v) {
    if (current - x.second >= 0) {
      ans += x.first * x.second;
      current -= x.second;
    } else {
      ans += x.first * current;
      cout << ans << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4900
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
  ll n;
  scanf("%lld",&n);
  ll a,count4=0,count2=0,odd=0;
  rep(i,n){
    scanf("%lld",&a);
    if(a%2){
      odd++;
    }else if(a%4==0){
      count4++;
    }else{
      count2++;
    }
  }

  if(odd==0){
    printf("Yes\n");
    return 0;
  }

  if(odd+(count2?1:0)<=count4+1){
    printf("Yes\n");
    return 0;
  }
  printf("No\n");
  return 0;
}

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

int main(void){
    int n,m;
    scanf("%d%d",&n,&m);
    int a[m],b[m];
    int c[n+1];
    int d[n+1];
    for(int i=0;i<m;i++){
        scanf("%d%d",&a[i],&b[i]);
    }
    for(int i=0;i<=n;i++){
        c[i]=0;
        d[i]=0;
    }
    for(int i=0;i<m;i++){
        c[a[i]]++;
        d[b[i]]++;

    }
    
    for(int i=1;i<=n;i++){
        printf("%d\n",c[i]+d[i]);
    }
    return 0;
}

Measured memory_bytes: 128
use std::fmt::Debug;
use std::str::FromStr;

pub struct TokenReader {
    reader: std::io::Stdin,
    tokens: Vec<String>,
    index: usize,
}

impl TokenReader {
    pub fn new() -> Self {
        Self {
            reader: std::io::stdin(),
            tokens: Vec::new(),
            index: 0,
        }
    }

    pub fn next<T>(&mut self) -> T
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index += 1;
        self.tokens[self.index - 1].parse().unwrap()
    }

    pub fn vector<T>(&mut self) -> Vec<T>
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index = self.tokens.len();
        self.tokens.iter().map(|tok| tok.parse().unwrap()).collect()
    }

    pub fn load_next_line(&mut self) {
        let mut line = String::new();
        self.reader.read_line(&mut line).unwrap();

        self.tokens = line
            .split_whitespace()
            .map(String::from)
            .collect();
        self.index = 0;
    }
}

fn solve(points: Vec<(i64, i64)>) -> i64 {
    let mut min1 = std::i64::MAX;
    let mut max1 = std::i64::MIN;

    let mut min2 = std::i64::MAX;
    let mut max2 = std::i64::MIN;

    for (x, y) in points {
        let f1 = x + y;
        min1 = std::cmp::min(min1, f1);
        max1 = std::cmp::max(max1, f1);

        let f2 = x - y;
        min2 = std::cmp::min(min2, f2);
        max2 = std::cmp::max(max2, f2);
    }

    std::cmp::max(max1 - min1, max2 - min2)
}

fn main() {
    let mut reader = TokenReader::new();
    let n = reader.next();
    let points = (0..n).map(|_| (reader.next(), reader.next())).collect();

    let res = solve(points);
    println!("{}", res);
}


Measured memory_bytes: 5124
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] a_asArgs)
        {
			int[] l_aiAB = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

			int l_iCount = 0;
			for (int l_iN = l_aiAB[0]; l_iN <= l_aiAB[1]; l_iN++)
			{
				if (l_iN / 10000 == l_iN % 10 && (l_iN / 1000) % 10 == (l_iN / 10) % 10)
				{
					l_iCount++;
				}
			}
			Console.WriteLine(l_iCount);
		}
	}
}


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

long long int abs1(long int a)
{
	if(a<0)
	  return -a;
	else
	  return a;
}

int main() {
	long int i,n;
	cin>>n;
	long long int a[n+2],sum=0;
	a[0]=0;
	for(i=1;i<=n;i++)
	  {
	  	  cin>>a[i];
	  	  sum+=abs1(a[i]-a[i-1]);
	  	  //cout<<sum<<"\n";
	  }
	 //cout<<sum<<'\n'; 
	 a[n+1]=0; 
	 sum+=abs(a[n+1]-a[n]);
	for(i=1;i<=n;i++)
	  {	long int temp=sum;
	  	  temp-=abs1(a[i]-a[i-1]);
	  	  temp-=abs1(a[i+1]-a[i]);
	  	  temp+=abs1(a[i-1]-a[i+1]);
	  	  cout<<temp<<"\n";
	  }
	// your code goes here
	return 0;
}

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

int main()
{
  int H, W;
  while(true) {
    cin >> H >> W;
    if (H == 0 && W == 0) {
      break;
    }
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        cout << '#';
      }
      cout << endl;
    }
    cout << endl;
  }
}



Measured memory_bytes: 3120
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            int cnt = 0;
            for(int i=0;i<S.Length;i++)
            {
                if (S.Substring(i, 1) != T.Substring(i, 1))
                {
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


//Console.WriteLine(ans);


Measured memory_bytes: 36696
# -*- coding: utf-8 -*-

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

s = 0
remain = A[-1]
for i in range(N-1, -1, -1):
    if remain >= B[i]:
        s += B[i]
        remain = A[i]
    elif remain + A[i] >= B[i]:
        s += B[i]
        remain = remain + A[i] - B[i]
    else:
        s += remain + A[i]
        remain = 0

print(s)

Measured memory_bytes: 18624
module UnionFind : sig
  type t

  module Class : sig
    type t
    val to_int : t -> int
    val compare : t -> t -> int
  end

  (* n要素の素集合データ構造を作る *)
  val make : int -> t
  (* 要素がどの集合に属するか調べる *)
  (* 要素は0からn-1の整数である必要がある *)
  val find : t -> int -> Class.t
  (* 与えられた要素が属する集合同士を合併する *)
  val unite : t -> int -> int -> unit
end = struct
  type t = { rank : int array; parent : int array }

  module Class = struct
    type t = int
    let to_int c = c
    let compare = compare
  end

  let make n =
    { rank = Array.make n 0;
      parent = Array.init n @@ fun c -> c }

  let rec find uf x =
    if x = uf.parent.(x) then x
    else begin
      let y = find uf uf.parent.(x) in
      uf.parent.(x) <- y; y
    end

  let unite uf i j =
    let x = find uf i in
    let y = find uf j in
    if x <> y then begin
      if uf.rank.(x) < uf.rank.(y) then uf.parent.(x) <- y
      else begin
        uf.parent.(y) <- x;
        if uf.rank.(x) = uf.rank.(y) then
          uf.rank.(x) <- 1 + uf.rank.(x)
      end
    end
end

let () = Scanf.scanf "%d %d\n" @@ fun h w ->
  let ss = Array.init h @@ fun _ -> Scanf.scanf "%s\n" @@ fun s -> s in
  let uf = UnionFind.make (h * w) in
  for i = 0 to h - 1 do
    for j = 0 to w - 2 do
      if ss.(i).[j] <> ss.(i).[j + 1] then
        UnionFind.unite uf (w * i + j) (w * i + j + 1)
    done
  done;
  for i = 0 to h - 2 do
    for j = 0 to w - 1 do
      if ss.(i).[j] <> ss.(i + 1).[j] then
        UnionFind.unite uf (w * i + j) (w * (i + 1) + j)
    done
  done;
  let countw = Array.make (h * w) 0 in
  let countb = Array.make (h * w) 0 in
  for i = 0 to h - 1 do
    for j = 0 to w - 1 do
      let c = UnionFind.find uf (w * i + j) in
      let count = if ss.(i).[j] = '.' then countw else countb in
      count.(UnionFind.Class.to_int c) <- count.(UnionFind.Class.to_int c) + 1
    done
  done;
  Printf.printf "%d\n" @@
  Array.fold_left ( + ) 0 @@ 
  Array.init (h * w) @@ fun i -> countb.(i) * countw.(i)


Measured memory_bytes: 8320
# coding: utf-8
# Your code here!
length = int(raw_input())
li = list(map(int,raw_input().split()))
li_sort = sorted(li)
if li_sort[length/2] == li_sort[length/2-1]:
    for i in range(length):
        print li_sort[length/2]
else:
    for i in li:
        if i <= li_sort[length/2-1]:
            print li_sort[length/2]
        else:
            print li_sort[length/2-1]

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

//テストケースが通らない。

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

    bool s[10] = {};
    int cnt = 0, f = 0;
    rep(i, n)
    {
        int a;
        cin >> a;
        if (!s[a / 400] && a < 3200)
        {
            cnt++;
            s[a / 400] = 1;
        }
        else if (a >= 3200)
            f++;
    }

    cout << (cnt == 0 ? 1 : cnt) << " " << cnt + f << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN 500
#define LL long long
using namespace std;

int n;
LL c[MAXN][5],p[5],a[MAXN];

LL getA(int c1,int c2,int c3,int c4){
	LL t1=c1*p[0]+c2*p[1]+c3*p[2]+c4*p[3];
	LL t2=c2*p[0]+c3*p[1]+c4*p[2]+c1*p[3];
	LL t3=c3*p[0]+c4*p[1]+c1*p[2]+c2*p[3];
	LL t4=c4*p[0]+c1*p[1]+c2*p[2]+c3*p[3];
	return min(min(t1,t2),min(t3,t4));
}

LL getD(int c1,int c2,int c3,int c4){
	LL t1=c1*p[0]+c2*p[1]+c3*p[2]+c4*p[3];
	LL t2=c2*p[0]+c3*p[1]+c4*p[2]+c1*p[3];
	LL t3=c3*p[0]+c4*p[1]+c1*p[2]+c2*p[3];
	LL t4=c4*p[0]+c1*p[1]+c2*p[2]+c3*p[3];
	return 1+(t1==t2)+(t1==t3)+(t1==t4);
}

LL cnt[5],b[5],visit[5];

LL getP(LL x,int y){
	LL res=1;
	for(int i=0;i<y;i++) res*=x-i;
	return res;
}

LL calc(){
	memset(visit,0,sizeof visit);
	LL res=1;
	for(int i=0;i<4;i++)
		if(!visit[i]){
			int temp=0;
			for(int j=0;j<4;j++)
				if(b[i]==b[j]){
					temp++;
					visit[j]=1;
				}
			res*=getP(cnt[i],temp);
		}
	return res;
}

LL gao(int x,int y,int d){
	static LL top[5],bot[5];
	for(int i=0;i<4;i++){
		top[i]=c[x][i];
		bot[i]=c[y][(4-(i+d)%4)%4];
	}
	b[0]=getA(top[3],top[2],bot[2],bot[3]);
	b[1]=getA(top[2],top[1],bot[1],bot[2]);
	b[2]=getA(top[1],top[0],bot[0],bot[1]);
	b[3]=getA(top[0],top[3],bot[3],bot[0]);
	LL delta=1;
	delta*=getD(top[3],top[2],bot[2],bot[3]);
	delta*=getD(top[2],top[1],bot[1],bot[2]);
	delta*=getD(top[1],top[0],bot[0],bot[1]);
	delta*=getD(top[0],top[3],bot[3],bot[0]);
	memset(cnt,0,sizeof cnt);
	for(int i=1;i<=n;i++)
		if((i^x) && (i^y)){
			(a[i]==b[0])?cnt[0]++:0;
			(a[i]==b[1])?cnt[1]++:0;
			(a[i]==b[2])?cnt[2]++:0;
			(a[i]==b[3])?cnt[3]++:0;
		}
	LL res=calc();
	return res*delta;
}

int main(){
#ifdef DEBUG
	freopen("E.in","r",stdin);
#endif
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld%lld%lld%lld",&c[i][0],&c[i][1],&c[i][2],&c[i][3]);
	p[0]=1;
	for(int i=1;i<4;i++) p[i]=p[i-1]*1000;
	for(int i=1;i<=n;i++) a[i]=getA(c[i][0],c[i][1],c[i][2],c[i][3]);
	LL ans=0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			for(int k=0;k<4;k++)
				ans+=gao(i,j,k);
	ans/=3;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(ll a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll in1, in2, in3;
	while (true) {
		cin >> in1 >> in2 >> in3;
		if (in1 == 0 && in2 == 0 && in3 == 0) { break; }
		vector<ll>a;
		a.pb(in1);
		a.pb(in2);
		a.pb(in3);

		Sort(a);
		ll n;
		cin >> n;
		double save = sqrt(a[0] * a[0] + a[1] * a[1]) / 2.00;
		rep(i, n) {
			double r;
			cin >> r;
			if (r > save) { cout << "OK" << endl; }
			else { cout << "NA" << endl; }
		}
		}return 0;

}


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

int down(const void *a,const void *b){
  if(*(long long *)a > *(long long *)b){
    return -1;
  }
  else if(*(long long *)a < *(long long *)b){
    return 1;
  }
  else if(*(long long *)a == *(long long *)b){
    return 0;
  }
}

int main(void){
  int n , m;
  scanf("%d %d",&n ,&m);

  long long x[n] , y[n] , z[n];
  for(int i = 0;i < n;i ++){
    scanf("%lld %lld %lld",&x[i] ,&y[i] ,&z[i]);
  }

  long long cake1[n] , cake2[n] , cake3[n] , cake4[n];
  long long cake5[n] , cake6[n] , cake7[n] , cake8[n];

  for(int i = 0;i < n;i ++){
    cake1[i] = x[i] + y[i] + z[i];
    cake2[i] = x[i] + y[i] - z[i];
    cake3[i] = x[i] - y[i] + z[i];
    cake4[i] = x[i] - y[i] - z[i];
    cake5[i] = -x[i] + y[i] + z[i];
    cake6[i] = -x[i] + y[i] - z[i];
    cake7[i] = -x[i] - y[i] + z[i];
    cake8[i] = -x[i] - y[i] - z[i];
  }

  qsort(cake1,n,sizeof(long long),down);
  qsort(cake2,n,sizeof(long long),down);
  qsort(cake3,n,sizeof(long long),down);
  qsort(cake4,n,sizeof(long long),down);
  qsort(cake5,n,sizeof(long long),down);
  qsort(cake6,n,sizeof(long long),down);
  qsort(cake7,n,sizeof(long long),down);
  qsort(cake8,n,sizeof(long long),down);

  long long ans = 0;
  long long count[8] = {0};
  for(int i = 0;i < m;i ++){
    ans += cake1[i];
    count[0] += cake2[i];
    count[1] += cake3[i];
    count[2] += cake4[i];
    count[3] += cake5[i];
    count[4] += cake6[i];
    count[5] += cake7[i];
    count[6] += cake8[i];
  }

  for(int i = 0;i <= 6;i ++){
    if(ans < count[i]){
      ans = count[i];
    }
  }

  printf("%lld\n",ans);

  return 0;
}

Measured memory_bytes: 1828
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int F = 0;
  string color,result;
  for(int i = 0; i < N; i++){
    cin >> color;
    if (color == "Y"){
      F = 1;
    }  
  }
  if (F == 0){
    result = "Three";
  }else{
    result = "Four";
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    string str;
    cin >> str;
    string ori = "CODEFESTIVAL2016";
    int ret = 0;
    for(int i=0; i<16; i++)
    {
        if(ori[i] != str[i]) ret++;
    }
    cout << ret << endl;
}

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

res = []

x, y = len(s), len(t)
for i in range(0, x):
	c = 0
	sub = s[i:i+y]
	if len(sub) == y:
		for a, b in zip(sub, t):
			if a != b:c+=1
		res += [c]
	else:
		break
print(min(res))

Measured memory_bytes: 9124
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
char s[100000 + 5], st[100000 + 5];
int n, top = 0;
int main() {
	scanf("%s", s);
	n = strlen(s);
	for (int i = 0; i < n; ++i) {
		if (top && (st[top] == '0' && s[i] == '1') || (st[top] == '1' && s[i] == '0')) --top;
		else st[++top] = s[i];
	}
	printf("%d\n", n - top);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

struct UF{
    LL n;
    vector<LL> par;
    UF(LL n) : n(n) {
        for(LL i = 0; i < n; i++) par.push_back(i);
    }
    LL find(LL a){
        if(a != par[a]) par[a] = find(par[a]);
        return par[a];
    }
    void join(LL a, LL b){
        par[find(a)] = find(b);
    }
};

int main(){
    LL n, m;
    cin >> n >> m;
    LL a[n];
    for(LL i = 0; i < n; i++){
        cin >> a[i];
    }
    UF uf(n);
    LL num = n-1;
    for(LL j = 0; j < m; j++){
        LL x, y;
        cin >> x >> y;
        uf.join(x, y);
        num--;
    }
    num *= 2;
    vector<multiset<LL> > f(110000);
    for(LL i = 0; i < n; i++){
        f[uf.find(i)].insert(a[i]);
    }
    LL ans = 0;
    multiset<LL> g;
    for(auto x : f){
        if(num > 0 && x.size() > 0){
            ans += *x.begin();
            x.erase(x.begin());
            num--;
        }
        for(auto y : x){
            g.insert(y);
        }
    }
    while(num > 0 && g.size() > 0){
        ans += *g.begin();
        g.erase(g.begin());
        num--;
    }
    if(num > 0){
        cout << "Impossible" << endl;
    } else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 20980
a,b = map(int,input().split())
print(100,100)

for i in range(50):
    if i%2 == 1:
        print("#"*(100))
    else:
        res = []
        for j in range(100):
            if j%2 == 1:
                res.append("#")
            elif a > 1:
                res.append(".")
                a -= 1
            else:
                res.append("#")
        print("".join(res))

for i in range(50):
    if i%2 == 0:
        print("."*(100))
    else:
        res = []
        for j in range(100):
            if j%2 == 1:
                res.append(".")
            elif b > 1:
                res.append("#")
                b -= 1
            else:
                res.append(".")
        print("".join(res))

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

vector<int> a;
vector<vector<int> > b;
const int BIT = 30;
int n;

int main(){
    cin >> n;
    a.assign(n, 0);
    b.assign(BIT, vector<int>(n, 0));
    for(int i = 0; i < n;i ++){
        cin >> a[i];
    }
    for(int i = 0 ; i < n; i++){
        int tb;
        cin >> tb;
        for(int k = 0; k < BIT; k++){
            b[k][i] = (tb % (1 << (k + 1)));
        }
    }
    int ans = 0;
    for(int i = 0 ; i < BIT;i++){
        sort(b[i].begin(), b[i].end());
    }
    for(int i = 0;i < a.size(); i++){
        int crt;
        for(int k = 0; k < BIT; k++){
            int t = (1 << k);
            crt = a[i] % (1 << (k + 1));
            vector<int>::iterator left1 = lower_bound(b[k].begin(), b[k].end(), t - crt);
            vector<int>::iterator right1 = lower_bound(b[k].begin(), b[k].end(), 2 * t - crt);
            // right1 --;
            #ifdef DEBUG
            if (k <= 2){
                cout << "k = " << k << "\n";
            }
            #endif // DEBUG
            if(right1 >= left1){
                #ifdef DEBUG
                 if (k <= 2){
                    cout << "\tCase 1: " << left1 - b[k].begin() << " - " << right1 - b[k].begin() << "\n";
                    cout << "\t" << (*left1) << " " <<  t - crt <<  "\n";
                 }
                #endif // DEBUG
                ans ^= (((right1 - left1) & 1) ? 1 : 0) * (1 << k);
            }

            vector<int>::iterator left2 = lower_bound(b[k].begin(), b[k].end(), 3 * t - crt);
            vector<int>::iterator right2 = lower_bound(b[k].begin(), b[k].end(), 4 * t - crt);
            // right2 --;
            if(right2 >= left2){
                #ifdef DEBUG
                 if (k <= 2)
                cout << "\tCase 2: " << left2 - b[k].begin() << " - " << right2 - b[k].begin() << "\n";
                #endif // DEBUG
                ans ^= (((right2 - left2) & 1) ? 1 : 0) * (1 << k);
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 28252
# encoding:utf-8

import copy
import numpy as np
import random

a = []
b = []

for i in range(3):
    a_now,b_now = map(int, input().split())
    a.append(a_now)
    b.append(b_now)

town_dic = {1:0,2:0,3:0,4:0}

for i in range(3):
    town_dic[a[i]] += 1
    town_dic[b[i]] += 1

answer = "YES"
for i in range(4):
    if town_dic[i+1] == 3:
        answer = "NO"


print(answer)


Measured memory_bytes: 13752
n = int(input())
dic = {}
val_set = set()
ans = []

for i in range(n):
  temp = input()
  try:
    dic[temp] += 1
  except:
    dic[temp] = 1

dic = sorted(dic.items(), key=lambda x: x[1], reverse=True)

for key,val in dic:
  val_set.add(val)
  if len(val_set) == 2:
    break
  else:
    ans.append(key)
  
ans = sorted(ans)

for x in ans:
  print(x)

Measured memory_bytes: 43228
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;


int main()
{
    // 整数の入力
    ll N,K;
    cin >> N >> K;
    vector<double> Sums;
    Sums.push_back(0);
    for(int i = 0; i< N;i++){
        double p;
        cin >> p;
        Sums.push_back(Sums.back() + (p+1)/2);
        // cout << Sums.back() << endl;
    }
    double ans = 0;
    for(int i = 0; i<= N - K;i++){
        // cout << Sums[i] << "," << Sums[i+K] << ":" << Sums[i+K] - Sums[i] << endl;
        ans = max(ans, Sums[i+K] - Sums[i]);
        // cout << ans << endl;
    }
    cout << fixed << setprecision(12) << ans << endl;;
    return 0;
}

Measured memory_bytes: 2420
use std::io;
use std::io::prelude::*;

fn run(args: &Vec<String>) -> (i32, i32) {
    let s = args[0].to_string();
    for i in 0..s.len() {
        if s.len() >= 2 && i <= s.len() - 2 && s[i..i+1] == s[i+1..i+2] {
            return ((i+1) as i32, (i+2) as i32);
        } else if s.len() >= 3 && i <= s.len() - 3 && s[i..i+1] == s[i+2..i+3] {
            return ((i+1) as i32, (i+3) as i32);
        }
    }
    (-1, -1)
}

fn main() {
    let stdin = io::stdin();
    let args = stdin.lock().lines().map(|l| l.unwrap()).collect();
    let r = run(&args);
    println!("{} {}", r.0, r.1);
}


Measured memory_bytes: 508
n = int(raw_input())
for _ in range(n):
    xa,ya,ra,xb,yb,rb = map(float, raw_input().split())
    d = ((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb))
    sr = ((ra + rb) * (ra + rb))
    dr = ((ra - rb) * (ra - rb))
    if d > sr:
        print 0
    elif (d < sr and dr < d):
        print 1
    elif dr > d:
        if ra > rb:
            print 2
        else:
            print -2
    else:
        print 1

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;



// Build "penalty" graph
// We sum up all positive values, but we then have to compute the penalty of doing so
// If there was a negative value removed, the penalty is either the positive values that we wrongly took
// For example, in the case of [-10, 3, 1], -10 was deleted, but now we have to pay back penalty of 3+1
// Or, if negative value was smaller than positive, we should incur this cost
// For example, [-1, 6, 7], we need to give back our debt of -1, which will be reflected in the penalty graph.

const int maxn = 110;
const ll inf = 1e18;

struct edge {
    ll to, cost, cap, rev;
};

struct min_cost_max_flow {

    int n;
    vector<vector<edge>> g;
    min_cost_max_flow(int n) {
	this->n = n;
	g.resize(n);
    }


    void add_edge(ll from, ll to, ll ecost, ll ecap) {
	assert(from>=0 && from<n);
	assert(to>=0 && to<n);

	edge fwd = { to, ecost, ecap, int(g[to].size()) };
	edge bak = { from, -ecost, 0, int(g[from].size()) };

	g[from].push_back(fwd);
	g[to].push_back(bak);
    }



    void sp(ll source, vector<ll>& dist, vector<pair<ll,ll>>& par) {
	dist.resize(n, inf);
	par.resize(n);
	dist[source] = 0;
	vector<bool> inq(n, false);
	queue<ll> qq;
	qq.push(0);
	while (!qq.empty()) {
	    ll at = qq.front();
	    qq.pop();
	    inq[at] = false;
	    for (int i=0; i<(int)g[at].size(); i++) {
		edge &ed = g[at][i];
		ll to = ed.to;
		if (ed.cap > 0 && dist[to] > dist[at] + ed.cost) {
		    dist[to] = dist[at] + ed.cost;
		    par[to] = {at, i};
		    if (!inq[to]) {
			inq[to] = true;
			qq.push(to);
		    }
		}
	    }
	}
    }

    pair<ll, ll> compute(int source, int sink, ll k=inf) {
	ll mincost = 0;
	ll maxflow = 0;
	
	while (maxflow < k) {
	    vector<ll> dist;
	    vector<pair<ll,ll>> par;
	    sp(source, dist, par);

	    
	    if (dist[sink] == inf) {
		break;
	    }

	    ll f = k - maxflow;
	    ll at = sink;
	    while (at != source) {
		ll to = par[at].first;
		ll id = par[at].second;
		f = min(f, g[to][id].cap);
		at = to;
	    }

	    at = sink;
	    while (at != source) {
		ll to = par[at].first;
		ll id = par[at].second;
		mincost += f*g[to][id].cost;
		g[to][id].cap -= f;
		ll revid = g[to][id].rev;
		g[at][revid].cap += f;
		at = to;
	    }
	    maxflow += f;
	}

	return make_pair(mincost, maxflow);
    }
};


int n;
ll a[maxn];


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

    cin>>n;
    for (int i=1; i<=n; i++) {
	cin>>a[i];
    }
    int S = 0;
    int T = n+1;
    min_cost_max_flow flow(n+2);


    ll psum = 0;

    for (int i=1; i<=n; i++) {
	if (a[i]<=0) {
	    flow.add_edge(S, i, 0, -a[i]);
	} else {
	    psum += a[i];
	    flow.add_edge(i, T, 0, a[i]);
	}

	for (int j=i+i; j<=n; j+=i) {
	    flow.add_edge(i, j, 0, inf);
	}
    }


    pair<ll,ll> res = flow.compute(S, T);
    ll mincut = res.second;

    // watch(psum);
    // watch(mincut);

    out(psum - mincut);
    return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>
 
#define N 8
#define FREE 1
#define NOT_FREE -1
 
void putQueen(int);
void printBoard(void);
 
int Q[N][N];
int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
 
int main() {
    int i,j,k,a,b;
     
    for(i=0; i<N; i++) {
        for(j=0; j<N; j++)
	  Q[i][j] = 0;
    }
    scanf("%d",&k);
    
    for(i=0; i<k; i++) {
        scanf("%d%d",&a,&b);
        Q[a][b] = FREE;
    }
     
    for(i=0; i<N; i++) {
        row[i] = FREE;
        col[i] = FREE;
    }
     
    for(i=0; i<20; i++) {
        dpos[i] = FREE;
        dneg[i] = FREE;
    }
     
    putQueen(0);
    return 0;
}
 
 
void putQueen(int i) {
    int j;
     
    if(i==N) {
        printBoard();
        return;
    }
     
    for(j=0; j<N; j++) {
        if(col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1]==NOT_FREE) continue;
 
        row[i] = j;
        col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
	putQueen(i+1);
	row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
    }
}
 
void printBoard() {
    int i,j;
     
    for(i=0; i<N; i++) {
        for(j=0; j<N; j++) {
            if(Q[i][j]) {
                if(row[i]!=j) return;
            }
        }
    }
     
    for(i=0; i<N; i++) {
        for(j=0; j<N; j++) {
            if(row[i]==j) printf("Q");
            else printf(".");
        }
        printf("\n");
    }
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int dp[3][n];
    cin>>dp[0][0]>>dp[1][0]>>dp[2][0];
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>dp[j][i];
            dp[j][i]+=max(dp[(j+1)%3][i-1] , dp[(j+2)%3][i-1]);
        }
    }
    cout<<max({dp[0][n-1] , dp[1][n-1] , dp[2][n-1]});
}

Measured memory_bytes: 4748
//
//  main.cpp
//  ProgrammingContestChallengeBook2
//
//  Created by Hisaki Kobayashi on 2020/04/04.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string>
#include <bits/stdc++.h>
#include <stdlib.h>
//#include "mylibrary.hpp"



using namespace std;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 2000001
#define vmax 10000
constexpr ll inf = 100000000000000;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

int main() {
  ll n,m,ans=0;
  cin>>n>>m;
  vector<int> x1(n,0),y1(n,0),x2(m,0),y2(m,0);
  for(int i=0;i<n;i++){
      cin>>x1[i]>>y1[i];
    }
    for(int i=0;i<m;i++){
        cin>>x2[i]>>y2[i];
    }
    for(int i=0;i<n;i++){
        int l=INT_MAX;
        for(int j=0;j<m;j++){
            if(l>(abs(x1[i]-x2[j])+abs(y1[i]-y2[j]))){
                l=(abs(x1[i]-x2[j])+abs(y1[i]-y2[j]));
                ans=j;
            }
        }
        cout<<ans+1<<endl;
    }
    return 0;
}











Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
const int INF = 1e9;
const int MXN = 0;
const int MXV = 0;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i != (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);

int f(int n)
{
    if(n < 2){
        return 0;
    }
    return n * (n - 1) / 2;
}

int main()
{
    IOS;
    int n, m;
    cin >> n >> m;
    cout << f(n) + f(m) << '\n';
}


Measured memory_bytes: 256