akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b, bool equal = false){
    if(a < b || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b, bool equal = false){
    if(b < a || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

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

    string s;
    cin >> s;

    string t[2] = {"RUD", "LUD"};

    bool flag = true;
    rep(i, s.size()){
        bool ok = false;
        rep(j, 3){
            if(s[i] == t[i & 1][j]){
                ok = true;
            }
        }
        flag &= ok;
    }

    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main()
{
    int n;
    cin >> n;
    vector<int> h(n + 1);
    h[0] = 0;
    rep(i, n)
    {
        cin >> h[i + 1];
    }

    int result = 0;
    rep(i, n)
    {
        result += max(0, h[i + 1] - h[i]);
    }

    cout << result << endl;

    return 0;
}

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

int main() {
  int A, B, sum=0;
  int d1, d2, d4, d5;
  
  cin >> A >> B;
  
  int i = (A/100 * 100)+((A/1000 % 10)*10)+(A/10000);
  if ( i < A ) i+=100;
  
  int i2 = (i/100) % 100;
  while ( i <= B ) {
    sum++;
    
    i += 100;
    i2++;
    
    if ( !(i2 % 10) ) {
      i += 10;
      
      if ( !(i2 % 100) ) {
        i -= 100;
        i += 1;
      }
    }
  }
  cout << sum << endl;
}


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



int main(){
        int n;
        cin >> n;
        string s;
        cin >> s;
        int ans = 0;
        for(int i=0;i<n;i++){
                string now = s.substr(i);
                //cout << now << endl;
                vector<int> a(n-i,0);
                int c = 0;
                for(int j=1;j<now.size();j++){
                        if(j + a[j-c] < c + a[c]){
                                a[j] = a[j-c];
                        }
                        else{
                                int k = max(0,c+a[c]-j);
                                while(j+k < now.size() && now[k] == now[j+k]) k ++;
                                a[j] = k;
                                c = j;
                        }
                        int res = min(a[j],j);
                        ans = max(ans,res);
                }
        }
        cout << ans << endl;
    

        return 0;
}






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

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    char c;
    cin >> c;
    if(c%97<=26)
    {
        cout << 'a';
    }
    else
    {
        cout << 'A';
    }
    
    return 0;
}




Measured memory_bytes: 3604
#include <bits/stdc++.h> 
using namespace std; 
  
int main() 
{  int a,b,c,d;
   cin>>a>>b>>c>>d;
   while(a>0||c>0){
       c=c-b;
       if(c<=0){
        cout<<"Yes";
       break;}
       a=a-d;
       if(a<=0){
        cout<<"No";
           break;
       }
   }
    return 0; 
} 

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vec> mat;
int main(){
    ll x,y;
    cin>>x>>y;
    if(abs(x-y)>1) cout<<"Alice";
    else cout<<"Brown";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d", &n);
	n %= 10;
	switch(n){
		case 2:
			printf("hon");
			break;
		case 4:
			printf("hon");
			break;
		case 5:
			printf("hon");
			break;
		case 7:
			printf("hon");
			break;
		case 9:
			printf("hon");
			break;
		case 0:
			printf("pon");
			break;
		case 1:
			printf("pon");
			break;
		case 6:
			printf("pon");
			break;
		case 8:
			printf("pon");
			break;
		case 3:
			printf("bon");
			break;
	}   
	return 0;                                                 
}

Measured memory_bytes: 3724
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let (N, K) = get!(usize, usize);
    let MOD: usize = 1000000007;

    // floor(N / i) の値に応じてグループ分けし、
    // グループ単位で条件を満たす列の個数を動的計画法で求める
    let P = (N as f64).sqrt() as usize;
    let Q = N / P;
    let R = P + Q;
    let C = (0..R).map(|i|
        if i <= P {
            1
        } else {
            N / (R - i) - N / (R - i + 1)
        }
    ).collect::<Vec<_>>();
    let mut dp = vec![vec![0; R]; K];
    for i in 0..R {
        dp[0][i] = C[i];
    }
    for j in 1..K {
        let mut acc = 0;
        for i in (1..R).rev() {
            acc = (acc + dp[j - 1][R - i]) % MOD;
            dp[j][i] = (C[i] * acc) % MOD;
        }
    }
    let ans: usize = dp[K - 1].iter().sum::<usize>() % MOD;

    println!("{}", ans);
}


Measured memory_bytes: 71932
// author: Saman Mahdanian
#include <bits/stdc++.h>

using namespace std;
const int N = 5e5 + 10;
const int MOD = 1e9 + 7;

int _sum (int, int);
int _mul (int, int);
int _pow (int, int);
int gcd (int, int);

int dp[N][3];

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

	string s;
	cin >> s;
	int n = s.size();
	dp[0][0] = dp[0][1] = 1;
	dp[0][int(s[0] - '0')] = 0;
	for (int i = 1; i < n; i++)
		for (int c: {0, 1})
			dp[i][c] = dp[i - 1][1 ^ c] + (s[i] == '0' + c? 0 : 1);
	cout << min(dp[n - 1][0], dp[n - 1][1]) << endl;
}

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

// int choose (int r, int k) {
// 	return _mul (f[k], _mul(inv[r], inv[k - r]));
// }

int _sum (int a, int b) {
	return a + b - (a + b >= MOD? MOD : 0);
}

int _mul (int a, int b) {
	return 1LL * a * b % MOD;
}

int _pow (int a, int b) {
	if (!b) 
		return 1;
	int res = _pow (a, b >> 1);
	res = _mul (res, res);
	if (b & 1)
		res = _mul (res, a);
	return res;
}

// SamMHD :: Jun27-2019 :: Another Day with Shayan...

Measured memory_bytes: 1616
def f(n):
    if n==0:
        return 1
    return 2*f(n-1)+3
def g(n):
    if n==0:
        return 1
    return 2*g(n-1)+1
def F(n,x):
    if n==0:return 1
    if x<=n:return 0
    if x<=f(n-1)+1:
        return F(n-1,x-1)
    elif x==f(n-1)+2:
        return g(n-1)+1
    else:
        return g(n-1)+1+F(n-1,x-f(n-1)-2)
N,X = map(int,input().split())
print(F(N,X))

Measured memory_bytes: 44784
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <map>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1ll << 60

using namespace std;
typedef unsigned long long ll;
typedef pair<int, int> pp;

ll a[3], d;
ll Search(ll n, map<ll, ll> & mp) {
	if (mp.count(n))
		return mp[n];
	ll i, ans = INF, k[3] = { 2, 3, 5 };
	rep(i, 3) {
		chmin(ans, Search(n / k[i], mp) + a[i] + (n % k[i]) * d);
		if (n % k[i])
			chmin(ans, Search(n / k[i] + 1, mp) + a[i] + (k[i] - (n % k[i])) * d);
	}
	if (d * n / n == d)
		chmin(ans, d * n);
	return mp[n] = ans;
}

int main(void) {
	int i, k, q;
	ll num, ans;
	cin >> q;
	rep(k, q) {
		cin >> num >> a[0] >> a[1] >> a[2] >> d;
		map<ll, ll> mp;
		mp[0] = 0;
		mp[1] = d;
		ans = Search(num, mp);
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 4440
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A=sc.nextInt(),B=sc.nextInt(),C=sc.nextInt();
		final int K=sc.nextInt();
		int k=1;
		for(int i=0;i<K;i++){
			k=k*2;
		}
		if(A>B){
			if(A>C){
				A=A*k;
			}else{
				C=C*k;
			}
		}else{
			if(B>C){
				B=B*k;
			}else{
				C=C*k;
			}
		}
		int ans=A+B+C;
		System.out.println(ans);
	}
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define filename "lynext"
#define freop freopen(filename ".cik","w",stdout);freopen(filename ".gir","r",stdin)
const long long int N = ((long long int)1e5) + 5;
const long long int M = ((long long int)1e3) + 5;
const long long int llinf = (long long int)1e18;
const int inf = INT_MAX;
typedef long long int lli;

lli dp[N];
lli n;
lli h[N];

lli f (lli i)
{
	if (dp[i] != -1)
		return dp[i];
	if (i == n)
		return 0;
	if (i == n - 1)
		return abs(h[n] - h[i]);
	lli t1 = f(i + 1) + abs(h[i] - h[i + 1]);
	lli t2 = f(i + 2) + abs(h[i] - h[i + 2]);
	return dp[i] = min(t1,t2);
}

int main ()
{
	fast;
	//freop;
	cin >> n;
	memset(dp, -1, sizeof dp);
	for (int i = 1; i <= n; i++)
	{
		cin >> h[i];
	}
	cout << f(1) << "\n";
}


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

int main(){
	int W, H, N;
	int x, y, a;

	int x_max, x_min;
	int y_max, y_min;

	cin >> W >> H >> N;

	x_min = 0;
	y_min = 0;
	x_max = W;
	y_max = H;

	for(int i=0; i<N; i++){
		cin >> x >> y >> a;

		if(a == 1){
			if(x_min < x) x_min = x;
		}
		else if(a == 2){
			if(x_max > x) x_max = x;
		}
		else if(a == 3){
			if(y_min < y) y_min = y;
		}
		else if(a == 4){
			if(y_max > y) y_max = y;
		}
	}

	if(x_max-x_min < 0 || y_max-y_min < 0){
		cout << 0 << endl;
		return 0;
	}

	int area = (x_max - x_min)*(y_max-y_min);
	cout << area << endl;
	return 0;
}

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

int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  vector<long long> X(N);
  for (int i = 0; i < N; i++) cin >> X.at(i);
  long long ans = 0;
  for (int i = 1; i < N; i++) {
    ans += min((X.at(i)-X.at(i-1))*A, B);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
w,h,x,y =map(int, input().split())
men=w*h
bun1=x*h
bun2=(w-x)*h
bun3=w*y
bun4=w*(h-y)
if w/2==x and h/2==y:
    ans=1
else:
    ans=0
print(w*h/2, ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,k;
  cin>>h>>w>>k;
  char s[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>s[i][j];
    }
  }
  long long ans=0;
  for(int bit1=0;bit1<(1<<h);bit1++){
    for(int bit2=0;bit2<(1<<w);bit2++){
      long long black=0;
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if(bit1&(1<<i)) continue;
          if(bit2&(1<<j)) continue;
          if(s[i][j]=='#') black++;
        }
      }
      if(black==k) ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3604
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int gcd(int a, int b){
    int g, buf;
    if (a < b){
        buf = b;
        b = a;
        a = buf;
    }
    while (b > 0){
        buf = a % b;
        a = b;
        b = buf;
    }
    return a;
}

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


Measured memory_bytes: 3220
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np
#import bisect

from itertools import product

def main():
	n,m=MI()
	li=[[] for _ in range(8)]

	for _ in range(n):
		a,b,c=MI()
		for i,e in enumerate(product((1,-1),repeat=3)):
			li[i].append(a*e[0]+b*e[1]+c*e[2])

	ans=0

	for l in li:
		l.sort(reverse=True)
		ans=max(ans,sum(l[:m]))
	print(ans)



if __name__ == "__main__":
	main()


Measured memory_bytes: 71712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

int main(){
    ll N, K;
    cin >> N >> K;
    vll h(N);
    rep(i, N){
        cin >> h[i];
    }
    sort(ALL(h));
    ll ans = 1LL << 40;
    rep(i, N-K+1){
        ans = min(ans, h[i+K-1] - h[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iostream>

using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); i++)
#define RFOR(i, a, b)  for(int i = (a); i > (b); i--)
#define rep(i, n)	   for(int i = 0; i < (n); i++)
#define all(c)		   begin(c), end(c)
#define rall(c)		   rbegin(c), rend(c)
#define foritr(itr, c) for(auto itr = begin(c); itr != end(c); itr++)
#define SZ(a)		   ((ll) a.size())

typedef long long int		   ll;
typedef long long unsigned int llu;

void solve(ll A, ll B, ll C) {
	bool t = false;
	rep(i, 100) {
		if(A * i % B == C) t = true;
	}
	if(t) printf("YES");
	else printf("NO");
}

int main() {
	ll A;
	ll B;
	ll C;
	scanf("%lld", &A);
	scanf("%lld", &B);
	scanf("%lld", &C);
	solve(A, B, C);
	return 0;
}


Measured memory_bytes: 256
// 2011/07/27 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int seg[11][7] = {{0,1,1,1,1,1,1},	// eÌf[^
	                  {0,0,0,0,1,1,0},
	                  {1,0,1,1,0,1,1},
	                  {1,0,0,1,1,1,1},
	                  {1,1,0,0,1,1,0},
	                  {1,1,0,1,1,0,1},
	                  {1,1,1,1,1,0,1},
	                  {0,1,0,0,1,1,1},
	                  {1,1,1,1,1,1,1},
	                  {1,1,0,1,1,1,1},
	                  {0,0,0,0,0,0,0}};	// seg[10]Íñ\¦

	while(true){
		int n;
		cin >> n;
		if(n==-1)
			break;

		int now = 10;		// ¡ÌiúlÍñ\¦j
		int nxt;		// Ì
		for(int i=0; i<n; i++){
			cin >> nxt;
			for(int j=0; j<7; j++)
				cout << (seg[now][j]+seg[nxt][j])%2;	// r¼I_a
			cout << endl;
			now = nxt;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define inf (int)(1e18)

int max(int a, int b){
	return a >= b ? a : b;
}

signed main(){
	int N, i, j;
	char sub[2];
	scanf("%lld", &N);
	int *A = (int *)malloc(sizeof(int) * N);
	int *op = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		if(i == 0){
			op[i] = 1;
		}
		else{
			scanf("%s", sub);
			op[i] = (sub[0] == '+' ? 1 : -1);
		}
		scanf("%lld", &A[i]);
	}
	int **dp = (int **)malloc(sizeof(int *) * N);
	for(i = 0; i < N; i++){
		dp[i] = (int *)malloc(sizeof(int) * 3);
		for(j = 0; j < 3; j++){
			dp[i][j] = -inf;
		}
	}
	dp[0][0] = A[0];
	for(i = 1; i < N; i++){
		if(op[i] == 1){
			dp[i][0] = max(max(dp[i - 1][0] + A[i], dp[i - 1][1] - A[i]), dp[i - 1][2] + A[i]);
			dp[i][1] = max(dp[i - 1][1] - A[i], dp[i - 1][2] + A[i]);
			dp[i][2] = dp[i - 1][2] + A[i];
		}
		else{
			dp[i][0] = max(max(dp[i - 1][0] - A[i], dp[i - 1][1] + A[i]), dp[i - 1][2] - A[i]);
			dp[i][1] = max(max(dp[i - 1][1] + A[i], dp[i - 1][2] - A[i]), dp[i - 1][0] - A[i]);
			dp[i][2] = max(dp[i - 1][2] - A[i], dp[i - 1][1] + A[i]);
		}
	}
	printf("%lld\n", dp[N - 1][0]);
	return 0;
}

Measured memory_bytes: 5632
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto N = readln.chomp.to!int;
    auto E = new Tuple!(int, int)[](N-1);
    auto G = new Tuple!(int, int)[][](N);
    foreach (i; 0..N-1) {
        auto s = readln.split.map!(to!int);
        G[s[0]-1] ~= tuple(s[1]-1, i);
        G[s[1]-1] ~= tuple(s[0]-1, i);
        E[i] = tuple(s[0]-1, s[1]-1);
    }
    auto S = readln.split.map!(to!long).array;

    if (N == 2) {
        writeln(S[0]);
        return;
    }
    
    auto depth = new int[](N);
    auto sub = new int[](N);
    auto ans = new long[](N-1);
    
    int dfs(int n, int p, int d) {
        depth[n] = d;
        foreach (m; G[n]) if (m[0] != p) sub[n] += dfs(m[0], n, d+1);
        return sub[n] + 1;
    }
    dfs(0, -1, 0);

    long dfs2(int n, int p, long d) {
        long ret = d;
        foreach (m; G[n]) if (m[0] != p) ret += dfs2(m[0], n, d+ans[m[1]]);
        return ret;
    }

    foreach (i, e; E.enumerate) {
        int a = e[0];
        int b = e[1];
        if (S[a] == S[b]) continue; 
        if (depth[a] > depth[b]) swap(a, b);
        long aa = sub[b];
        long bb = N - sub[b] - 2;
        ans[i] = (S[a] - S[b]) / (aa - bb);
    }

    foreach (i, e; E.enumerate) {
        int a = e[0];
        int b = e[1];
        if (S[a] != S[b]) continue;
        if (depth[a] > depth[b]) swap(a, b);
        long aa = dfs2(a, b, 0);
        long bb = dfs2(b, a, 0);
        long ss = aa + bb;
        ans[i] = (S[a] - ss) / (sub[b] + 1);
    }

    ans.each!writeln;
}


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

using namespace std;

int main() {
string S; 
long long k;
cin >> S >> k;	
for(int i = 0; i < min((long long) S.size(), k); i++){
	if(S[i] >= '2'){
		cout << S[i] << endl;
		return 0;
	}
}
	cout << 1 << endl;
}


Measured memory_bytes: 3576
#include <iostream>

#define MOD 1000000007

int main(void) {
    int N;
    std::cin >> N;
    unsigned long long* reads = new unsigned long long[N];
    unsigned long long rightSum = 0;
    for(int i = 0; i < N; ++i){
        std::cin >> reads[i];
        rightSum += reads[i];
    }
    unsigned long long result = 0;
    for(int i = 0; i < N-1; ++i){
        rightSum -= reads[i];

        result = (result + reads[i] * (rightSum % MOD)) % MOD;
    }

    std::cout << result << std::endl;

    delete[] reads;
}

Measured memory_bytes: 4816
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	while (N > 0) {
		N -= 1000;
	}

	int ans = -N;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int D = line[0], N = line[1];

            switch (D)
            {
                case 0:
                    Console.WriteLine(N == 100 ? N + 1 : N);
                    break;
                case 1:
                    Console.WriteLine(N == 100 ? 100 * N + 100 : 100 * N);
                    break;
                case 2:
                    Console.WriteLine(N == 100 ? 10000 * N + 10000 : 10000 * N);
                    break;
                default:
                    break;
            }
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include<bitset>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); ++i)
#define loops(i,f,n) for(int i = (f); i < (n); ++i)
#define INF 9999999
#define lint long long int
#define VEC vector<int>
#define VEC2 vector<vector<int>>

bool isObstacle[10005][4];
int dp[20005][1 << 4];



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, n;
	cin >> h >> n;
	loop(i, n)
	{
		int x, y;
		cin >> y >> x;
		isObstacle[h - x - 1][y] = true;
	}
	loop(i, h - 1)
	{
		loop(j, 1 << 4) {
			dp[i + 1][0] = max(dp[i + 1][0], dp[i][j]);
			loop(k, 3) {
				if (!(j >> k & 1) && !(j >> (k + 1) & 1) && !isObstacle[i][k] && !isObstacle[i][k + 1] && !isObstacle[i + 1][k] && !isObstacle[i + 1][k + 1]) {
					dp[i + 1][(1 << k) | (1 << (k + 1))] = max(dp[i + 1][(1 << k) | (1 << (k + 1))], dp[i][j] + 1);
				}
			}
			if (j == 0) {
				bool flag = true;
				loop(k, 2)
				{
					loop(t, 4) {
						if (isObstacle[i + k][t] == 1)flag = false;
					}
				}
				if (flag) {
					dp[i + 1][(1 << 4) - 1] = max(dp[i + 1][(1 << 4) - 1], dp[i][j] + 2);
				}
			}
		}
	}
	int ans = 0;
	loop(i, 1 << 4) {
		ans = max(ans, dp[h - 1][i]);
	}
	cout << ans << endl;
}


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

int main(){

	int a, b, c;
	cin >> a >> b >> c;
  	if(a>=c&&a>=b)cout << b+c <<endl; 
	else if(b>=c&&b>=a)cout << c+a <<endl; 
    else if(c>=b&&c>=a)cout << a+b <<endl; 

}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
from decimal import Decimal

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B = sl()
    A = int(A)

    # Bを整数部と小数部に分けて
    # 100倍した整数に変換する。
    b, bb = B.split('.')
    B = int(b) * 100 + int(bb)

    print((A * B) // 100)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10704
def solve(lr):
    L, R = lr
    ans = 2018
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            x = i * j % 2019
            if x == 0:
                return 0
            if x < ans:
                ans = x
    return ans

print(solve(tuple(int(i) for i in input().split())))

Measured memory_bytes: 3060
def main():
    N = int(input())
    num_list = set()
    for i in range(1,N+1):
        tmp = N - i
        if i == tmp or tmp == 0:
            continue
        else:
            num_list.add((i,tmp))

    if len(num_list) % 2 == 0:
        print(len(num_list) // 2)
    else:
        print(len(num_list) // 2 + 1)



if __name__ == "__main__":
    main()

Measured memory_bytes: 101580
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

    vector<int> a(n + 1), b(n);
    for (int i = 0; i < n + 1; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        cin >> b[i];

    long long cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (b[i] <= a[i])
            cnt += b[i];
        else
        {
            cnt += a[i];
            b[i] -= a[i];
            if (b[i] <= a[i + 1])
            {
                cnt += b[i];
                a[i + 1] -= b[i];
            }
            else
            {
                cnt += a[i + 1];
                a[i + 1] = 0;
            }
        }
    }
    cout << cnt;
}

Measured memory_bytes: 4060
import sys
input=sys.stdin.readline
n=int(input())
a=[int(input()) for _ in range(n)]
if a[0]!=0:
    print(-1)
    exit()

ans=0
for i in range(1,n):
    if a[i]>a[i-1]+1:
        print(-1)
        exit()
    if a[i]==a[i-1]+1:
        ans+=1
    else:
        ans+=a[i]

print(ans)


Measured memory_bytes: 50396
#include<bits/stdc++.h>
using namespace std;
int main(){
	int A,B;
	cin>>A>>B;
	if(A==B)
	cout<<"Draw";
    else if((A==1)||(A>B)&&(B!=1))
	cout<<"Alice";
	else if((B==1)||(A<B)&&(A!=1))
	cout<<"Bob";

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

const std::vector<int> dx{-1, 1, 0, 0}, dy{0, 0, -1, 1};

void solve() {
    int n;
    std::cin >> n;
    int m = n * n;

    auto enc = [&](int k) {
        return std::make_pair(k / n, k % n);
    };

    auto dist = vec(n, vec(n, 0));
    for (int x = 0; x < n; ++x) {
        for (int y = 0; y < n; ++y) {
            dist[x][y] = std::min({x, n - x - 1, y, n - y - 1});
        }
    }

    auto erased = vec(n, vec(n, false));
    int ans = 0;

    for (int i = 0; i < m; ++i) {
        int p;
        std::cin >> p;
        auto [sx, sy] = enc(--p);
        ans += dist[sx][sy];

        std::queue<std::pair<int, int>> que;
        erased[sx][sy] = true;
        que.emplace(sx, sy);

        while (!que.empty()) {
            auto [x, y] = que.front();
            que.pop();

            int cost = (erased[x][y] ? 0 : 1);

            for (int j = 0; j < 4; ++j) {
                int nx = x + dx[j],
                    ny = y + dy[j];

                if (nx < 0 || n <= nx ||
                    ny < 0 || n <= ny ||
                    dist[nx][ny] != dist[x][y] + cost + 1) continue;

                dist[nx][ny] = dist[x][y] + cost;
                que.emplace(nx, ny);
            }
        }
    }

    std::cout << ans << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 4680
N, M = map(int,input().split())

if N >= M:
  print(0)
  exit()
  
X = list(map(int,input().split()))
X.sort()

dif = {}
for i in range(M-1):
  dif[i] = X[i+1]-X[i]
  
sorted_dif = sorted(dif.items(), key=lambda x:x[1], reverse=True)
difs = 0
for i in range(N-1):
  difs += sorted_dif[i][1]

print(X[-1]-X[0]-difs)

Measured memory_bytes: 24484
import java.util.Scanner;

public class Main {
    final static int M = 200005;
    static long[] f = new long[M];
    static int[] a = new int[M];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long ans = 0;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            f[a[i]]++;
        }
        for (int i = 0; i < M; i++) {
            if (f[i] != 0) ans += f[i] * (f[i] - 1) / 2;
        }
        for (int i = 0; i < n; i++) {
            System.out.println(ans -  f[a[i]] + 1);

        }
    }
}


Measured memory_bytes: 100500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  string s; cin >> s;
  int q; cin >> q;
  bool rev = false;

  for (int i = 0; i < q; i++) {
    int t, f;
    string c;

    cin >> t;

    if (t == 1) {
      rev = !rev;
    } else {
      cin >> f >> c;

      if ((f == 1 && rev) || (f == 2 && !rev)) {
        s.append(c);
      } else if ((f == 1 && !rev) || (f == 2 && rev)) {
        s.insert(0, c);
      }
    }
  }

  if (rev) reverse(s.begin(), s.end());

  cout << s << endl;
}

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

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


Measured memory_bytes: 3112
s=input()
n=len(s)
for i in range(1,n):
    if s[i]==s[i-1]:
        print(i,i+1)
        exit()

for i in range(2,n):
    if s[i]==s[i-2]:
        print(i-1,i+1)
        exit()

print(-1,-1)


Measured memory_bytes: 39408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int a = 1;
    for (int i = 0; i < n; i++) {
        if (a < k) {
            a *= 2;
        }
        else a += k;
    }
    cout << a << endl;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
typedef long long int ll;
const int INF = 1 << 30;
using namespace std;
#define pp pair<int,int>
#define FOR(i,a,n) for(int i=(ll)a;i<(ll)n;++i)
#define TFOR(i,n)FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
int main() {
	ll n, sum = 0;
	cin >> n;
	TFOR(i, n)sum += (i + 1);
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, A, B;
  cin >> N >> A >> B;
  const int64_t d = abs(A - B);
  int64_t result;
  if (d % 2LL == 0) {
    result = d / 2L;
  } else {
    const int64_t x = (A - 1LL + B - 1LL + 1LL) / 2LL;
    const int64_t y = ((N - A) + (N - B) + 1) / 2LL;
    result = min(x, y);
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

//COMinit()をmain関数の中で行う！
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    COMinit();
    vector<ll> c(2010ll,1ll);
    Rep(i,2005){
        c[i+1] = (i+1)*c[i];
        c[i+1] %=INF;
    }
    Rep(i,k){
        ll x = COM(k-1,i) * COM(n-k+1,i+1);
        x %=INF;
        cout << x << endl; 
    }
}

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

if sum(A) < sum(B):
    print(-1)
else:
    dif = [a - b for a, b in zip(A, B)]
    negative = [d for d in dif if d < 0]
    neg_sum = - sum(negative)
    ans = len(negative)
    positive = sorted([d for d in dif if d >= 0], reverse=True)
    i = 0
    while neg_sum > 0:
        neg_sum -= positive[i]
        i += 1
        ans += 1
    print(ans)

Measured memory_bytes: 18292
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
map<string,int>dp;
int DP(string s){
	if(s.empty())return 1;
	if(dp.count(s))return dp[s];
	int res=1LL*(1+(s[0]=='1'))*DP(s.substr(1))%mod;
	for(int i=1;i<s.size();++i){
		for(int j=i*2;j<=s.size();j+=i){
			string t(i,'1');
			for(int k=0;k<j;k+=i){
				for(int l=k;l<k+i;++l){
					t[l-k]=min(t[l-k],s[l]);
				}
			}
			res=(res+1LL*DP(t)*DP(s.substr(j))%mod)%mod;
		}
	}
	return dp[s]=res;
}
int main(){
	string s;cin>>s;
	cout<<DP(s)<<endl;
	return 0;
}

Measured memory_bytes: 5632
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        for (int i = 0; i < h; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < w; j++) {
                if (i < b) {
                    if (j < a) {
                        sb.append('0');
                    } else {
                        sb.append('1');
                    }
                } else {
                    if (j < a) {
                        sb.append('1');
                    } else {
                        sb.append('0');
                    }
                }
            }
            System.out.println(sb);
        }
    }
}



Measured memory_bytes: 41768
#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
#include <cctype>
#include <string>
#include <algorithm>
#include <cmath>
typedef unsigned long long ll;
using namespace std;
int main(){
	ll N;
	cin>>N;
	ll b,c;
	ll preresult = 0;
	ll prevb, prevc  =0;
	ll result =0;
	cin>>b>>c;
	result = b+c;
	prevb = b;
	prevc = c;
	preresult = result;
	for(ll i=1;i<N;i++){
		cin>>b>>c;
		ll d = b+c;

		ll x;
		if (result % d==0)
			x = result/d;
		else
		 	x  =(result/d)+1;
		ll x1 = (preresult/(prevb+prevc))*prevb;
		if (x1 % b ==0 )
			x1 = x1/b;
		else 
			x1 = x1/b +1;
		//cout<<"??"<<x1<<" "<<preresult<<" "<<prevb<<" "<<prevc<<endl;
		ll x2 = (preresult/(prevb+prevc))*prevc;
		//x2 = (ll)ceil(x2/(c*1.0));
		if (x2 % c ==0 )
			x2 = x2/c;
		else 
			x2 = x2/c +1;
		x = max(max(x,x1),x2);
		//cout<<"!!"<<b<<" "<<c<<" "<<x1<<" " << x2<<" "<<x<<endl;
		result = x*d;
		//cout<<result<<endl;
		prevb = b;
		prevc = c;
		preresult = result;
		
	}
	cout<<result<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 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; }
const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long K, std::vector<long long> A){
    REP(i, N-K){
        if(A[K+i] > A[i]) cout<<YES<<endl;
        else cout<<NO<<endl;    
    }
}
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, K, std::move(A));
    return 0;
}


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

int main(){
    char kalimat[100];
    int limit;
 
    scanf("%d\n%[^\n]", &limit, &kalimat);
    int length = strlen(kalimat);
       if(length <= limit){
        printf("%s", kalimat);
        } else {
            for(int a = 0; a < limit; a++){
            printf("%c", kalimat[a]);
            
        } 
    puts("...");
        }
    return 0;
}

Measured memory_bytes: 1728
n,k=map(int,input().split())
P=list(map(int,input().split()))

S=[0]
for i in range(n):
   S.append(S[i]+P[i])
ans=0
for j in range(n-k+1):
   ans=max(ans,(S[j+k]-S[j]))

print((ans+k)/2)

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

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] ia;

        while(true){
            ia = in.readLine().split(" ");
            int a = Integer.parseInt(ia[0]);
            int L = Integer.parseInt(ia[1]);
            if(a == 0 && L == 0){
                break;
            }
            int now = a;
            TreeMap<Integer, Integer>tm = new TreeMap<Integer, Integer>();
            tm.put(a,0);
            for(int i = 1;;++i){
                char[] tmp = (new Integer(a)).toString().toCharArray();
                Arrays.sort(tmp);
                StringBuffer sb = (new StringBuffer()).append(tmp);
                int small = Integer.parseInt(sb.toString());
                sb = sb.reverse();
                while(sb.length() < L){
                    sb.append('0');
                }
                int large = Integer.parseInt(sb.toString());
                Integer old;
                if((old = tm.get(large-small)) != null){
                    System.out.println("" + old + " " + (large-small) + " " + (i - old));
                    break;
                } else {
                    tm.put(large-small, i);
                    a = large-small;
                }
            }
        }
    }
}

Measured memory_bytes: 20332
z=[]
10.times{
  z.push([0,0,0,0,0,0,0,0,0,0])
}
while n=gets
  x,y,s=n.split(",").map(&:to_i)
      z[x][y]+=1
      z[x-1][y]+=1 if x>0
      z[x+1][y]+=1 if x<9
      z[x][y-1]+=1 if y>0
      z[x][y+1]+=1 if y<9
      z[x+1][y+1]+=1 if x<9 && y<9 && s>1
      z[x+1][y-1]+=1 if x<9 && y>0 && s>1
      z[x-1][y+1]+=1 if x>0 && y<9 && s>1
      z[x-1][y-1]+=1 if x>0 && y>0 && s>1
      z[x-2][y]+=1 if x>1 && s>2
      z[x+2][y]+=1 if x<8 && s>2
      z[x][y-2]+=1 if y>1 && s>2
      z[x][y+2]+=1 if y<8 && s>2
end

x=0
y=0
zMax=0
sum=0
10.times{|x|
  10.times{|y|
    zMax = z[x][y] if z[x][y] > zMax
    sum+=1 if z[x][y] == 0
  }
}
p sum
p zMax


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

int main(){
    int N;cin>>N;
    int abc[N][3];

    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++)cin>>abc[i][j];
    }
    int dp[N+1][3];
    dp[0][0]=0;
    dp[0][1]=0;
    dp[0][2]=0;

    for(int i=1;i<=N;i++){
        dp[i][0]=abc[i-1][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=abc[i-1][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=abc[i-1][2]+max(dp[i-1][1],dp[i-1][0]);
    }
    cout<<max({dp[N][0],dp[N][1],dp[N][2]})<<endl;
    }

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  int j, k, l;
  j = 0;
  k = 0;
  l = 0;
  while(j < N){
    if(vec.at(l) == 2){
      cout << k + 1 << endl;
      break;
    }
    else{
      l = vec.at(l) - 1;
      k += 1;
      j += 1;
    }
  }
  if(j >= N){
    cout << -1 << endl;
  }
}

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

bool check(char ch, string s) {
  for(int i=0; i<s.size(); i++) {
    if(s.at(i)==ch) {
      if(i+1<s.size()) {
	if(s.at(i+1)==ch) {
	  cout << i+1 << " " << i+2 << endl;
	  return true;
	}
      }
      if(i+2<s.size()) {
	int cnt = 0;
	if(s.at(i+1)==ch) cnt++;
	if(s.at(i+2)==ch) cnt++;
	if(cnt>0) {
	  cout << i+1 << " " << i+3 << endl;
	  return true;
	}
      }
    }
  }
  return false;
}

int main() {
  string s;
  cin >> s;
  set<char> charset;
  for(int i=0;i<s.size(); i++) {
    charset.insert(s.at(i));
  }
  for(char ch : charset) {
    if(check(ch, s)) {
      return 0;
    }
  }
  cout << "-1 -1" << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<iomanip>
#include<queue>
#include<cmath>
#include<stack>
#include <map>
#define ll                   long long
#define skip                 cin>>ws;
#define vll                  vector<ll> 
#define vb                   vector<bool>
#define vpll                 vector<pair<ll,ll>>
#define vvll                 vector<vector<ll>>
#define pll                  pair<ll,ll>
#define vs                   vector<string>
#define vvpll                vector<vector<pair<ll, ll>>>
#define pb                   push_back
#define pob                  pop_back()
#define MOD                  (ll)(1e9 + 7)
#define INF                  (ll)(1e18 + 5)
#define count1(n)            __builtin_popcountll(n)
#define                      test ll t; cin>>t; while(t--)

using namespace std;

void enter(vll &ar)
{
    ll n = ar.size();
    for(ll i=0;i<n;i++) cin>>ar[i];
}

void show(vll &a)
{
    ll n = a.size();
    for(ll i=0;i<n;i++) cout<<a[i]<<" ";
    cout<<"\n";
}

void SieveOfErat1sthenes(ll n, vll &pri) 
{ 
    vb prime(n+1, true); 
   
    for (ll p=2; p*p<=n; p++) 
    { 
        
        if (prime[p] == true) 
        { 
            pri.pb(p);
            
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll mo(ll a)
{
    return a%MOD;
}

ll maxn, n;
vvll mat;
vvll dp;

ll solve(ll mask, ll l)
{
    if(mask==maxn) return 1;
    if(l>=n) return 0;

    if(dp[mask][l]!=-1) return dp[mask][l];
    ll res = 0; 

    for(ll i=0;i<n;i++)
    {
        if(mask&(1<<i)) continue;

        if(mat[l][i])
        {
            res = mo(mo(res) + mo(solve(mask|(1<<i), l+1)));
        }
    }

    return dp[mask][l] = mo(res);
}

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

    cin>>n;
    maxn = (1<<n) - 1;
    dp.assign(maxn, vll(n, -1));

    mat.resize(n, vll(n, 0));

    for(ll i=0;i<n;i++) for(ll j=0;j<n;j++) cin>>mat[i][j];

    ll ans = solve(0, 0);
    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 412932