akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <map>
using namespace std;

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

	int N;
	cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; ++i) {
		cin >> v[i];
	}
	int cnt = 0;
	for (int i = 0; i < N; ++i) {
		if (v[i] & 1) {
			cnt ^= 1;
		}
	}
	if (cnt) {
		cout << "NO" << endl;
	} else {
		cout << "YES" << endl;
	}
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
ll c[200005],pre[200005],sx[200005],mod=2019;
ll qpow(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1) res=res*a%mod;
        b/=2;
        a=a*a%mod;
    }
    return res%mod;
}
map<ll,ll> t;
int main(){
    string s;
    cin>>s;
    ll now=0,ans=0,n=s.length();
    s=" "+s;
    for(ll i=1;i<=n;i++){
        c[i]=qpow((ll)10,n-i)*(s[i]-'0');
        c[i]%=2019;
    }
    for(int i=1;i<=n;i++){
        pre[i]=(c[i]+pre[i-1])%2019;
        if(pre[i]==0) ans++;
    }
    for(int i=n;i>=1;i--){
        sx[i]=(c[i]+sx[i+1])%2019;
        if(sx[i]==0) ans++;
        t[sx[i]]++;
    }
    for(int i=1;i<n;i++){
        t[sx[i]]--;t[sx[i+1]]--;
        ans+=t[(pre[n]+2019-pre[i])%2019];
        t[sx[i+1]]++;
    }
    cout<<ans<<endl;
} 

Measured memory_bytes: 8304
#include<bits/stdc++.h>
using namespace std;
int n,k,a[510],tmp[510],r[510],l[510],sum,ans=1;
bool check(int num) {
	for(int i=1;i<=n;++i)
		tmp[i]=a[i]%num;
	sort(tmp+1,tmp+n+1);
	for(int i=1;i<=n;++i)
		l[i]=l[i-1]+tmp[i];
	for(int i=n;i>=1;--i)
		r[i]=r[i+1]+(num-tmp[i]);
	for(int i=1;i<n;++i)
		if(l[i]==r[i+1]&&l[i]<=k) return true;
	return false;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i) {
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	for(int i=1;i*i<=sum;++i)
		if(sum%i==0) {
			if(check(i)) ans=max(ans,i);
			if(check(sum/i)) ans=max(ans,sum/i);
		}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define PI 3.14159265358979
#define MOD 1000000007
#define ERR 0.00000000000001
#define NUM 200010

int main(){
    LL n, k, x, min1, min2;
    scanf("%lld %lld",&n,&k);
    x = n/k;
    min1 = n - x*k;
    min2 = (n - (x+1)*k)*-1;
    if(min2<min1){ min1 = min2; }
    printf("%lld",min1);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
ll lcm(ll x, ll y){
  return x / gcd(x,y) * y;
}
ll comb(ll n, ll r){
  if (r*2>n) r=n-r;
  ll x=1, y=1;
  reps(i,1,r+1){ x *= (n-i+1); y *= i; }
  return x / y;
}


int main(){
  int n; cin >> n;
  vector<ll> t(n); rep(i,n) cin >> t[i];
  ll ans=1;
  rep(i,n) ans = lcm(ans, t[i]);
  
  cout << ans;
  
return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n,0),b(n,0);
    for(int i = 0;i < n;i ++){
        int p;
        cin >> p;
        p --;
        a[p] += i;
        if(p+1<n)b[p+1] -= i; 
    }
    for(int i = 0;i < n;i ++){
        if(i) a[i] += a[i-1],b[i] += b[i-1];
    }
    for(int i = 0;i < n;i ++){
        cout << a[i]+n*n+i << " ";
    }
    cout << endl;
    for(int i = 0;i < n;i ++){
        cout << b[i]+n*n-i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 768
# coding: utf-8

# In[243]:


N = int(input())


# In[244]:


list_9 = [9]
for i in range(4):
    list_9.append(list_9[i] * 9)
    
list_6 = [6]
for i in range(5):
    list_6.append(list_6[i] * 6)


# In[245]:


amount_list = list_9 + list_6 + [1]
amount_list.sort(reverse=True)


# In[247]:


dp = [10**9] * (N+1)
dp[0] = 0


# In[248]:


for i in range(len(dp)):
    for amount in amount_list:
        if i >= amount:
            dp[i] = min(dp[i],dp[i-amount]+1)
print(dp[N])



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

int main() {
  int N;
  string color;
  bool flag=false;
  cin >> N;
  rep(i, N){
    cin >> color;
    if(color == "Y") flag = true;
  }
  if(flag) cout << "Four" << endl;
  else cout << "Three" << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())

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

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

'''
T - li[] * 0.006 = A が一番近いもの
'''

p = abs(t - li[0] * 0.006 - a) #基準の絶対値
q = 0
s = 0

for i in li:

    b = abs(t - int(i) * 0.006 - a)

    if b < p :
        p = b
        s = q

    q = q + 1

print(s + 1)


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

typedef long long ll;
#define REP(i,n) for (ll i = 0; i < n; ++i)

int Q;

int main() {
    cin >> Q;
    ll ans = 0;
    multiset<ll> left, right;
    REP (q, Q) {
        int w, a, b; cin >> w;
        if (w == 1) {
            cin >> a >> b;
            ans += b;
            if (q == 0) {
                left.insert(a);
                right.insert(a);
            } else {
                ll lmx = *left.rbegin();
                ll rmn = *right.begin();

                if (a < lmx) {
                    left.insert(a);
                    left.insert(a);

                    ll m = *left.rbegin();
                    left.erase(--left.end());
                    right.insert(m);
                    ans += m - a;
                } else if (a > rmn) {
                    right.insert(a);
                    right.insert(a);

                    ll m = *right.begin();
                    right.erase(right.begin());
                    left.insert(m);
                    ans += a - m;
                } else {
                    right.insert(a);
                    left.insert(a);
                }
            }
        } else {
            cout << *left.rbegin() << " " << ans << endl;
        }
    }
}

Measured memory_bytes: 18944
import std.stdio,std.conv,std.string,std.algorithm,std.array;
void main(){
  auto s=readln().chomp().split().map!(to!int);
  int a,b,c,d;
  a=s[0];
  b=s[1];
  c=s[2];
  d=s[3];
  
  if(a+b>c+d) writeln("Left");
  else if(a+b==c+d) writeln("Balanced");
  else writeln("Right");
}

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

ll dp[100004];

ll solve(ll height[], ll n) {

    if (dp[n] != -1)
        return dp[n];
    else {
        if (n == 1)
            return dp[n] = 0;

        else if (n == 2)
            return dp[n] = abs(height[n] - height[n - 1]);
        else {
            ll ans1 = abs(height[n] - height[n - 1]);
            ll ans2 = abs(height[n] - height[n - 2]);

            return dp[n] = min(ans1 + solve(height, n - 1), ans2 + solve(height, n - 2));
        }
    }
}
int main()
{
//#ifndef ONLINE_JUDGE
  //  freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);
//#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    ll n;
    cin >> n;

    ll height[n + 1];
    // ll sum = 0;
    for (ll i = 1; i <= n; i++)  cin >> height[i];
    memset(dp, -1, sizeof(dp));
    //dp[1] = height[1];
    cout << solve(height, n) << endl;

    return 0;
}

Measured memory_bytes: 4224
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

vector<string> v;

int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < 26; i++)
		v.push_back(string(1, 'a' + i));
	for (int i = s.size() - 1; i >= 0; i--) {
		int minIdx;
		int minLength = 987654321;
		for (int j = 0; j < 26; j++) {
			if (v[j].size() < minLength) {
				minLength = v[j].size();
				minIdx = j;
			}
		}
		v[s[i] - 'a'] = string(1, s[i]) + v[minIdx];
	}
	int minIdx;
	int minLength = 987654321;
	for (int j = 0; j < 26; j++) {
		if (v[j].size() < minLength) {
			minLength = v[j].size();
			minIdx = j;
		}
	}
	cout << v[minIdx] << endl;
}

Measured memory_bytes: 644
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
inline int read(){
	int ans=0,fh=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') fh=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
		ans=(ans<<1)+(ans<<3)+ch-'0',ch=getchar();
	return ans*fh;
}
const int maxn=4e5+100;
int n,k,siz[maxn<<2],mx;
ll a[maxn],b[maxn];
map<ll,int>bh;
inline void lsh(){
	for(int i=1;i<=n;i++) b[i]=a[i];
	sort(b+1,b+n+1),b[0]=b[1]-1;
	for(int i=1;i<=n;i++)
		if(b[i]!=b[i-1]) bh[b[i]]=++mx;
	for(int i=1;i<=n;i++) a[i]=bh[a[i]];
}
void insert(int o,int l,int r,int qz){
	siz[o]++;
	if(l==r) return;
	int mid=l+r>>1;
	if(qz<=mid) insert(o<<1,l,mid,qz);
	else insert(o<<1|1,mid+1,r,qz);
}
ll query(int o,int l,int r,int ql,int qr){
	if(ql==l&&qr==r) return siz[o];
	int mid=l+r>>1;
	ll ans=0;
	if(ql<=mid) ans=query(o<<1,l,mid,ql,min(qr,mid));
	if(qr>mid) ans+=query(o<<1|1,mid+1,r,max(ql,mid+1),qr);
	return ans;
}
int main(){
//	freopen("nh.in","r",stdin);
	n=read(),k=read();
	for(int i=1;i<=n;i++)
		b[i]=read()-k;
	for(int i=1;i<=n+1;i++) a[i]=a[i-1]+b[i-1];
	n++,lsh();
	ll ans=0;
	for(int i=1;i<=n;i++){
		ans+=query(1,1,mx,1,a[i]);
		insert(1,1,mx,a[i]);
	}
	cout<<ans<<endl;
	return 0;
}










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

using namespace std;

int getdir(char c) {
    switch (c) {
    case 'N':
        return 0;
    case 'E':
        return 1;
    case 'S':
        return 2;
    case 'W':
        return 3;
    default:
        return -1;
    }
}

int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};
char num2dir[4] = {'N', 'E', 'S', 'W'};

int main(void) {
    int h, w;
    long long l;
    while (cin >> h >> w >> l, h|w|l) {
        vector<string> vs;
        long long count = 0;
        string wall = "";
        int memo[101][101][4];
        fill_n((int *)memo, 101*101*4, -1);

        for (int i = 0; i < w+2; i++) {
            wall += "#";
        }
        vs.push_back(wall);
        string input;
        for (int i = 0; i < h; i++) {
            cin >> input;
            vs.push_back("#"+input+"#");
        }
        vs.push_back(wall);

        int x, y, dir;
        for (int j = 0; j < h+2; j++) {
            for (int i = 0; i < w+2; i++) {
                if (vs[j][i] != '#' && vs[j][i] != '.') {
                    x = i;
                    y = j;
                    dir = getdir(vs[j][i]);
                    vs[j][i] = '.';
                }
            }
        }

        memo[y][x][dir] = 0;
        while (l > 0) {
            if (vs[y+dy[dir]][x+dx[dir]] == '.') {
                y += dy[dir];
                x += dx[dir];
                l--;
                count++;
            }
            else {
                dir = (dir+1) % 4;
                continue;
            }
            if (memo[y][x][dir] != -1) {
                l = l % (count - memo[y][x][dir]);
            }
            memo[y][x][dir] = count;
        }
        cout << y << " " << x << " " << num2dir[dir] << endl;
    }
    return 0;
}

Measured memory_bytes: 3252
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////
ll N, Z, W;
ll a[10001];
ll dp[5100][3];
ll rec(int cur, bool sente) {
	if (dp[cur][sente] != -1)return dp[cur][sente];
	ll aite = -1;
	if (cur == 0)aite = W;
	else aite = a[cur - 1];
	if (cur == N - 1)return abs(a[N - 1] - aite);
	ll res = -1;
	if (sente) {
		ll Max = abs(aite - a[N - 1]);
		for (int j = cur; j < N - 1; ++j) {
			ll tmp = rec(j + 1, false);
			chmax(Max, tmp);
		}
		res = Max;
	}
	else {
		ll Min = abs(aite - a[N - 1]);
		for (int j = cur; j < N - 1; ++j) {
			ll tmp = rec(j + 1, true);
			chmin(Min, tmp);
		}
		res = Min;
	}
	return dp[cur][sente] = res;
}
int main() {
	cin >> N >> Z >> W;
	REP(i, N)cin >> a[i];
	memset(dp, -1, sizeof(dp));
	cout << rec(0, true) << endl;
	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//







int main(void) {

    ll N, K; cin >> N >> K;
    ll ans = K * pow(K-1, N-1);
    out(ans);

    
    return 0;
}











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

#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
using namespace std;


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<pair<int,int>> a(n);
	rep(i,0,n){
		cin >> a[i].first;
		a[i].second = i+1;
	}
	sort(all(a));
	rep(i,0,n){
		cout << a[i].second << " ";
	}
	cout << endl;
}


Measured memory_bytes: 1664
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    ll a,b;
    cin >> a >> b;
    string _a = "", _b = "";
    ll output;

    rep(i,a) _b.append(to_string(b));
    rep(i,b) _a.append(to_string(a));

    if(a < b) output = stoi(_a);
    else output = stoi(_b);

    cout << output << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int k,s;cin>>k>>s;
    int r=0;
    for(int x=0;x<k+1;x++){
        for(int y=0;y<k+1;y++){
            if(0<=s-x-y && s-x-y<=k){
                r++;
            }
        }
    }
    cout<<r<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll n, q;
    cin >> n >> q;
    vector<pair<int,pii>> xst(n);
    for(int i = 0; i < n; i++){
        cin >> xst[i].second.first >> xst[i].second.second >> xst[i].first;
        xst[i].second.first -= xst[i].first;
        xst[i].second.second -= xst[i].first;
    }
    sort(all(xst));
    set<pii> d;
    for(int i = 0; i < q; i++){
        int dd;
        cin >> dd;
        d.insert({dd, i});
    }
    vector<int> ans(q, -1);

    for(int i = 0; i < n; i++){
        auto it = d.lower_bound({xst[i].second.first, -1});
        while(it != d.end()){
            if(it->first >= xst[i].second.second){break;}
            ans[it->second] = xst[i].first;
            d.erase(it++);
        }
    }
    for(int i = 0; i < q; i++){
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 14336
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n, loc_1, loc_2, s;
vector<ll> pos;
ll ans[111111];
ll fac[111111];
ll invfac[111111];
ll vv[111111];

ll ncr(ll u, ll v)
{
	if(u<v || u<0 || v<0) return 0;
	ll ret=fac[u];
	ret=(ret*invfac[v])%mod;
	ret=(ret*invfac[u-v])%mod;
	return ret;
}

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n; ll i; fac[0]=invfac[0]=1;
	for(i=1 ; i<=n+1 ; i++) fac[i]=(i*fac[i-1])%mod;
	for(i=1 ; i<=n+1 ; i++) invfac[i]=exp(fac[i],mod-2);
	for(i=1 ; i<=n+1 ; i++) cin>>vv[i];
	for(i=1 ; i<=n+1 ; i++) s+=vv[i]; s-=n*(n+1)/2; 
	for(i=1 ; i<=n+1 ; i++) if(vv[i]==s) pos.push_back(i);
	loc_1=pos[0]; loc_2=pos[1];
	for(i=1 ; i<=n+1 ; i++) ans[i]=ncr(n+1,i);
	for(i=0 ; i<=n ; i++) ans[i+1]+=(mod-ncr(loc_1-1+n+1-loc_2,i));
	for(i=1 ; i<=n+1 ; i++) ans[i]%=mod;
	for(i=1 ; i<=n+1 ; i++) cout<<ans[i]<<"\n";
	return 0;
}

// 제출하기 전에 생각햇나요?
// it may be easier/harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

Measured memory_bytes: 4352
// dile a la jardinera que traigo flores
// corner cases // int vs ll // cin vs scanf
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define N 100050
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int n,k,h[N],dp[N];

void go(){
	dp[0] = 0;
	for(int i = 1; i < n; ++i){
		dp[i] = 1e9;
		for(int j = 1; j <= k and (i-j) >= 0; ++j)
			dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
	}
}

int main(){
	
	fastio;
	cin >> n; k = 2;
	FER(i,0,n) cin >> h[i];

	go();

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

	return 0;
}



Measured memory_bytes: 1024
// skip until line 65
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
struct Vec{
    double v[2];
    string to_s(){
        return "("+to_string(v[0])+","+to_string(v[1])+")";
    }
    double& operator[](int t){
        return v[t];
    }
    Vec operator+(Vec t) {
        return {v[0]+t[0],v[1]+t[1]};
    }
    Vec& operator+=(Vec t) {
        v[0]+=t[0];v[1]+=t[1];
        return *this;
    }
    Vec operator-(Vec t) {
        return {v[0]-t[0],v[1]-t[1]};
    }
    Vec& operator-=(Vec t) {
        v[0]-=t[0];v[1]-=t[1];
        return *this;
    }
    Vec operator*(double t) {
        return {v[0]*t,v[1]*t};
    }
    Vec& operator*=(double t) {
        v[0]*=t;v[1]*=t;
        return *this;
    }
    double operator*(Vec t) {
        return v[0]*t[0]+v[1]*t[1];
    }
    Vec operator-(){
        return {-v[0],-v[1]};
    }
    static Vec Z;
};
Vec Vec::Z={0,0};
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
int main() {
    string S,T;
    cin >> S >> T;
    for(int i=0;i<S.size();++i) {
        if (S[i]!=T[i]) {
            cout<<"No"<<endl;
            exit(0);
        }
    }
    cout << "Yes"<<endl;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

template<class T>
T read() {
    T x{};
    cin >> x;
    return x;
}

template<class T>
vector<T> read(int N){
    vector<T> x(N);
    for(int i = 0; i < N; ++i){
        cin >> x[i];
    }
    return x;
}

template<class T>
void write(const T &x){ cout << x << endl; }

template<class Itr>
std::vector<int> Z_Algorithm(Itr itBegin, Itr itEnd)
{
  using namespace std;

  const int len = itEnd - itBegin;
  vector<int> prefix(len);
  const auto s = itBegin;
  for (int i = 1, j = 0; i < len; i++)
  {
    if (i + prefix[i - j] < j + prefix[j])
    {
      prefix[i] = prefix[i - j];
    }
    else
    {
      int k = max(0, j + prefix[j] - i);
      while (i + k < len && s[k] == s[i + k])
      {
        ++k;
      }
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = len;
  return prefix;
}

int main(){
    auto N = read<ll>();
    auto S = read<string>();
    
    vector<vector<ll>> m(256);
    for(ll i = 0; i < N; ++i){
        m[S[i]].push_back(i);
    }
    
    ll ans = 0;
    for(ll i = 0; i < N; ++i){
        auto prefix = Z_Algorithm(S.begin() + i, S.end());
        for(int i = 1; i < (int)prefix.size(); ++i)
        {
            ans = max(ans, (ll)min(i, prefix[i]));
        }
    }
    write(ans);
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n, k;
int main(){
	cin >> n >> k;
	int res = 1, cnt = 0;
	while(res <= n){
		res *= k;
		cnt++;
	}
	if(!cnt) cnt = 1;
	cout << cnt << "\n";
	return 0;
} 

Measured memory_bytes: 256
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();
 
function main(){
  var read = 0;
  var resultCase = 1;
  while(true){
    var maxWeight = +input[read++];
    if(!maxWeight){
      break;
    }
     
    var treasures = +input[read++];
    var pdp = new Int32Array(maxWeight + 1);
    for(var i = treasures; i--;){
      var c = input[read++].split(",");
      var tv = +c[0];
      var tw = +c[1];
 
      var dp = new Int32Array(maxWeight + 1);
      for(var w = 1; w <= maxWeight; w++){
        if(w - tw < 0){
          dp[w] = pdp[w];
        }else{
          dp[w] = max(pdp[w-tw] + tv, pdp[w]);
        }
      }
      pdp = dp;
    }
 
    var resultWeight = 1001;
    var resultCost = 0;
    for(var i = 0; i <= maxWeight; i++){
      if(pdp[i] > resultCost){
        resultCost = pdp[i];
        resultWeight = i;
      }
    }
     
    console.log("Case " + resultCase++ + ":\n" + resultCost + "\n" + resultWeight);
  }
}
 
function max(a, b) {
  var t = a - b;
  return a - (t & (t >> 31));
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    ll N;
    cin >> N;
    ll K;
    cin >> K;
    vector<ll> A(N);
    map<ll, vector<ll>> mp;
    for(ll i = 0; i < N; i++){
        cin >> A[i];
        mp[A[i]].push_back(i);
    }

    vector<ll> ord;

    ord.push_back(0);

    ll tmp_val = A[0];
    ll tmp_ind = 0;
    
    while(true){
      auto itr = lower_bound(mp[tmp_val].begin(), mp[tmp_val].end(), tmp_ind);
      if(distance(mp[tmp_val].begin(), itr) + 1 == mp[tmp_val].size()){
        if( mp[tmp_val].at(0) == (N-1) ) {
          ord.push_back(N-1);
          break;
        }
        ord.push_back(mp[tmp_val].at(0)+1);
        tmp_ind = mp[tmp_val].at(0) + 1;
      }else{
        ll next = mp[tmp_val].at(distance(mp[tmp_val].begin(), itr)+1);
        if(next==N-1) break;
        tmp_ind = next+1;
      }
      tmp_val = A[tmp_ind];
    }

    ll start;
    ll ord_size;
    ord_size = ord.size();
    start = K % ord_size;
    if(start > 0){
        start--;
    }else{
        start = ord.size()-1;
    }

    ll start_ind;
    start_ind = ord[start];

    ll ind;
    ind = start_ind;
    vector<ll> ans;

    while(ind < N){
      tmp_val = A[ind];
      auto itr = lower_bound(mp[tmp_val].begin(), mp[tmp_val].end(), ind);
      if(distance(mp[tmp_val].begin(), itr) + 1 == mp[tmp_val].size()){
        ans.push_back(tmp_val);
        ind++;
      }else{
        ind = mp[tmp_val].at(distance(mp[tmp_val].begin(), itr)+1)+1;
      }
    }

    for(ll i = 0; i < ans.size(); i++){
        cout << ans[i] << " ";
    }
    cout << endl;
    



    return 0;
}



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

int main(){
  int X,Y;
  cin >> X >> Y;
  bool exist = false;
  for(int i = 0; i <= X; i++){
    if(i*2+(X-i)*4 == Y) exist = true;
  }
  if(exist) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3540
// base: http://drken1215.hatenablog.com/entry/2019/09/16/014600

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>
#include <string.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> triple;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll powmod(ll x, ll y) {
  ll r = 1;
  while (y) {
    if (y & 1) {
      r = r * x % MOD;
    }
    x = x * x % MOD;
    y >>= 1;
  }
  return r;
}

// Rolling Hash
struct RollingHash {
  static const int base1 = 1007, base2 = 2009;
  static const int mod1 = 1000000007, mod2 = 1000000009;
  vector<ll> hash1, hash2, power1, power2;

  RollingHash(const string& S) { init(S); }
  void init(const string& S) {
    int n = S.size();
    hash1.resize(n+1);
    hash2.resize(n+1);
    power1.assign(n+1, 1);
    power2.assign(n+1, 1);
    rep(i, n) {
      hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
      hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
      power1[i+1] = (power1[i] * base1) % mod1;
      power2[i+1] = (power2[i] * base2) % mod2;
    }
  }

  // get hash of S[left:right]
  inline pair<ll, ll> get(int l, int r) const {
    ll res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
    if (res1 < 0) res1 += mod1;
    ll res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
    if (res2 < 0) res2 += mod2;
    return {res1, res2};
  }
};

int N;
RollingHash rh("");

bool check(int d) {
  map< pair<ll,ll>, int> ma;
  for (int i = 0; i + d <= N; ++i) {
    auto p = rh.get(i, i + d);
    if (ma.count(p)) {
      if (i - ma[p] >= d) { // no overlap
        return true;
      }
    } else {
      ma[p] = i; // set first i.
    }
  }
  return false;
}

int main(int argc, char** argv) {
  cin >> N;
  string S;
  cin >> S;

  rh.init(S);

  // Find the largest left by binary search.
  int left = 0;
  int right = N/2 + 1;
  while (right - left > 1) {
    int mid = (left + right) / 2;
    if (check(mid)) {
      left = mid;
    } else {
      right = mid;
    }
  }

  cout << left << endl;
}


Measured memory_bytes: 768
#include <iostream>

using namespace std;
/*
1 insertionSort(A, N) // N個の要素を含む0-オリジンの配列A
2   for i が 1 から N-1 まで
3     v = A[i]
4     j = i - 1
5     while j >= 0 かつ A[j] > v
6       A[j+1] = A[j]
7       j--
8     A[j+1] = v
*/
void printArray(int n, int a[]){
  for (int i=0; i<n-1; i++) cout << a[i] << " ";
  cout << a[n-1] << endl;
}

int main(void){
  int n;
  int a[100];
  
  cin >> n;
  for (int i=0; i<n; i++) cin >> a[i];
  printArray(n,a);
  for (int i=1; i<n; i++){
    int j,t = a[i];
    for (j=i; j>0 && a[j-1]>t; j--){
      a[j] = a[j-1];
    }
    a[j] = t;
    // test output
    printArray(n,a);
  }
  return 0;
}



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

int main() {
    ll n;
    std::cin >> n;
    string s;
    std::cin >> s;
    ll ans = 0;
    for (int i = 1; i < n; i++) {
        ll now = 0;
        for (int j = i; j < n; j++) {
            if(s[ j-i ] == s[ j ]){
                now++;
                ans = max(ans,min((ll)i,now));
            }else{
                now = 0;
            }
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

bool ok(int idx, vector<ll> &A, int N) {
	ll cur=0;
	for (int i=0; i<=idx; i++)
		cur+=A[i];
	for (int i=idx+1; i<N; i++) {
		if(cur*2<A[i])
			return false;
		cur+=A[i];
	}
	return true;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; cin>>N;
	vector<ll> A(N);
	for (int i=0; i<N; i++)
		cin>>A[i];
	sort(A.begin(),A.end());
	int low=0, high=N-1;
	while(low<high) {
		int mid=(low+high)/2;
		if(ok(mid,A,N)) high=mid;
		else low=mid+1;
	}
	cout<<N-low<<"\n";
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
using namespace std;
int n, k;
int card[100000];
int main() {
    while (scanf("%d%d",&n,&k)) {
        if (!n&&!k) break;
        for (int i=0; i<k; i++) scanf("%d",&card[i]);
        sort(card, card+k);
        int res=0, cnt=1;
        if (card[0]) {
            for (int i=1; i<k; i++) {
                if (card[i]-card[i-1]==1) cnt++;
                else {
                    res=max(res,cnt);
                    cnt=1;
                }
            }
            printf("%d\n",max(res,cnt));
        } else {
            int flag=1, pos=0;
            for (int i=2; i<k; i++) {
                if (card[i]-card[i-1]==1) {
                    cnt++;
                } else if (flag&&card[i]-card[i-1]==2) {
                    pos=i; flag=0;
                    cnt+=2;
                } else if (card[i]-card[i-1]==2) {
                    res=max(res,cnt);
                    cnt=1; i=pos; flag=1;
                } else {
                    res=max(res,cnt);
                    cnt=1; flag=1;
                }
            }
            printf("%d\n",max(res,cnt));
        }
    }
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/a.in", "r", stdin);
//  freopen("../IO/a.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

void solve(std::istream &in, std::ostream &out) {
  int n;
  in >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; ++i) {
    in >> a[i].first;
    a[i].second = i;
  }
  vector<int64_t> cnt(n, 0);

  sort(a.rbegin(), a.rend());
  int index = n;
  for (int i = 0; i < n; ++i) {
    int j = i;
    while (j + 1 < n && a[i].first == a[j + 1].first) ++j;
    index = min(index, a[j].second);
    int nextval = j == n - 1 ? 0 : a[j + 1].first;
    int cc = j + 1;
    cnt[index] += (int64_t) cc * (a[j].first - nextval);
    i = j;
  }

  for (int64_t i : cnt) out << i << '\n';
}

Measured memory_bytes: 4764
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dl double long
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rrep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); --i)
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;

ll cnt;
int n, a[1000000], l;
vector<int> G;

void insertionsort(int g){
    rep(i, g, n){
        int v = a[i];
        int j = i - g;
        while(j >= 0 && a[j] > v){
            a[j+g] = a[j];
            j -= g;
            cnt++;
        }
        a[j+g] = v;
    }
}

void shellsort(){
    cnt = 0;
    int g = 1;
    do{
        G.push_back(g);
        g = 3 * g + 1;
    }while(g < n);

    for(auto itr = G.rbegin(); itr != G.rend(); itr++){
        insertionsort(*itr);
    }
}

int main(void){
    cin >> n;
    rep(i, 0, n) cin >> a[i];
    shellsort();
    cout << G.size() << endl;
    for(auto itr = G.rbegin(); itr != G.rend(); itr++){
        cout << *itr << ' ';
    }
    cout << endl << cnt << endl;
    rep(i, 0, n) cout << a[i] << endl;
    
    return 0;
}


Measured memory_bytes: 7060
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
typedef long long ll;
#define MAX 200000
#define INFTY 9000000000

int main(){
  ll dp[MAX];
  for(int i=0;i<MAX;i++){
    dp[i]=INFTY;
  }
  ll N;
  cin>>N;
  dp[0]=0;
  for(int i=0;i<N;i++){
    dp[i+1]=min(dp[i+1],dp[i]+1);
    for(int j=6;j+i<=N;j*=6){
      dp[i+j]=min(dp[i+j],dp[i]+1);
    }
    for(int k=9;k+i<=N;k*=9){
      dp[i+k]=min(dp[i+k],dp[i]+1);
    }
  }
  cout<<dp[N]<<endl;


}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
using ll = long long;
int main(){
    vector<ll> a(4);
    for(int i=0;i<4;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    if(a[0]==1&&a[1]==4&&a[2]==7&&a[3]==9){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int min = 0;
		int max = 0;
		long sum = 0;
		int check;
		for (int i = 0; i < n; i++) {
			check = scan.nextInt();
			
			if (min > check || i == 0) {
				min = check;
			}
			if (max < check || i == 0) {
				max = check;
			}
			sum += check;
		}
		System.out.println(min + " " + max + " " + sum);
	}

}

Measured memory_bytes: 40996
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> pt;
#define rep(i,n) for(int i=0;i<n;i++)
int n;
pt z[305];
int check(pt C){
	int ret = 0;
	rep(i,n){
		if(abs(z[i]-C) <= 1.0+1e-12) ret++;
	}
	assert(ret>=2);
	return ret;
}
int main(){
	while(1){
		scanf("%d",&n);
		if(n == 0) return 0;
		rep(i,n){
			double x,y; scanf("%lf%lf",&x,&y);
			z[i] = pt(x,y);
		}
		int ans = 1;
		rep(i,n) for(int j=i+1;j<n;j++){
			if(abs(z[i]-z[j]) > 2.0+1e-12) continue;
			pt mid = (z[i]+z[j])/2.0;
			double leng = sqrt(1.0-abs(z[i]-z[j])*abs(z[i]-z[j])/4.0);
			pt c1 = mid + (z[i]-z[j])/abs(z[i]-z[j]) * polar(leng,3.141592653589/2.0);
			pt c2 = mid - (z[i]-z[j])/abs(z[i]-z[j]) * polar(leng,3.141592653589/2.0);
			ans = max(ans,check(c1));
			ans = max(ans,check(c2));
		}
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  if (A%3==0||B%3==0||(A+B)%3==0) {
    cout << "Possible" << endl;
  }
  else {
    cout << "Impossible" << endl;
  }
}


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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;
void solve(void)
{
    int n;
    cin >> n;
    cout << n / 3 << endl;
}
int main(void)
{
    solve();
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n;
    cin >> n;
    int a[n + 5], b[n + 5];
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    bool can = 0;
    for (int i = 2; i < n; i++) {
        if (a[i - 2] == b[i - 2] && a[i - 1] == b[i - 1] && a[i] == b[i]) {
            cout << "Yes" << endl;
            can = 1;
            break;
        }
    }
    if (!can) {
        cout << "No" << endl;
    }
    return 0;
}





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

int main() {
	int t,n,s,f,i,sum;
	
	while(1){
		cin>>t;
		if(t==0) break;
		cin>>n;
		sum=0;
		for(i=0;i<n;i++) {
			cin>>s>>f;
			sum+=f-s;
		}
		if(sum>=t) cout<<"OK"<<endl;
		else cout<<t-sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include<iostream>
#include<vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)

int main() {
int n;
cin >> n;
vector<int> p(n);
rep(i, n) cin >> p[i];
int k = 0;
rep(i, n) if(p[i] != i + 1) k++;
if(k <= 2) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
  

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    ll x; cin >> x;
    ll ans = 0;
    ans += (x / 500) * 1000; x %= 500;
    ans += (x / 5) * 5; x %= 5;
    cout << ans << endl;
}

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

int main() {
    string s;
    cin >> s;
    int ans = 1;
    int last = 1;
    for(int i = 1; i < s.size(); i++) {
        if(s[i] != s[i-1] or last == 2) last = 1, ans++;
        else {
            if(i == s.size()-1) break;
            i++;
            ans++;
            last = 2;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
import sys

def resolve():
    A, B = list(map(int, input().split(" ")))
    cnt = 0
    for i in range(A, B+1):
        s = str(i)
        if s[0] == s[4] and s[1] == s[3]:
            cnt += 1
    print(cnt)

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 39024
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, m;
	cin >> n >> m;

	vector<string> canvas(n);
	for (int i = 0; i < n; ++i) {
		canvas[i] = string(m, '.');
	}

	vector<string> grid(n);
	for (int i = 0; i < n; ++i) {
		cin >> grid[i];
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (j < m - 1 && grid[i][j] == '#' && grid[i][j + 1] == '#') {
				canvas[i][j] = '#';
				canvas[i][j + 1] = '#';
			}
			if (i < n - 1 && grid[i][j] == '#' && grid[i + 1][j] == '#') {
				canvas[i][j] = '#';
				canvas[i + 1][j] = '#';	
			}
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (grid[i][j] != canvas[i][j]) {
				cout << "No\n";
				return 0;
			}
		}
	}

	cout << "Yes\n";

	return 0;

}

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

const int MOD = 1000000007;
const int INF = 1e9;

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

  long long sum = 0;
  for(int i = 1; i < n; i++){
    sum += i;
  }
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 3672
N,A,B,C,D = map(int, input().split())
s = input()
index = [(n+1) for n, v in enumerate(s) if s[n:n+3] == "..."]

if C < D:
    if "##" in s[A-1:D]:
        print("No")
    else:
        print("Yes")

if C > D:
    if "##" in s[A-1:C]:
        print("No")
    else:
        if len(index)>=1:
            for i in index:
                if B <= i+1 <= D:
                    print("Yes")
                    exit()
            print("No")
        else:
            print("No")


Measured memory_bytes: 3572
// unihernandez22
// https://atcoder.jp/contests/abc076/tasks/abc076_c
// string manipulation

import std.stdio;
import std.string;
void main() {
	string s = readln.chomp;
	string t = readln.chomp;

	long idx = -1;
	bool matched;
	for(long i = (s.count-t.count); i >= 0; i--) {
		if (s[i] == '?' || s[i] == t[0]) {
		matched = true;
		foreach(j; 0..t.count) {
			if (s[i+j] != '?' && s[i+j] != t[j]) {
				matched = false;
				break;
			}
		}
		if (matched) {
			idx = i;
			break;
		}
		}
	}
	if (idx == -1) {
		writeln("UNRESTORABLE");
		return;
	}
	foreach(i; 0..s.count) {
		if (s[i] == '?' && (i < idx || i >= t.count+idx))
			write("a");
		else if (s[i] == '?')
			write(t[i-idx]);
		else
			write(s[i]);
	} writeln;
}


Measured memory_bytes: 3184