akhauriyash/Code-Regression huggingface dataset:
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

using ll = long long;
using Graph = vector<vector<int>>;

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN2(n,m);
  Vi X(m);
  VIN(X)
  SORT(X);
  Vi diff(m-1);
  REP(i,m-1){
    diff[i] = abs(X[i]-X[i+1]);
  }
  SORT(diff);
  if(n >= m){
    OUT(0);
  } else {
    REP(i,m-n){
      z += diff[i];
    }
    OUT(z);
  }
}

Measured memory_bytes: 1792
from itertools import permutations

N = int(input())
Plist = tuple(map(int, input().split()))
Qlist = tuple(map(int, input().split()))

perm = list(permutations(range(1, N+1)))
a = perm.index(Plist)
b = perm.index(Qlist)

print(abs(a-b))

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

/*  using namespace  */
using namespace std;

/*  local var  */
//None

/*  define  */
#define loop(i,j) for(int i = 0; i < j; i++)
#define scan1(d) scanf("%lld",&d);
#define scan2(a,b) scanf("%lld %lld",&a,&b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define print(a) printf("%lld\n",a);

/*  typedef  */
typedef long long ll;

/*  function  */
//None

/*  main program  */
int main()
{
	ll A,B,C,t;
	scan3(A,B,C);
	t=(3*max({A,B,C})-A-B-C);
	if(t%2)
		cout<<(t+3)/2<<endl;
	else
		cout<<t/2<<endl;
	
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n,k;
	std::cin >> n >> k;
	// either all 0 mod k or k/2 mod k
	int x = n/k;
	int xxx = x*x*x;
	if(k%2==0) {
		int y = (n+k/2)/k;
		int yyy = y*y*y;
		xxx+=yyy;
	}
	print(xxx);
	return 0;
}


Measured memory_bytes: 256
ma = 3010
dp = [[0] * ma for _ in range(ma)]
mod = 998244353


a, b, c, d = map(int, input().split())
dp[a][b] = 1
for i in range(b+1, ma):
    dp[a][i] = dp[a][i - 1] * a % mod
for i in range(a+1, ma):
    dp[i][b] = dp[i - 1][b] * b % mod


for i in range(a+1, ma):
    for j in range(b+1, ma):
        dp[i][j] = (-dp[i - 1][j - 1] * (i-1)*(j-1) +
                    dp[i - 1][j] * j + dp[i][j - 1] * i) % mod
print(dp[c][d])


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

long long N, M, dp0[1 << 18], dp1[1 << 18], mod = 1000000007;

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

	dp0[0] = 1; long long r0 = 0;
	dp1[0] = 1; long long r1 = 0;
	for (int i = 1; i <= N; i++) {
		r0 += dp0[i - 1]; r0 %= mod;
		r1 += dp1[i - 1]; r1 %= mod;
		if (i >= M) { r0 -= dp0[i - M]; r0 = (r0 + mod) % mod; }

		dp0[i] = r1;
		dp1[i] = r0;
	}

	long long v = 1;
	for (int i = 1; i <= N; i++) { v *= 2; v %= mod; }

	cout << (v - (dp0[N] + dp1[N]) + mod * mod) % mod << endl;
	return 0;
}


Measured memory_bytes: 4648
#include <iostream>
#include <string>

using namespace std;

struct node {
    int data;
    struct node *next, *prev;
};

class list{
public:
    node *head, *tail;
    list():head(NULL),tail(NULL){};
    void insert(int x) {
        node *c = new node;
        c->data=x;
        c->prev=NULL;
        c->next = head;
        if(head==NULL) {
            head=tail=c;
        } else {
            head->prev=c;
            head=c;
        }
    }
    void deleteFirst() {
        node *c = head;
        head = head->next;
        if(head) head->prev=NULL;
        else tail=NULL;
        delete c;
    }
    void deleteLast() {
        node *c = tail;
        tail = tail->prev;
        if(tail) tail->next=NULL;
        else head=NULL;
        delete c;
    }
    void deletex(int x) {
        node *c;
        for(c=head; c!=NULL && c->data!=x; c=c->next);
        if(c==NULL) return;
        if(c->prev==NULL) deleteFirst();
        else if(c->next==NULL) deleteLast();
        else {
            c->prev->next = c->next;
            c->next->prev = c->prev;
            delete c;
        }
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    string com;
    int x;
    list li;
    for(int i=0; i<n; i++) {
        cin>>com;
        if(com[0]=='i') {
            cin>>x;
            li.insert(x);
        } else if(com[6]=='F') {
            li.deleteFirst();
        } else if(com[6]=='L') {
            li.deleteLast();
        } else {
            cin>>x;
            li.deletex(x);
        }
    }
    bool first=true;
    for(node *c=li.head; c; c=c->next) {
        if(!first) cout<<' ';
        else first=false;
        cout<<c->data;
    }
    cout<<'\n';
    return 0;
}

Measured memory_bytes: 32464
#include <iostream>
#include<stdio.h>
using namespace std;

int main()
{
   int a,b,c,d,e,max1;
   scanf("%d%d",&a,&b);
   c=a+b;
   d=a-b;
   e=a*b;
   max1=c;
   if(max1<d)
    max1=d;
   if(max1<e)
    max1=e;
   printf("%d\n",max1);
    return 0;
}


Measured memory_bytes: 888
// In the name of god
#include <bits/stdc++.h>
#pragma GCC optimze("02")
#define F first
#define S second
#define pb push_back
using namespace std;
using ll = long long;
const ll maxn=105,inf=1e18+18;
ll n,a[maxn],dp[maxn],x,m,y,z;
int main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		dp[i]=1000;
	}
	for(int i=0;i<n-1;i++){
		x=dp[i];
		for(int j=i+1;j<n;j++){
			y=x/a[i];
			z=x%a[i];
			z+=y*a[j];
			dp[j]=max(dp[j],max(dp[i],z));			
		}
	}
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#define ll long long
using namespace std;

int main(){
//  cout<<123<<endl;
  int N;
  cin>>N;
  vector <int> a(2*N);
  for(int i=0;i<=2*N-1;i++){
    cin>>a[i];
  }
  sort(a.begin(), a.end());
  int ans=0;
  for(int i=0;i<2*N;i++){
    ans += i%2==0 ? a[i] : 0;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#-------------
X = int(input())
#-------------
if 400 <= X <= 599 :
  print("8")
elif 600 <= X <= 799 :
  print("7")
elif 800 <= X <= 999 :
  print("6")
elif 1000 <= X <= 1199 :
  print("5")
elif 1200 <= X <= 1399 :
  print("4")
elif 1400 <= X <= 1599 :
  print("3")
elif 1600 <= X <= 1799 :
  print("2")
elif 1800 <= X <= 1999 :
  print("1")

Measured memory_bytes: 9188
x,y=map(int,input().split())
a=abs(abs(x)-abs(y))
if x==0:
  if y<0:
    print(a+1)
  else:
    print(a)
elif y==0:
  if x<0:
    print(a)
  else:
    print(a+1)
elif y*x>0 and y>x:
  print(a)
elif y*x>0 and x>y:
  print(a+2)
elif y*x<0:
  print(a+1)


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  int n; cin >> n;
  string s; cin >> s;
  int ans = 0;

  for (int i = 0; i < 1000; i++) {
    vector<int> targets = {i / 100, i / 10 % 10, i % 10};
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      if (s[j] - '0' == targets[cnt]) cnt++;
    }
    if (cnt == 3) ans++;
  }
  outl(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
	for (;;) {
		int x, y, s;
		cin >> x >> y >> s;

		if (x == 0 && y == 0 && s == 0) {
			break;
		}
		int max_s = 0;

		int past_n1, past_n2;
		for (int i = 1; i < s; ++i) {
			past_n1 = (i * 100) / (100 + x);

			past_n2 = ((s - i) * 100) / (100 + x);

			if (((past_n1+1)*(100 + x) / 100 + (past_n2*(100 + x) / 100)) == s) {
				past_n1++;
			}
			else if (((past_n1)*(100 + x) / 100 + ((past_n2 + 1)*(100 + x) / 100)) == s) {
				past_n2++;
			}
			else if ((((past_n1 + 1)*(100 + x) / 100 + ((past_n2 + 1)*(100 + x) / 100)) == s)) {
				past_n1++;
				past_n2++;
			}

			if (past_n1 == 0 || past_n2 == 0) {
				continue;
			}

			int new_s = past_n1*(100 + y) / 100 + past_n2*(100 + y) / 100;
			//printf(" %d -> %d %d ->%d %d\n", i, past_n1, s-i, past_n2, new_s);
			if (new_s > max_s) {
				max_s = new_s;
			}
		}

		printf("%d\n", max_s);
	}
	return 0;
}

Measured memory_bytes: 1144
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,x,y,z;
double d,e,f;
string s,t;
//

signed main() {
  RAPID;
  IN2(a,b);
  OUT((a-1)*(b-1));
}

Measured memory_bytes: 256
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

ll powmod(ll x, ll k) {
	ll ans = 1;
	for (; k; k >>= 1, x = (x * x) % hell)
		if (k & 1)
			ans = (ans * x) % hell;
	return ans % hell;
}

const ll sz = 200009;
ll dp[sz];

ll dfs(ll n) {
	if (n < 3)	return 0;

	ll &res = dp[n];
	if (res == -1) {
		res = 0;
		for (ll i = 3; n - i >= 3; i++) {
			res += dfs(n - i);
			if (res >= hell)	res %= hell;
		}
		res %= hell;
	}

	return res + 1;
}

int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

	ll t, i, x, j, y, 	z, k, n;
	cin >> n;
	memset(dp, -1, sizeof(dp));
	t = dfs(n) % hell;
	debug(t);
	ce(t);
}



Measured memory_bytes: 5236
// Problem Code: abc176_a

#include <bits/stdc++.h>

using namespace std;

int A(int N, int X, int T) {
	int x = (N + X - 1) / X;
	return x * T;
}

int main() {
	int N, X, T;
	cin >> N >> X >> T;
	cout << A(N, X, T);
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>

inline int get_function(const u_int x)
{
    return x * x;
}

int get_integral(const u_int x, const u_int d)
{
    u_int ans, num_of_iter = x / d;
    for(u_int i = 1; i < num_of_iter; ++i)
        ans += d * get_function(d * i);
    return ans;
}

int main()
{
    const u_int x = 600;
    u_int d;
    while(std::cin >> d)
        std::cout << get_integral(x, d) << std::endl;
    
    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#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 drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    ll n,k;cin>>n>>k;
    vl a(n);rep(i,n)cin>>a[i];
    vl sum(n+1);
    rep(i,n) a[i]--;
    rep(i,n){
        sum[i+1]=(sum[i]+a[i])%k;
    }
    map<ll,ll> mp;
    ll ans=0;
    queue<ll> q;
    rep(i,n+1){
        ans+=mp[sum[i]];
        mp[sum[i]]++;
        q.push(sum[i]);
        if(q.size()==k){
            mp[q.front()]--;
            q.pop();
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 17536
#!/usr/bin/env ruby

(n, m, x, y) = gets.chomp.split(/ /).map(&:to_i)
xs = gets.chomp.split(/ /).map(&:to_i)
ys = gets.chomp.split(/ /).map(&:to_i)

xs << x
ys << y

xs.sort!
ys.sort!

if (xs[-1] < ys[0])
  puts 'No War'
else
  puts 'War'
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// 0 - indexed
template <typename Monoid>
struct Segmenttree
{
    using F = function<Monoid(Monoid, Monoid)>;
    const Monoid e;
    const F f;

    int sz;
    vector<Monoid> seg;

    // size, operator, unit
    Segmenttree(int N, const F f, const Monoid e) : f(f), e(e)
    {
        sz = 1;
        while (sz < N)
            sz *= 2;
        seg.assign(2 * sz - 1, e);
    }

    void set(int k, const Monoid &x) { seg[k + sz - 1] = x; }
    void build()
    {
        for (int k = sz - 2; k >= 0; k--)
        {
            seg[k] = f(seg[2 * k + 1], seg[2 * k + 2]);
        }
    }

    void update(int k, const Monoid &x)
    {
        k += sz - 1;
        seg[k] = x;
        while (k > 0)
        {
            k = (k - 1) / 2;
            seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2]);
        }
    }

    Monoid sub_query(int a, int b, int k, int l, int r)
    {
        if (r <= a || b <= l)
            return e;

        if (a <= l && r <= b)
            return seg[k];
        else
        {
            Monoid vl = sub_query(a, b, k * 2 + 1, l, (l + r) / 2);
            Monoid vr = sub_query(a, b, k * 2 + 2, (l + r) / 2, r);
            return f(vl, vr);
        }
    }

    // [l, r)
    Monoid query(int l, int r)
    {
        return sub_query(l, r, 0, 0, sz);
    }

    Monoid operator[](const int &k) const
    {
        return seg[k + sz];
    }
};

int main()
{
    int N;
    cin >> N;
    Segmenttree<int> seg(N, [](int a, int b) { return gcd(a, b); }, 0);
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        seg.set(i, a);
    }
    seg.build();

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans = max(gcd(seg.query(0, i), seg.query(i + 1, N)), ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
	static final long MOD = 1000000007L;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		
		int N = sc.ni();
		int K = sc.ni();
		int[] nums = new int[N];
		for (int i = 0; i < N; i++) {
			nums[i] = sc.ni();
		}
		for (int i = K; i < N; i++) {
			if (nums[i] > nums[i-K])
				pw.println("Yes");
			else
				pw.println("No");
		}
		pw.close();
	}
	
    static class FastScanner { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        }
        
        int ni() { 
            return Integer.parseInt(next()); 
        }
  
        long nl() { 
            return Long.parseLong(next()); 
        } 
  
        double nd() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() {
            String str = ""; 
            try { 
                str = br.readLine(); 
            } catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str;
        }
    }
}

Measured memory_bytes: 56360
#include <stdio.h>
  #define N 100

  typedef struct{
    char a;
    char value;
  }Card_t;

  void bubble(Card_t A[],int v){
    int i,j;
    Card_t t;
    for(i=0;i<v;i++){
      for(j=v-1;j>=i;j--){
        if(A[j].value < A[j-1].value){
          t=A[j];
          A[j]=A[j-1];
          A[j-1]=t;
        }
      }
    }
  }

  void selection(Card_t A[],int v){
    int i,j;
    int minj;
    Card_t t;
    for(i=0;i<v;i++){
      minj=i;
      for(j=i;j<v;j++){
        if(A[j].value<A[minj].value){
          minj=j;
        }
      }
        t=A[i];
        A[i]=A[minj];
        A[minj]=t;
      }
    }

  int isStable(Card_t C1[],Card_t C2[],int v){
   int i;
   for(i=0;i<v;i++){
     if(C1[i].a != C2[i].a) return 0; //false
   }
   return 1; //true
  }

  int main(){
    Card_t C1[N],C2[N];
    int v,i,j;
    char S[3];

    scanf("%d",&v);
    for(i=0;i<v;i++){
      scanf("%s",S);
      C1[i].a=S[0];
      C1[i].value=S[1];
    }

    for(i=0;i<v;i++){
      C2[i]=C1[i];
    }

    bubble(C1,v);
    selection(C2,v);
    for(i=0;i<v;i++){
      if(i>0) printf(" ");
      S[0]=C1[i].a;
      S[1]=C1[i].value;
      printf("%s",S);
    }
    printf("\n");
    printf("Stable\n");

    for(i=0;i<v;i++){
      if(i>0) printf(" ");
      S[0]=C2[i].a;
      S[1]=C2[i].value;
      printf("%s",S);
    }
    printf("\n");
    if(isStable(C1,C2,v)==1) {
      printf("Stable\n");
    } else {
      printf("Not stable\n");
    }
    return 0;
  }

Measured memory_bytes: 608
#include<iostream>
using namespace std;
int main(){
  int a;
  scanf("%d",&a);
  int L=a/100;
  int R=a%100;
  if(1<=L && L<=12){
      if(1<=R && R<=12){
        cout << "AMBIGUOUS" << endl;
      }else{
        cout << "MMYY" << endl;
      }
  }
  else if(1<=R && R<=12){
    cout << "YYMM" << endl;
  }else{
    cout << "NA" << endl;
  }
  return 0;
}
  
    

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;
//using Graph = vector<vector<int>>;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> P;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n)  for(int i=0; i<(n); i++)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}
LL sum(LL a, LL b){
    LL cnt=0;
    cnt=(b-a+1)*(a+b)/2;
    return cnt;
}
/*LL yaku(int x){
    vector<pair<LL, LL> a=[];
    LL xh;
    if(x==1){
        pair<LL, LL> tmp;
        tmp=MP(1,1);
        return tmp;
    }
    else{
        FOR(i, 1, x/2+1){
            if(x%i==0){
                a.append(MP(i,x/i));
            }
        }
    }
    return a;

}*/
LL cul(int a, int b){
    LL f = pow(a,4)+pow(a,3)*b+pow(a,2)*pow(b,2)+a*pow(b,3)+pow(b,4);
    return f;
} 
int main(){
    int x;
    cin >> x;
    cout << x*x*x << endl;
}
    





Measured memory_bytes: 3092
N, K = map(int, input().split())
dp = [[0] * (N + 1) for _ in range(N + 1)]
#dp[i][j]...コンビネーションiCj
mod = 10 ** 9 + 7

for i in range(N + 1):
	for j in range(N + 1):
		if j == 0:
			dp[i][j] = 1
		elif i > 0:
			dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % mod
			
for i in range(K):
	print((dp[K - 1][i] * dp[N - K + 1][i + 1]) % mod)

Measured memory_bytes: 75484
#include<stdio.h>
#include<string.h>
#define N 100005
 
typedef struct Name
{

  char name[100];
  int t;

} Name;
 
Name dequeue();

int min();
void enqueue();

Name Q[N];

int head,tail,n;
 
int main(){

  int e=0,c,i,q;
  Name x;

  scanf("%d%d",&n,&q);

  for(i=1;i<=n;i++){

    scanf("%s",Q[i].name);

    scanf("%d",&Q[i].t);

  }
  
  head = 1;
  tail = n+1;
  
  while( head != tail ){

    x = dequeue();

    c = min(q,x.t);

    x.t=x.t-c;

    e = e + c;

    if( x.t > 0 ) enqueue(x);

    else printf("%s %d\n",x.name,e);

  }

  return 0;
}
 
void enqueue( Name x ){

  Q[tail] = x;
  tail = (tail+1) % N;

}
 
Name dequeue(){

  Name x;
  x = Q[head];
  head=(head+1) % N;
  return x;
}
 
int min(int a,int b){

  return a < b ? a : b;

}

Measured memory_bytes: 10756
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




vector<pair<char, int> > runlength(string str) {
    vector<pair<char, int> > ret;
    int cnt = 1;
    int n = sz(str);
    rep3(i, 1, n) {
        if (str[i] == str[i - 1]) {
            cnt++;
        } else {
            ret.eb(make_pair(str[i - 1], cnt));
            cnt = 1;
        }
    }
    ret.eb(make_pair(str[n - 1], cnt));
    return ret;
}

pii calc(int m, int n, int x, int y) {
    return pii(m * x - n * y, m * y + n * x);
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    int q;
    cin >> q;
    while (q--) {
        ll m, n;
        cin >> m >> n;
        /*
        set<pii> s;
        s.insert(pii(1, 0));
        s.insert(pii(0, 1));
        s.insert(pii(-1, 0));
        s.insert(pii(0, -1));
        s.insert(pii(m, n));
        s.insert(pii(-m, n));
        s.insert(pii(m, -n));
        s.insert(pii(-m, -n));
        
        s.insert(calc(m, n, 1, 0));
        s.insert(calc(m, n, 0, 1));
        s.insert(calc(m, n, -1, 0));
        s.insert(calc(m, n, 0, -1));
        s.insert(calc(m, n, m, n));
        s.insert(calc(m, n, -m, n));
        s.insert(calc(m, n, m, -n));
        s.insert(calc(m, n, -m, -n));
        for (auto e : s) cout << e.F << " " << e.S << endl; cout << endl;
        int cnt = 0;
        for (auto e : s) {
            cout << "e " << e.F << " " << e.S << endl;
            if (e.F * e.F + e.S * e.S > 1) {
                cnt++;
                cout << e.F << " " << e.S << endl;
            }
        }
        cout << cnt << endl;
        if (cnt != 8) {
            cout << "C" << endl;
            continue;
        }
        cout << "P" << endl;
         */
        
        vector<pair<ll, ll> > v;
        for (ll i = -500; i < 500; ++i)  for (ll j = -500; j < 500; ++j) {
            if (i * i + j * j == 0) continue;
            if ((i * m + j * n) % (i * i + j * j)) continue;
            if ((i * n - j * m) % (i * i + j * j)) continue;
            
            ll x = (i * m + j * n) / (i * i + j * j);
            ll y = (i * n - j * m) % (i * i + j * j);
            
            if ((i * x - j * y) == m && (i * y + j * x) == n) {
                if ((i * i + j * j) * (x * x + y * y) != m * m + n * n) continue;
            }
            
            v.eb(pii(i, j));
        }
        // rep(i, sz(v)) cout << v[i].F << " " << v[i].S << endl;
        if (sz(v) == 8) cout << "P" << endl;
        else cout << "C" << endl;
    }
}





Measured memory_bytes: 3032
#include<iostream>
#include<map>
 
using namespace std;
 
typedef long long ll;
 
ll mod = 1000000007;
 
//nが素数かを判定する関数
bool prime(int n){
  bool x = true;
  for(int i=2;i*i<=n;i++)
    if(n%i==0) x = false;
  return x;
}
 
//a^pを求める関数
ll modpow(ll a,ll p){
  if(p==0) return 1;
  if(p%2==0){
    ll halfP = p/2;
    ll half = modpow(a,halfP);
    return half * half % mod;
  }
  else{
    return a * modpow(a,p - 1) % mod;
  }
}
 
//aCb mod 1000000007を求める
long comb(ll a,ll b){
  if(b>a-b) return comb(a,a-b);
  ll ansMul = 1;
  ll ansDiv = 1;
  for(int i=0;i<b;i++){
    ansMul *= (a-i);
    ansDiv *= (i+1);
    ansMul %= mod;
    ansDiv %= mod;
  }
  ll ans = ansMul * modpow(ansDiv,mod-2) % mod;
  return ans;
}
 
int main(){
  ll N,M;
  cin >> N >> M;
  ll i;
  map<ll,int> mp;
  ll count;
  ll ans = 1;
  for(i=2;i*i<=M;i++){
    if(M%i==0 && prime(i)){
      count = 0;
      while(M%i==0){
        M /= i;
        mp[i]++;
      }
      mp[i] += count;
    }
  }
  if(M!=1) mp[M]++;
  for(auto i : mp){
    ans *= comb(i.second + N - 1, i.second);
    ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define mod 1000000007
unordered_map<ll,vector<ll>> adj;
vector<ll> vis(300005,0);
vector<ll> p(100005,0);
ll c[100005];
ll cnt;
void dfs(ll node)
{
  if(vis[node])
    return;
  vis[node]=1;
  cnt++;
  for(auto i:adj[node])
    {
      dfs(i);
    }
}
ll modexpo(ll x,ll n,ll M){
    if(n==0)return 1;
    else if(n%2 == 0)return modexpo((x*x)%M,n/2,M);
    else return(x*modexpo((x*x)%M,(n-1)/2,M))%M;
}
int main()
{
  ll s,i,j;
  cin>>s;
  ll count[s+1];
  memset(count,0,sizeof(count));
  count[0]=1;
  for(i=1;i<=s;i++)
  {
      for(j=3;j<=s;j++)
        {
           if(i>=j)
            count[i]=(count[i-j]+count[i])%mod;
        }
  }
  cout<<count[s];}

Measured memory_bytes: 6232
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using ll = long long;
#define ull unsigned ll
#define endl "\n"
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(),(v).end()
#define mst(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<int, pii>
#define mt make_tuple
#define eb emplace_back
using namespace std;

const int N = 10, mod = 1e9 + 7;
const ll inf = 1e18;
int n, m, k, tb, sl, sr;
int a[N], b[N];
string s[N];
int ans;
void solve(){
    ll a;
    long double b;
    cout << fixed << setprecision(11);
    cin >> a >> b;
    b = b * 100.0 + 0.5;
    ll c = b;
    a = a * c;
    cout << a/100 << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);//cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t,p;
    t=1;
    //cin>>t;
    for(p=1;p<=t;p++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3724
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), k = scanner.nextInt();
			int[] x = new int[n], y = new int[n];
			IntStream.range(0, n).forEach(i -> {
				x[i] = scanner.nextInt();
				y[i] = scanner.nextInt();
			});
			long answer = Long.MAX_VALUE;
			int[] sortedX = x.clone();
			int[] sortedY = y.clone();
			Arrays.sort(sortedX);
			Arrays.sort(sortedY);
			for (int xi = 0; xi < n; xi++) {
				for (int xj = xi + 1; xj < n; xj++) {
					for (int yi = 0; yi < n; yi++) {
						for (int yj = yi + 1; yj < n; yj++) {
							int count = 0;
							for (int i = 0; i < n; i++) {
								if ((sortedX[xi] <= x[i]) && (x[i] <= sortedX[xj]) && (sortedY[yi] <= y[i])
										&& (y[i] <= sortedY[yj])) {
									count++;
								}
							}
							if (count >= k) {
								answer = Math.min(answer,
										1L * (sortedX[xj] - sortedX[xi]) * (sortedY[yj] - sortedY[yi]));
							}
						}
					}
				}
			}
			System.out.println(answer);
		}
	}
}


Measured memory_bytes: 38168
H, W, K = map(int, input().split())
c = [input() for _ in range(H)]
ybla = [0]*H
xbla = [0]*W
all_black = 0
for i in range(H):
    all_black += c[i].count('#')
    ybla[i] += c[i].count('#')
    for j in range(W):
        if c[i][j] == '#':
            xbla[j] += 1

# print(ybla, xbla)
ans = 0
for i in range(2**H):
    y = []
    total1 = 0
    for j in range(H):
        if (i >> j) & 1:
            y.append(j)
            total1 += ybla[j]
    # print(y, total)
    for k in range(2**W):
        x = []
        total2 = 0
        for l in range(W):
            if (k >> l) & 1:
                # print(bin(k), l)
                x.append(l)
                total2 += xbla[l]
        total = total1 + total2
        if len(y) and len(x):
            for yy in y:
                for xx in x:
                    if c[yy][xx] == '#':
                        total -= 1
        # print(y, x, total, total1, total2)
    
        if all_black == K + total:
            ans += 1

print(ans)
        


Measured memory_bytes: 9204
#########################################.#..################....##..........
###################.#####################..#.##################.....#........
####################.#####################.#..#######..##########......#.....
####################..####################....####...#.....######.###........
#####################################....#...##...###..#.......##..####......
################.##.#....#########........#.#........##.###..................
#################.#..#....##..#..........#.##........##.#######..............
########.########.....#.....##.............####...#..#...########..#.........
#########.########.....#...................########..#...########...#.##.....
#####..###..####.....#####..................#######.......##.####..#....#....
#####.....#.....##########...................#####........#..###..#.......##.
#####........#####.##....##.#............................###.##..#...........
#####......######.........................#.................##...............
#####.....########....................................##....#................
#####.....##############......................#...........##.#...............
######...###############.....................................................

a, b, t = map(int, input().split())
print(b * (t // a))

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n, m;
	cin >> n >> m;
	vector<pii> lane(n);
	REP(i, n) {
		lane[i].first=lane[i].second = i;
	}
	vector<pii> arms(m);
	REP(i,m) {
		cin >> arms[i].first >> arms[i].second;
	}
	SORT(arms);
	REP(i, m) {
		lane[arms[i].second - 1].second = lane[arms[i].second].second;
		lane[arms[i].second].first = lane[arms[i].second-1].first;
	}
	cout << lane[0].second - lane[0].first + 1;
	FOR(i,1, n) {
		cout <<" "<< lane[i].second - lane[i].first + 1;
	}
	cout << endl;
}

Measured memory_bytes: 5124
import sys

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b / gcd(a, b)

for s in sys.stdin:
    a, b = map(int, s.split())
    print "%d %d"%(gcd(a, b), lcm(a, b))

Measured memory_bytes: 6344
#include <iostream>

using namespace std;

int main(){
    int A[3][3];
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin >> A[i][j];
        }
    }

    int N;
    cin >> N;
    int b[N];
    for(int i=0; i<N; i++){
        cin >> b[i];
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(b[i] == A[j][k]) A[j][k]=-1;
            }
        }
    }

    bool fl = false;
    for(int i=0; i<3; i++){
        if(A[i][0] == -1 && A[i][1] == -1 && A[i][2] == -1) fl = true;
        if(A[0][i] == -1 && A[1][i] == -1 && A[2][i] == -1) fl = true;
    }
    if(A[0][0] == -1 && A[1][1] == -1 && A[2][2] == -1) fl = true;
    if(A[0][2] == -1 && A[1][1] == -1 && A[2][0] == -1) fl = true;

    if(fl) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 404,mo=998244353;const ll MOD=7ll*mo*mo;
inline int power(int a, int n) {
	int res=1;
	while (n) {
		if (n&1) res=1LL*res*a%mo;
		a=1LL*a*a%mo; n>>=1;
	}
	return res;
}
int n,a[N],f[N][N],tot,dp1[N][N],dp2[N][N],C[N][N],mi[N*N],xs1[N][N],xs2[N][N];
int solve(int l, int r, int bas){
	if(l>r)return 0;
	int mn=l;rep(i,l,r)if(a[i]<a[mn])mn=i;
	int u=++tot;
	int lc=solve(l,mn-1,a[mn]),rc=solve(mn+1,r,a[mn]);
	int h=a[mn]-bas;
	memset(dp1,0,sizeof(dp1));
	rep(k,0,h)rep(j,0,mn-l)rep(q,0,mn-l-j){
		dp1[k][j]=(dp1[k][j]+1ll*xs2[j][h-k]*C[j+q][q]%mo*xs1[h-k][q]%mo*f[lc][j+q])%mo;//xs2[h-k][mn-l-j-q]%mo*
	//	if(k==0&&j==0)printf("zzy %d %d %d %d %d\n",xs2[j][h-k],C[mn-l-j][l],xs1[h-k][l],xs2[h-k][mn-l-j-l],f[lc][j+l]);
	}
	memset(dp2,0,sizeof(dp2));
	rep(k,0,h)rep(j,0,r-mn)rep(q,0,r-mn-j)dp2[k][j]=(dp2[k][j]+1ll*xs2[j][h-k]*C[j+q][q]%mo*xs1[h-k][q]%mo*f[rc][j+q])%mo;//xs2[h-k][r-mn-j-q]%mo*
	rep(k,0,h)rep(i,0,r-l+1){
		ll res=0;rep(j,0,i)res+=1ll*dp1[k][j]*dp2[k][i-j],res=res<MOD?res:res-MOD;
		rep(j,0,i-1)res+=1ll*dp1[k][j]*dp2[k][i-j-1],res=res<MOD?res:res-MOD;
		f[u][i]=(f[u][i]+res%mo*C[h][k]%mo*(k&1?mo-1:1)%mo*mi[h-k])%mo;
	//	if(r-l+1==3&&i==0)printf("qwq %d:%d %d %lld %lld\n",k,dp1[k][0],dp2[k][0],res%mo,res%mo*C[h][k]%mo*mi[h-k]%mo);//(k&1?mo-1:1)%mo*
	}
//	rep(i,0,r-l+1)printf("%d %d:%d\n",r-l+1,i,f[u][i]);
	rep(j,1,h){
		static int dp[N];memset(dp,0,sizeof(dp));dp[0]=1;
		rep(k,l,r){
			int cur=mi[a[k]-j-bas];
			per(i,k-l+1,0)dp[i]=(1ll*dp[i]*(cur-1)+1ll*(i-1>=0?dp[i-1]:0)*cur)%mo;
		}
		rep(i,0,r-l+1)f[u][i]=(f[u][i]+1ll*C[h][j]*(j&1?1:mo-1)%mo*dp[i])%mo;
	}
//	rep(i,0,r-l+1)printf("%d %d:%d\n",r-l+1,i,f[u][i]);
	return u;
}
int main() {
	n=400;
	rep(i,0,n){
		C[i][0]=C[i][i]=1;
		rep(j,1,i-1)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mo;
	}
	mi[0]=1;rep(i,1,n*n)mi[i]=2*mi[i-1]%mo;
	rep(i,0,n)rep(j,0,n)xs1[i][j]=power(mi[i]-1,j),xs2[i][j]=power(mi[i],j);//init
	
	read(n);rep(i,1,n)read(a[i]);
	f[0][0]=1;
	int rt=solve(1,n,0);
	cout<<f[rt][0];
	return 0;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
const int N=20010<<4;

struct E{
	int f,t,xt;
}e[N*20];

struct data{
	int x,t;
	data(int a=0,int b=0):x(a),t(b){}
	bool operator<(const data&a)const{
		return x<a.x;
	}
}a[N],tmp[N];

bool cmp(int x,int y){
	return a[x].x<a[y].x;
}	

int h[N],cnt;

void adge(int f,int t){
	e[++cnt]=(E){f,t,h[f]};h[f]=cnt;
}

int pre[N],low[N],dfs_clock,ssc_cnt,sscno[N];
stack<int> s;

void dfs(int u){
    pre[u]=low[u]=++dfs_clock;
    s.push(u); 
    for(int i=h[u];i>-1;i=e[i].xt){
        if(!pre[e[i].t]){
            dfs(e[i].t);
            low[u]=min(low[u],low[e[i].t]);
        }else if(!sscno[e[i].t]){
            low[u]=min(low[u],pre[e[i].t]);
        }
    }
    if(low[u]==pre[u]){
        ssc_cnt++;
        for(;;){
            int x=s.top();s.pop();
            sscno[x]=ssc_cnt;
            if(x==u) break;
        }
    }
}
int mx,id[N],n,ct,ls[N<<2],rs[N<<2];
void build(int &o,int L,int R){
	o=++ct;
	if(L==R){ mx=max(mx,o);id[L]=o;return;}
	int M=L+R>>1;
	build(ls[o],L,M);
	build(rs[o],M+1,R);
	adge(o,ls[o]);
	adge(o,rs[o]);
}

void link(int o,int L,int R,int x,int l,int r){
	if(l>r) return;
	if(l<=L&&r>=R){
		adge(x,o);
	}else{
		int M=L+R>>1;
		if(l<=M) link(ls[o],L,M,x,l,r);
		if(r>M) link(rs[o],M+1,R,x,l,r);
	}
}

bool check(int k){
	for(int i=1;i<=n;i++){
		int p=lower_bound(a+1,a+n+1,data(a[i].x-k,0))-a;
		if(a[p].x<a[i].x-k) p++;
		link(1,1,n,i+mx,p,i-1);
		p=lower_bound(a+1,a+n+1,data(a[i].x+k,0))-a;
		if(a[p].x>a[i].x+k||p>n) p--;
		link(1,1,n,i+mx,i+1,p);
	}
	for(int i=1;i<=mx+n;i++) sscno[i]=pre[i]=low[i]=0;
	for(int i=1;i<=mx+n;i++) if(!pre[i]) dfs(i);
	for(int i=1;i<=n;i++){ 
		if(sscno[id[i]]==sscno[i+mx]){ 
			return 0;
		}
	}
	return 1;
}	
		
int r[N],h2[N];

int main(){	
	int L=-1,R=0;
	memset(h,cnt=-1,sizeof(h));
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i].x,&a[i+n].x);
		R=max(R,max(a[i+n].x,a[i].x));
	}
	n=n<<1;
	for(int i=1;i<=n;i++) r[i]=i;
	sort(r+1,r+n+1,cmp);
	for(int i=1;i<=n;i++){
		if(r[i]>(n>>1)) a[r[i]-(n>>1)].t=i;
		else a[r[i]+(n>>1)].t=i;
	}
	for(int i=1;i<=n;i++) tmp[i]=a[r[i]];
	for(int i=1;i<=n;i++) a[i]=tmp[i];	
	int rt;
	build(rt,1,n);
	for(int i=1;i<=n;i++){
		adge(id[i],a[i].t+mx);
		adge(a[i].t+mx,id[i]);
	}
	int initcnt=cnt;
	for(int i=1;i<=n+mx;i++) h2[i]=h[i];
	while(R>L+1){
		int M=L+R>>1;
		if(check(M)) L=M;
		else R=M;
		for(int i=1;i<=n+mx;i++) h[i]=h2[i];
		cnt=initcnt;
	}
	printf("%d\n",L+1);
	return 0;
}
	


Measured memory_bytes: 29952
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
signed main(){
    int n,a;cin>>n>>a;
    n%=500;
    if(n-a<=0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CRally solver = new CRally();
        solver.solve(1, in, out);
        out.close();
    }

    static class CRally {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.nextArrInt(n);
            int best = Integer.MAX_VALUE / 2;
            for (int i = 1; i <= 100; i++) {
                int cost = 0;
                for (int j = 0; j < n; j++) {
                    cost += (a[j] - i) * (a[j] - i);
                }
                best = Math.min(best, cost);
            }

            out.println(best);
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream in) {
            this(new InputStreamReader(in));
        }

        public FastReader(InputStreamReader input) {
            br = new BufferedReader(input);
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    String s = br.readLine();
                    if (s == null)
                        return null;
                    st = new StringTokenizer(s);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextArrInt(int n) {
            int[] a = new int[n];
            for (int i = 0; i < a.length; i++)
                a[i] = nextInt();
            return a;
        }

    }
}



Measured memory_bytes: 23124
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	m = readline() |> parseInt
	i = 2
	n = m
	d = Dict{Int,Int}()
	while n>1&&i<sqrt(m)
		if n%i==0
			if haskey(d,i)
				d[i]+=1
			else
				d[i]=1
			end
			n = div(n,i)
		else
			i += 1
		end
	end
	if n!=1
		if haskey(d,n)
			d[n]+=1
		else
			d[n]=1
		end
	end
	x = 0
	for k in keys(d)
		i = 1
		while (i*(i+1))>>1<=d[k]
			i+=1
		end
		x += i-1
	end
	println(x)
end

main()

Measured memory_bytes: 162780