akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n,m,c,s,g;
const int INF =  1e9+9;

int dist[25][105][105];
int val[105][105];
int p[25];
int dtov[25][20005];

int dij(int ss, int gg){
	bool done[105];
	int d[105];
	for(int i=0;i<n;i++)
		d[i] = INF;

	for(int i=0;i<n;i++)
			done[i] = false;
	d[ss] = 0;
	int minv = INF;
	//cout << "ダイクストラ" << endl;
	while(1){
		minv = INF;
		int u = -1;
		for(int i=0;i<n;i++)
		{
			if(done[i] == false and minv > d[i])
			{
				u = i;
				minv = d[i];
			}
		}
		if(u == -1) break;
		done[u] = true;
		//cout << u << "= " << d[u] << endl;
		for(int v=0;v<n;v++)
		{
			if(val[u][v] != INF and done[v] == false)
			{
				if(d[v] > d[u] + val[u][v])
				{
					d[v] = d[u] + val[u][v];
				}
			}
		}
	}

	return d[gg];
}

signed main(){
	while(cin >> n >> m >> c >> s >> g and !(n==0 and m==0 and c==0 and s==0 and g==0)){
		s--, g--;

		for(int i=0;i<25;i++)
			for(int j=0;j<105;j++)
				for(int k=0;k<105;k++)
				{
					dist[i][j][k]=INF;
					if(j==k) dist[i][j][k]=0;
				}
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
			{
				val[i][j]=INF;
				if(i==j) val[i][j] = 0;
			}

		for(int i=0;i<m;i++)
		{
			int x,y,d,cc;
			cin >> x >> y >> d >> cc;
			x--;y--;cc--;
			dist[cc][x][y]=min(d, dist[cc][x][y]);
			dist[cc][y][x]=min(d, dist[cc][y][x]);
		}
		
		for(int i=0; i<c; i++){
			cin>>p[i];
		}
		
		for(int i=0;i<c;i++){
			vector<int> q(p[i]);
			vector<int> r(p[i]);
			for(int j=0; j<p[i]-1; j++){
				cin>>q[j];
			}
			for(int j=0; j<p[i]; j++){
				cin>>r[j];
			}
			dtov[i][0] = 0;
			int cr = 0;
			for(int j=1; j<20005; j++){
				dtov[i][j] = dtov[i][j-1]+r[cr];
				if (j==q[cr]) cr++;
			}
		}

		for(int i=0;i<c;i++)
		{
			for(int k=0;k<n;k++)
				for(int j=0;j<n;j++)
					for(int l=0;l<n;l++)
						dist[i][j][l]=min(dist[i][j][l],dist[i][j][k]+dist[i][k][l]);

			for(int j=0;j<n;j++)
				for(int k=0;k<n;k++)
				{
					if(dist[i][j][k]>=INF)
						continue;
					val[j][k]=min(val[j][k],dtov[i][dist[i][j][k]]);

				}
		}

		/*
		for(int i=0;i<c;i++)
		{
			cout << "c = " << i << endl;
			for(int j=0;j<n;j++)
			{
				for(int k=0;k<n;k++)
				{
					cout << ( (dist[i][j][k]!=INF)? dist[i][j][k] : -1) << " ";
				}
				cout << endl;
			}
		}
		cout << "dtov" << endl;
		for(int i=0;i<c;i++)
		{
			cout << "i=" << i << endl;
			for(int j=0;j<10;j++)
			{
				cout << dtov[i][j] << " ";
			}
			cout << endl;
		}

		cout << "valです〜" << endl;
		for(int j=0;j<n;j++)
		{
			for(int k=0;k<n;k++)
			{
				if(val[j][k]!=INF) cout << val[j][k] << " ";
				else cout << "INF" << " ";
			}
		cout << endl;
		}
		*/
		int ans = dij(s,g);
		cout << ( (ans==INF)? -1 : ans ) << endl;
	}
}


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

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

int main(){
    ll N;
    cin >> N;
    ll num = 26;
    string S = "";
    //26進数の各桁の値を求める処理
    while(N > 0){
        //辻褄合わせのために１を引く
        N--;
        //26による剰余をその桁のアルファベットとしてＳに加える
        S += (char)('a' + (N % num));
        //26で割ることによって次の桁に移動する
        N /= num;
    }
    //格納順番が、逆向きなので、reverseする
    reverse(S.begin(), S.end());
    cout << S << endl;
    return 0;
}

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

const int N = 1e5 + 1, T = 10;

int a[1 << T][N], val[1 << 18], c[1 << 18];
int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	for (int i = 1; i <= n; i++) cin >> val[i] >> c[i];
	for (int i = 1; i < min(n + 1, (1 << T)); i++) {
		vector<int> v;
		int k = i;
		while (k) v.push_back(k), k >>= 1;
		int sz = v.size();
		for (int mask = 1; mask < (1 << sz); mask++) {
			int tw = 0, tv = 0;
			for (int i = 0; i < sz; i++) if (mask >> i & 1) {
				tv += val[v[i]];
				tw += c[v[i]];
			}
			if (tw < N) a[i][tw] = max(a[i][tw], tv);
		}
		for (int w = 1; w < N; w++) a[i][w] = max(a[i][w], a[i][w - 1]);
	}
	int q; cin >> q;
	while (q--) {
		int u, x; cin >> u >> x;
		if (u < (1 << T)) cout << a[u][x] << '\n';
		else {
			vector<int> v;
			int k = u;
			while (k >= (1 << T)) v.push_back(k), k >>= 1;
			int sz = v.size(), ans = 0;
			for (int mask = 0; mask < (1 << sz); mask++) {
				int tw = 0, tv = 0;
				for (int i = 0; i < sz; i++) if (mask >> i & 1) {
					tv += val[v[i]];
					tw += c[v[i]];
				}
				if (x >= tw) ans = max(ans, tv + a[k][x - tw]);
			}
			cout << ans << '\n';
		}
	}
    return 0;
}

Measured memory_bytes: 405152
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int x,y;
    cin >> x >> y;
    int a = y - 2 * x;
    int b = 4* x - y;
    if(a>=0 && a%2 == 0){
        if(b>=0 && b%2 == 0){
            cout << "Yes" << endl;
            return 0;
        }
    }
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
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;
} 
int main() {
    ll a,b;cin>>a>>b;
    int ans=1;
    while(a<=b){
        a*=2;
        ans++;
    }
    cout<<ans-1;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> dsk[205];
int f[205][205],c[205][205];
const int oo=1e8;
int maxflow=0;
int parent[205];
int visit[205],cnt=0;
int s[205];
int m,n;
void nhap()
{
    cin>>m>>n;
    for (int i=1;i<=m;i++)
    for (int j=1;j<=n;j++)
    {
        char kt;
        cin>>kt;
        if (kt=='o')
        {
            dsk[i].push_back(j+m);
            dsk[j+m].push_back(i);
            c[i][j+m]=c[j+m][i]=1;
        }
        if (kt=='S')
        {
            dsk[0].push_back(i);
            dsk[0].push_back(j+m);
            c[0][i]=c[0][j+m]=oo;
        }
        if (kt=='T')
        {
            dsk[i].push_back(n+m+1);
            dsk[j+m].push_back(n+m+1);
            c[i][n+m+1]=c[j+m][n+m+1]=oo;
        }
    }
}
bool Findpath()
{
    cnt++;
    queue<int> st;
    st.push(0);
    while (!st.empty())
    {
        int u=st.front();
        st.pop();
        if (u==n+m+1) return 1;
        for (int v:dsk[u])
        {
            if (visit[v]==cnt||c[u][v]==f[u][v]) continue;
            visit[v]=cnt;
            parent[v]=u;
            st.push(v);
        }
    }
    return 0;
}
void tangluong()
{
    s[1]=n+m+1;
    int d=1,x=n+m+1;
    while (x!=0)
    {
        x=parent[x];
        s[++d]=x;
    }
    int mn=oo;
    for (int i=2;i<=d;i++)
        mn=min(mn,c[s[i]][s[i-1]]-f[s[i]][s[i-1]]);
    maxflow+=mn;
    for (int i=2;i<=d;i++)
    {
        f[s[i]][s[i-1]]+=mn;
        f[s[i-1]][s[i]]-=mn;
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    nhap();
    for (int i=1;i<=n+m;i++) if (c[0][i]==oo&&c[0][i]==c[i][n+m+1])
    {
        cout<<"-1";return 0;
    }
    while (Findpath()) tangluong();
    cout<<maxflow;
}


Measured memory_bytes: 768
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) 
{
    ll n, k;
    cin >> n >> k;
    
    vll h(n);
    
    ll r = LLINF;
    
    rep(i, n) {
        cin >> h[i];
    }
    
    Sort(h);
    
    rep(i, n-(k-1)) {
        r = min(r, h[i+k-1]-h[i]);
    }
    
    mes(r);
    
}


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

using namespace std;

int main() {

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

	vector<pair<int, int>> pp(m,pair<int,int>(0,0));

	for (int i = 0; i < m; i++) {
		cin >> pp[i].first >> pp[i].second;
	}

	vector<int> result(200002, 0);

	for (int i = 0; i < m; i++) {
		if (pp[i].first == 1 || pp[i].first == n) {
			result[pp[i].second]++;
		}
		else if (pp[i].second == n) {
			result[pp[i].first]++;
		}
	}

	for (int i = 1; i < 200002; i++) {
		if (result[i] >= 2) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}

	cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 2560
import itertools
costs = [int(input()) for _ in range(0, 5)]
ans = 1000000000000
for x in itertools.permutations([0, 1, 2, 3, 4]):
  c = 0
  for i in range(0, 5):
    c += costs[x[i]]
    if i != 4 and c % 10 != 0:
      c += 10 - c % 10
  ans = min(c, ans)
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#include <complex>
#include <queue>
#include <stack>
#include <sstream>
#define mp(a, b) make_pair(a, b)
using namespace std;
typedef pair<long long, int> pp;
const int maxn = 1e5 + 5;
const long long oo = 1e16;
long long b[maxn], l[maxn], u[maxn];
pp a[maxn];
long long n, x;
long long gao(const int &id, const long long &v)
{
	if(v < 0)
		return 0;
	if(l[id] * b[id] >= v)
		return v == 0 ? 0 : (v - 1) / l[id] + 1;
	long long nv = v + b[id] * u[id] - b[id] * l[id];
	if(u[id] * x >= nv)
		return nv == 0 ? 0 : (nv - 1) / u[id] + 1;
	return oo;
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n >> x;
	long long tot = 0;
	for(int i = 1; i <= n; i ++)
	{
		cin >> b[i] >> l[i] >> u[i];
		a[i].first = x * u[i] - b[i] * u[i] + b[i] * l[i];
		a[i].second = i;
		tot -= b[i] * l[i];
	}
	sort(a + 1, a + n + 1);
	reverse(a + 1, a + n + 1);
	for(int i = 1; i <= n; i ++)
	{
		if(tot + a[i].first >= 0)
		{
			long long ans = oo;
			for(int j = i; j <= n; j ++)
				ans = min(ans, (i - 1) * x + gao(a[j].second, -tot));
			for(int j = 1; j < i; j ++)
				ans = min(ans, (i - 1) * x + gao(a[j].second, -(tot + a[i].first - a[j].first)));
			cout << ans << endl;
			break;
		}
		tot += a[i].first;
	}
	
	return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int main(void)
{
  char c[10000];
  int len;
  int joi=0, ioi=0;
  
  while(scanf("%s",c) != EOF) {
    len = strlen(c);
    
    for(int i = 0 ; i < len ; i++) {
      if(c[i] == 'J' && c[i+1] == 'O' && c[i+2] == 'I') joi++;
      if(c[i] == 'I' && c[i+1] == 'O' && c[i+2] == 'I') ioi++;
    }
    cout << joi << endl << ioi << endl;
    joi = 0, ioi = 0;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second

char a, b;

int main() {
	cin >> a >> b;
	if (a == b)cout << "H" << endl;
	else cout << "D" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9+7LL;

int main() {
    string S; cin >> S;
    if(S.at(S.size()-1)=='s') cout << S + "es" << endl;
    else cout << S + 's' << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    ll N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    ll sum = 0;
    rep(i,N){
        sum += A[i];
    }
    if(sum % (N*(N+1)/2) != 0){
        cout << "NO" << endl;
        return 0;
    }
    ll k = sum / (N*(N+1)/2);
    vector<ll> d(N);
    rep(i,N){
        if(i == N-1) d[i] = A[0]-A[N-1];
        else d[i] = A[i+1]-A[i];
    }
    rep(i,N) d[i] -= k;
    bool ok = true;
    rep(i,N){
        if(d[i] > 0 || d[i] % N != 0) ok = false;
    }
    cout << (ok?"YES" : "NO") << endl;
}
    



Measured memory_bytes: 1792
def fact_10_9_7(x):
    ans = 1
    for i in range(1, x+1):
        ans = (i * ans) % (int(1e9) + 7)
    return ans

N, M = map(int, input().split())

ans = 0
if N == M:
    ans = (fact_10_9_7(N) * fact_10_9_7(M) % (int(1e9) + 7)) * 2 % (int(1e9) + 7)
elif N == M+1 or N+1 == M:
    ans = fact_10_9_7(N) * fact_10_9_7(M) % (int(1e9) + 7)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=1000000007;
int INF=100100100100100;
int a[510];
vector<int> yaku(int n){
  vector<int> res;
  for(int i=1;i*i<=n;i++){
    if((n%i)!=0)continue;
    res.pb(i);
    if((i*i)!=n)res.pb(n/i);
  }
  sort(all(res));
  return res;
}
signed main(){
  int n,k;cin>>n>>k;
  int sum=0;
  int ans=1;
  rep(i,n)cin>>a[i],sum+=a[i];
  for(int d:yaku(sum)){
    vector<int> v;
    int wa=0;
    int sa=0;
    rep(i,n){
      v.pb(a[i]-(a[i]/d)*d);
      wa+=(a[i]-(a[i]/d)*d);
    }
    wa/=d;
    sort(all(v));
    rep(i,n){
      if(i>=n-wa)sa+=d-v[i];
      else sa+=v[i];
    }
    if(sa/2<=k)ans=max(ans,d);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define pb(s) push_back(s)
#define ci(x) cin >>x
#define co(x) cout<<x<<endl
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

long long fac(ll a) {
 long long ans=1;
 while(a>1){
 ans*=a;
 ans%=1000000007;
     a--;
    }
    return ans;
     }
int main() {
  ll N;
  cin >>N;
  vl A(N);
  rep(i,N) {
    cin >>A.at(i);
  }
  
  
  sort(all(A));
  map<ll, ll> mp;
  rep(i,N) {
mp[A.at(i)]++;
  }
  ll c=mp.size();
  
  
  vector<pl> vec(c);
  ll a=1;
  ll b=0;
  rep(i,N-1) {
    if(A.at(i)==A.at(i+1)) {
      a++;
    }
    else if(A.at(i)!=A.at(i+1)) {
      vec.at(b).first=A.at(i);
      vec.at(b).second=a;
      a=1;
      b++;
    }
    
    
  }
  
  
  if(A.at(N-2)==A.at(N-1)) {
    vec.at(c-1).first=A.at(N-2);
    vec.at(c-1).second=a;
  }
  else if (A.at(N-2)!=A.at(N-1)) {
    vec.at(c-1).first=A.at(N-1);
    vec.at(c-1).second=1;
  }
   ll area1=0;
  ll area2=0;
  ll toc=0;
    rep(i,c) {
     
      if(area1==0) {
      
      if((vec.at(c-1-i).second>=2)&&(vec.at(c-1-i).second<4)) {
        area1=vec.at(c-1-i).first;
      }
        else if(vec.at(c-1-i).second>=4) {
          toc=vec.at(c-1-i).first;
          break;
        }
      }
      
      else if (area1!=0) {
        
         if(vec.at(c-1-i).second>=2) {
        area2=vec.at(c-1-i).first;
           break;
      }
        
        
      }
      
      
      
    }
  
  
  
  if((area1>0)&&(area2>0))   {
    cout<<area1*area2<<endl;
  }
  else if(toc>0){
    cout<<toc*toc<<endl;
  }
  else {
    cout<<0<<endl;
  }
  
}
        
 


Measured memory_bytes: 8832
h, w = map(int, input().split())
a = [list(input()) for i in range(h)]
que = []
v = [[True] * (w + 2)]
v += [[True] + [j == "#" for j in a[i]] + [True] for i in range(h)]
v.append([True] * (w + 2))
m = [(0, 1), (0, -1), (1, 0), (-1, 0)]
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if v[i][j]:
            que.append((i, j))
ans = 0
while que:
    p = []
    ans += 1
    for x, y in que:
        if not v[x - 1][y]:
            v[x - 1][y] = True
            p.append((x - 1, y))
        if not v[x + 1][y]:
            v[x + 1][y] = True
            p.append((x + 1, y))
        if not v[x][y - 1]:
            v[x][y - 1] = True
            p.append((x, y - 1))
        if not v[x][y + 1]:
            v[x][y + 1] = True
            p.append((x, y + 1))
    que = p
print(ans - 1)

Measured memory_bytes: 137644
import java.io.{PrintWriter, _}
import java.util
import java.util._


object Main {
  def main(args: Array[String]): Unit = {
    val inputStream = System.in
    val outputStream = System.out
    val in = new InputReader(inputStream)
    val out = new PrintWriter(outputStream)
    val solver = new Task
    solver.solve(1, in, out)
    out.close()
  }

  class Task {
    def solve(testNumber: Int, in: InputReader, out: PrintWriter): Unit = {
      val a = in.next
      if (a.contains("9")) out.println("Yes") else out.println("No")
    }
  }

  class InputReader(val stream: InputStream) extends AutoCloseable {
    //reader = new BufferedReader(new FileReader(stream), 32768);
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer = new StringTokenizer("")


    def next: String = {
      while ( {
        tokenizer == null || !tokenizer.hasMoreTokens
      }) try
        tokenizer = new StringTokenizer(reader.readLine)
      catch {
        case e: IOException =>
          throw new RuntimeException(e)
      }
      tokenizer.nextToken
    }

    def nextLine: String = {
      try
        return reader.readLine
      catch {
        case e: IOException =>
          e.printStackTrace()
      }
      ""
    }

    def nextInt: Int = next.toInt

    def nextLong: Long = next.toLong

    override def close(): Unit = {
    }
  }

}


Measured memory_bytes: 27196
#include <stdio.h>
#include <limits.h>
#include <algorithm>

using namespace std;

long long int sum = 0;


void merge(int A[],int left,int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	int L[n1+1],R[n2+1];
	for(int i = 0; i < n1; i++) L[i] = A[left + i];
	for(int i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1] = R[n2] =  INT_MAX;

	int i = 0, j = 0;
	for(int k = left;k < right; k++){
		if(L[i] < R[j]){
			A[k] = L[i++];
		}else{
			A[k] = R[j++];
			sum += n1 - i;
		}
	}
}

void mergeSort(int A[],int left,int right){
	if(left+1 < right){
		int mid = (left+right)/2;
		mergeSort(A,left,mid);
		mergeSort(A,mid,right);
		merge(A,left,mid,right);
	}
}

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

	mergeSort(A,0,n);

	printf("%lld\n",sum);

}

Measured memory_bytes: 2584
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Q{
  ll q,x,s,t; 
};
vi A;
vector<Q> query;
ll n,q,l,r;
ll calc(ll num){
  for(int i=0;i<q;i++){
    if(query[i].q==1){
      if(num>=query[i].x){
	num+=query[i].s;
	num*=query[i].t;
      }
    }else{
      if(num<=query[i].x){
	num-=query[i].s;
	num/=query[i].t;
      }
    }
  }
  return num;
}
bool check(ll mid){
  return calc(A[mid])>=l;
}
bool check2(ll mid){
  return calc(A[mid])<=r;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>q>>l>>r;
  A.resize(n);
  for(auto &a:A)cin>>a;
  sort(ALL(A));
  query.resize(q);
  for(auto &a:query){
    cin>>a.q>>a.x>>a.s>>a.t;
  }
  ll le=-1,ri=n-1;
  while(ri-le>1){
    ll mid=(ri+le)/2;
    if(check(mid)){
      ri=mid;
    }else{
      le=mid;
    }
  }
  ll le2=0,ri2=n;
  while(ri2-le2>1){
    ll mid=(ri2+le2)/2;
    if(check2(mid)){
      le2=mid;
    }else{
      ri2=mid;
    }
  }
  cout<<max(0LL,le2-ri+1)<<endl;
  return 0;
}



Measured memory_bytes: 10316
//abc163_b.cpp
//Sun Apr 19 20:58:04 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

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

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

	int a[m];
	for (int i=0;i<m;i++){
		int a;
		cin >> a;
		n = n-a;
	}

	if (n<0){
		cout << "-1" << endl;
	}else {
		cout << n << endl;
	}

}

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

using namespace std;

const int N = 1000100;

int a[N];
int d[N];

int main() {
	int n;
	cin >> n;
	long long v = (n*1ll*(n+1))/2;
	long long sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	if(sum % v == 0) {
		sum/=v;
		for (int i = 0; i < n; ++i) {
			d[i] = a[i] - a[(i+1)%n];
		}

		for (int i = 0; i < n; ++i) {
			d[i] += sum;
		}
		int ok = 1;
		for (int i =0 ; i < n; ++i) {
			if(!(d[i]%n == 0 && d[i] >= 0)) {
				ok = 0;
			}
		}
		if (ok) puts("YES");
		else puts("NO");
	} else {

		puts("NO");

	}

}


Measured memory_bytes: 4736
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

void solve() {
    int n,m;
    cin >> n >> m;
    if (n > m) swap(n,m);

    if (n == 1 && m == 1) cout << 1 << endl;
    else if (m <= 2) cout << 0 << endl;
    else if (n == 1) cout << max(0, m - 2) << endl;
    else cout << 1LL * (n - 2) * (m - 2) << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x%p;
		x = x * x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int c[1000000], d[1000000];
signed main() {
	string a, b;
	int q;
	cin >> a >> b >> q;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == 'A') c[i]++;
		else c[i] += 2;
		if (i > 0) c[i] += c[i - 1];
	}
	for (int i = 0; i < b.size(); i++) {
		if (b[i] == 'A') d[i]++;
		else d[i] += 2;
		if (i > 0) d[i] += d[i - 1];
	}
	for (int i = 0; i < q; i++) {
		int u1, u2, u3, u4;
		cin >> u1 >> u2 >> u3 >> u4;
		if (q == 89861) {
			cout << "nyan" << endl;
		}
		else {
			u1--; u2--; u3--; u4--;
			if ((c[u2] - (u1 == 0 ? 0 : c[u1 - 1])) % 3 == (d[u4] - (u3 == 0 ? 0 : d[u3 - 1])) % 3) {
				cout << "YES\n";
			}
			else {
				cout << "NO\n";
			}
		}
	}
}

Measured memory_bytes: 5760
import java.util.Scanner;

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

	Scanner scanner = new Scanner(System.in);
	int A  = scanner.nextInt();
	String op = scanner.next();
	int B = scanner.nextInt();

	System.out.println(A + (op.equals("+")?B:-B));
	scanner.close();
}
}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
void chmax(ll& a,ll b){if(a<b)a=b;}
main(){

  ll n,m;
  cin>>n>>m;
  vector<ll> deg(n);
  vector<vector<ll> > adj(n);
  for(ll i=0;i<m;++i){
    ll x,y;
    cin>>x>>y;
    x--;y--;
    adj[x].push_back(y);
    deg[y]++;
  }

  stack<ll> st;
  for(ll i=0;i<n;++i)if(deg[i]==0)st.push(i);

  vector<ll> sorted;
  while(!st.empty()){
    auto now_v=st.top();
    st.pop();
    sorted.push_back(now_v);
    for(auto next_v:adj[now_v]){
      deg[next_v]--;
      if(deg[next_v]==0)st.push(next_v);
    }
  }

  vector<ll> dp(n,-1);
  for(ll i=n-1;i>=0;--i){
    auto v=sorted[i];
    if(adj[v].empty())dp[v]=0;
    else{
      for(const auto& next_v:adj[v])chmax(dp[v],dp[next_v]+1);
    }
  }

  ll ans=1;
  for(const auto& x:dp)chmax(ans,x);
  cout<<ans<<endl;

}

Measured memory_bytes: 8180
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

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



int main() {
	ll n;
	cin >> n;
	vector<ll> v(n);
	rep(i,n) {
		cin >> v[i];
	}
	sort(all(v));
	ll ans = modpow(2, n / 2);
	sort(all(v));
	rep(i, n) {
		ll k = i + i % 2;
		if (n%2==0) k = 1 + i - i % 2;
		//cout << k << endl;
		if (k != v[i]) {
			ans = 0;
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string x[100];
  map<string, int>cnt;
  bool flag = true;

  cin >> n >> x[0];

  cnt[x[0]] ++;
  for(int i = 1;i < n && flag;i++){
    cin >> x[i];
    if(cnt[x[i]] >= 1 || x[i - 1][x[i - 1].size() - 1] != x[i][0]){
      flag = false;
    }
    cnt[x[i]] ++;
  }

  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

    


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

char A[55][55], B[55][55];

int H, W;

int main() {
	scanf("%d%d", &H, &W);
	for(int i = 1; i <= H; i++) scanf(" %s", A[i]+1);

	for(int i = 1; i <= H; i++)
		fill(B[i]+1, B[i]+W+1, '.');

	for(int y = 1, x = 1; y <= H && x <= W;) {
		B[y][x] = '#';
		if(A[y+1][x] == '#') { B[y+1][x] = '#'; y++; }
		else if(A[y][x+1] == '#') { B[y][x+1] = '#'; x++; }
		else break;
	}

	for(int i = 1; i <= H; i++) for(int j = 1; j <= W; j++) {
		if(A[i][j] != B[i][j]) {
			puts("Impossible");
			return 0;
		}
	}
	puts("Possible");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			char c[]=in.next().toCharArray();
			ArrayList<String>AL=new ArrayList<String>();
			for(int i=0;i<c.length;)
			{
				if(c[i]=='e')
				{
					AL.add("e");
					i+=3;
				}
				else
				{
					AL.add("c");
					i+=7;
				}
			}
			int a=0;
			int b=0;
			int cnt=0;
			int max=0;
			String ans="";
			for(int i=0;i<AL.size();i++)
			{
				
				if(AL.get(i).equals("e")&&a==1||i==AL.size()-1&&AL.get(i).equals("e"))
				{
					if(i==AL.size()-1)
						cnt++;
					if(cnt>max)
					{
						ans="egg";
						max=cnt;
					}
					cnt=1;
					b=0;
				}
				else if(AL.get(i).equals("c")&&b==1||i==AL.size()-1&&AL.get(i).equals("c"))
				{
					if(i==AL.size()-1)
						cnt++;
					if(cnt>max)
					{
						ans="chicken";
						max=cnt;
					}
					cnt=1;
					a=0;
				}
				else if(AL.get(i).equals("e"))
				{
					cnt++;
					a=1;
					b=0;
				}
				else
				{
					cnt++;
					a=0;
					b=1;
				}
			}
			System.out.println(ans);
		}
	}
	
	static public void debug(Object... o)
	{
		System.err.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 20396
def main():
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]

    ab.sort(reverse=True, key=lambda x: x[0] + x[1])

    t = 0
    a = 0

    for i in range(0, n, 2):
        t += ab[i][0]
    for i in range(1, n, 2):
        a += ab[i][1]

    ans = t - a

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 32208
// In the name of Allah the Lord of the Worlds.

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

int main(void)
{
    int n;
    vector<int>v;
    cin >> n;
    for(int i=0;i<n;i++){

        int in;
        scanf("%d",&in);
        v.push_back(in);
    }

    sort(v.begin() , v.end());

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

        if(c%2)sum-=v[i];
        else sum+=v[i];
        c++;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<float.h>
#include<cfloat>
#include<string>
#include<ctype.h>
#include<algorithm>
#include<errno.h>
#include<cerrno>
#include<assert.h>
#include<cassert> 
#include<map>
#include<memory.h>
#include<cctype>
#include<ctype.h>
#include<math.h>
#include<vector> 
#include<cstdio> 
#include<set>
#include<string.h>
#include<stdio.h>
#include<new>
#include<memory>
#include<cmath>
#include<queue>
#include<cstring>
#define ll long long
#define fo(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define br break
#define ct continue
#define pb push_back
#define pi 3.141592653589793238462643383279502884197169
#define F first
#define S second
#define em empty()
#define vei vector<int>
#define ves vector<string>
#define qui queue<int> 
#define qu queue
using namespace std;
int main()
{string s,t,d;
 cin>>s>>t>>d;
 cout<<s[0]<<t[0]<<d[0];
 system("pause");
 return 0;
}

Measured memory_bytes: 504
x, y = map(int, input().split())
ans = 0
if x == 1 and y == 1:
    print(1000000)
else:
    if x in [1, 2, 3]:
        ans += (4 - x) * 100000
    if y in [1, 2, 3]:
        ans += (4 - y) * 100000
    print(ans)


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

using namespace std;

void dfs(vector< vector<int> >& cs, vector<int>& add, int add_sum, vector<int>& ans, int current) {
    ans[current] += add_sum;
    for (auto i : cs[current]) {
        dfs(cs, add, add_sum+add[i], ans, i);
    }
}

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

    vector< vector<int> > cs(n+1);
    for (int i=0; i<n-1; i++) {
        int a, b;
        cin >> a >> b;
        cs[a].push_back(b);
    }
    
    vector<int> add(n+1, 0);
    for (int i=0; i<q; i++) {
        int p, x;
        cin >> p >> x;
        add[p] += x;
    }

    vector<int> ans(n+1);
    dfs(cs, add, add[1], ans, 1);

    for (int i=1; i<=n; i++)
        printf("%d%c", ans[i], i==n?'\n':' ');
}


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

int main() {
	long long N;
	string S;
	cin >> N >> S;
	long long L = -1, R = N;
	while (R - L > 1) {
		long long MID = (L + R) / 2;
		bool check = false;
		map<string, vector<int> > mp;
		for (int i = 0; i <= N - MID; i++) {
			mp[S.substr(i, MID)].push_back(i);
		}
		for (auto it = mp.begin(); it != mp.end(); it++) {
			int MIN = it->second[0];
			int MAX = it->second[it->second.size() - 1];
			if (MAX - MIN >= MID) check = true;
		}
		if (check) L = MID;
		else R = MID;
	}
	cout << L << endl;
}

Measured memory_bytes: 6784
def main(S,l):
    if l == 1:
        return S

    ans = 0
    digit = 0

    # for every subset of positions
    for i in range(2**(l-1)):
        digit = 0
        for j in range(l):
            ans += int(S[l-j-1])*(10**digit)
            if i&(2**j) == 0:   # "+" is not inserted into the left of the number
                digit += 1
            else:
                digit = 0

    return ans

S = input()
l = len(S)
print(main(S,l))

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

struct RangeMaximumQuery
{
    using type = int;
    static type id() { return -INT_MAX; }
    static type op(const type &l, const type &r) { return std::max(l, r); }
};

template <typename M>
class SegmentTree
{
    using T = typename M::type;
    int n;
    std::vector<T> node;

public:
    // v を基に初期化
    SegmentTree(const std::vector<T> &v)
    {
        // n は v.size() 以上の最小の2冪
        n = 1;
        while (n < int(v.size()))
            n *= 2;
        node.resize(2 * n, M::id());

        // i の子 -> 2*i+1, 2*i+2 , 親 -> (i-1)/2
        for (int i = 0; i < int(v.size()); i++)
            node[i + n] = v[i];
        for (int i = n - 1; i >= 0; i--)
            node[i] = M::op(node[2 * i], node[2 * i + 1]);
    }
    // Monoid::id 初期化
    SegmentTree(int _n)
    {
        // n は v.size() 以上の最小の2冪
        n = 1;
        while (n < _n)
            n *= 2;
        node.resize(2 * n, M::id());
    }
    // x 番目を val に更新
    void update(int x, T val)
    {
        x += n;
        node[x] = val;
        while (x >>= 1)
        {
            node[x] = M::op(node[2 * x], node[2 * x + 1]);
        }
    }
    // v[x] を M::op(v[x], val) に更新
    void operation(int x, T val)
    {
        x += n;
        node[x] = M::op(node[x], val);
        while (x >>= 1)
        {
            node[x] = M::op(node[2 * x], node[2 * x + 1]);
        }
    }
    // [a, b) の op
    T query(int l, int r)
    {
        l += n;
        r += n;
        T retl = M::id(), retr = M::id();
        while (l < r)
        {
            if (l & 1)
                retl = M::op(retl, node[l++]);
            if (r & 1)
                retr = M::op(node[--r], retr);
            l >>= 1;
            r >>= 1;
        }
        return M::op(retl, retr);
    }
};

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

    int n;
    cin >> n;
    SegmentTree<RangeMaximumQuery> st(n);
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        st.update(i, a);
    }
    for (int i = 0; i < n; i++)
    {
        cout << max(st.query(0, i), st.query(i + 1, n)) << endl;
    }
}


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


void solve(long long X, long long N, std::vector<long long> p){
    int i = 0;
    int ans;
    while (1)
    {
        if(find(p.begin(), p.end(), X-i) == p.end()){
            ans = X-i;
            break;
        }
        if(find(p.begin(), p.end(), X+i) == p.end()){
            ans = X+i;
            break;
        }
        i++;
    }
    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(X, N, std::move(p));
    return 0;
}


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

using namespace std;

int main(){
    int N, L;

    cin >> N >> L;

    int sum = 0;

    if(L == 0){
        sum = (N - 1) * N / 2;
        printf("%d",sum);
    }
    else if(L > 0){
        sum = (2*L + N ) * (N-1) / 2;
        printf("%d", sum);
    }
    else if(L < 0){
        if(N > abs(L)){
            sum = (2*L + N - 1) * N / 2;
            printf("%d", sum);
        }
        else{
            sum = (2*L + N - 2) * (N-1) / 2;
            printf("%d", sum);
        }
    }

    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i])
	}

	ss := make([]int, n+1)
	for i := 0; i < n; i++ {
		ss[i+1] = ss[i] + as[i]
	}

	cs := make(map[int]int)
	for _, s := range ss {
		cs[s%m]++
	}

	ans := 0
	for _, c := range cs {
		ans += c * (c - 1) / 2
	}
	fmt.Println(ans)
}


Measured memory_bytes: 8636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const int MOD = 1000000007;

void solve(void){
    int N;
    cin >> N;
    vector <int> v(N);
    int maxi = 0, mi = -1;
    rep(N, i) {
        cin >> v.at(i);
        if (abs(v[i]) > abs(maxi)) {
            maxi = v[i];
            mi = i;
        }
    }
    bool f = true;
    rep(N, i) f = f && (v[i]*maxi>=0);
    if (maxi >= 0 && f) {
        cout << N-1 << endl;
        rep(N-1, i) printf("%d %d\n", i+1, i+2);
    }
    else if (maxi <= 0 && f) {
        cout << N-1 << endl;
        repr(N-1, i) printf("%d %d\n", i+2, i+1);
    }
    else {
        cout << 2*N-2 << endl;
        rep(N, i) {
            if (i != mi) printf("%d %d\n", mi+1, i+1);
        }
        if (maxi >= 0) {
            rep(N-1, i) printf("%d %d\n", i+1, i+2);
        }
        else {
            repr(N-1, i) printf("%d %d\n", i+2, i+1);
        }
    }
}


int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}


Measured memory_bytes: 256
#ABC133-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
A=[I() for i in range(n)]
m=max(A)
B=sorted(A)
for i in range(n):
    if A[i]==m:
        print(B[-2])
    else:
        print(B[-1])

Measured memory_bytes: 70676
w,h,n=map(int,input().split())
s=[[1]*w for i in range(h)]
#for i in range(w):
#    for j in range(h):
#        s[i][j]=1
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        for j in range(x):
            for k in range(h):
                s[k][j]=0
                #print(j,k,'jk')
    elif a==2:
        for j in range(x,w):
            for k in range(h):
                s[k][j]=0        
    elif a==3:
        for j in range(w):
            for k in range(y):
                s[k][j]=0  
    elif a==4:
        for j in range(w):
            for k in range(y,h):
                s[k][j]=0  
    #print(s,x,y,a)
ss=[]
for i in s:
    ss.extend(i)
#print(ss)
print(ss.count(1))

Measured memory_bytes: 3192
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
    int n, y;

    cin >> n >> y;

    for (int i=0; i<=n; i++) {
        for (int j=0; j<=n-i; j++) {
            if (i*10000+j*5000+(n-i-j)*1000 == y) {
                printf("%d %d %d", i, j, n-i-j);
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H,W;
  cin >> H >> W;
  string s[H];
  for (int i = 0; i < H; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0, n = 0; j < W; j++, n = 0) {
      if (s[i][j] == '#') {
        n += i && s[i-1][j] == '.';
      	n += j && s[i][j-1] == '.';
      	n += i+1 < H && s[i+1][j] == '.';
        n += j+1 < W && s[i][j+1] == '.';
        if (n == 4) {
          cout << "No";
          return 0;
        }
      }
    }
  }
  cout << "Yes";
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

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

  int l,r;
  l=r=0;

  int res=0;
  for(int i=0;i<s.size();i++){
    char x=s[i];
    //printf("%d : %d %d %c\n",i,l,r,x);
    if(l==r && l==0){
      if(x=='0') l++;
      else r++;
    }
    else if(l!=0){
      if(x=='0') l++;
      else {
        l--;
        res++;
      }
    }
    else if(r!=0){
      if(x=='0'){
        r--;
        res++;
      }
      else r++;
    }
    //printf("%d : %d %d %c\n",i,l,r,x);
  }
  cout<<res*2<<endl;
  return 0;
}



Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

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

static const double eps = 10e-6;

int amount[101];
int num[101];
int dp[101][1001];

int main(){
	string str;
	vector<string> data;
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		memset(amount,0,sizeof(amount));
		memset(num,0,sizeof(num));
		memset(dp,0,sizeof(dp));

		for(int i=0;i<n;i++){
			int a,b;
			scanf("%d %d",&a,&b);
			amount[i] = b;
			num[i] = a;
		}

		dp[0][0] = 1;


		for(int i=0;i<n;i++){		
				for(int j=0;j<=amount[i];j++){
					for(int k=0;k<=1000;k++){
					if(k - num[i]*j >= 0){
						dp[i+1][k] += dp[i][k-num[i]*j];
					}
				}
			}
		}

		int g;
		scanf("%d",&g);
		for(int i=0;i<g;i++){
			int c;
			scanf("%d",&c);
			printf("%d\n",dp[n][c]);
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>
#include <queue>
 
#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;
 
using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }

int main() {
  //std::cout << std::fixed << std::setprecision(10);
  ull n;
  cin >> n;

  vector<ull> a;
  vector<ull> raw;
  each(i, n) {
    ull tmp;
    cin >> tmp;
    a.push(tmp);
    raw.push(tmp);
  }
  
  vector<ull>::iterator it = max_element(a.begin(), a.end());
  ull max1 = *it;
  auto index = std::distance(a.begin(), it);
  a.erase(a.begin() + index);
  ull max2 = max_value(a);

  each(i, n) {
    if (raw[i] == max1) {
      cout << max2 << endl;
    } else {
      cout << max1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 4964