akhauriyash/Code-Regression huggingface dataset:
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int N;
    R(N);
    int ma=0;
    int ss=0;
    REP(i,N){
        int x;
        R(x);
        ma=max(ma,x);
        ss+=x;
    }
    W(ss-ma/2);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
using namespace std;
vector <int> a;
void insert(int t) {
    int k = a.size();
    a.push_back(t);
    while (k != 0 && a[(k - 1) / 2] < a[k]) {
        swap(a[k], a[(k - 1) / 2]);
        k = (k - 1) / 2;
    }
}
 

void maxheapify(int i) {
    int l = 2 * i + 1;
    int r = 2 * i + 2;
    int largest = i;
    if (l<(int)a.size() && a[l]>a[i]) {
        largest = l;
    }
    if (r<(int)a.size() && a[r]>a[largest]) {
        largest = r;
    }
    if (largest != i) {
        swap(a[i], a[largest]);
        maxheapify(largest);
    }
}

int extractmax() {
    int c;
    c = a[0];
    a[0] = a.back();
    a.pop_back();
    maxheapify(0);
    cout << c << endl;
}
int main() {
    string x;
    int y;
    while (cin >> x) {
        if (x == "end") {
            return 0;
        }
        else if (x == "insert") {
            cin >> y;
            insert(y);
        }
        else if (x=="extract"){
            extractmax();
        }
    }
}

Measured memory_bytes: 7008
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import combinations
def run():
    N, *X = list(map(int, read().split()))
    A = sum(X)
    B = sum([val ** 2 for val in X])
    if A%N == 0:
        print(round(B - A ** 2 / N))
    else:
        p = A // N
        alpha = min(abs(p - A/N), abs(p - A/N + 1)) ** 2 * N + B - A ** 2 / N
        print(round(alpha))


if __name__ == "__main__":
    run()

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const double PI=3.141592653589;

int main(){
    double a, b, x;
    cin >> a >> b >> x;

    double ans;

    if(x <= a * a * b / 2.0){
        double y = 2 * x / a / b;
        ans = atan2(b, y);
        ans *= 180.0;
        ans /= PI;
    } else {
        double y = 2.0 * (a * a * b - x) / a / a;
        ans = atan2(y, a);
        ans *= 180.0;
        ans /= PI;
    }

    printf("%.10lf\n", ans);
    //cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

main() {
  int a[4], b[4], i, j, hit ,blow;

  while((scanf("%d %d %d %d %d %d %d %d", &a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3])) == 8) {
    hit = blow = 0;
    //HIT
    for(i=0 ; i<4 ; i++) {
      if(a[i] == b[i]) hit++;
    }
    //blow
    for(i=0 ; i<4 ; i++) {
      for(j=0 ; j<4 ; j++) {
	if(i==j) continue;
	if(a[i] == b[j]) blow++;
      }
    }
    printf("%d %d\n", hit, blow);
  }
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define Rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define Repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define Print(x) cout << (x) << endl 
#define Min2(a, b) ((a) < (b)) ? (a) : (b)
#define Max2(a, b) ((a) > (b)) ? (a) : (b)

typedef long long ll;

using namespace std;

int N, M;
vector<int> edge[8];

int solve(int node, int state){
    if((state >> node) & 1) return 0;
    else if((state | (1 << node)) == (int)pow(2, N) - 1) return 1;
    state = (state | (1 << node));
    int ret = 0;
    for(int i : edge[node]){
        ret += solve(i, state);
    }
    return ret;
}

int main(){
    int a, b, ans = 0;
    cin >> N >> M;
    Rep(i, 0, M){
        cin >> a >> b;
        edge[a - 1].push_back(b - 1);
        edge[b - 1].push_back(a - 1);
    }
    ans = solve(0, 0);
    Print(ans);
    return 0;
}

Measured memory_bytes: 512
N,C = map(int,input().split())
xv = [[0,0]]+[list(map(int,input().split())) for i in range(N)]+[[C,0]]
#0~N+1

#xがある位置
#vがカロリー

#時計回りでの最大値
tokei_maxs = [0]*(N+2)
#時計まわりでの最大値（現状）
tokei=[0]*(N+2)
tokei_max = 0
preans = 0
for i in range(1,N+1,1):
    tmpans = preans + xv[i][1] - (xv[i][0]-xv[i-1][0])
    tokei_max = max(tokei_max,tmpans)
    tokei[i]=tmpans
    tokei_maxs[i]=tokei_max
    preans = tmpans


#h時計回りでの最大値
htokei_maxs = [0]*(N+2)
htokei=[0]*(N+2)
#h時計まわりでの最大値（現状）
htokei_max = 0
preans = 0
for i in range(N,0,-1):
    tmpans = preans + xv[i][1] - (xv[i+1][0]-xv[i][0])
    htokei_max = max(htokei_max,tmpans)
    htokei_maxs[i]=htokei_max
    htokei[i]=tmpans
    preans=tmpans

ans = max(max(tokei),max(htokei))

for i in range(0,N+1,1):
    ans = max(ans,tokei[i]+htokei_maxs[i+1]-xv[i][0])
for i in range(N+1,0,-1):
    ans = max(ans,htokei[i]+tokei_maxs[i-1]-C+xv[i][0])

print(ans)



Measured memory_bytes: 95900
#include<bits/stdc++.h>
using namespace std;
string s;
int a,i,ans;
int main(){
	cin>>s;
	while(s.find("BW",i)!=-1){
		i=s.find("BW",i)+1;
		ans++;
	}
	i=0;
	while(s.find("WB",i)!=-1){
		i=s.find("WB",i)+1;
		ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
n, m = map(int, input().split())
alist = list(map(int, input().split()))

blist = [0]
for a in alist:
  blist.append(blist[-1] + a)

bdic = {}
for b in blist:
  rb = b % m
  if rb in bdic:
    bdic[rb] += 1
  else:
    bdic[rb] = 1

ans = 0
for v in bdic.values():
  if v >= 2:
    ans += ((v-1)*v) // 2
print(ans)


Measured memory_bytes: 63256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

int n;
int k;
int h[100010];
int f[100010];	//i点时的最小消耗 

int main()
{
	scanf("%d%d", &n, &k);
	
	
	for (int i = 1 ; i <= n ; i++)
		scanf("%d", &(h[i]));
		
	f[0] = 0;
	f[1] = 0;
	int j;	
	for (int i = 2 ; i <= n ; i++)
	{
		f[i] = -1;
		for (int dk = 1 ; dk <= k ; dk++)
		{
			j = i - dk;
			
			if (j >= 1)
			{
				int newF = f[j] + abs(h[j] - h[i]);
				if (f[i] == -1 || f[i] >= newF)
					f[i] = newF;
			}
		}
	}
	
	printf("%d\n", f[n]);
	
	return 0;
}

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

int main(){
  int n;
  cin >>n;
  string s[n];
  rep(i,n) cin>>s[i];
  int m;
  cin >>m;
  string t[m];
  rep(i,m) cin >>t[i];
  
  int max=0;
  
  rep(i,n){
    int cnt=0;
    rep(j,n){
      if(s[i]==s[j]) cnt++;
    }
    rep(l,m){
      if(s[i]==t[l]) cnt--;
    }
    if(max<cnt) max=cnt;
  }
  cout<<max<<endl;
}
    
  

Measured memory_bytes: 256
import sys
a=list(map(int,input().split()))
a.sort()
ans=0
while True:
    if a[0]==a[1]==a[2]:
        print(ans)
        sys.exit()
    if a[0]<a[1]:
        a[0]+=2
        ans+=1
        a.sort()
        if a[0]==a[1]==a[2]:
            print(ans)
            sys.exit()
    if a[0]==a[1]:
        a[0]+=1
        a[1]+=1
        ans+=1
        a.sort()
        if a[0]==a[1]==a[2]:
            print(ans)
            sys.exit()

Measured memory_bytes: 3064
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	int n, m;
	cin >> n >> m;
	vector<P>p(m);
	for (int i = 0; i < m; i++) {
		cin >> p[i].first >> p[i].second;
		
	}
	for (int i = 0; i < m; i++) {
		if (n >= 2 && p[i].first == 1 && p[i].second == 0) {
			cout << "-1" << endl;
			return 0;
		}
		
	}
	vector<ll>number(n,-1);
	for (int i = 0; i < m; i++) {
		if (number[p[i].first - 1] == -1) {
			number[p[i].first-1] = p[i].second;
		}
		else {
			if (p[i].second != number[p[i].first - 1]) {
				cout << "-1" << endl;
				return 0;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (n != 1 && i == 0 && number[i] == -1) {
			number[i] = 1;
		}
		else if (n != 1 && i == 0 && number[i] == -1)number[i] = 0;
		else if (number[i] == -1) {
			number[i] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << number[i];
	}
	cout << endl;
}



Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)

uint32_t a[10000];

int main(void) {
	uint32_t N;

	scanf("%"PRIu32"\n", &N);
	for (uint32_t idx = 0; idx < N - 1; idx++) {
		scanf("%"PRIu32" ", &(a[idx]));
	}
	scanf("%"PRIu32, &(a[N - 1]));

	uint32_t min2Div = UINT32_MAX;
	uint32_t max2Div = 0;
	uint32_t min3Mul = UINT32_MAX;
	uint32_t max3Mul = 0;
	uint32_t minOpCount = UINT32_MAX;
	uint32_t div2Sum = 0;
	uint32_t mul3Sum = 0;

	for (uint32_t idx = 0; idx < N; idx++) {
		uint32_t div2Count = 0;

		while (a[idx] % 2 == 0 && a[idx] > 1) {
			div2Count++;
			a[idx] /= 2;
		}
		div2Sum += div2Count;

		uint32_t mul3Count = 0;
		while (a[idx] <= UINT32_C(1000000000) / UINT32_C(3)) {
			mul3Count++;
			a[idx] *= 3;
		}
		mul3Sum += mul3Count;

		if (div2Count + mul3Count < minOpCount) {
			minOpCount = div2Count + mul3Count;
		}

		if (div2Count < min2Div) {
			min2Div = div2Count;
		}
		if (max2Div < div2Count) {
			max2Div = div2Count;
		}
		if (mul3Count < min3Mul) {
			min3Mul = mul3Count;
		}
		if (max3Mul < mul3Count) {
			max3Mul = mul3Count;
		}
	}

	printf("%"PRIu32,div2Sum);

	return 0;
}


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

#define N ((int)1e5 + 1)
#define forn(i,x,y) for(int i = int(x); i<int(y); i++)
#define debug(x) cerr << #x << " == " << (x) << '\n';

template<typename T> ostream &operator<<(ostream &out, const pair<T, T> &P){ out << P.first << ' ' << P.second; return out; }
template<typename T>
ostream &operator<<(ostream &out, const vector<T> &V){ for(int i = 0; i<V.size(); ++i) out << V[i] << (i == V.size() - 1 ? "" : " "); return out; }

template<typename T> istream &operator>>(istream &in, vector<T> &V){ for(T &i : V) in >> i; return in; }
template<typename T> istream &operator>>(istream &in, pair<T,T> &P){ in >> P.first >> P.second; return in; }

int main(){
    ios::sync_with_stdio(false);
    int n, a, b; cin >> n >> a >> b;
    cout << min(b, n*a) << '\n';

    return 0;
}

/* don't forget to check:
   int overflow
   min/max cases
   printing index of sorted array
   limits for ans
 */

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

#define REP(i,n) for(decltype(n) i=0; i<(n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define st first
#define nd second
#define pb push_back

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef long long ll;

void solve(){
    int k;
    cin>>k;
    vi dist(k,-1);
    deque<pii> q;
    dist[1] = 1;
    q.push_front({10%k, 1});
    q.push_back({2%k, 1});
    while(!q.empty()){
        auto p = q.front();
        q.pop_front();
        if(dist[p.st] != -1) continue;
        if(p.st == 10*p.nd%k) dist[p.st] = dist[p.nd];
        else dist[p.st] = dist[p.nd]+1;
        if(p.st == 0) break;
        q.push_front({10*p.st%k, p.st});
        q.push_back({(p.st+1)%k, p.st});
    }
    cout<<dist[0];
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort(all(vec));
#define rever(vec) reverse(all(vec));
#define bisea binary_search
#define unsort(vec) sort(vec); rever(vec);
#define cend cout<<endl;
using namespace std;
int gcd(int a,int b) {
  if(a<b) swap(a,b);
  if(b==0) return a;
  return gcd(b,a%b);
}
signed main() {
  int n,x;
  cin>>n>>x;
  int a;
  vector<int>vec(n+1);
  vector<int>vek(n);
  rep(i,n) cin>>vec.at(i);
  if(n==1) {
    cout<<abs(vec.at(0)-x)<<endl;
    return 0;
  }
  vec.at(n)=x;
  sort(vec);
  rep(i,n) {
    vek.at(i)=vec.at(i+1)-vec.at(i);
  }
  a=gcd(vek.at(0),vek.at(1));
  for(int i=2;i<n-1;i++) {
    a=gcd(a,vek.at(i));
  }
  cout<<a<<endl;
}

Measured memory_bytes: 1792
n = int(input())
a = list(map(int,input().split()))

sn = sum(a)
m = a[0]
mn = abs((sn - m)-m)
for i in range(1,n):
    if(abs((sn-m)-m)<mn):
        mn =abs( (sn  - m)-m)
    #print(mn)
    m += a[i]
    
print(mn)

Measured memory_bytes: 76752
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A=0, B=0;
  char op;
 
  cin >> A >> op >> B;
  if(op == '+')
    cout << A + B << endl;
  else if(op == '-')
    cout << A - B << endl;
  else
    cout << "error" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 200005;
ll A[MAX_N];

int main()
{
	int N;
	cin >> N;
	rep(i,N)
	{
		cin >> A[i];
	}
	ll M = A[0];
	ll ans = 0;
	rep(i,N-1)
	{
		if (A[i+1] < M)
		{
			ans += M- A[i+1];
		}
		M = max(M,A[i+1]);
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    while(cin>>n)
    {
        ll ans=(n*(n-1))/2LL;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    C = [[0]*10 for i in range(10)]
    N = read_int()
    for n in range(1, N+1):
        first = last = n%10
        while n != 0:
            first = n%10
            n //= 10
        C[first][last] += 1
    answer = 0
    for i in range(0, 10):
        for j in range(0, 10):
            answer += C[i][j]*C[j][i]
    return answer


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 73372
#include<stdio.h>

int main(void){
  int n,k,min=0;
  scanf("%d %d",&n,&k);
  while(1){
    min++;
    if((k-n)>=0){
      printf("%d\n",min);
      break;
    }else{
      n = (n-k)+1;
    }
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int m = sc.nextInt();
        
        int[] array = new int[n];
        int sum = 0;
        
        for(int i=0 ; i<m ; i++){
            array[i] = sc.nextInt();
            sum +=array[i];
        }
        
        int total = n-sum;
        
        if(total<0){
            System.out.println(-1);
        }else{
            System.out.println(total);
        }
    }
}

Measured memory_bytes: 43416
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int main(){
	char c[4] = {'.','?','!',' '};
	string S;
	while(cin>>S){
		string ans;
		if(S.size()%2!=0){
			puts("NA"); goto NEXT;
		}
		for(int i=0;i<S.size();i+=2){
			int a = S[i]-'0', b = S[i+1]-'0';
			if(!isdigit(S[i]) || !isdigit(S[i+1]) || a<1 || 6<a || b<1 || 5<b){
				puts("NA"); goto NEXT;
			}
			int n = (a-1)*5+(b-1);
			if(n<26) ans += ('a'+n);
			else if(n<30) ans += c[n-26];
			else{
				puts("NA"); goto NEXT;
			}
		}
		cout<<ans<<endl;
		NEXT:;
	}
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

int n;
vector<vi> adj;
vll a;

ll dfs(int x, int p) {
    vll r;
    ll t, s=0, m=-1;
    for(int y:adj[x]) if(y!=p) {
        t=dfs(y, x);
        if(t<0) return -1;
        s+=t;
        m=max(m, t);
    }
    if(m==-1) return a[x];
    t=s-a[x];
    if(t<0 || (m>s-m && s-m<t)) return -1;
    return s-2*t;
}

int main() {
    int i, u, v;
    scanf("%d", &n);
    a.assign(n+1, 0);
    for(i=1; i<=n; i++) scanf("%lld", &a[i]);
    adj.assign(n+1, vi(0));
    for(i=1; i<=n-1; i++) {
        scanf("%d%d", &u, &v);
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for(i=1; i<=n; i++) if(sz(adj[i])==1) break;
    printf(dfs(i, 0)>=0? "YES\n" : "NO\n");
    return 0;
}

Measured memory_bytes: 14336
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // double
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vii> data (4,vii(3,vi(10,0)));
  rep(i,n) {
      int a,b,c,d;
      cin >> a >> b >> c >> d;
      data[a - 1][b - 1][c - 1] += d;
  }
  rep(i,4) {
      rep(j,3) {
          rep(k,10) {
              cout << " " << data[i][j][k];
          }
          cout << "\n";
      }
      if(i <= 2) {
          rep(j,20) cout << "#";
          cout << "\n";
      }
  }
}


Measured memory_bytes: 3192
X = int(input())

def is_prime(n):
    if n == 2: return True
    if n < 2 or n%2 == 0: return False
    m = 3
    while m*m <= n:
        if n%m == 0: return False
        m += 2
    return True

while 1:
    if is_prime(X):
        print(X)
        exit()
    X += 1

Measured memory_bytes: 9188
#include <iostream>
#include <string>
#include <set>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
int main(){
    int n, x, D = 1000000000;
    cin >> n >> x;
    int xx [n + 1];
    for(int i = 0; i < n; i++) cin >> xx[i];
    xx[n] = x;
    sort(xx, xx + n + 1);
    D = abs(xx[0] - xx[1]);
    for(int i = 1; i < n; i++){
        D = __gcd(abs(xx[i] - xx[i + 1]), D);
    }
    cout << D << endl;

}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int f(int x) {
  if(x == 0) return 0;
  return (x % 10) + f(x / 10);
}

int main() {
  int x;
  cin >> x;
  if(x % f(x) == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
    return 0;
}


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

namespace AtCoder {
    class Program {

        static void Main(string[] args) {

            var n = int.Parse(Console.ReadLine());
            var v = Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToList();
            var result = 0;
            var av = new List<int>();
            var bv = new List<int>();

            for (int i = 0; i < v.Count; i++) {

                if (i % 2 == 0) {

                    av.Add(v[i]);
                } else {

                    bv.Add(v[i]);
                }
            }
            var ao = av.GroupBy(g => g).OrderByDescending(o => o.Count());
            var bo = bv.GroupBy(g => g).OrderByDescending(o => o.Count());

            var a = ao.First().Key;
            var b = bo.First().Key;
            if (a == b) {

                if (av.Distinct().Count() != 1 && bv.Distinct().Count() != 1) {

                    var ass = ao.Skip(1);
                    var bss = bo.Skip(1);

                    var aa = ass.First().Count();
                    var bb = bss.First().Count();

                    if (aa > bb) {

                        a = ass.First().Key;
                    } else if (aa < bb) {

                        b = bss.First().Key;
                    }
                } else {

                    b = a + 2;
                }
            }

            for (int i = 0; i < v.Count; i += 2) {

                if (a != v[i]) {
                    result++;
                }
            }
            for (int i = 1; i < v.Count; i += 2) {

                if (b != v[i]) {
                    result++;
                }
            }
            Console.WriteLine(result);
        }
    }
}


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


int main() {
  long long a , b ;
  cin >> a >> b ;
  
  long long sum=1;
  for(long long i = 0 ; i<a; i++ ){
    if(i==0){
      sum=sum*b;
    }
    if(i>0){
      sum=sum*(b-1);
    }
  }
    cout << sum << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	string A, B; cin >> A >> B;
	if (A.size() > B.size()) {
		cout << "GREATER" << endl;
		return 0;
	}
	else if (A.size() < B.size()) {
		cout << "LESS" << endl;
		return 0;
	}
	else {
		int i = 0;
		while (A[i]) {
			if (A[i] != B[i]) {
				break;
			}
			i++;
		}
		if (A[i] > B[i]) {
			cout << "GREATER" << endl;
			return 0;
		}
		else if (A[i] < B[i]) {
			cout << "LESS" << endl;
			return 0;
		}
		else {
			cout << "EQUAL" << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N,M;
    int A[114514];
    cin >> N >> M;
    REP(i,N){
        cin >> A[i];
    }
    priority_queue<int> P;
    REP(i,N){
        P.push(A[i]);
    }
    REP(i,M){
        int t=P.top();
        P.pop();
        P.push((int)t/2);
    }
    int Ans=0;
    while(!P.empty()){
        int s=P.top();
        P.pop();
        Ans+=s;
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 2168
using namespace std;
#include<iostream>
#include<stdio.h>

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

    long long ans = 0;

    long long i = 0;
    long long usiro = s.length()-1;

    while(i<usiro){
        //cout << i << usiro;
        //cout << s.substr(i,1) << s.substr(usiro,1);
        if (s.substr(i,1) == s.substr(usiro,1)){
            i++;
            usiro--;
        }
        else if(s.substr(i,1) == "x"){
            i++;
            ans++;
        }
        else if(s.substr(usiro,1) == "x"){
            usiro--;
            ans++;
        }
        else{
            ans = -1;
            i = 0;
            usiro = -1;
        }
        
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int R;
  cin >> N >> R;
  if(N >= 10){
    cout << R << endl;
  } else {
    int r = 10 - N;
    r = r * 100;
    R = R + r;
    cout << R << endl;
  }
}


Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;


int main() {
  ll a,b,n;
  cin >> a >> b >> n;
  if (b > n) cout << floor((a*n)/b) - a * floor(n/b) << endl;
  else cout << floor((a* (b-1))/b) - a * floor((b-1)/b) << endl;
}


Measured memory_bytes: 3228
n=int(input())
v=sorted(list(map(int,input().split())))
ans=0
l=len(v)
for i in range(n):
  if i==0:
    ans+=v[i]/((2**(l-1)))
  else:
    ans+=v[i]/(2**(l-1))
    l-=1
print(ans)

Measured memory_bytes: 3060
def s()
  gets().chomp
end
def i()
  gets.to_i
end
def li()
  gets.split.map(&:to_i)
end
def ili()
  n = gets.to_i
  as = gets.split.map(&:to_i)
  [n, as]
end

n, as = ili()

res = {}
before = as[0]
j = 0
1.upto(n-1){|i|
  if before == as[i]
    if res[j] == nil
      res[j] = 2
    else
      res[j] += 1
    end
  else
    j+=1
  end
  before = as[i]
}

res = res.select{|k, v| v>=2}
sum = 0
res.each{|k,v|
  sum += v/2
}
puts sum


Measured memory_bytes: 1788
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const long long INF = 1LL << 60;

long long dp[100010];

int N,K;
long long h[100010];

int main()
{
    cin >> N >> K;
    rep(i,N) cin >> h[i];

    rep(i,100010) dp[i] = INF;

    dp[0] = 0;

    rep(i,N){
        for(int j = 1; j<=K; ++j){
        chmin(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
            }
        }
    cout << dp[N-1] << endl;
    return 0;
}


Measured memory_bytes: 1792
num=int(input())
re=0
res=0
for i in range(num):
    a=input().split(" ")
    if a[0]==a[1]:
        re +=1
        if re>=3:
            res=1
    else:
        re=0

if(res==0):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9172
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int H1 = sc.nextInt();
        int M1 = sc.nextInt();
        int H2 = sc.nextInt();
        int M2 = sc.nextInt();
        int K = sc.nextInt();
        
        int ans = (H2 * 60 + M2) - (H1 * 60 + M1) - K;
        System.out.println(ans);
    }    
}

Measured memory_bytes: 27044
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define sum(x) accumulate(all(x),0)
#define gll greater<ll>()


void solve(){
 ll d;
  cin >> d;
  vll c(26);
  rep(i,0,26) cin >> c[i];  
  
 vvll s(d,vll(26));
  rep(i,0,d){
    rep(j,0,26) cin >> s[i][j]; 
  }
  vll t(d);
  rep(i,0,d) {
    cin >> t[i];
    t[i]--;
  }
  vll last(26,-1);
   ll ans=0;
  rep(i,0,d){
    ans+=s[i][t[i]];
    last[t[i]]=i;
    rep(j,0,26) ans-=c[j]*(i-last[j]);
    cout << ans << endl;
  }
  
}

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

Measured memory_bytes: 3708
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])
res = 0
output = 0
j = M
num = 0
for i in range(N + 1):
  if K < a[i]:
    break
  else:
    res = K - a[i]
  while b[j] > res:
    j -= 1
  num = i + j 
  output = max(output, num)
print(output)

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

int main() {
  string s, t;
  cin >> s >> t;
  if(s+t[t.size()-1] == t && 'a' <= t[t.size()-1] && t[t.size()-1] <= 'z') {
    cout << "Yes"<< endl;
  } else {
    cout << "No"<< endl;
  }

  return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
int main(){
char a[10],b[10];
scanf("%s %s",&a,&b);
int p = atoi(strcat(a,b));
if(sqrt(p)!=(int)sqrt(p)) printf("No");
else printf("Yes");
return 0;}


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



int main() {
  ll n;
  cin >> n;
  cout << n*(n-1)/2 << endl;
  return 0;
}

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

int main(void){
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    int lr = 0;
    int rl = 0;
    for(int i = 0; i < S.length() - 1; i++){
        if(S[i] == 'L' && S[i + 1] == 'R') lr++;
        else if(S[i] == 'R' && S[i + 1] == 'L') rl++;
    }
    if(lr < rl) swap(lr, rl);
    if(K >= lr) lr = rl = 0;
    else{
        lr -= K;
        rl -= K;
    }
    cout << N - lr - rl - 1 << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
//#include <numeric>
#include <vector>
	#include<math.h>
	//#include <algorithm>
	//#include <functional>
	//#include <numeric>
	//#include<cmath>
//#include <stdio.h> 
#include <cstdint>
	#include <string>
	//#include <cstdlib>
	//#define pi 3.14159265359
using namespace std;


int main() {

	string s, t;
	cin >> s>> t;
	int a;
	int b;
	cin >> a>>b;
	string u;
	cin >> u;

	if (s == u) {
		a -= 1;
	}
	else {
		b -= 1;
	}
	cout << a << " " << b;

	return 0;

}

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

using pii = pair<int, int>;
using ll = long long;

constexpr ll M = 1e9 + 7;

int main() {
    ll w, h, v, t, x, y, p, q;
    cin >> w >> h >> v >> t >> x >> y >> p >> q;
    vector<ll> xs = {p, w + (w - p)};
    vector<ll> ys = {q, h + (h - q)};
    for(int i = 0; ;) {
        ll t1 = xs[xs.size() - 2] + 2 * w, t2 = xs.back() + 2 * w;
        xs.push_back(t1);
        xs.push_back(t2);
        if(xs.back() >= v * t) {
            break;
        }
    }
    for(int i = 0; ;) {
        ll t1 = ys.back() + 2 * h, t2 = ys[ys.size() - 2] + 2 * h;
        ys.push_back(t1);
        ys.push_back(t2);
        if(ys.back() >= v * t) {
            break;
        }
    }
    int n = xs.size(), m = ys.size();
    for(int i = 0; i < n; ++i) {
        xs.push_back(-xs[i]);
    }
    for(int i = 0; i < m; ++i) {
        ys.push_back(-ys[i]);
    }
    n = xs.size(), m = ys.size();
    for(int i = 0; i < n; ++i) {
        xs[i] = (abs(xs[i] - x) * abs(xs[i] - x));
    }
    for(int i = 0; i < m; ++i) {
        ys[i] = abs(ys[i] - y);
    }
    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());

    ll res = 0;
    for(int i = 0; i < m; ++i) {
        if(ys[i] > v * t) {
            break;
        }
        res += upper_bound(xs.begin(), xs.end(), (v * t) * (v * t) - ys[i] * ys[i]) - xs.begin();
    }

    cout << res << endl;
}


Measured memory_bytes: 18944
#include<bits/stdc++.h>
using namespace std;
long long a[100005],mod=1e9+7;
long long qpow(long long a,long long b){
    long long res=1;
    while(b){
        if(b&1) res=res*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return res%mod;
}
int main(){
    long long n,k;
    cin>>n>>k;
    for(long long i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    long long sum=1,num=1;
    for(long long i=1;i<=k-1;i++){
        sum=sum*(n-i)%mod;
        sum%=mod;
    }
    for(long long i=1;i<=k-1;i++){
        num=num*i%mod;
        num%=mod;
    }
    long long x=(sum%mod*qpow(num,mod-2)%mod)%mod,y=x;
    long long num1=0,num2=0;
    for(long long i=1;i<=n+1-k;i++){
        num1=(num1+(y%mod*a[i]%mod)%mod)%mod;
        y=y%mod*qpow(n-i,mod-2)%mod*(n-k+1-i)%mod;
        y%=mod;
    }
    for(long long i=n;i>=k;i--){
        num2=(num2+(x%mod*a[i]%mod)%mod)%mod;
        x=x%mod*qpow(i-1,mod-2)%mod*(i-k)%mod;
        x%=mod;
    }
    cout<<(num2-num1+mod+mod)%mod<<endl;
}

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

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

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

    if(b>n){
        cout << (a*n)/b;
    }
    else{
        cout << (a*(b-1))/b;
    }

    return 0;
}


Measured memory_bytes: 3640
import copy


def main():
    h, w, k = [int(e) for e in input().split()]
    C = [list(input()) for i in range(h)]

    ans = 0
    for hi in range(2 ** h):
        hib = format(hi, f'0{h}b')
        for wi in range(2 ** w):
            wib = format(wi, f'0{w}b')

            CC = copy.deepcopy(C)
            for hci, hc in enumerate(hib):
                for wci, wc in enumerate(wib):

                    if hc == '1':
                        CC[hci] = ['r'] * w

                    if wc == '1':
                        for cc in CC:
                            cc[wci] = 'r'

            if sum([cc.count('#') for cc in CC]) == k:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 76252
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void){
  int N;
  scanf("%d\n",&N );
  int a[N];
  int count[100001]={0};
  int i;
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
    count[a[i]]++;
  }
  int max=0;
  int num=0;
  if(N>2){
    for(i=0;i<N-2;i++){
      num=count[i]+count[i+1]+count[i+2];
      if(num>max){
        max=num;
      }
    }
  }else if(N==2){
    if(abs(a[0]-a[1])<3){
      max=2;
    }
    else{
      max=1;
    }
  }else{
    max=1;
  }

  printf("%d",max);
}


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

int main()
{
    int a, b, c, d, left, right;
    cin >> a >> b >> c >> d;
    left = a + b;
    right = c + d;
    if (left > right)
    {
        cout << "Left" << endl;
    }
    else if (left < right)
    {
        cout << "Right" << endl;
    }
    else
    {
        cout << "Balanced" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,y;cin>>h>>w;
  char x;
  vector<string> a(h*w);
  for(int i=0;i<h*w;i++)cin>>a.at(i);
  
  vector<char> cap(w);
  cap.at(0)='A';
  for(int g=1;g<w;g++)cap.at(g)=cap.at(g-1)+1;
  
  for(int j=0;j<h*w;j++){
    if(a.at(j)=="snuke"){
      x=cap.at(j%w);
      y=j/w+1;
      break;
    }
  }
  cout<<x<<y<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

#define rep(i, s, n) for(int i = s;i<n;i++)
#define repe(i, s, n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<int> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll) 1 << 62;
const ll MOD = 1000000007, INF = 1e18;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};

template<typename T1, typename T2>
bool pairCompare(const pair<T1, T2> &firstElof, const pair<T1, T2> &secondElof) {
    return firstElof.second > secondElof.second;
}

int mapMaxValue(std::map<ll, int> m) {
    int max = 0;
    for (std::map<ll, int>::iterator it = m.begin(); it != m.end(); it++) {
        if (max < it->second) max = it->second;
    }
    return max;
}

int main(void) {
    int n, l;
    cin >> n >> l;
    vi taste(n);

    int n_sum = 0;
    for (int i = 0; i < n; ++i) {
        taste[i] = l + i;
        n_sum += taste[i];
    }

    int prev_diff = 9999;
    int diff = 0;
    for (int i = 0; i < n; ++i) {
        int ex_sum = 0;
        for (int j = 0; j < n; ++j) {
            if (i != j) {
                ex_sum += taste[j];
            }
        }
        diff = min(prev_diff, abs(n_sum - ex_sum));
        prev_diff = diff;
    }

    int ans = n_sum < 0 ? abs(diff) + n_sum : n_sum - diff;

    cout << ans << endl;
}

Measured memory_bytes: 256
program non_decreasing
  implicit none
  integer :: n, a(50), mn, mx, i, in, ix, k, b(50,2)
  a = 0
  b = 0
  read(*,*) n
  read(*,*) a(1:n)
  mn = minval(a(1:n))
  mx = maxval(a(1:n))
  do i = 1, n
    if (mn.eq.a(i)) in = i
    if (mx.eq.a(i)) ix = i
  end do
  k = 0
  if (sign(1,mn)*sign(1,mx).lt.0) then
    if (mx.gt.abs(mn)) then
      mn = mn + mx
      do i = 1, n
        if (a(i).lt.0) then
          k = k + 1
          b(k,1:2) = (/ix,i/)
        end if
      end do
    else
      mx = mx + mn
      do i = 1, n
        if (a(i).gt.0) then
          k = k + 1
          b(k,1:2) = (/in,i/)
        end if
      end do
    end if
  end if
  write(*,'(i0)') k+n-1
  if (k.gt.0) then
    do i = 1, k
      write(*,'(i0,x,i0)') b(i,1), b(i,2)
    end do
  end if
  if (mn.ge.0) then
    do i = 2, n
      write(*,'(i0,x,i0)') i-1, i
    end do
    stop
  end if
  if (mx.le.0) then
    do i = n-1, 1, -1
      write(*,'(i0,x,i0)') i+1, i
    end do
    stop
  end if
end program non_decreasing

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main()
{
    int N, K;
    cin>>N>>K;
    vector<int> H(N);
    for (int &h: H)
        cin>>h;

    set<int> S;
    S.insert(0);
    for (int h: H)
        S.insert(h);

    vector<int> V(S.begin(), S.end());
    int M = (int)V.size();
    vector<int> H2;
    for (int &h: H)
        for (int i=0; i<M; i++)
            if (V[i]==h)
                H2.push_back(i);

    long long oo = 1000000000000LL;
    vector<vector<long long>> T(K+1, vector<long long>(M, oo));
    T[0][0] = 0;
    for (int i=0; i<N; i++)
    {
        vector<vector<long long>> P(K+1, vector<long long>(M, oo));
        P.swap(T);

        for (int k=0; k<=K; k++)
        for (int m=0; m<M; m++)
        {
            T[k][H2[i]] = min(T[k][H2[i]], P[k][m]+max(0, V[H2[i]]-V[m]));
            if (k<K)
                T[k+1][m] = min(T[k+1][m], P[k][m]);
        }
    }

    long long ans = oo;
    for (auto &t: T)
        for (auto x: t)
            ans = min(ans, x);
    cout<<ans<<endl;
}


Measured memory_bytes: 1760
import sys
from collections import deque
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    H,W=map(int,input().split())
    a=[[] for _ in range(H+2)]
    a[0]=a[H+1]='#'*(W+2)
    for i in range(1,H+1):
        a[i]='#'+input()+'#'
    dp=[[0]*(W+2) for _ in range(H+2)]
    dp[1][1]=1
    que=deque()
    que.append((1,1))
    dx=[1,0]
    dy=[0,1]
    used=[[False]*(W*2) for _ in range(H+2)]
    used[1][1]=True
    while que:
        y,x=que.popleft()
        for k in range(2):
            ny,nx=y+dy[k],x+dx[k]
            if a[ny][nx]=='.':
                dp[ny][nx]+=dp[y][x]
                dp[ny][nx]%=MOD
                if not used[ny][nx]:
                    que.append((ny,nx))
                    used[ny][nx]=True
    print(dp[H][W])

if __name__ == '__main__':
    main()


Measured memory_bytes: 80220
import heapq

n = int(input().strip())
v = list(map(int, input().split()))
heapq.heapify(v)

while (1 < len(v)):
    heapq.heappush(v, (heapq.heappop(v) + heapq.heappop(v)) / 2)

print(v[0])


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    bool solution = false, c1, c2;
    string s;
    cin >> n >> s;
    int f[n];
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            if (solution == true) break;
            c1 = false;
            c2 = false;
            f[0] = i;
            f[1] = j;
            for (int k = 2; k < n; k++)
            {
                if (f[k - 1] == 1 && s[k - 1] == 'o')
                    f[k] = f[k - 2];
                if (f[k - 1] == 1 && s[k - 1] == 'x')
                    f[k] = (f[k - 2] + 1) % 2;
                if (f[k - 1] == 0 && s[k - 1] == 'o')
                    f[k] = (f[k - 2] + 1) % 2;
                if (f[k - 1] == 0 && s[k - 1] == 'x')
                    f[k] = f[k - 2];
            }
            if (s[0] == 'o' && (f[1] == f[n - 1]) == f[0]) c1 = true;
            if (s[0] == 'x' && (f[1] != f[n - 1]) == f[0]) c1 = true;
            if (s[n - 1] == 'o' && (f[0] == f[n - 2]) == f[n - 1]) c2 = true;
            if (s[n - 1] == 'x' && (f[0] != f[n - 2]) == f[n - 1]) c2 = true;
            if (c1 == true && c2 == true)
            {
                solution = true;
                for (int i = 0; i < n; i++)
                {
                    if (f[i] == 1) cout << 'S';
                    else cout << 'W';
                }
            }
        }
    }
    if (solution == false) cout << "-1";
}

Measured memory_bytes: 3984
import java.util.*;

public class Main{
    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int a[] = new int[n];

        for (int i=0; i<n; i++) a[i] = sc.nextInt();

        double mother = 0;

        for (int i=0; i<n; i++){
            mother += (double)1/a[i];
        }
        System.out.println((double)1/mother);

    }
}

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

using namespace std;

int main()
{
    int n ;
    cin >> n ;
    int arr[n];
    for(int i = 0 ; i < n ;i++)
    {
        cin >> arr[i];
    }
    if(n==1||n==2)
    {
        cout<< 1;
        return 0;
    }
    int ndiff=0;
    int ans=0;
    int pdiff=arr[1]-arr[0];
    for(int i = 2 ; i < n ;i++)
    {
      //  cout << arr[i]<< " " << pdiff << "\n";
        if(arr[i]==arr[i-1])
            continue;
        ndiff=arr[i]-arr[i-1];
        if(pdiff==0)
        {
            pdiff=ndiff;
            continue;
        }
        if(ndiff>0&&pdiff<0||ndiff<0&&pdiff>0)
        {
            ans++;
            pdiff=0;
        }
        //cout << ans << "\n";
    }
    ans++;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int a, b, c; cin >> a >> b >> c;
    cout << (a * b) / 2 << "\n";
}


Measured memory_bytes: 256
N = int(input())
texts = []
for i in range(N):
    texts.append((input()))

import collections
counters = []
count = 0
for text in texts:
    text_list = list(text)
    text_list.sort()
    text = "".join(text_list) 
    c = collections.Counter(text)
    counters.append(c)



ccccc = []
anss = []
for ccc in counters:
    ccc = str(ccc)
    ccccc.append(ccc)
    

dd = collections.Counter(ccccc)
for v in dd.values():
    ans = v * (v-1) / 2
    anss.append(ans)
    
print(int(sum(anss)))


Measured memory_bytes: 86844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  int ans=0;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  rep(i,0,N){
    int X; cin>>X;
    ans+=X;
  }
  vi C(N);
  rep(i,0,N) cin>>C[i];
  rep(i,1,N){
    if(A[i-1]+1==A[i]){
      ans+=C[A[i-1]-1];
    }
  }
  cout<<ans<<endl;
  }


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

int main() {
    int N;
    std::string S;
    std::cin >> N >> S;

    int cnt = 0;
    for (size_t i = 0; i < S.size() - 2; ++i) {
        if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
            ++cnt;
        }
    }

    std::cout << cnt << std::endl;

    return 0;
}


Measured memory_bytes: 256