akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
int d5=100100;
int h,w;
string s[22];
int dist[22][22];
int res=0;
void bfs(int sy,int sx){
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            dist[i][j]=-1;
        }
    }
    queue<pair<int,int>> Q;
    Q.push(make_pair(sy,sx));
    dist[sy][sx]=0;
    bool flag=true;
    while(!Q.empty()){
        auto now=Q.front();
        Q.pop();
        int y=now.first;
        int x=now.second;
        for(int i=0;i<4;i++){
            int ny=y+dy[i];
            int nx=x+dx[i];
            if(ny<0||nx<0||ny>=h||nx>=w)continue;
            if(s[ny][nx]=='#')continue;
            if(dist[ny][nx]!=-1)continue;
            dist[ny][nx]=dist[y][x]+1;
            Q.push(make_pair(ny,nx));
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            res=max(res,dist[i][j]);
        }
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>h>>w;
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
                if(s[i][j]=='.')bfs(i,j);
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    int H, W; cin >> H >> W;
    vector<string> S(H); readv(S);

    if(W == 1){
        vec cnt(26, 0);
        REP(j, H) cnt[S[j][0] - 'a']++;
        int o = 0;
        REP(j, 26) if(cnt[j] % 2 == 1) o++;
        if(o <= 1){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
        return 0;
    }

    int n = W / 2;
    vec p(n, 0), per(W);
    vector<bool> used(H);
    while(p[0] < 2 * n - 1){

        REP(c, W){
            vec v(W);
            REP(i, W) v[i] = i;
            if(W % 2 == 1){
                per[W / 2] = c;
                v.erase(v.begin() + c);
            }
            REP(i, n){
                int j1 = v[0];
                v.erase(v.begin());
                int j2 = v[p[i]];
                v.erase(v.begin() + p[i]);
                per[i] = j1;
                per[W - 1 - i] = j2; 
            }

            fill(used.begin(), used.end(), false);
            int np = 0;
            REP(i, H){
                if(!used[i]){
                    FOR(j, i + 1, H){
                        bool tmp = true;
                        REP(k, W) if(S[i][per[k]] != S[j][per[W - 1 - k]]) tmp = false;
                        if(tmp){
                            np++;
                            used[i] = true;
                            used[j] = true;
                            break;
                        }
                    }
                }
            }
            if(np == H / 2){
                if(H % 2 == 0){
                    cout << "YES" << endl;
                    return 0;
                }else{
                    bool tmp = true;
                    REP(i, H) if(!used[i]){
                        REP(k, W) if(S[i][per[k]] != S[i][per[W - 1 - k]]) tmp = false;
                    }
                    if(tmp){
                        cout << "YES" << endl;
                        return 0;
                    }
                }
            }
        }

        p[n - 1]++;
        IFOR(i, 1, n) if(p[i] >= 2 * n - 1 - 2 * i){
            p[i] = 0;
            p[i - 1]++;
        }
    }
    cout << "NO" << endl; 
    
    return 0;
}

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

int a[100000][3], dp[100000][3];

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

	int n;
	cin >> n;
	for(int i=0; i<n; ++i)
		for(int j=0; j<3; ++j)
			cin >> a[i][j];
	for(int j=0; j<3; ++j)
		dp[0][j]=a[0][j];
	for(int i=1; i<n; ++i) {
		for(int j=0; j<3; ++j) {
			int mx=0;
			for(int k=0; k<3; ++k)
				if(k!=j)
					mx=max(dp[i-1][k], mx);
			dp[i][j]=mx+a[i][j];
		}
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}


Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i += 2) {
        cout << s[i];
    }
    cout << endl;
}




Measured memory_bytes: 3712
#include<cstdio>
#include<algorithm>
using namespace std;
const int Maxn=100;
int N;
int A[Maxn+5];
bool vis[Maxn+5];
int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d",&A[i]);
	int ans=0;
	if(N==2) {
		if(A[1]==A[2])puts("1");
		else puts("0");
		return 0;
	}
	for(int i=2;i<N;i++) {
		if((A[i-1]==A[i]&&!vis[i-1])&&!vis[i]) {
			ans++;
			vis[i-1]=vis[i]=true;
		}
		if((A[i]==A[i+1]&&!vis[i+1])&&!vis[i]) {
			ans++;
			vis[i+1]=vis[i]=true;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

string L;

Int dp[100000+10][2];

int main(void) {
    cin>>L;

    dp[0][0] = 1;
    for(int i = 0;i < L.size();i++) {
        if(L[i] == '1') {
            //a+b == 0
            dp[i+1][1] += (dp[i][0]+dp[i][1])%MOD;
            //a+b == 1
            dp[i+1][0] += dp[i][0]*2%MOD;
            dp[i+1][1] += dp[i][1]*2%MOD;
        } else {
            //a+b == 0
            dp[i+1][1] += dp[i][1];
            dp[i+1][0] += dp[i][0];
            //a+b == 1
            dp[i+1][1] +=dp[i][1]*2%MOD;

        }
    }

    cout<<(dp[L.size()][0]+dp[L.size()][1])%MOD<<endl;

    return 0;
}


Measured memory_bytes: 2048
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int a,b,c,d,e,f,i,j,s[10010],w[10010],x=1,y=0;
  scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
  for(i=0;i<f;i++)s[i+1]=w[i+1]=0;
  s[0]=w[0]=1;
  x=a*100;
  for(i=0;i*100<=f;i++){
    // printf("%d\n",w[i]);
    if(w[i])w[i+a]=w[i+b]=1;
  }
  for(i=0;i<=f;i++){
    //printf("%d ",s[i]);
    if(s[i])s[i+c]=s[i+d]=1;
  }//printf("\n");
  for(i=a;i*100<=f;i++){
    if(w[i]==0)continue;
    for(j=0;j<=f;j++){
      if(s[j]==0)continue;
      if(j>i*e||i*100+j>f)continue;
      if((i*100+j)*y<(x+y)*j){
	x=i*100;
	y=j;
      }
    }
  }
  printf("%d %d\n",x+y,y);
  return 0;
}


Measured memory_bytes: 256
n,m,x = map(int,input().split())

A=[0]*n
c=[0]*n

for i in range(n):
    A[i] = list(map(int,input().split()))

for i in range(n):
    c[i]= A[i][0]
    A[i] = A[i][1:]

import numpy as np
import sys

a = np.array(A)

ans = np.inf

for s in range(1<<n):
    cost = 0
    d = np.array([0]*m)
    for i in range(n):
        if s>>i&1:
            cost += c[i]
            d += a[i]
    if all(d >= x):
        ans = min(ans,cost)

print(ans if ans != np.inf else '-1')


Measured memory_bytes: 27316
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll H,N;
  cin>>H>>N;
  ll A[N],B[N];
  REP(i,N) cin>>A[i]>>B[i];
  
  ll DP[H+10]; // DP[i]=体力をi減らすのに必要な最小の魔力
  REP(i,H+10) DP[i]=INF;
  DP[0]=0;
  
  REP(i,N){
    for(ll j=0; j<=H; ++j){
      chmin(DP[j],DP[max(j-A[i],0ll)]+B[i]);
    }
  }
  
  co(DP[H]);
  return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////


void solve() {
	int N; cin >> N;
	vi vx(N), vy(N);
	rep(i, 0, N) {
		cin >> vx[i] >> vy[i];
	}
	vi ord(N);
	rep(i, 0, N) ord[i] = i;

	double ans = 0.0;
	do {
		rep(i, 0, N - 1) {
			int x1 = vx[ord[i]], y1 = vy[ord[i]];
			int x2 = vx[ord[i + 1]], y2 = vy[ord[i + 1]];
			ans += sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
		}
	} while(next_permutation(all(ord)));
	rep(i, 0, N) {
		ans /= i + 1;
	}
	cout << ans << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>

struct weighted_union_find {
	long long N;					// the number of nodes
	long long M;					// the number of trees
	std::vector<long long> parent;	// parent[i] := the direct parent of i
	std::vector<long long> size;	// size[i] := the number of nodes in the tree containing i
	std::vector<long long> weight;	// weight[i] := the weight of the edge from i to parent[i]

	weighted_union_find(long long n) : N(n), M(n) {
		parent.resize(n, -1);
		size.resize(n, 1);
		weight.resize(n, 0);
	}

	long long weight_sum_to_root(long long i) {
		if (parent[i] == -1) return 0;
		else return weight[i] + weight_sum_to_root(parent[i]);
	}

	long long root(long long i) {
		if (parent[i] == -1) return i;
		long long x = root(parent[i]);
		weight[i] += weight[parent[i]];
		return parent[i] = x;
	}

	bool is_united(long long i, long long j) {
		return (root(i) == root(j));
	}

	long long dist(long long i, long long j) {
		if (!is_united(i, j)) return LLONG_MAX;
		else return weight_sum_to_root(j) - weight_sum_to_root(i);
	}

	// false : detected confliction
	bool unite(long long i, long long j, long long w) {
		w += weight_sum_to_root(i) - weight_sum_to_root(j);
		i = root(i); j = root(j);
		if (i == j) return (w == 0);
		if (size[i] < size[j]) {
			std::swap(i, j);
			w *= -1;
		}
		parent[j] = i;
		size[i] += size[j];
		weight[j] = w;
		return true;
	}
};

int main() {
	long long n, q;
	std::cin >> n >> q;
	weighted_union_find uf(n);
	while (q--) {
		long long w, x, y;
		std::cin >> w >> x >> y;
		if (w == 0) {
			long long z;
			std::cin >> z;
			uf.unite(x, y, z);
		} else {
			long long d = uf.dist(x, y);
			if (d == LLONG_MAX) std::cout << "?\n";
			else std::cout << d << '\n';
		}
	}
}


Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int n;
int a[200100];
int digit;
stack<i_i> now;

void printer(){
    stack<i_i> sub;
    while(!now.empty()){
        sub.push(now.top());
        now.pop();
    }
    while(!sub.empty()){
        cout << sub.top().first << " " << sub.top().second << endl;
        now.push(sub.top());
        sub.pop();
    }
}

bool add(int digit_now, int maxi){
    if(maxi == 0) return false;
    //cout << "add to " << digit_now << endl;
    //printer();
    if(now.empty()){
        now.push({digit_now, 1});
        return true;
    }
    if(now.top().first < digit_now){
        now.push({digit_now, 1});
        return true;
    }
    if(now.top().second < maxi){
        int New = now.top().second + 1;
        now.pop();
        now.push({digit_now, New});
        return true;
    }
    if(digit_now == 1){
        //cout << "Failed " << maxi << endl;
        return false;
    }
    now.pop();
    return add(digit_now - 1, maxi);
}

bool checker(int maxi){
    //cout << endl << endl << endl << maxi << endl;
    digit = 0;
    while(!now.empty()) now.pop();
    for(int i = 1; i <= n; i++){
        //cout << endl << i << endl << endl;
        //printer();
        if(a[i] > digit){
            digit = a[i];
            continue;
        }
        digit = a[i];
        while(!now.empty()){
            i_i next = now.top();
            if(next.first <= digit) break;
            now.pop();
        }
        if(!add(digit, maxi)) return false;
    }
    return true;
}

int main() {
    //cout.precision(10);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int ok = n;
    int ng = 0;
    while(ok - ng > 1){
        int mid = (ok + ng) / 2;
        if(checker(mid - 1)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 998244353;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

const int MAX = 3e5+1;
const int MOD = 998244353;

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

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

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

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    COMinit();

    ll N,A,B,K;
    cin >> N >> A >> B >> K;
    ll ans = 0;
    for(ll i=0;i<=N;i++){
        ll np = A*i;
        if(np>K)break;
        if( (K-np) % B == 0 ){
            ans += COM(N,i) * COM(N,(K-np)/B);
            ans %= mod;
        }
    }
    cout << ans << endl;
}

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

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto A = H.iota.map!(_ => readln.split.to!(long[])).array;

    auto dp = new long[][][](H+W-1, H, H);
    dp[0][0][0] = A[0][0];

    foreach (i; 0..H+W-2) {
        foreach (r1; 0..H) {
            foreach (r2; 0..H) {
                int c1 = i - r1;
                int c2 = i - r2;
                if (c1 < 0 || c2 < 0 || c1 >= W || c2 >= W) continue;
                foreach (j; 0..2) {
                    foreach (k; 0..2) {
                        int nr1 = r1 + j;
                        int nc1 = c1 + 1 - j;
                        int nr2 = r2 + k;
                        int nc2 = c2 + 1 - k;
                        if (nr1 >= H || nc1 >= W || nr2 >= H || nc2 >= W) continue;
                        if (nr1 == nr2 && nc1 == nc2) {
                            dp[i+1][nr1][nr2] = max(dp[i+1][nr1][nr2], dp[i][r1][r2] + A[nr1][nc1]);
                        } else {
                            dp[i+1][nr1][nr2] = max(dp[i+1][nr1][nr2], dp[i][r1][r2] + A[nr1][nc1] + A[nr2][nc2]);
                        }
                    }
                }
            }
        }
    }

    dp[H+W-2].map!(d => d.reduce!max).reduce!max.writeln;
}


Measured memory_bytes: 171132
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int INF = 1e9;
const int MOD = INF+7;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define all(v) v.rbegin(),v.rend()
#define MP make_pair
#define pb push_back
using P = pair<int,int>;
//c

signed main(){
    int N;
    string S,T;
    cin >> N >> S;
    T = S;

    int ans = INF,res = 0;
    vector<int> B(N+1,0),W(N+1,0);
    for(int i=0;i<N;i++){
        if(S[i] == '#') B[i+1]++;
        if(S[i] == '.') W[i+1]++;
        B[i + 1] += B[i];
        W[i + 1] += W[i];
    }

    for(int i=0;i<N+1;i++){
        res = B[i] + (W[N] - W[i]);
        ans = min(ans,res);
    }


    cout << ans << endl;
}


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

int main(void) {
	int n; cin >> n;
	vll a(n),b(n);
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> b[i];
	vi c(n); rep(i,n) c[i]=b[i]-a[i];
	ll pos=0;
	ll neg=0;
	rep(i,n){
		if(c[i]>0) pos+=c[i]/2;
		else neg += c[i];
	}
	 if(pos+neg>=0) cout << "Yes" << endl;
	else cout << "No" << endl;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n, k; cin >> n >> k;
	int p[n];
	rep(i,n) {
		cin >> p[i];
		p[i] = p[i] + 1;
	}
	double sum = 0;
	for(int i = 0; i < k; ++i) {
		sum += p[i];
	}
	double ans = 0;
	for(int i = k; i < n; ++i) {
		ans = max(ans, sum / 2.0);
		sum -= p[i - k];
		sum += p[i];
	}
	ans = max(ans, sum / 2.0);
	printf("%.10f\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

int simulate(int j, const std::string &arrayChar,
             const std::vector<char> &queryChar,
             const std::vector<char> &queryDirection) {
  const int numArray = arrayChar.length() - 1;
  const int numQuery = queryChar.size() - 1;
  assert(numQuery == static_cast<int>(queryDirection.size()) - 1);
  assert(1 <= j and j <= numArray);
  // move j by queries
  for (int i = 1; i <= numQuery; ++i) {
    // query hit
    if (queryChar[i] == arrayChar[j]) {
      switch (queryDirection[i]) {
      case 'L': // move left
        if (j == 1)
          return -1;
        --j;
        break;
      case 'R': // move right
        if (j == numArray)
          return +1;
        ++j;
        break;
      default:
        assert(false);
      }
    }
  }
  return 0;
}

int main() {
  // Input
  int numArray; // index: j
  int numQuery; // index: i
  std::cin >> numArray >> numQuery;
  assert(1 <= numArray and numArray <= 2 * 1.0e+5);
  assert(1 <= numQuery and numQuery <= 2 * 1.0e+5);
  std::string arrayChar;
  std::cin >> arrayChar;
  arrayChar.insert(arrayChar.begin(), '-');
  assert(static_cast<int>(arrayChar.length()) == 1 + numArray);
  std::vector<char> queryChar(1 + numQuery);
  std::vector<char> queryDirection(1 + numQuery);
  for (int i = 1; i <= numQuery; ++i) {
    std::cin >> queryChar[i] >> queryDirection[i];
    assert(queryDirection[i] == 'L' or queryDirection[i] == 'R');
  }

  // left drop
  int ng = numArray + 1;
  int ok = 0;
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (simulate(mid, arrayChar, queryChar, queryDirection) == -1)
      ok = mid;
    else
      ng = mid;
  }
  assert(abs(ok - ng) == 1);
  const int leftDrop = ok;

  // right drop
  ng = 0;
  ok = numArray + 1;
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (simulate(mid, arrayChar, queryChar, queryDirection) == +1)
      ok = mid;
    else
      ng = mid;
  }
  assert(abs(ok - ng) == 1);
  const int rightDrop = ok;

  std::cout << rightDrop - leftDrop - 1 << std::endl;

  return 0;
}


Measured memory_bytes: 900
import sys
readline = sys.stdin.readline
import numpy as np
N = int(input())
S = np.array(list('-'+readline()),dtype='U1')
Q = int(input())
query = map(int,input().split())

isD = S == 'D'
isM = S == 'M'
isC = S == 'C'

cumD = isD.cumsum(dtype=np.int64)
cumM = isM.cumsum(dtype=np.int64)

for K in query:
    x = cumD.copy(); x[K:] -= cumD[:-K]
    x *= isM
    x[K+1:] -= isD[1:-K] * (cumM[K:-1] - cumM[:-K-1])
    print((x.cumsum() * isC).sum())


Measured memory_bytes: 58432
<?php

fscanf(STDIN, "%d", $num);
$single_num = substr($num, -1, 1);
if (
    $single_num == '2' || $single_num == '4' || $single_num == '5'
    || $single_num == '7' || $single_num == '9'
) {
    echo 'hon';
} elseif (
    $single_num == '0' || $single_num == '1' || $single_num == '6' || $single_num == '8'
) {
    echo 'pon';
} else {
    echo 'bon';
}


Measured memory_bytes: 16192
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  n <- readLn
  print $ g n

f :: Int -> V.Vector (Int,Int)
f n = V.fromList [(x, n-x) | x <- [1..((n+1) `div` 2)]]

sod
  :: Int -> Int
sod n
  | q == 0 = r 
  | otherwise = r + sod q
  where
    (q,r) = quotRem n 10

sod2
  :: Int -> Int -> Int
sod2 x y = sod x + sod y

g :: Int -> Int
g = V.minimum . V.map (uncurry sod2) . f

Measured memory_bytes: 892
<?php
    $input_line = trim(fgets(STDIN));
    
    $ans = explode(" ",$input_line);
    
    //print_r($ans);
    
    $t_mons_ps = $ans[0];
    $t_mons_at = $ans[1];
    $a_mons_ps = $ans[2];
    $a_mons_at = $ans[3];
    
    $i=0;
    while($t_mons_ps > 0 or $a_mons_ps > 0){
        $r[$i] = ($a_mons_ps -= $t_mons_at);
        $t[$i] = "takahashi";
        if($r[$i] <= 0){
            break;
        }else{
            $r[$i+1] = ($t_mons_ps -= $a_mons_at);
            $t[$i+1] = "aoki";
            if($r[$i+1] <= 0){
                break;
            }else{
                $i++;
            }
        }
        $i++;
    }

    if($t[count($t)-1] == 'takahashi'){
        echo "Yes";
    }elseif($t[count($t)-1] == "aoki"){
        echo "No";
    }
?>

Measured memory_bytes: 16132
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>

using namespace std;

#define int long long
typedef long double ld;
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<vi>
#define viii vector<vii>
#define vpii vector<pii>
#define vb vector<bool>
#define vbb vector<vb>
#define vs vector<string>
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define in(a, x) for (int i = x; i < (a).size(); ++i) cin >> (a)[i]
#define out(a) for (auto qwe : a) cout << qwe << " "

const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int MOD3 = 998244353;
const int P = 37;

const int mxn = 200000;

struct SegTree {
    vi t;
    int m = 1;

    SegTree (int n) {
        while (m < n) m <<= 1;
        t.assign(2 * m, 0);
    }

    void set(int id, int x) {
        int j = id + m;
        t[j] = x;
        while (j > 1) {
            j >>= 1;
            t[j] = max(t[j << 1], t[(j << 1) + 1]);
        }
    }

    int fmax(int v, int tl, int tr, int l, int r) {
        if (tl > r || tr < l) return 0;

        if (tl >= l && tr <= r) {
            return t[v];
        }

        int mid = (tl + tr) >> 1;

        return max(fmax(v << 1, tl, mid, l, r), fmax((v << 1) + 1, mid + 1, tr, l, r));
    }

    int fmax(int l, int r) {
        return fmax(1, 1, m, l + 1, r + 1);
    }
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

    vi h(n), b(n);
    in(h, 0);
    in(b, 0);

    SegTree t(n);

    for (int j = 0; j < n; ++j) {
        t.set(h[j] - 1, t.fmax(0, h[j] - 1) + b[j]);
    }

    cout << t.t[1];
}


Measured memory_bytes: 7552
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;


int main(){
  int H, W, M; cin >> H >> W >> M;
  int row[H]={}, col[W]={};
  set<pii> s;
  int r_max = 0, c_max = 0;
  rep(i,M){
    int h, w; cin >> h >> w;
    h--, w--;
    s.insert({h,w});
    row[h]++;
    col[w]++;
    chmax(r_max, row[h]);
    chmax(c_max, col[w]);
  }
  ll cnt_r = 0, cnt_c = 0;
  rep(i,H) if (row[i]==r_max) cnt_r++;
  rep(i,W) if (col[i]==c_max) cnt_c++;

  int cnt_b = 0;
  for (auto p : s){
    int r = p.first, c = p.second;
    if (row[r]==r_max && col[c]==c_max) cnt_b++;
  }
  if (cnt_r*cnt_c>cnt_b) cout << r_max+c_max << endl;
  else cout << r_max + c_max - 1 << endl;




  // cout << fixed << setprecision(10);
  
  return 0;
}

Measured memory_bytes: 20008
#include<stdio.h>
int main(){
  int N,A[1000],i,j,z,k;
 
    scanf("%d",&N);
    for(i=0; i<N; i++){
      scanf("%d",&A[i]);
    }
    for(k=0; k<N; k++){
      if(k==N-1)printf("%d",A[k]);
      else printf("%d ",A[k]);
    }
    printf("\n");
    for(i=1; i<=N-1; i++){
      z=A[i];
      j=i-1;
      while(j>=0 && A[j]>z){
	A[j+1]=A[j];
	j--;
	A[j+1]=z;
      }
      for(k=0; k<N; k++){
	if(k==N-1)printf("%d",A[k]);
	else printf("%d ",A[k]);
      }
      printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] s = sc.next().split("");
		if(s.length ==1) {
			System.out.println("0");
			return;
		}
		int answer1 =0;
		int answer2 =0;
		int tile1=0;
		for(int i =0;i <s.length;i++) {
			if(Integer.parseInt(s[i]) !=tile1) {
				answer1++;
			}else {
				answer2++;
			}
			if(tile1 ==0) {
				tile1 =1;
			}else {
				tile1 =0;
			}
		}
		if(answer1 < answer2) {
			System.out.println(answer1);
		}else {
			System.out.println(answer2);
		}
	}
}

Measured memory_bytes: 34084
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){ 
    int a, b, c, d; cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << ln;
}

Measured memory_bytes: 256
import sys, os

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

def solve():
    n, m = f()
    g = [ f() for i in range(m)]

    dm = [0] * (n+2)

    for x,y in g:
        dm[x] += 1
        dm[y+1] -= 1

    cnt = 0

    
    for i in range(1, n+1):
        dm[i] = dm[i] + dm[i-1]
        if dm[i] == m:
            cnt += 1

    print(cnt)


solve()


Measured memory_bytes: 31344
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

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

	int n = s.size();

	stack<char> st;
	rep (i, n) {
		if (st.size() == 0) {
			st.push(s[i]);
		}
		else {
			if (st.top() != s[i]) st.pop();
			else st.push(s[i]);
		}
	}
	cout << n - st.size() << endl;
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using ll = long long;
vector<int> lis(200005, 1e9), G[200005];
int ans[200005], a[200005];
void DFS(const int& v, stack<pair<int, int>>& s) {
	int k = lower_bound(lis.begin(), lis.end(), a[v]) - lis.begin();
	s.push({k, lis[k]});
	lis[k] = a[v];
	ans[v] = lower_bound(lis.begin(), lis.end(), 1e9) - lis.begin();
	for (auto nv : G[v]) {
		if (ans[nv] == 0) DFS(nv, s);
	}
	int p = s.top().first, q = s.top().second;
	s.pop();
	lis[p] = q;
	return;
}
int main() {
	int n;
	scanf("%d", &n);
	rep(i, n) scanf("%d", &a[i]);
	rep(i, n - 1) {
		int u, v;
		scanf("%d%d", &u, &v);
		u--, v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	stack<pair<int, int>> s;
	DFS(0, s);
	rep(i, n) printf("%d\n", ans[i]);
	return 0;
}


Measured memory_bytes: 29444
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

const int MAXN = 200010;
const u64 MOD = 1000000007;
const f80 MI = f80(1)/MOD;
const int INF = 1000000010;

int n;
int a[MAXN], b[MAXN];
ll ans;

int main()
{
	
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i)
		scanf("%d", &a[i]);
	sort(a+1, a+n+1);
	int L = 2, R = n;
	int x, y;
	x = y = n/2+1;
	b[x] = a[1];
	while (L <= R)
	{
		if (L <= R)
		{
			b[-- x] = a[R];
			R --;
		}
		if (L <= R)
		{
			b[++ y] = a[R];
			R --;
		}
		if (L <= R)
		{
			b[-- x] = a[L];
			L ++;
		}
		if (L <= R)
		{
			b[++ y] = a[L];
			L ++;
		}
	}
	ans = 0;
	for (int i = x; i < y; ++ i)
		ans += abs(b[i+1]-b[i]);
	ll ans1 = ans;
	
	reverse(a+1, a+n+1);
	L = 2, R = n;
	x = y = n/2+1;
	b[x] = a[1];
	while (L <= R)
	{
		if (L <= R)
		{
			b[-- x] = a[R];
			R --;
		}
		if (L <= R)
		{
			b[++ y] = a[R];
			R --;
		}
		if (L <= R)
		{
			b[-- x] = a[L];
			L ++;
		}
		if (L <= R)
		{
			b[++ y] = a[L];
			L ++;
		}
	}
	ans = 0;
	for (int i = x; i < y; ++ i)
		ans += abs(b[i+1]-b[i]);
	ll ans2 = ans;
	cout << max(ans1, ans2) << endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int H, W;

int dp[80][80][80 * 160 + 1];

struct P {
  int x, y;
};

int main() {
  cin >> H >> W;
  vector<vector<int>> A(H, vector<int>(W)), B(H, vector<int>(W));
  rep(i, H) rep(j, W) cin >> A[i][j];
  rep(i, H) rep(j, W) cin >> B[i][j];

  dp[0][0][0] = 1;
  rep(i, H) rep(j, W) {
    int d = abs(A[i][j] - B[i][j]);
    rep(k, 80 * 160 + 1) {
      if (dp[i][j][k]) {
        if (i + 1 < H) {
          dp[i + 1][j][abs(k - d)] = 1;
          dp[i + 1][j][k + d] = 1;
        }
        if (j + 1 < W) {
          dp[i][j + 1][abs(k - d)] = 1;
          dp[i][j + 1][k + d] = 1;
        }
      }
    }
  }

  int ans = 1e9;
  int d = abs(A[H - 1][W - 1] - B[H - 1][W - 1]);
  rep(k, 80 * 160 + 1) {
    if (dp[H - 1][W - 1][k]) ans = min(ans, abs(k - d));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 318720
fun main() {
    val n = readLine()!!.toInt()
    var ac = 0
    var wa = 0
    var tle = 0
    var re = 0
    Array(n){
        val tmp = readLine()
        if(tmp == "AC"){
            ac++
        }else if(tmp == "WA"){
            wa++
        }else if(tmp == "TLE"){
            tle++
        }else{
            re++
        }
    }
        println("AC x $ac")
        println("WA x $wa")
        println("TLE x $tle")
        println("RE x $re")
}

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

int main() {
  int N;
  scanf("%d", &N);
  for (auto i=0; i<N; i++) {
    int c[9];
    for (auto i=0; i<9; i++) {
      scanf("%x", &c[i]);
    }
    int key = 0;
    for (auto i=0; i<32; i++) {
      int sum = 0;
      for (auto j=0; j<8; j++) {
	sum += c[j];
      }
      if ((sum >> i & 1) != (c[8] >> i & 1)) {
	key = key | (1 << i);
      }
      for (auto j=0; j<9; j++) {
	c[j] = c[j] ^ (key & 1 << i);
      }
    }
    printf("%x\n", key);
  }
  return 0;
}

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

int main(void)
{
  int a,b,i,sum;
  while(scanf("%d%d",&a,&b)!=EOF){
    i=0;
    sum=a+b;
    do{
      sum=sum/10;
      i++;
    }while(sum>0);
    printf("%d\n",i);
  }
  
  
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

const ll mod = 1000000007;

ll fc(vector<pair<ll, bool>> &all, int k, int nouseindex, int add){
  int n = all.size();
  ll ret = 1;
  rrep2(i, n-k, n){
    if(i == nouseindex) continue;
    ret *= all.at(i).first;
    ret %= mod;
  }
  ret *= add;
  ret %= mod;
  return ret;
}

int main(){
  int n, k;
  cin >> n >> k;
  vector<ll> plv, miv;
  vector<pair<ll, bool>> all;
  int pl = 0, mi = 0;
  rep(i, n){
    ll in;
    cin >> in;
    if(in >= 0){
      all.push_back({in, true});
      pl++;
    }else{
      miv.push_back(in*-1);
      all.push_back({in*-1, false});
      mi++;
    }
  }
  sort(miv.begin(), miv.end());
  sort(all.begin(), all.end());
  if(k % 2 == 1 && pl == 0){//必ず負
    ll ans = 1;
    rep(i, k){
      ans *= miv.at(i);
      ans %= mod;
    }
    ans = mod - ans;
    ans %= mod;
    cout << ans << endl;
    return 0;
  }
  ll ans = 1;
  pl = 0, mi = 0;
  int mindex = -1, pindex = -1;
  rrep2(i, n-k, n){
    ans *= all.at(i).first;
    ans %= mod;
    if(all.at(i).second == true){
      pl++;
      pindex = i;
    }else{
      mi++;
      mindex = i;
    }
  }
  if(mi % 2 == 0 || n == k){
    if(mi % 2 == 1){
      ans = mod - ans;
      ans %= mod;
    }
    cout << ans << endl;
    return 0;
  }
  int smindex = -1, spindex = -1;
  rrep(i, n-k){
    if(smindex == -1 && all.at(i).second == false) smindex = i;
    if(spindex == -1 && all.at(i).second == true) spindex = i;
  }
  if((smindex == -1) || (pindex == -1) || (spindex != -1 &&  all.at(pindex).first * all.at(spindex).first > all.at(mindex).first * all.at(smindex).first)){
    ans = fc(all, k, mindex, all.at(spindex).first);
  }else{
    ans = fc(all, k, pindex, all.at(smindex).first);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9228
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

template <typename T>
T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }

int main() {
	int X;
	cin >> X;
	cout << 360 / gcd(X, 360) << "\n";

	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    int k;
    cin >> k;
    int a, b;
    cin >> a >> b;
    string ans = "NG";
    for (int i=a; i<=b; i++) {
        if (i%k==0) ans = "OK";
    }

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


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(co) begin(co), end(co)

signed main() {
	int n, m, h, k; 
	while (cin >> n >> m >> h >> k && n) {
		vector<int> ss(n);
		rep(i, n) cin >> ss[i];
		vector<P> as(m);
		rep(i, m) cin >> as[i].second >> as[i].first;
		sort(all(as));

		vector<int> v(n);
		vector<P> rs(m);
		rep(i, n) v[i] = i;
		int tmp = 0;
		rep(i, m) {
			int a = as[i].second;
			swap(v[a - 1], v[a]);
			rs[i] = P(v[a - 1], v[a]);
		}
		vector<int> ns(n);
		rep(i, n) ns[v[i]] = ss[i];

		int sum = 0;
		rep(i, k) sum += ns[i];
		int ans = sum;
		for (P p : rs) {
			int a = p.first, b = p.second;
			if (a > b) swap(a, b);
			if (a >= k || b < k) continue;
			ans = min(ans, sum - ns[a] + ns[b]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 5808
#include <cstdint>
#include <iostream>

int main(void)
{
    std::string s;

    std::cin >> s;

    uint32_t cost = 700;

    for (auto c : s) {
        if (c == 'o') cost += 100;
    }

    std::cout << cost << std::endl;

    return 0;
}

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


int main()
{
    double a, b, C;
    cin >> a >> b >> C;
    C *= M_PI / 180;
    
    double h = b * sin(C);
    double S = a * h / 2;
    double c = sqrt(a*a + b*b - 2 * a * b * cos(C));
    double L =  a + b + c;
    cout << fixed << setprecision(4);
    cout << S << endl;
    cout << L << endl;
    cout << h << endl;
    return 0;
}

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

int A,B;

int main(){  
  //freopen("ABC049C_in.txt", "r", stdin);

  scanf("%d%d",&A,&B);

  if(A>8 or B >8 ){printf(":(\n");}
  else{printf("Yay!\n");}
  
  return 0;
}

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

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            Console.WriteLine((N[0] - 1) * (N[1] - 1));
        }
    }
}

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

int main() {
  int n, m;
  cin >> n >> m;
  int M;
  M = m * 2;
  
  //入力値の管理
  vector<int> vec(M);
  for(int i = 0; i < M; i++) {
    cin >> vec.at(i);
    //cout << vec.at(i) << endl;
  }
  
  //都市の定義(ai = i + 1)
  vector<int> a(n);
  for(int j = 0; j < n; j++) {
    int J = j + 1;
    a.at(j) = J;
    //cout << a.at(j) << endl;
  }
  
  //各都市の橋の本数
  vector<int> asum(n);  
  for(int k = 0; k < M; k++) {
    for(int l = 0; l < n; l++) {
      //cout << a.at(l) << endl;
      if(vec.at(k) == a.at(l)) {
        asum.at(l) += 1;
        //cout << asum.at(l) << endl;
      }
      
    }
  }
  
  for(int x = 0; x < n; x++) {
      cout << asum.at(x) << endl;
  }
}

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

using namespace std;
#define rep(i, N) for(int i=0;i<int(N);++i)
#define rep1(i, N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

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

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

const int INF = (ll) 1e9;
const ll INFLL = (ll) 1e18 + 1;
const ll MOD = (ll) 1e9 + 7;
const double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int x[5];
    rep(i,5)cin >> x[i];
    rep(i,5){
        if(x[i] == 0){
            cout << i + 1 << endl;
        }
    }
}

Measured memory_bytes: 3656
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val A = sc.nextInt
    val B = sc.nextInt
    val K = sc.nextInt

    val a = new ArrayBuffer[Int]()
    var i = 0
    for (i <- 100 to 1 by -1) {
      if (A % i == 0 && B % i == 0) {
        a.append(i)
      }
    }
    a(K - 1).toString
  }
}


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

int function(int i);

int main(void) {
	int p[8];
	int c[8] = {4,1,4,1,2,1,2,1};
	int min, cn, ms;
	int sum;
	int i, j;
	while(1) {
		for (i = 0; i < 8 && scanf(" %d", &p[i]) != EOF;i++);
		if (i != 8)
			break;
		for (i = 0, min = 99999; i < 8; i++) {
			for (j = 0, sum = 0; j < 8; j++) {
				if (p[j] - c[(i+j)%8] > 0)
					sum += p[j] - c[(i+j)%8];
			}
			if (min > sum) {
				min = sum;
				cn = i;
				for (j = 0, ms = 0; j < 8; j++) {
					ms += c[(i+j)%8] * function(7-j);
				}
			}
			else if (min == sum) {
				for (j = 0, sum = 0; j < 8; j++) {
					sum += c[(i+j)%8] * function(7-j);
				}
				if (sum < ms) {
					ms = sum;
					cn = i;
				}
			}
		}
		for (i = 0; i < 8; i++) {
			if (i)
				putchar(' ');
			printf("%d", c[(cn+i)%8]);
		}
		putchar('\n');
	}
	return 0;
}

int function(int i) {
	int sum = 1;
	for (; i > 0; i--)
		sum *= 10;
	return sum;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
typedef long long LL;
#define pb push_back
#define mst(a) memset(a,0,sizeof(a))
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int mod = 1e9+7;
const int maxn = 1e5+10;
using namespace std;

unordered_map<LL, LL> ump;
LL a, b, c, d, n;

LL DFS(LL n)
{
	if(!n) return 0;
	if(n==1) return d;
	if(ump[n]) return ump[n];
	LL res = 1e18;
	if(n < res/d) res = n*d;
	res = min(res, n%2*d+DFS(n/2)+a); res = min(res,(2-n%2)*d+DFS((n+1)/2)+a);
	res = min(res, n%3*d+DFS(n/3)+b); res = min(res,(3-n%3)*d+DFS((n+2)/3)+b);
	res = min(res, n%5*d+DFS(n/5)+c); res = min(res,(5-n%5)*d+DFS((n+4)/5)+c);
	ump[n]=res;
	return res;
}

int main()
{
	#ifdef DEBUG
	freopen("sample.txt","r",stdin); //freopen("data.out", "w", stdout);
	#endif
	
	int T;
	scanf("%d",&T);
	while(T--)
	{
		ump.clear();
		scanf("%lld %lld %lld %lld %lld",&n, &a, &b, &c, &d);
		printf("%lld\n",DFS(n));
	}
	
	return 0;
}

Measured memory_bytes: 4216