akhauriyash/Code-Regression huggingface dataset:
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=998244353;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int inc(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
typedef long long ll;
const int N=5e5+5,M=2.5e5;
const int bas[6]={691,769,823,877,911,967};
const int ib[6]={37560569,983965175,992179685,349442436,115055606,356147158};
struct node{
	int a[6];
	inline int& operator [](const int &x){return a[x];}
	inline bool operator <(const node &b)const{
		fp(i,0,5)if(a[i]!=b.a[i])return a[i]<b.a[i];
		return 0;
	}
	inline bool operator ==(const node &b)const{
		fp(i,0,5)if(a[i]!=b.a[i])return 0;
		return 1;
	}
}pr[N],bn[N],sm;
char s[N];int pos[N],n;
map<node,int>mp;ll res;
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%s",&n,s+1);
	fp(j,0,5)bn[M][j]=1;
	fp(i,1,n)fp(j,0,5){
		bn[i+M][j]=mul(bn[i-1+M][j],bas[j]);
		bn[-i+M][j]=mul(bn[-i+1+M][j],ib[j]);
	}
	for(R int p=0,i=1;i<=n;++i){
		switch(s[i]){
			case '>':++p;break;
			case '<':--p;break;
			case '+':{
				fp(j,0,5)upd(sm[j],bn[p+M][j]);
				break;
			}
			case '-':{
				fp(j,0,5)upd(sm[j],P-bn[p+M][j]);
				break;
			}
		}
		fp(j,0,5)pr[i][j]=sm[j];
		pos[i]=p;
	}
	++mp[sm];
	fp(i,1,n){
		res+=mp[pr[i]];
		fp(j,0,5)upd(pr[i][j],mul(sm[j],bn[pos[i]+M][j]));
		++mp[pr[i]];
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 58752
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>

#define x 0
#define y 1
using namespace std;

int main()
{
    double a[2][2];
    double b[2][2];
    bool flag;
    while(cin >> a[0][x] >> a[0][y] >> a[1][x] >> a[1][y])
    {
        cin >> b[0][x] >> b[0][y] >> b[1][x] >> b[1][y];
        flag = !(a[1][x] < b[0][x] || b[1][x] < a[0][x] ||
                 a[1][y] < b[0][y] || b[1][y] < a[0][y] );
        if(flag) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>    
#include <unordered_map>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cerr<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define endl "\n"
#define fo(i,n) for(int i=0;i<n;i++)
#define foo(i,x,n) for(int i=x;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define w(x) int x;cin>>x;while(x--)
#define display(a,n) {fo(i,n) {cout<<a[i]<<" ";}cout<<endl;}
#define fil(a,n,val) {fo(i,n) a[i]=val; }
#define sp(x,y) cout<<fixed<<setprecision(y)<<x<<endl;
const ll MOD   = 1000*1000*1000+7;
const ll MOD2  = 998244353;
const ll N = 1000*1000+5;
const double PI  = 3.14159265;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
ll search(vl arr, ll l, ll r, ll x){if (r >= l) {ll mid = l + (r - l) / 2;if (arr[mid] == x)return mid;if (arr[mid] > x)return search(arr, l, mid - 1, x);return search(arr, mid + 1, r, x);} return -1;}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll lcm(ll a , ll b){return (a*b)/ gcd(a,b);}
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p; } return res; }
ll modInverse(ll n, ll p){return power(n, p-2, p);}
const int maxn=3e5+5;

int n;
ll dp[3005][3005];
ll a[3005];

ll solve(int i , int j){
	if(i>j)
		return 0;
	if(i==j)
		return a[i];
	if(dp[i][j]!=-1)
		return dp[i][j];
	return dp[i][j]=max(a[i]+min(solve(i+1,j-1),solve(i+2,j)), a[j]+min(solve(i+1,j-1),solve(i,j-2)));
}

int main(){
	fastio();
	cin>>n;
	ll sum=0;
	fo(i,n) {cin>>a[i];sum+=a[i];}
	fill(dp,-1);

	cout<<2ll*solve(0,n-1)-sum<<endl;

}

Measured memory_bytes: 74280
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
 
 
int main() {
    string S;
    cin >> S;
    if(S[3]==S[2]&&S[4]==S[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;

    long ans = 0;
  
    for(int b = k + 1; b <= n; b++)
    {
        ans += (n / b) * (b - k) + max( 0, (n % b) - k + 1);
    }
    if(k == 0) ans -= n - k;
    cout << ans << endl;
}



Measured memory_bytes: 256
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	cout << (n + 1) / 2 << endl;
}


Measured memory_bytes: 256
n=gets.to_i
a = gets.split(' ').map(&:to_i)
#h=gets.split(' ').map(&:to_i)
right = Array.new()
left = Array.new()
left[0] = a[0]
right[n-1] = a[n-1]
for i in 1..n-1
  left[i] = left[i-1].gcd(a[i])
end

(n-2).downto(0) do |i|
  right[i] = right[i+1].gcd(a[i])
end



max=0
for  i in 1..n-2
  smp = left[i-1].gcd(right[i+1])
  if smp > max
    max = smp
  end
end

#puts [left[n-1],right[0],max].max
puts [right[1],left[n-2],max].max

Measured memory_bytes: 10324
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define mp make_pair
#define P pair<int,int>

int main() {
	int V;
	cin >> V;
	int E = V - 1;
	vector<int>A(E);
	vector<int>B(E);
	rep(i, E) {
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}
	vector<vector<int>>G(V);
	rep(i, E) {
		G[A[i]].push_back(B[i]);
		G[B[i]].push_back(A[i]);
	}
	int max_color = 0;
	rep(i, V) {
		max_color = max(max_color, int(G[i].size()));
	}
	
	vector<set<int>>SC(V);
	vector<map<int, int>>MC(V);
	rep(i, V) {
		rep(j, G[i].size()) {
			MC[i][G[i][j]] = -1;
		}
	}

	int color = 0;
	map<int, int>::iterator it;
	rep(i, V) {
		color = 0;
		for (it = MC[i].begin(); it != MC[i].end(); it++) {
			if (it->second == -1) {
				while (1) {
					if (SC[i].count(color)) {
						color++;
					}
					else {
						it->second = color;
						MC[it->first][i] = color;
						SC[i].insert(color);
						SC[it->first].insert(color);
						break;
					}
				}
			}
		}
	}
	
	cout << max_color << endl;
	rep(i, E) {
		cout << MC[A[i]][B[i]] + 1 << endl;
	}

}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define repi(i,a,b) for(int i = (a); i<= (b); i++)
#define repA(i,n) for(int i=n; i>=0; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (int)(a.size())
#define fastio ios::sync_with_stdio(0);cin.tie(0); cout.tie(0)

typedef long long ll;
typedef long double ld;
const ll mod = (ll)(1e9+7);//998244353;
const int N = (int)(1e6+5);

int n,t;

void solve() {

}

int main() {
  fastio;
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  #endif
  //cin>>t;rep(i,t)solve();

  cin>>n;
  int ans = n/1000;

  n -= ans*1000;

  n = 1000 - n;

  cout<<(n%1000);

  return 0;
}


Measured memory_bytes: 3648
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);

    int N, T;
    int c[100], t[100];
    cin >> N >> T;
    int m1, m2;
    for (int i = 0; i < N; i++) {
        cin >> c[i] >> t[i];
    }

    int min = 10000;
    for (int i = 0; i < N; i++) {
        if (t[i] <= T) {
            if (c[i] < min) {
                min = c[i];
            }
        }
    }

    if (min == 10000) {
        cout << "TLE" << endl;
    } else {
        cout << min << endl;
    }

    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define cases long long test;cin>>test;while(test--)
#define f_io ios::sync_with_stdio(false); cin.tie(0)
#define foi(a,n) for(long long i=a;i<n;i++)
#define foj(a,n) for(long long j=a;j<n;j++)
#define fok(a,n) for(long long k=a;k<n;k++)
#define ll long long
#define MOD 1000000007
#define INF 1000000000
using namespace std;

int main()
{
    f_io;
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans = max(a*c,b*d);
    ans = max(ans,a*d);
    ans = max(ans,b*c);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
int dx8[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };




int main()
{
  int N,M;
  cin >> N >> M;
  vector<pll> a;
  rep(i,N){
      ll x;
      cin >> x;
      a.push_back({x,1});//もとのやつは一枚ずつ
  };

  rep(i,M){
      int b,c;
      cin >> b >> c;
      a.push_back({c,b});//cがb枚あるとする,簡単なのはcも一つずつとして、repで[c,c,c,c]みたいにすることだけど、Nが大きいので無理、なのでこうしている
  }

  sort(a.begin(),a.end(),greater<pll>());//ソートして大きいものからN個とっていき、その合計が答え

  ll sum=0;
  ll num=0;
  for(auto v:a){
      if(num+v.second <= N){
          //枚数分取れるとき
          sum += v.first*v.second;
          num += v.second;
      }else{
         //多くとりすぎた時
         sum += v.first*(N-num);
         num = N;
         break;//もうここまでしかとれないのでここでおわり
      }
  }

  fin(sum);
  
  
}



Measured memory_bytes: 6512
import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    N = int(input())
    Alist = []; Blist = []
    for _ in range(N):
        A, B = map(int, readline().split())
        Alist.append(A); Blist.append(B)
    Alist.sort()
    Blist.sort()
    i = N//2
    if N%2 == 0:
        medmin = (Alist[i] + Alist[i-1])
        medmax = (Blist[i] + Blist[i-1])
        ans = medmax - medmin + 1
    else:
        ans = Blist[i] - Alist[i] + 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 25560
#include <bits/stdc++.h>
using namespace std;
typedef pair <int,int> pii;
const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=1e5+50;
int n,a[N],b[N],step;
int anc[N],vis[N];
map <int,int> s;
set <int> pos[N];
inline void lsh(int *c) {
	vector <int> vec;
	for(int i=1;i<=n+1;i++) vec.push_back(c[i]);
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());
	for(int i=1;i<=n+1;i++) c[i]=lower_bound(vec.begin(),vec.end(),c[i])-vec.begin()+1; 
} 
inline int ga(int x) {return (anc[x]==x) ? x : (anc[x]=ga(anc[x]));}
inline void merge(int x,int y) {anc[ga(x)]=ga(y);}
int main() {
	n=rd();
	for(int i=1;i<=n;i++) a[i]=rd(), a[n+1]^=a[i], ++s[a[i]]; ++s[a[n+1]];
	for(int i=1;i<=n;i++) b[i]=rd(), b[n+1]^=b[i], --s[b[i]]; --s[b[n+1]];
	for(auto v:s) if(v.second) return puts("-1"),0;
	lsh(a); lsh(b); int m=*max_element(a+1,a+n+2);
	for(int i=1;i<=n+1;i++) 
		if((a[i]^b[i]) || i>n) pos[a[i]].insert(i);
	for(int i=1;i<=m;i++) anc[i]=i;
	for(int i=n+1;i;i--) if(i>n || (a[i]^b[i])){
		if(vis[i]) continue;
		vector <int> vec; 
		for(int j=b[i];;) {
			int nxt=*pos[j].begin();
			pos[j].erase(pos[j].begin());
			vec.push_back(nxt);
			if(nxt==i) break;
			else j=b[nxt];
		}
		for(auto j:vec) merge(b[j],b[i]), vis[j]=1; 
	}
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n+1;i++) if(a[i]^b[i] || i==n+1) {
		if(i<=n) ++step;
		if(!vis[ga(a[i])] && (ga(a[i])==a[i])) vis[ga(a[i])]=1, ++step;
	}
	cout<<step-1<<'\n';
}


Measured memory_bytes: 17000
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define ll long long 
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << endl;    
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n) 
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << ' ';
    cout << endl;
}
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
 
ll modulo = 1e9 + 7;

ll fpow(ll a, ll n) 
{
    ll ans = 1;
    while (n) 
    {
        if (n&1) ans = (ans*a)%modulo;
        a = (a*a)%modulo; n = n >> 1;
    }
    return ans;
}

void solve() 
{
    int n; cin >> n;
    map <string, int> d;
    For(i,0,n) {
        string s; cin >> s;
        ++d[s];
    }    
    vector < pair <int, string> > arr;
    for (auto a : d) {
        arr.pb({a.S,a.F});
    }
    sort(all(arr));
    n = arr.size();
    int max_val = arr[n-1].F;
    vector <string> ans;
    Forr(i,n-1,-1) {
        if (arr[i].F == max_val) {
            ans.pb(arr[i].S);
        }
        else {
            break;
        }
    }
    reverse(all(ans));
    for (string a : ans) {
        cout << a << endl;
    }
}

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

Measured memory_bytes: 30572
import java.util.Scanner;

/** https://atcoder.jp/contests/abc048/tasks/abc048_b */
public class Main {

  /**
   * メインメソッド
   *
   * @param args 実行時引数
   */
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long X = sc.nextLong();

    System.out.println(solve(a, b, X));
  }

  private static long solve(long a, long b, long x) {
    if (a > 0) {
      return b / x - (a - 1) / x;
    } else {
      return b / x + 1;
    }
  }
}


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

using namespace std;

int main()
{
  int a, b;
  
  cin >> a >> b;
  
  string s1;
  for (int i = 0; i < a; i++) {
    s1 += '0' + b;
  }
  string s2;
  for (int i = 0; i < b; i++) {
    s2 += '0' + a;
  }
  
  if (a > b) {
    cout << s1 << endl;
  }
  else {
    cout << s2 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,e) for(ll i=0;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;
ll i;



int main(){
    ll N;
    cin>>N;
    if(N%2)cout<<2*N;
    else cout<<N;
    cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fastinput ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{    
    fastinput;
    LL n,i,j,k,t,temp;
    cin>>n;
    LL h[n+4],dp[n+4];
    const LL INF=100000000000000000;
    for(i=1;i<=n;i++)
    {
        cin>>h[i];
        dp[i]=INF;
    }
    dp[1]=0;
    for(i=1;i<=n;i++)
    {
        dp[i+1]=min(dp[i+1],dp[i]+(LL)fabs(h[i]-h[i+1]));
        dp[i+2]=min(dp[i+2],dp[i]+(LL)fabs(h[i]-h[i+2]));
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;
int gcd(int a, int b) { while (a) { b %= a; swap(a, b); } return b; }
bool solve(int n, vector<int> & a) {
    ll sum = whole(accumulate, a, 0ll);
    bool is_first = (sum - n) % 2;
    int even = whole(count_if, a, [&](int ai) { return ai % 2 == 0; });
    auto odd = whole(find_if,  a, [&](int ai) { return ai % 2 == 1; });
    if (not is_first and even == n-1 and *odd != 1) {
        -- (*odd);
        int d = a[0]; repeat (i,n) d = gcd(d, a[i]);
        repeat (i,n) a[i] /= d;
        return not solve(n, a);
    } else {
        return is_first;
    }
}
int main() {
    int n; cin >> n;
    vector<int> a(n); repeat (i,n) cin >> a[i];
    cout << (solve(n, a) ? "First" : "Second") << endl;
    return 0;
}

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

using namespace std;

int main(){

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

  for(int j=0; j<m; j++){
    int ans=sum;
    int p, x;
    cin>>p>>x;
    ans=sum-a[p-1]+x;
    cout<<ans<<endl;
  }
}


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

int main()
{
  int n;
  while( cin >> n, n ) {
    int m;
    string s, tmp = "";
    cin >> m >> s;
    
    for(int i=0; i<n; i++) tmp += "IO";
    tmp += "I";
    int p = 0, cnt = 0;

    while( p != -1 ) {
      p = s.find(tmp, p+1);
      cnt++;
    }
  
    cout << cnt-1 << endl;
  }

}

Measured memory_bytes: 2120
# coding: utf-8
# Your code here!
D,G=map(int,input().split())

def saiki(n,point,ans,last):
    #print(point,ans)
    if n==D:
        if point>=G:
            lis.append(ans)
        else:
            if (G-point)<=(No[last]-1)*100*(last+1):
                lis.append(ans+(-(-(G-point)//(100*(last+1)))))
            else:
                pass#どう転んでも条件を満たさない
    else:
        saiki(n+1,point,ans,n)#足さない場合
        saiki(n+1,point+al[n],ans+No[n],last)#足す場合

No=[]
al=[]
for i in range(D):
    p,c=map(int,input().split())
    No.append(p)
    al.append(p*(i+1)*100+c)

#print(No,al)

lis=[]
saiki(0,0,0,0)

print(min(lis))

Measured memory_bytes: 3064
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <array>
#include <bitset>

using namespace std;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
// all_of

#if 1
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif
int N;
int D[300][300];
bool U[300][300];

int main() {
	cin >> N;
	REP(i, 0, N) {
		REP(j, 0, N) {
			cin >> D[i][j];
		}
	}
	Fill(U, true);
	REP(i, 0, N) {
		REP(j, 0, N) {
			REP(k, 0, N) {
				if (i == k || j == k) continue;
				if (D[i][j] > D[i][k] + D[k][j]) {
					cout << -1 << endl;
					return 0;
				} else if (D[i][j] == D[i][k] + D[k][j]) {
					U[i][j] = false;
				}
			}
		}
	}
	LL sum = 0;
	REP(i, 0, N){
		REP(j, i + 1, N) {
			sum += U[i][j] * D[i][j];
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> dp(100110);
  unordered_map<int, int> dest{};
  vector<ll> a(M);
  REP(i, M) {
    cin >> a[i];
    dest[a[i]]++;
  }
  REP(i, dp.size()) dp[i] = 0;
  dp[0] = 1;
  for (int i = 0; i < N; i++) {
    if (dest[i] != 0) continue;
    if (dest[i + 1] == 0) {
      dp[i + 1] += dp[i];
      dp[i + 1] %= MOD;
    }
    if (dest[i + 2] == 0) {
      dp[i + 2] += dp[i];
      dp[i + 2] %= MOD;
    }
  }
  cout << dp[N] << endl;
}

Measured memory_bytes: 8792
N,A,B,C = list(map(int,input().split()))
list = [int(input()) for _ in range(N)]

def dfs(cnt,a,b,c):
    if cnt == N:
        return abs(A-a)+abs(B-b)+abs(C-c) if min(a,b,c) > 0 else float('inf')
    l0 = dfs(cnt+1,a,b,c)
    la = dfs(cnt+1,a+list[cnt],b,c) +(10 if a != 0 else 0)
    lb = dfs(cnt+1,a,b+list[cnt],c) +(10 if b != 0 else 0)
    lc = dfs(cnt+1,a,b,c+list[cnt]) +(10 if c != 0 else 0)
    return min(l0,la,lb,lc)

print(dfs(0,0,0,0))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  int n; cin>>n;
  vector<int> a(n);
  rep(i, n) cin>>a[i];

  double sum = 0;
  rep(i, n) sum += a[i];
  double ave = sum / n;

  double mi = 10000;
  int ans = 0;
  rep(i, n) {
    if (mi > abs(a[i] - ave)) {
      mi = abs(a[i] - ave);
      ans = i;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3596
import sys
def input():
  return sys.stdin.readline().rstrip()

ma={"N":0,"S":0,"E":0,"W":0}

def func(S):
  for x in S:
    ma[x]=1
  if ma["N"]!=ma["S"]:
    return False
  if ma["W"]!=ma["E"]:
    return False
  return True

S=input()
print("Yes" if func(S) else "No")


Measured memory_bytes: 62012
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
   int a,b,c,d; cin>>a>>b>>c>>d;
   cout<<(a<b?a:b)+(c<d?c:d)<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

int N;

int f(int x) {
  if(x < 10) return x;
  return x % 10 + f(x/10);
}

bool harshad(int x) {
  return x % f(x) == 0;
}

int main () {
  cin >> N;

  cout << (harshad(N) ? "Yes" : "No") << endl;
  return 0;
}


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

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    rep(i,a+1){
        rep(j,b+1){
            rep(k,c+1){
                if(500*i + 100*j + 50*k == x){
                    ++ans;
                }
            }
        }
    }
    cout << ans << endl;
}


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


int main(){
  int A, B, C;
  cin >> A >> B >> C;
  set<int> ans;
  ans.insert(A);
  ans.insert(B);
  ans.insert(C);
  cout << (ans.size()==2?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 256
N=int(input())
XY=[[[]] for n in range(N+1)]
for n in range(1,N+1):
  a=int(input())
  XY[n]=[list(map(int, input().split())) for _ in range(a)]

maxH=0
for mask_i in range(1<<N):
  
  H=[0]*(N+1)
  for n in range(N):
    if mask_i>>n&1:
      H[n+1]=1
  #print(H[1:])
  
  ok=True
  for n in range(1,N+1):
    if H[n]==1:
      for x,y in XY[n]:
        if H[x]!=y:
          ok=False
          break
  if ok:
    maxH=max(maxH,sum(H))

print(maxH)


Measured memory_bytes: 9136
n = gets.chomp.to_i
ai = gets.chomp.split.map(&:to_i)
ans = []
bi = Array.new(n, 0)

n.downto(1) do |i|
  sum = 0
  (2*i).step(n, i){|j| sum += bi[j-1]}
  if sum % 2 != ai[i-1]
    bi[i-1] = 1
    ans << i
  end
end

puts ans.size
puts ans

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

using namespace std;

int main() {
	string s;
	set<char> S;
	cin >> s;
	for(char c : s) {
		S.insert(c);
	}
	if(s.size() == S.size()) cout << "yes\n";
	else cout << "no\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N , A , B;
  cin >> N >> A >> B;
  if( A * N  > B ){
    cout << B << endl;
  }else if( A * N  < B ){
    cout << A * N << endl;
  }else{
    cout << B << endl;
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <functional>
#include <queue>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


int main(){
    int n ;
    cin >> n ;
    vector<int64_t> a(n) ;
    vector<int64_t> b(n) ;
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i) >> b.at(i) ;
    }
    sort(a.begin(),a.end()) ;
    sort(b.begin(),b.end()) ;
    int64_t ans = 0 ;

    if (n % 2 == 0)
    {
        ans = (b.at((n/2)-1)+b.at(n/2)) - (a.at((n/2)-1)+a.at(n/2)) + 1 ;
    }else
    {
        ans = b.at(n/2) -a.at(n/2) + 1 ;
    }
    
    cout << ans << endl ;
}

Measured memory_bytes: 6424
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll n ;
    cin >> n ;
    vl v;
    forn(i , 1 , n ){
       ll x;
       cin >> x;
       v.pb(x) ;
    }
    vl vv = v;
    sort(all(v));
    forn(i ,  0 , n- 1){
       ll curr = vv[i] ;
       if(curr == v[n-1]){
        cout << v[n-2] << el ;
       }
       else if(curr == v[0]){
        cout << v[n-1] << el ;
       }
       else {
        cout << v[n-1] << el ;
       }
    }
    ro ;
}































Measured memory_bytes: 4848
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC optimize("Ofast")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

/////////////////////////////////////////////////////////////////////

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T1, typename T2>
T2 sum_mod(T1 x, T2 MOD) {
	if (x < 0)
		x += MOD;
	if (x >= MOD)
		x -= MOD;
	return x;
}

template <typename T1, typename T2>
T2 mul_mod(T1 x, T2 MOD) {
	if (x < 0)
		return (abs(x) % MOD == 0 ? 0 : MOD - abs(x) % MOD);
	return x % MOD;
}

template <typename T>
bool uax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
bool uin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

const int LOG = 18;
const int N = (int)1e5 + 7;
const int MAXN = (int)2e3 + 7;
const int MOD = (int)998244353;
const int INF = (int)1e9 + 7;
const int CONST = 300;
const LL LINF = (i64)2e15;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

/////////////////////////////////////////////////////////////////////

LL n, k;

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
#endif

	cin >> n >> k;
	if (n > k)
		n -= n / k * k;
	cout << min(n, k - n);

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int n, p[20];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", p + i);
	int count = 0;
	for (int i = 1; i + 1 < n; i++)
		count += ((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i - 1] > p[i] && p[i] > p[i + 1]));
	printf("%d\n", count);
}

Measured memory_bytes: 128
import math

def div(x):
	d=[]
	for i in range(int(math.sqrt(x))):
		if x%(i+1)==0:
			d=d+[i+1]
			d=d+[x//(i+1)]
	return d

N,M=map(int,input().split())
d=div(M)
dmax=-1
for i in range(len(d)):
	if d[i]<=M//N:
		if d[i]>dmax:
			dmax=d[i]
print(dmax)

Measured memory_bytes: 3064
z = list(map(int, input().split()))

for i in range(2):
  z.append(z[2*i+2] - (z[2*i+3] - z[2*i+1]))
  z.append(z[2*i+3] + (z[2*i+2] - z[2*i]))
  
print(str(z[4]) + " " + str(z[5]) + " " + str(z[6]) + " " + str(z[7]))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int l,r;
    cin >> l >> r;
    if(r - l > 2019){
        cout << 0 << endl;
        return 0;
    }
    int mi = INF;
    FOR(i,l,r){
        FOR(j,i+1,r+1){
            mi = min(mi, (i * j) % 2019 );
        }
    }
    cout << mi << endl;
}

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

int main(){
    double a,b,x;
    cin>>a>>b>>x;
    double v=a*a*b;
    double ans;
    double rest=v-x;
    double pi=3.141592653589;
    if(v<2*x){
        ans=atan2(2*rest,pow(a,3));
        //cout<<1<<endl;
    }else{
        ans=atan2(a*b*b,2*x);
    }
    cout<<fixed<<setprecision(12)<<ans*180/pi<<endl;
}

Measured memory_bytes: 4212
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};


int cakesize(int x1,int y1, int x2, int y2){
	return abs(x1-x2)*abs(y1-y2);
}

struct cake{
	int x[4];	//左上、右上、右下、左下
	int y[4];
	bool operator==(const cake& c1){
		rep(i,4){
			if(x[i] != c1.x[i]){
				return false;
			}
			if(y[i] != c1.y[i]){
				return false;
			}
		}
		return true;
	}
	
	bool operator<(const cake& c1){
		
	}
};


bool cakesort(const cake& c1, const cake& c2){
	return cakesize(c1.x[0],c1.y[0],c1.x[2],c1.y[2]) < cakesize(c2.x[0],c2.y[0],c2.x[2],c2.y[2]); 
}


int main(){
	int n,w,d;
	while(true){
		cin >> n >> w >> d;
		if(n+w+d == 0){
			break;
		}
		vector<cake> data;
		cake s;
		s.x[0] = 0; s.x[1] = w; s.x[2] = w; s.x[3] = 0;
		s.y[0] = d; s.y[1] = d; s.y[2] = 0; s.y[3] = 0;
		data.pb(s);

		int a,b;
		rep(i,n){
			cin >> a >> b;
			a--;
			cake buf = data[a];
			vector<cake>::iterator del = remove(all(data),data[a]);
			data.erase(del, data.end());

			int mx = buf.x[1] - buf.x[0];
			int my = buf.y[1] - buf.y[2];
			int mv = 0;
			while(true){
				if(b / mx == 0){
					break;
				}
				b -= mx;
				mv++;

				if(b / my == 0){
					break;
				}
				b -= my;
				mv++;
			}
			mv %= 4;

			cake add1,add2;
			rep(i,4){
				add1.x[i] = buf.x[i]; add2.x[i] = buf.x[i];
				add1.y[i] = buf.y[i]; add2.y[i] = buf.y[i];
			}

			if(mv&1){
				int ny;
				if(mv == 1){
					ny = (my-b) + buf.y[2];
				}else{
					ny = b + buf.y[2];
				}
				add1.y[2] = ny; add1.y[3] = ny;
				add2.y[0] = ny; add2.y[1] = ny;
			}else{
				int nx;
				if(mv == 2){
					nx = (mx-b) + buf.x[0];
				}else{
					nx = b + buf.x[0];
				}
				add1.x[1] = nx; add1.x[2] = nx;
				add2.x[0] = nx; add2.x[3] = nx;
			}

			if(cakesize(add1.x[0],add1.y[0],add1.x[2],add1.y[2]) < cakesize(add2.x[0],add2.y[0],add2.x[2],add2.y[2])){
				data.pb(add1);
				data.pb(add2);
			}else{
				data.pb(add2);
				data.pb(add1);
			}
		}

		sort(all(data), cakesort);

		rep(i,data.size()){
			cout << cakesize(data[i].x[0],data[i].y[0],data[i].x[2],data[i].y[2]) << (i+1==data.size() ? "\n" : " ");
		}
	}
}

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

int main(){
 int n,i,j;
 int a[30];
 int num=0;
 cin>>n;
  num=n;
for(i=0;i<n;i++){
     cin>>a[i];
}
  
for(i=0;i<n;i++){
    for(j=0;j<i;j++){
        if(a[i]<a[j]){
            num--;
          	break;
        }
    }
}

cout<<num;

}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int []arr=new int[n];
		for(int i=0;i<n;i++) {
			arr[i]=scn.nextInt();
		}
		Arrays.sort(arr);
		int ans=arr[0];
		for(int i=1;i<n;i++) {
			int x=arr[i]%ans;
			while(x!=0) {
				int temp=x;
				x=ans%x;
				ans=temp;
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 49984
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

map<ll, ll> memo;
ll N, A, B, C, D;

ll Recursive(ll n){
	if(n == 1){
		return D;
	}
	if(n == 0){
		return LLONG_MAX / 2;
	}
	else if(memo.find(n) != memo.end()){
		return memo[n];
	}
	
	ll value = LLONG_MAX;
	// 2の倍数
	if(n % 2 == 1){
		ll nextN = (n+1)/2;
		value = min(value, Recursive(nextN) + min(A+D, n < 2000000000 ? D*(n-nextN) : LLONG_MAX));
		nextN = (n-1)/2;
		value = min(value, Recursive(nextN) + min(A+D, n < 2000000000 ? D*(n-nextN) : LLONG_MAX));
	}else{
		ll nextN = n/2;
		value = min(value, Recursive(nextN) + min(A, n < 2000000000 ? D*(n-nextN) : LLONG_MAX));
	}
	// 3の倍数
	if(n % 3 == 0){
		ll nextN = n/3;
		value = min(value, Recursive(nextN) + min(B, n < 2000000000 ? D*(n-nextN) : LLONG_MAX));
	}
	else if(n % 3 == 1){
		ll nextN = (n-1)/3;
		value = min(value, Recursive(nextN) + min(B+D, n < 2000000000 ? D*(n-nextN) : LLONG_MAX));
	}
	else{
		ll nextN = (n+1)/3;
		value = min(value, Recursive(nextN) + min(B+D, n < 2000000000 ? D*(n-nextN) : LLONG_MAX/2));
	}
	
	// 5の倍数
	if(n % 5 == 0){
		ll nextN = n/5;
		value = min(value, Recursive(nextN) + min(C, n < 2000000000 ? D*(n-nextN) : LLONG_MAX));
	}
	else if(n % 5 == 1 || n % 5 == 4){
		ll nextN = n % 5 == 1 ? (n-1)/5 : (n+1)/5;
		value = min(value, Recursive(nextN) + min(C+D, n < 2000000000 ? D*(n-nextN) : LLONG_MAX));
	}else{
		ll nextN = n % 5 == 2 ? (n-2)/5 : (n+2)/5;
		value = min(value, Recursive(nextN) + min(C+2*D, n < 2000000000 ? D*(n-nextN) : LLONG_MAX));
	}
	
	// 1減らすだけで0にする場合
	if(n < 2000000000){
		ll nextN = 1;
		value = min(value, Recursive(nextN) + D*(n-nextN));
	}
	
	memo[n] = value;
	return value;
}

int main()
{
	int T;
	cin >> T;
	vector<ll> result;
	for(int t = 0; t < T; t++){
		cin >> N >> A >> B >> C >> D;
		memo.clear();
		result.push_back(Recursive(N));
	}
	for(int t = 0; t < T; t++){
		cout << result[t] << endl;
	}
	
	return 0;
}

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

int main()
{
    int N;
    while (cin >> N, N) {
        vector<vector<bool> > v(N, vector<bool>(33, false));
        vector<vector<long long> > dp(N, vector<long long>(33, 0));
        for (int i = 0; i < N; i++) {
            int m;
            cin >> m;
            dp[i][1] = 1LL << i;
            for (int j = 0; j < m; j++) {
                int tmp;
                cin >> tmp;
                v[i][tmp] = true;
            }
        }

        int res = 0;

        for (int k = 1; k <= 31; k++) {
            long long tmp = 0;
            for (int i = 0; i < N; i++) {
                if (v[i][k]) {
                    tmp |= dp[i][k];
                }
            }

            if ((1LL << N) - 1LL == tmp) {
                res = k;
                break;
            }

            for (int i = 0; i < N; i++) {
                if (v[i][k]) {
                    dp[i][k+1] |= tmp;
                } else {
                    dp[i][k+1] |= dp[i][k];
                }
            }
        }

        cout << (res == 0 ? -1 : res) << endl;
    }

    return 0;
}

Measured memory_bytes: 1236
# -*- coding: utf-8 -*-


import sys
from collections import deque
from collections import defaultdict
from collections import Counter
import heapq
import collections
import itertools
import bisect
import copy
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def zz(): return list(map(int, sys.stdin.readline().split()))


def z(): return int(sys.stdin.readline())


def S(): return sys.stdin.readline()[:-1]


def C(line): return [sys.stdin.readline() for _ in range(line)]


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = zz()
A = [0]*M
B = [0] * M
tree = UnionFind(N)
# friends = [[0]*N for i in range(N)]
# print(friends)
for i in range(M):
    a, b = zz()
    a -= 1
    b -= 1
    # A[i], B[i] = a, b
    tree.union(a, b)
ans = 0
for p in tree.parents:
    ans = max(ans, tree.size(p))
if (ans == 0):
    print(N)
else:
    print(ans)
# used = [0]*N
# group = UnionFind(N)

# for i in range(N):
#     if (used[i] == 1):
#         # すでに振り分け済み
#         continue
#     for j in range(i + 1, N):
#         if (used[j] == 1):
#             # すでに振り分け済み
#             continue
#         if (tree.same(i, j)):
#             # 友達
#             continue
#         else:
#             used[i] = 1
#             used[j] = 1
#             group.union(i, j)

#     # # 全員と友達
#     # if (used[i] == 0):
# # print(used)
# print(group.group_count())


# 最大でNグループにわければいける
# 素朴にやる


Measured memory_bytes: 18252
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c;
    char dust;
    cin >> a >> b >> dust >> c;
    ll ans = a * b;
    ans += a * c / 100;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3656
a, b = map(int, input().split())
if a > 0 and b > 0:
  print("Positive")
elif a < 0 and  b < 0:
  if (b - a + 1) % 2 == 0:
    print("Positive")
  else:
    print("Negative")
else:
  print("Zero")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    int N;
    cin >> N;
    valarray<i64> A(N), B(N), C;
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    i64 upper = B.sum() - A.sum();
    i64 ope = (B - A).apply([](i64 x){ return max((x+1)/2, 0l); }).sum();
    if(ope > upper) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 512