akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n;
int pp[100100];

ll d[100010];

void dijkstra(int start) {
	fill(d, d + 100010, INF);
	d[start] = 0;

	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, start));

	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		if (pp[v] == 0) {
			for (int i = 1; i <= 6; i++) {
				int nv = min(n - 1, v + i);
				if (d[nv] > p.first + 1) {
					d[nv] = p.first + 1;
					que.push(P(d[nv], nv));
				}
			}
		}
		else {
			int nv = min(n - 1, v + pp[v]);
			if (d[nv] > p.first) {
				d[nv] = p.first;
				que.push(P(d[nv], nv));
			}
		}
	}
}


int main() {
	cin >> n;
	rep(i, n) {
		cin >> pp[i];
	}
	dijkstra(0);
	cout << d[n - 1] << endl;
}


Measured memory_bytes: 4288
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

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

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    string digit4;
    cin >> digit4;
    int A,B,C,D;
    A = digit4[0]-'0';
    B = digit4[1]-'0';
    C = digit4[2]-'0';
    D = digit4[3]-'0';
    for (int bit = 0; bit < (1<<3); bit++) {
        int a=A;
        int b=B;
        int c=C;
        int d=D;
        bool op1_is_p = bit & 1;
        bool op2_is_p = bit & (1<<1);
        bool op3_is_p = bit & (1<<2);

        if (op1_is_p) b*=-1;
        if (op2_is_p) c*=-1;
        if (op3_is_p) d*=-1;

        if (a+b+c+d == 7) {
            cout << a;
            if (b>=0) cout << "+";
            cout << b;
            if (c>=0) cout << "+";
            cout << c;
            if (d>=0) cout << "+";
            cout << d;
            cout << "=7" << endl;
            return 0;
        }
    }

    return 1;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <vector>
#include <stack>
#include <set>
using namespace std;
typedef unsigned long long ll;
const int maxn=2e5+50;
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;
const int HASH=131;

int num[maxn];
int root[maxn];
int FIND(int x)
{
	return root[x]==x?x:root[x]=FIND(root[x]);
}

void hb(int x,int y)//合并
{
	int xx=FIND(x);
	int yy=FIND(y);
	if(xx!=yy)
	{
		root[xx]=yy;
	}
}

int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        root[i]=i;
    for(int i=1;i<=m;i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        if(a>b) swap(a,b);
        hb(a,b);
    }
    for(int i=1;i<=n;i++)
    {
        num[FIND(i)]++;
    }
    sort(num,num+maxn);
    printf("%d\n",num[maxn-1]);

    return 0;
}


Measured memory_bytes: 11452
s = gets.chomp.chars.map(&:to_i)

results = []
len = s.count - 1
(2**len).times do |n|
  p = n.to_s(2).rjust(len, '0').chars.map { |i| i == '1' ? '+' : nil }
  results << eval(s.zip(p).flatten.compact.join(''))
end
puts results.inject(:+)

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define MAX 300005
#define INF 1000005
#define endl "\n"
int arr[MAX];
int main(){
    lli N;
    cin>>N;
    cout<<(1000-N%1000)%1000<<endl;
    
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main() {
  int top=0;
  string input="", output="";
  vector<string> vec(10);
  cin >> input;

  for (int i=0; i<input.size(); i++)
  {
    switch (input[i])
    {
    case '0':
      vec.at(top++) = '0';
      break;
    case '1':
      vec.at(top++) = '1';
      break;
    case 'B':
      if(top!=0) top--;
      break;
    }
  }

  for (int i=0; i<top; i++) output += vec.at(i);

  cout << output << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)

ll binpowmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return binpowmod(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double n,i,j,m;
    
    cin >> n;
    double ans=pow(n,3);
    m=pow(3,3);
    double f=ans/m;
    cout << fixed << setprecision(9) << f;
    
    
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>v;
#define tc int t; cin>>t; while(t--)
#define an long long n; cin>>n; long long a[n]; for(int i=0;i<n;i++) cin>>a[i];
int main()
{ 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);

    long long i,j,x,y,len; string s; bool flag;
    cin>>i;
    if(i==0)cout<<1<<endl;
    else cout<<0<<endl;
}


Measured memory_bytes: 3620
#define _USE_MATH_DEFINES 
#include <iomanip> 
#include <cmath>  
#include<iostream>
#include <fstream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

ll n, z, w, a[2020];

ll absX(ll x) {
	if (x < 0) x *= -1;
	return x;
}

int main() {
	cin >> n >> z >> w;
	repi(i, 0, n) rd(a[i]);
	if (n == 1) {
		wrln(absX(w - a[0]));
		return 0;
	}
	wrln(max(absX(w - a[n - 1]), absX(a[n - 1] - a[n - 2])));
	return 0;
}

Measured memory_bytes: 256
/*
created by: Son Dinh
*/
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sqr(X) ((X)*(X))
#define sz(x) ((int)(x).size())
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
string b;
char res[256];
int main(){
    res['A']='T';
    res['T']='A';
    res['C']='G';
    res['G']='C';
    cin>>b;
    for(int i=0;i<sz(b);++i) cout<<res[b[i]];
    return 0;
}



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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b)
		cout << c << endl;
	else if (a == c)
		cout << b << endl;
	else
		cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n,m;
ll a[100100];
ll b[100100];
map<ll,ll> mp;

int main(){
	cin>>n>>m;
	REP(i,n)
		cin>>a[i];
	ll ans=0;
	
	b[0]=(a[0]%m);
	mp[b[0]]++;
	for(int i=1;i<n;i++){
		b[i]=(b[i-1]+a[i])%m;
		mp[b[i]]++;
	}
	if(mp.find(0)!=mp.end()){
		ans+=mp[0];
	}
	for(auto itr=mp.begin();itr!=mp.end();itr++){
		ans+=(itr->second)*(itr->second-1)/2;
	}
	cout<<ans<<endl;
	return 0;
}
	

Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define mod 1000000007
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int f[51][51],C[51][51];
void add(int&a,int b){a=a+b>=mod?a+b-mod:a+b;}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi();
	C[0][0]=1;
	for(int i=1;i<=n;++i){
		C[i][0]=1;
		for(int j=1;j<=i;++j)C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	}
	f[1][0]=f[1][1]=1;
	for(int i=1;i<=n;++i)
		for(int j=0;j<=i;++j)
			for(int x=0;i+x<=n;++x)
				for(int y=0;i+x+y<=n;++y)
					if(x+y&&x+y>=j&&!((x+y-j)&1))
						add(f[i+x+y][abs(j+(x+y-j)/2-x)],1ll*f[i][j]*C[i+x+y][x+y]%mod*C[x+y][y]%mod);
	printf("%d\n",f[n][0]);
	return 0;
}


Measured memory_bytes: 256
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sat Jan 18 17:39:17 2020
//
package main

import (
	"fmt"
	"sort"
)

const MOD = 1e9 + 7

type comb struct {
	memo []int
}

func (c *comb) fact(n int) int {
	if c.memo[n] > 0 {
		return c.memo[n]
	}
	c.memo[n] = n * c.fact(n-1) % MOD
	return c.memo[n]
}

func (c *comb) pow(n, k int) int {
	if k == 0 {
		return 1
	}
	if k%2 == 1 {
		return n * c.pow(n*n%MOD, k/2) % MOD
	}
	return c.pow(n*n%MOD, k/2)
}

func (c *comb) calc(n, k int) int {
	if n == 0 || k == 0 || n-k < 0 {
		return 0
	}

	return c.fact(n) * c.pow(c.fact(k), MOD-2) % MOD * c.pow(c.fact(n-k), MOD-2) % MOD
}

func newComb(n int) *comb {
	c := comb{}
	c.memo = make([]int, n+1)
	c.memo[0] = 1
	return &c
}

var N, K int
var A []int

func main() {
	fmt.Scan(&N, &K)
	A = make([]int, N)
	for i := range A {
		fmt.Scan(&A[i])
	}
	sort.Ints(A)

	c := newComb(N)
	ans := 0
	for i := 0; i < N; i++ {
		ans += c.calc(N-1-i, K-1) * A[N-1-i] % MOD
		ans -= c.calc(N-1-i, K-1) * A[i] % MOD
		ans += MOD
		ans %= MOD
	}
	fmt.Println(ans)
}


Measured memory_bytes: 20608
x a p = a * p
y b c d p =
  if p <= c
  then b
  else b + d * (p - c)

ans a b c d p =
  let xx = x a p
      yy = y b c d p
  in
    if xx <= yy
    then xx
    else yy

main = do
  z <- getContents
  let (a:b:c:d:p:_) = map read $ lines z :: [Int]
      o = ans a b c d p
  print o

Measured memory_bytes: 3624
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
	while (true) {
		int n = -1;
		cin >> n;
		if (n <= 0) break;
		vector<vector<int>> d(n, vector<int>(n));
		int st = -1;
		for (int i = 0; i < n; ++i) {
			string s;
			cin >> s;
			for (int j = 0; j < n; ++j) {
				d[i][j] = s[j] == '1' ? 1 : 1 << 29;
				if (s[j] == '1') {
					st = j;
				}
			}
			d[i][i] = 0;
		}
		int ans = 0;
		vector<int> color(n, -1), q;
		if (st >= 0) {
			q.push_back(st);
			color[st] = 1;
		} else {
			ans = -1;
		}
		while (!q.empty()) {
			vector<int> nx;
			for (int x : q) {
				for (int i = 0; i < n; ++i) {
					if (d[x][i] == 1) {
						if (color[i] < 0) {
							color[i] = !color[x];
							nx.push_back(i);
						} else if (color[i] != !color[x]) {
							ans = -1;
						}
					}
				}
			}
			q = nx;
		}
		if (ans >= 0) {
			for (int k = 0; k < n; ++k) {
				for (int i = 0; i < n; ++i) {
					for (int j = 0; j < n; ++j) {
						d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
					}
				}
			}
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < n; ++j) {
					if (d[i][j] < (1 << 29)) {
						ans = max(ans, d[i][j] + 1);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;

int main()
{
	int n;
	ll ans=0;
	cin>>n;
	for(int i=1;i<=n/2;i++)
	{
		if(i!=n-i)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

int cusum[2020][2020];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // in
    int N, K; cin >> N >> K;
    int x[101010], y[101010];
    char c[101010];
    for(int i=0; i < N; ++i) cin >> x[i] >> y[i] >> c[i];

    // calc
    // 基本方針：二次元累積和
    // しかしx, yは大きい。
    // 市松模様なので(0, 0)から2 * Kの位置で全探索すると
    // 他の場所の状態は一意にさだまる
    // つまりx, yをmod 2 * Kで場合分けすればよい？（白ならKずらす）
    for(int i=0; i < N; ++i) {
        if(c[i] == 'W') x[i] += K;
        int mx = x[i] % (K * 2);
        int my = y[i] % (K * 2);
        ++cusum[my  ][mx  ];
        ++cusum[(my+K) % (K * 2)][(mx+K) % (K * 2)];
    }

    for(int i = 0; i < K * 2; ++i) 
        for(int j = 0; j < K * 2; ++j) 
            cusum[i+1][j+1] = cusum[i+1][j+1] + cusum[i][j+1] + cusum[i+1][j] - cusum[i][j];
    
    // out
    int ans = 0;
    for(int i=0; i < K; ++i) {
        for(int j=0; j < K; ++j) {
            int unko = cusum[i+K][j+K] - cusum[i+K][j] - cusum[i][j+K] + cusum[i][j];
            ans = max(ans, unko);
            ans = max(ans, N-unko);
        }
    }

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

Measured memory_bytes: 16896
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	ll N;
	cin >> N;
	ll X = 0;
	for (; X <= 50000; X++) {
		if (floor((ld)X * 1.08) == N) {
			cout << X << "\n";
			return 0;
		}
	}
	cout << ":(\n";
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define Rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)

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

//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//べき//
ll squ(ll n, ll p, ll m){
	if(p==0) return 1;
	if(p%2==0){
		ll t=squ(n, p/2, m);
		return t*t%m;
	}
	return n*squ(n,p-1,m);
	
}


//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll 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;
	}
}

// 二項係数計算
ll 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;
}

//nが大

ll com(ll n,ll m){
	if(n<=0 || m<=0 || n==m){
		return 1;
	}
	if(n<m){
		return 0;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}

	return k;
}


//


////////////////////////////////////////////////////////////////////
int main(){
ll n,k;
cin>>n>>k;
ll a[n+1];
rep(i, n){
    cin>>a[i];
}

ll dp[k+1];
for(int i=0;i<=k;i++){
dp[i]=-1;
}

ll lim=a[1]-1;
for(int i=0;i<=lim;i++){
    dp[i]=0;
    for(int j=1;j<=n;j++){
        if(i+a[j]<=k){
            dp[i+a[j]]=1;
        }
    }
}

for(int i=lim+1;i<=k-a[1];i++){
if(dp[i]==0){
    for(int j=1;j<=n;j++){
        if(i+a[j]<=k)
        dp[i+a[j]]=1;
    }
}
if(dp[i]==1){
    for(int j=1;j<=n;j++){
        if(i+a[j]<=k && dp[i+a[j]]!=1)
        dp[i+a[j]]=0;
    }
}

}




if(dp[k]==0){
    cout<<"Second"<<endl;
}
else{
    cout<<"First"<<endl;
}
return 0;










}





Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = Integer.parseInt(in.nextLine());
        final String word = in.nextLine();
        int red = 0;
        for (char c : word.toCharArray()) {
            if (c == 'R') {
                red++;
            }
        }
        int res = 0;
        for (int i = 0; i < red; i++) {
            if (word.charAt(i) == 'W') {
                res++;
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 42084
#include <bits/stdc++.h>
#define P pair<long long, long long>

using namespace std;
const int INF=1e5;

int main(){
  int h, w, n;
  cin >> h >> w >> n;
  int mx = max(h, w);
  cout << (n-1)/mx + 1 << endl;
}



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

int main() {
  uint64_t n;
  std::cin >> n;
  std::string s;
  std::cin >> s;

  uint64_t index = 0;
  uint64_t cost1 = 0, cost2 = 0;
  if (s.front() == 'W') {
    cost2++;
  }

  for (uint64_t i = 1; i < s.size(); i++) {
    if (cost2 < cost1) {
      cost1 = cost2 = 0;
      index = i;
    }
    if (s[i] == 'W') {
      cost2++;
    } else {
      cost1++;
    }
  }

  if (s.back() == 'E') {
    cost1++;
  }

  if (cost2 < cost1) {
    cost1 = cost2 = 0;
    index = s.size() - 1;
  }

  uint64_t cost = 0;

  for (uint64_t i = 0; i < s.size(); i++) {
    if (i < index && s[i] == 'W') {
      cost++;
    } else if (index < i && s[i] == 'E') {
      cost++;
    }
  }

  std::cout << cost << std::endl;
  return 0;
}


Measured memory_bytes: 900
m,d = map(int,input().split())
count = 0
for month in range(1,m+1):
  for day in range(1,d+1):
    if (day%10) >= 2 and (day//10) >= 2:
      if (day%10)*(day//10) == month:
        #print(month,day)
        count += 1
print(count)


Measured memory_bytes: 2940
import collections

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]
ans_count = []
total = 0
for i in range(n):
  total += a[i]

count = collections.Counter(a)
for i in range(q):
  num = count[bc[i][0]]
  count[bc[i][0]] = 0
  count[bc[i][1]] += num
  total += (bc[i][1] - bc[i][0]) * num
  print(total)

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

int main()
{
    int a, b, c, d, e, k;
    string ans;

    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    cin >> e;
    cin >> k;
    
    if (e-a <= k){
        ans = " Yay!";
    }
    else {
        ans = ":(";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#include "bits/stdc++.h"

namespace adaptor = boost::adaptors;

const int64_t nmax = 1000;
const int64_t vmax = 1e4;

int64_t n, A[nmax], s;
int64_t B[nmax], T[vmax + 1];

int64_t calcCost() {
    int64_t ans = 0;

    bool V[nmax];
    for (int64_t i = 0; i < n; i++) {
        B[i] = A[i];
        V[i] = false;
    }
    std::sort(B, B + n);
    for (int64_t i = 0; i < n; i++) T[B[i]] = i;
    for (int64_t i = 0; i < n; i++) {
        if (V[i]) continue;
        int64_t cur = i;
        int64_t S = 0;     // サイクル内の要素の和
        int64_t m = vmax;  // サイクル内の最小値
        int64_t an = 0;    // サイクル内の個数
        while (true) {
            V[cur] = true;
            an++;
            int64_t v = A[cur];
            m = std::min(m, v);
            S += v;
            cur = T[v];
            if (V[cur]) break;
        }
        ans += std::min(S + (an - 2) * m, m + S + (an + 1) * s);
    }
    return ans;
}

void solve() {
    std::cin >> n;
    s = vmax;
    for (int64_t i = 0; i < n; i++) {
        std::cin >> A[i];
        s = std::min(s, A[i]);
    }
    int64_t ans = calcCost();
    std::cout << ans << std::endl;

    return;
}

int main() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}



Measured memory_bytes: 3240
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int prime = 0;
        for(int i = 0; i < n; i++){
            int input = sc.nextInt();
            if(input == 2){
                prime++;
            }else{
                boolean isPrime = true;
                int a = (int)Math.sqrt(input);
                for(int j = 2; j <= a; j++){
                    if(input % j == 0){
                        isPrime = false;
                        break;
                    }
                }
                if(isPrime){
                    prime++;
                }
            }
        }
        System.out.println(prime);
    }
}


Measured memory_bytes: 40348
#include <iostream>
using namespace std;
int main()
{

    int k, n;
    cin >> k >> n;
    int arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    int temp[n];
    int skippeddist = 0;
    int currmax = 0;
    for (int i = 0; i < n - 1; i++)
    {
        skippeddist = max(abs(arr[i] - arr[i + 1]), skippeddist);
    }
    int lastdist = k - arr[n - 1] + arr[0];
    skippeddist = max(skippeddist, lastdist);
    cout << k - skippeddist;

    return 0;
}

Measured memory_bytes: 1024
package main

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

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

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

//var done []bool = make([]bool, 10)
//var memo []int = make([]int, 10)

//func fib(n int) int {
//	fmt.Println(n)
//	if n == 0 {
//		return 0
//	}
//	if n == 1 {
//		return 1
//	}
//	if done[n] {
//		fmt.Println("done" + fmt.Sprint(n))
//		return memo[n]
//	}
//	done[n] = true
//	memo[n] = fib(n-1) + fib(n-2)
//	return memo[n]
//}

var dp []int = make([]int, 10)
var m map[string]int = make(map[string]int)
var mInt map[int]int = make(map[int]int)

func fib(n int) int {
	dp[0] = 0
	dp[1] = 1
	for i := 2; i <= n; i++ {
		dp[i] = dp[i-1] + dp[i-2]
	}
	return dp[n]
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	n := nextInt()
	ns := nextInts(n)
	for i := 0; i < len(ns); i++ {
		a := ns[i]
		if a%2 == 0 {
			if a%3 != 0 && a%5 != 0 {
				fmt.Fprint(out, string("DENIED"))
				return
			}
		}
	}
	fmt.Fprint(out, string("APPROVED"))
}


Measured memory_bytes: 640
import itertools

N, M, X = list(map(int, input().split()))
c_list = []
a_table = []
for _ in range(N):
    a_list = list(map(int, input().split()))
    a_table.append(a_list[1:])
    c_list.append(a_list[0])

p_list = list(itertools.product([True, False], repeat=N))
min_cost = float("inf")
for pattern in p_list:  # 4092 (10 ** 3)
    cost = 0
    rikai_list = [0] * M
    for n, is_buy in enumerate(pattern):  # N個  # 12
        # n番目の参考書
        if not is_buy:
            continue
        cost += c_list[n]
        for m, a in enumerate(a_table[n]):  # 12
            # m番目のアルゴリズム
            rikai_list[m] += a
    not_understand = [r for r in rikai_list if r < X]  # 12
    if not not_understand:
        min_cost = min(min_cost, cost)

ans = min_cost if min_cost != float("inf") else -1
print(ans)

Measured memory_bytes: 69244
#include <stdio.h>

 int main(void)
 {
     int times;              // N
     scanf("%d", &times);

     int value[times];       // K
     int headCount[times];   // P
     int i;

     // printf("???????????????????????°?????\????????????????????????");

     for (i = 0; i < times; i++)
     {
         // printf("???????????°??¨?????°?????\????????????????????????");
         scanf("%d %d", &value[i], &headCount[i]);
     }

     for (i = 0; i < times; i++)
     {
         if ((value[i] % headCount[i]) == 0)
         {
             printf("%d\n", headCount[i]);
         }
         else
         {
             printf("%d\n", value[i] % headCount[i]);
         }
     }

     return 0;
 }

Measured memory_bytes: 596
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    s = 0
    for i in a:
        s ^= i
    ans = [s^i for i in a]
    print(*ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 105984
import java.util.*;

class Main{
	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		String t=s.next();

		if(n%2==0&&t.substring(0,n/2).equals(t.substring(n/2))) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

struct node {
  map<string, node*> childs;
  string value;
  bool object;

  node(): object(true) {}
  node(string value): value(value), object(false) {}
};

vector<string> split(string s, string p) {
  vector<string> ret;
  ll h = 0;
  REP(i, 0, s.size() - p.size() + 1) if(s.substr(i, p.size()) == p) {
    ret.push_back(s.substr(h, i - h));
    h = i + p.size();
    i += (ll) p.size() - 1;
  }
  ret.push_back(s.substr(h, (ll) s.size() - h));
  return ret;
}

int main(void) {
  string target;
  getline(cin, target);
  vector<string> yaml;
  string line;
  while(getline(cin, line)) yaml.push_back(line);

  ll p = 0;
  function<node* (ll&)> parse = [&](ll &p) {
    ll d = 0;
    while(yaml[p][d] == ' ') d++;

    node* n = new node();

    while(p < yaml.size()) {
      ll ld = 0;
      while(yaml[p][ld] == ' ') ld++;
      if(ld < d) break;

      vector<string> tmp = split(yaml[p], ":");
      string key = tmp[0].substr(d, tmp[0].length() - d);
      p++;

      if(tmp[1].length() == 0) {
        n->childs[key] = parse(p);
      } else {
        string val = tmp[1].substr(1, tmp[1].length() - 1);
        n->childs[key] = new node(val);
      }
    }

    return n;
  };
  node* object = parse(p);

  vector<string> keys = split(target, ".");
  node* r = object;
  REP(i, 1, keys.size()) {
    string key = keys[i];
    if(r->object && r->childs.count(key)) {
      r = r->childs[key];
    } else {
      cout << "no such property" << endl;
      return 0;
    }
  }
  if(r->object) cout << "object" << endl;
  else cout << "string \"" << r->value << "\"" << endl;
}



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

const int mod=1e9+7;
int dp[2005][2005];
int a[2005],b[2005];
int n,m;

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=1; i<=m; i++)
    {
        scanf("%d",&b[i]);
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
            if(a[i]==b[j])
                dp[i][j]+=(dp[i-1][j-1]+1);
            if(dp[i][j]<0)
                dp[i][j]+=mod;
            if(dp[i][j]>=mod)
                dp[i][j]%=mod;
        }
    }
    int ans = (dp[n][m]+1)%mod;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 15872
import java.util.Scanner;

public class Main {





    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);
        int a,b,c;
        a= s.nextInt();
        b=s.nextInt();
        c=s.nextInt();

        int pole = b-a;
        int pole2=c-b;

        if(pole ==pole2){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }


    }

}


Measured memory_bytes: 22868
from subprocess import*
with open('Main.java','w')as f:f.write(r"""
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		PrintWriter out = new PrintWriter(System.out);
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int c[] = new int[n];
		int s[] = new int[n];
		int f[] = new int[n];
		for (int i = 1; i < n; i++) {
			c[i] = Integer.parseInt(sc.next());
			s[i] = Integer.parseInt(sc.next());
			f[i] = Integer.parseInt(sc.next());
		}
		for (int i = 1; i <= n; i++) {
			int t = 0;
			for (int j = i; j < n; j++) {
				if (t < s[j])
					t = s[j];
				else if ( t % f[j] != 0)
					t += f[j] - t % f[j];
				t += c[j];
			}
			out.println(t);
		}
		out.flush();
	}
}
""")
call(('javac','Main.java'))
call(('java','Main'))

Measured memory_bytes: 58632
#include <iostream>
#include <vector>
using namespace std;
long long N, W;
vector<long long> w, v;
vector<vector<long long>> dp;//dp[i + 1][j]でi番目までのうち価値がjとなるように選んだときの重さの最小
long long INF = 1e18;
int main(){
    cin >> N >> W;
    w.resize(N);
    v.resize(N);
    for(int i = 0; i < N; i++) cin >> w[i] >> v[i];
    dp.resize(N + 1, vector<long long> (100001, INF));
    dp[0][0] = 0;
    long long ans = 0;
    for(int i = 0; i < N ; i++){
        for(int j = 0; j < 100001; j++){
            if(j < v[i]) dp[i + 1][j] = dp[i][j];
            else{
                dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
            }
        }
    }
    for(int i = 0; i < 100001; i++){
        if(dp[N][i] <= W) ans = max(ans, (long long)i);
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3624
import numpy as np
n, m= map(int , input().split())
xy=[list(map(int,input().split())) for _ in range(m)]
count=[1]*n
ans=[True]+[False]*(n-1)
f=True
for i in range(m):
    if ans[xy[i][0]-1]== True:
        ans[xy[i][1]-1]=True
        if count[xy[i][0]-1]==1:
            ans[xy[i][0]-1]=False
    count[xy[i][0]-1]-=1
    count[xy[i][1]-1]+=1

answer=0
for i in range(n):
    if ans[i]==True:
        answer+=1

print(answer)
    
        

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
//typedef long long int;
const ll M = 1000000007;
ll A, B, C, D, G, H, N, L, K, P, Q, R, W, X, Y, Z;
string S, T;

signed main(){
	std::cin >>A>>B ;
	if((A+B)%2==0)std::cout << (A+B)/2 << std::endl;
	else std::cout << "IMPOSSIBLE" << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define frfr  freopen("input.text","r",stdin); freopen("output.text","w",stdout)
#define ll long long int
#define wh int T;cin >> T;while(T--)
#define pb push_back
#define loop(i,a,b) for (int i = a; i < n; i++)
int main(){
  //IOS;
  //frfr;
  int n;
  cin >> n;
  int r = n%1000;
  if(r == 0){
    cout << "0" << endl;
  }else{
    cout << (1000 - r ) << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_144
{
    class F
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            int n = nm[0];
            int m = nm[1];
            List<int>[] graph = new List<int>[n];
            for (int i = 0; i < n; i++) graph[i] = new List<int>();
            for(int i = 0; i < m; i++)
            {
                int[] st = ReadInts();
                graph[st[0] - 1].Add(st[1] - 1);
            }
            double[] baseDP = new double[n];

            for(int i = n - 2; i >= 0; i--)
            {
                double val = 0;
                for(int j = 0; j < graph[i].Count; j++)
                {
                    val += baseDP[graph[i][j]];
                }
                baseDP[i] += 1 + val / graph[i].Count;
            }

            double res = baseDP[0];
            for(int i = 0; i < n; i++)
            {
                if (graph[i].Count <= 1) continue;
                double[] tempDP = new double[n];
                double nextVal = 0;
                double maxVal = 0;
                for(int j = 0; j < graph[i].Count; j++)
                {
                    nextVal += baseDP[graph[i][j]];
                    maxVal = Max(maxVal, baseDP[graph[i][j]]);
                }
                tempDP[i] = 1 + (nextVal - maxVal) / (graph[i].Count - 1);
                for(int j = i - 1; j >= 0; j--)
                {
                    double val = 0;
                    for(int k = 0; k < graph[j].Count; k++)
                    {
                        if (graph[j][k] <= i) val += tempDP[graph[j][k]];
                        else val += baseDP[graph[j][k]];
                    }
                    tempDP[j] = 1 + val / graph[j].Count;
                }
                res = Min(res, tempDP[0]);
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 19624
#include<iostream>
    using namespace std;
    int main(void)
    {
    	int a[3],t, k;
    	cin >> a[0] >> a[1] >> a[2] >> k;
    	if(a[0]>a[1])
    	{
    		if(a[0]>a[2])
    		{
    			t = 0;
    		}
    		else
    		{
    			t = 2;
    		}
    	}else
    	{
    		if (a[1]>a[2])
    		{
    			t = 1;
    		}
    		else
    		{
    			t = 2;
    		}
    	}
     
    	for(int i=0;i<k;i++)
    	{
    		a[t] *= 2;
    	}
    	cout << a[0] + a[1] + a[2];
    	return 0;
    }

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

int main(){
  int res[4][13]={};
  int n,c;
  char m;
  
   
  cin >> n;
   
  for(int i = 0; i < n;i++){
    cin >> m >> c;
    if(m=='S')
      res[0][c-1] = 1;
    else if(m=='H')
      res[1][c-1] = 1;
    else if(m=='C')
      res[2][c-1] = 1;
    else 
      res[3][c-1] = 1;
    
    
  }
  
  for(int i = 0; i < 4; i++){
    for(int j = 0; j < 13; j++){
      if(!res[i][j]){
        if(i==0)cout << "S" << ' ' << j+1 << endl;
        else if(i==1)cout << "H" << ' ' << j+1 << endl;
        else if(i==2)cout << "C" << ' ' << j+1 << endl;
        else if(i==3)cout << "D" << ' ' << j+1 << endl;
      }
    }
  }
      
  
  
  
}



Measured memory_bytes: 3052
n, k = map(int, input().split())
ans = 0
if k == 0:
    ans = n ** 2
else:
    for b in range(k + 1, n):
        p = n // b
        r = n % b
        ans += p * max(0, b - k) + max(0, r - k + 1)
    ans += n - k
print(ans)


Measured memory_bytes: 3060
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<int>num(4);
	for (int i = 0; i < N; i++) {
		cin >> M;
		num[M]++;
	}
	vector < vector < vector<long double>>>dp(num[1] + num[2] + num[3] + 1, vector<vector<long double>>(num[2] + num[3] + 1, vector<long double>(num[3] + 1)));
	vector < vector < vector<long double>>>p(num[1] + num[2] + num[3] + 1, vector<vector<long double>>(num[2] + num[3] + 1, vector<long double>(num[3] + 1)));
	dp.back().back().back() = 0;
	p.back().back().back() = 1;
	for (int i = num[1] + num[2] + num[3]; i >= 0; i--) {
		for (int j = min(i, num[2] + num[3]); j >= 0; j--) {
			for (int k = min(j, num[3]); k >= 0; k--) {
				int a, b, c;
				c = k;
				b = j - k;
				a = i - j;
				long double by = N;
				by /= i;
				dp[i][j][k] /= p[i][j][k];
				if (a) {
					p[i - 1][j][k] += p[i][j][k] * a / i;
					//dp[i - 1][j][k] += dp[i][j][k] * a / i * p[i][j][k] + by /* p[i][j][k] * a / i*/;
					dp[i - 1][j][k] += (dp[i][j][k] + by)*p[i][j][k] * a / i;
				}
				if (b) {
					p[i][j - 1][k] += p[i][j][k] * b / i;
					//dp[i][j - 1][k] += dp[i][j][k] * b / i * p[i][j][k] + by /* p[i][j][k] * b / i*/;
					dp[i][j - 1][k] += (dp[i][j][k] + by)*p[i][j][k] * b / i;
				}
				if (c) {
					p[i][j][k - 1] += p[i][j][k] * c / i;
					//dp[i][j][k - 1] += dp[i][j][k] * c / i * p[i][j][k] + by /* p[i][j][k] * c / i*/;
					dp[i][j][k - 1] += (dp[i][j][k] + by)*p[i][j][k] * c / i;
				}
			}
		}
	}
	cout<<setprecision(20);
	//for (int i = 0; i < dp.size(); i++)for (int j = 0; j < dp[i].size(); j++)for (int k = 0; k < dp[i][j].size(); k++)cerr << i << " " << j << " " << k << " " << dp[i][j][k] << " " << p[i][j][k] << endl;
	cout << dp.front().front().front() << endl;
	return 0;
}

Measured memory_bytes: 861056
while 1:
	n,k=map(int,raw_input().split())
	if n==0:break
	a=[int(raw_input()) for i in range(n)]
	cur=mx=sum(a[:k])
	for i in range(n-k):
		cur=cur-a[i]+a[i+k]
		mx=max(mx,cur)
	print mx

Measured memory_bytes: 10460
#include <stdio.h>

int main(void) {
	int H,W;
	int i,j;
	while(1)
	{
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0) {
			break;
		}
		for (i = 0; i < H; ++i) {
			for (j = 0; j < W; ++j) {
				if (i == 0 || i == (H - 1) || j == 0 || j == (W - 1)) {
					printf("#");
				} else {
					printf(".");
				}
 			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;

bool pairCompare(const pair<int, int>& firstElof, const pair<int, int>& secondElof) {
    return firstElof.first > secondElof.first;
}

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

    vector<bool> a(N+1);
    for(ll i=0;i<N+1;i++) {
        a.at(i) = true;
    }
    ll m;
    for(ll i=0;i<M;i++) {        
        cin >> m;
        a.at(m) = false;
    }

    vector<ll> dp(N+1);
    dp.at(0) = 1;
    for(ll i=0;i<N;i++) {
        if(a.at(i)&&i<=N-2) {
            dp.at(i+1) += dp.at(i);
            dp.at(i+2) += dp.at(i);
            dp.at(i+1) %= MOD;
            dp.at(i+2) %= MOD;
        }
        if(a.at(i)&&i==N-1) {
            dp.at(i+1) += dp.at(i);
            dp.at(i+1) %= MOD;
        }
        //cout << dp.at(i) << " ";
    }
    //cout << endl;
    cout << dp.at(N) << endl;

    return (0);
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t x, n;
    cin >> x >> n;

    unordered_set<int64_t> p;
    for (auto _ : irange(0L, n)) {
        int64_t pp;
        cin >> pp;
        p.insert(pp);
    }

    int64_t ans = 0;
    for (auto i : irange(1L, 102L)) {
        if (p.count(i)) {
            continue;
        }
        if (abs(x - i) < abs(x - ans)) {
            ans = i;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

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

int main(){
  ll n,x;
  cin >> n >> x;
  cout << 3*(n-gcd(n,x)) << endl; 
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
using II = pair<int,int>;
using VII = vector<II>;
using VVII = vector<VII>;

#define V_MAX 100000
vl visited(V_MAX+1);
vl dist(V_MAX+1);

void dfs(VVII &T, int p, ll w){
	if(visited[p]) return;
	visited[p] = true;
	dist[p] = w;
	for(auto cw:T[p]){
		int np,nw; tie(np,nw) = cw;
		dfs(T, np, w+nw);
	}
}

int main(){
	int N,M; cin>>N>>M;
	if(M==0){ puts("Yes"); return 0; }

	VVII V(N+1);
	int l,r,d, mini = INT_MAX, maxi = 0;
	rp(i, 0, M){
		cin>>l>>r>>d;
		V[l].emplace_back(r, d);
		V[r].emplace_back(l,-d);
		mini = min(mini, l);
		maxi = max(maxi, r);
	}

	rp(l, mini, maxi+1){
		dfs(V, l, 0);
		for(auto rd:V[l]){
			tie(r,d) = rd;
			if(abs(d) != abs(dist[r]-dist[l])){ puts("No"); return 0; }
		}
	}
	puts("Yes");
}

Measured memory_bytes: 13184
#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
int e[300500],w[300500];
string st;
int main()
{
	int n,i;
	scanf("%d",&n);
	cin >> st;
	memset(e,0,sizeof(e));
	memset(w,0,sizeof(w));
	for (i=1;i<n;i++)
		if (st[i-1]=='E') e[i]=e[i-1]+1;
		else e[i]=e[i-1];
	for (i=n-1;i>=0;i--)
	    if (st[i+1]=='W') w[i]=w[i+1]+1;
	    else w[i]=w[i+1];
	int ans=-1;
	//for (i=0;i<n;i++) cout << e[i] << " ";cout << endl;
	//for (i=0;i<n;i++) cout << w[i] << " ";cout << endl;
	for (i=0;i<n;i++)
	{
		ans=max(ans,e[i]+w[i]+1);
	}
	printf("%d",n-ans);
	return 0;
}

Measured memory_bytes: 3076
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().rstrip()

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

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

        if x == y:
            return

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

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

def main():
    N, K, L = map(int, input().split())
    road = UnionFind(N)
    train = UnionFind(N)

    for _ in range(K):
        p, q = map(int, input().split())
        road.union(p, q)
    
    for _ in range(L):
        r, s = map(int, input().split())
        train.union(r, s)
    
    ans = []
    counter = defaultdict(int)
    for i in range(1, N + 1):
        root = (road.find(i), train.find(i))
        ans.append(root)
        counter[root] += 1
    for i in range(1, N + 1):
        root = (road.find(i), train.find(i))
        print(counter[root])

if __name__ == '__main__':
    main()


Measured memory_bytes: 43416
fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}

fun main() {
	abc000X()
}

fun abc000X() {
	val day = int()
	val penalty = list().toIntArray()
	val advantage = Array(day) {list().toIntArray()}

	val last = IntArray(26) {-1}

	var r = 0L
	for(d in 0 until day) {
		val t = int()-1
		last[t] = d
		r += advantage[d][t]

		for(i in 0..25)
			r -= penalty[i]*(d-last[i])
		println(r)
	}
}


Measured memory_bytes: 40220
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <vector>
#include <cassert>
using namespace std;

#define DEBUG(x) cerr << #x << ":" << x << endl;

typedef string::const_iterator State;

bool express(State &p);
bool term(State &p);
bool elem(State &p);

bool express(State &p) {
	bool r = term(p);
	for(;;) {
		if(*p == '*') {
			p++;
			bool rs = term(p);
			r = r && rs;
		}
		else if(*p == '+') {
			p++;
			bool rs = term(p);
			r = r || rs;
		}
		else if(*p == '>') {
			p++;
			bool rs = term(p);
			if(r == false) r = true;
			else if(r == true) r = rs;
		}
		else {
			break;
		}
	}
	return r;
}

bool term(State &p) {
	if(*p == '(') {
		p++;
		bool r = express(p);
		p++;
		return r;
	}
	return elem(p);
}

bool elem(State &p) {
	if(*p == '-') {
		p++;
		return !term(p);
	}

	bool r = (*p == 'T');
	p++;

	return r;
}

void replaceAll(string &str, const string &from, const string &to) {
	int p = 0;
	while(p = str.find(from, p), p != -1) {
		str.replace(p, from.length(), to);
		p += to.length();
	}
}

int main() {
#if 0
	string line;
	getline(cin, line);
	State p = line.begin();
	cout << (int)express(p) << endl;
#else
	string alpha = "abcdefghijk";
	while(true) {
		string line;
		getline(cin, line);
		if(line == "#") break;
		replaceAll(line, "->", ">");
		vector<int> place[11];
		for(int i = 0; i < (int)line.size(); i++) {
			char c = line[i];
			string::iterator it = find(alpha.begin(),alpha.end(), c);
			if(it != alpha.end()) {
				place[it - alpha.begin()].push_back(i);
			}
		}

		bool flag = true;
		int equal = find(line.begin(), line.end(), '=') - line.begin();
		for(int i = 0; i < (1 << 11); i++) {
			string s = line;
			for(int j = 0; j < 11; j++) {
				for(int k = 0; k < (int)place[j].size(); k++) {
					char c = (i & (1 << j)) ? 'T' : 'F';
					s[place[j][k]] = c;
				}
			}
			string left = s.substr(0, equal);
			string right = s.substr(equal + 1);
#if 0
			DEBUG(left)
			DEBUG(right)
			cin >> s;
#endif
			State lp = left.begin();
			State rp = right.begin();

			if(express(lp) != express(rp)) {
				flag = false;
				break;
			}
		}
		cout << (flag ? "YES" : "NO") << endl;
	}
#endif
	return 0;
}

Measured memory_bytes: 920