akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100000
int a[MAXN+5];
int n,sum;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum+=abs(a[i]-a[i-1]);
	}
	sum+=abs(a[n+1]-a[n]);
	for(int i=1;i<=n;i++)
	{
		if((a[i]-a[i-1]<=0)==(a[i+1]-a[i]<=0))
			printf("%d\n",sum);
		else printf("%d\n",sum-2*(min(abs(a[i]-a[i-1]),abs(a[i+1]-a[i]))));
	}
}

Measured memory_bytes: 1536
#include <stdio.h>
#define MAX 100001

int partition(int A[],int p, int r){

  int x,i,j,rep;
x=A[r];
i=p-1;

  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
      i=i+1;
      rep=A[i];
      A[i]=A[j];
      A[j]=rep;
    }
  }

  rep=A[i+1];
  A[i+1]=A[r];
  A[r]=rep;

  return i+1;
}

int main(){

  int A[MAX],n,i,t;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  t=partition(A,0,n-1);

  for(i=0;i<n;i++){
    if(i==t){
      printf("[%d]",A[i]);
    }
      else printf("%d",A[i]);

    if(i<n-1){
      printf(" ");
    }

  }
  printf("\n");


  return 0;
}



/*1 partition(A, p, r)
  2   x = A[r]
  3   i = p-1
  4   for j = p to r-1
  4     if A[j] <= x
  5       i = i+1
  6       A[i] と A[j] を交換
  7   A[i+1] と A[r] を交換
  8   return i+1            */


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

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

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

int main(void){

    double a, b, angle;
    cin >> a >> b >> angle;

    double pi = acos(-1);

    double area = a * b * sin(angle*(pi/180)) / 2;
    double line = sqrt(a*a + b*b - 2*a*b*cos(angle*(pi/180))) + a + b;
    double high = area * 2 / a;

    cout << fixed << setprecision(8);
    cout << area << endl;
    cout << line << endl;
    cout << high << endl;

    return 0;
}



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

int main() {
  int N;
  cin >> N;
  int x = 0;
  int l, r;
  for (int i = 0; i < N; i++) {
  cin >> l >> r;
  x += (r - l + 1);
  }
  cout << x << endl;
}

Measured memory_bytes: 256
// #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define IMAX 2147483647
#define LMAX 9223372036854775807
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);
#define fou(i,a,n) for(int i=a;i<n;i++)
#define fod(i,a,n) for(int i=n-1;i>=a;i--)
#define rep(n) fou(_,0,n)
#define tra(a,x) for(auto& a : x)
#define elif(c) else if(c)
#define VI vector<int>
#define VD vector<double>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVD vector<VD>
#define VVC vector<VC>
#define VVS vector<VS>
#define emb emplace_back
#define pub push_back
#define pob pop_back
#define mp make_pair
#define fi first
#define se second
#define si(vec) ((int)(vec).size())
#define all(vec) vec.begin(),vec.end()
#define lla(vec) vec.rbegin(),vec.rend()
#define range(vec,x,y) vec.begin()+x,vec.begin()+y
#define sortup(vec) sort(all(vec))
#define sortdown(vec) sort(lla(vec))
#define eraseif(vec,condition_VAR) vec.erase(remove_if(all(vec),[&](auto VAR){return condition_VAR;}),vec.end())
#define countif(vec,condition_VAR) count_if(all(vec),[&](auto VAR){return condition_VAR;})
#define replaceif(vec,condition_VAR,n) replace_if(all(vec),[&](auto VAR){return condition_VAR;},n)
#define erase_unique(vec) vec.erase(unique(all(vec)),vec.end())
#define calcvec(vec,calc_VAR) for_each(all(vec),[&](auto&VAR){VAR=calc_VAR;});
#define calc2vec(vec1,op,vec2) {rep(1){int s=min(si(vec1),si(vec2));fou(i,0,s)vec1[i]=vec1[i] op vec2[i];}}
template<class C>void mini(C &a,C b){a=min(a,b);}
template<class C>void maxi(C &a,C b){a=max(a,b);}
#define in(T,...) T __VA_ARGS__;_cin(__VA_ARGS__);
#define out(...) _cout(__VA_ARGS__);
void _cin(){}template<class Head,class...Tail>void _cin(Head&head,Tail&&...tail){cin>>head;_cin(forward<Tail>(tail)...);}
template<class Head>void _cout(Head head){cout<<head<<endl;}template<class Head,class...Tail>void _cout(Head head,Tail...tail){cout<<head<<" ";_cout(forward<Tail>(tail)...);}
template<class C>void outvec(vector<C> vec){int vecsize=si(vec);fou(i,0,vecsize-1)cout<<vec[i]<<" ";out(vec[vecsize-1]);}
template<class C> C gcd(C a,C b){if(a&&b)return gcd(min(a,b),max(a,b)%min(a,b));else return a;}
template<class C> C lcm(C a,C b){return a/gcd(a,b)*b;}
template<class C>int binarysearch(vector<C> vec,C n,char c){int left=-1;int right=si(vec);bool outleft=(c=='d'||c=='U');int getmin=(c=='u'||c=='d')?1:-1;while(right-left>1){int mid=left+(right-left)/2;bool OK=vec[mid]*getmin>=n*getmin;if(outleft==OK) left=mid;else right=mid;}return outleft?left:right;}


#define int int64_t
// #define double long double


// map,makepair



signed main(){
  IOS;

  in(int,n,x);
  VI a(n);
  fou(i,0,n) cin>>a[i];

  int ans=0;
  if(a[0]>x){
    ans+=a[0]-x;
    a[0]=x;
  }
  fou(i,1,n){
    if(a[i-1]+a[i]>x){
      ans+=(a[i-1]+a[i])-x;
      a[i]-=(a[i-1]+a[i])-x;
    }
  }
  out(ans);
}

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

int min(int a, int b) {
    if (a <= b) {
        return a;
    } else {
        return b;
    }
}

int main(void) {
    long long int a, b, gcd = 1, sqrt;
    scanf("%lld%lld", &a,&b);
    long long int ans;
    for (long long int i = 2; i <= min(a,b); i++) {
        if (a%i==0 && b%i==0) {
            gcd = i;
        }
    }
    ans = a*b/gcd;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	int N, x;
	cin >> N >> x;
	int a[N];
	for(int i = 0; i < N; i++) cin >> a[i];
	sort(a, a + N);
	int ans = 0;
	for(int i = 0; i < N; i++) {
		ans++;
		x -= a[i];
		if(x <= 0) break;
	}
	if(x != 0) ans--;
	cout << ans;
	return 0;
}


Measured memory_bytes: 3632
using System;
using System.Linq;

public class ABC158_B {
	private static void Main(string[] args) {
		var input = ReadLongsAsArray();
		var n = input[0];
		var a = input[1];
		var b = input[2];

		var quotient = n / (a + b);
		var remainder =  n % (a + b);

		var answer = quotient * a + Math.Min(a, remainder);
		Console.WriteLine(answer);
	}

	private static long[] ReadLongsAsArray() => Console.ReadLine().Trim().Split().Select(x => long.Parse(x)).ToArray();
}

Measured memory_bytes: 13268
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int n,k,a,b;

int main()
{
	//fuck
	scanf("%d%d%d%d",&n,&k,&a,&b);
	if(n<=k)
	{
		printf("%d\n",a*n);
	}
	else
	{
		printf("%d\n",a*k+b*(n-k));
	}
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      int[][] a = new int[n][m];
      for (int i = 0; i < n; i++) {
        int k = sc.nextInt();
        for (int j = 0; j < k; j++) {
          a[i][j] = sc.nextInt();
        }
      }
      int[] list = new int[m+1];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (a[i][j] > 0) {
            list[a[i][j]] += 1;
          }
        }
      }
      int ans = 0;
      for (int i = 0; i < m+1; i++) {
        if (list[i] == n) {
          ans++;
        }
      }
      System.out.println(ans);
    }
  }

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

int main() {
    long n,k,ai,bi;
    cin >> n >> k;
    vector<long> l(100001);
    rep(i,n){
        cin >> ai >> bi;
        l[ai]+=bi;
    }
    for (int i = 0; i < 100001; i++){
        if (l[i] > 0){
            k-=l[i];
            if (k <= 0){
                cout << i << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 4032
N, P = map(int, input().split())
S = input()
l = list(reversed(list(S)))
each = [0]*N
ten = 1
for i in range(N):
    each[i] = int(l[i])*ten%P
    ten = ten*10%P
Sum = [0]*N
num = 0
for i in range(N):
    num = (num + each[i])%P
    Sum[i] = num
Sum.sort()
fac = Sum[0]
ans = 0
cnt = 0
for i in range(N):
    if Sum[i] == 0:
        ans += 1
    if Sum[i] == fac:
        cnt += 1
    else:
        ans += cnt*(cnt-1)//2
        cnt = 1
        fac = Sum[i]
ans += cnt*(cnt-1)//2
if P != 5 and P != 2:
    print(ans)
else:
    ans = 0
    for i in range(N):
        if int(l[i])%P == 0:
            ans += N-i
    print(ans)

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

int main() {

    int n;
    scanf("%d", &n);

    int arr[n];

    for (int i = n; i >= 1; i--) {
        
        int cnt = 0;

        int ntemp = i;

        while (ntemp >= 1) {
            
            if (ntemp % 2 == 0) {
                cnt++;
                ntemp /= 2;
            } else {
                break;
            }


        }
        arr[i] = cnt;

    }

    int maxdata = -1;
    int idx = 0;

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

        //printf("%d %d\n", i, arr[i]);
        if (maxdata < arr[i]) {
            idx = i;
            maxdata = arr[i];
        }

    }

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

    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll N = 3e3 + 5;

ll f[N]={0,0,0,1},n;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    if(n>3) for(int i=4;i<=n;i++) f[i]=(f[i-1]+f[i-3])%mod;
    cout<<f[n];
    return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;

    vector<vector<ll> > A(N, vector<ll>(3));

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

    ll ans = 0;

    for(int i = 0; i < 8; i++) {
        vector<ll> B(N);
        for(int j = 0; j < N; j++) {
            for(int k = 0; k < 3; k++) {
                if(i & (1 << k)) B[j] -= A[j][k];
                else B[j] += A[j][k];
            }
        }
        sort(B.begin(), B.end(), greater<ll>());

        ll c = 0;
        for(int j = 0; j < M; j++)
            c += B[j];
        
        ans = max(ans, c);
    }

    cout << ans << endl;
}

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

//macro
#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, n, m) for(int i = m; i < n; ++i)
#define LL long long

using namespace std;

typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

int main(){
    int h, w;
    cin >> h >> w;

    string a[101];
    REP(i, h){
        cin >> a[i];
    }

    REP(i, h){
        a[i].insert(a[i].begin(), '#');
        a[i].push_back('#');
    }

    REP(i, w + 2){
        cout << "#";
    }
    cout << endl;
    REP(i, h){
        cout << a[i] << endl;
    }
    REP(i, w + 2){
        cout << "#";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main()
{
	cin>>n>>s;
	if(s.size()>n)
	{
		for(int i=0;i<=n-1;i++)cout<<s[i];
		cout<<"...";
	}
	else 
		cout<<s;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =1e6+10;
const int mod=1e9+7;
int a[105];
int mp[1005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x,n;
    cin>>x>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    int min1=1e9;
    int ans=0;
    for(int i=-1000;i<=1000;i++)
    {
        if(i<0)
        {
            if(abs(i-x)<min1)
            {
                min1=abs(x-i);
                ans=i;
            }
            continue;
        }
        if(abs(i-x)<min1&&mp[i]==0)
        {
            min1=abs(x-i);
            ans=i;
        }
    }
    cout<<ans<<'\n';







}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(i=0;i<n;i++)
int main(){
  int aH,bP;
  int cH,dP;
  int yesFrag = 0;
  int noFrag = 0;
  
  cin >> aH >> bP >> cH >> dP; 
  
  while(1){
    
    cH -= bP;
    if(cH <= 0){
      yesFrag = 1;
      break;
    }
    
    aH -= dP;
    if(aH <= 0){
      noFrag = 1;
      break;
    }
  }
  if(yesFrag == 1){
    cout << "Yes";
  }
  if(noFrag == 1){
    cout << "No";
  }
    
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int n;
  int X[200010],Y[200010];
  cin>>n;
  for(int t=1;t<=n;t++){
    cin>>X[t];
    Y[t]=X[t];
  }

  sort(Y+1,Y+1+n);

  for(int t=1;t<=n;t++){
    if(X[t]<=Y[n/2]){
      cout<<Y[n/2+1]<<"\n";
    }else if(X[t]>=Y[n/2+1]){
      cout<<Y[n/2]<<"\n";
    }
  }

  return 0;
}


Measured memory_bytes: 3712
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long N, M;
  cin >> N >> M;
  map<long, long> mp;
  rep (i, M) {
    long a, b;
    cin >> a >> b;
    a--;
    b--;
    mp[a]++;
    mp[b]++;
  }
  rep (i, N) cout << mp[i] << endl;
}

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a[] = new int[26];
		String s = sc.next();
		for (int i=0;i<s.length();i++) {
			a[s.charAt(i)-'a']++;
		}
		for (int i=0;i<26;i++) {
			if (a[i]==0) {
				System.out.println((char)(i+'a'));
				return ;
			}
		}
		System.out.println("None");
		return ;
	}

	public class People implements Comparable<People> {
		int a;
		int b;
		@Override
		public int compareTo(People o) {
			return this.a - o.a;
		}

	}
}

Measured memory_bytes: 38992
#include<stdio.h>

int ab(int x){
	if(x<0)return -x;
	return x;
}

int main(){
	char S[11];
	int ans=99999;
	scanf("%s",S);
	for(int i=0;S[i+2]!='\0';i++){
		int x=(S[i]-'0')*100+(S[i+1]-'0')*10+(S[i+2]-'0');
		if(ab(x-753)<ans)ans=ab(x-753);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <array>
#include <functional>
#include <algorithm>
#include <numeric>
#include <string>
#include <stack>

int main()
{
	//std::cout << std::fixed << std::setprecision(15);

	long long N;
	std::string S;
	std::cin >> N >> S;

	if (N % 2 != 0)
	{
		std::cout << "No" << std::endl;
		return 0;
	}

	for (size_t i = 0; i < N / 2; ++i)
	{
		if (S.at(i) != S.at(i + N / 2))
		{
			std::cout << "No" << std::endl;
			return 0;
		}
	}

	std::cout << "Yes" << std::endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String weather = sc.next();

		int count = 0;
		String sunny = "RSR";

		for(int i=0; i<3; i++){
			if(weather.equals(sunny)){
				count= 1;
				break;
			}else if(weather.charAt(i) == 'R'){
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 26780
#include <algorithm>
#include <iostream>
#include <vector>

constexpr int mod {1000000007};
struct mint {
  using ll = long long;
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
constexpr long long N_max {100000};
std::vector<mint> inv_factorial(N_max+1);
std::vector<mint> factorial(N_max+1);

mint nCr(const long& n, const long& r) {
  if (n < r) return 0;
  return factorial[n]*inv_factorial[n-r]*inv_factorial[r];
}

int main(int argc, char** argv) {
  int N, K;
  std::cin >> N >> K;
  std::vector<long long> A(N);
  for (auto i = 0;i < N;++i) std::cin >> A[i];
  std::sort(A.begin(), A.end()); // A[0] = smallest, A[N-1] = biggest
  factorial[0].x = 1;
  for (long long i = 1;i <= N;++i) {
    factorial[i] = factorial[i-1]*i;
  }
  for (long long i = 0;i <= N;++i) {
    inv_factorial[i] = factorial[i].inv();
  }
  mint answer {};
  for (long long i = N-1;i >= 0;--i) {
    mint tmp = A[i];
    answer += tmp*nCr(i, K-1);
  }
//  std::cout << answer.x << '\n';
  for (long long i = 0;i < N;++i) {
    mint tmp = A[i];
    answer -= tmp*nCr(N-i-1, K-1);
  }
  std::cout << answer.x << '\n';
}


Measured memory_bytes: 3192
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    if(S.equals("Sunny")){
      System.out.println("Cloudy");
    }if(S.equals("Cloudy")){
      System.out.println("Rainy");
    }if(S.equals("Rainy")){
      System.out.println("Sunny");
    }
  }
}
    


Measured memory_bytes: 19796
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n,W;
    cin>>n>>W;
    int v[n];
    int w[n];
    for (int i=0;i<n;i++){
        cin>>w[i]>>v[i];
    }
    long long int k[n+1][W+1];
    for (int i=0;i<=n;i++){
        for (int j=0;j<=W;j++){
            if (i==0||j==0){
                k[i][j]=0;
            }
            else if(w[i-1]>j){
                k[i][j]=k[i-1][j];
            }
            else{
                k[i][j]=max(v[i-1]+k[i-1][j-w[i-1]],k[i-1][j]);
            }
        }
    }
    cout<<k[n][W];
}


Measured memory_bytes: 79104
#include "bits/stdc++.h"
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(c - a) <= d || (abs(b - a) <= d && abs(c - b) <= d)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	// Code for B - Thin
	var H, W int
	fmt.Scanf("%d %d", &H, &W)

	C := make([]string, H)
	for i := 0; i < H; i++ {
		fmt.Scanf("%s", &C[i])
	}

	for i := 0; i < H; i++ {
		fmt.Printf("%s\n%s\n", C[i], C[i])
	}
}


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

int main(){

	int H;
	int W;

	scanf("%d %d",&H,&W);

	char a[H][W];
	char b[H+2][W+2];

	for(int i=0; i<H+2; i++){
		for(int j=0; j<W+2; j++){
			b[i][j] = '#';
		}
	}

	for(int i=0; i<H; i++){
		scanf("%s",a[i]);
	}

	printf("\n");

	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			b[i+1][j+1] = a[i][j];
		}
	}

	for(int i=0; i<H+2; i++){
		for(int j=0; j<W+2; j++){
			printf("%c",b[i][j]);
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>

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

using namespace std;
using ll = long long int;
using ull = unsigned long long;

constexpr ull mod = 1e9+7;
constexpr int N = 13;
ull dp[100010][N];

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int n, i;
	string s;
	cin >> n >> s;
	if (n < 2 || n % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	for (i = 0; i < (s.length() / 2); i++) {
		if (s[i] != s[(s.length() / 2) + i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main(){
	string str;
	cin >> str;
	
	for(int i = 0; i < str.length(); i++){
		if(str[i] == ','){
			cout << " ";
		}else{
			cout << str[i];
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

template<typename T>
bool is_prime(T n)
{
	if (n == 2)
	{
		return true;
	}
	else if ((n == 1) || (n % 2 == 0))
	{
		return false;
	}

	T p = (T)sqrt(n);
	for (T i = 3; i <= p; i += 2)
	{
		if (n % i == 0)
		{
			return false;
		}
	}

	return true;
}

int main()
{
	int n;
	vector<ullong> prime;

	int sum = 0;
	int k = 0;
	for (ullong i = 2; ; i += (i == 2 ? 1 : 2))
	{
		if (is_prime(i))
		{
			sum += i;
			prime.push_back(sum);

			k++;
			if (k == 10000)
			{
				break;
			}
		}

	}

	for (; cin >> n;)
	{
		if (n == 0)
		{
			break;
		}
		cout << prime.at(n - 1) << endl;
	}
}


Measured memory_bytes: 3272
import java.util.*;

class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();

    int[] arr = new int[n];
    long result = 0;
    for(int i = 0; i < n; i++) {
      arr[i] = scan.nextInt();
    }

    for(int i = 0; i < n-1; i++) {
      if(arr[i]%2==1 && arr[i+1]>0) {
        arr[i]--;
        arr[i+1]--;
        result++;
      }
    }

    for(int i = 0; i < n; i++) {
      result += arr[i]/2;
      arr[i] %= 2;
    }

    for(int i = 0; i < n-1; i++) {
      if(arr[i] == 1 && arr[i+1] == 1) {
        arr[i]--;
        arr[i+1]--;
        result++;
      }
    }

    System.out.println(result);
  }
}


Measured memory_bytes: 23848
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        k: i64
    }
    let even = (1..k + 1).filter(|i| i % 2 == 0).count();
    let odd = (1..k + 1).filter(|i| i % 2 == 1).count();
    let ans = even * odd;
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<algorithm>
using namespace std;
int UF[1001];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);
	b=FIND(b);
	if(a==b)return;
	UF[a]+=UF[b];
	UF[b]=a;
}
int fib[1000];
int ABS(int a){
	return max(a,-a);
}
int main(){
	int a,b;
	fib[0]=2;
	fib[1]=3;
	for(int i=2;i<1000;i++)fib[i]=(fib[i-1]+fib[i-2])%1001;
	while(~scanf("%d%d",&a,&b)){
		for(int i=0;i<1001;i++)UF[i]=-1;
		for(int i=0;i<a;i++){
			for(int j=i+1;j<a;j++)if(ABS(fib[i]-fib[j])<b)UNION(i,j);
		}
		int ret=0;
		for(int i=0;i<a;i++)if(UF[i]<0)ret++;
		printf("%d\n",ret);
	}
}

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

using namespace std;

int main (void) {
    int N;
    long long K;
    cin >> N >> K;

    vector<long long> array(1e5 + 1, 0);
    int a, b;
    for ( int i = 0; i < N; i++ ) {
        cin >> a >> b;
        array.at(a) += b;
    }

    long long rest = K;
    for ( int i = 1; i < 1e5 + 1; i++ ) {
        rest -= array.at(i);
        if ( rest <= 0 ) {
            cout << i << endl;
            return 0;
        }
    }
    assert(0);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  i64 n;
  cin >> n;
  i64 ans = 0;
  for (i64 x = 1; x * x <= n; ++x) ans = x * x;
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 256
def cost(fr, to):
    if to <= fr:
        return fr - to
    else:
        d = to - fr
        return (d + 1) // 2 + d % 2


def main():
    a, b, c = map(int, input().split())
    ans = 9999999
    for m in range(min(a, b, c) - 5, max(a, b, c) + 5):
        ans = min(ans, cost(a, m) + cost(b, m) + cost(c, m))
    print(ans)


if __name__ == '__main__':
    main()

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

#include <utility>
using namespace std;

#define REP(i, n) for ( int i = 0; i < (n); i++ )
const int INF = 1e9;
using Pii = pair<int, int>;

const int con_type = 26;
int D = 365;
int C[con_type];
int S[365][con_type];
vector<int> ans;
int last[con_type];

struct State {
  int cost;
  vector<int> ans;
  vector<int> last;

  State() {
    cost = 0;
    last = vector<int>(26, -1);
  }

  State(int cost, vector<int> ans, vector<int> last):
    cost(cost), ans(ans), last(last) {};

  bool operator<( const State& s ) const {
    return cost < s.cost;
  }

  bool operator>( const State& s ) const {
    return cost > s.cost;
  }
};

void solve() {
  priority_queue<State> Q;
  Q.push(State());
  REP(d, D) {
    priority_queue<State> nQ;
    while ( !Q.empty() ) {
      State now = Q.top(); Q.pop();
      vector<Pii> add_cost;
      REP(i, con_type) {
        add_cost.emplace_back(Pii(S[d][i]+(d-last[i])*C[i], i));
      }
      sort(add_cost.begin(), add_cost.end(), greater<Pii>());
      REP(i, 5) {
        int id = add_cost[i].second;
        State next = now;
        next.cost += S[d][id];
        REP(j, con_type) {
          if ( j == id ) continue;
          next.cost -= (d-last[j])*C[j];
        }
        next.ans.emplace_back(id);
        next.last[id] = d;
        nQ.push(next);
      }
    }
    Q = priority_queue<State>();
    REP(i, min(200, (int)nQ.size())) {
      Q.push(nQ.top()); nQ.pop();
    }
  }

  ans = Q.top().ans;
}

void input() {
  cin >> D;
  REP(i, con_type) {
    cin >> C[i];
    last[i] = -1;
  }
  REP(i, D) REP(j, con_type) cin >> S[i][j];
}

void output() {
  REP(i, D) cout << ans[i]+1 << endl;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  input();
  solve();
  output();

  return 0;
}


Measured memory_bytes: 5760
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

string ans;
ll n;

void dfs(ll len, ll used) {
  if (len == n) {
    cout << ans << endl;
    return;
  }
  rep(i, used) {
    ans[len] = 'a' + i;
    dfs(len+1, used);
  }
  if (used < 26) {
    ans[len] = 'a' + used;
    dfs(len+1, used+1);
  }
}

void solve() {
  cin >> n;
  ans = string(n, 'a');
  dfs(0, 0);
}


Measured memory_bytes: 1536
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
N = int(input())
anslist = make_divisors(N)
anslice = anslist[len(anslist)//2-1:len(anslist)//2+1]
ansquare = anslist[len(anslist)//2]
if len(anslist)%2 == 0:
  print(sum(anslice)-2)
else:
  print(ansquare*2-2)


Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007ll;


int main(){
	int h,w;
	std::cin >> h>>w;
    rep(i,w+2)std::cout << "#" ;
    std::cout << std::endl;
	rep(i,h){
		string s;
		std::cin >> s;
		std::cout << "#"<<s<<"#" << std::endl;
	}
	rep(i,w+2)std::cout << "#" ;
    std::cout << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#define U unsigned
#define L long
using namespace std;

U L gcd(U L L a,U L L b){
	if (a*b==0) return (a==0?b:a);
	else if (b%a==0) return a;
	else return gcd(b,a%b);
}

int main(){
	U L L x,y,g;
	while(cin>>x>>y){
		g=gcd(x,y); cout<<g<<" "<<(x/g)*y<<"\n";
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define f(i,a,b,c) for(ll i=a;i<b;i+=c)
#define r(i,a,b,c) for(ll i=a;i>=b;i-=c)
#define mod 1000000007
int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll n; cin >> n;
    ll ar[n];
    f(i,0,n,1){
    	cin >> ar[i]; 
    }
    ll c = 0;
    sort(ar,ar+n);
    f(i,0,n-2,1){
    	f(j,i+1,n-1,1){
    		f(k,j+1,n,1){
    		if(ar[i]+ar[j]>ar[k] && (ar[i]!=ar[j] && ar[j]!=ar[k] && ar[k]!=ar[i]))
    			c++;
    		}
    	}
    }
    cout << c;
    return 0;
}

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

int main(){
  int N, M, h[1500], w[1500];

  while(cin >> N >> M, N){
    for(int i = 0; i < N; i++){
      cin >> h[i];
    }
    for(int i = 0; i < M; i++){
      cin >> w[i];
    }
    
    map< int, int > foo, piyo;
    for(int i = 0; i < N; i++){
      int sum = 0;
      for(int j = i; j < N; j++){
        sum += h[j];
        foo[sum]++;
      }
    }
    for(int i = 0; i < M; i++){
      int sum = 0;
      for(int j = i; j < M; j++){
        sum += w[j];
        piyo[sum]++;
      }
    }


    int cnt = 0;
    for(map< int , int >::iterator it = foo.begin(); it != foo.end(); it++){
      cnt += it -> second * piyo[it -> first];
    }
    cout << cnt << endl;
  }
}

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

using namespace std;
typedef long long li;
typedef pair <li, li> pi;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

int main() {
    li n, l;
    cin >> n >> l;

    vector<li> a(n);
    rep(i, n) {
        cin >> a[i];
    }

    li center = -1;
    rep(i, n-1) {
        if (a[i] + a[i+1] >= l) {
            center = i;
        }
    }

    if (center == -1) {
        cout << "Impossible" << endl;
    } else {
        cout << "Possible" << endl;
        for (int i = 0; i < center; ++i) {
            cout << i + 1 << endl;
        }
        for (int i = n - 2; i >= center; --i) {
            cout << i + 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <math.h>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cstdlib>
#include <unordered_map>
#include <numeric>
#include <functional>
#include <limits.h>
#include <utility>

using namespace std;

#define fs first
#define sc second

typedef long long ll;
typedef pair<ll, ll> P;

ll a[16][16];
ll dp[101000];

int main(){
    int N;
    cin >> N;
    fill(dp, dp+101000, 0);

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

    dp[0] = 0;
    for(int s = 1; s < (1 << N); s++){
        // 切らない
        ll res = 0;
        for(int i = 0; i < N; i++){
            for(int j = i+1; j < N; j++){
                if(((s >> i) % 2 & (s >> j) % 2) == 1){
                    res += a[i][j];
                }
            }
        }

        for(int t = (s-1) & s; t > 0; t = (t-1) & s){
            res = max(res, dp[t] + dp[(s^t)&s]);
        }
        dp[s] = res;
//        cout << s << " " << res << endl;
    }

    cout << dp[(1 << N) - 1] << endl;


    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>

using namespace std;

string finder,check;
int ring;
int answer;

int main()
{
	cin >> finder;
	cin >> ring;
	string str[100];
	for (int i = 0; i < ring; i++)
	{
		cin >> str[i];
		check = str[i] + str[i];
		if (check.find(finder) != -1)answer++;
		check.clear();
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 1216
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
const int mod=1e9+7;
inline int ad(int x){return x>=mod?x-mod:x;}
inline int dec(int x){return x<0?x+mod:x;}
inline int power(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}return ans;
}
int f[5010],g[5010],a[5010],b[5010];
int fac[5010],inv[5010];
inline int C(int n,int m){return 1LL*fac[n]*inv[m]%mod*inv[n-m]%mod;}
int fa[5010],s1[5010],s2[5010];
inline int findfa(int x)
{
	if(fa[x]!=x)fa[x]=findfa(fa[x]);
	return fa[x];
}
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	fac[0]=1;
	for(int i=1;i<=5000;i++)fac[i]=1LL*fac[i-1]*i%mod;inv[5000]=power(fac[5000],mod-2);
	for(int i=5000;i>=1;i--)inv[i-1]=1LL*inv[i]*i%mod;
	int n=read(),m=0,ans=0,cnt=0;
	for(int i=1;i<=n;i++)a[i]=read(),fa[i]=i,s1[i]=1;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==-1){cnt++;continue;}
		int fx=findfa(i),fy=findfa(a[i]);
		if(fx!=fy){fa[fy]=fx;s1[fx]+=s1[fy],s2[fx]+=s2[fy];}
		s2[fx]++;
	}cnt=power(n-1,cnt);
	for(int i=1;i<=n;i++)
	{
		int ff=findfa(i);
		if(ff!=i)continue;
		if(s1[i]>s2[i])b[++m]=s1[i];
		else ans=ad(ans+cnt);
	}
	for(int i=1;i<=m;i++)
	{	
		f[i]=fac[i];
		for(int j=1;j<i;j++)f[i]=dec(f[i]-1LL*C(i-1,j-1)*f[j]%mod*fac[i-j]%mod);
	}
	g[0]=1;
	for(int i=1;i<=m;i++)
	{
		for(int j=i;j>=1;j--)g[j]=ad(g[j]+1LL*g[j-1]*b[i]%mod);
	}
	for(int i=1;i<=m;i++)
	{
		int uf=g[i];if(i==1)uf-=m;
		ans=ad(ans+1LL*f[i]*uf%mod*power(n-1,m-i)%mod);
	}pr2(dec(1LL*n*cnt%mod-ans));
	return 0;
}

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int E = abs(A - B);
  int F = abs(B - C);
  int G = abs(C - A);
  if (G <= D || (E <= D && F <= D))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3624
loop do
    n, m = gets.split.map(&:to_i)
    break if n == 0 && m == 0
    r = gets.to_i
    log = r.times.map{gets.split.map(&:to_i)}
    q = gets.to_i
    fr = q.times.map{gets.split.map(&:to_i)}
    c = Array.new(m).map{Array.new(1261,0)}
    log.each do |l|
        c[l[2]-1][l[0]] += l[3] == 1 ? 1 : -1
    end
    fr.each do |f|
        u = Marshal.load(Marshal.dump(c[f[2]-1]))
        u.each_with_index do |d,j|
            next if j == 0
            u[j] += u[j-1]
        end
        p u[f[0]...f[1]].count{|d| d > 0}
    end
end

Measured memory_bytes: 107100
n, k = map(int, input().split())
p_list = list(map(int, input().split()))
num = sum(p_list[0:k])
max = 0
index = 0
value = 0

for i in range(n - k):
    num = num + p_list[i + k] - p_list[i]
    if num > max:
        max = num
        index = i + 1

for i in range(k):
    value += (1 + p_list[index + i])/ 2

print(value)


Measured memory_bytes: 24548
/**

F(i) = min( F(i-j) + |h[i]-h[i-j]| ) ; j = 1 to k

Base case:
F(1)   = 0   // as initial position , no cost
F(<=0) = INF // as not possible

**/

/** Which of the favors of your Lord will you deny ? **/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define MP make_pair
#define F first
#define S second

#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>using indexed_set = tree<TIn, null_type, less<TIn>,rb_tree_tag, tree_order_statistics_node_update>;

/**

PBDS
-------------------------------------------------
1) insert(value)
2) erase(value)
3) order_of_key(value) // 0 based indexing
4) *find_by_order(position) // 0 based indexing

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;
const LL LINF = 1e17;

template <class T>
string to_str(T x)
{
    stringstream ss;
    ss<<x;
    return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}

int ara[nmax];
int dp[nmax];

const int INF = 1e9;

int solve(int pos,int k)
{
    if(pos==1)
        return 0;
    if(pos<=0)
        return INF;

    int &ret = dp[pos];

    if(ret!=-1) return ret;

    ret = INT_MAX;

    for(int i=1;i<=k;i++)
        ret = min(ret, solve(pos-i,k) + abs(ara[pos]-ara[pos-i]));

    return ret;
}

int main()
{
    optimizeIO();

    int n,k;
    cin>>n>>k;

    for(int i=1;i<=n;i++)
        cin>>ara[i];

    memset(dp,-1,sizeof dp);

    cout<<solve(n,k)<<endl;

//    for(int i=1;i<=n;i++)
//        cout<<dp[i]<<" ";
//    cout<<endl;

    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}




Measured memory_bytes: 6144
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N = int(input())
list_V = list(map(float, input().split()))
list_V.sort()

n = 0.0
while len(list_V) >= 2:
    list_V.sort()
    n = (list_V[0] + list_V[1])/2
    list_V.append(n)
    list_V.pop(0)
    list_V.pop(0)

print(list_V[0])


Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int N,l,max_p,ans;
	cin >> N;
	ans = 0;
	max_p = 0;
	for (int i = 0;i < N;i++){
		cin >> l;
		max_p = max(max_p,l);
		ans += l;
	}	
	ans -= max_p / 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int D;
array<int, 26> C;
vector<array<int, 26>> S;
int main() {
    cin >> D;
    for (auto &c : C) cin >> c;
    S.resize(D);
    for (auto &row : S) for (auto &s : row) cin >> s;
    vector<int> last(26);
    Int value = 0;
    for (int d = 0; d < D; d++) {
        Int vmax = -1e18;
        Int tmax = 0;
        Int v = value;
        for (int i = 0; i < 26; i++) {
            v -= C[i] * (d + 1 - last[i]);
        }
        for (int t = 0; t < 26; t++) {
            Int v2 = v + S[d][t] + C[t] * (d + 1 - last[t]);
            if (v2 > vmax) {
                vmax = v2;
                tmax = t;
            }
        }
        value = vmax;
        last[tmax] = d + 1;
        cout << tmax + 1 << '\n';
    }
    cerr << value << endl;
    return 0;
}


Measured memory_bytes: 3700
#include<iostream>
using namespace std;
int main()
{
	int H, W;
	while (true)
	{
		cin >> H >> W;
		if (!H && !W)
			break;
		for (int i = 1; i <= H; i++)
		{
			for (int j = 1; j <= W; j++)
				cout << '#';
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3068
n, k = map(int, input().split())

a = list(map(int, input().split()))

visited = [1]
is_visited = [0] * n
now = 1
step = 0
for i in range(k):
    now = a[now-1]
    step += 1
    if is_visited[now-1] == 0:
        is_visited[now-1] = 1
        visited.append(now)
    else:
        ind = visited.index(now)
        loop = visited[ind:]
        tmp = (k-step) % len(loop)
        now = loop[tmp]
        break

print(now)


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

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int N;
    cin >> N;
    vector<int64_t> a(3 * N);
    rep(i, 3 * N) cin >> a.at(i);

    sort(a.begin(), a.end(), greater<int>());
    int64_t ans = 0;
    for (int i = 0; i < 2 * N; i++) {
        if (i % 2 == 1) {
            ans += a.at(i);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
#include <queue>
#include <complex>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

#define ll int64_t
const long MOD = 1e9 + 7;


int main()
{
  int n, m, q;

  cin >> n >> m >> q; //nは10の5乗数

  vector<long> l(m);
  vector<long> r(m);

  vector<long> p_(q);
  vector<long> q_(q);

  vector<vector<long> > d(n,vector<long>(n,0));
  // long d[1000][1000];


  // cerr << d.size() <<endl;

  for (int i = 0; i < m; ++i) {
    cin >> l[i] >> r[i];
    l[i]--;
    r[i]--;
    long dist = r[i] - l[i];
    d[l[i]][dist]+=1;
    // cerr <<"l=" <<l[i] <<" ";
  }

  // cerr << "A  " <<endl;

  //d[開始街][距離]
  for (int i = 0; i < n; ++i){
    for (int j = 1; j < n; ++j){
      d[i][j] += d[i][j-1];
    }
  }

  
  for (int i = 0; i < n; ++i){
    for (int j = 0; j < n; ++j){
      // cerr << "d_" << i <<"_" <<j << "="<<d[i][j]<<endl;
    }
  }

 // cerr << "B  " <<endl;
  //d[開始街][その距離以内の本数]


  for (int i = 0; i < q; ++i) {
    cin >> p_[i] >> q_[i];
    p_[i]--;
    q_[i]--;
  }

  // long dd[1000][1000];
  vector<vector<long> > dd(n,vector<long>(n,0));

  for (int i = 0; i < n; ++i){//d[i][dist] iからi+dist以内の本数
    for(int j=i;j<n;j++){//dd[i][j]街iからjまでの本数
      if (i==j){
        dd[i][j] = d[i][0];
        continue;
      }
      for(int l=0;l<=j-i;l++){//ここがエラーの原因d[i][j] = d[i][i-j]+,,,dd[1][5] =  1-4 2-3 3-2 4-1 5-0
        dd[i][j]+=d[i+l][ (j-i) -l];//1-4のとききょり3よってd[1][3],d[2][2] d[3][1]d[4][0]
      }
    }
  }


  // cerr << "C  " <<endl;

  // for (int i = 0; i < n; ++i){
  //   for (int j = 0; j < n; ++j){
  //     cerr << "d_" << i <<"_" <<j << "="<<dd[i][j]<<endl;
  //   }
  // }


  for (int i = 0; i < q; ++i) {//最大10^5
    long ans=0;
    long inter = q_[i] - p_[i];
    long start = p_[i];

    // for (int j = 0; j <= inter; ++j){//最大500=5*10^2
    //   ans += d[start + j][inter - j];
    //   // cerr << "d_" << start + j <<"_" <<inter - j << "="<<d[start + j][inter - j]<<endl;
    // }
    ans = dd[start][q_[i]];

    cout <<ans<<endl;
  }


  return 0;
}


Measured memory_bytes: 10880