akhauriyash/Code-Regression huggingface dataset:
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//HELPERS
map<int,int> dp;
int mod = 1e9+7;
int func(int x) {
    if(dp[x]) return dp[x];
    return dp[x] = (func((x-1)>>1) + func((x-2)>>1) + func(x/2))%mod;
}
vector<int> powers2(32,0);void initialize(){ for(int i=1;i<powers2.size();i++) powers2[i] = powers2[i-1]*2;}
int32_t main()
{
IOS
int n;
cin>>n;
dp[0] = 1;
dp[1] = 2;
cout<<func(n);
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func show(dp [101][100001]int, N, K int) {
	for i := 0; i <= N; i++ {
		for j := 0; j <= K; j++ {
			fmt.Printf("%d\t", dp[i][j])
		}
		fmt.Println("")
	}
	out("-----------------------------")
}

const MOD = 1000000007

func main() {
	sc.Split(bufio.ScanWords)

	N, K := getInt(), getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	var dp [101][100001]int

	dp[0][0] = 1
	for i := 1; i <= N; i++ {
		s := 0
		for j := 0; j <= K; j++ {
			s += dp[i-1][j]
			s %= MOD
			dp[i][j] = s
			//			out(j, a[i-1], s)
			if j >= a[i-1] {
				s -= dp[i-1][j-a[i-1]]
				s %= MOD
				if s < 0 {
					s += MOD
				}
				//				out("--", j, a[i-1], dp[i-1][j-a[i-1]], s)
			}
		}
		//		show(dp, N, K)
	}
	out(dp[N][K])
}


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

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }

void main()
{
	auto N = RD;
	auto M = RD;
	auto ac = new bool[](N);
	auto wa = new long[](N);

	foreach (i; 0..M)
	{
		auto p = RD-1;
		auto S = RD!string;
		if (ac[p]) continue;
		if (S == "WA")
			++wa[p];
		else
			ac[p] = true;
	}

	long ans0, ans1;
	foreach (i; 0..N)
	{
		if (ac[i])
		{
			++ans0;
			ans1 += wa[i];
		}
	}

	writeln(ans0, " ", ans1);
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 4092
N=int(input())
A=[]
B=[]
for i in range(N):
    _A,_B=[int(i) for i in input().split(" ")]
    A.append(_A)
    B.append(_B)

A=sorted(A)
B=sorted(B)
if N%2==1:
    print(B[(N+1)//2-1]-A[(N+1)//2-1]+1)

else:
    print(B[N//2-1]-A[N//2-1]+B[N//2]-A[N//2]+1)


Measured memory_bytes: 26988
A, B, C, D = map(int, input().split())

t = 0

while True:
  if t == 0:
    C = C - B
    t = 1
    if C <= 0:
      print('Yes')
      break
  else:
    A = A - D
    t = 0
    if A <= 0:
      print('No')
      break


Measured memory_bytes: 9172
from itertools import permutations as p
 
from scipy.sparse.csgraph import floyd_warshall
 
n, m, r = map(int, input().split())
R = list(map(int, input().split()))
l = [[0]*n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    l[a][b] = c
    l[b][a] = c
F = floyd_warshall(l)
 
ans = float("inf")
for v in p(R):
    temp = 0
    for i in range(r-1):
        temp += F[v[i]-1][v[i+1]-1]
    ans = min(ans, temp)
print(int(ans))

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

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

  string a, b;
  cin >> a >> b;

  int lenA = a.size();
  int lenB = b.size();

  string ans;
  if (lenA > lenB) {
    ans = "GREATER";
  } else if (lenA < lenB) {
    ans = "LESS";
  } else {
    ans = "EQUAL";
    for (int i = 0; i < a.size(); i++) {
      int ai = (int)a[i];
      int bi = (int)b[i];

      if (ai == bi) continue;

      if (ai > bi) {
        ans = "GREATER";
      } else {
        ans = "LESS";
      }

      break;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100000

int A1[N];
char A2[N];
int input1[N];
char input2[N];

void swap1(int* a, int* b){
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void swap2(char* a, char* b){
  char tmp = *a;
  *a = *b;
  *b = tmp;
}

int partition(int p, int r){
  int x = A1[r];
  int i = p - 1, j;
  for(j=p;j<r;j++){
    if(A1[j] <= x){
      i++;
      swap1(&A1[i], &A1[j]);
      swap2(&A2[i], &A2[j]);
    }
  }
  swap1(&A1[i+1], &A1[r]);
  swap2(&A2[i+1], &A2[r]);
  return i+1;
}

void quic_sort(int p, int r){
  if(p < r){
    int q = partition(p, r);
    quic_sort(p, q-1);
    quic_sort(q+1, r);
  }
}

int check(int n){
  int i, j;
  for(i=1;i<n;i++){
    if(A1[i-1] == A1[i]){
      int a, b;
      for(j=0;j<n;j++){
        if(A1[i-1] == input1[j] && A2[i-1] == input2[j]) a = j;
        if(A1[i] == input1[j] && A2[i] == input2[j]) b = j;
      }
      if(a > b) return 0;
    }
  }
  return 1;
}

main(){
  int n, i;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    getchar();
    scanf("%c%d", &A2[i], &A1[i]);
  }
  for(i=0;i<n;i++){
    input1[i] = A1[i];
    input2[i] = A2[i];
  }
  quic_sort(0, n-1);
  printf("%s\n", (check(n) ? "Stable" : "Not stable"));
  for(i=0;i<n;i++) printf("%c %d\n", A2[i], A1[i]);
  return 0;
}



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

int main(void){
	char s1[4]={NULL},s2[4]={NULL},tmp;
	scanf("%s",s1);
	scanf("%s",s2);
	tmp=s2[0];
	s2[0]=s2[2];
	s2[2]=tmp;
	if(0==strcmp(s1,s2)){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 128
import sys
import math
import bisect

def main():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    B = [0]
    for a in A:
        B.append(B[-1] + a)
    ans = 0
    for b in B:
        if b <= m:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
/*
*	3 ????????°?????´???
*	?°????????????????????????????
***/

#include <iostream>

int main(void)
{
	int a, b, c, d;
	std::cin >> a >> b >> c;
	
	if ( a <= b ){
		//???????????????
	} else if( a > b){
		d = a;
		a = b;
		b = d;
	}
	else {
		//???????????????
	}

	if( b <= c ){
		//???????????????
	} else if( b > c){
		d = b;
		b = c;
		c = d;
	}
	else {
		//???????????????
	}
	
	if( a <= b ){
		//???????????????
	} else if( a > b){
		d = a;
		a = b;
		b = d;
	}
	else {
		//???????????????
	}

	
	std::cout << a << " " << b << " " << c << std::endl;

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

vector<ll> compress (vector<ll>& vec) {
    vector<ll> v = vec;
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    vector<ll> ret;
    rep(i,vec.size()) {
        ret.push_back(lower_bound(v.begin(), v.end(), vec[i]) - v.begin());
    }
    return ret;
}

#define MAX_N (1<<18) //260000
template<typename T>
struct segtree{
    int n;
    T dat[2*MAX_N-1];
    T cnt[2*MAX_N-1];

    void init(int n_){
        n = 1;
        while(n < n_) n *= 2;
        for(int i = 0; i < 2*n-1; i++) dat[i] = 0;
    }

    void update(int k, T a){
        k += n-1;
        dat[k] += a;
        while(k > 0){
            k = (k-1)/2;
            dat[k] = dat[k*2+1]+dat[k*2+2];
        }
    }

    //(a,b,0,0,seg.n)で呼ぶ
    T query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return dat[k];
        else{
            T vl = query(a,b,k*2+1,l,(l+r)/2);
            T vr = query(a,b,k*2+2,(l+r)/2,r);
            return vl+vr;
        }
    }
};

int n;
vector<ll> X, Y;
vector<ll> x, y;
vector<pl> p;
segtree<ll> seg;
ll block[200000][4];
ll po2[200001];

int main() {
    cin >> n;
    po2[0] = 1;
    for (int i = 1; i <= n; i++) po2[i] = po2[i-1] * 2 % MOD;
    rep(i,n) {
        ll tx, ty;
        cin >> tx >> ty;
        X.push_back(tx); Y.push_back(ty);
    }
    x = compress(X);
    y = compress(Y);
    rep(i,n) p.push_back(pl(y[i],x[i]));
    sort(p.begin(), p.end());
    seg.init(p.size());
    rep(i,p.size()) {
        block[i][0] = seg.query(0, p[i].second, 0, 0, seg.n);
        block[i][1] = i-block[i][0];
        seg.update(p[i].second, 1);
    }
    reverse(p.begin(), p.end());
    seg.init(p.size());
    rep(i,p.size()) {
        block[p.size()-1-i][3] = seg.query(0, p[i].second, 0, 0, seg.n);
        block[p.size()-1-i][2] = i-block[p.size()-1-i][3];
        seg.update(p[i].second, 1);
    }
    ll ans = 0;
    rep(i,n) {
        ll add = po2[n]-1;
        rep(j,4) add = (add - po2[block[i][j]+block[i][(j+1)%4]] + 1 + 2*MOD) % MOD;
        rep(j,4) add = (add + (po2[block[i][j]]-1)) % MOD;
        (ans += add) %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 24552
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>
#include <map>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(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; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

//////////////////////////////////////////////////////////////



int main() {

	ll N, K;
	cin >> N >> K;

	vector<int> A(N);
	rep(i, N) {
		cin >> A[i];
		A[i]--;
	}
	int a=0, b=0;

	while (1) {
		a = A[a];
		b = A[b];
		b = A[b];
		if (a == b)break;		
	}

	a = 0;
	int k = 0;
	while (1) {
		if (a == b) {
			break;
		}
		k++;
		a = A[a];
		b = A[b];
		b = A[b];
	}
	int circle = 1;
	b = A[b];
	while (a != b) {
		circle++;
		b = A[b];
	}

	int ans = 0;
	if (K < k) {
		
		rep(i, K)ans = A[ans];
	}
	else {
		ans = a;
		K -= k;
		K = K % circle;
		rep(i, K)ans = A[ans];
	}
	cout << ans + 1 << endl;
}


Measured memory_bytes: 4052
#include <stdio.h>
int main(void){
  int h,w,i,j;
  while(scanf("%d %d",&h,&w),h+w){
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        if(!((i+j)%2))
          putchar('#');
        else
          putchar('.');
      }
      putchar('\n');
    }
    putchar('\n');
  }
  return 0;
}

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

int main() {
  int N;
  int dig;
  int sum=0;
  cin >>N;
  int num=N;
  while(num){
    dig = num % 10;
      sum = sum +dig;
      num = num /10;
  }
  if(N % sum ==0){
    cout << "Yes" <<endl;
    }
  else {
    cout << "No"<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x;
	cin>>n>>x;
	vector<int>m(n);
	int lo=0;
	for(int i=0;i<n;i++){
		cin>>m.at(i);
		lo+=m.at(i);}
	int y=x-lo;
	sort(m.begin(),m.end());
	int z=m.at(0);
	int sub=y/z;
	cout<<n+sub<<endl;
	return 0;}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  char s[3];
  cin >> s;
  if(s[0] == '9') cout << 1;
  else cout << 9;
  if(s[1] == '9') cout << 1;
  else cout << 9;
  if(s[2] == '9') cout << 1;
  else cout << 9;
  cout << endl;
}


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

ll A, B;

void solve() {
  ll res = 0;
  if (A > 12) {
    res = B;
  } else if (A < 6) {
    res = 0;
  } else {
    res = B / 2;
  }
  cout << res << "\n";
  return;
}

int main() {
  cin >> A >> B;
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    string s; cin >> s; sort(s.begin(), s.end());
    if(s == "abc")
        cout << "Yes";
    else
        cout << "No";
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#define min(a,b) (((a)<=(b))?(a):(b))

int toC(int A,int B,int C) {
	if(A==0&&B==0) return 0;
	if(C&1) return toC(A>>1,B>>1,C>>1);
	if(B&1) return toC(C>>1,B>>1,A>>1)+1+toC((A|B|C)>>1,0,0);
	if(A&1) return toC(A>>1,B>>1,C>>1)+2*toC((A|B|C)>>1,0,0)+2;
}
int main() {
	int n,m,t[3];
	while(scanf("%d %d",&n,&m),n||m) {
		t[0]=t[1]=t[2]=0;
		for(int i=0;i<3;i++) {
			int x,y;
			scanf("%d",&x);
			for(int j=0;j<x;j++) {
				scanf("%d",&y);
				t[i]|=(1<<(y-1));
			}
		}
		int ans=min(toC(t[0],t[1],t[2]),toC(t[2],t[1],t[0]));
		printf("%d\n",ans<=m?ans:-1);
	}
}

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

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

    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin>>A[i];
    }

    ll CurrentMoney = 1000;
    for(int i=0; i<N-1; i++){
        ll stock = 0;
        if(A[i] < A[i+1]){
            stock = CurrentMoney / A[i];
            CurrentMoney += (A[i+1] - A[i]) * stock;
        } 
    }
    cout<<CurrentMoney<<endl;

    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(auto i = (N) - 1; i >= 0; i -= 1)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define rand mtrand
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cout << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cout << #v << " = "; array_out(v , ##__VA_ARGS__);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
#endif
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = 0x1FFFFFFFFFFFFFFFLL;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}

random_device seed_gen; mt19937_64 mtrand(seed_gen());
constexpr int MOD = 1000000007;
//////////////////////////////////////////

int main(){
  ini(N);
  vi a(N); in(a);
  int ans = inf;
  for(int i = -100; i <= 100;i++){
    int cur = 0;
    rep(j,N) cur += (i - a[j]) * (i - a[j]);
    amin(ans , cur);
  }
  out(ans);

}

Measured memory_bytes: 256
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <unordered_map>
//#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007

int main() {
    int n;
    int tmp_a;
    bool ans=true;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> tmp_a;
        if(tmp_a%2==0 && tmp_a%3!=0 && tmp_a%5!=0){
            ans=false;
        }
    }
    if(ans==true){
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

//range s[l..r)
fn flip(s: &mut Vec<char>, l: usize, r: usize){
    for i in l..r+1{
        if s[i] == '0'{
            s[i] = '1';
        }else{
            s[i] = '0';
        }
    }
}

fn main(){
    let s = read_as_string().chars().collect::<Vec<char>>();

    let mut ans : i64 = std::i64::MAX;
    if s.iter().all(|x| *x == '1') || s.iter().all(|x| *x == '0'){
        println!("{}", s.len());
        return;
    }

    for i in 0..s.len()-1{
        if s[i] != s[i+1]{
            ans = cmp::min(ans, cmp::max(i+1, s.len()-i-1) as i64);
        }
    }

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


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
//#define hell        1000000007
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.0000001
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e7+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

using namespace std;
#include <stdio.h>

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0){
    if(y%2) res=(x%hell*res%hell)%hell;
    x=(x%hell*x%hell)%hell;
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,hell-2);
}

void solve();


void fastIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);

/*
  For freq or prime factors

for(auto pri:prime){
  while(k%pri==0){
    pcnt[pri]++;
    k/=pri;
  }
}*/


void solve(){
  int test;
  //cin>>test;
  test=1;
  while(test--){
        int n,k;
        cin>>n>>k;
        
        ll a[n];
        
        forn(i,0,n)
        cin>>a[i];
        
        double ans=0,sum;
        forn(i,0,k){
            sum+=double(a[i]+1)/2.0;
        }
        ans=sum;
        forn(i,k,n){
            sum-=double(a[i-k]+1)/2.0;
            sum+=double(a[i]+1)/2.0;
            
            if(sum-ans>eps)
            ans=sum;
        }
        cout<<fixed<<setprecision(7)<<ans;
  }         
}    

    




///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll a,ll b)
{
    while( b != 0)
	{
		ll  t = b;
		b= a %t;
		a = t;
	}
	return a;
}


ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1))*k);
  else
  return ((pw(k,x/2))*(pw(k,x/2)));
}





Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
vector<string> bit;


void subBin(string str, int n)
{
    if (n == 0){
        bit.push_back(str);
    }
    if (n > 0) {
        subBin(str + "0", n - 1);
        subBin(str + "1", n - 1);
    }
}
string toBin(int n){
    if(n == 1)return "1";
    else if(n == 0)return "0";

    return toBin(n/2)  + to_string(n%2);
}

long long gcd(long long a,long long b)
{
	if (a%b==0){
		return(b);
    }
	else{
		return(gcd(b,a%b));
    }
}

int main(){
    long long n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    vector<long long> idx;
    idx.push_back(0);
    long long ans, count;
    ans = count = 0;
    rep(i, n){
        //cout << endl << s[i] << endl;
        if(s[i] == '1'){
            while(s[i]=='1')i++;
            if(i > ans)ans = i;
            i--;
            continue;
        }
        if(s[i+1] == '0')continue;
        count++;
        if(s[i+1] == '1')idx.push_back(i++);
        while(s[i+1] == '1')i++;

        long long len;
        //cout << "i:" << i << "idx:";
        //rep(j, idx.size())cout << idx[j] << "->";
        //cout << endl << "count:" << count << endl;
        if(count > k)len = i - idx[count-k];
        else len = i - idx[0] + 1;
        //cout << "len:" << len << endl;
        if(len > ans)ans = len;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1020
import copy
S = list(input())
T = list(input())
ans = "UNRESTORABLE"

for i in range(len(S)-len(T),-1,-1):
    flag = 1
    s = copy.deepcopy(S)
    x = S[i:i+len(T)]
    for j in range(len(x)):
        if x[j] == "?":
            s[i+j] = T[j]
        elif x[j] != T[j]:
            flag = 0
            break
    if flag:
        ans = "".join(s).replace("?", "a")
        break
print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define ll long long
#define dot cout<< setprecision(20)<<endl;
#define vsor(x) sort(x.begin(),x.end());
#define vrev(x) reverse(x.begin(),x.end());
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define move(i) for(int i=0;i<4;i++)
#define bit(b,n) for(int b=0;b<(1<<(ll)(n));b++)

using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
typedef pair<int,int>P;//状態を表すクラスpairの場合、typedefしておくと便利

int main(){
    int x;
    cin>>x;
    if(x==1)cout<<0<<endl;
    else cout<<1<<endl;
}

Measured memory_bytes: 3596
#include <stdio.h>
int a[101][101];
int main(){
  int n,i,k,j,l,b;
  scanf("%d",&n);
 
  for(i=1;i<=n;i++){ 
    scanf("%d%d",&k,&l);    
 for(j=1;j<=l;j++){
   scanf("%d",&b);
   a[k][b]=1;
}

}

 for(i=1;i<=n;i++){ 
   for (j=1;j<=n;j++){
     if(j<n)     
       printf("%d ",a[i][j]);
     else printf("%d\n",a[i][j]);
}

}
return 0;
}

Measured memory_bytes: 636
import sys
readline = sys.stdin.readline

class BIT:
    #1-indexed
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.p = 2**(n.bit_length() - 1)
        self.dep = n.bit_length()
    def get(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
    
    def bl(self, v):
        if v <= 0:
            return -1
        s = 0
        k = self.p
        for _ in range(self.dep):
            if s + k <= self.size and self.tree[s+k] < v:
                s += k
                v -= self.tree[s+k]
            k //= 2
        return s + 1

def compress(L):
    L2 = list(set(L))
    L2.sort()
    C = {v : k for k, v in enumerate(L2)}
    return L2, C

N = int(readline())
A = list(map(int, readline().split()))
A2, C = compress(A)
A = [C[a] for a in A]
ok = 0
ng = max(A)+1
T = BIT(ng)
ma = min(A)+1
while abs(ok-ng) > 1:
    med = (ok+ng)//2
    B = [1 if a >= med else -1 for a in A]
    for i in range(1, N):
        B[i] += B[i-1]
    
    
    mb = -min(0, min(B))+1
    T = BIT(max(B)+mb)
    T.add(mb, 1)
    res = 0
    for b in B:
        res += T.get(mb+b)
        T.add(mb+b, 1)
    if res >= N*(N+1)//4:
        ok = med
    else:
        ng = med
print(A2[ok])

Measured memory_bytes: 93520
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,k,ans,a,b;
	cin>>n>>k;
	if(n%k==0)cout<<"0"<<endl;
	else if(n>k)
	{
		a=n/k;
		b=a+1;
		ans=min(abs(n-a*k),abs(n-b*k));
		cout<<ans<<endl;
	}
	else
	{
		if(n<=k/2)cout<<n<<endl;
		else cout<<k-n<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = a; i < n; i++)
#define Repr(i, n, a) for (int i = n; i >= a; i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n, m;
vector<int> v[100010], vv[100010];
int x[100010];
int cost[100010];
int par[100010];
set<int> st;
int r;

void bfs()
{
    queue<P> que;
    que.push(P{r, 1});
    while (!que.empty())
    {
        P a = que.front();
        int aa = a.first, bb = a.second;
        cost[aa] = bb;
        que.pop();
        if (st.count(aa) != 0)
            continue;
        else
            st.insert(aa);
        rep(i, v[aa].size())
        {
            if (x[v[aa][i]] == 1)
                que.push(P{v[aa][i], bb + 1});
            else
                x[v[aa][i]]--;
        }
    }
    return;
}
void dfs(int pos)
{
    rep(i, v[pos].size())
    {
        if (cost[v[pos][i]] == cost[pos] + 1)
        {
            par[v[pos][i]] = pos + 1;
            dfs(v[pos][i]);
        }
    }
}

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

    cin >> n >> m;
    rep(i, n + m - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        v[a].push_back(b);
        vv[b].push_back(a);
    }
    rep(i, n) x[i] = vv[i].size();
    rep(i, n) if (vv[i].size() == 0) r = i;
    bfs();
    par[r] = 0;
    dfs(r);
    rep(i, n) cout << par[i] << endl;
}

Measured memory_bytes: 23552
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#define pii pair<int,int> 
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){c=Getchar();rev|=c=='-';if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	if(c=='.'){
		c=Getchar();double t=0.1;
		while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
	}
	x=rev?-x:x;
	return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------head---------------------------------------------

const int inf=1e9;
const int N=1000005,M=100005,mod=1e9+7;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,D,Q,a[N],b[N],c[N];
set<int> s[N];

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	read(n,D);
	for(int i=1;i<=n;i++) 
		read(a[i]);
	s[n+1].insert(0);
	b[0]=D;
	for(int i=1;i<=n;i++)
		b[i]=min(b[i-1],abs(b[i-1]-a[i]));
	c[n+1]=0;
	for(int i=n;i;i--)
		if(a[i]<=c[i+1]*2+1) c[i]=c[i+1]+a[i];
		else c[i]=c[i+1];
	read(Q);
	for(int i=1;i<=Q;i++){
		int x,isok=0;read(x);
		puts(b[x-1]>c[x+1]?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 59392
from sys import stdin 
n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
answer = 0
r = 0
g = 0 
b = 0
for i in range(n):
    if s[i] == 'R':
        r += 1
    elif s[i] == 'G':
        g += 1
    else:
        b += 1
answer += r*g*b
for i in range(n):
    for j in range(i):
        k = 2*j - i
        if k >= 0:
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                answer -= 1
print(answer)

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

using namespace std;


bool binary_search(int a[],int n,int x){
    int l=0,r=n;
    while(r-l>0){
        int mid = (l+r)/2;
        if(a[mid] == x)return true;
        else if(x < a[mid])r=mid;
        else l =mid+1;
    }
    return false;
}

int main(){
    int N,q,ans=0;
    int S[100000]={};
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> S[i];
    }
    cin >> q;
    for(int i=0;i<q;i++){
        int T;
        cin >> T;
        if(binary_search(S,N,T)){
            ans++;
        }
    }
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3468
import bisect
N = int(input())
L = list(map(int, input().split()))
count = 0

L.sort()

for i in range(N-2):
    for j in range(i+1,N-1):
        k = bisect.bisect_left(L,L[i]+L[j])
        count += k-j-1

print(count)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<int>
#define ll long long
using namespace std;


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

    int ans = 0;
    rep(i, 1, s.size()){
        if(s[i] == '1' && s[i-1] == '1'){
            s[i] = '0';
            ans++;
        }
        else if(s[i] == '0' && s[i-1] == '0'){
            s[i] = '1';
            ans++;
        } 
    }

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

Measured memory_bytes: 512
from heapq import *
from collections import deque
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

t = int(input())

ans = [0]*t
for i in range(t):
    n = int(input())
    plus = [[] for i in range(n)]
    minus = [[] for i in range(n)]
    delta = 0
    for _ in range(n):
        k,l,r = map(int,input().split())
        k -= 1
        ans[i] += r
        if l-r > 0:
            plus[k].append(l-r)
        elif l-r < 0:
            minus[k].append(l-r)
            delta += l-r
    can = 0
    pq = []
    for j in range(n-1,-1,-1):
        while plus[j]:
            heappush(pq,-plus[j].pop())
        if pq:
            delta += -heappop(pq)
            can += 1
    pqm = []
    for j in range(n):
        if j >= can and pqm:
            delta += -heappop(pqm)
        while minus[j]:
            heappush(pqm,minus[j].pop())
    ans[i] += delta
print("\n".join(str(i) for i in ans))


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

#define LL long long
#define RG register

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 1e5 + 10;
int p[N], siz[N], X[N], Y[N], fa[N];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
LL D[N];
map<LL, int> M;
vector<int> e[N];
bool cmp(int x, int y) { return D[x] > D[y]; }
LL res;
void dfs(int u, int ff) {
	siz[u] = 1;
	for (auto v : e[u])
		if (v != ff) {
			dfs(v, u);
			res += siz[v];
			siz[u] += siz[v];
		}
}
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi<int>();
	for (int i = 1; i <= n; i++)
		D[i] = gi<LL>(), M[D[i]] = i, p[i] = i;
	sort(p + 1, p + 1 + n, cmp);
	for (int i = 1; i <= n; i++) siz[i] = 1, fa[i] = i;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		int x = p[i];		
		if (M.find(D[x] - n + 2 * siz[x]) == M.end()) continue;
		int y = M[D[x] - n + 2 * siz[x]];
		if (find(x) == find(y)) continue;
		fa[find(y)] = find(x);
		siz[y] += siz[x]; X[++cnt] = x; Y[cnt] = y;
		e[x].push_back(y); e[y].push_back(x);
	}
	dfs(1, 0);
	if (cnt < n - 1 || res != D[1])
		puts("-1");
	else
		for (int i = 1; i < n; i++)
			printf("%d %d\n", X[i], Y[i]);	
	return 0;
}


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

int main(){ 
    int n;
    cin>>n;
    vector<long long int> a(n+1);
    a[0]=2;
    a[1]=1;
    for(int i=2;i<n+1;i++){
    a[i]=a[i-1]+a[i-2];
    }
    cout<<a[n];
    return 0;
}


Measured memory_bytes: 256
k = input()

if k[-1] in ['0','2','4','5','6','8']:
    print(-1)
else:
    k = int(k)
    i = 1
    x = 7
    while x != 0:
        if x % k == 0:
            break
        else:
            x = (x%k)*10 + 7
            i += 1
    print(i)

Measured memory_bytes: 9168
#include <stdio.h>
 
int main(void)
{
  char c;
  scanf("%c", &c);
  switch (c) {
    case 'A':printf("T\n");break;
    case 'C':printf("G\n");break;
    case 'G':printf("C\n");break;
    case 'T':printf("A\n");break;
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=LONG_LONG_MAX;
const ll ms=(2e5)+5;

int ar[10]={0};

int main()
{
    idfc;
    int n;
    cin>>n;
    int i;
    int e;

    while(n--)
    {
        cin>>e;
        e/=400;
        e=min(8,e);
        ar[e]++;
    }
    int a=0;
    int b=0;
    for(i=0;i<8;i++)
    {
        if(ar[i]){a++; b++;}
    }
    if(ar[8])
    {
        if(!a)a++;
        b+=ar[8];
    }
    cout<<a<<" "<<b;
    
    return 0;
}

Measured memory_bytes: 3584
//include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

//conversion
//------------------------------------------
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();
}

//math
//-------------------------------------------
template <class T>
inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

int main() {
    int ans {0};
    string s; cin >> s;
    REP (i, s.size()) {
        if (i % 2 == 0) {
            if (s[i] == 'p') --ans;
        }
        else {
            if (s[i] == 'g') ++ans;
        }
    }
    cout << ans << "\n";
}


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

int main() {
    double a, b, x;
    cin >> a >> b >> x;
    cout << setprecision(12);
    if (a * a * b * 0.5 > x) {
        double c = 2 * x / (a * b);
        cout << 180 * atan(b / c) / M_PI << endl;
    } else {
        double l = (2 * x - a * a * b) / (a * a);
        cout << 180 * atan((b - l) / a) / M_PI << endl;
    }
    return 0;
}


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

int main(){
  int n, x;
  cin >> n;
  vector<queue<int>> an(n);
  for(int i=0; i<n; ++i) for(int j=0; j<n-1; ++j){
    cin >> x;
    --x;
    an[i].push(x);
  }
  queue<int> que1;
  for(int i=0; i<n; ++i) que1.push(i);
  int day = 0;
  int mach = n *(n-1) /2;
  while(mach >0){
    ++day;
    vector<bool> played(n,false);
    queue<int> que2;
    while(!que1.empty()){
      x = que1.front();
      que1.pop();
      if(played[x] || an[x].empty()) continue;
      int y = an[x].front();
      if(an[y].front() == x){
        played[x] = true;
        played[y] = true;
        que2.push(x);
        que2.push(y);
        --mach;
      }
    }
    for(int i=0; i<n; ++i) if(played[i]) an[i].pop();
    /*
    cout << "day" << day << " ";
    for(int i=0; i<n; ++i){
      cout << i << ":";
      if(played[i]) cout << "play ";
      else cout << "stay ";
    }
    cout << endl;
    */
    if(que2.empty()){
      cout << -1 << endl;
      return 0;
    }
    que1 = que2;
    while(!que2.empty()) que2.pop();
  }
  cout << day << endl;
}

Measured memory_bytes: 8016
#include<bits/stdc++.h>
using namespace std;
static const int INF=10000000000;
int main(){
int H,N;
  cin>>H>>N;
  vector<int64_t>A(N);
  vector<int64_t>B(N);
  for(int i=0;i<N;i++){
  cin>>A.at(i);
    cin>>B.at(i);
 }vector<vector<int64_t>>dp(N+1,vector<int64_t>(H+1,0));
  for(int j=1;j<=H;j++)
    dp[0][j]=INF;
  for(int i=1;i<=N;i++){
  for(int j=1;j<=H;j++){
  if(A[i-1]<=j)
    dp[i][j]=min(dp[i][j-A[i-1]]+B[i-1],dp[i-1][j]);
  else
    dp[i][j]=min(dp[i-1][j],B[i-1]);
  }
  }cout<<dp[N][H]<<endl;
   return 0;
}

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

using namespace std;


int main(){
  long long int i,o,t,j,l,s,z ;
   cin >> i >> o >> t >> j >> l >> s >> z ;
  
  if(i > 0 && j > 0 && l > 0){

  long long int a = (i/2)*2+(j/2)*2+(l/2)*2;
  long long int b = ((i-1)/2)*2 + ((j-1)/2)*2 + ((l-1)/2)*2 + 3;
  long long int ans = max(a,b);
  
  cout << ans + o << endl;
  
}
  
  else{
    cout << (i/2)*2+(j/2)*2+(l/2)*2 + o << endl;
  }
  
}
  
 


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

ll n, k, m, M = 1e9 + 7;

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

    ll a, b;
    cin >> a >> b;

    ll num;
    if(b < 10) num = 1;
    else if(b < 100) num = 2;
    else num = 3;

    ll c = a * pow(10, num) + b;
    ll d = sqrt(c);

    if(d * d == c) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3900
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;

const ll INF = 1ll << 60;

int main()
{
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, n)
    {
        int t;
        cin >> t;
        mp[t]++;
    }
    int ans = 0;
    for (auto x : mp)
    {
        int val = x.first;
        int num = x.second;
        if (num >= val)
        {
            ans += num - val;
        }
        else
        {
            ans += num;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> A(N);
    for(auto& i : A)cin >> i;
    partial_sum(A.begin(), A.end(), A.begin());
    unsigned long a{numeric_limits<unsigned long>::max()};
    for(unsigned long i = 0; i < N; ++i)a = min(a, max(A.back(), 2 * A[i]) - min(A.back(), 2 * A[i]));
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

class Main {
    //
    static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int ans = 0;
        for(int i = n;i <= m;i++){
            char[] s = String.valueOf(i).toCharArray();
            if(s[0]==s[4]&&s[1] == s[3])ans++;
        }
        System.out.println(ans);
    }
}

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

struct Card {char alpha; int num;};

void BubbleSort(Card c[], int n){
    for(int i=0;i<n;i++){
        for(int j=n-1;j>i;j--){
            if(c[j].num < c[j-1].num)swap(c[j], c[j-1]);
        }
    }
}

void SelectionSort(Card c[], int n){
    for(int i=0;i<n;i++){
        int minj=i;
        int j;
        for(j=i;j<n;j++){
            if(c[j].num < c[minj].num)minj=j;
        }
        swap(c[i], c[minj]);
    }
}

bool CheckStable(Card c1[], Card c2[], int n){
    int counting=0;
    for(int i=0;i<n;i++){
        if(c1[i].alpha != c2[i].alpha)return false;
    }
    return true;
}

int main(){
    Card c1[40], c2[40];
    int n; cin >> n;

    for(int i=0;i<n;i++){
        cin >> c1[i].alpha >> c1[i].num;
        c2[i]=c1[i];
    }
 
    BubbleSort(c1, n);
    for(int i=0;i<n;i++){
        if(i)cout << " ";
        cout << c1[i].alpha << c1[i].num; 
    }

    cout << endl << "Stable" << endl;

    SelectionSort(c2, n);
    for(int i=0;i<n;i++){
        if(i)cout << " ";
        cout << c2[i].alpha << c2[i].num;
    }
    
    cout << endl;

    if(CheckStable(c1, c2, n))cout << "Stable" << endl;
    else cout << "Not stable" << endl;
    
}


Measured memory_bytes: 3120
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
	int n,m,i,ans=0;
	cin>>n>>m;
	int x[m],sa[m-1];
	for(i=0;i<m;i++)cin>>x[i];
	sort(x,x+m);
	for(i=1;i<m;i++)sa[i-1]=x[i]-x[i-1];
	sort(sa,sa+m-1);
	for(i=0;i<m-n;i++)ans+=sa[i];
	cout<<ans<<endl;
}


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

int n, m;
string grid[1000];
int ans[1000][1000];
bool found[1000][1000];

int dp(int r, int c){
	if(r >= n || c >= m)
		return 1e9;
	if(r == n-1 && c == m-1){
		return 1;
	}
	if(found[r][c])
		return ans[r][c];
	found[r][c] = true;
	return ans[r][c] = min(
		dp(r+1, c) + (grid[r+1][c] != grid[r][c]),
		dp(r, c+1) + (grid[r][c+1] != grid[r][c]));
}

int main(){
	cin >> n >> m;
	for(int i = 0; i < n; ++i){
		cin >> grid[i];
	}
	if(grid[0][0] == '.')
		printf("%d\n", dp(0, 0)/2);
	else
		printf("%d\n", (dp(0, 0)+1)/2);
}

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

typedef long long ll;

int
main(void){
  string s; cin >> s;
  map<string, int> map;
  map["SUN"] = 7;
  map["MON"] = 6;
  map["TUE"] = 5;
  map["WED"] = 4;
  map["THU"] = 3;
  map["FRI"] = 2;
  map["SAT"] = 1;
  cout << map[s] << endl;

  return 0;
}

Measured memory_bytes: 256