akhauriyash/Code-Regression huggingface dataset:
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

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

    ull N;
    cin >> N;
    cout << N*(N-1)/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <string>
#define INF 99999999
typedef long long ll;
using namespace std;
int main()
{
	char s[15];
	cin>>s;
	int len = strlen(s);
	int flag=1;
	int sum=0;
	if(s[0]!='A')
	flag=0;
	for(int i=0;i<len;i++)
	{
		if(s[i]>='a'&&s[i]<='z'||s[i]=='A'||s[i]=='C')
		{
			if(s[i]=='C')
			{
				if(i+1>=3&&i+1<=len-1)
				sum++;
			}
		}
		else
		flag=0;
	}
	if(sum!=1)
	flag=0;
	if(flag)
	cout<<"AC"<<endl;
	else
	cout<<"WA"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
using namespace std;
multiset<string> s;
int main()
{
	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);
	for(int i=1;i<=A;i++) s.insert("a");
	for(int i=1;i<=B;i++) s.insert("b");
	for(int i=1;i<=C;i++) s.insert("c");
	for(int i=1;i<=A+B+C-1;i++)
	{
		string s1,s2;
		s1=*s.begin(); s.erase(s.begin());
		s2=*(--s.end()); s.erase(--s.end());
		s.insert(s1+s2);
	}
	cout<<*s.begin();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#define rep(i,o,u) for(int i = o;i < u; i++)
using namespace std;
int gcd (int a,int b){
	if(a < b) swap(a,b);
	int temp;
	while(a%b != 0){
		temp = b;
		b = a%b;
		a = temp;
	}
	return b;
}
int main(){
	int a,b;
	cin >> a >> b;
	cout << gcd(a,b) << endl;
	return 0;
}

Measured memory_bytes: 3104
N=int(input())
V=[]
V=list(map(int,input().split(" ",N)))
C=[]
C=list(map(int,input().split(" ",N)))
max=0
for i in range(len(V)):
    if V[i]-C[i]>0:
        max+=V[i]-C[i]

if max>0:
    print(max)
else:
    print(0)

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	double n,tmp;
	cin >> n;
	tmp = ceil(n / 1.08);
	if (floor(tmp * 1.08) != n) { cout << ":(" << endl; }
	else { cout << tmp << endl; }
	return 0;
}


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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define eb(x) emplace_back(x)
#define mp(a,b) make_pair(a,b)
#define sz(a) int((a).size())
#define mod 1000000007
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }


void seethis(vector<ll>vect)
{
    for(ll x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
//LCM
int lcm(int a, int b) {  return a * (b / __gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

int main()
{
	FASTIO;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	

	ll n,k;
	 cin>>n>>k;

	int ans=0;

	 f(i,0,n)
	 {
	 	ll x;
	 	 cin>>x;

	 	 if(x>=k)
	 	 	ans++;
	 }

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

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 200005;

ll dp[2005][2005];

void solve(){
	ll n;
	cin >> n;
	vector<ii> v;
	for(int i = 1; i <= n; i++){
		ll x; cin >> x;
		v.pb({x, i});
	}
	sort(v.rbegin(), v.rend());
	for(int i = 1; i <= n; i++){
		ll val = v[i-1].fst, pos = v[i-1].snd;
		for(int j = 0; j < i; j++){
			ll l = j, r = i - 1 - j; // elements in the left and right corner
			dp[l+1][r] = max(dp[l+1][r], dp[l][r] + val * abs(l+1ll-pos));
			dp[l][r+1] = max(dp[l][r+1], dp[l][r] + val * abs(n-r-pos));
			l = i - 1 - j, r = j;
			dp[l+1][r] = max(dp[l+1][r], dp[l][r] + val * abs(l+1ll-pos));
			dp[l][r+1] = max(dp[l][r+1], dp[l][r] + val * abs(n-r-pos));
		}
	}
	ll ans = 0;
	for(int i = 0; i <= n; i++){
		ans = max(ans, dp[i][n-i]);
	}
	cout << ans << endl;
}

int main(){
	fastio;
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 26276
#include<iostream>
using namespace std;
int main(void){
	int n;
	cin>>n;
	int fib[n];
	fib[0]=fib[1]=1;
	for(int i=2;i<=n;i++)fib[i]=fib[i-1]+fib[i-2];
	cout<<fib[n]<<endl;;
	return 0;
}



Measured memory_bytes: 3124
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

void Calculate_Depth(vector<vector<int>>&edge, vector<int>&depth, int stnode) {
	depth[stnode] = 0;
	queue<int>Q;
	Q.push(stnode);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (auto i : edge[cn]) {
			if (depth[i] > depth[cn] + 1) {
				depth[i] = depth[cn] + 1;
				Q.push(i);
			}
		}
	}
	return;
}

void Search(vector<int>&dis, vector<vector<int>>&edge, vector<int>&box ,vector<int>&v,vector<int>&ans, int node = 0) {
	for (auto i : edge[node]) {
		if (dis[i] < dis[node])continue;
		auto it = lower_bound(box.begin(), box.end(), v[i]) - box.begin();
		int bef = box[it];
		box[it] = v[i];
		ans[i] = lower_bound(box.begin(), box.end(), MOD) - box.begin() - 1;
		Search(dis, edge, box, v, ans, i);
		box[it] = bef;
	}
}

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

	cin >> N;
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	vector<vector<int>>edge(N);
	for (int i = 1; i < N; i++) {
		cin >> L >> R;
		L--, R--;
		edge[L].push_back(R);
		edge[R].push_back(L);
	}
	vector<int>dis(N, MOD);
	Calculate_Depth(edge, dis, 0);
	vector<int>ans(N, 1);
	vector<int>box(N + 2, MOD);
	box[0] = 0;
	box[1] = v[0];
	Search(dis, edge, box, v, ans);
	for (auto i : ans)cout << i << endl;
}

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

int main(){
    string s,t;
    cin>>s;
    cin>>t;
    for(int i=0; i<t.length(); i++){
        if(s==t){
            cout<<"Yes\n";
            return 0;
        }
        s = s.substr(t.length()-1) + s.substr(0,t.length()-1);
    }
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{

    public static List<Integer> P;
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        long N = scanner.nextLong();
        long A = scanner.nextLong();
        long B = scanner.nextLong();
        long C = scanner.nextLong();
        long D = scanner.nextLong();
        long E = scanner.nextLong();

        List<Long> throughTime = new ArrayList<>();
        throughTime.add(N/A + (N%A==0 ? 0 : 1));
        throughTime.add(N/B + (N%B==0 ? 0 : 1));
        throughTime.add(N/C + (N%C==0 ? 0 : 1));
        throughTime.add(N/D + (N%D==0 ? 0 : 1));
        throughTime.add(N/E + (N%E==0 ? 0 : 1));
        Long maxTT = Collections.max(throughTime);

        System.out.println(maxTT + 4);
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define INF 100000000
typedef long long ll;
 
int main(){
    string a,b;
    cin>>a>>b;
    if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if (a==1) a=14;
  if (b==1) b=14;
  if (a>b) cout<<"Alice";
  else if (b>a) cout<<"Bob";
  else cout<<"Draw";
  system("pause");
  return 0;
}

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int N=26;
	int D;
	cin >>D;
	vector<int> c(N+1, 0);
	Rep1(i, N)
		cin >>c.at(i);
	vector<vector<int>> s(D+1, vector<int> (N+1, 0));
	Rep1(i, D)
		Rep1(j, N)
			cin >>s.at(i).at(j);
	vector<int> t(D+1);
	Rep1(i, D)
		//	cin >>t.at(i);
		t.at(i)=i%26+1;
	//
	vector<vector<int>> LAST(D+1, vector<int> (N+1, 0));
	int S=0;
	vector<vector<int>> SS(D+1, vector<int> (N+1, 0));
	Rep1(i, D) {
		Rep1(j, N) {
			if (j==t.at(i)) {
				LAST.at(i).at(j)=0;
				SS.at(i).at(j)=SS.at(i-1).at(j)+s.at(i).at(j);
				S +=s.at(i).at(j);
			} else {
				LAST.at(i).at(j) =LAST.at(i-1).at(j)+c.at(j);
				SS.at(i).at(j)=SS.at(i-1).at(j)-LAST.at(i).at(j);
			}
			S -=LAST.at(i).at(j);
		}
		//cout <<S <<endl;
	}
	//
	int SSS=0;
	int M=500000;
	bool OK=false;
	int q;
	Rep1(i, M) {
		int SSSS=S;
		int d=rand()%365+1;
		if (!OK)
			q=rand()%26+1;
		//int d, q;
		//cin >>d >>q;
		int q0=t.at(d);
		if (q==q0)
			continue;
		S -=SS.at(D).at(q0)+SS.at(D).at(q);
		t.at(d)=q;
		for (auto j=d; j<=D; j++) {
			if (q0==t.at(j)) {
				LAST.at(j).at(q0)=0;
				SSS=SS.at(j-1).at(q0)+s.at(j).at(q0);
			} else {
				LAST.at(j).at(q0)=LAST.at(j-1).at(q0)+c.at(q0);
				SSS=SS.at(j-1).at(q0)-LAST.at(j).at(q0);
			}
			if (SSS==SS.at(j).at(q0))
				break;
			else
				SS.at(j).at(q0)=SSS;
		}
		for (auto j=d; j<=D; j++) {
			if (q==t.at(j)) {
				LAST.at(j).at(q)=0;
				SSS=SS.at(j-1).at(q)+s.at(j).at(q);
			} else {
				LAST.at(j).at(q)=LAST.at(j-1).at(q)+c.at(q);
				SSS=SS.at(j-1).at(q)-LAST.at(j).at(q);
			}
			if (SSS==SS.at(j).at(q))
				break;
			else
				SS.at(j).at(q)=SSS;
		}
		S +=SS.at(D).at(q0)+SS.at(D).at(q);
		OK=true;
		if (S<SSSS) {
			OK=false;
			t.at(d)=q0;
			for (auto j=d; j<=D; j++) {
				if (q0==t.at(j)) {
					LAST.at(j).at(q0)=0;
					SSS=SS.at(j-1).at(q0)+s.at(j).at(q0);
				} else {
					LAST.at(j).at(q0)=LAST.at(j-1).at(q0)+c.at(q0);
					SSS=SS.at(j-1).at(q0)-LAST.at(j).at(q0);
				}
				if (SSS==SS.at(j).at(q0))
					break;
				else
					SS.at(j).at(q0)=SSS;
			}
			for (auto j=d; j<=D; j++) {
				if (q==t.at(j)) {
					LAST.at(j).at(q)=0;
					SSS=SS.at(j-1).at(q)+s.at(j).at(q);
				} else {
					LAST.at(j).at(q)=LAST.at(j-1).at(q)+c.at(q);
					SSS=SS.at(j-1).at(q)-LAST.at(j).at(q);
				}
				if (SSS==SS.at(j).at(q))
					break;
				else
					SS.at(j).at(q)=SSS;
			}
			S=SSSS;
		}
		//cout <<i <<":" <<S <<endl;////////////////////////////
	}
	Rep1(i, D)
		cout <<t.at(i) <<endl;
	//cout <<S <<endl;//////////////////////
	return 0;
}



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

#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ld long double

#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define Fit(i,v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define Fitd(i,v) for(__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))

using namespace std;

#include <bits/stdc++.h>

using namespace std;

const int nm = 90;
const int mm = 2 * nm * nm;
const int inf = 1e9;

int m, n, a[nm][nm], b[nm][nm];
queue<pair<pair<int, int>, int>> q;
bool f[nm][nm][2 * mm];

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    scanf("%d%d", &m, &n);
    for (int i = 1; i <= m; ++i) {
    	for (int j = 1; j <= n; ++j) {
    		scanf("%d", &a[i][j]);
    	}
    }
    for (int i = 1; i <= m; ++i) {
    	for (int j = 1; j <= n; ++j) {
    		scanf("%d", &b[i][j]);
    		a[i][j] -= b[i][j];
    	}
    }
    q.push(mp(mp(1, 1), a[1][1]));
    q.push(mp(mp(1, 1), -a[1][1]));
    f[1][1][a[1][1] + mm] = 1;
    f[1][1][-a[1][1] + mm] = 1;
    while (!q.empty()) {
    	int i = q.front().fi.fi, j = q.front().fi.se, d = q.front().se;
    	q.pop();
    	if (i + 1 <= m) {
    		if (!f[i + 1][j][d + a[i + 1][j] + mm]) {
    			f[i + 1][j][d + a[i + 1][j] + mm] = 1;
    			q.push(mp(mp(i + 1, j), d + a[i + 1][j]));
    		}
    		if (!f[i + 1][j][d - a[i + 1][j] + mm]) {
    			f[i + 1][j][d - a[i + 1][j] + mm] = 1;
    			q.push(mp(mp(i + 1, j), d - a[i + 1][j]));
    		}
    	}
    	if (j + 1 <= n) {
    		if (!f[i][j + 1][d + a[i][j + 1] + mm]) {
    			f[i][j + 1][d + a[i][j + 1] + mm] = 1;
    			q.push(mp(mp(i, j + 1), d + a[i][j + 1]));
    		}
    		if (!f[i][j + 1][d - a[i][j + 1] + mm]) {
    			f[i][j + 1][d - a[i][j + 1] + mm] = 1;
    			q.push(mp(mp(i, j + 1), d - a[i][j + 1]));
    		}
    	}
    }

    for (int i = 0; ; ++i) {
    	if (f[m][n][i + mm] || f[m][n][-i + mm]) {
    		printf("%d\n", i);
    		return 0;
    	}
    }
#ifdef LOCAL
    cout << (double) clock() / CLOCKS_PER_SEC << "\n";
#endif
}


Measured memory_bytes: 236548
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
typedef long long int ll;
typedef long double ld;
const ll INF = 1LL << 60;
const int inf = (1 << 30);
const int MOD = 1000000007;
int dx[4] = { 0,-1,0,1 }, dy[4] = { 1,0,-1,0 };
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int gcd(int a, int b) {
    if (a == 0) return b;
    else if (b == 0) return a;
    return b ? gcd(b, a % b) : a;
}
int main() {
    int n,sum = 0; cin >> n; vector<int> a(n),l(n+1),r(n+1);
    l[0] = 0; r[n] = 0;
    rep(i, n) {
        cin >> a[i];
        l[i + 1] = gcd(l[i], a[i]);
    }
    rrep(i, n) {
        r[i] = gcd(r[i + 1], a[i]);
    }
    rep(i, n) {
        sum = max(sum, gcd(l[i], r[i + 1]));
    }cout << sum << endl;
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
bool tf[123456 * 2 + 1] = { false };

void CheckList(){
	for (int i = 2; i <= 123456 * 2; i++){
		if (tf[i]) continue;
		for (int j = i * 2; j <= 123456 * 2; j += i){
			tf[j] = true;
		}
	}
}

int main(){
	int n;
	CheckList();
	while (1){
		cin >> n;
		if (n == 0) break;
		int n2 = n * 2;
		int count = 0;
		for (int i = n + 1; i <= n2; i++){
			if (!tf[i]) count++;
		}
		cout << count << endl;
	}
	return 0;
}

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

int main (void){
int N;
cin >> N;
string W[N];
bool a = true;
for(int i = 0; i < N; i++){
	cin >> W[i];
	}
	for (int i = 0; i < N - 1; i++){
		if(W[i].back() != W[i + 1].front()){
			a = false;
		}
	}
	for(int i = 0; i < N; i++){
		for(int j = 0; j < i; j++){
			if(W[i] == W[j]){
				a = false;
			}
		}
	}
	if(a){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
N=int(input())
S=str(input())
#W=左
#E=右
ans=[]
count=0
#一番左
for i in range(1,N):
    
    if S[i]=="E":
        count+=1    
        
        
ans.append(count)


for i in range(1,N):
    
    if S[i-1]=="W":
        count+=1
    if S[i]=="E":
        count-=1

    ans.append(count)

print(min(ans))


Measured memory_bytes: 15520
#!/usr/bin/python
# -*- coding: utf-8 -*-

X, N = map(int,input().split())
p = list(map(int,input().split()))


for x in range(0,101):
    if X-x not in p:
        print(X-x)
        exit()
    elif X+x not in p:
        print(X+x)
        exit()


Measured memory_bytes: 61752
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {

      long long N;
      long long px;
      long long py;
      long long qx;
      long long qy;
      long long S;

      cin >> N;
      
      S = N;

      long long l = sqrt(S);

      if(S == l*l){
          px = l;
          py = 0;

          qx = 1;
          qy = l;
      }
      else if( S < (l+1)*l){
          px = l;
          py = 1;

          qx = (l+1)*l-S;
          qy = l+1;
      }
      else if(S == (l+1)*l){
          px = l;
          py = 0;

          qx = 1;
          qy = l+1;

      }
      else{
          px = l+1;
          py = 1;

          qx = (l+1)*(l+1)-S;
          qy = l+1;
      }

      cout << 0 <<" "<< 0 <<" "<<px<<" "<<py<<" "<<qx<<" "<<qy <<endl;
      //cout << px*qy - qx*py << endl;
      return 0;
     
    }

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
  ll n; ll k; cin >> n >> k;
  vector<ll> a(n+1);
  rep(i, n){
    cin >> a.at(i+1);
  }

  vector<bool> used(n+1, false);
  queue<ll> q, q1, q2;
  q.push(1);

  ll cnt = 0;
  ll ploop=0;
  while(!q.empty()){
    ll now = q.front();
    if(cnt==k){
      cout << now << endl;
      return 0;
    }
    used.at(now) = true;
    q.pop();
    cnt++;

    dump(now);
    if(!used.at(a.at(now))){
      q.push(a.at(now));
    }
    else{
      ploop = a.at(now);
      break; 
    }
  }


  q1.push(1);
  rep(i, n+1){
    used.at(i) = false;
  }
  used.at(1) = true;

  ll cnt2= 0;
  ll sp = 0;
  while(!q1.empty()){
    ll now = q1.front();
    if(now==ploop){
      sp = cnt2;
      break;
    }
    cnt2++;
    
    used.at(now) = true;
    q1.pop();

    if(!used.at(a.at(now))){
      q1.push(a.at(now));
    }
    else{
      break; 
    }
  }

  ll loop = (k-sp)%(ll)(cnt-sp);
  q2.push(1);
  rep(i, n+1){
    used.at(i) = false;
  }
  used.at(1) = true;
  dump(loop);

  ll cnt3= 0;
  bool st = false;
  while(!q2.empty()){
    ll now = q2.front();
    
    used.at(now) = true;
    q2.pop();

    if(now==ploop){
      st = true;
    }
   
    if(st && cnt3==loop){
      cout << now << endl;
      return 0;
    }
    else if(st) cnt3++;
    
    if(!used.at(a.at(now))){
     q2.push(a.at(now));
    }
    else{
      break; 
    }
  }

  return 0;
}


Measured memory_bytes: 4828
#include <bits/stdc++.h>
#define P pair<int, int>
#define PP pair<char, P>

using namespace std;

int main(){
  int h, w, n, sr, sc;
  string s, t;
  map<char, char> oposite;
  oposite['L'] = 'R';
  oposite['R'] = 'L';
  oposite['U'] = 'D';
  oposite['D'] = 'U';
  cin >> h >> w >> n >> sr >> sc;
  cin >> s >> t;
  sr--;sc--;
  for(auto p: {PP('L', P(0, -1)), PP('R', P(0, 1)), PP('U', P(-1, 0)), PP('D', P(1, 0))}){
    char c=p.first;
    int dy=p.second.first;
    int dx=p.second.second;
    int cy=sr;
    int cx=sc;
    for(int i=0;i<n;i++){
      if(s[i]==c){
        cy+=dy;
        cx+=dx;
      }
      if(!(0<=cy&&cy<=h-1&&0<=cx&&cx<=w-1)){
        cout << "NO" << endl;
        return 0;
      }
      if(t[i]==oposite[c]){
        cy=max(0, min(h-1, cy-dy));
        cx=max(0, min(w-1, cx-dx));
      }
    }
  }
  cout << "YES" << endl;
}



Measured memory_bytes: 3900
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  long[] a; readA(n, a);

  auto b = a.map!"a>0".array;
  foreach (i; 0..n-1)
    if (!b[i]) {
      b[i] = !b[i];
      b[i+1] = !b[i+1];
    }

  auto c = a.map!abs.array;
  if (b[$-1])
    writeln(c.sum);
  else
    writeln(c.sum-c.reduce!min*2);
}


Measured memory_bytes: 4988
import sys
input = sys.stdin.readline
 
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
 
dp = [0 for i in range(K+1)]
for i in range(K+1):
    if not dp[i]:
        for j in range(N):
            if i + A[j] < K + 1:
                dp[i+A[j]] = 1
 
if dp[K]: print("First")
else: print("Second")

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

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

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

    int n;
    while(cin>>n,n)
    {
        int cnt[26]={0};
        string s;
        REP(i,n) cin>>s[i];
        REP(i,n){
            cnt[s[i]-'A']++;

            int fst=0,scd=0;
            REP(j,26){
                if(cnt[j]>fst) scd=fst,fst=cnt[j];
                else if(cnt[j]>scd) scd=cnt[j];
            }
            int rest=n-(i+1);
            if(fst>scd+rest){
                REP(j,26) if(cnt[j]==fst) cout<<(char)('A'+j)<<" ";
                cout<<i+1<<endl; break;
            }else if(i==n-1){
                cout<<"TIE"<<endl;
            }
        }
    }
}



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

#include <atcoder/all>

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;
using namespace atcoder;

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;

inline char getcha() {
  if (ci - cn == cm) {
    fread(cn, 1, cm, stdin);
    ci = cn;
  }
  return *ci++;
}

inline int getint() {
  int A = 0;
  if (ci - cn + 16 > cm) {
    while ((ct = getcha()) >= '0') {
      A = A * 10 + ct - '0';
    }
  } else {
    while ((ct = *ci++) >= '0') {
      A = A * 10 + ct - '0';
    }
  }
  return A;
}

int main() {
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  int tt = getint();
  while (tt--) {
    int n = getint(), m = getint(), a = getint(), b = getint();
    printf("%lld\n", floor_sum(n, m, a, b));
  }
  return 0;
}

Measured memory_bytes: 3820
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std ;

typedef long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/


/*
// failed for large value with error code 135 and <Illegal instruction: 4> on mac
class Point
{
public:
	ll x;
	ll y;
};

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

	ll H, W;
	int N;
	
	cin >> H >> W >> N;

	Point m[N];

	for (int i = 0; i < N; i++)
	{
		cin >> m[i].y >> m[i].x;
	}

	ll d[H-2][W-2];
	memset(d, 0, sizeof(ll) *(H-2)*(W-2));

	for (int i = 0; i < N; i++)
	{
		
		for (ll j = m[i].y - 3; j <= m[i].y - 1; j++)
		{
			
			if ((j < 0) || (j >= H-2))
			{
				continue;
			}
			

			for (ll k = m[i].x - 3; k <= m[i].x - 1; k++)
			{
				
				if ((k < 0) || (k >= W-2))
				{
					continue;
				}
				
				d[j][k]++;
				
			}
		}
		
	}

	ll cnt[10];
	memset(cnt, 0, sizeof(ll) * 10);

	for (int i = 0; i < 10; i++)
	{
		for (ll j = 0; j < H-2; j++)
		{
			for (ll k = 0; k < W-2; k++)
			{
				if (d[j][k] == i)
				{
					cnt[i]++;
				}
			}
		}
		cout << cnt[i] << endl;
	}

	
	return 0;
}
*/


// others
#include <iostream>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int MAXN = 100010;
ll h, w, n;
ll a[MAXN], b[MAXN];
ll _count[10];
map<P, int> m;
void solve() {
  for (int i=0;i<n;i++) {
    for (int x=0;x<=2;x++) {
      for (int y=0;y<=2;y++) {
        int nx = b[i] - x;
        int ny = a[i] - y;
        if (nx >=0 && nx < w-2 && ny >= 0 && ny < h-2) {
          m[P(nx, ny)]++;
        }
      }
    }
  }
  ll tot = 0;
  for (auto const& x : m) {
    _count[x.second]++;
    tot++;
  }
  _count[0] = (h-2) * (w-2) - tot;
  for (int i=0;i<10;i++) {
    cout << _count[i] << endl;
  }
}

int main() {
  cin >> h >> w >> n;
  for (int i=0;i<n;i++) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }
  solve();
}


Measured memory_bytes: 58112
#include<bits/stdc++.h>
#define l long 
#define ll long long 
#define ld long double 
#define INF 1000000000000000
#define MOD 1000000007
#define MAX_N 1000006
#define f first
#define s second
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULLL);
using namespace std;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    l n;
    cin>>n;
    vector<ll> a;
    ll x;
    for(l i=0;i<n;i++)
    {
        cin>>x;
        a.push_back(x);
    }
    ll prf[n],suf[n];
    prf[0]=a[0];
    for(l i=1;i<n;i++)
    {
        prf[i]=prf[i-1]+a[i];
    }
    suf[n-1]=a[n-1];
    for(l i=n-2;i>=0;i--)
    {
        suf[i]=suf[i+1]+a[i];
    }
    ll dp[n][n],sum=0LL;
    for(l i=0;i<n;i++){
        for(l j=0;j<n;j++)
        dp[i][j]=INF;
    }
    for(l len=1;len<=n;len++)
    {
        for(l i=0;i<n;i++)
        {
            if(i+len-1>=n)
            break;
            if(len==1)
                dp[i][i]=0;
            else 
            {
                sum=prf[n-1];
                if(i>0)
                sum-=prf[i-1];
                if(i+len<n)
                sum-=suf[i+len];
                for(l j=i;j<i+len-1;j++)
                {
                    dp[i][i+len-1]=min(dp[i][j]+dp[j+1][i+len-1]+sum,dp[i][i+len-1]);
                }
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

int main() {
    // O[1]

    string str[3];
    cin >> str[0];
    cin >> str[1];
    str[2] = str[0] + str[0];

    if (str[2].find(str[1]) != string::npos) {
        cout << "Yes"
             << "\n";
    } else {
        cout << "No"
             << "\n";
    }

    return 0;
}



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

int sumdigit(int i){
 int count=0;
  while(i>0){
     count+=i%10;
     i=i/10;
  }
 return count;
}

int main() {
 int N,A,B,ans;
 cin>>N>>A>>B;
  ans=0;
  for(int i=1;i<=N;i++){
  int sum=sumdigit(i);
    if(A<=sum&&sum<=B){
      ans+=i;
    }
   } 
 cout<<ans<<endl;
}


Measured memory_bytes: 256
use proconio::input;
use std::process::exit;

fn main() {
    input! (
        a: i64,
        b: i64,
    );

    for i in 1..10001 {
        let n = i as f64;
        if ( n * 0.08 ) as i64 == a && ( n * 0.1 ) as i64 == b {
            println!("{}", i);
            exit(0);
        }
    }
    println!("-1");
}


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

using namespace std;

int main() {
   ios_base :: sync_with_stdio(0);
   cin.tie(0) , cout.tie(0);
   int n;
   cin >> n;
   string s;
   cin >> s;
   int ans = 0;
   for (int i = 0; i < n - 2; i++) {
      if (s[i] == 'A') {
         if (s[i + 1] == 'B') {
            if (s[i + 2] == 'C') {
               ans++;
            }
         }
      }
   }
   cout << ans << '\n';
   return 0;
}


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

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> V(N);
  vector<int> C(N);
  for( int i=0;i<N;++i )
    cin >> V[i];
  for( int i=0;i<N;++i )
    cin >> C[i];

  int ans = 0;
  for( int i=0;i<N;++i )
    if( V[i]>C[i] )
      ans += V[i]-C[i];

  cout << ans <<  endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>

using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    double *p = new double[n];
    double *E = new double[n];
    double sum=0;
    double maxsum=0;
    for(int i=0;i<n;i++){
        scanf("%lf",&p[i]);
    }

    for(int i=0;i<n;i++){
        E[i] = (1+p[i])/2;
    }
    for(int i=0;i<k;i++){
        sum += E[i];
    }
    maxsum = sum;
    for(int i=0;i<n-k;i++){
        sum = sum - E[i] + E[i+k];
        maxsum = max(maxsum,sum);
    }

    cout << setprecision(10) << maxsum << endl;
    delete[] p,E;
    return 0;
}

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

// Type Aliases
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vec<vec<T>>;
template <class T, class U>
using pairs = vector<pair<T, U>>;
template <class T>
using pqueue = priority_queue<T>;
using ll = long long;
using vll = vec<ll>;
using vvll = vvec<ll>;
using pll = pair<ll, ll>;
using vpll = pairs<ll, ll>;

// constants
static const ll INF = 1LL << 50;
static const double dINF = 1e290;
static const ll MOD = (ll)1e9 + 7;
//static const ll MOD = (ll)1e9+9;
//static const ll MOD = 998244353;

#define endl "\n"
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define range(i, a, b) for (ll(i) = (a); (i) <= (b); (i)++)

#define all(v) (v).begin(), (v).end()
#define asc(v) sort(all(v))
#define desc(v) sort((v).rbegin(), (v).rend())

#define fold(src, dst, lambda) partial_sum(all(src), (dst).begin(), lambda)
#define rfold(src, dst, lambda)                   \
    reverse(all(src));                            \
    partial_sum(all(src), (dst).begin(), lambda); \
    reverse(all(dst));
#define cumsum(src, dst) fold(src, dst, [](auto &a, auto &b) { return a + b; })
#define sum(v) accumulate(all(v), 0, [](auto &a, auto &b) { return a + b; })

#define del(v, i) (v).erase((v).begin() + i)
#define uniq(v) \
    asc(v);     \
    (v).erase(unique(all(v)), (v).end())

template <typename T>
T min(vec<T> v)
{
    return *min_element(all(v));
}
template <typename T>
T max(vec<T> v)
{
    return *max_element(all(v));
}

// io helper
template <typename T>
void debug(T t)
{
    cerr << t << endl;
}
template <typename T, typename... Args>
void debug(T t, Args... args)
{
    cerr << t << " ";
    debug(args...);
}
template <typename T>
void out(T t)
{
    cout << t << endl;
}
template <typename T, typename... Args>
void out(T t, Args... args)
{
    cout << t << " ";
    out(args...);
}
template <typename T>
istream &operator>>(istream &is, vec<T> &v)
{
    for (auto &a : v)
        is >> a;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, vec<T> &v)
{
    os << "[";
    rep(i, v.size() - 1)
            os
        << v[i] << ", ";
    os << v[v.size() - 1] << "]";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <size_t N, typename T>
ostream &operator<<(ostream &os, array<T, N> &v)
{
    os << "[";
    rep(i, N - 1)
            os
        << v[i] << ", ";
    os << v[N - 1] << "]";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &mp)
{
    os << "{ ";
    for (auto &p : mp)
        os << p.first << ": " << p.second << ", ";
    os << "}";
    return os;
}

void solve()
{
    string s;
    ll k;
    cin >> k >> s;
    if (s.size() > k)
    {
        cout << s.substr(0, k) << "..." << endl;
    }
    else
    {
        out(s);
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(20);
    solve();
    return 0;
}

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

namespace ABC140A
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray().First();
            long[] A = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
            long[] B = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
            long[] C = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();

            long ans = 0;
            long beforeDish = -1;
            foreach (long dish in A)
            {
                ans += B[dish - 1];
                if (beforeDish + 1 == dish)
                {
                    ans += C[beforeDish - 1];
                }

                beforeDish = dish;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13396
#include <stdio.h>
#define MAX 100000

int parent(int);

int left(int);

int right(int);

int main(){
    int H,i,A[MAX+1];
    
    scanf("%d",&H);
    for(i=1;i<=H;i++){
        scanf("%d",&A[i]);
    }
    for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i) >= 1){
        printf("parent key = %d, ",A[parent(i)]);
    }
    if(left(i) <= H){printf("left key = %d, ",A[left(i)]);}
    if(right(i) <= H){printf("right key = %d, ",A[right(i)]);}
    printf("\n");
    }
    
    return 0;
}
int parent(int i){
    return i/2;
}
int left(int i){
    return 2 * i;
}
int right(int i){
    return 2 * i + 1;
}


Measured memory_bytes: 2052
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct seg {
  int start, end, value;
};


long long INF=1e18;

struct ST {

  vector<long long> t;
  vector<long long> lazy;
  int size;

  ST(int N) {
    size = N;
    t.assign(N*4+10, 0);
    lazy.assign(N*4+10, 0);
  }

  void push(int nodeid) {
    // push lazy[nodeid] to childs
    t[nodeid*2] += lazy[nodeid];
    t[nodeid*2+1] += lazy[nodeid];
    lazy[nodeid*2] += lazy[nodeid];
    lazy[nodeid*2+1] += lazy[nodeid];
    lazy[nodeid] = 0;
  }

  void update(int l, int r, int ql, int qr, int nodeid, long long addvalue) {
    if(ql > qr) return;
    if (l==ql && r==qr) {
      t[nodeid] += addvalue;
      lazy[nodeid] += addvalue;
    } else {
      push(nodeid);
      int m = (l + r) / 2;
      update(l, m, ql, min(m, qr), nodeid*2, addvalue);
      update(m+1, r, max(m+1, ql), qr, nodeid*2+1, addvalue);
      t[nodeid] = max( t[nodeid*2], t[nodeid*2+1] );
    }
  }

  long long query(int l, int r, int ql, int qr, int nodeid) {
    if (ql > qr) return -INF;
    if (l>=ql && r <=qr) return t[nodeid];
    push(nodeid);
    int m = (l+r) / 2;
    return max(
      query(l, m, ql, min(m, qr), nodeid*2),
      query(m+1, r, max(m+1, ql), qr, nodeid*2+1)
    );
  }
};

vector<seg> l;

int main() {

  int N, M;

  cin >> N >> M;

  l.resize(M);
  vector< vector<int> > open_seg(N+2), close_seg(N+2);
  ST st(N+2);


  for (auto i=0; i<M; i++) {
    cin >> l[i].start >> l[i].end >> l[i].value;
    open_seg[ l[i].start ].push_back(i);
    close_seg[ l[i].end ].push_back(i);
  }


  // st.update(0, N, 0, N, 1, -INF);

  for (int i=1; i<=N+1; i++) {
    for (auto segid: open_seg[i]) {
      st.update(0, N+1, 0, l[segid].start-1, 1, l[segid].value);
    }

    auto dp = st.query(0, N+1, 0, i-1, 1);
    st.update(0, N+1, i, i, 1, dp);

    for (auto segid: close_seg[i]) {
      st.update(0, N+1, 0, l[segid].start-1, 1, -l[segid].value);
    }

    if (i==N+1) cout << dp << endl;
  }

  return 0;
}

Measured memory_bytes: 36992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[][] a = new int[2][n];
		for(int i=0;i<2;i++) {
			for(int j=0;j<n;j++) {
				a[i][j] = in.nextInt();
			}
		}
		int max = 0;
		for(int i=0;i<n;i++) {
			int total = 0;
			for(int j=0;j<=i;j++) {
				total += a[0][j];
			}
			for(int j=i;j<n;j++) {
				total += a[1][j];
			}
			if(total>max) max = total;
		}
		System.out.println(max);
		in.close();
	}

}


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

int main(){
	long long a;
	long long min = 1000000;
	long long max = -1000000;
	long long sum = 0;
	long long n;

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> a;
		if(min > a){
			min = a;
		}
		if(max < a){
			max = a;
		}
		sum += a;
	}
	cout << min << " " << max << " " << sum << endl;

	return 0; 
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline void LB(vector<T>& v, T& a) { return *lower_bound(ALL(v),a); }
template <typename T> inline void LBP(vector<T>& v, T& a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline void UB(vector<T>& v, T& a) { return *upper_bound(ALL(v),a); }
template <typename T> inline void UBP(vector<T>& v, T& a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template< typename T, typename V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; }
template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int N;
  cin >> N;
  map<int,int> mp;
  REP(i,N) {
    int a;
    cin >> a;
    mp[a]++;
  }
  int d = mp.rbegin()->first;
  if (mp.begin()->first < (d+1)/2) {
    cout << "Impossible" << endl;
    return 0;
  }
  if (d % 2 == 0) {
    if (mp[d/2] != 1) {
      cout << "Impossible" << endl;
      return 0;
    }
    for (int i = d/2+1; i <= d; i++) {
      if (mp[i] < 2) {
        cout << "Impossible" << endl;
        return 0;
      }
    }
  } else {
    if (mp[(d+1)/2] != 2) {
      cout << "Impossible" << endl;
      return 0;
    }
    for (int i = (d+1)/2+1; i <= d; i++) {
      if (mp[i] < 2) {
        cout << "Impossible" << endl;
        return 0;
      }
    }
  }
  cout << "Possible" << endl; 

  return 0;
}

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

int main(){
  string S;
  cin >> S;
  int lenS = S.size();
  int i = 0;
  string dream = "dream";
  string erase = "erase";
  while (i < lenS){
    if (S.at(i) == 'd'){
      for (int j=1; j<5; j++){
        if (i+j >= lenS){
          cout << "NO" << endl;
          return 0;
        }
        if (S.at(i+j) != dream.at(j)){
          cout << "NO" << endl;
          return 0;
        }
      }
      i += 5;
      if (i >= lenS) break;
      if (S.at(i) != 'e') ;
      else{
        if (i+1 >= lenS){
          cout << "NO" << endl;
          return 0;
        }
        if ((i+2 < lenS) && (S.at(i+2) == 'a')) ;
        else{
          if (S.at(i+1) == 'r')
            i += 2;
          else{
            cout << "NO" << endl;
            return 0;
          }
        }
      }
    }
  else if (S.at(i) == 'e'){
    for (int j=1; j<5; j++){
      if (i+j >= lenS){
        cout << "NO" << endl;
        return 0;
      }
      if (S.at(i+j) != erase.at(j)){
        cout << "NO" << endl;
        return 0;
      }
    }
    i += 5;
    if (i >= lenS) break;
    if (S.at(i) == 'r') i++;
    else if (S.at(i) == 'd' || S.at(i) == 'e') ;
    else{
      cout << "NO" << endl;
      return 0;
    }
  }
  else{
    cout << "NO" << endl;
    return 0;
  }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 512
n = int(input())
h = list(map(int, input().split()))
a = [0]*n
a[1] = abs(h[1]-h[0])
for i in range(2, n):
    a[i] = min(a[i-2]+abs(h[i]-h[i-2]), a[i-1]+abs(h[i]-h[i-1]))
print(a[n-1])

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

int main(){
	int N;
	cin >> N;
	int d[100];
	for(int i = 0;i < N;i++){
		cin >> d[i];
	}

int sum = 0;
	for(int i = 0;i < N;i++){
		for(int j = i+1;j < N;j++){
			int c = d[i]*d[j];
			sum += c;
		}
	}
	cout << sum << endl;
}


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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  VI v(n);
  rep(i, n) cin >> v[i];
  int r = min(n, k);
  int ans = -INF;
  for(int i = 0; i <= r; ++i){
    for(int j = 0; j <= r - i; ++j){
      VI s;
      for(int m = 0; m < i; ++m) s.pb(v[m]);
      for(int m = n - 1; m >= n - j; --m) s.pb(v[m]);
      sort(s.rbegin(), s.rend());
      rep(m, k - (i + j)) {
        if(s.empty()) break;
        else if(s.back() >= 0) break;
        else s.pop_back();
      }
      ans = max(ans, accumulate(ALL(s), 0));
    }
  }

  out(ans);
  return 0;
}


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

using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    if(A == B && B == C) {
        cout << "No" << endl;
    } else if(A == B || B == C || A == C) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
//Sasayego! Sasayego! Shinzou wo Sasageyo!

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bitset>
#include <ctime>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 4e2 + 5;
const int maxM = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

bool mark[maxN];
pii a[maxM];
bitset <maxN> bt[maxN];

int main(){
	time_t START = clock();
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, q; scanf("%d%d", &n, &q);
	for (int i = 1; i <= q; i++)
		scanf("%d%d", &a[i].first, &a[i].second);
	for (int i = 1; i <= n; i++){
		bt[i][i] = 1;
		mark[i] = true;
		for (int j = q; j > 0; j--){
			if (bt[i][a[j].first] == 1){
				if (bt[i][a[j].second] == 1){
					mark[i] = false;
					break;
				}
				else
					bt[i][a[j].second] = 1;
			}
			else{
				if (bt[i][a[j].second] == 1)
					bt[i][a[j].first] = 1;
			}
		}
	}
	int res = 0;
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
			if (mark[i] && mark[j] && (bt[i] & bt[j]).count() == 0)
				res++;
	printf("%d\n", res);
	time_t FINISH = clock();
	cerr << "Execution time: " << (ld)(FINISH - START) / CLOCKS_PER_SEC * 1000.0 << " milliseconds.\n";
	return 0;
}
 



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long root1[200000],rank1[200000]/*道路*/,root2[200000],rank2[200000]/*鉄道*/;
long long find1(long long x){
    if(root1[x]==x)return x;
    else return root1[x]=find1(root1[x]);
}
long long find2(long long x){
    if(root2[x]==x)return x;
    else return root2[x]=find2(root2[x]);
}
int main(){
    #define int long long
    int n,k,l;
    cin>>n>>k>>l;
    for(int i=0;i<n;i++)root1[i]=i,rank1[i]=0,root2[i]=i,rank2[i]=0;
    int a[k],b[k],c[l],d[l];
    for(int i=0;i<k;i++){
        cin>>a[i]>>b[i];
        int x=find1(a[i]-1),y=find1(b[i]-1);
        if(x==y)continue;
        if(rank1[x]<rank1[y])root1[x]=y;
        else{
            root1[y]=x;
            if(rank1[x]==rank1[y])rank1[x]++;
        }
    }
    for(int i=0;i<l;i++){
        cin>>c[i]>>d[i];
        int x=find2(c[i]-1),y=find2(d[i]-1);
        if(x==y)continue;
        if(rank2[x]<rank2[y])root2[x]=y;
        else{
            root2[y]=x;
            if(rank2[x]==rank2[y])rank2[x]++;
        }
    }
    map<long long,int>m;
    for(int i=0;i<n;i++){
        root1[i]=find1(i),root2[i]=find2(i);
        m[root1[i]*200000+root2[i]]++;
    }
    for(int i=0;i<n;i++)cout<<m[root1[i]*200000+root2[i]]<<endl;
    return 0;
}

Measured memory_bytes: 23808
function main(input) {
  let N = parseInt(input, 10);
  let result = "";
  const alphabet = "abcdefghijklmnopqrstuvwxyz";

  while (0 < N) {
    let M = N % 26;
    if (M === 0) {
      M = 26;
    }
    result = alphabet.substr(M - 1, 1) + result;
    N = (N - M) / 26;
  }

  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29504