akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;
 
int main() {
    ll n, ans=1, mo = 998244353;
    cin >> n;
    vector<ll> d(n), num(100004, 0);
    rep(i, n){
        cin >> d.at(i);
        num[d.at(i)]++;
    }
    if(d.at(0) != 0)ans=0;
    sort(all(d));
    if(num[0] != 1)ans=0;
    for(int i = 1; i < n; i++){
        if(d.at(i) - d.at(i-1) > 1)ans=0;
        ans = ans*num[d.at(i)-1]%mo;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60; 
#define MOD 1000000007

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}


long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

//ここまでライブラリ
//ここから本文

long long int tpimin(vector<int> a) {
	int MIN = 1000000000;
	int number = 0;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
		number = i;
	}
	return number;
}


int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		a.at(x-1)++;
		a.at(y-1)++;
	}
	for (int i = 0; i < n; i++) {
		cout << a.at(i) << endl;
	}

}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

template <class T>
void VecRowShow(vector<T> vec) {
	rep(i, vec.size()) {
		if (i != vec.size() - 1) cout << vec[i] << " ";
		else cout << vec[i] << endl;
	}
}



int main() {
	string s;
	int q;
	cin >> s >> q;
	bool j = 0;
	vector<char> f(0), b(0);
	rep(i, q) {
		int qq;
		cin >> qq;
		if (qq == 1) {
			if (j == 0)j = 1;
			else j = 0;
			continue;
		}
		int ff; char c;
		cin >> ff >> c;
		if ((ff == 1 && j == 0) ||(ff == 2 && j == 1)) {
			f.push_back(c);
		}
		else {
			b.push_back(c);
		}

	}
	if (j == 0) {
		rep(i, f.size()) {
			cout << f[f.size() - 1 - i];
		}
		cout << s;
		rep(i, b.size()) {
			cout << b[i];
		}
		cout << endl;
	}
	else {
		rep(i, b.size()) {
			cout << b[b.size() -1-i];
		}
		reverse(s);
		cout << s;
		rep(i, f.size()) {
			cout << f[i];
		}
		cout << endl;
	}
}



Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
	int r, g, b, s;
	scanf("%d %d %d", &r, &g, &b);
	s = r * 100 + g * 10 + b;
	if (s % 4 == 0)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll inf = 10e17;
const ld eps = 10e-9;



ll solve(void);
ll gcd(ll x, ll y);

int main(void)
{
	while (solve())
	{
	}
	return 0;
}

ll gcd(ll x, ll y)
{
	if (y == 1) { return 1;}
	if (x % y == 0) { return y; }
	return gcd(y, x % y);
}

ll judge(string s)
{
	return (s[2] == s[3] && s[4] == s[5]);
}

ll solve(void)
{
	string s;
	cin >> s;
	
	cout << (judge(s) ? "Yes" : "No") << endl;

	return 0;
}



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

int main() {
  int a,b;
  float c;
  int x;
  cin >> a >> b;
  c=(a+b)/2;
  if((a+b)%2==0){
    x=c;
    cout << x << endl;
  }else{
    x=(a+b)/2+1;
    cout << x << endl;
  }
 }



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int n=0,c=0;
  for(int i=0;i<=S.size();i++){
    if(S[i]=='R'){n++;}
    else{c=(c>=n)?c:n;n=0;}
  }
  cout << (c=(c>=n)?c:n) << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>

typedef long long ll;
const ll MOD = 1e9 + 7;

using namespace std;

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

    ll cost[N+1];
    for(int i = 0; i < N; i++){
        cost[i] = __LONG_LONG_MAX__;
    }

    cost[0] = 0;
    for(ll i = 0; i < N-1; i++){
        cost[i+1] = min(cost[i+1],cost[i]+abs(h[i+1]-h[i]));
        if(i < N-2){
            cost[i+2] = min(cost[i+2],cost[i]+abs(h[i+2]-h[i]));
        }
    }

    cout << cost[N-1] << endl;

    return 0;
}

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

const ll inf = 1e10;

int main() {
	ll n;
	cin >> n;
	vector<vector<ll>> v(n, vector<ll>(3));
	for (ll i = 0; i < n; ++i) {
		for (ll j = 0; j < 3; ++j)cin >> v[i][j];
	}
	vector<vector<ll>> dp(n, vector<ll>(3));
	dp[0] = v[0];
	for (ll i = 1; i < n; ++i) {
		for (ll j = 0; j < 3; ++j) {
			ll tmp = 0;
			for (ll k = 0; k < 3; ++k) {
				if (j == k)continue;
				tmp = max(tmp, dp[i - 1][k] + v[i][j]);
			}
			dp[i][j] = tmp;
		}
	}
	cout << *max_element(dp.back().begin(), dp.back().end()) << endl;
}


Measured memory_bytes: 11136
# -*- coding: utf-8 -*-

import sys

from scipy.sparse.csgraph import floyd_warshall

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def build_grid(H, W, intv, _type, space=True, padding=False):
    # 入力がスペース区切りかどうか
    if space:
        _input = lambda: input().split()
    else:
        _input = lambda: input()
    _list = lambda: list(map(_type, _input()))
    # 余白の有無
    if padding:
        offset = 1
    else:
        offset = 0
    grid = list2d(H+offset*2, W+offset*2, intv)
    for i in range(offset, H+offset):
        row = _list()
        for j in range(offset, W+offset):
            grid[i][j] = row[j-offset]
    return grid

H, W = MAP()
G = build_grid(10, 10, 0, int)
grid = build_grid(H, W, 0, int)

# 全頂点(数字0~9)間の最短距離
wf = floyd_warshall(G)

ans = 0
for i in range(H):
    for j in range(W):
        if grid[i][j] != -1:
            a = grid[i][j]
            # 数字aを1に変える最小コスト
            ans += int(wf[a,1])
print(ans)


Measured memory_bytes: 17380
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double 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 rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; 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;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

}

signed main() {
	ll n, k;

	cin >> n >> k;

	vector<ll> v(n, 0);
	vector<ll> dp(n, INF);

	REP(i, n) {
		cin >> v[i];
	}

	dp[0] = 0;

	FOR(i, 1, n) {
		FOR(j, 1, min(i + 1, k + 1)) {
			dp[i] = min(dp[i], dp[i - j] + abs(v[i] - v[i - j]));
		}
	}

	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
N = int(input())
H = list(map(int, input().split()))

flag = 0
ans = [0]
for n in range(N-1):
    if H[n+1]<=H[n] and flag==0:
        l = n
        flag = 1
    elif H[n+1]>H[n] and flag==1:
        r = n
        flag = 0
        ans.append(r-l)
if flag==1:
    ans.append(N-1-l)
print(max(ans))

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

int main() {

	while (1) {
		int n;
		cin >> n;
		if (n == 0)
			break;

		string word;
		int *length = new int[n];
		int key[5] = { 5,7,5,7,7 };
		for (int i = 0; i < n; i++) {
			cin >> word;
			length[i] = word.size();
		}

		int count = 0;
		int section = 0;
		int index = 0;
		int output = 0;
		int start = 0;
		bool found = false;
		while (index != n) {
			index = output;
			output++;

			while (count <= 5) {
				if (key[count] > section) {
					section += length[index++];
				}
				else if (key[count] == section) {
					section = 0;
					count++;
				}
				else {
					break;
				}

				if (count == 5) {
					cout << output << endl;
					found = true;
				}
			}
			count = 0;
			section = 0;
			if (found)
				break;
		}
	}
	return 0;
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int con(int a)
{
    int res=0;
    while(a%2==0&&a!=0)
    {
        a/=2;
        res++;
    }
    return res;
}

int main()
{
    int N,res,a;
    res=0;
    scanf("%d",&N);
    while(N--)
    {
    scanf("%d",&a);
    res+=con(a);
    }
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k,a=0,b=0;
    cin>>k;
    for(int i=1; i<=k; i++)
    {
        if(i%2==0)
            a++;
        else
            b++;
    }
    cout<<a*b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<pair<long, long>> eng(N);
    for(auto& i : eng)cin >> i.first >> i.second;
    auto d = static_cast<unsigned long>(partition(eng.begin(), eng.end(), [](auto i){return i.first == 0 ? i.second > 0 : i.first > 0;}) - eng.begin());
    for(unsigned long i = 0; i < N; ++i)eng.emplace_back(-eng[i].first, -eng[i].second);
    for(unsigned long i = 0; i < d; ++i)eng.emplace_back(eng[i].first, eng[i].second);
    auto cmp = [](auto i, auto j){return i.first * j.second > i.second * j.first;};
    sort(eng.begin(), eng.begin() + d, cmp);
    sort(eng.begin() + d, eng.begin() + d + N, cmp);
    sort(eng.begin() + d + N, eng.end(), cmp);
    long a{0}, b{0};
    unsigned long ans{0};
    for(unsigned long i = 0; i < 2 * N + d; ++i){
        a += eng[i].first;
        b += eng[i].second;
        ans = max<unsigned long>(ans, a * a + b * b);
    }
    boost::multiprecision::cpp_dec_float_100 t(ans), l(10), k(boost::multiprecision::floor(boost::multiprecision::sqrt(t) * boost::multiprecision::pow(l, 48)) * boost::multiprecision::pow(l, -48));
    cout << k.str(48, std::ios_base::fixed) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int C = 100010;
const int N = 200200;
ll a[N], b[N];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int n;
	scanf("%d", &n);
	a[C]++;
	b[C]++;
	while(n--) {
		int l, r;
		scanf("%d%d", &l, &r);
		l += C;
		r += C;
		a[l]++;
		b[r]++;
	}
	for (int i = N - 2; i >= 0; i--)
		a[i] += a[i + 1];
	for (int i = 1; i < N; i++)
		b[i] += b[i - 1];
	ll ans = 0;
	for (int i = 0; i < N - 1; i++)
		ans += min(b[i], a[i + 1]);
	printf("%lld\n", ans * 2);

	return 0;
}


Measured memory_bytes: 3456
/*
Owner: dxxrk
Problem: Poisonous Cookies 
Date: 22/11/2019
*/
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 8;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

int main(){
//	freopen("ex.in", "r", stdin);
//	freopen("ex.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int a, b, c; cin >> a >> b >> c;
	
	if(a + b >= c) return cout << b + c, 0;
	
	int ans = 0;
	while(c){
		ans++;
		c--;
		if(!a && !b) break;
		if(a) a--;
		else b--, ans++;
	}
	cout << ans;
	return 0;
}



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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());


signed main()
{
    gearup;
    ll n,h,w; cin >> n >> h >> w;
    out( (n - h + 1) * (n - w + 1));
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Floor[] floors = {new Floor(),new Floor(),new Floor(),new Floor()};
        int n = sc.nextInt();
        for(int i = 0;i < n;++i) floors[sc.nextInt() - 1].add(sc.nextInt() - 1,sc.nextInt() - 1,sc.nextInt());
        System.out.print(floors[0]);
        for(int i = 1;i < 4;++i){
            System.out.println("####################");
            System.out.print(floors[i]);
        }
    }

}

class Floor{

    private int[][] room = new int[10][3];

    public void add(int f,int r,int a){
        room[r][f] += a;
    }

    @Override
    public String toString(){
        StringBuilder sb = new StringBuilder();
        for(int i = 0;i < 3;++i){
            for(int j = 0;j < 10;++j) sb.append(' ').append(room[j][i]);
            sb.append("\n");
        }
        return sb.toString();
    }

}

Measured memory_bytes: 29736
N = int(input())
A = list(map(int, input().split()))
L, R = [0 for _ in range(N)], [0 for _ in range(N)]
L[0] = A[0]
R[N-1] = A[N-1]
for i in range(N-1):
  L[i+1] = L[i] + A[i+1]
  R[N-2-i] = R[N-1-i] + A[N-2-i]
m = int(1e15)
for i in range(1, N):
  a = abs(L[i-1] - R[i])
  if a < m:
    m = a
print(m)


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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT_ON(bit, i) (bit & (1LL << i))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<typename T> using VVVV = std::vector<std::vector<std::vector<std::vector<T>>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;


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

    while (true) {
        string S;
        cin >> S;
        int n = (int)S.size();
        if (S == "0") {
            break;
        }

        VV<LL> dp(n + 10, V<LL>(11, 0));
        FOR(i, 0, n) {
            int d = S[i] - '0';

            // dが先頭
            if (d != 0) {
                dp[i + 1][d % 11] += 1;
            }
            // dが末尾
            FOR(j, 0, 11) {
                dp[i + 1][(j * 10 + d) % 11] += dp[i][j];
            }
        }

        int ans = 0;
        FOR(i, 0, dp.size()) {
            ans += dp[i][0];
        }
        print(ans);

    }
    return 0;
}


Measured memory_bytes: 12344
def factorize(n, d):
  # if n == 0 or n == 1:
    # return []
    arr = []
    tmp = n
    while True:
      i = d[tmp]
      if i == 1:
        break
      #cnt=0
      while tmp%i==0:
        #cnt+=1
        tmp //= i
      arr.append(i)
    if tmp!=1:
      arr.append(tmp)
    if arr==[]:
      arr.append(n)
    return arr

def minimum_prime(n):
  # 試し割りをする際の最小の素数
  # エラトステネスの篩と同様の実装
    d = list(range(n+1))
    d[0] = 1
    for i in range(2, int(n**0.5) + 1):
        if d[i] != i:
          continue
        for j in range(i * 2, n + 1, i):
          if d[j] == j:
            d[j] = i
    return d  

def main():
  n = int(input())
  arr = list(map(int, input().split()))
  max_arr = max(arr)
  d = minimum_prime(max_arr)
  dp = [0]*(max_arr+1)
  
  
  searched = []
  for a in arr:
    if a != 1:
      primes = factorize(a, d)
      for p in primes:
        dp[p] += 1
  
  max_dp = max(dp)
  if max_dp < 2:
    print('pairwise coprime')
  elif max_dp == n:
    print('not coprime')
  else:
    print('setwise coprime')
    

main()

Measured memory_bytes: 189560
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<iomanip>

using namespace std;
int main()
{
	int q,h,s,d,n;
	long long ans;
	scanf("%d%d%d%d%d",&q,&h,&s,&d,&n);
	if(h > q*2) h = q*2;
	if(s > h*2) s = h*2;
	if(d > s*2) d = s*2;
	ans = 1LL*(n/2)*d + (n&1)*s;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
M=998244353
N,*A=open(0)
d=[0]*90001
d[0]=1
e=[0]*90001
e[0]=1
z=1
s=0
for a in A:
	i=s;a=int(a);s+=a;z*=3
	while i>=0:d[i+a]+=d[i]%M;d[i]*=2;e[i+a]+=e[i]%M;i-=1
i=s+1>>1
while i<=s:z=(z-d[i]*3)%M;i+=1
print([(z+e[s//2]*3)%M,z][s%2])

Measured memory_bytes: 141900
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	N := oneInt()

	x := int(math.Sqrt(float64(N)))
	mini := N + 1
	for x > 0 {
		if N%x == 0 {
			temp := N/x + x - 2
			mini = min(mini, temp)
		}
		x--
	}
	fmt.Print(mini)
}

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

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

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}


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

int main(){
  	int n, i, total = 0;
  	int value[20], resale[20] ;
  	
  	cin >> n;
  
  for(int i = 0; i < n; i++ )
      	cin >> value[ i ];
  	for(int i = 0; i < n; i++ )
      	cin >> resale[ i ];
  
  	for(int i = 0; i < n; i++ )
      	if(value[ i ] > resale[ i ] )
         	total += value[ i ] - resale[ i ];
  	cout << total;
  return 0;
}
  
  	
  

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

int main()
{
    int n,k,ans = 0;
    cin >> n >> k;
    vector<int> h(n);
    for( int i = 0; i < n; i++ )
    {
        cin >> h[i];
        if( h[i] >= k ){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 640
using System;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{

        //int[] a = new int[10];
        List<int> a = new List<int>();
        List<int> b = new List<int>();
        List<int> c = new List<int>();

		//long[] a = new long[n];


		//string[] s = Console.ReadLine().Split(' ');

		int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n;i++)
		{
			string input = Console.ReadLine();
			if (string.IsNullOrEmpty(input)) break;

			int[] nums = Array.ConvertAll(input.Split(' '), int.Parse);
            Array.Sort(nums);
			a.Add(nums[0]);
			b.Add(nums[1]);
            c.Add(nums[2]);
		}


		for (int i = 0; i < a.Count;i++)
        {
            if(c[i]*c[i]==a[i]*a[i]+b[i]*b[i])
            {
              Console.WriteLine("YES");  
            }
            else
            {
                Console.WriteLine("NO");
			}

        }

		//Console.WriteLine("");


	}
}

Measured memory_bytes: 9240
A, B, C, D = gets.split.map(&:to_i)
MAX_INT = 10**9
x_list = [A, B]
x_list << A+1 if A <  MAX_INT && A < B
x_list << B-1 if B > -MAX_INT && A < B
y_list = [C, D]
y_list << C+1 if C <  MAX_INT && C < D
y_list << D-1 if D > -MAX_INT && C < D
max_val = -MAX_INT**2
x_list.each do |x|
    y_list.each do |y|
        max_val = [x*y, max_val].max
    end
end
puts max_val

Measured memory_bytes: 14368
module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

------------------------------------------

main :: IO ()
main = do
  [n,_] <- readInts
  cloud <- replicateM n getLine
  mapM_ solve cloud

solve :: String -> IO ()
solve line = foldM_ f (-1, 0) line >> putStrLn ""
  where f (prv, idx) c = do
          let prv' = if c == 'c' then idx else prv
          when (idx > 0) $ putStr " "
          putStr $ show (if prv' < 0 then -1 else idx - prv')
          return (prv', idx+1)

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"

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

const int MAX_N = 100;

int max(int n, int a[]){
  int j, k = 0;

  for(j = 0; j < n; j++){
    if(a[j] > k){
      k = a[j];
    }
  }

  return k;
}

int min(int n, int b[]){
  int j, k = 100000000;

  for(j = 0; j < n; j++){
	if (b[j] < k) {
		k = b[j];
	}
  }

  return k;
}



int main(){
  int n, s[MAX_N], max_num, min_num, sum = 0, ave;

  while(scanf("%d", &n), n != 0){
    for(int i = 0;i < n; i++){
      cin >> s[i]; 
    }

    max_num = max(n, s);
    min_num = min(n, s);

    sum = 0;
    for(int l = 0; l < n; l++){
      sum = sum + s[l];
    }

    sum = sum - max_num - min_num;
    ave = sum / (n - 2);

    cout << ave << endl;
  }
    return 0;
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
#define DEBUG
#define REP(i,n) for(ll i=0;i<n;i++)
typedef long long ll;
ll n=0,id,sum,tmp; //標準入力、指数部仮入れ、合計、元値格納用
string str;
void SUM();
int main(){
  while(cin>>n && n!=0){
    cin>>str;
    SUM();
  }
  return 0;

}
void SUM(){
  ll coe=0; //係数
  id=sum=tmp=0;
  str='1'+str;
  REP(i,str.size()){
    if(str[str.size()-i-1]=='1') tmp+=(1LL << i);
  }
  sum=tmp;
  while(1){
    //何回足せるか
    coe=((1LL<<53)-sum)/tmp;
    if(((1LL<<53)-sum)%tmp==0) coe--;
    if(coe>=n){
      sum+=tmp*n;
      break;
    }else{
      sum+=tmp*(coe+1);
      sum=sum>>1;
      tmp=tmp>>1;
      n=n-(coe+1);
      id++;
    }
    if(tmp==0 || n==0) break;
  }
  cout<<bitset<12>(id)<<bitset<52>(sum)<<endl;
}



Measured memory_bytes: 3196
#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()
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<bool>color(9);
    rep(i,9)color[i]=false;
    int cnt = 0;
    rep(i,n){
        int r;
        cin >> r;
        if(r>=3200){
            color[8]=true;
            cnt++;
        }else{
        color[r/400]=true;
        
        }
    }
    //rep(i,9)cout << color[i] << endl;
    int ans = 0;
    for(int i = 0;i < 8;i++){
        if(color[i])ans++;
    }
    if(ans == 0)cout << 1 << " " << cnt << endl;
    else cout << ans << " " << ans+cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

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


		int w = stdIn.nextInt();
		int h = stdIn.nextInt();
		int x = stdIn.nextInt();
		int y = stdIn.nextInt();


		System.out.print(w*(long)h/2.0+" ");
		if(x*2 == w && y * 2 == h) {
			System.out.println("1");
		}else {
			System.out.println("0");
		}



	}

}


Measured memory_bytes: 23764
n=input()

if len(n) == 1:
    a = int(n[0])
elif len(n) == 2:
    a =  int(n[1])
elif len(n) == 3:
    a = int(n[2])

if a == 3:
    print('bon')
elif a == 0 or a == 1 or a == 6 or a == 8:
    print('pon')
else:
    print('hon')

Measured memory_bytes: 9132
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
struct _IO { _IO() { ios::sync_with_stdio(0); cin.tie(0); } }_io;
typedef long long ll; typedef long double db;

ll exgcd(ll a, ll b, ll& x, ll& y)
{
	if (!b)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll d = exgcd(b, a % b, x, y);
	ll t = x;
	x = y;
	y = t - (a / b) * y;
	return d;
}
ll getInv(ll a, ll mod)
{
	ll x, y;
	return exgcd(a, mod, x, y) == 1 ? (x % mod + mod) % mod : -1;
}

const ll mod = 1e9 + 7;
ll dp[3005];

int main()
{
	ll s;
	cin >> s;
	dp[0] = dp[1] = dp[2] = 0;
	dp[3] = dp[4] = dp[5] = 1;
	for (ll i = 6; i <= s; ++i)
	{
		for (ll j = 3; j <= i - 3; ++j)
		{
			dp[i] = (dp[i] + dp[j]) % mod;
		}
		dp[i] = (dp[i] + 1) % mod;
	}
	cout << dp[s] << endl;
	return 0;
}

Measured memory_bytes: 3624
n,m=map(int,input().split())
ls=list(map(int,input().split()))
ls.sort()
a=[]
for i in range(1,m):
  a.append(ls[i]-ls[i-1])
a.sort()
if(n>=m):
  print(0)
else:
  print(sum(a[:m-n]))

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

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    const int INF = 1e9;
    int n;
    cin>>n;
    int h[n];
    for (int i=0;i<n;++i) cin>>h[i];

    int dp[n+1];
    dp[0] = dp[1] = 0;
    for (int i=2;i<=n;++i){
        dp[i] = dp[i-1] + abs(h[i-1]-h[i-2]);
        if (i>2) dp[i] = min(dp[i-2] + abs(h[i-1]-h[i-3]), dp[i]);
    }
    cout<<dp[n]<<endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
typedef pair<ll,ll> P;

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

  int N; cin>>N;
  vector<P> arr(N);
  for(int i=0; i<N; i++) {
    ll a,b; cin>>a>>b;
    arr[i].first = a, arr[i].second = b;
  }
  sort(arr.begin(), arr.end(), [](P x, P y) { return x.first + x.second > y.first + y.second; });
  ll a_point = 0, b_point = 0;
  for(int i=0; i<N; i++) {
    if(i % 2 == 0) {
      a_point += arr[i].first;
    } else {
      b_point += arr[i].second;
    }
  }
  cout << a_point - b_point << endl;
}


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

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

#define maxs(x,y) (x=std::max(x,y))
#define mins(x,y) (x=std::min(x,y))

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll tmp = c - a - b;
  if (tmp < 0) {
    cout << "No\n";
    return 0;
  } else {
    ull k = ((ull)tmp)*((ull)tmp);
    ull k2 = 4*a*b;
    if (k2 < k) {
      cout << "Yes\n";
      return 0;
    } else {
      cout << "No\n";
      return 0;
    }
  }
}


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

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A <= C && C <= B) cout << "Yes";
	else cout << "No";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

書いてある通りに判定してください

*/

Measured memory_bytes: 256
i = input()
a,b,c = map(int, i.split())
if b<a:
    temp = a
    a = b
    b = temp
if c<b:
    temp = b
    b = c
    c = temp
if b<a:
    temp = a
    a = b
    b = temp

print('{} {} {}'.format(a,b,c))


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=-mod;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
//ショートカット
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<n;i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//nCr
long long Comb (long long n, long long r);
//nCr (mod)
long long modC(long long n, long long r) {
    vector<long long> f(n+1),inv(n+1),invf(n+1);
    f[0]=f[1]=1;
    invf[0]=invf[1]=1;
    inv[1]=1;
    for (long long i=2;i<n+1;i++) {
        f[i]=(i*f[i-1])%mod;
        inv[i]=mod-((mod/i)*inv[mod%i])%mod;
        invf[i]=(inv[i]*invf[i-1])%mod;
    }
    long long cmb=f[n]*(invf[r]*invf[n-r]%mod)%mod;
    if (n>=r) return cmb;
    else return 0;
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(a);lin(b);
  if(a>=13) cout<<b;
  else if(a<=5) cout<<0;
  else cout<<b/2;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;
	template<class T>using pair = std::pair<T, T>;

	struct max_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	constexpr max_t max;
	constexpr min_t min;

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min();

	template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;
	
	template<class T>constexpr T pow(T val, std::uint64_t p)
	{
		auto ret = T(1);
		auto s = 1ULL;
		for (auto i = 0; i < 63; ++i, s <<= 1)
		{
			if (p & s)
			{
				ret *= val;
			}
			val *= val;
		}
		return ret;
	}
	template<class Range>void sort(Range& rng)
	{
		std::sort(std::begin(rng), std::end(rng));
	}
	template<class Range, class Pred>void sort(Range& rng, Pred pred)
	{
		std::sort(std::begin(rng), std::end(rng), pred);
	}
}

void Main()
{
	std::string S, T;
	std::cin >> S >> T;
	std::size_t min = T.size();
	for (std::size_t s = 0; s + T.size() <= S.size(); ++s)
	{
		std::size_t count = 0;
		for (auto i : boost::irange(T.size()))
		{
			count += S[s + i] != T[i];
		}
		min = std::min(min, count);
	}
	std::cout << min << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

constexpr int MAXN = 100005;
int n;
int a[MAXN];
int b[MAXN];

constexpr int DEBUG = 0;

ll brute() {
    vector<ll> init(n);
    for (int i = 0; i < n; ++i) {
        init[i] = a[i];
    }

    set<vector<ll>> seen;
    queue<vector<ll>> q;
    q.push(init);
    seen.insert(init);

    ll ans = -1e18;

    while (!q.empty()) {
        vector<ll> cur = q.front();
        q.pop();

        /*
        for (ll x : cur) {
            cout << x << ' ';
        }
        cout << '\n';
        */

        if (cur.size() == 1) {
            ans = max(ans, cur[0]);
            continue;
        }

        int m = cur.size();
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < m; ++j) {
                if (i == j) continue;

                vector<ll> nxt;
                for (int k = 0; k < m; ++k) {
                    if (i == k or j == k) continue;
                    nxt.push_back(cur[k]);
                }

                nxt.push_back(cur[i] - cur[j]);
                sort(all(nxt));
                if (!seen.count(nxt)) {
                    seen.insert(nxt);
                    q.push(nxt);
                }
            }
        }
    }

    return ans;
}

void read() {
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a, a + n);
}

void gen() {
    srand(time(0));

    n = 3 + (rand() % 5);
    for (int i = 0; i < n; ++i) {
        int sgn = (rand() & 1) ? -1 : 1;
        a[i] = (rand() % 10) * sgn;
    }
    sort(a, a + n);
}

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

    read();
    // gen();

    ll exp = 0;
    if (DEBUG)
        exp = brute();

    for (int i = 0; i < n; ++i)
        b[i] = a[i];

    vector<pair<ll, ll>> moves;
    // get down to 1 negative number
    int l = 0;
    while (l + 1 < n - 1 and b[l + 1] <= 0) {
        moves.emplace_back(b[n - 1], b[l]);
        b[n - 1] -= b[l];
        ++l;
    }

    // l points to the <= 0, everything after is pos
    for (int i = l + 1; i < n - 1; ++i) {
        moves.emplace_back(b[l], b[i]);
        b[l] -= b[i];
    }

    moves.emplace_back(b[n - 1], b[l]);
    ll res = b[n - 1] - b[l];

    if (DEBUG) {
        cout << n << '\n';
        for (int i = 0; i < n; ++i) {
            cout << a[i] << ' ';
        }
        cout << '\n';

        cout << res << ' ' << exp << '\n';
        assert(res == exp);
    }

    cout << res << '\n';
    for (auto& p : moves) {
        cout << p.first << ' ' << p.second << '\n';
    }

    return 0;
}


Measured memory_bytes: 4336
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
char check[55];
int main() {
    ll m, f, r;
    cin >> m >> f >> r;
    int i = 0;
    while (m + f + r != -3) {
        if (m==-1||f==-1) {
            check[i] = 'F';
        }
        else if(m+f>=80){
            check[i] = 'A';
        }
        else if (m + f < 80 && m + f >= 65) {
            check[i] = 'B';
        }
        else if (m + f < 65 && m + f >= 50||m+f>=30&&r>=50) {
            check[i] = 'C';
        }
        else if (m + f >= 30 && m + f < 50 || m + f >= 30 && r < 50) {
            check[i] = 'D';
        }
        else {
            check[i] = 'F';
        }
        cin >> m >> f >> r;
        i++;
    }
    for (int j = 0; j < i; j++) {
        cout << check[j] << endl;
    }
    return 0;
}



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

const ll MX = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool ng = false;
  rep(i,n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (ng || (MX)/ans + 1 < a || ans*a > MX) {
      ng = true;
    }
    ans *= a;
  }
  if (ng) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


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

int random(int seed);

int main(void){
  int n;
  cin>>n;
  int x;
  for(int c=0;c<n;c++){
    cout<<"Case "<<c+1<<":"<<endl;
    cin>>x;
    for(int i=0;i<10;i++){
      x=random(x);
      cout<<x<<endl;
    }
  }
  return 0;
}


int random(int seed){
  int retval;
  retval=(seed*seed)/100;
  retval=retval%10000;
  return retval;
}



Measured memory_bytes: 3004
h,w = gets.split.map(&:to_i)
arr = []
h.times do
  arr << gets.chomp.split("")
end

arr.map do |i|
  i.push('.')
  i.unshift('.')
end

arr.push(Array.new(w+2,'.'))
arr.unshift(Array.new(w+2,'.'))

(1..h).each do |i|
  (1..w).each do |j|
    cnt = 0
      cnt+=1 if arr[i-1][j-1] == '#'
      cnt+=1 if arr[i-1][j] == '#'
      cnt+=1 if arr[i-1][j+1] == '#'
      cnt+=1 if arr[i][j-1] == '#'
      cnt+=1 if arr[i][j+1] == '#'
      cnt+=1 if arr[i+1][j-1] == '#'
      cnt+=1 if arr[i+1][j] == '#'
      cnt+=1 if arr[i+1][j+1] == '#'
      print arr[i][j] == '#' ? "#" : cnt
  end
  print "\n"
end


Measured memory_bytes: 2172
/*************************************************************************
    > File Name: A.cpp
    > Author: HandsomeHow
    > Mail: handsomehowyxh@gmail.com 
    > Created Time: 2017/4/29 19:57:22
 ************************************************************************/

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

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int mod=1000000007;
const double pi=acos(-1.0);
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
// (づ°ω°)づe★------------------------------------------------

int main(){
#ifdef HandsomeHow
	//freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
#endif
	string a,b,c;
	cin>>a>>b>>c;
	int sz1 = a.length();
	int sz2 = b.length();
	int szc = c.length();
	if(a[sz1-1] == b[0] && b[sz2-1]==c[0])puts("YES");
	else puts("NO");
	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, b, c, d, e;
		
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		d = sc.nextInt();
		e = sc.nextInt();
		while (a < b || b < c || c < d || d < e) {
			int swap;
			if (a < b) {
				swap = a;
				a = b;
				b = swap;
			}
			if (b < c) {
				swap = b;
				b = c;
				c =swap;
			}
			if (c < d) {
				swap = c;
				c = d;
				d = swap;
			}
			if (d < e) {
				swap = d;
				d = e;
				e = swap;
			}
		}
		System.out.println(a + " " + b + " " + c + " " + d + " " + e);
	}
}

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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++) cin >> p.at(i);
  int prep, nowp, nextp;
  int count = 0;
  for(int i = 0; i < n - 2; i++){
    prep = p.at(i);
    nowp = p.at(i + 1);
    nextp = p.at(i + 2);
    if(prep < nowp && nowp < nextp) count++;
    else if(prep > nowp && nowp > nextp) count++;
    else continue;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
S = input()


def count(s1, s2):
    res = 0
    for t1, t2 in zip(s1, s2):
        if t1 != t2:
            res += 1

    return res


res = 0
lenS = len(S)
if lenS > 1:
    if lenS % 2 == 0:
        s1, s2 = S[lenS//2:], S[:lenS//2][::-1]
        res = count(s1, s2)
    else:
        s1, s2 = S[lenS//2:], S[:lenS//2+1][::-1]
        res = count(s1, s2)

print(res)


Measured memory_bytes: 3060
from collections import defaultdict

N = int(input())
S_dic = defaultdict(int)

for i in range(N):
  S = input()
  S_dic[S] += 1

m = max(S_dic.values())
max_S = [i[0] for i in S_dic.items() if i[1] == m ]
max_S.sort()
print("\n".join(max_S))

Measured memory_bytes: 34384
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main(){
	int n;
	cin>>n;
	cin.ignore();

	for(int i=0;i<n;i++){
		string str, s = "Hoshina";
		getline(cin, str);

		while(str.find("Hoshino") != string::npos)
			str.replace(str.find("Hoshino"), s.size(), s);

		cout<<str<<endl;
		
	}

	return 0;
}

Measured memory_bytes: 1220
class UnionFind:
    def __init__(self, n):
        self.par = [-1]*(n+1)  # 頂点番号とindexをそろえるためにn+1。idx0は使わない
        self.rank = [0]*(n+1)

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])  # 再帰で根までたどる.その過程で根とつなぎかえる
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return
        else:
            if self.rank[x] < self.rank[y]:
                self.par[y] += self.par[x]
                self.par[x] = y
            else:
                self.par[x] += self.par[y]
                self.par[y] = x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def same_check(self, x, y):
        return self.find(x) == self.find(y)  # 根同じならTrue違うならFalseを返す

    def size(self, x):
        return -self.par[self.find(x)]


n, m = map(int, input().split())
p = list(map(int, input().split()))
p = [0] + p
uf = UnionFind(n)
for _ in range(m):
    x, y = map(int, input().split())
    uf.union(x, y)

ans = 0
for i in range(1, n+1):
    if uf.same_check(i, p[i]):
        ans += 1
print(ans)



Measured memory_bytes: 87168
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  cout << (n - 2) * 180 << endl;
  return 0;
}


Measured memory_bytes: 256