akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const ll MOD=1000000007;
int n;
char s1[60],s2[60];
int main(){
  scan(n);
  rep(i,n){
    scan(s1[i]);
  }
  rep(i,n){
    scan(s2[i]);
  }
  vector<int> vi;
  rep(i,n){
    if(s1[i]==s2[i]){
      vi.push_back(1);
    }
    else{
      vi.push_back(0);
      i++;
    }
  }
  int vs=vi.size();
  ll res;
  if(vi[0]==0){
    res=6;
  }
  else{
    res=3;
  }
  rep1(i,vs-1){
    if(vi[i]==0){
      if(vi[i-1]==0){
	res=(res*3)%MOD;
      }
      else{
	res=(res*2)%MOD;
      }
    }
    else{
      if(vi[i-1]==0){
	res=res;
      }
      else{
	res=(res*2)%MOD;
      }
    }
  }
  prin(res);


  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>
#include <complex>

using int64 = long long;
using uint64 = unsigned long long;

using namespace std;

using P = tuple<long double, long double>;

P rotate(P p, double theta) {
    double x, y;
    tie(x, y) = p;
    return P(cos(theta) * x - sin(theta) * y, sin(theta) * x + cos(theta) * y);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int a, b, h, m;
    cin >> a >> b >> h >> m;

    P p1 = rotate(P(0, a), 2 * M_PI * (30 * h + (long double)m / 2.0) / 360.0),
      p2 = rotate(P(0, b), 2 * M_PI * (long double)m / 60);
    long double dx = get<0>(p1) - get<0>(p2),
                dy = get<1>(p1) - get<1>(p2);
    cout << sqrt(dx * dx + dy * dy) << endl;

    return 0;
}



Measured memory_bytes: 3680
//https://atcoder.jp/contests/tenka1-2017-beginner/tasks/tenka1_2017_a
//A - Accepted...?
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    string S; cin>>S;
    ll ans=0;
    for(const auto c: S){
        if(c=='1')++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int mod=1e9+7;
// Not for Rating """"""""""I'm in Love with Experience :)""""""""""""""""""
void solve()
{
    ll x;cin>>x;
    if(x==0)cout<<"1";
    else cout<<"0";
}
int main(void)
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);solve();return 0;
}/*Solved By:- RITIK AGARWAL*/

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <cmath>

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

using namespace std;
typedef long long ll;

int main(){
    
    int N;
    cin>>N;
    int A[N+1];
    
    
    for(int i=1;i<=N;++i)cin>>A[i];
    
    bool flag;
    
    ll ans[2];
    for(int k=0;k<=1;++k){
        flag=k;
        ll balance=1000;
        ll stock=0;
        
        for(int i=1;i<N;++i){
            if(flag){
                if(A[i+1]<A[i]){  //売却
                    balance+=stock*A[i];
                    stock=stock-stock;
                    flag=0;
                    //cout<<"i:"<<i<<" balance:"<<balance<<" stock:"<<stock<<endl;
                }
            }else{
                if(A[i+1]>A[i]){
                    if(balance>=0){
                        stock+=balance/A[i];
                        balance-=A[i]*stock;
                        flag=1;
                      //   cout<<"i:"<<i<<" balance:"<<balance<<" stock:"<<stock<<endl;
                        
                    }
                }
            }
            ans[k]=balance+stock*A[N];
        }
    }
    
    
    cout<<(ans[0]>=ans[1]?ans[0]:ans[1])<<endl;
}

Measured memory_bytes: 3620
import sys
sys.setrecursionlimit(10**7)
import copy
N,M=map(int,input().split())
G=[[]for _ in range(N)]

for i in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

ans=0
def bfs(v,chk,G):
    global ans
    #print(chk)
    if chk[v]!=0:
        return
    chk[v]=1
    if sum(chk)==N:
        ans+=1
    for tmp in G[v]:
        chk1=copy.copy(chk)
        bfs(tmp,chk1,G)

chk=[0]*N
bfs(0,chk,G)
print(ans)

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

int main() {
    int of[5][4][11] = {{{0}}};
    int n, b, f, r, v;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> b >> f >> r >> v;
        of[b][f][r] += v;
    }
    for(int i = 1; i <= 4; i++) {
        for(int j = 1; j <= 3; j++) {
            for(int k = 1; k <= 10; k++)
                cout << ' ' << of[i][j][k];
            cout << endl;
        }
        if(i < 4)
            cout << "####################\n";
    }
    return 0;
}


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

ll n;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin>>n;
    vector <ll> v(n);
    for (ll i=0; i<n; i++){
        cin>>v[i];
    }

    ll res=0;
    for (ll i=0; i<n-1; i++){
        while (v[i]>v[i+1]){
            res += v[i] - v[i+1];
            v[i+1] = v[i];
        }
    }
    
    
    cout<<res;
    
    
    return 0;
}

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


int main(){
    int a,b,c;


    cin >> a;
    cin >> b;
    cin >> c;
    for(int i = 0; i <100; i++){
        if((a*i)%b == c){
            cout << "YES" <<"\n";
            return 0;
        }
    }
    
    //if(a%x == 0  || b%x == 0){
        //ans++;
    //}

    cout << "NO" <<"\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

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

  char a;
  cin >> a;
  if('a' <= a && a <= 'z'){
    cout << "a\n";
  } else {
    cout << "A\n";
  }
  return 0;
}


Measured memory_bytes: 3596
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,x,ans[100010];

int main()
{
	cin>>n;
	repn(i,n)
	{
		cin>>x;
		ans[x]=i;
	}
	repn(i,n) cout<<ans[i]<<' ';
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1152
n,k,*x=gets(p).split.map &:to_i
m=10**9
for i in 0..x.size-k
	l,h=x[i],x[i+k-1]
	t=h-l+(l.abs<h.abs ? l.abs: h.abs)
	m=t<m ? t: m
end
p m

Measured memory_bytes: 9212
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main()
{
	ll N, a, cnt = 0, d[101] = {}; cin >> N;
	rep(i, 0, N) {
		cin >> a;
		if (!d[a]++)cnt++;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))

int main(){
	char s[9];
	ll a,b,c;
	while(scanf(" %s%lld%lld%lld",s,&a,&b,&c),*s!='#'){
		if(a<=30||(a==31&&b<=4))printf("HEISEI %lld %lld %lld\n",a,b,c);
		else printf("? %lld %lld %lld\n",a-30,b,c);
	}
}



Measured memory_bytes: 2032
def slove():
    import sys
    input = sys.stdin.readline
    w, h, x, y = list(map(int, input().rstrip('\n').split()))
    if x * 2 == w and y * 2 == h:
        print(w * h / 2, 1)
    else:
        print(w * h / 2, 0)


if __name__ == '__main__':
    slove()


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

int main(){
  ll i,j,cnt=0;
  int n;
  cin>>n;
  ll a[n];
  for(i=0;i<n;i++)cin>>a[i];
  ll p,mi=LLONG_MAX;
  ll h=100000000,t=500000000;
  while(h!=0){
    for(i=t-10*h;i<t+10*h;i+=h){
      p=0;
      for(j=0;j<n;j++)p+=max(a[j]-(i+j+1),(i+j+1)-a[j]);
      if(mi>p){
        mi=p;
        cnt=i;
      }
    }
    t=cnt;
    h/=2;
    i=t-h;
  }
  cout<<mi<<endl;
    
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n, k;
  cin >> n >> k;
  ll cnt = 0;
  ll t = 1;
  while (n > t-1) {
    t *= k;
    cnt++;
  }
  cout << cnt << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  string ans = "APPROVED";
  rep(i,n) {
    int x = a[i];
    if (x % 2 == 0  && x % 3 != 0 && x % 5 != 0) {
      ans = "DENIED";
      break;
    }
  }
  cout << ans << endl;
  
  return 0;
}


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

using namespace std;

#pragma GCC optimization("O3")
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
#define INF 1000000000

#define start_routine() int begtime = clock();
#define end_routine()                                                       \
  int endtime = clock();                                                    \
  cerr << "\nTime elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \
       << " ms\n\n";
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define sz(a) a.size()
#define all(a) a.begin(), a.end()

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  start_routine();
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  ll n, a;
  cin >> n;
  vector<pii> ans;
  for (auto i = 1; i <= n; i++) {
    cin >> a;
    ans.push_back(make_pair(a, i));
  }
  sort(all(ans));
  for (const auto val : ans) cout << val.ss << " ";

#ifndef ONLINE_JUDGE
  end_routine();
#endif
  return 0;
}

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

int main()
{
	const int kMax = 9;
	for(int i = 1; i <= kMax; i++)
	{
		for(int j = 1; j <= kMax; j++)
		{
			cout << i << "x" << j << "=" << i * j << endl;
		}
	}
    return 0;
}

Measured memory_bytes: 3060
import math
def calcAngle(h,m): 
          
        if (h < 0 or m < 0 or h > 12 or m > 60): 
            print('Wrong input') 
          
        if (h == 12): 
            h = 0
        if (m == 60): 
            m = 0
          
       
        hour_angle = 0.5 * (h * 60 + m) 
        minute_angle = 6 * m 
          
  
        angle = abs(hour_angle - minute_angle) 
          
   
        angle = min(360 - angle, angle) 
          
        return angle 
  
a,b,h,m=map(int,input().split())
angle=calcAngle(h,m)
rad=math.radians(angle)
val=math.cos(rad)
c=math.sqrt(pow(a,2)+pow(b,2)-2*a*b*val)
print(c)

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

int main(){
  int n,a,mina,ans=-(1e9);
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    if(!i)mina=a;
    else ans=max(ans,a-mina);
    mina=min(mina,a);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1164
import random

class RollingHash(object):
    def __init__(self, S: str, MOD: int = 10 ** 9 + 7, BASE: int = 10 ** 5 + 7):
        self.S = S
        self.N = N = len(S)
        self.MOD = MOD
        self.BASE = BASE
        self.S_arr = [ord(x) for x in S]

        self.POWER = [1] * (N + 1)
        self.HASH  = [0] * (N + 1)
        p, h = 1, 0
        for i in range(N):
            self.POWER[i + 1] = p = (p * BASE) % MOD
            self.HASH[i + 1] = h = (h * BASE + self.S_arr[i]) % MOD

    def hash(self, l: int, r: int):
        # get hash for S[l:r]
        _hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD
        return _hash

# 汎用的な二分探索のテンプレ
# check_func(x) = true となるxの最小値を探索する
# left : check_func(x) = falseとなるx
# right: check_func(x) = true となるx
# search_max: check_func(x) = true となるxの"最大値"を探索する場合はTrue
# check_func: answer <= x であればcheck_func(x) = true となるような関数
def binary_search(left: int, right: int, check_func, search_max:bool=False):
    # ok と ng のどちらが大きいかわからないことを考慮
    while abs(right - left) > 1:
        mid = (left + right) // 2
    
        if check_func(mid) ^ search_max:
            right = mid
        else:
            left = mid

    return left if search_max else right

def main():
    N = int(input())
    S = input()
    MOD = 998244353
    # BASEはMOD未満で1でない奇数とする
    BASE = random.randint(2, MOD // 2 - 1) * 2 + 1
    rs = RollingHash(S, MOD=MOD, BASE=BASE)

    D = [0] * N
    # 長さLの部分文字列同士が、範囲を重ねず同じ文字列となる場合はTrue,
    # そうでない場合はFalseを返す関数
    def isOK(L):
        if L == 0:
            return True
        
        for i in range(min(L, N - 2 * L + 1)):
            D[i] = rs.hash(i, i + L)
        hashes = set()
        for i in range(L, N - L + 1):
            # 自分より開始点がL以上前の文字列のハッシュを検索対象に追加
            hashes.add(D[i - L])
            D[i] = v = rs.hash(i, i + L)
            # ハッシュが衝突したら、範囲を重ねず同じ文字列となる文字列が存在することになる
            if v in hashes:
                return True
        return False

    # 範囲が重ならないことが条件にあるので、答えは最大でもN // 2（文字列の長さの半分）となる。
    # ただし、二分探索する上で絶対に答えとならない範囲を含めたいので、
    # 探索範囲としてはN // 2 + 1 と、+1しておく。
    ans = binary_search(0, N // 2 + 1, isOK, search_max=True)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 4264
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 7+1e18
# define lld long double
#define eps 0.000001
#define endl '\n'
using namespace std ;
 
int main()
{

	
   string s;
   cin>>s;
   lli a=0,b=0,c=0;

   if(s[0]=='A') a=1;
   loopl(i,2,s.size()-1)
   {
   	if(s[i]=='C') c++;
   	if(s[i]-'A'>=0 && s[i]-'A'<=25) b++;
    }

    if(s[s.size()-1]-'A'>=0 && s[s.size()-1]-'A'<=25) b++;
    if(s[1]-'A'>=0 && s[1]-'A'<=25) b++;

    if((a==1 && c==1) && b==1) cout<<"AC"<<endl;
    else cout<<"WA"<<endl;
}

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

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    cin >> n;
    unordered_map<int, int> fac;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a % 2 == 0) {
            fac[2]++;
            while(a % 2 == 0) a /= 2;
        }
        for (int j = 3; (ll)j * j <= a; j += 2) {
            bool yes = 0;
            while (a % j == 0) a /= j, yes = 1;
            if (yes) fac[j]++;
        }
        if (a > 1) fac[a]++;
    }
    bool s = true, p = true;
    for (auto [f, c] : fac) {
        if (c == n) s = false;
        if (c > 1) p = false;
    }
    if (p) cout << "pairwise coprime\n";
    else if (s) cout << "setwise coprime\n";
    else cout << "not coprime\n";
    return 0;
}

Measured memory_bytes: 6624
#include<set>
#include<list>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[100500]={0};
    memset(a,0,sizeof(a));
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    bool k=true;
    for(int i=n-1;i>=1;i--)
    {
        if(a[i]<=a[i+1])
        {

        }
        else
        {
            if(a[i]-1<=a[i+1])
            {
                a[i]--;
            }
            else
            {
                cout<<"No";
                k=false;
                break;
            }
        }
    }
   if(k)cout<<"Yes";
    
    return 0;
}

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

int n;

int main(){

    cin>>n;

    int ans = 1;
    for (int i = 6; i >=0 ; i--)
    {
        if(n>=pow(2,i)){
            ans = (int)pow(2,i);
            break;
        }
    }
    
    cout << ans << endl;
    return 0;
    
}


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

int n;
int dat[100000000];

priority_queue<int,vector<int> ,greater<int> > que;

int main(){
  cin >> n;
  
  for(int i = 0;i < 5;i++){
    dat[i] = 100000;
  }

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

  sort(dat,dat + n);
  
  for(int i = 0;i < 4;i++){
    int wa = 0;
    for(int k = 0,d = 1;k < 5;k++){
      if(dat[i] / d >= 1){
	wa = d;
      }
      else{
	wa *= 10;
	break;
      }
      d *= 10;
    }
	  
    for(int j = 0;j < 4;j++){
      if(i != j){
	//      	cout << dat[i] * wa << " " << dat[j] << endl;
	//	cout << dat[j] * wa + dat[i] << endl; 
	if(dat[j] * wa + dat[i] != 0){
	  que.push(dat[j] * wa + dat[i]);      
	}
      }
    }
  }
  que.pop();
  que.pop();
  cout << que.top() << endl;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define MODD 1000000007LL
#define MAX_SIZE 400001
#define MAX_N 100001
using namespace std;
typedef long long ll;

ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}

ll modd(ll a){if(a<0LL) return a*-1LL;return a;}
double modd(double a){if(a<0.0) return a*-1.0;return a;}

ll modulo(ll a){return a % MODD; }

ll comp(ll& a, ll& b){
    return a>b;
}

ll power(ll k, ll p){
    if (p == 0)
        return 1LL;
 
    ll P = power(k, p/2LL);
    P = (P * P) % MODD;
 
    if (p % 2 == 1)
        P = (P * k) % MODD;
 
    return P;
}

ll sum(ll bit[], ll i){
    // sum of [1...i] 
    ll ans=0;
    while(i>0){
        ans+=bit[i];
        i-=i&(-i); // lowest set bit
    }
    return ans;
}

void update(ll bit[], ll n, ll i, ll delta){
    // update ith element with value of delta
    while(i<=n){
        bit[i]+=delta;
        i+=i&(-i);
    }
}

int main(){





    // #ifndef ONLINE_JUDGE 

    // // For getting input from input.txt file 
    // freopen("input.txt", "r", stdin); 

    // // Printing the Output to output.txt file 
    // freopen("output.txt", "w", stdout); 
    // #endif 




    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll h,w;
    cin>>h>>w;
    ll ans=0;
    if(h==1 || w==1){
        ans=1;
    }else{
        ll m=(h*w);
        if(h%2==1 && w%2==1){
            ans=(m/2)+1;
        }
        else{
            ans=m/2;
        }
    }
    
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
N, A, B, C, D = map(int, input().split())
S = input()
flag2 = True
flag3 = False
if C < D:
    AS = S[A:C-1]
    BS = S[B:D-1]
    for i in range(len(S)-1):
        if BS[i:i+2] == '##':
            flag2 = False
    for i in range(len(S)-1):
        if AS[i:i+2] == '##':
            flag2 = False
    if flag2:
        print('Yes')
    else:
        print('No')
else:
    AS = S[A:C-1]
    BS = S[B:D-1]
    BD = S[B-2:D+1]
    # print(BD)
    for i in range(len(S)-2):
        if BD[i:i+3] == '...':
            flag3 = True
    for i in range(len(S)-1):
        if BS[i:i+2] == '##':
            flag2 = False
    for i in range(len(S)-1):
        if AS[i:i+2] == '##':
            flag2 = False
    if flag2 and flag3:
        print('Yes')
    else:
        print('No')


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

typedef long long ll;
#define fio() cin.tie(0); ios::sync_with_stdio(false);
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(c) c.begin(),c.end()
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
#define pu push
#define pb push_back
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
const ll MOD = 1000000007;


int main(){
    fio();
    int K,S;
    cin>>K>>S;
    int iter,x,y,z,count=0;
    // rep(iter,K+1){
    rep(x,K+1){
        rep(y,K+1){
            z = S-x-y;
            if(z >=0 && z<=K && x<=K && y<=K)
                count += 1;
            // cout<<x<<" "<<y<<" "<<z<<endl;
        }
    }
    cout<<count;
    // }




}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int K;
	scanf("%d", &K);
	int m = K / 2;
	if (K % 2 == 0) {
		printf("%d", m * m);
	} else {
		printf("%d", m * (m + 1));
	}

	return 0;
}


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

int main(){
    long long n;
    cin >> n;
    cout << n << ":";
    int fr=2;
    int lim=sqrt(n)+1;
    while(fr<=lim){
        if(n%fr==0){
            cout << " " << fr;
            n/=fr;
        }
        else{
            if(fr==2) fr++;
            else{
                fr+=2;
            }
        }
    }
    if(n==1){
        cout << endl;
    }
    else{
        cout << " " << n << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
// D - Friend Suggestions
// UnionFinde version (with rank)
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

class UnionFind{//union-find class (rank)
	vector<int> parent;//parent number
	vector<int> rank;//rank
	public:
	UnionFind(int n){
		parent.resize(n);
		rank.resize(n);
		init();
	}
	void init(){//initialize all parent to root
		for(int v=0; v<parent.size(); ++v){
			parent[v] = v;
			rank[v] = 0;
		}
	}
	int root(int v){//get root
		if(parent[v]==v) return v;//root
		return parent[v] = root(parent[v]);//path compression
	}
	bool same(int v, int u){//v & u the same set
		return root(v)==root(u);
	}
	void unite(int v, int u){
		v = root(v); u = root(u);
		if(v==u) return;
		//concat low rank to high rank (but rank is no compress)
		if(rank[v]<rank[u]){
			parent[v] = u;
		}else{
			parent[u] = v;
			if(rank[v]==rank[u]) rank[v]++;//fix rank when same rank concat
		}
	}
	void printParent(){
		for(auto e:parent){cout<<e<<",";}cout<<"\n";
	}
	void printRank(){
		for(auto e:rank){cout<<e<<",";}cout<<"\n";
	}
};

#define MAX 100000+1
int N,M,K;
vvi F(MAX),B(MAX);//friend,block
vi gid(MAX);

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

	UnionFind uni(N+1);

	rp(i,0,M){
		int s,t; cin>>s>>t;
		uni.unite(s,t);
		F[s].push_back(t);
		F[t].push_back(s);
	}

	vi cnt(N+1);rp(i,1,N+1) cnt[uni.root(i)]++;

	rp(i,0,K){
		int s,t; cin>>s>>t;
		if(uni.root(s) != uni.root(t)) continue;
		B[s].push_back(t);
		B[t].push_back(s);
	}

	int self = 1;
	rp(i,1,N+1) cout<< cnt[uni.root(i)]-F[i].size()-B[i].size()-self <<" ";

}

Measured memory_bytes: 13432
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <cstdio>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define SIZE 100000
#define MOD 1000000007
using namespace std;
typedef long long ll;

struct ModFact {
    int sum[SIZE+1];
    int fact[SIZE+1];
    constexpr ModFact() : fact(), sum() {
        ll f = 1;
        fact[0] = f;
        for (int i = 0; i <= SIZE; i++) {
            f = f*(i+1)%MOD;
            fact[i+1] = f;
        }
        f = power(f, MOD-2);
        for (int i = SIZE; i >= 0; i--) {
            sum[i] = fact[i] * f % MOD;
            f = f * (i+1) % MOD;
        }
        for (int i = 1; i <= SIZE; i++) {
            sum[i] = (sum[i] + sum[i-1]) % MOD;
        }
    }
    inline constexpr ll power(ll a, ll b) {
        ll r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%MOD;
            a = (a*a)%MOD;
            b >>= 1;
        }
        return r;
    }
} fact;

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
    if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
    return *ci++;
}

inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
    else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
    return A;
}

int main() {
    ll ans = 0;
    int N, prev, now;
    N = getint();
    prev = getint();
    REP(i, N-1) {
        ans += fact.sum[i] * ll((now = getint()) - prev);
        prev = now;
    }
    printf("%lld\n", (ans%MOD)*fact.fact[N-1]%MOD);
	return 0;
}


Measured memory_bytes: 256
import math

class Ufo:
  def __init__(self, x, y, r, v):
    self.dist = get_dist(x, y)
    self.angle = get_angle(y, x)
    self.rad = r
    self.v = v

def get_dist(x, y):
  return (x ** 2 + y ** 2) ** (1 / 2)

def get_angle(x, y):
  angle = math.atan2(y, x)
  if angle < 0:
    angle += math.pi * 2
  return angle

def reach(ufos, R):
  remove_lst = []
  for ufo in ufos:
    ufo.dist -= ufo.v
    if ufo.dist <= R:
      remove_lst.append(ufo)
  for ufo in remove_lst:
    ufos.remove(ufo)
  return len(remove_lst)

def is_dead(ufo, laser, R):
  diff = abs(ufo.angle - laser)
  if diff > math.pi:
    diff = math.pi * 2 - diff
  if (diff <= math.pi / 2 and ufo.dist * math.sin(diff) <= ufo.rad) or (ufo.dist <= ufo.rad):
    if ufo.dist * math.cos(diff) + (ufo.rad ** 2 - (ufo.dist * math.sin(diff)) ** 2) ** (1 / 2) > R:
      return True
  return False

def shoot(ufos, laser, R):
  remove_lst = []
  for ufo in ufos:
    if is_dead(ufo, laser, R):
      remove_lst.append(ufo)
  for ufo in remove_lst:
    ufos.remove(ufo)

def main():
  while True:
    R, n = map(int, input().split())
    if R == 0:
      break
  
    ufos = []
    for _ in range(n):
      x, y, r, v = map(int, input().split())
      ufos.append(Ufo(x, y, r, v))
    
    ans = 0
    while ufos:
      ans += reach(ufos, R)
      if ufos:
        laser = min(ufos, key=lambda ufo:ufo.dist).angle
        shoot(ufos, laser, R)
    print(ans)
main()


Measured memory_bytes: 5844
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int compare_int2(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

int main()
{
    int n,h,res=0;
    scanf("%d %d", &n, &h);
    int a[n],b[n], asum, bsum=0, amax=0, bmin=1000000000;
    for(int i=0;i<n;i++){
        scanf("%d %d", &a[i], &b[i]);
        if(a[i]>amax)
            amax=a[i];
        if(b[i]<bmin)
            bmin=b[i];
        //asum+=a[i];
        //bsum+=b[i];
    }
    //printf("bmin %d\n", bmin);
    //printf("amax %d\n", amax);
    qsort(b, n, sizeof(int), compare_int2);
    qsort(a, n, sizeof(int), compare_int2);
    int i=0;
    while((b[i]>amax)&&(i<n)){
        bsum+=b[i];
        i++;
    }
    //printf(" i %d\n", i);

    if(h<=bsum){

        while(h>0){
            h-=b[res];
            res++;
        }
    }else{
        h-=bsum;
        res+=i;
        while(h>0){
            h-=a[0];
            res++;
        }
    }
    printf("%d\n", res);
    return 0;
}


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

int main() {
	
	const int p = 3;
	vector<int> c(p);
	cin >> c[0] >> c[1] >> c[2];
	sort(c.rbegin(), c.rend());
	int diff = c[0] - c[1] + c[0] - c[2];
	int ans = 0;
	if (diff % 2 == 0) {
		ans = diff / 2;
	}
	else {
		c[0]++;
		diff = c[0] - c[1] + c[0] - c[2];
		ans = diff / 2 + 1;
	}
	cout << ans << endl;
    return 0;
}

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

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    if(n == 0 && m == 0) {
        cout << "0 0" << endl;
        return 0;
    }

    int test = 0;
    for(int i = 0; i < (1 << n); ++i)
        if(i != m) test ^= i;
    

    if(test == m) {
        for(int i = 0; i < (1 << n - 1); ++i)
            if(i != m) cout << i << ' ';
        cout << m << ' ';
        for(int i = (1 << n - 1) - 1; i >= 0; --i)
            if(i != m) cout << i << ' ';
        for(int i = (1 << n - 1); i < (1 << n); ++i)
            if(i != m) cout << i << ' ';
        cout << m << ' ';
        for(int i = (1 << n) - 1; i >= (1 << n - 1); --i)
            if(i != m) cout << i << ' ';
        return 0;
    }

    if(m)
        return cout << -1 << endl, 0;

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


Measured memory_bytes: 1792
h = int(input())
cnt=0
while h>1:
  h=h//2
  #print(h)
  cnt+=1
  
n=cnt
"""
#print(cnt)
sn = (n/2)* (4+(n-1)*2)
sn+=1
#print(int(sn))
"""
r = 2
sn = ( 2*(r**n -1) )/(r-1)
  
print(int(sn+1))





Measured memory_bytes: 3064
import java.util.Vector;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Vector <Integer> vector = new Vector<Integer>();
		try (Scanner sc = new Scanner (System.in)){
			int times = sc.nextInt();
			for (int i=0; i < times; i++) {
				int request = sc.nextInt();
				switch (request) {
				case 0:
					int x = sc.nextInt();
					vector.add(x);
					break;

				case 1:
					int p = sc.nextInt();
					System.out.println(vector.get(p));
					break;

				case 2:
					vector.remove(vector.size()-1);
					break;

				}
			}
		}
	}
}



Measured memory_bytes: 142524
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n,k;
    cin >> n >> k;
    int a = 0, b = 0;
    loop(i,1,n+1){
        if(i%k == 0)a++;
        if(k%2 == 0 && i%k == k/2)b++;
    }
    cout << a*a*a+b*b*b << endl;
}


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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (auto &i : a) cin >> i;
	sort(a.begin(), a.end());

	auto f = [&](ld x)
	{
		ll r = 0;
		for (auto i : a)
		{
			if (i == 0) r += n * (x >= 0);
			else
			{
				ll x1 = floorl(x / i);
				ll x2 = ceill(x / i);
				if (i > 0) r += upper_bound(a.begin(), a.end(), x1) - a.begin();
				else r += a.end() - lower_bound(a.begin(), a.end(), x2);
			}
			r -= i*i <= x;
		}
		return r / 2;
	};

	ll l = -1e18, r = 1e18;
	while (l < r)
	{
		ll md = (l + r) >> 1;
		if (f(md) < k)
			l = md + 1;
		else
			r = md;
	}
	cout << l << "\n";

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

map<string, P> mp;

int main(){
	int n, q;
	string name;
	int num;
	int year;
	while(cin >> n >> q && (n || q)){
		mp.clear();
		for(int i = 0; i < n; i++){
			cin >> name >> num >> year;
			mp[name] = make_pair(num, year);
		}
		for(int i = 0; i < q; i++){
			cin >> year;
			bool f = false;
			for(map<string, P>::iterator iter = mp.begin();
				iter != mp.end(); iter++)
			{
				P p = (*iter).second;
				if(year <= p.second && year > p.second - p.first){
					f = true;
					cout << (*iter).first << " " << year - (p.second - p.first) << endl;
				}
			}
			if(!f) cout << "Unknown" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 996
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    ll ans=0;
    rep(i,n){
        ll a; cin>>a;
        ans+=a;
    }
    cout<<ans-n<<endl;
}

Measured memory_bytes: 256
using System;

namespace Application
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());

            var ans = long.MaxValue;
            for (long i = 1; i * i <= n; i++)
            {
                if (n % i != 0) continue;
                ans = Math.Min(ans,
                    n / i + i - 2);
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
// In The Namw Of Allah
#include <bits/stdc++.h>
using namespace std;

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

const int N = 5e5 + 10, mod = 1e9 + 7;


int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	string s;
	cin >> n >> s;
	if(n & 1)	return cout << "No\n", 0;
	else {
		string t;
		for (int i = 0; i < n / 2; i++)	t.push_back(s[i]);
		for (int i = n - 1; i >= n / 2; i--)
			if(s[i] == t.back())	t.pop_back();
		if(t.empty())	cout << "Yes\n";
		else	cout << "No\n";
	}
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
div4 = 0
div2 = 0
for i in a:
  if i % 4 == 0:
    div4 += 1
  elif i % 2 == 0:
    div2 += 1
if div2 == 0:
  if n - div4 <= div4 + 1:
    print("Yes")
  else:
    print("No")
else:
  if n - div4 - div2 <= div4:
    print("Yes")
  else:
    print("No")


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

const int INF = 1e9;

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

  int n, k;
  cin >> n >> k;

  vector<int> h(n);
  for(int i=0; i<n; i++)
    cin >> h[i];

  vector<int> dp(n, INF);
  dp[0] = 0;
  for(int i=0; i<n; i++) {
    for(int j=i+1; j<=i+k; j++) {
      if(j < n) {
        dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
      }
    }
  }

  cout << dp[n-1] << '\n';
  
  return 0;
}

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

int main()
{
    double N,T,A;
    double H[1050];
    int ans;
    double min_diff = 100000;
    scanf("%lf%lf%lf",&N,&T,&A);
    for(int i=0;i<N;i++){
        scanf("%lf",&H[i]);
        if( fabs( T - ( H[i] * 0.006 ) - A) < min_diff ){
            ans = i + 1;
            min_diff = fabs( T - ( H[i] * 0.006 ) - A);
        }
    }

    printf("%d\n",ans);

    return 0;
}

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

int main()
{
    std::string N;
    std::cin >> N;
    int64_t s = 0;
    for (auto n : N)
    {
        s += n - '0';
    }
    std::cout << (s % 9 ? "No" : "Yes") << std::endl;

    return 0;
}



Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std; 
int main()
{
    int H,W;
    char c;
    cin>>H>>W;
    char grid[H][W];
    long long int dp[H][W];
    long long int hell=1000000007;
    
    for(int i=0;i<H;i++)
    {
        
        for(int j=0;j<W;j++)
        {
            cin>>c;
            grid[i][j]=c;
            dp[i][j]=0;
        }  
    }
 
    dp[0][0]=1;
    if(grid[0][0]=='#')
    dp[0][0]=0;
    
    long long int ans=0;
    for(int i=0;i<H;i++)
    {
        
        for(int j=0;j<W;j++)
        {
            if(i==0 and j==0)
            continue;
        
            ans=0;
            // cout<<i<<"i"<<" "<<j<<"j"<<"\n";
            if(grid[i][j]=='#')
            continue;
            if(i-1>=0 and grid[i-1][j]=='.')
            ans=(ans+dp[i-1][j]);
            if(j-1>=0 and grid[i][j-1]=='.')
            ans=(ans+dp[i][j-1]);
            dp[i][j]=ans%hell;
            
        }
    }
    cout<<dp[H-1][W-1];
    
    
    
}

Measured memory_bytes: 12340
while True:
    n = int(raw_input())
    if n == 0: break
    trea = [0]*n
    for i in range(n):
        trea[i] = map(int, raw_input().split())
    x,y = 10,10
    thr = [[0 for i in range(21)] for j in range(21)]
    m = int(raw_input())
    for i in range(m):
        line = raw_input().split()
        news = line[0]
        d = int(line[1])
        dire = {"N":[0,1], "E":[1,0], "W":[-1,0], "S":[0,-1]}
        for i in range(1,d+1):
            thr[x+i*dire[news][0]][y+i*dire[news][1]] = 1
        x += d * dire[news][0]
        y += d * dire[news][1]

    for i in range(n):
        if thr[trea[i][0]][trea[i][1]] == 0:
            print "No"
            break
        if i == n-1:
            print "Yes"

Measured memory_bytes: 6324
/*  -*- coding: utf-8 -*-
 *
 * 2896.cc: Test
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int cnt = 0;
  for (int i = 0; i < m; i++) {
    int ai;
    scanf("%d", &ai);
    if (ai > m) cnt++;
  }

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



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

const int N = 100 * 1000 + 5, LG = 61;

int dp[N][LG];
long long a[N];
long long ans[N];

long long get(long long x, long long y) {
	return (x >> y) & 1;
}


int main() {
	int n, m;
	long long k;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		dp[i][0] = i;
	}
	cin >> m >> k;
	for (int i = 0; i < m; i++) {
		int x;
		cin >> x;
		swap(dp[x][0], dp[x - 1][0]);
	}
	for (int j = 1; j < LG; j++) {
		for (int i = 1; i < n; i++) {
			dp[i][j] = dp[dp[i][j - 1]][j - 1];
		}
	}
	ans[1] = a[1];
	for (int i = 2; i <= n; i++) {
		int x = i - 1;
		for (int j = 0; j < LG; j++) {
			if (get(k, j)) {
				x = dp[x][j];
			}
		}
		ans[i] = (long long) ans[i - 1] + a[x + 1] - a[x];
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 26624
#include<iostream>
#include<iomanip>
using namespace std;
#define FOR(i,b,n) for(int i = (b) ; i < (n) ; ++i)
#define rep(i,n) FOR(i,0,n)
int main(){
  double dp[101000],ans[101000];
  dp[1] = 1.0;
  FOR(i,1,100001){
    double ogmm = dp[i] , nkmr = 1.0;
    rep(j,/*about*/10){
      dp[i + j + 1] += ogmm * ( 1.0 - nkmr );
      ogmm *= nkmr;
      nkmr /= 2;
      ans[i + j] += ogmm;
    }
  }
  int n;
  FOR(i,1,100001) ans[i] += ans[i-1];
  while(cin >> n , n) cout << fixed << setprecision(3) <<  ans[n] << endl;
}

Measured memory_bytes: 2808
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var n = next();
  var a = nexts(n);
  var b = xArray(0,n+1);
  for(var i = 0; i < n; i++)b[a[i]]++;
  var sum = 0;
  for(var i = 1; i <= n; i++)sum += b[i]*(b[i]-1)/2;
  var ans = xArray(sum, n);
  for(var i = 0; i < n; i++){
    var t = b[a[i]];
    ans[i] -= t*(t-1)/2-(t-2)*(t-1)/2;
  }
  return ans.join("\n");
}

Measured memory_bytes: 73168
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
 
 
public class Main {
	
	public static void main(String[] args) throws IOException {
		Main m = new Main();
		//*
		m.input();
		m.solve();
		m.output();
		/*/
		m.debug();
		//*/
	}
	
	public void debug() {
	}
	
	/*
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	/*/
	InputUtil in = new InputUtil();
	//*/
	PrintWriter out = new PrintWriter(System.out);
	//char[] S = null;
	int N = 0;
	int[] d = null;
	int ans = 0;
	
	public void input() throws IOException {
		/*
		S = br.readLine().toCharArray();
		/*/
		N = in.nextInt();
		d = in.nextInt(new int[N]);
		//*/
		
	}
	
	public void solve() throws IOException {
		HashSet<Integer> dh = new HashSet<>();
		for(Integer di: d){
			dh.add(di);
		}
		ans = dh.size();
	}
	
	
	
	public void output() {
		out.println(ans);
//		out.println(ans[0]==1?"Yes":"No");
		out.flush();
	}
}

//*
class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 100000;
	
	//Fields
	protected InputStream in;
	private byte[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private DataInputStream dis = null;
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {dis = new DataInputStream(this.in = in);}
	protected void initBuf(int bufsiz) {buf = new byte[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && dis.available()>0) {
			if(max>0) Arrays.fill(buf,0,max,(byte)0);
			max = dis.read(buf);
			ptr = 0;
		}
	}
	
	//Number Input Reader/Parser
	private boolean isNum(byte b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(byte b) {return b=='-'; }
 
	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		byte c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}
 
	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}
}
//*/

Measured memory_bytes: 23252
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<deque>
using namespace std;

int main(){
	
	long long Low,Hi;
	cin >> Low >> Hi;
	int ans=2019;
	
	if(Low<2019 && 2019<Hi)//2019が範囲内に存在
	{
		int ans=0;
		cout << ans << endl;
		return 0;
	}
	else if(Hi<=2019)//範囲が2019より小さい
	{
		for(int i=Low;i<Hi;i++){
			for(int j=i+1;j<=Hi;j++){
				int cmp=(i*j) % 2019;
				ans = min(ans,cmp);
			}
		}
		cout << ans << endl;
		return 0;
	}
	else if(2019<=Low)//範囲が2019より大きい場合	
	{
		if(Hi-Low>=2019*2)Hi=2019*2+Low;
		
		for(long long i=Low;i<Hi;i++){
			for(int long long j=i+1;j<=Hi;j++){
				int cmp=(i*j) % 2019;
				ans = min(ans,cmp);
			}
		}
		cout << ans << endl;
		return 0;
	}
	
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main() { 
   int h, w, d; cin >> h >> w >> d;
   map<int, pii>mp;//各数のx座標,y座標
   rep(i, h){
       rep(j, w){
           int num; cin >> num;
           mp[num] = {i, j};
       }
   }
   int mx = h*w;
   vector<ll> S(90010);
   for(int i=1; i<=d; i++){
       int num = i; S[i] = 0;
       while(num+d <= mx){
           int nx = mp[num+d].first, ny = mp[num+d].second;
           int x = mp[num].first, y = mp[num].second;
           ll cost = abs(ny-y)+abs(nx-x);
           S[num+d] = S[num]+cost;
           num += d;
       }
   }
   /*fo(i, 1, 10) cout << S[i] << " ";
   cout << ln;*/
   int q; cin >> q;
   vector<ll> res;
   rep(i, q){
       ll l, r; cin >> l >> r;
       res.push_back(S[r]-S[l]);
   }
   for(ll ans: res) cout << ans << ln;
}

Measured memory_bytes: 8308
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int H =0;
    int W =0;
    while(true){
     H = sc.nextInt();
     W = sc.nextInt();

//  System.out.println("");
   if(H != 0 && W != 0){
    for(int i = 1; i <= H ; i++){
      for(int j = 1; j <= W ; j++){
        if((i+j)%2==0)
        System.out.print("#");
        else if((i+j)%2==1)
        System.out.print(".");
      }
        System.out.print("\n");
      }
      System.out.println("");
    }else{
      break;
    }
  }
}
//  sc.close();
  //System.exit(0);

  }



Measured memory_bytes: 34808
from itertools import count
def get_weed(h):
    d10 = h[1] - h[0]
    d21 = h[2] - h[1]
    d32 = h[3] - h[2]
    if d10 == d21 == d32:
        for hi, expect in zip(h, count(h[0], d10)):
            if hi != expect:
                return hi

    d43 = h[4] - h[3]

    if d21 == d32 == d43:
        return h[0]
    elif h[2] - h[0] == d32 == d43:
        return h[1]
    elif d10 == h[3] - h[1] == d43:
        return h[2]
    elif d10 == d21 == h[4] - h[2]:
        return h[3]

import sys
f = sys.stdin

while True:
    n = int(f.readline())
    if n == 0:
        break
    h = list(map(int, f.readline().split()))
    print(get_weed(h))

Measured memory_bytes: 6740