akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll 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(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main(){
  int n;
  cin>>n;
  vi a(n);
  rep(i,n) cin>>a[i];
  sort(all(a));
  ll ans=INF;
  ll cnt=0;
  for(int i=a[0];i<=a[n-1];i++){
    cnt=0;
    for(int j=0;j<n;j++){
      cnt+=(a[j]-i)*(a[j]-i);
    }
    mins(ans,cnt);
  }
  cout<<ans<<endl;
}

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

int main() {
    int n,m,q;
    cin>>n>>m>>q;
    int a[q],b[q],c[q],d[q];
    for (int i = 0; i < q; ++i) {
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    int num[n];
    for (int j = 0; j < n; ++j) {
        num[j]=1;
    }
    ll ans=0;
    while(num[0]<=m){
        //for (int l = 0; l < n; ++l) {
        //    cout<<num[l]<<" ";
        //}
        ll now=0;
        for (int i = 0; i < q; ++i) {
            if(num[b[i]-1]-num[a[i]-1]==c[i])now+=d[i];
        }
        //cout<<now<<endl;
        ans=max(ans,now);
        num[n-1]++;
        for (int j = n-1; j >0; --j) {
            if(num[j]==m+1)num[j-1]++;
        }
        int nowm=m+1;
        for (int k = 0; k < n; ++k) {
            if(num[k]!=m+1)nowm=num[k];
            if(num[k]==m+1)num[k]=nowm;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

signed main(){
	IO_STREAM;
	int a;	cin>>a;
	ll ans;
	ans=a+a*a+a*a*a;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3632
def palind(LIST, N):
    for i in range(N):
        if LIST[i] != LIST[-1-i]:
            return False
    return True

S = list(input())
n = len(S)
flag = palind(S, n)

front = S[:((n+1)//2-1)]
rear = S[((n+3)//2-1):]
n = len(front)
flag = flag and palind(front, n) and palind(rear, n)

if flag == True:
    print('Yes')
else:
    print('No')

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

int main() {
	int N; cin >> N;
	ll x;  cin >> x;
	vector<ll> a(N);
	for (int i = 0; i < N; i++) cin >> a[i];

	ll ans = 0;
	for (int i = 1; i < N; i++) {
		ll S = a[i] + a[i - 1];
		if (S > x) {
			ll del = S - x;
			ans += del;
			if (del > a[i]) {
				a[i - 1] -= del - a[i];
				a[i] = 0;
			}
			else {
				a[i] -= del;
			}
		}
	}

	cout << ans << endl;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

struct bit {
	ll n;
	vl a;
	bit(ll n): n(n), a(n+2) {}

	void add(ll i, ll v) {
		for (++i; i <= n+1; i += i & -i) a[i] += v;
	}

	ll get(ll i) {
		ll res = 0;
		for (; i; i -= i & -i) res += a[i];
		return res;
	}
};

ll count_inversions(vl &a) {
	ll n = sz(a);
	bit b(n);

	ll res = n*(n-1)/2;
	FOR(i,0,n) {
		res -= b.get(a[i]);
		b.add(a[i],1);
	}
	return res;
}

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

	ll n; cin >> n;
	vl a(n), b(n), c(n);
	FOR(i,0,n) cin >> a[i] >> b[i] >> c[i];
	
	auto evals = [&](double x) {
		vector<pair<double,ll>> res(n);
		FOR(i,0,n) res[i] = {(c[i]-a[i]*x)/double(b[i]),i};
		sort(all(res));
		return res;
	};
	
	vector<double> res(2);
	
	ll target = (n*(n-1)/2 + 1)/2;

	FOR(dir,0,2) {
		double xmin = -1e9, xmax = 1e9;
		
		auto evalxmin = evals(xmin);
		vl pi(n);
		FOR(i,0,n) pi[evalxmin[i].yy] = i;
		
		FOR(k,0,100) {
			double x = (xmin+xmax)/2;
			auto evalx = evals(x);

			vl q(n);
			FOR(i,0,n) q[i] = pi[evalx[i].yy];
			
			ll cur = count_inversions(q);
			if (cur < target) xmin = x; else xmax = x;
		}
		cout << fixed << setprecision(20) << xmin << " \n"[dir];
		swap(a,b);
	}
}



Measured memory_bytes: 4240
#include <stdio.h>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int,int> pii;
pii ldp[200001], rdp[200001];
char txt[200001];
int main(){
	int N,K,C;scanf("%d %d %d",&N,&K,&C);
	scanf("%s",txt);
	if(txt[0]=='o') ldp[0] = {1,0};
	if(txt[N-1]=='o') rdp[N-1] = {1,N-1};
	for(int i=1;i<N;i++){
		if(txt[i]=='o'){
			pii x = ldp[i-1];
			pii y = {(i-C-1>=0?ldp[i-C-1].first:0) + 1,i};
			if(x.first<y.first) ldp[i] = y;
			else ldp[i] = x;
		}
		else ldp[i] = ldp[i-1];
	}
	for(int i=N-2;i>=0;i--){
		if(txt[i]=='o'){
			pii x = rdp[i+1];
			pii y = {(i+C+1<N?rdp[i+C+1].first:0) + 1,i};
			if(x.first<y.first) rdp[i] = y;
			else rdp[i] = x;
		}
		else rdp[i] = rdp[i+1];
	}
	for(int i=0;i<N;i++){
		//if(txt[i]!='o') continue;
		int sum = 0;
		if(i>0){
			sum+=ldp[i-1].first;
			if(max(i+1,ldp[i-1].second+C+1)<N) sum+=rdp[max(i+1,ldp[i-1].second+C+1)].first;
		}
		sum = max(i+1<N?rdp[i+1].first:0,sum);
		//printf("%d %d\n",i,sum);
		if(sum<K) printf("%d\n",i+1);
	}
}

Measured memory_bytes: 4736
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int t[3];
int main(void)
{
	int n,a,i;
	scanf("%d",&n);
	FOR(i,0,n){
		scanf("%d",&a);
		if(a%4==0) t[0]++;
		else if(a%2==0) t[1]++;
		else t[2]++;
	}
	if(t[2]==0) puts("Yes");
	else if(t[1]==0&&t[2]==t[0]+1) puts("Yes");
	else if(t[2]==t[0]) puts("Yes");
	else puts("No");
	return 0;
}
    
    


Measured memory_bytes: 128
function Main(input){
  input = input.split(' ');
  var a = Number(input[0]);
  var b = Number(input[1]);

  var time = a + b;
  if(time <= 23) {
      console.log(time);
  } else {
      console.log( time - 24 );
  }

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

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

Measured memory_bytes: 3072
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli n,a,b,c,q,sum=0;
    vector<lli> ans;
    map<lli,lli> map;
    lli i;
    cin>>n;
    rep(i,0,n){
        cin>>a;
        sum+=a;
        map[a]++;
    }
    cin>>q;
    rep(i,0,q){
        cin>>b>>c;
        map[c]+=map[b];
        sum+=(c-b)*map[b];
        map[b]=0;
        ans.push_back(sum);
    }
    rep(i,0,q){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 9904
using System;
class Program{
    static void Main(string[]args){
        int N=int.Parse(Console.ReadLine());
        if(N%S(N)==0){
            Console.WriteLine("Yes");
        }else if(N%S(N)!=0){
            Console.WriteLine("No");
        }
    }
    static int S(int n){
        int sum=0;
        while(n!=0){
        sum+=n%10;
        n=n/10;

        }
        //Console.WriteLine(sum);
        return sum;
    }
}

Measured memory_bytes: 13140
#include<stdio.h>
main(){
  
  int mem, n, h1=0, h2=0, h3=0,h4=0, h5=0, h6=0 ;
  double s[41];
  
  scanf("%d", &mem);
  
  
  for(n=1; n < mem+1; n++){//1~nÜÅÉüÍ
    scanf("%lg", &s[n]);
  }
  
  
  for(n=1; n < mem+1; n++){
    if(s[n]<165.0){h1++;}
    if(165.0<=s[n] && s[n]<170.0){h2++;}
    if(170.0<=s[n] && s[n]<175.0){h3++;}
    if(175.0<=s[n] && s[n]<180.0){h4++;}
    if(180.0<=s[n] && s[n]<185.0){h5++;}
    if(185.0<=s[n]){h6++;}  
  }
  
  //output
  printf("1:");
  for(n=1; n< h1 +1; n++){
    printf("*");
  }
  printf("\n");
  printf("2:");
  for(n=1; n< h2 +1; n++){
    printf("*");
  }
  printf("\n");
  printf("3:");
  for(n=1; n< h3 +1; n++){
    printf("*");
  }
  printf("\n");
  printf("4:");
  for(n=1; n< h4 +1; n++){
    printf("*");
  }
  printf("\n");
  printf("5:");
  for(n=1; n< h5 +1; n++){
    printf("*");
  }
  printf("\n");
  printf("6:");
  for(n=1; n< h6 +1; n++){
    printf("*");
  }
  printf("\n");
 

  return 0;

}

Measured memory_bytes: 0
#include <iostream>
using ll = long long;
using namespace std;

/* initialize */
struct Node{
    int key;
    Node *parent, *left, *right;
};
Node *root, *NIL;
/* main */
void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x!=NIL){
        y = x;
        if (z->key < x ->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    z->parent = y;
    if (y == NIL){
        root = z;
    } else {
        if (z->key < y->key){
            y ->left = z;
        }else{
            y->right = z;
        }
    }
}

void preorder(Node *u){
    if(u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
};

void inorder(Node *u){
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
};
int main() {
    int n;
    int x;
    string s;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        if ( s == "insert"){
            scanf("%d", &x);
            insert(x);
        } else if  ( s == "print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;

}


Measured memory_bytes: 26716
#include <iostream>
#include <vector>
#define INF (int)1e9

void warshall_floyd(int m, int p, int q, std::vector<std::vector<int> > &dp) { 
    for (int i = 0; i < m; i++) {
        dp[i][i] = 0;
    }
    for (int k = 0; k < m; k++) {
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < m; j++) {
                dp[i][j] = std::min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }
    return;
}

int main(void) {
    int n;
    int m;
    int a;
    int b;
    int cost;
    int time;
    int k;
    int p;
    int q;
    int r;

    while (true) {
        std::cin >> n >> m;
        if (n == 0 && m == 0) {
            break; 
        }
        std::vector<std::vector<int> > vcost(m, std::vector<int>(m, INF));
        std::vector<std::vector<int> > vtime(m, std::vector<int>(m, INF));

        for (int i = 0; i < n; i++) {
            std::cin >> a >> b >> cost >> time;
            --a;
            --b;
            vcost[a][b] = cost; 
            vcost[b][a] = cost; 
            vtime[a][b] = time; 
            vtime[b][a] = time; 
        }

        warshall_floyd(m, p, q, vcost); 
        warshall_floyd(m, p, q, vtime); 
        std::cin >> k;
        for (int i = 0; i < k; i++) {
            std::cin >> p >> q >> r;
            --p;
            --q;
            if (r == 0) {
                std::cout << vcost[p][q] << std::endl;            
            } else {
                std::cout << vtime[p][q] << std::endl;            
            }
        }
    } return 0;
}

Measured memory_bytes: 3104
#include <iostream>
using namespace std;
const int N=105;
int H,W,i,j,f[N][N];
char c[N][N];
int main() {
	scanf("%d%d",&H,&W);
	for (i=1; i<=H; ++i) scanf("%s",c[i]+1);
	f[1][1]=c[1][1]=='#';
	for (i=1; i<=H; ++i)
        for(j=1; j<=W; ++j)
            if (i>1 || j>1)
		        f[i][j] = min(
			        i>1?f[i-1][j]+(c[i][j]=='#' && c[i-1][j]=='.'):114514,
			        j>1?f[i][j-1]+(c[i][j]=='#' && c[i][j-1]=='.'):114514
                );
	        printf("%d\n",f[H][W]);
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
 
N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N-1)]

# graph[i]: 頂点iの親と子の集合
graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

# 根
root = 1
# parent[i]: 頂点iの親
parent = [0]*(N+1)
# トポロジカル順序
order = []
# 未探索の頂点
stack = [root]

# dfsでparentを求める
while stack:
    # n: 探索する頂点
    n = stack.pop()
    order.append(n)
    for j in graph[n]:
        # jがnの親の場合
        if j == parent[n]:
            continue
        parent[j] = n
        stack.append(j)

# color[i]: 頂点iと親を繋ぐ辺の色
color = [-1] * (N+1)
# dfsで色を塗る
for i in order:
    # 既に使用した色
    ng = color[i]
    # 色
    c = 1
    for j in graph[i]:
        # jがiの親の場合(塗装済みなのでcontinue)
        if j == parent[i]:
            continue
        if c == ng:
            c += 1
        # 頂点iと頂点jの辺に色を塗る
        color[j] = c
        c += 1

# 入力順に辺の色を出力する
answer = [color[a] if parent[a]==b else color[b] for a,b in AB]
print(max(answer))
print("\n".join(map(str,answer)))

Measured memory_bytes: 42848
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> p(n);
    REP(i,n){
        cin >> p[i];
    }
    ll max = 0;
    vector<ll> s(n+1,0);
    REP(i,n){
        s[i+1] = s[i] + p[i];
    }
    REP(i,n-k+1){
        ll sum = s[i+k] - s[i];
        if(sum > max){
            max = sum;
        }
    }
    cout << fixed <<double(max + k)/2 << endl;
    
}


Measured memory_bytes: 3328
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
void RatingGoal() {
	int r, g;
	cin >> r;
	cin >> g;

	cout << (g * 2 - r) << endl;
}
int main() {

	RatingGoal();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int a,b,c;
    std::cin >> a >> b >> c ;
    if (c>b) 
    {
        if (b>a)
        {
            cout<< "Yes" << std::endl ;
        }
        else
        {
          cout << "No" << std::endl;  
        }
    }
    else
    {
        cout << "No" << std::endl;  
    };
}



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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    ll N; cin >> N;
    vll X(N), L(N); REP(i, N) cin >> X[i] >> L[i];
    vector<pll> R(N);
    REP(i, N)
    {
        R[i] = make_pair(X[i]+L[i], X[i]-L[i]);
    }
    sort(ALL(R));

    ll ans = 1;
    REP1(i, N-1)
    {
        int k = i-1;
        while(R[i].second < R[k].first) i++;
        if(i >= N) break;
        ans++;
    }
    cout << ans << endl;
}
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

vector<ll> a[100001];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k, n;
    cin >> n >> k;
    for (int i = 0; i < n; ++i)
    {
        int t, d;
        cin >> t >> d;
        a[t].push_back(d);
    }
    vector<ll> bst, ot;
    for (int i = 1; i <= n; ++i)
    {
        if (a[i].empty()) continue;
        sort(all(a[i]));
        reverse(all(a[i]));
        bst.push_back(a[i][0]);
        for (int j = 1; j < a[i].size(); ++j)
            ot.push_back(a[i][j]);
    }
    sort(all(bst));
    reverse(all(bst));
    sort(all(ot));
    reverse(all(ot));
    for (int i = 1; i < bst.size(); ++i)
        bst[i] += bst[i - 1];
    for (int i = 1; i < ot.size(); ++i)
        ot[i] += ot[i - 1];

    ll sol = 0;
    for (int i = 0; i < min((int)bst.size(), k); ++i)
    {
        ll att = bst[i] + 1ll * (i + 1) * (i + 1);
        if (k - i - 2 >= 0 && !ot.empty())
            att += ot[max(0, min((int)ot.size() - 1, k - i - 2))];
        sol = max(sol, att);
    }
    cout << sol;
}


Measured memory_bytes: 6904
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;
double kitaichi(int P){
  double ans = 0;
  for(int i = 1;i<P+1;i++){
    ans += i;
  }
  ans/=P;
  return ans;
}

int main(){

  int N,K;
  cin>>N>>K;
  vector<double>p(N);
  for(int i=0;i<N;i++){
    int P;
    cin>>P;
    p.at(i)=kitaichi(P);
  }
  double ans=0;
  double now =0;
  for(int i=0;i<K;i++){
    now+=p.at(i);
  }
  ans = now;
  for(int i=K;i<N;i++){
    now+=p.at(i);
    now-=p.at(i-K);
    if(now>ans)ans = now;
  }

  cout<<setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        int d = a;
        
        if (b * c >= d) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        
    }
}


Measured memory_bytes: 35612
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] c = s.toCharArray();
		sc.close();
		if (c[0] == c[1] || c[1] == c[2] || c[2] == c[3]) {
			System.out.println("Bad");
		} else {
			System.out.println("Good");
		}
	}
}


Measured memory_bytes: 21844
N=int(input())
A=input().split()

B=A[:]
S=A[:]

def BubbleSort(A, N):
    count = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if A[j][1] < A[j-1][1]:
                A[j], A[j-1] = A[j-1], A[j]
                count += 1
                flag = True
                
    return A

def SelectionSort(A, N):
    count = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j][1] < A[minj][1]:
                minj = j
        A[i], A[minj] = A[minj], A[i] 
        count += 1
    return A

b = BubbleSort(B, N)
s = SelectionSort(S, N)
print(*b)
print("Stable")
print(*s)

if b == s:
    print("Stable")
else:
    print("Not stable")

Measured memory_bytes: 7788
import qualified Data.Vector.Mutable as VM
import Control.Monad
import Data.List

solve :: Int -> String -> VM.IOVector [String] -> IO ()
solve n xs vec
  | n == length xs = do 
    rs <- VM.read vec 0
    VM.write vec 0 (xs:rs)
  | otherwise = 
    forM_ ['a'..succ m] $ \x -> solve n (xs++[x]) vec
    where
      m = maximum xs

main = do 
  n <- readLn :: IO Int 
  table <- VM.replicate 1 [] :: IO (VM.IOVector [String])
  solve n "a" table
  res <- sort <$> VM.read table 0
  forM_ res putStrLn


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

int main() {
  string A, B, C;
  cin >> A; reverse(A.begin(),A.end());
  cin >> B; reverse(B.begin(),B.end());
  cin >> C; reverse(C.begin(),C.end());
  string win; //勝者
  char next = 'a';  //次の人、最初はA

  while(true){
  if (next == 'a'){
  //Aがカードを1枚捨てる
    if (A.size()>=1){
      next = A.at(A.size()-1);//次の人
      A.pop_back();
    }
    else {
      win = "A";
      break;
    }
  }
  else if (next == 'b'){
  //Bがカードを1枚捨てる
    if (B.size()>=1){
      next = B.at(B.size()-1);//次の人
      B.pop_back();
    }
    else {
      win = "B";
      break;
    }
  }
  //Cがカードを1枚捨てる
  else if (next == 'c'){
    if (C.size()>=1){
      next = C.at(C.size()-1);//次の人
      C.pop_back();
    }
    else {
      win = "C";
      break;
    }
  }
  }

  cout << win << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<bool> vb;

const int MAXN = 101;
const int MAXK = 100001;

int turns[MAXK]={0};
int A[MAXN];

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

    int n,k; cin >> n >> k;
    for(int i=0; i<n; i++)
        cin >> A[i];

    for(int i=0; i<=k; i++){
        for(int j=0; j<n; j++){
            if(i>=A[j] && !turns[i-A[j]])
                turns[i] = 1;
        }
    }

    if(turns[k]) cout << "First\n";
    else cout << "Second\n";

    return 0;
}



Measured memory_bytes: 3904
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <array>
#include <map>

using tile = std::array<int16_t, 4>;
constexpr int coeff[] = { 1, 2, 4 };

tile rotate(const tile &t, int r) {
  tile res{};
  for (int i = 0; i < 4; ++i) {
    res[i] = t[(i + r) & 3];
  }
  return res;
}

tile normalize(const tile &t) {
  std::array<tile, 4> tmp{};
  for (int i = 0; i < 4; ++i) {
    tmp[i] = rotate(t, i);
  }
  std::sort(tmp.begin(), tmp.end());
  return tmp.front();
}

int type(const tile &t) {
  if (t[0] == t[1] && t[1] == t[2] && t[2] == t[3]) return 2;
  if (t[0] == t[2] && t[1] == t[3]) return 1;
  return 0;
}

int main() {
  int N;
  std::cin >> N;
  std::vector<tile> C(N);
  std::map<tile, int> memo;
  for (int i = 0; i < N; ++i) {
    for (auto &x: C[i]) {
      std::cin >> x;
    }
    C[i] = normalize(C[i]);
    memo[C[i]]++;
  }
  int64_t ans = 0;
  for (int i = 0; i < N; ++i) {
    memo[C[i]]--;
    const auto &up = C[i];
    for (int j = i + 1; j < N; ++j) {
      memo[C[j]]--;
      for (int k = 0; k < 4; ++k) {
        auto down = rotate(C[j], k);
        std::map<tile, int> query;
        query[normalize(tile{ up[0], up[3], down[2], down[1] })]++;
        query[normalize(tile{ up[1], up[0], down[1], down[0] })]++;
        query[normalize(tile{ up[2], up[1], down[0], down[3] })]++;
        query[normalize(tile{ up[3], up[2], down[3], down[2] })]++;
        int64_t add = 1;
        for (auto &q: query) {
          auto itr = memo.find(q.first);
          if (itr == memo.end()) {
            add = 0;
            break;
          }
          int s = itr -> second, t = type(q.first);
          for (int i = 0; i < q.second; ++i) {
            add *= (s - i) * coeff[t];
          }
        }
        ans += add;
      }
      memo[C[j]]++;
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,t="",alph="abcdefghijklmnopqrstuvwxyz",alphh="zyxwvutsrqponmlkjihgfedcba";
  cin >> s;
  if(s==alphh){
    cout << -1 << endl;
    return 0;
  }else if(s.size()==26&&s!=alphh){
    for(int i=25;i>=0;i--){
      string ss=s.substr(i,s.size()-i);
      sort(ss.begin(),ss.end());
      for(int j=0;j<ss.size();j++){
        if(ss[j]>s[i-1]){
          cout << s.substr(0,i-1) << ss[j] << endl;
          return 0;
        }
      }
    }
  }
  t+=s;
  sort(s.begin(),s.end());
  for(int i=0;i<alph.size();i++){
    if(s[i]!=alph[i]){
      cout << t << alph[i] << endl;
      return 0;
    }
  }
}


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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll a;
    cin >> a;
    ans += --a;
  }
  cout << ans << '\n';
  return 0;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    string s;
    cin >> s;

    ll n = s.length();

    NREP() {
        if (s[i] != s[n - i - 1]) {
            cout << "No" << endl;
            exit(0);
        }
    }

    string sub = s.substr(0, (n - 1) / 2);
//    cout << sub << endl;
    n = sub.length();
    NREP() {
        if (sub[i] != sub[n - i - 1]) {
            cout << "No" << endl;
            exit(0);
        }
    }

    sub = s.substr(n + 3 / 2, n);
//    cout << sub << endl;
    n = sub.length();
    NREP() {
        if (sub[i] != sub[n - i - 1]) {
            cout << "No" << endl;
            exit(0);
        }
    }

    cout << "Yes" << endl;

}


Measured memory_bytes: 256
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()

	N := readInt()
	M := readInt()

	uf := NewUnionFind(N+1)
	for i := 0; i < M; i++ {
		x := readInt()
		y := readInt()
		_ = readInt()
		uf.Union(x, y)
	}

	m := make(map[int]bool)
	for i := 1; i <=N; i++ {
		m[uf.Find(i)] = true
	}
	println(len(m))
}

// -----------------------------------------------------------------------------

type UnionFind struct {
	parent []int
	rank   []int
	size   []int
}

// Initialize UnionFind for [0 - n) elements.
// Use n+1 if you need [1 - n] elements
func NewUnionFind(n int) *UnionFind {
	u := &UnionFind{
		parent: make([]int, n),
		rank:   make([]int, n),
		size:   make([]int, n),
	}

	for i := range u.parent {
		u.parent[i] = i
		u.rank[i] = 0
		u.size[i] = 1
	}

	return u
}

func (u *UnionFind) Find(i int) int {
	if u.parent[i] == i {
		return i
	}
	p := u.Find(u.parent[i])
	u.parent[i] = p
	return p
}

func (u *UnionFind) Union(i, j int) {
	p := u.Find(i)
	q := u.Find(j)

	if p == q {
		return
	}

	if u.rank[p] < u.rank[q] {
		p, q = q, p
	}
	u.parent[p] = q
	if u.rank[p] == u.rank[q] {
		u.rank[q]++
	}
	u.size[q] += u.size[p]
}

func (u *UnionFind) Size(i int) int {
	p := u.Find(i)
	return u.size[p]
}


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

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

using namespace std;

typedef long long int ll;

const ll inf = 1e18;

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

  ll n, u, v;
  cin >> n;
  cin >> u >> v;
  for(int i = 1; i < n; i++){
    ll t, a, lowest_mid = inf;
    cin >> t >> a;
    ll lo = 1, hi = inf;
    while(lo <= hi){
      ll mid = (hi - lo) / 2 + lo;
      if(t > (inf / mid) || a > (inf / mid)){
        hi = mid - 1;
        continue;
      }
      if(t * mid >= u && a * mid >= v){
        lowest_mid = min(lowest_mid, mid);
        hi = mid - 1;
      }else lo = mid + 1;
    }
    u = t * lowest_mid;
    v = a * lowest_mid;
  }

  ll ans = u + v;
  cout << ans << '\n';
}


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

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

typedef long long ll;

ll INF = 100000000000000;
ll MOD = 1e9+7;

ll N;
string S;

bool judge(string S,vector<char>& A){
    int N = A.size();
    bool frag = 0;
    for(int i = 1;i < N-1;i++){
        if(i != N-1){
            if(A[i] == 'S'){
                if(S[i] == 'o'){
                    A[i+1] = A[i-1];
                }else{
                    if(A[i-1] == 'S'){
                        A[i+1] = 'W';
                    }else{
                        A[i+1] = 'S';
                    }
                }
            }else{
                 if(S[i] == 'o'){
                     if(A[i-1] == 'S'){
                         A[i+1] = 'W';
                     }else{
                         A[i+1] = 'S';
                     }
                 }else{
                     A[i+1] = A[i-1];
                 }
            }
        }
    }
    if(A[N-1] == 'S'){
        if(S[N-1] == 'o'){
            if(A[N-2] == A[0]){
                frag = true;
            }
        }else{
            if(A[N-2] != A[0]){
                frag = true;
            }
        }
    }else{
        if(S[N-1] == 'o'){
            if(A[N-2] != A[0]){
                frag= true;
            }
        }else{
            if(A[N-2] == A[0]){
                frag = true;
            }
        }
    }
    if(A[0] == 'S'){
        if(S[0] == 'o'){
            if(A[N-1] != A[1]){
                frag = false;
            }
        }else{
            if(A[N-1] == A[1]){
                frag = false;
            }
        }
    }else{
        if(S[0] == 'o'){
            if(A[N-1] == A[1]){
                frag = false;
            }
        }else{
            if(A[N-1] != A[1]){
                frag = false;
            }
        }
    }
    if(frag){
        return true;
    }else{
        return false;
    }
}


int main(){
   cin >> N >> S;
   vector<char> case1(N),case2(N),case3(N),case4(N);
   case1[0] = 'S';case1[1] = 'S';
   case2[0] = 'S';case2[1] = 'W';
   case3[0] = 'W';case3[1] = 'S';
   case4[0] = 'W';case4[1] = 'W';
   if(judge(S,case1)){
       for(int i = 0;i < N;i++){
           cout << case1[i];
       }
       cout << endl;
       return 0;
   }
   if(judge(S,case2)){
       for(int i = 0;i < N;i++){
           cout << case2[i];
       }
       cout << endl;
       return 0;
   }
   if(judge(S,case3)){
       for(int i = 0;i < N;i++){
           cout << case3[i];
       }
       cout << endl;
       return 0;
   }
   if(judge(S,case4)){
       for(int i = 0;i < N;i++){
           cout << case4[i];
       }
       cout << endl;
       return 0;
   }
   cout << -1 << endl;
}



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

const int N = 2005;
typedef long long LL;

int n, k, cnt, first[N], ans = 1e9, res, r;
bool vis[N];
struct Edge {
	int to, next;
} e[N<<1];

void add(int u, int v) {
	e[++cnt] = (Edge) {v, first[u]};
	first[u] = cnt;
}

void Dfs(int u, int f, int d) {
	if(d <= r) vis[u] = 1;
	for(int i = first[u]; i; i = e[i].next) {
		int v = e[i].to;
		if(v == f) continue;
		Dfs(v, u, d + 1); 
	}
}

int main() {
	cin>>n>>k;
	if(k%2 == 0) r = k/2;
	else r = (k - 1)/2;
	for(int i = 1, u, v; i < n; i++) {
		cin>>u>>v;
		add(u, v);
		add(v, u);
	}
	if(k%2 == 1) {
		for(int i = 1; i <= cnt; i += 2) {
			int u = e[i].to, v = e[i + 1].to;
			res = 0;
			memset(vis, 0, sizeof(vis));
			Dfs(u, 0, 0);
			Dfs(v, 0, 0);
			for(int j = 1; j <= n; j++)
				if(vis[j]) res++;
			ans = min(ans, n - res); 
		}
	}
	else {
		for(int i = 1; i <= n; i++) {
			memset(vis, 0, sizeof(vis));
			Dfs(i, 0, 0);
			res = 0;
			for(int j = 1; j <= n; j++)
				if(vis[j]) res++;
			ans = min(ans, n - res); 
		}
	}
	cout<<max(ans, 0)<<endl;
	return 0;
}

Measured memory_bytes: 3660
//#pragma comment(linker,"/STACK:102400000,102400000")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define PI 3.14159265357979823846
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<double,int>
using namespace std;

const int N = 1e5 + 10, INF = 0x3f3f3f3f , MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};
struct node{
    double first;
    ll second,t;
}s[5];
bool cmp(node a,node b){
    return a.t < b.t;
}
int main(){
//	freopen("C:\\Users\\wz\\Desktop\\in.txt","r",stdin);
//	freopen("C:\\Users\\wz\\Desktop\\out.txt","w",stdout);
	ios_base::sync_with_stdio(0);
    s[0].first = 0.25;
    s[1].first = 0.5;
    s[2].first = 1;
    s[3].first = 2;
    ll  n;
    cin>>s[0].second>>s[1].second>>s[2].second>>s[3].second>>n;
    for(int i = 0;i < 4;i++)s[i].t = (ll)s[i].second/s[i].first;
    sort(s,s+4,cmp);
    ll ans = 0;
    //for(int i  = 0; i < 4;i++)cout<<s[i].t<<' ';cout<<endl;
    for(int i = 0;i < 4;i++){
        if(n >= s[i].first){
            ll c = (ll)n/s[i].first;
            ans += c*s[i].second;
            n -= c*s[i].first;
        }
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int sum_of_disits(int n) {
  int r = 0;
  while (n > 0) {
    r += n % 10;
    n /= 10;
  }
  return r;
}

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

  int sum = sum_of_disits(N);

  if (!(N % sum)) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
int n,a[200005],i,j,mx,num,b[200005],ed[200005][2];
struct bit{
	int a[200005];
	vector<int> pos,mem;
	void add(int x,int y){
		while(x){
			pos.push_back(x);
			mem.push_back(a[x]);
			a[x]=max(a[x],y);
			x-=(x&-x);
		}
	}
	int qry(int x){
		int ans=-0x3f3f3f3f;
		while(x<=n){
			ans=max(ans,a[x]);
			x+=(x&-x);
		}return ans;
	}
	void undo(){
		a[pos.back()]=mem.back();
		pos.pop_back();
		mem.pop_back();
	}
}t[2];
int main(){
	cin>>n;
	rep(i,n){
		cin>>a[i];
		if(a[i]>mx){
			mx=a[i];
			num++;
			b[i]=2;
		}
		else{
			b[i]=1;
		}
	}
	memset(t[1].a,-0x3f,sizeof(t[1].a));
	for(i=n;i;i--){
		int s0=t[0].qry(a[i]),s1=t[1].qry(a[i]);
		if(s0+b[i]<=num) t[(s0+b[i])&1].add(a[i],s0+b[i]);
		if(s1+b[i]<=num) t[(s1+b[i])&1].add(a[i],s1+b[i]);
		ed[i][0]=t[0].pos.size();
		ed[i][1]=t[1].pos.size();
	}
	if(t[num&1].qry(1)!=num){
		puts("-1");
		return 0;
	}
	int mx0=0,mx1=0,cnt0=0,cnt1=0;
	rep(i,n){
		while(t[0].pos.size()>ed[i+1][0]){
			t[0].undo();
		}
		while(t[1].pos.size()>ed[i+1][1]){
			t[1].undo();
		}
		int nmx1=mx1,ncnt1=cnt1;
		if(a[i]>nmx1){
			nmx1=a[i];
			ncnt1++;
		}
		num-=(b[i]==2);
		if((num+cnt0-ncnt1>=0&&t[(num+cnt0-ncnt1)&1].qry(nmx1)>=num+cnt0-ncnt1)||
		   (num-cnt0+ncnt1>=0&&t[(num-cnt0+ncnt1)&1].qry(max(1,mx0))>=num-cnt0+ncnt1)){
				putchar('0');
				mx1=nmx1;
				cnt1=ncnt1;
		}
		else{
				putchar('1');
				if(a[i]>mx0){
					mx0=a[i];
					cnt0++;
				}
		}
	}
	puts("");
	return 0;
}

Measured memory_bytes: 37412
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair

using namespace std;
const int N=2e5+5;

bool check(int n,int k)
{
    while(n%k==0) n/=k;
    return (n%k==1);
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    int dem=0;
    for(int i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            if(i!=1&&check(n,i)) dem++;
            if(i*i!=n&&check(n,n/i)) dem++;
        }
    }
    n--;
    for(int i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            if(i!=1) dem++;
            if(i*i!=n) dem++;
        }
    }
    cout<<dem;
}


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

typedef long long ll;
ll n, m, z, ans, mx, a[N][3], b[N];
int main()
{
	ll i, j, k;
	cin >> n >> m;
	for (i = 0; i <n; i++) {
		for (j = 0; j < 3; j++) {
			scanf ("%lld", &a[i][j]);
		}
	}
	for (i = 0; i < 8; i++) {
		for (j =0; j < n; j++) {
			b[j] = 0;
			for (k = 0; k < 3; k++) {
				if((i & (1 << k))) z = 1;
				else z = -1;
				b[j] += z * a[j][k];
			}
		}
		sort(b, b + n, greater<ll>());
		ans = 0;
		for (j = 0; j < m; j++) {
			ans += b[j];
		}
		mx = max(mx, ans);
	}
	cout << mx;
    return 0;
}


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


int top, S[1000];

void push(int x){
  S[++top] = x;
}

int pop(){
  top--;
  return S[top+1];
}

int main()
{
  int a, b;
  top = 0;
  char s[100];
  while(scanf("%s", s) != EOF){
    if(s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if (s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if (s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }

  printf("%d\n", pop());

  return 0;
}



Measured memory_bytes: 2112
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<bitset>
#include<random>
#include<cstdint>
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
#define shosu setprecision(17)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<char,P> Q;
ll longinf=(1ll<<60);
ll inf=1<<21;
int main(){
      ll N,K;
      vector<ll> S;
      cin>>N>>K;
      ll a[N];
      rep0(i,N){
            cin>>a[i];
      }
      ll accum[N+1];
      accum[0]=0;
      rep1(i,N){
            accum[i]=accum[i-1]+a[i-1];
      }
      rep0(i,N){
            for(ll j=i+1;j<=N;j++){
                  S.push_back(accum[j]-accum[i]);
            }
      }
      sort(S.begin(),S.end());
      reverse(S.begin(),S.end());
      ll keta=0;
      ll hoge=S[0];
      while(hoge>0){
            hoge>>=1;
            keta++;
      }
      ll ans=0;
      bool good[S.size()];
      fill(good,good+S.size(),true);
      while(keta>=0){
            int ok=0;
            rep0(i,S.size()){
                  if(good[i]){
                  if(S[i]&(1ll<<keta)){
                        ok++;
                  }
                  }
            }
            if(ok>=K){
                  ans+=(1ll<<keta);
                  rep0(i,S.size()){
                        if(good[i]){
                              if(!(S[i]&(1ll<<keta))){
                                    good[i]=false;
                              }
                        }
                  }
            }
            keta--;
      }
      cout<<ans<<endl;

      return 0;
}

Measured memory_bytes: 6512
#include <iostream>
#include <iomanip>
/*cout <<setprecision(11)<<ret<<endl;で、数字部分を計11桁表示*/
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//Shift+Command+bでデバッグ
//その後ターミナルで./a.outを実行
//入力を貼り付ける

//////////////////
//  A
/*int main(void){
    int a,p;cin >>a >>p;
    cout<<(a*3+p)/2<<endl;

    return 0;
}*/
//////////////////
//  B
/*int main(void){
    int n;cin>>n;
    vector<pair<string,pair<int,int> > > box(n);

    rep(i,n){
        cin>>box[i].first>>box[i].second.first;
        box[i].second.second=i+1;
        box[i].second.first*=-1;
    }
    sort(box.begin(), box.end());

    //rep(i,n)cout <<box[i].first<<" "<<box[i].second.first<<" "<<box[i].second.second<<endl;

    rep(i,n) cout<<box[i].second.second<<endl;
    return 0;
}*/
//////////////////
//  C
int main(void){
    int n,m;cin>>n>>m;
    int ret=0;
    vector<vector<bool>> map(m,vector<bool>(n));
    vector<int> p(m);

    rep(i,m){
        int t;cin>>t;
        rep(j,t){
            int d;cin>>d;
            map[i][d-1]=true;
        }
    }
    rep(i,m)cin>>p[i];

    //rep(i,m){rep(j,n)cout<<map[i][j];cout<<endl;}


    for(int bit=0;bit<(1<<n);bit++){
        bool isclear=true;//電球が全て着いたならtrueで通過する
        rep(i,m){
            int denkyugaONnokazu=0;
            rep(j,n){
                if((map[i][j]==true)&&(bit&(1<<j))){//mapが1になってて、bitのj+1ビット目が1なら
                    denkyugaONnokazu++;
                }
            }
            if(denkyugaONnokazu%2!=p[i]){//違った瞬間抜ける
                isclear=false;
                break;
            }
        }
        if(isclear)ret++;
    }

    cout<<ret<<endl;
    return 0;
}
//////////////////
//  D
/*int main(void){

    return 0;
}*/
//////////////////
//  E
/*int main(void){

    return 0;
}*/
//////////////////
//  F
/*int main(void){

    return 0;
}*/


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

int main() {
  string s,t;
  cin >> s >> t;
  int count = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == t.at(i)) {
      count++;
    }
  }
  if  (count == s.size()) {
    cout << "Yes" <<endl;
  }
  else {
    cout << "No" <<endl;
  }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)

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

template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
//******************************************************************************

int A,B,C,D,E,F,G,N,M,R,Q,X,Y,Z,K;
string s,t;

signed main()
{
	//IOS();
	cin>>N>>K>>s;
	rep(i,0,N){
		if(i==K-1)s[i]-='A'-'a';
	}
	cout<<s<<endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.NoSuchElementException;
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws IOException {

		InputStreamReader sr = null;
		Scanner sc = null;
		BigDecimal value1 = null;
		BigDecimal value2 = null;
		BigDecimal sum = new BigDecimal("0");

		try {
			sc = new Scanner(sr = new InputStreamReader(System.in));
			int datasets = sc.nextInt();

			for (int i = 1; i <= datasets; i++) {

				value1 = sc.nextBigDecimal();
				value2 = sc.nextBigDecimal();
				sum = sum.add(value1.add(value2));

				if (sum.precision() > 80) {
					System.out.println("overflow");
				} else {
					System.out.println(sum.toPlainString());
				}
				sum = BigDecimal.ZERO;
			}

		} catch (NoSuchElementException e) {

		}

		finally {
			sr.close();
			sc.close();
		}

	}

}

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

int main() {
  int n;cin>>n;
  vector<int> v(n);
  rep(i,n)cin>>v[i];
  sort(all(v));
  double ans=v[0];
  for(int i=1;i<n;i++){
    ans=(ans+v[i])/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3744
n = input()
m = n.split(" ")
 
x_min = int(m[0])
x_max = int(m[1])
y_min = int(m[2])
y_max = int(m[3])
 
a = x_min * y_min
b = x_min * y_max
c = x_max * y_min
d = x_max * y_max
 
if a >= b and a >= c and a >= d:
    print(a)
 
elif b >= a and b >= c and b >= d:
    print(b)
 
elif c >= a and c >= b and c >= d:
    print(c)
 
elif d >= a and d >= b and d >= c:
    print(d)

Measured memory_bytes: 9200