akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll a;
cin >> a;
cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
long double eps = LDBL_EPSILON;
signed main() {
    long double a,b,c;
    cin >> a >> b >> c;
    if(sqrt(a)+sqrt(b)+eps*2+0.00000000000002 < sqrt(c)+eps+0.00000000000001) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; // trick to explore an implicit 2D grid
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; // S,SE,E,NE,N,NW,W,SW neighbors  //GO FOR EVEN FOR 4 moves

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n, i, j, k, t, temp, tc;
    LL a, b, c;
    k = 0;
    LL c1 = 0, c2 = 0;
    cin >> a >> b >> c >> k;
    while (b <= a)
    {
        b *= 2;
        c1++;
    }
    while (c <= b)
    {
        c *= 2;
        c2++;
    }

    if (c1 + c2 <= k)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    

    return 0;
}


Measured memory_bytes: 3648
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    a,b,c = LI()
    ans = 4*a*b<(c-a-b)**2 and c-a-b>0
    print("Yes" if ans else "No")
main()            


Measured memory_bytes: 74320
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=505;
const int d=1000;

int n,m,h,w,x,y,v;
int a[N][N];

int main(){
	int i,j;
	scanf("%d%d%d%d",&n,&m,&h,&w);
	x=n/h; y=m/w; v=-h*w;
	if (n%h==0&&m%w==0){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	for (i=1;i<=x;i++)
		for (j=1;j<=y;j++) a[i*h][j*w]=v*d+d-1;
	for (i=1;i<=n;i++){
		for (j=1;j<=m;j++)
			if (a[i][j]) printf("%d ",a[i][j]);
		else printf("%d ",d);
		printf("\n");
	}
	return 0;
} 

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

using namespace std;
typedef long long int lld;

int arr[222222];
int main(void){
	int n;
	scanf("%d",&n);
	for(int e=2;e<=n;e++){
		int r;
		scanf("%d",&r);
		arr[r]++;
	}
	for(int e=1;e<=n;e++) printf("%d\n",arr[e]);
	return 0;
}


Measured memory_bytes: 4500
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;

int main () {
	int N;
	cin >> N;
	vvi A(2,vi(N));
	REP(i, 2) {
		REP(j, N) {
			cin >> A[i][j];
		}
	}

	A[1][0] += A[0][0];

	FOR(i, 1, N - 1) {
		A[0][i] += A[0][i - 1];
		A[1][i] = A[1][i] + max(A[0][i], A[1][i - 1]);
	}

	cout << A[1][N - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int child[1000100][26];
bool is_end[1000100];
int nxt = 1;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n;
  cin >> n;
  vector<string> s(n);
  vector<vector<int>> paths(n);
  rep(i, n) {
    cin >> s[i];
    reverse(s[i].begin(), s[i].end());
    int node = 0;
    for (char c: s[i]) {
      paths[i].push_back(node);
      if (child[node][c - 'a'] == 0) {
        child[node][c - 'a'] = nxt++;
      }
      node = child[node][c - 'a'];
    }
    is_end[node] = 1;
  }
  ll ans = -n;
  rep(i, n) {
    set<char> suffix;
    repr(j, s[i].size() - 1) {
      suffix.insert(s[i][j]);
      int node = paths[i][j];
      for (char c: suffix) ans += is_end[child[node][c - 'a']];
    }
  }
  cout << ans << '\n';

  

  




  
  return 0;
}

Measured memory_bytes: 112260
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;

int main(void){
    int N;
    cin >> N;

    long amari_max = 0;
    for(int i=0; i<N; ++i){
        amari_max += i;
    }

    cout << amari_max << endl;
}


Measured memory_bytes: 256
a,b,m=map(int,input().split())
ak=list(map(int,input().split()))
bk=list(map(int,input().split()))
kei=[]
w=min(ak)+min(bk)
kei.append(w)
for i in range(m):
    x,y,c=map(int,input().split())
    pay=ak[x-1]+bk[y-1]-c
    kei.append(pay)
print(min(kei))


Measured memory_bytes: 18736
#include<bits/stdc++.h>
using namespace std;
int y,wq[100003],st[100003];
int dmc(int h)
{
    int g;
    if(h<=0)return 0;
    if(st[h]!=1e9)return st[h];
    for(g=1;g<=y&&g<=h;g++)
        st[h]=min(st[h],dmc(h-g)+abs(wq[h]-wq[h-g]));
    return st[h];
}
int main()
{
    int g,t;
    scanf("%d %d",&t,&y);
    for(g=0;g<t;g++){
        scanf("%d",&wq[g]);
        st[g]=1e9;
    }
    dmc(t-1);
    printf("%d\n",st[t-1]);
    return 0;
}


Measured memory_bytes: 5760
import java.util.*;
public class Main {
	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int H;	//縦
		 int W;	//横
		 while(true){
			 H = Integer.parseInt(scan.next());
			 W = Integer.parseInt(scan.next());
			 if(H == 0 && W == 0){
				 //HとWが0の時、終了。
				 break;
			 }//if
			 //--- 出力 ---
			 for (int i = 0; i < H; i++ ){
				 for (int j = 0; j < W; j++ ){
					 if(i == 0 || j == 0 || j == W-1 || i == H-1){
						 //iとjが0かつ、入力された横(W)と縦(H)の数字の時に "#" を出力する
						 System.out.print("#");
					 }else{
						 System.out.print(".");
					 }//if
				 }//for
				 System.out.println();
			 }//for
			 System.out.println();
		 }//while 
	}
}

Measured memory_bytes: 24828
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

ll maeA[200001], maeB[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	ll N, X, D;
	cin >> N >> X >> D;
	if (D == 0) {
		if (X == 0) printf("1");
		else printf("%lld", N + 1);
		return 0;
	}

	if (D < 0) {
		D *= -1;
		X *= -1;
	}

	ll R = (X ? D / __gcd(abs(X), D) : 1);
	ll Z = (X ? X / __gcd(abs(X), D) : 0);
	int r = 0;
	ll zure = 0;
	ll a = 0;
	ll b = 0;
	ll kotae = 0;
	rep(i, min(N + 1, R)) {
		maeA[i] = a + zure;
		maeB[i] = b + zure;
		kotae += maeB[i] - maeA[i] + 1;
		a += i;
		b += N - i - 1;
		r++;
	}
	r = 0;
	zure += Z;
	for (int i = min(N + 1, R); i <= N; i++) {
		ll A = a + zure;
		ll B = b + zure;
		if (maeA[r] >= A && maeB[r] <= B) {
			kotae += B + maeA[r] - A - maeB[r];
		}
		else if (maeA[r] <= A && maeB[r] >= B) {
			break;
		}
		else if (maeA[r] <= A) {
			kotae += B - max(maeB[r] + 1, A) + 1;
		}
		else {
			kotae += min(maeA[r] - 1, B) - A + 1;
		}
		maeA[r] = A;
		maeB[r] = B;

		a += i;
		b += N - i - 1;
		r++;
		if (r >= R) {
			r = 0;
			zure += Z;
		}
	}
	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;



int main(void) {
	ll x;
	cin >> x;

	ll ans = 0;
	ans += x / 500 * 1000;

	x -= x / 500 * 500;
	ans += x / 5 * 5;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long K,X;
    cin >> K >> X;
    long long right,left;
    left=max(-2000000LL,X-K+1);
    right=min(2000000LL,X+K-1);
    for(long long i=left; i<=right; i++){
        cout << i << " ";
    }
    return 0;
}

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


int main(void){
	int N,D;
	string s;
	cin >> N;
	cin >> s;
	cin >> D;
	int count = D;
	/*
	for(int i = 0; i < s.length(); ++i){
		if(s[i] =='0'){
			count++;
		}
	}
	if(count > D){
	*/

	for(int i = 0; i < s.length(); ++i){
		if(N-count>i){
			if(count>=1 && s[i]=='0'){
				cout << 1;
				--count;
			}else{
				cout << s[i];
			}
		}else{
			if(s[i] == '0'){
				cout << 1;
			}else{
				cout << 0;
			}
		}
	}
		/*
	} else{
		for(int i = s.length()-1; i >= 0; --i){
			if(D>=1 && s[i]=='1'){
				s[i] = '0';
				--D;
			}
		}
		cout << s;
	}
	*/
	cout << endl;
	return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
int num;
int main(){
	scanf("%d",&num);
	int n=num%10;
	if(n==2||n==4||n==5||n==7||n==9){
		printf("hon");
	}else if(n==0||n==1||n==6||n==8){
		printf("pon");
	}else{
		printf("bon");
	}
	return 0;
} 

Measured memory_bytes: 3828
#include<cstdio>
#include<algorithm>
using namespace std;
const int INF=1e9+7;
const int N=2003;
struct Edge {
	int v;
	Edge *nxt;
}edge[2*N];
Edge *ecnt,*NIL;
Edge *head[N];
int n,ans=INF;
char ch[N];
int Min[N],Max[N];
int siz[N],yl[N];
void AddEdge(int u,int v) {
	ecnt->v=v; ecnt->nxt=head[u];
	head[u]=ecnt++;
	ecnt->v=u; ecnt->nxt=head[v];
	head[v]=ecnt++;
}
void Dfs1(int u,int fa) {
	siz[u]=ch[u]-'0';
	yl[u]=Min[u]=Max[u]=0;
	int son=-1;
	for(Edge *e=head[u];e!=NIL;e=e->nxt) {
		if(e->v==fa) continue;
		Dfs1(e->v,u);
		if(siz[e->v]) {
			siz[u]+=siz[e->v];
			Max[u]+=Max[e->v]+siz[e->v];
			Min[u]+=Min[e->v];
			yl[u]+=yl[e->v]+siz[e->v];
			
			if(son==-1||yl[son]+siz[son]<yl[e->v]+siz[e->v])
				son=e->v;
		}
	}
	if(son==-1) return ;
	if(yl[son]+siz[son]>yl[u]-(yl[son]+siz[son])) {
		Min[u]+=yl[u]-(yl[son]+siz[son]);
		yl[u]=yl[son]+siz[son]-(yl[u]-(yl[son]+siz[son]));
	}
	else {
		Min[u]+=yl[u]>>1;
		yl[u]=yl[u]&1;
	}
}
int main() {
	NIL=&edge[0]; ecnt=&edge[1];
	scanf("%d",&n);
	scanf("%s",ch+1);
	for(int i=1;i<=n;i++) head[i]=NIL;
	for(int i=1,u,v;i<n;i++) {
		scanf("%d %d",&u,&v);
		AddEdge(u,v);
	}
	for(int i=1;i<=n;i++) {
		Dfs1(i,i);
		int son=-1,add=0;
		for(Edge *e=head[i];e!=NIL;e=e->nxt) {
			if(son==-1||yl[e->v]+siz[e->v]>yl[son]+siz[son])
				son=e->v;
			add+=Max[e->v]-yl[e->v];
		}
		add-=Max[son]-yl[son];
		if(add>=yl[i]&&!(Max[i]&1))
			ans=min(ans,Max[i]>>1);
	}
	if(ans>=INF) printf("-1\n");
	else printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <climits>

using namespace std;


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

	int ans = 0;

	for (int i = 1; i <= n; i++) {
		
		int h = i;
		int count = 0;

		while (1) {
			
			if (h == 0)break;

			h = h / 10;
			count++;

		}

		if (count % 2 == 1)ans++;

	}
	
	cout << ans << endl;

	return 0;
}

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

#define inf 2000000000  // 1e17
template <class T>
struct Dinic {
  struct edge {
    int to;
    T cap;
    int rev;
  };
  vector<vector<edge>> edges;
  vector<int> id;
  vector<int> d;
  Dinic(int n = 1) {
    edges.clear();
    edges.resize(n);
    id.resize(n);
    d.resize(n);
  }
  bool add(int start, int goal, T capacity) {
    edges[start].push_back((edge){goal, capacity, (int)edges[goal].size()});
    edges[goal].push_back((edge){start, 0, (int)edges[start].size() - 1});
    return 1;
  }
  void bfs(int st) {
    d.assign(d.size(), -1);
    queue<int> qu;
    d[st] = 0;
    qu.push(st);
    while (qu.size()) {
      int now = qu.front();
      qu.pop();
      for (auto e : edges[now])
        if (e.cap > 0 && d[e.to] < 0) {
          d[e.to] = d[now] + 1;
          qu.push(e.to);
        }
    }
  }
  T pathdfs(int now, int goal, T nf) {
    if (now == goal) return nf;
    for (int& i = id[now]; i < (int)edges[now].size(); ++i) {
      edge* e = &edges[now][i];
      if (e->cap > 0 && d[now] < d[e->to]) {
        T res = pathdfs(e->to, goal, min(nf, e->cap));
        if (res > 0) {
          e->cap -= res;
          edges[e->to][e->rev].cap += res;
          return res;
        }
      }
    }
    return 0;
  }
  T solve(int start, int goal) {
    T res = 0, nf = 0;
    while (1) {
      bfs(start);
      if (d[goal] < 0) return res;
      id.assign(id.size(), 0);
      while ((nf = pathdfs(start, goal, inf)) > 0) res += nf;
    }
    return -1;
  }
};

int h, w;
vector<string> s;
pair<int, int> st, go;

int main() {
  cin >> h >> w;
  s.resize(h);
  for (int i = 0; i < h; ++i) cin >> s[i];
  Dinic<long long> din(h + w + 2);
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) {
      if (s[i][j] != '.') {
        if (s[i][j] == 'S') {
          st = make_pair(i, j);
          din.add(h + w, i, inf);
          din.add(h + w, j + h, inf);
        } else if (s[i][j] == 'T') {
          go = make_pair(i, j);
          din.add(i, h + w + 1, inf);
          din.add(j + h, h + w + 1, inf);
        }
        din.add(i, j + h, 1);
        din.add(j + h, i, 1);
      }
    }
  if (st.first == go.first || st.second == go.second)
    cout << "-1" << endl;
  else
    cout << din.solve(h + w, h + w + 1) << endl;
  return 0;
}


Measured memory_bytes: 4560
#include<iostream>
#include<string>
#include<algorithm>
#include<unordered_set>
#include<vector>
#include<math.h>
#include<iomanip>

using namespace std;

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

	int n, m;
	cin >> n >> m;
	vector<bool> v(n+1, false);
	vector<int> u(n + 1, 0);
	int p; string s;
	int ans = 0, w = 0;
	while (m--) {
		cin >> p >> s;
		if (s == "WA") {
			if (v[p] == false) {
				u[p]++;
			}
		}
		else {
			if (v[p] == false) {
				v[p] = true;
				ans++;
			}
		}
	}


	for (int i = 1; i <= n; i++) {
		if (v[i] == true) {
			w += u[i];
		}
	}
	

	cout << ans << " " << w;
}


Measured memory_bytes: 640
use proconio::input;

fn main() {
    input! {
        n: usize,
        d: i64,
        xy: [(i64, i64); n]
    }

    solve(d, &xy);
}

fn solve(d: i64, xy: &[(i64, i64)]) {
    let mut cnt = 0;
    for &(x, y) in xy.iter() {
        if x * x + y * y <= d * d {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 7796
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp(aa,bb) make_pair(aa,bb)
#define _for(i,b) for(int i=(0);i<(b);i++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,b,a) for(int i=(b);i>=(a);i--)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define X first
#define Y second
#define lowbit(a) (a&(-a))
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef long double ld;
const int N=100010;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const double eps=1e-6;

ll a[N];
int ans=0;

void solve(){
	int n;cin>>n;
	_for(i,n) cin>>a[i];
	sort(a,a+n);
	_for(i,n){
		for(int j=i+1;j<n;j++){
			for(int k=j+1;k<n;k++){
				if(a[i]+a[j]>a[k]){
					if(a[i]!=a[j]&&a[j]!=a[k]) ans++;
				}
				else break;
			}
		}
	}
	cout<<ans<<"\n";
}


int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
    freopen("F:/laji/1.in", "r", stdin);
//	freopen("F:/laji/2.out", "w", stdout);
#endif
//	int t;cin>>t;while(t--)
	solve();
    return 0;
}



Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,vl>;
using Tu = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
const ll INF=1LL<<60;
const ll MOD=1000000007;


int main(){
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    string S;
    cin >> S;
    deque<ll> deq;
    ll mark=0;
    for(ll i=1;i<N;i++){
        if(S[i-1]!=S[i]){
            deq.emplace_back(i-mark);
            mark=i;
        }
    ;}
    deq.emplace_back(N-mark);
    if(deq.size()<=2*K){
        cout<<N<<endl;return 0;
    }
    ll f=S[0]-'0';
    ll t=deq.size();
    ll sum=0;
    for(ll i=0;i<2*K;i++){
        sum+=deq[i]
    ;}
    ll ans=sum;
    ll g;
    for(ll i=2*K;i<t;i++){
        sum-=deq[i-2*K];
        sum+=deq[i];
        if(i%2!=f)g=deq[i-2*K];
        else g=0;
        ans=max(ans,sum+g);
    ;}
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<tuple<string,int,int>>a;
    for(int i=1; i<=n; ++i){
        string s; int p;
        cin>>s>>p;
        p=-p;
        a.push_back(tie(s,p,i));
    }
    sort(a.begin(),a.end());
        rep(i,n){
            cout<<get<2>(a[i])<<endl;
        }
}

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

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

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

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int A, B, C;
  cin >> A >> B >> C;
  double answer = (A*B)/2.0;
  cout << answer << '\n';
}


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

a_l = a[:n]
a_c = a[n:2*n]
a_r = [ -1*i for i in  a[2*n:]]

left = [0] * (n+1)
right = [0] * (n+1)

# ヒープキュー（最小値・最大値の取得）
from heapq import heapify,heappop,heappush

left[0] = sum(a_l)
heapify(a_l)
for i,val in enumerate(a_c):
    heappush(a_l,val)
    left[i+1] = left[i] + val - heappop(a_l)

right[-1] = -1 * sum(a_r)
heapify(a_r)
for i,val in enumerate(a_c[::-1],1):
    heappush(a_r,val * -1)
    right[n-i] = right[n+1-i] + val + heappop(a_r)

lr = [i-j for i,j in zip(left,right)]
print(max(lr))

Measured memory_bytes: 120848
#include <iostream>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)

using namespace std;

int main(){
	long long X,money=100,year=0;
	int i,j;
	cin >> X;
	while(money < X){
		money *= 1.01;
		year++;
	}
	cout << year << endl;
	return 0;
}

Measured memory_bytes: 3192
from collections import defaultdict
N,X,Y = map(int,input().split())

k = defaultdict(lambda: 0)

for i in range(N-1):
    for j in range(i+1,N):
        dist = min( j-i , abs(X-1-i)+1+abs(Y-1-j) , abs(Y-1-i)+1+abs(X-1-j) )
        k[dist] += 1

for i in range(1,N):
    print(k[i])


Measured memory_bytes: 3956
#include <stdio.h>

struct heap_ {
  int data[100000];
  int index[100000];
  int last;
};

struct heap_ heap;

void swap(int *x, int *y)
{
  int temp = *x;
  *x = *y;
  *y = temp;
}

void init()
{
  heap.last = -1;
}

void insert(int idx, int d)
{
  heap.last++;

  heap.index[heap.last] = idx;
  heap.data[heap.last] = d;

  int i = heap.last;
  while(i > 0) {
    if(heap.data[i] < heap.data[(i-1)/2]) {
      swap(&heap.index[i], &heap.index[(i-1)/2]);
      swap(&heap.data[i], &heap.data[(i-1)/2]);
      i = (i-1)/2;
    }
    else {
      break;
    }
  }
}

int deletemin()
{
  int min_idx = heap.index[0];

  heap.index[0] = heap.index[heap.last];
  heap.data[0]  = heap.data[heap.last];
  heap.last--;

  int i = 0;
  while(i < heap.last) {
    if(heap.data[i] > heap.data[i * 2 + 1] &&
       heap.data[i] > heap.data[i * 2 + 2] &&
       i * 2 + 2 <= heap.last) {
      if(heap.data[i * 2 + 1] < heap.data[i * 2 + 2]) {
        swap(&heap.data[i], &heap.data[i * 2 + 1]);
        swap(&heap.index[i], &heap.index[i * 2 + 1]);
        i = i * 2 + 1;
      }
      else {
        swap(&heap.data[i], &heap.data[i * 2 + 2]);
        swap(&heap.index[i], &heap.index[i * 2 + 2]);
        i = i * 2 + 2;
      }
    }
    else if(heap.data[i] > heap.data[i * 2 + 1] && i * 2 + 1 <= heap.last) {
      swap(&heap.data[i], &heap.data[i * 2 + 1]);
      swap(&heap.index[i], &heap.index[i * 2 + 1]);
      i = i * 2 + 1;
    }
    else if(heap.data[i] > heap.data[i * 2 + 2] && i * 2 + 2 <= heap.last) {
      swap(&heap.data[i], &heap.data[i * 2 + 2]);
      swap(&heap.index[i], &heap.index[i * 2 + 2]);
      i = i * 2 + 2;
    }
    else {
      break;
    }
  }

  return min_idx;
}

int main(void)
{
  int n;
  scanf("%d", &n);

  init();

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

    insert(i, a[i]);
  }

  for(int i = 0; i < n; i++) {
    printf("%d ", deletemin() + 1);
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		while (true) {
			int T = sc.nextInt();
			String N = sc.next();
			int num = Integer.parseInt(N);
			if (T == 0 && num == 0) break;
			int L = N.length();
			int[][] v = new int[L][L + 1];
			for (int i = 0; i < L; ++i) {
				for (int j = i + 1; j <= L; ++j) {
					v[i][j] = Integer.parseInt(N.substring(i, j));
				}
			}
			int best = -1;
			int bestI = -1;
			for (int i = 0; i < (1 << (L - 1)); ++i) {
				int idx = (1 << L) + (i << 1) + 1;
				int sum = 0;
				int left = 0;
				while (left < L) {
					int right = left + 1;
					while ((idx & (1 << right)) == 0) {
						++right;
					}
					sum += v[left][right];
					left = right;
				}
				if (sum <= T) {
					if (sum > best) {
						best = sum;
						bestI = idx;
					} else if (sum == best) {
						bestI = -2;
					}
				}
			}
			if (bestI == -1) {
				System.out.println("error");
			} else if (bestI == -2) {
				System.out.println("rejected");
			} else {
				System.out.print(best);
				int left = 0;
				while (left < L) {
					int right = left + 1;
					while ((bestI & (1 << right)) == 0) {
						++right;
					}
					System.out.print(" " + v[left][right]);
					left = right;
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 19960
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S;
  cin >> N >> S;
  int ma = 0;
  int buri = 0;
  for(int i=0; i<N; i++){
    if(S.at(i) == 'D')buri--;
    if(S.at(i) == 'I')buri++;
    ma = max(buri,ma);
  }
  cout << ma << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    string s;
    int k;
    vector<string> sub;
    cin >> s >> k;
    int ssize=s.size();
    for(int mask=1; mask<=k; mask++){
        for(int i=0; i<=ssize-mask; i++){
            string tmp=s.substr(i,mask);
            sub.push_back(tmp);
        }
    }
    sort(sub.begin(),sub.end());
    sub.erase(unique(sub.begin(),sub.end()),sub.end());
    cout << sub[k-1] << endl;
    return 0;
}


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

class Cmondai
{
    static void Main()
    {

        var N = Int32.Parse(Console.ReadLine());
        var A = new long[N];
        var ans = 0;
        var currentNum = 0L;
        var currentNumCount = 0;
        for (int i = 0; i < N; ++i) A[i] = Int64.Parse(Console.ReadLine());
        A = A.OrderBy(x => x).ToArray();
        for (int i = 0; i < N; ++i)
        {
            if (A[i] == currentNum)
            {
                currentNumCount++;
            }
            else
            {
                if (currentNumCount % 2 != 0) ans++;
                currentNum = A[i];
                currentNumCount = 1;
            }
            if (i == N - 1) if (currentNumCount % 2 != 0) ans++;
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 22748
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <utility>

intmax_t gcd(intmax_t m, intmax_t n) {
  while (n) std::swap(m %= n, n);
  return m;
}

int solve_testcase() {
  intmax_t h, w;
  scanf("%jd %jd", &h, &w);

  if (h == w)
    return puts("1 0"), 0;

  intmax_t g = gcd(h, w);
  h /= g;
  w /= g;

  if (h * w % 2 == 0)
    return puts("1 1"), 0;

  intmax_t hw = h*w;
  intmax_t white = hw/2+1;
  intmax_t black = white-1;

  printf("%jd %jd\n", white, black);
  return 0;
}

int main() {
  int T;
  scanf("%d", &T);

  for (int i = 0; i < T; ++i)
    solve_testcase();
}



Measured memory_bytes: 2720
import java.io.*;
class Main{
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		int n=Integer.parseInt(str);
		
		String[] a=br.readLine().split(" ");
		int min=1000000,max=-1000000,ai=0;
		long sum=0;
		for(int i=0;i<n;i++){
			ai=Integer.parseInt(a[i]);
			sum+=ai;
			if(min>ai){
				min=ai;
			}
			if(max<ai){
				max=ai;
			}
		}
		System.out.println(min+" "+max+" "+sum);
	}
}

Measured memory_bytes: 28576
#include <iostream>
#include <algorithm>

int main(){
    int a, b, m;
    std::cin >> a >> b >> m;
    int A[a], B[b];
    for (int i = 0; i < a; ++i) {
        std::cin >> A[i];
    }
    for (int i = 0; i < b; ++i) {
        std::cin >> B[i];
    }
    int min = *std::min_element(A, A+a) + *std::min_element(B, B+b);
    while(m--){
        int x, y, c;
        std::cin >> x >> y >> c;
        min = std::min(min, A[x-1]+B[y-1]-c);
    }
    std::cout << min;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
const int maxn = 300005;
const int mod = 998244353;
int h[maxn];
int gg[maxn];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    f1(n) {
        cin >> h[i];
    }
    f(m) {
        int x, y;
        cin >> x >> y;
        if (h[x] >= h[y]) {
            gg[y] = 1;
        }
        if (h[y] >= h[x]) {
            gg[x] = 1;
        }
    }
    int ans = 0;
    f1 (n) {
        if (!gg[i]) {
            ans++;
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 4440
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
	for true {
		a -= d
		c -= b
		if a <= 0 || c <= 0 {
			break
		}
	}
	if c <= 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1816
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  string s, t;
  cin >> s >> t;

  bool ok = true;
  rep(i, 0, sz(s)){
    if(s[i] == t[i]) continue;
    else ok = false;
  }

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

Measured memory_bytes: 3612
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>

namespace detail {
template <typename Tp, size_t N>
std::vector<Tp> make_vector(
    std::vector<size_t>& sizes,
    typename std::enable_if<(N == 1), Tp const&>::type x
) {
  return std::vector<Tp>(sizes[0], x);
}
template <typename Tp, size_t N>
auto make_vector(
    std::vector<size_t>& sizes,
    typename std::enable_if<(N > 1), Tp const&>::type x
) {
  size_t size = sizes[N-1];
  sizes.pop_back();
  return std::vector<decltype(make_vector<Tp, N-1>(sizes, x))>(
      size, make_vector<Tp, N-1>(sizes, x)
  );
}
}  // detail::

template <typename Tp, size_t N>
auto make_vector(size_t const(&sizes)[N], Tp const& x) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return detail::make_vector<Tp, N>(s, x);
}

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
// constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

int main() {
  size_t n, k;
  scanf("%zu %zu", &n, &k);

  std::vector<intmax_t> h(n);
  for (auto& hi: h) scanf("%jd", &hi);
  h.insert(h.begin(), 0);

  intmax_t inf = 1e14;
  auto dp = make_vector<intmax_t>({n+1, n+1}, inf);
  dp[0][0] = 0;
  for (size_t i = 1; i <= n; ++i) {
    for (size_t j = 0; j < i; ++j) {
      for (size_t k = 0; k < i; ++k) {
        dp[i][j+1] = std::min(dp[i][j+1], dp[k][j] + std::max(0_jd, h[i]-h[k]));
      }
    }
  }

  intmax_t res = inf;
  for (size_t i = 0; i <= n; ++i)
    res = std::min(res, dp[i][n-k]);

  printf("%jd\n", res);
}


Measured memory_bytes: 1024
A, B, K = map(int, input().split())

mi = min([A, B])
ma = max([A, B])

k = 0

for i in range(mi):
  if ma % (mi - i) == 0 and mi % (mi - i) == 0:
    k += 1
    if k == K:
      print(mi - i)
      break


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
const long long INF = INT64_MAX;

#define REP(i, n) for(ll i=0;i<n;i++)
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).rbegin(), (v).rend())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define DESC(v) sort((v).rbegin(), (v).rend())
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);erase(unique(v.begin(), v.end()), v.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

ll f(vll A, ll b) {
    ll ret = 0;
    for(ll i = 0; i < A.size(); i++) {
        ret += abs(A[i] - (b + i + 1LL));
    }
    return ret;
}

ll argmax(vll A, ll lb, ll ub) {
    while(ub - lb > 1) {
        ll m = (ub + lb) / 2;
        (f(A, m) - f(A, m - 1) < 0 ? lb : ub) = m;
    }
    return lb;
}

void solve() {
    ll N;
    cin >> N;
    vll A(N);
    for(auto &a:A) cin >> a;
    ll lb = argmax(A, (ll)-1e17, (ll) 1e17);
    cout << f(A, lb) << endl;
}

int main() {
    FIO;
    solve();
    return 0;
}


Measured memory_bytes: 6576
def main():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    if S[0][0] == '.':
        c, f = 0, False
    else:
        c, f = 1, True
    v = [(c, f)]
    for s in S[0][1:]:
        sf = s == '#'
        if sf != f:
            c, f = c + 1, not f
        v.append((c, f))
    u = v
    for ss in S[1:]:
        c, f = u[0]
        sf = ss[0] == '#'
        if sf != f:
            c, f = c + 1, not f
        v = [(c, f)]
        for i, s in enumerate(ss[1:], 1):
            uc, uf = u[i]
            sf = s == '#'
            if uf != sf:
                uc, uf = uc + 1, not uf
            if f != sf:
                c, f = c + 1, not f
            if uc < c:
                c, f = uc, uf
            v.append((c, f))
        u = v
    return (u[-1][0] + 1) // 2

print(main())


Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define y1 my_y1
#define fi first
#define se second
#define lcm mylcm
 
using namespace std;
 
const ll mod = 1e9 + 7;
const ll inf = 2e9;
const int N = 1e5 + 5;

ll n, m, dp[1050][1050];
char c[1050][1050];

int main () {
	//freopen("a.out", "w", stdout);
    cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	dp[1][1] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> c[i][j];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (c[i][j] != '#' && !(i == 1 && j == 1)) {
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
			}
		}
	}
	cout << dp[n][m];
	return 0;
}

Measured memory_bytes: 9472
#include<stdio.h>

int main(){
    int n,i,a[100];
    double S=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        S+=1.0/a[i];
    }
    printf("%lf\n",1/S);
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second


int c,n,m,s,d;
typedef struct{
  int to,cost;
}edge;

vector<edge> V[11*100];


int dijkstra(int from,int to){
  from=(c+1)*from+c;
  bool used[n*(c+1)];
  memset(used,0,sizeof(used));
  int len[n*(c+1)];
  rep(i,n*(c+1))len[i]=1<<23;
  len[from]=0;

  priority_queue<PI,vector<PI>,greater<PI> > Q;
  Q.push(mp(0,from));
  while(!Q.empty()){
    int cost=Q.top().F,tfrom=Q.top().S;Q.pop();
    if(used[tfrom])continue;
    used[tfrom]=true;
    rep(i,V[tfrom].size()){
      int tto=V[tfrom][i].to,tcost=V[tfrom][i].cost;
      if(used[tto])continue;
      len[tto]=min(len[tfrom]+tcost,len[tto]);
      Q.push(mp(len[tto],tto));
    }
  }
/*
  rep(i,n){
    rep(j,c+1)printf("%6d",len[i*(c+1)+j]);
    cout<<endl;
  }
*/
  int ans=len[to*(c+1)];
  rep(i,c+1)ans=min(ans,len[to*(c+1)+i]);
  return ans;
}

main(){
  while(cin>>c>>n>>m>>s>>d,c|n|m|s|d){
    --s,--d;
    rep(i,n*(c+1))V[i].clear();

    rep(j,m){
      int a,b,cost;
      cin>>a>>b>>cost;
      --a,--b;
      rep(i,c+1){
        V[a*(c+1)+i].pb((edge){b*(c+1)+i,cost});
        V[b*(c+1)+i].pb((edge){a*(c+1)+i,cost});
        if(i){
          V[a*(c+1)+i].pb((edge){b*(c+1)+i-1,cost/2});
          V[b*(c+1)+i].pb((edge){a*(c+1)+i-1,cost/2});
        }
      }
    }
/*
    rep(i,n*(c+1)){
      printf("%d ",i/(c+1)+1);
      rep(j,V[i].size()){
        printf("%d %6d ",V[i][j].to/(c+1)+1,V[i][j].cost);
      }
      cout<<endl;
    }
*/
    cout<<dijkstra(s,d)<<endl;
  }
}

Measured memory_bytes: 1204
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int gcd(int a, int b){
    int tmp;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    int r; 
    r = a%b;
    while(r!=0){
        a = b;
        b = r;
        r = a%b;
    }
    return b;
}

int main(){
    int n;
    cin >> n;
    vector<int>a(n+1);

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

    vector<int>l(n+1);
    vector<int>r(n+1);

    l[1] = a[1];
    r[n] = a[n];
    for(int i = 2; i <= n-1; i++){
        l[i] = gcd(l[i-1],a[i]);
    }
    for(int i = n-1; i >= 1; i--){
        r[i] = gcd(r[i+1],a[i]);
    }

    int result = max(l[n-1],r[2]);//両端を入れないやつをまず最初に見る///
    for(int i = 2; i < n; i++){
        result = max(result,gcd(l[i-1],r[i+1]));
    }

    cout << result << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  long long ans = 0;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  for(int i = 0; i < N-1; i++){
    for(int j = i+1; j < N; j++){
      ans = max(ans,abs(A[i] - A[j]));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
int dp[50][3001];
int main() {
	int N,M,S;
	while(scanf("%d %d %d",&N,&M,&S),N) {
		memset(dp,0,sizeof(dp));
		dp[0][0]=1;
		for(int m=1;m<=M;m++)for(int k=N*N;k>=1;k--)for(int s=m;s<=S;s++) {
			dp[k][s]+=dp[k-1][s-m];
			if(dp[k][s]>100000)dp[k][s]-=100000;
		}
		printf("%d\n",dp[N*N][S]);
	}
}

Measured memory_bytes: 1620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 +7;
const ll MAXN = 1e6 + 5;

map<string,int>mp;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	string s;
	int ans=0;
	for(int i=1;i<=n;i++){
		cin>>s;
		mp[s]++;
		ans=max(ans,mp[s]);
	}
	for(auto it:mp){
		if(it.second==ans)
		cout<<it.first<<endl;
	}
	return 0;
}


Measured memory_bytes: 23808
# -*- coding: utf-8 -*-
from sys import stdin

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


N, K = ds_in()
height_list = []
for _ in range(N):
    height_list.append(d_in())

height_list.sort()
ans = float('inf')
for i in range(N - K + 1):
    ans = min(ans, height_list[i+K-1] - height_list[i])
print(ans)


Measured memory_bytes: 7508
//Volume0-0046
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		//declare
		double h,
		       max = 0,
		       min = Double.MAX_VALUE;

        //input
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
        	h = sc.nextDouble();
        	if(max < h){max = h;}
        	if(min > h){min = h;}
        }
        System.out.println(max - min);
	}
}

Measured memory_bytes: 18612
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct node *link;
struct node{
	int v;
	link next;
	link prev;
};

link head=NULL;
link tail=NULL;

void insert(int v){
	link x = malloc(sizeof(*x));
	x->v = v; x->next=NULL; x->prev=NULL; 
	if(head==NULL){
		head=x; tail=x;
	}else{
		head->prev=x;
		x->next=head;
		head=x;
	}
}

link search(int v){
	link t;
	for(t=head;t!=NULL;t=t->next){
		if(t->v==v)return t;
	}
	return NULL;
}

void deleteFirst(){
	head=head->next;
	if(head==NULL){
		//free(tail);
		tail=NULL;
	}else head->prev=NULL;
}

void deleteLast(){
	tail=tail->prev;
	if(tail==NULL){
		//free(head);
		head=NULL;
	}else tail->next=NULL;
	
}

void delete(int v){
	link next,prev;
	link t=search(v);
	if(t==NULL)return;
	if(t==head)deleteFirst();
	else if(t==tail)deleteLast();
	else{
		next=t->next;
		prev=t->prev;
		next->prev=prev;
		prev->next=next;
		//t->prev->next=t->next;
		//t->next->prev=t->prev;
		free(t);
	}
}

void Print(){
	link t;
	for(t=head;t!=NULL;t=t->next){
		if(t->next==NULL)
			printf("%d\n",t->v);
		else
			printf("%d ",t->v);
	}
}
void PrintR(){
	link t;
	for(t=tail;t!=NULL;t=t->prev){
		if(t->prev==NULL)
			printf("%d\n",t->v);
		else
			printf("%d ",t->v);
	}
}

void FreeList(){
	link next;
	while(head->next!=NULL){
		next=head->next;
		free(head);
		head=next;
	}
}

int main(void){
	int n,i;
	char c[20];
	int x;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",c);
		
		if(!strcmp(c,"insert")){
			scanf("%d",&x);
			insert(x);
		}else if(!strcmp(c,"delete")){
			scanf("%d",&x);
			delete(x);
		}else if(!strcmp(c,"deleteFirst")){
			deleteFirst();
		}else if(!strcmp(c,"deleteLast")){
			deleteLast();
		}
		//printf("head:%d\ntail:%d\n",head->v,tail->v);
		//Print();
		//PrintR();
	}
	Print();
	FreeList();
	return 0;
}

Measured memory_bytes: 36132
#include <stdio.h>
#include <iostream>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

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

    int ans = 0;
    ans += A > B ? A-- : B--;
    ans += A > B ? A-- : B--;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()
sw4li = ["SS", "SW", "WS", "WW"]
t = ""
for v in sw4li:
    t = ""
    t += v
    for i in range(1, len(s)):
        if t[-2] == "S" and t[-1] == "S":
            if s[i] == "o":
                t += "S"
            elif s[i] == "x":
                t += "W"
        elif t[-2] == "S" and t[-1] == "W":
            if s[i] == "o":
                t += "W"
            elif s[i] == "x":
                t += "S"
        elif t[-2] == "W" and t[-1] == "S":
            if s[i] == "o":
                t += "W"
            elif s[i] == "x":
                t += "S"
        elif t[-2] == "W" and t[-1] == "W":
            if s[i] == "o":
                t += "S"
            elif s[i] == "x":
                t += "W"
    if t[-1] == t[0]:
        if t[-1] == "S" and t[1] == "S":
            if s[0] == "o":
                if t[-2] == "S":
                    print(t[:-1])
                    exit()
            elif s[0] == "x":
                if t[-2] == "W":
                    print(t[:-1])
                    exit()
        elif t[-1] == "S" and t[1] == "W":
            if s[0] == "o":
                if t[-2] == "W":
                    print(t[:-1])
                    exit()
            elif s[0] == "x":
                if t[-2] == "S":
                    print(t[:-1])
                    exit()
        elif t[-1] == "W" and t[1] == "S":
            if s[0] == "o":
                if t[-2] == "W":
                    print(t[:-1])
                    exit()
            elif s[0] == "x":
                if t[-2] == "S":
                    print(t[:-1])
                    exit()
        elif t[-1] == "W" and t[1] == "W":
            if s[0] == "o":
                if t[-2] == "S":
                    print(t[:-1])
                    exit()
            elif s[0] == "x":
                if t[-2] == "W":
                    print(t[:-1])
                    exit()
print(-1)

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

namespace Sample
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = Console.ReadLine();
			var array = Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
			var min = array.Min();
			var max = array.Max();
			var sum = array.Sum();

			Console.WriteLine($"{min} {max} {sum}");

		}
	}
}



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

using namespace std;

const int nmax=100000;

struct linie
{
    int nod,d;
};
int n,m;
vector<linie>v[nmax+5];
bool viz[nmax+5];
bool Gata=0;
int P[nmax+5];
void dfs(int nod)
{
    if(Gata==1)
        return;
    viz[nod]=1;
    for(int i=0;i<v[nod].size();i++)
    {
        int b,d;
        b=v[nod][i].nod;
        d=v[nod][i].d;
        if(P[nod]+d!=P[b] && viz[b])
        {
            Gata=1;
            return;
        }
        P[b]=P[nod]+d;
        if(viz[b]==0)
            dfs(b);
    }
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int a,b,d;
        cin>>a>>b>>d;
        v[a].push_back({b,d});
        v[b].push_back({a,-d});
    }
    for(int i=1;i<=n;i++)
        if(viz[i]==0)
        {
            dfs(i);
            if(Gata==1)
            {
                cout<<"No";
                return 0;
            }
        }
    cout<<"Yes";
    return 0;
}
/**
**/


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int D,N;
    cin>>D>>N;

    int x=1;
    rep(i,D)x*=100;
    if(N==100)N++;
    cout<<x*N<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;int n,m,d,x,q,a,c[100010];int main(){while(cin>>d&&d){cin>>n>>m;c[0]=a=0;for(q=1;q<n;q++)cin>>c[q];sort(c,c+n);while(m--){cin>>q;x=lower_bound(c,c+n,q)-c;if(x==n)a+=min(d-q,q-c[n-1]);else a+=min(c[x]-q,q-c[x-1]);}cout<<a<<endl;}return 0;}

Measured memory_bytes: 3496