akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    static int N;
    static int[] A;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        A = sc.nextIntArray(N);

        PrintWriter pw = new PrintWriter(System.out);
        for (int i : solve()) {
            pw.println(i);
        }
        pw.flush();
    }

    static int[] solve() {
        int sum = 0;
        sum += Math.abs(A[0]);
        for (int i = 1; i < N; i++) {
            sum += Math.abs(A[i-1] - A[i]);
        }
        sum += Math.abs(A[N-1]);

        int[] ans = new int[N];
        for (int i = 0; i < N; i++) {
            int prev = i == 0 ? 0 : A[i-1];
            int post = i == N-1 ? 0 : A[i+1];
            ans[i] = sum - Math.abs(prev - A[i]) - Math.abs(A[i] - post) + Math.abs(prev - post);
        }
        return ans;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

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

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

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

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

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 44256
def solveequation(edge,ans,n,m):
    #edge=[[to,dire,id]...]
    x=[0]*m
    used=[False]*n

    def dfs(v):
        used[v]=True
        r=ans[v]
        for to,dire,id in edge[v]:
            if used[to]:
                continue
            y=dfs(to)
            if dire==-1:
                x[id]=y
            else:
                x[id]=-y
            r+=y
            r%=26
        return r

    for v in range(n):
        if used[v]:
            continue
        y=dfs(v)
        if y%26!=0:
            return False
    return x

alphabetlist=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
alpha={i:e for e,i in enumerate(alphabetlist)}


import sys

S=input()
sys.setrecursionlimit(10**5)
n=len(S)
N=int(input())
k=n//2



if n%2==0:
    edge=[[] for i in range(k+1)]
    for i in range(N):
        l,r=map(int,input().split())
        l-=1;r-=1;
        if l>k-1:
            L=n-1-r
            R=n-1-l
            edge[L].append((R+1,-1,i))
            edge[R+1].append((L,1,i))
        elif r>k-1:
            R=n-1-r
            if R>l:
                edge[l].append((R,1,i))
                edge[R].append((l,-1,i))
            elif l>R:
                edge[l].append((R,-1,i))
                edge[R].append((l,1,i))
        else:
            edge[l].append((r+1,1,i))
            edge[r+1].append((l,-1,i))
    ans=[alpha[S[i]]-alpha[S[-i-1]] for i in range(k)]
    ans+=[0]
    for i in range(k,0,-1):
        ans[i]-=ans[i-1]
    res=solveequation(edge,ans,k+1,N)
    if res:
        print("YES")
    else:
        print("NO")
else:
    edge=[[] for i in range(k+1)]
    for i in range(N):
        l,r=map(int,input().split())
        l-=1;r-=1;
        if l>k:
            L=n-1-r
            R=n-1-l
            edge[L].append((R+1,-1,i))
            edge[R+1].append((L,1,i))
        elif l==k:
            R=k-1
            L=n-1-r
            edge[L].append((R+1,-1,i))
            edge[R+1].append((L,1,i))
        elif r>k:
            R=n-1-r
            if R>l:
                edge[l].append((R,1,i))
                edge[R].append((l,-1,i))
            elif l>R:
                edge[l].append((R,-1,i))
                edge[R].append((l,1,i))
        elif r==k:
            edge[l].append((k,1,i))
            edge[k].append((l,-1,i))
        else:
            edge[l].append((r+1,1,i))
            edge[r+1].append((l,-1,i))
    ans=[alpha[S[i]]-alpha[S[-i-1]] for i in range(k)]
    ans+=[0]
    for i in range(k,0,-1):
        ans[i]-=ans[i-1]
    res=solveequation(edge,ans,k+1,N)
    if res:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 75140
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int INF = 1 << 29;
const ll LINF = 1l << 61;
const ld PI = abs(acos(-1));
#define pq priotity_queue
#define mp make_pair
#define P pair
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = a; i >= b; i--)
#define cbuf(buf, init) memset(buf, init, sizeof(buf))
#define modp(x, y) (((y) + (x) % (y)) % (y))
#define divd(x, y) (static_cast<double>(x) / static_cast<double>(y))

ll n, a[300000];

int main()
{
    //
    cin >> n;
    rep(i, 0, n) { cin >> a[i]; }

    if (n % 2 == 0) {
        for (ll i = n - 1; i >= 1; i -= 2) {
            cout << a[i] << " ";
        }
        for (ll i = 0; i < n; i += 2) cout << a[i] << " ";
    }
    else {
        for (ll i = n - 1; i >= 0; i -= 2) {
            cout << a[i] << " ";
        }
        for (ll i = 1; i < n; i += 2) cout << a[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3712
// https://atcoder.jp/contests/abc098/tasks/arc098_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (auto &x : a)
        cin >> x;
    int ans = 0, h = 0, r = 0;
    REP(l, N) {
        while (r < N && (h ^ a[r]) == h + a[r]) {
            h += a[r++];
        }
        ans += r - l;
        h -= a[l];
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 4780
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

k = int(input())
a, b = map(int, input().split())

def cond(k, a, b):
    multi = 1
    total = k
    while total <= b:
        if total >= a:
            return True
        multi += 1
        total = k * multi
    return False

if cond(k, a, b):
    print('OK')
else:
    print('NG')


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

int rem[100000];
deque<int> W[100000];
typedef pair<int, int> P;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N, M, C;
	cin >> N >> M >> C;
	for(int i = 0; i < C; i++){
		cin >> rem[i];
	}
	for(int i = 0; i < N; i++){
		int c, w;
		cin >> c >> w;
		c--;
		W[c].push_back(w);
	}

	priority_queue<P> q;
	for(int c = 0; c < C; c++){
		sort(W[c].begin(), W[c].end());
		reverse(W[c].begin(), W[c].end());
		if(rem[c] && W[c].size()){
			rem[c]--;
			q.push({ W[c].front(), c });
			W[c].pop_front();
		}
	}

	ll ans = 0;
	while(M--){
		if(q.size() == 0) break;
		P p = q.top();
		q.pop();
		int c = p.second, w = p.first;
		ans += w;
		if(rem[c] && W[c].size()){
			rem[c]--;
			q.push({ W[c].front(), c });
			W[c].pop_front();
		}
	}

	cout << ans << endl;
}



Measured memory_bytes: 70992
sub f{$_[$_[1]<$_[0]]}
 
for$i(@N=1..<>){
	$_[$i][$_]=1e9for@N;
	$_[$i][$i]=0;
}
/ .* /,$_[$`][$&]=$_[$&][$`]=$' for@M=<>;
 
for$m(@N){
	for$x(@N){
		for$y(@N){
			$_[$x][$y]=f($_[$x][$y],$_[$x][$m]+$_[$m][$y]);
		}
	}
}
/ .* /,$\+=$_[$`][$&]<$' for@M;
 
print


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

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

    int sum = 0;
    rep(i,n - 2){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') sum++;
    }
    
    cout << sum << endl;
}

Measured memory_bytes: 256
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main {
    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) throws java.lang.Exception {
        // your code goes here
        FastReader scn = new FastReader();
        int i, j, t, n, x, y, num;
        n = scn.nextInt();
        if (n==0)
        System.out.println("1");
        else if (n==1)
        System.out.println("0");
    }
}


Measured memory_bytes: 32524
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int start = h1 * 60 + m1;
    int end = h2 * 60 + m2;
    cout << (end - start - k) << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef vector<lo> vl;
typedef vector<vl>vll;
#define all(v) (v).begin(), (v).end()
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define REPV(a, b, c) for (lo(a) = b; (a) < (c); (a)++) 
#define REP(a,b) for(lo i =(a) ;i<(b);i++)

template <typename T>

istream &operator>>(istream &in, vector<T> &v)
{
    for (unsigned i = 0; i < v.size(); i++)
        in >> v[i];
    return in;
}

void solve(){
	lo n;
	cin>>n;
	lo flag =0;
	while(n){
		lo a = n%10;
		if(a==7){flag =1;break;}
		n=n/10;
	}
	if(flag ==0)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout.precision(20);
    solve();
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define uLL unsigned long long
uLL num[1000000],sum[1000000];
#define min(a,b) (((a)<(b))?(a):(b))
int main()
{
//	freopen("in.in","r",stdin);
	uLL i,j,k,a,b,c,n,ans;
	scanf("%llu%llu",&n,&k);
	a=(uLL)0xFFFFFFFFFF;
	memset(num,0,sizeof(*num)*3*n);
	for (i=1;i<=n;i++)
	{
		scanf("%llu",&num[i]);
		a=min(num[i],a);
	}
	for (i=1;i<=n;i++)
	{
		num[i]=(num[i]==a);
	}
	for (i=n+1;i<=2*n;i++) {num[i]=0;}
	num[0]=1;
	sum[0]=0;
	for (i=1;i<=2*n;i++)
	{
		sum[i]=sum[i-1]+num[i];
	}
	ans=0;
	for (i=1;i<=n;i++)
	{
		if (num[i]==0)
		{
			a=i;j=i;
			while (1)
			{
				a+=k-1;ans+=1;
				for (;j<=a;j++)
				{
					if (num[j]==1) {goto SUC;}
				}
				if (a>n) {break;}
			}
			SUC:
			for (j=i;j<=a;j++) {num[j]=1;}
		}
	}
	printf("%llu\n",ans);
	return 0;
}

Measured memory_bytes: 5760
#include<cstdio>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
typedef long long ll;
int n;
ll a[11000];
vector<ll> prs;
bool ok(ll p)
{
	// ok to check only these values of x
	for (ll x = 0; x <= n && x < p; x++)
	{
		ll f = 0;
		for (int i = n; i >= 0; i--)
			f = (f * x + a[i]) % p;
		if (f % p) return false;
	}
	return true;
}
ll coef[11000][2];
bool ok2(ll p)
{
	memset(coef, 0, sizeof(coef));
	for (int i = 1; i <= n; i++) coef[i][1] = 1;
	bool ret = true;
	for (int k = 1; k <= n; k++)
	{
		ll csum = 0;
		for (int i = k; i <= n; i++)
		{
			csum = (csum + coef[i][k & 1] * a[i]) % p;
			coef[i][!(k & 1)] =
				(i == k) ? 0 : ((coef[i - 1][0] + coef[i - 1][1]) * (k + 1)) % p;
		}
		if (csum % p) {
			ret = false;
			break;
		}
	}
	return ret;
}
bool ok3(ll p)
{
	for (int i = 0; i < p - 1; i++)
	{
		ll t = 0;
		for (int j = i; j <= n; j += p - 1) t = (t + a[j]) % p;
		if (t) return false;
	}
	return true;
}
ll gcd(ll x, ll y)
{
	while (y) { x %= y; swap(x, y); }
	return x < 0 ? -x : x;
}
bool sieve[10100];
int main()
{
	ll m = 0;
	scanf("%d", &n);
	for (int i = n; i >= 0; i--) {
		scanf("%lld", &a[i]); m = gcd(m, a[i]);
	}
	set<ll> ans;
	for (ll p = 2; p * p <= m; p++)
	{
		if (m % p) continue;
		while (!(m % p)) m /= p;
		ans.insert(p);
	}
	if (m > 1) ans.insert(m);
	for (int i = 2; i <= n; i++)
	{
		if (sieve[i]) continue;
		for (int j = i + i; j <= n; j += i) sieve[j] = true;
		//matrix with (i, j) entry i^j mod p is invertible
		if (!(a[0]%i) && ok3(i))
			ans.insert(i);
	}
	for (auto x : ans)
	{
		printf("%lld\n", x);
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n,m,x;
	scanf("%d %d %d",&n,&m,&x);
	vector<int> cost(n);
	vector<vector<int> > gr;
	gr.assign(n,vector<int>(m));
	ll ans = 1LL<<50;
	for(int i = 0; i < n; i++){
		scanf("%d",&cost[i]);
		for(int j = 0; j < m; j++)
			scanf("%d",&gr[i][j]);
	}
	for(int i = 0; i < 1<<n; i++){
		ll auxi = 0;
		vector<int> v(m,x);
		for(int j = 0; j < n; j++){
			if(i&1<<j){
				auxi += cost[j];
				for(int h = 0; h < m; h++)
					v[h] -= gr[j][h];
			}
		}
		auto x = max_element(v.begin(), v.end());
		if(*x <= 0)
			ans = min(ans,auxi);
	}
	if(ans != 1LL<<50)
		printf("%lld\n", ans);
	else
		printf("-1\n");
	return 0;
}

Measured memory_bytes: 3760
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = int(1e9);
typedef long long int ll;
/* -- template -- */

int main(){
    int N, M; cin >> N >> M;
    int A[N];
    rep(i, N)cin >> A[i];
    pair<int, int> x[M];
    rep(i, M){
        cin >> x[i].second >> x[i].first;
    }
    sort(x, x + M);
    int B[N];
    int j = 0;
    for(int i = M - 1; i >= 0;--i){
        for(int k = 0; k < x[i].second;++k){
            B[j] = x[i].first;
            ++j;
            if(j == N)break;
        }
        if(j == N)break;
    }

    ll C[j + N];
    for(int i = 0;i < N;++i){
        C[i] = A[i];
    }
    for(int i = 0;i < j;++i){
        C[N + i] = B[i];
    }
    sort(C, C + j + N,greater<int>());
    ll ans = 0, count = 0;
    for(int i = 0;i < N;++i){
        ans += C[i];
    }
    cout << ans << endl;

}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
long long mod(long long x){
	if(x == 1)return 1;
	else return 1+2*1LL*(mod(x/2));	
}
int main(){
  long long n;
  cin>>n;
  if(n == 1){
  	  cout<<1;
  }
  else{
  	cout<<mod(n);
  }
}

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

const int MAX_N = 1e5+10;
vi es[MAX_N];
vi es2[MAX_N];

pii es3[MAX_N];
bool es4[MAX_N];

int d[MAX_N];

bool used[MAX_N];

bool dfs(int cur, int prv_i) {
    // cout << " " << cur << endl;
    bool ret = false; // false out even, true out odd
    used[cur] = true;
    rep(to_idx, es[cur].size()) {
        int to = es[cur][to_idx];
        int i = es2[cur][to_idx];
        // cout << " -> " << to << '\n';
        if(es4[i]) {
            if(es3[i].fi == cur) ret = !ret;
        }
        else {
            es4[i] = true;
            if(es3[i].se == cur) swap(es3[i].fi, es3[i].se);
            if(!used[to]) {
                auto tmp = dfs(to, i);
                if(tmp) swap(es3[i].fi, es3[i].se);
                else ret = !ret;
            }
            else {
                ret = !ret;
            }
        }
    }
    return ret;
}

int main(){
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a>> b;
        --a;
        --b;
        es[a].pb(b);
        es[b].pb(a);
        es2[a].pb(i);
        es2[b].pb(i);
        es3[i] = {a, b};
    }
    if(m&1) {
        cout << -1 << '\n';
        return 0;
    }
    bool ans = dfs(0, -1);
    if(ans) cout << -1 << '\n';
    else {
        rep(i, m) {
            cout << es3[i].fi+1 << " " << es3[i].se + 1 << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 21120
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
typedef long long ll;
int ceil(int a,int b){// a以上でbの倍数の最小値を出力//
    return (a+b-1)/b*b;
}

//シフト演算　(1<<k) 2のk乗

int stoii(string s){//stoi関数の代用 文字列を数値として読み取りint型に変換//
    return atoi(s.c_str());
}
int main (void){
    string s;
    cin>>s;
    int a=0;
    rep(i,s.size()) if(s[i]=='o'){
        a+=1;
    }
    cout<<700+100*a<<endl;
    return 0;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int,x)
function main()
  sx,sy,tx,ty = map(parseInt, split(readline()))
  dx = tx-sx
  dy = ty-sy
  for i in 1:dx
    print("R")
  end
  for i in 1:dy
    print("U")
  end
  for i in 1:dx
    print("L")
  end
  for i in 1:dy+1
    print("D")
  end
  for i in 1:dx+1
	print("R")
  end
  for i in 1:dy+1
    print("U")
  end
  print("LU")
  for i in 1:dx+1
    print("L")
  end
  for i in 1:dy+1
    print("D")
  end
  print("R")
end

main()

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

int main(){
	// sengen
	int h[2],m[2],k;
	// nyuryoku
	cin >> h[0] >> m[0] >> h[1] >> m[1] >> k;
	// keisan
	int min = 0;
	if(m[0] <= m[1]){
		min += m[1] - m[0];
		min += (h[1] - h[0])*60;
	}else{
		min += 60 + m[1] - m[0];
		min += (h[1] - h[0] -1)*60;
	}
	// syutsuryoku
	cout << min - k;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) cin >> S[i];

    bool ans = false;
    map<PII, int> vis;
    {
        int x = 0, y = 0;
        while (true) {
            vis[PII(x, y)] = true;

            if (x == W-1 && y == H-1) {
                ans = true;
                break;
            }

            if (x+1 < W && y+1 < H && S[y][x+1] == '#' && S[y+1][x] == '#') break;
            else if (x+1 < W && S[y][x+1] == '#') x++;
            else if (y+1 < H && S[y+1][x] == '#') y++;
            else break;
        }
    }

    if (ans) {
        rep(y, H) rep(x, W) {
            if (S[y][x] == '#' && !vis[PII(x, y)]) ans = false;
        }
    }

    cout << (ans ? "Possible" : "Impossible") << endl;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N,K,A,ans=0,counter=0;
  scanf("%d%d",&N,&K);
  int ball[N];for (int i = 0; i < N; i++){ball[i]=0;}
  
  for (int i = 0; i < N; i++)
  {
    scanf("%d",&A);
    if (ball[A-1]!=0)
    {
      ball[A-1]++;
    }else{
      ball[A-1]++;
      counter++;
    }
  }

  int del=counter-K;
  if (del<=0)
  {
    puts("0");
  }else{
    int j=0;
    while (del>0)
    {
      j++;
      for (int i = 0; i < N&&del>0; i++)
      {
        if (ball[i]!=0&&ball[i]==j)
        {
          ans+=j;
          ball[i]=0;
          del--;
        }
      }
    }

    printf("%d",ans);
    
  }
  
  return 0;
}

Measured memory_bytes: 2480
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String N = sc.next();
    char endChar = N.charAt(N.length() - 1);

    if (endChar == '2' || endChar == '4' || endChar == '5' || endChar == '7' || endChar == '9') {
      System.out.println("hon");
    }
    if (endChar == '0' || endChar == '1' || endChar == '6' || endChar == '8') {
      System.out.println("pon");
    }
    if (endChar == '3') {
      System.out.println("bon");
    }
  }
}


Measured memory_bytes: 35756
import java.util.*;
import java.util.stream.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int mod = (int)1e9 + 7;
        int n = sc.nextInt();
        int[] b = new int[n-1];
        for  (int i = 0; i < n-1; i++) {
            b[i] = sc.nextInt();
        }
        int[] a = new int[n];
        a[0] = b[0];
        int ans = a[0];
        for  (int i = 1; i < n; i++) {
            if (i == n-1) {
                a[i] = b[i-1];
            } else {
                a[i] = Math.min(b[i-1], b[i]);
            }
            ans += a[i];
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
#define faf ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define ll long long
#define pb push_back
#define mp make_pair
#define inff 100000


ll modo=1e9+7;



int main()
{
   faf;
   int n;
   cin>>n;
   double  ar[n];
   int i;
   for(i=0;i<n;i++)
   {
       cin>>ar[i];
   }
   sort(ar,ar+n);
   double ans=(ar[0]+ar[1])/2;
   for(i=2;i<n;i++)
   {
       ans=(ans+ar[i])/2;
   }
   cout<<fixed;
   cout<<setprecision(6)<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int a[10],n,e,s;
int get(){
	char x;
	cin>>x;
	if(isdigit(x))return x-'0';
	if(x!='A') return 10;
	else return 11;
}
void calc(int x){
	if(a[x]==11)e++;
	s+=a[x];
	if(s>21&&e)e--,s-=10;
}
main(){
	cin>>n;
	while(n--){
		s=e=0;
		r(i,10)a[i]=get();
		if(a[0]+a[1]==21)cout<<"blackjack"<<endl;
		else r(i,10){
			calc(i);
			if(s>=17&&!e||s>=18&&e){
				if(s<=21)cout<<s<<endl;
				else cout<<"bust"<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 2988
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const ll MOD=1e9+7;
const int MAXN=1e5+10;
int N,K;
ll cnt[MAXN];
void read()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>K;
}
ll qpow(ll n,ll t)
{
    ll acc=1;
    while(t){
        if(t&1)acc=(acc*n)%MOD;
        n=n*n%MOD;
        t>>=1;
    }
    return acc;
}
void solve()
{
    read();
    for(int u=1;u<=K;u++){
        cnt[u]=qpow(K/u,N);
    }
    ll ans=0;
    for(int u=K;u>=1;u--){
        int t=u+u;
        while(t<=K){
            cnt[u]=(cnt[u]-cnt[t]+MOD)%MOD;
            t=t+u;
        }
        ans=(ans+cnt[u]*u%MOD)%MOD;
    }
    cout<<ans;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

Measured memory_bytes: 4376
#include <ctime>
#include <iomanip>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdio>
#include <list>
#include <queue>
using namespace std;

#define int long long
#define INF 1e18
#define EPS 1e-9

signed main() {
    int a, b, t; cin >> a >> b >> t;
    int ans = 0;

    for(int i = 1; i <= t + 0.5; i++) {
        if(i % a == 0) ans += b;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    int N;
    cin >> N;
    string S;
    cin >> S;
    int left=0;
    int right=N/2+1;
    while(right-left>1){
        int mid=left+(right-left)/2;
        vector<pair<string,int>> happy;
        bool can=false;
        if(mid==0)can=true;
        else{
            rep(i,N-mid+1){
                happy.push_back(make_pair(S.substr(i,mid),i));
            }
            sort(all(happy));
            for(int i=0;i<happy.size() && !can;i++){
                for(int j=i+1;j<happy.size() && !can;j++){
                    if(happy[i].first==happy[j].first){
                        if(happy[i].second+mid<=happy[j].second){
                            can=true;
                            break;
                        }
                    }
                    else{
                        break;
                    }
                }
            }
        }
        if(can)left=mid;
        else right=mid;
    }
    cout << left;

    


}

/*



 */


Measured memory_bytes: 8508
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;


int main(){
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  int dx = tx - sx, dy = ty - sy;
  
  cout << string(dx,'R') << string(dy, 'U');
  cout << string(dx, 'L')  << string(dy, 'D');
  cout << 'D' << string(dx+1, 'R') << string(dy+1,'U') << 'L';
  cout << 'U' << string(dx+1,'L') << string(dy+1,'D') << 'R';
  cout << endl;
  
 }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)
#include <string>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < (n);++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)

const ll INF = 1e9+7;

// 各桁の和
template<typename T>T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;}
template<typename T>T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

int main() {
  int n;cin>>n;
  vector<int> h(n);rep(i,n)cin>>h[i];
  vector<int> dp(n+10,1000000);
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);
  
  for(int i = 2;i < n;++i){
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1])
               ,dp[i-2]+abs(h[i]-h[i-2]));
  }
  
  print(dp[n-1]);
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    ft
    long long n,l,r,i,j,mn1,mn2,mx1,mx2;
    mn1=mn2=LLONG_MAX;
    mx1=mx2=LLONG_MIN;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>l>>r;
        mn1=min(mn1,l+r);
        mn2=min(mn2,l-r);
        mx1=max(mx1,l+r);
        mx2=max(mx2,l-r);
    }
    mx1-=mn1;
    mx2-=mn2;
    cout<<max(mx1,mx2)<<"\n";
    return 0;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
	#define lb lower_bound 
	#define ub upper_bound
	#define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define mi          map<int,int>
	#define mii         map<pi,int>
	#define vi vector<int> 
	#define vvi vector<vi>
	#define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
	#define all(c) (c).begin(),(c).end()
	#define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
	
	 const int N =5e5+5;
	
	 int mod= 1e9+7;
	 int dx[4]={0,0,+1,-1};
	 int dy[4]={+1,-1,0,0};  
	 
	 
	int po(int a, int b) {
		a %= mod;
		int res = 1;
		while (b > 0) {
			if (b & 1)
				res = (res * a) % mod;
			a =(a*a) % mod;
			b >>= 1;
		}
		 return res;	
	   }
	     

	 void solve() {	    
          string s;
          cin>>s;
          int  len=sz(s),f=0,wyn=0;
          for(int i=len-1;i>=0;i--) {
			     int nax=s[i]-'0'+f;
			     wyn+=min(nax,10-nax);
			     f=(nax>5 || (nax==5 && s[i-1]-'0'>=5));
			  }
			  cout<<wyn+f<<endl;      
		       
	 }
	
int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
	   solve();
	   
	   
	   return 0;	   
}


Measured memory_bytes: 1948
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC114A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            a = int.Parse(Console.ReadLine());
            if (a == 3 || a == 5 || a == 7)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
            Console.ReadKey();
           
        }
    }
}



Measured memory_bytes: 11092
#include<iostream>

using namespace std;

int main()
{
  int a, b, c;
  char s;
  while(true)
  {
    cin >> a >> b;
    if(!a && !b)
      break;
    c = a + b;
    s = 'A';
    for(int i = 0; i < 4; i++)
    {
      cin >> a >> b;
      if(a + b > c)
      {
       	c = a + b;
	s = 'B' + i;
      }
    }
    cout << s << " " << c << endl;
  }
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    const vector<int> group = {-1, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};

    int x, y;
    cin >> x >> y;
    if(group[x] == group[y])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define togglebit(n,i) ((n)^(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
int main(){
    fastread;
    ll n,i,j,k,l,m;
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes";
    else
        cout<<"No";

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int n,s,x;
  cin>>n>>s>>x;
  int a;
  int l=0,m=0;
  
  rep(i,s){
    cin>>a;
    if(a<x) l++;
    else m++;
  }
  
  cout<<min(l,m)<<endl;
}


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

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
int n,a[N];
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n);
	if(a[n/2+1]==a[n/2])cout<<0<<endl;
	else cout<<a[n/2+1]-a[n/2]<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main() {
  int a, b;

  cin >> a;
  cin >> b;

  int w = 0, e = 1;
  for (int i = 1; i < 999; i++) {
    w += i;
    e += i + 1;

    if (w - a == e - b) {
      int ans = w - a;
      cout << ans << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int popcount(T n) { return n ? 1 + popcount(n & (n - 1)) : 0; }
#endif
#ifdef __GNUC__
template <class T> int popcount(T n);
template <> int popcount(unsigned int n) { return n ? __builtin_popcount(n) : 0; }
template <> int popcount(int n) { return n ? __builtin_popcount(n) : 0; }
template <> int popcount(unsigned long long n) { return n ? __builtin_popcountll(n) : 0; }
template <> int popcount(long long n) { return n ? __builtin_popcountll(n) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CL(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };
bool valid_pos(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }

template <class T> void print(T a, int n, int br = 1, const string& deli = ", ") { cout << "{ "; for (int i = 0; i < n; ++i) { cout << a[i]; if (i + 1 != n) cout << deli; } cout << " }"; while (br--) cout << endl; }
template <class T> void print(const vector<T>& v, int br = 1, const string& deli = ", ") { print(v, v.size(), br, deli); }


void solve(int a, int b, int c)
{
	vector<int> p, r;
	for (int i = 1; i * i <= a; ++i)
	{
		if (a % i == 0)
		{
			p.push_back(a / i);
			r.push_back(i);
		}
	}

	if (c != 0)
	{
		vector<int> q, s;

		int cc = abs(c);
		for (int i = 1; i * i <= cc; ++i)
		{
			if (cc % i == 0)
			{
				int n = cc / i, m = i;
				if (c < 0)
					m *= -1;

				q.push_back(n);
				s.push_back(m);

				q.push_back(m);
				s.push_back(n);

				q.push_back(-m);
				s.push_back(-n);

				q.push_back(-n);
				s.push_back(-m);
			}
		}

		for (int i = 0; i < p.size(); ++i)
		{
			for (int j = 0; j < q.size(); ++j)
			{
				if (p[i] * s[j] + r[i] * q[j] == b)
				{
					printf("%d %d %d %d\n", p[i], q[j], r[i], s[j]);
					return;
				}
			}
		}
	}
	else
	{
		for (int i = 0; i < p.size(); ++i)
		{
			int q, s;
			if (b % r[i] == 0)
			{
				q = b / r[i];
				s = 0;
			}
			else if (b % p[i] == 0)
			{
				q = 0;
				s = b / p[i];
			}
			else
				continue;

			if (p[i] == r[i] && q < s)
				swap(q, s);

			printf("%d %d %d %d\n", p[i], q, r[i], s);
			return;
		}
	}

	puts("Impossible");
}
int main()
{
	int a, b, c;
	while (scanf("%d%d%d", &a, &b, &c), a)
		solve(a, b, c);
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Diagnostics;
using static System.Math;
using static System.Array;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{

    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static int N;
        static int[] A;
       
        
        
        

        public static void Input()
        {
            var cin = new Scanner();
            N = int.Parse(Console.ReadLine());
            var input = cin.SplitReader();
            A = new int[N + 2];
            for(var i = 0; i <= N + 1; i++)
            {
                if (i == 0 || i == N + 1) { A[i] = 0; }
                else { A[i] = input[i - 1]; }
            }
        }

        static void Main(string[] args)
        {
            Input();

            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            long sum = 0;
            for(var i = 0; i <= N; i++)
            {
                sum += Abs(A[i] - A[i + 1]);
            }
            int[] skip = new int[N];
            for(var i = 1; i <= N; i++)
            {
                skip[i - 1] = Abs(A[i - 1] - A[i + 1]);
            }

            for(var i = 1; i <= N; i++)
            {
                Console.WriteLine(sum - Abs(A[i - 1] - A[i]) - Abs(A[i] - A[i + 1]) + skip[i - 1]);
            }


            Console.Out.Flush();

        }





    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

    }

    public class Graph
    {
        
    }
}

    



Measured memory_bytes: 29908
#include <algorithm>
#include <iostream>
#include <cstdio>
#define N 500005
using namespace std;

int n;
long long L, qv[N];
double qt[N];

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n >> L;

    long long nowv = 0; double nowt = 0;
    int ql = 1, qr = 0;
    for (int i = 1, t, v; i <= n; ++i) {
        scanf("%d%d", &t, &v);
        while (ql <= qr && nowv + v > L) {
            long long tmp = min(qv[ql], nowv + v - L);
            qv[ql] -= tmp, nowv -= tmp, nowt -= tmp * qt[ql];
            if (!qv[ql]) ++ql;
        }
        qt[++qr] = t, qv[qr] = v;
        nowt += 1ll * t * v, nowv += v;
        while (ql < qr && qt[qr - 1] > qt[qr]) {
            qt[qr - 1] = (double) (qt[qr - 1] * qv[qr - 1] + qt[qr] * qv[qr]) / (qv[qr - 1] + qv[qr]);
            qv[qr - 1] += qv[qr], --qr;
        }
        printf("%.7lf\n", (double) nowt / L);
    }

    return 0;
}


Measured memory_bytes: 16896
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int calc(int n[4], int op[3]) {
	int sum;
	int i;
	sum = n[0];
	for(i = 0; i < 3; i += 1) {
		if(op[i] == 0) {
			sum += n[i + 1];
		} else {
			sum -= n[i + 1];
		}
	}
	return sum;
}

void print_ans(int n[4], int op[3]) {
	int i;
	for(i = 0; i < 3; i += 1) {
		printf("%d", n[i]);
		if(op[i] == 0) {
			printf("+");
		} else {
			printf("-");
		}
	}
	printf("%d=7\n", n[3]);
}

int main(void) {
	int i, j, k;
	int if_seven;
	int op[3] = {0, 0, 0};//0:+, 1:-
	int n[4];
	char buf[128], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	i = atoi(ch);
	n[0] = i / 1000;
	i -= 1000 * n[0];
	n[1] = i / 100;
	i -= 100 * n[1];
	n[2] = i / 10;
	i -= 10 * n[2];
	n[3] = i;

	if_seven = 0;
	for(i = 0; i < 2; i += 1) {
		op[0] = i;
		for(j = 0; j < 2; j += 1) {
			op[1] = j;
			for(k = 0; k < 2; k += 1) {
				op[2] = k;
				if(calc(n, op) == 7) {
					print_ans(n, op);
					return 0;
				}
			}
		}
	}

	return 0;
}


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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) if((x)>(y))(x)=(y)
#define chmax(x,y) if((x)<(y))(x)=(y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, m, p[100100], x, y;
pii r[100100];

struct UF {
	vector<int> p;
	UF(int n) : p(n, -1) {};
	bool unite(int u, int v) {
		if ((u = find(u)) == (v = find(v))) return false;
		if (p[u] > p[v]) swap(u, v);
		p[u] += p[v]; p[v] = u;
		return true;
	}
	bool same(int u, int v) { return find(u) == find(v); }
	int find(int u) { return p[u] < 0 ? u : p[u] = find(p[u]); }
	int usize(int u) { return -p[find(u)]; }
};

signed main() {
	cin >> n >> m;
	rep(i,n) {
		cin >> p[i];
		r[i] = mp(p[i],i);
	}
	sort(r,r+n);
	UF uf(n+3);
	rep(i,m) {
		cin >> x >> y;
		uf.unite(x,y);
	}
	int res = 0;
	rep(i,n) if (p[i]==i+1 || uf.same(i+1,p[i])) res++;
	cout << res << ln;
}

Measured memory_bytes: 1792
local mfl, mce, mmi = math.floor, math.ceil, math.min
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    for j = 1, self.cnt[i] do
      self.stage[i][j] = self.func(self.stage[i + 1][j * 2 - 1], self.stage[i + 1][j * 2])
    end
  end
end
SegTree.create = function(self, ary, func, emptyvalue)
  self.func, self.emptyvalue = func, emptyvalue
  local stagenum, mul = 1, 1
  self.cnt, self.stage, self.size = {1}, {{}}, {}
  while mul < #ary do
    mul, stagenum = mul * 2, stagenum + 1
    self.cnt[stagenum], self.stage[stagenum] = mul, {}
  end
  for i = 1, stagenum do self.size[i] = self.cnt[stagenum + 1 - i] end
  self.stagenum = stagenum
  for i = 1, #ary do self.stage[stagenum][i] = ary[i] end
  for i = #ary + 1, mul do self.stage[stagenum][i] = emptyvalue end
  self:updateAll()
end
SegTree.getRange = function(self, left, right)
  if left == right then return self.stage[self.stagenum][left] end
  local start_stage = 1
  while right - left + 1 < self.size[start_stage] do
    start_stage = start_stage + 1
  end
  local ret = self.emptyvalue
  local t1, t2, t3 = {start_stage}, {left}, {right}
  while 0 < #t1 do
    local stage, l, r = t1[#t1], t2[#t1], t3[#t1]
    table.remove(t1) table.remove(t2) table.remove(t3)
    local sz = self.size[stage]
    if (l - 1) % sz ~= 0 then
      local newr = mmi(r, mce((l - 1) / sz) * sz)
      table.insert(t1, stage + 1) table.insert(t2, l) table.insert(t3, newr)
      l = newr + 1
    end
    if sz <= r + 1 - l then
      ret = self.func(ret, self.stage[stage][mce(l / sz)])
      l = l + sz
    end
    if l <= r then
      table.insert(t1, stage + 1) table.insert(t2, l) table.insert(t3, r)
    end
  end
  return ret
end
SegTree.recalc = function(self, idx)
  for i = self.stagenum - 1, 1, -1 do
    local dst = mce(idx / 2)
    local rem = dst * 4 - 1 - idx
    self.stage[i][dst] = self.func(self.stage[i + 1][idx], self.stage[i + 1][rem])
    idx = dst
  end
end
SegTree.new = function(ary, func, emptyvalue)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(ary, func, emptyvalue)
  return obj
end

local n, m = io.read("*n", "*n")
local t = {}
local c = {}
for i = 1, n do
  t[i] = io.read("*n")
  c[i] = 1
end
local tary = {}
for i = 1, n do tary[i] = i end
local st = SegTree.new(tary, function(x, y)
  if x == 0 then
    return y
  elseif y == 0 then
    return x
  else
    if t[x] * c[y] < t[y] * c[x] then
      return y
    else
      return x
    end
  end
end, 0)

for i = 1, m do
  local top = st.stage[1][1]
  c[top] = c[top] * 2
  st:recalc(top)
end
local ret = 0
for i = 1, n do
  ret = ret + mfl(t[i] / c[i])
end
print(ret)


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

int main() {
  int y, m, d;
  scanf("%d/%d/%d", &y, &m, &d);
  if (y > 2019) puts("TBD");
  else if (m > 4) puts("TBD");
  else if (d > 30) puts("TBD");
  else puts("Heisei");
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	while(n-->0){
		double x1,x2,x3,x4,y1,y2,y3,y4;
		cin >>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
		double xa = x2-x1;
		double xb = x4-x3;
		double ya = y2-y1;
		double yb = y4-y3;
		if(abs(xa*yb-xb*ya)<0.0000000001) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

Measured memory_bytes: 1224