akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod
#define AddMult(x, y, z) x = (x + (y) * (z)) % mod



signed main(){

    int H, W, d; cin >> H >> W >> d;
    int N = 1010;
    mat a(N, vec(N));
    REP(i, N) REP(j, N) a[i][j] = (i / d) % 2 + 2 * ((j / d) % 2);
    vector<char> s({'R', 'Y', 'G', 'B'});
    REP(i, H){
        REP(j, W) cout << s[a[i + j][i - j + 500]];
        cout << endl;
    }

    return 0;
}


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

int main() {
    int N, ta, xa, ya;
    int tc = 0, xc = 0, yc = 0;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> ta >> xa >> ya;
        int td = ta - tc;
        int dist = abs(xa - xc) + abs(ya - yc);
        if ((dist > td) || (dist % 2 != td % 2)) {
            cout << "No" << endl;
            return 0;
        }
        tc = ta;
        xc = xa;
        yc = ya;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3556
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let v = read_vec::<usize>();
    println!("{}", v.iter().max().unwrap() - v.iter().min().unwrap());
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N;
    string s;
    cin >> N >> s;
    vector<int> et(N, 0);
    vector<int> wt(N, 0);
    for (int i = 0; i < N; i++)
    {
        wt[i] += (s[i]=='W');
        if(i+1<N)wt[i+1]=wt[i];
    }
    for (int i = N-1; i >= 0; i--)
    {
        et[i] += (s[i]=='E');
        if(i-1>=0)et[i-1]=et[i];
    }
    int ans=N;
    for (int i = 0; i < N; i++)
    {
        int t;
        if(i==0)t=et[1];
        else if(i==N-1)t=wt[N-2];
        else t = wt[i-1]+et[i+1];
        ans = min(ans, t);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
#define re register int
#define F(x,y,z) for(re x=y;x<=z;x++)
#define FOR(x,y,z) for(re x=y;x>=z;x--)
typedef long long ll;
#define I inline void
#define IN inline int
#define C(x,y) memset(x,y,sizeof(x))
#define STS system("pause")
template<class D>I read(D &res){
	res=0;register D g=1;register char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')g=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		res=(res<<3)+(res<<1)+(ch^48);
		ch=getchar();
	}
	res*=g;
}
const int N=(1<<18)+10,Mod=998244353,inv2=499122177;
int n,m,p[N],s,S,a[N],b[N];
I add(int &x,int y){(x+=y)>=Mod?x-=Mod:0;}
IN Plus(int x,int y){(x+=y)>=Mod?x-=Mod:0;return x;}
IN Pow(int x,int y=Mod-2){
	re res=1;
	while(y){
		if(y&1)res=(ll)res*x%Mod;
		x=(ll)x*x%Mod;
		y>>=1;
	}
	return res;
}
I fwt(int *f,int sn){
	for(re i=1;i<S;i<<=1){
		for(re p=i<<1,j=0;j<S;j+=p){
			F(k,0,i-1){
				re X=f[j+k],Y=f[i+j+k];
				f[j+k]=Plus(X,Y);f[i+j+k]=Plus(X,Mod-Y);
				if(sn==-1)f[j+k]=(ll)f[j+k]*inv2%Mod,f[i+j+k]=(ll)f[i+j+k]*inv2%Mod;
			}
		}
	}
}
int main(){
	read(n);S=1<<n;
	F(i,0,S-1)read(p[i]),add(s,p[i]);
	s=Pow(s);F(i,0,S-1)p[i]=(ll)p[i]*s%Mod;add(p[0],Mod-1);
	F(i,1,S-1)b[i]=Mod-1;b[0]=S-1;
	fwt(b,1);fwt(p,1);
	F(i,0,S-1)b[i]=(ll)b[i]*Pow(p[i])%Mod;
	fwt(b,-1);
	F(i,0,S-1)printf("%d\n",Plus(b[i],Mod-b[0]));
	return 0;
}



Measured memory_bytes: 5528
import sys
input = sys.stdin.readline


def main():
    N, K = [int(x) for x in input().split()]
    H = [int(x) for x in input().split()]

    dp = [0] * (N + 1)
    dp[2] = abs(H[0] - H[1])

    for i in range(3, N + 1):
        mi = float("inf")
        for j in range(i - 1, i - K - 1, -1):
            if j == 0:
                break
            mi = min(mi, dp[j] + abs(H[j - 1] - H[i - 1]))
        dp[i] = mi

    print(dp[N])




if __name__ == '__main__':
    main()



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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int a[4][4];
map <int, pii> pos;

int main()
{
  fastio;
  for (int i = 1; i <= 3; i++){
    for (int j = 1; j <= 3; j++){
      int x; cin >> x;
      pos[x] = pii(i, j);
    }
  }
  int n; cin >> n;
  for (int i = 1; i <= n; i++){
    int x; cin >> x;
    if (pos.count(x)) a[pos[x].first][pos[x].second] = true;
  }
  for (int i = 1; i <= 3; i++){
    if (a[1][i] + a[2][i] + a[3][i] == 3) return cout << "Yes", 0;
    if (a[i][1] + a[i][2] + a[i][3] == 3) return cout << "Yes", 0;  
  }
  if (a[1][1] + a[2][2] + a[3][3] == 3) return cout << "Yes", 0;
  if (a[1][3] + a[2][2] + a[3][1] == 3) return cout << "Yes", 0;
  cout << "No";
  return 0;
}

Measured memory_bytes: 256
import math

n=int(input())
minx,miny=0,0

for i in range(math.floor(n**0.5),1,-1):
    if n%i==0:
        minx=i
        miny=n//i
        break
else:
    minx=n
    miny=1


timestep=minx+miny-2
print(timestep)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) throws IOException {
  	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int k = Integer.parseInt(br.readLine());
    
    long sum = 0L;
    for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k; j++)
        for (int s = 1; s <= k; s++)
          sum += gcd(gcd(i, j), s);
    
    System.out.print(sum);
  }
  
  private static int gcd(int a, int b) {
  	while (b != 0) {
      int t = b;
      b = a % b;
      a = t;
    }
    
    return a;
  }
}


Measured memory_bytes: 32724
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <set>
#include <sstream>
#include <string>
#include <queue>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define foreach(it, v) for(typeof(v.begin()) it=v.begin(); it!=v.end(); ++it)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;

//MOD//
const ll MOD = 1000000007;
struct big;
big ex(big a, ll tms);
typedef struct big{
  ll val;
  big():val(0){}
  big(ll val):val((val%MOD+MOD)%MOD){}
  big& operator += (const big& obj){ (val+=obj.val)%=MOD; return *this;}
  big& operator -= (const big& obj){ (val+=MOD-obj.val)%=MOD; return *this;}
  big& operator *= (const big& obj){ (val*=obj.val)%=MOD; return *this;}
  big& operator /= (const big& obj){ (val*=ex(obj,MOD-2).val)%=MOD; return *this;}
  big operator + (const big& obj)const{ return big(*this) += obj;}
  big operator - (const big& obj)const{ return big(*this) -= obj;}
  big operator * (const big& obj)const{ return big(*this) *= obj;}
  big operator / (const big& obj)const{ return big(*this) /= obj;}
  bool operator < (const big& obj)const{ return val < obj.val;}
  bool operator == (const big& obj)const{ return val == obj.val;}
} big;
istream& operator >> (istream& i, big& obj){ i>>obj.val; return i;}
ostream& operator << (ostream& o, const big& obj){ o<<obj.val; return o;}
big ex(big obj, ll tms){
  if(!tms) return 1;
  big ret = ex(obj, tms/2);
  ret *= ret;
  return (tms&1) ? ret*obj : ret;
}
//MOD//

ll pow(ll n, int m){
  if(!m) return 1;
  ll ret = pow(n, m/2);
  ret *= ret;
  return (m&1) ? ret*n : ret;
}

template <class F, class T>
void convert(const F &f, T &t){
  stringstream ss;
  ss << f;
  ss >> t;
}

int L, N;
long int X[200010];

int main(){
  scanf("%d%d",&L,&N);
  rep(i, N) scanf("%ld",&X[i]);

  long int ans = 0;
  long int b = L - X[0];
  ans = max(ans, b);
  if (N>1) {
    b = X[0] + (L - X[1]) * 2;
    ans = max(ans, b);
  }
  for(int i=2; i < N; ++i) {
    if (i%2==0) {
      long int l = b + X[i/2-1] + L + X[i/2] - X[i]*2;
      ans = max(ans, l);
      b = l;
    } else {
      long int l = b + (X[i/2] - X[i]) * 2 + L;
      ans = max(ans, l);
      b = l;
    }
  }

  rep(i,N/2) {
    long int c = X[i];
    X[i] = L - X[N-1-i];
    X[N-1-i] = L - c;
  }
  if (N%2==1) X[N/2] = L - X[N/2];

  b = L - X[0];
  ans = max(ans, b);
  if (N>1) {
    b = X[0] + (L - X[1]) * 2;
    ans = max(ans, b);
  }
  for(int i=2; i < N; ++i) {
    if (i%2==0) {
      long int l = b + X[i/2-1] + L + X[i/2] - X[i]*2;
      ans = max(ans, l);
      b = l;
    } else {
      long int l = b + (X[i/2] - X[i]) * 2 + L;
      ans = max(ans, l);
      b = l;
    }
  }

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


Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
int main()
{
    char string[1050], nstring[1050];

    int length, i, w, j;

    gets(string);

    length=strlen(string);

    scanf("%d", &w);

    for(i=0, j=0; i<length; i=i+w, j++)
    {
        nstring[j]= string[i];
    }
    nstring[j]='\0';

    printf("%s\n", nstring);

    return 0;
}


Measured memory_bytes: 128
import math
A,B,N = map(int,input().split())
max = 0
m = []
def f(x):
  return math.floor(A*x/B) - A*math.floor(x/B)

if N < B:
  max = f(N)
elif N == B:
  max = f(N-1)
else:
  max = f(B-1)
print(max)

Measured memory_bytes: 9128
#include<bits/stdc++.h>
using namespace std;
map<int,int> m;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            m[i*j]=1;
        }
    }
    if(m[n]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
template<class T>
void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>
void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	cout<<111*((n-1)/111+1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
using namespace std;
typedef long long LL;   
typedef unsigned long long ull;   
const int Mod = 1e6 + 7;
const int maxn = 2e5 + 5;
const double eps = 0.00000001;
const int INF = 0x3f3f3f3f;
inline int read()//inline 加速读入
{
	int x=0;char c=getchar();//x代表返回值，c代表读取的字符
	while (c<'0'||c>'9') c=getchar();//读取所有非数部分
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();//如果读取的字符为数，加入返回值
	return x;
}
long long a[300001],b[300001];
long long n,x,ans,sum;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		x=max(x,a[i]);
		b[a[i]]++;
	}
	for(int i=1;i<=x;i++)
	{
		if(b[i]>=2)ans+=b[i]*(b[i]-1)/2;
	}
	for(int i=1;i<=n;i++)
	{
		x=b[a[i]]-1;
		if(x>=1){
			sum=ans-(x+1)*x/2;
			sum+=x*(x-1)/2;
		}else sum=ans;
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (auto &&i : S) {
        cin >> i;
    }
    vector<int> dx = {-1, 1, 0, 0};
    vector<int> dy = {0, 0, -1, 1};
    auto exist     = [](int H, int W, int nx, int ny) -> bool {
        if (nx < 0 || W <= nx || ny < 0 || H <= ny)
            return false;
        else
            return true;
    };
    vector<vector<bool>> visited(H, vector<bool>(W));
    ll black, white;

    auto dfs = [&](auto f, int x, int y) {
        if (visited[y][x])
            return;
        visited[y][x] = true;
        if (S[y][x] == '#')
            black++;
        else
            white++;
        char next = S[y][x] == '#' ? '.' : '#';
        REP(i, 4) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (exist(H, W, nx, ny) && next == S[ny][nx]) {
                f(f, nx, ny);
            }
        }
        return;
    };
    ll ans = 0;

    REP(y, H) {
        REP(x, W) {
            if (S[y][x] == '#') {
                black = white = 0;
                dfs(dfs, x, y);
                ans += black * white;
            }
        }
    }

    std::cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 16768
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main () {
  int n,ac = 0,wa = 0,tle = 0,re;
  cin >> n;
  string s[n];
  for (int i = 0; i < n; i++){
    cin >> s[i];
    if (s[i] == "AC"){
      ac++;
    }
    if (s[i] == "WA"){
      wa++;
    }
    if (s[i] == "TLE"){
      tle++;
    }
    if (s[i] == "RE"){
      re++;
    }
  }
  cout << "AC x " << ac << '\n' << "WA x " << wa << '\n' << "TLE x " << tle << '\n' << "RE x " << re << '\n';
  return 0;
}

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

/*
1-----2---3--4-5------6
あるく＜てれぽならてれぽで1町すすめるだけ？


*/
int main(){
  ll N,A,B,ans=0; cin>>N>>A>>B;
  vector<ll> X(N+10,0);
  for(ll i=0; i<N; i++)cin>>X[i];
  for(ll i=1; i<N; i++){
    ll d=X[i]-X[i-1];
    ll a=d*A;
    if(a<B) ans+=a;
    else ans+=B;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define ios; ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define ls(x) (x<<1)
#define rs(x) (ls(x)|1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef double db;
mt19937 rnd(random_device{}());
const int mod = 1e9 + 7;
const int N = 2e6 + 5;
const int M = 2e6 + 5;
inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
inline ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll ksm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
int a[N],b[N],rt[N*20],ls[N*20],rs[N*20],sum[N*20],vis[N*20];
int n,q,k;
int id;
void build(int &o,int l,int r){
	o=++id;
	sum[o]=0;
	if(l==r) return;
	int m=(l+r)>>1;
	build(ls[o],l,m);
	build(rs[o],m+1,r);
}

void update(int &o,int l,int r,int last,int pos,int val){
	o=++id;
	ls[o]=ls[last];
	rs[o]=rs[last];
	sum[o]=sum[last]+val;
	if(l==r) return;
	int m=(l+r)>>1;
	if(pos<=m)
        update(ls[o],l,m,ls[last],pos,val);
	else
        update(rs[o],m+1,r,rs[last],pos,val);
}
int query(int pos,int root,int l,int r){
	if(l==r)
        return sum[root];
	int m=(l+r)>>1;
	if(m>=pos)
        return sum[rs[root]]+query(pos,ls[root],l,m);
	else
        return query(pos,rs[root],m+1,r);
}
void solve(){
    int l, r;scanf("%d%d",&l,&r);
    printf("%d\n",query(l,rt[r],1,n));
}

int main(){
    memset(vis,0,sizeof(vis));
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    id=0;
    build(rt[0],1,n);
    for(int i=1;i<=n;i++){
        if(!vis[a[i]])
            update(rt[i],1,n,rt[i-1],i,1);
        else{
            int pos=vis[a[i]];
            int temp;
            update(temp,1,n,rt[i-1],pos,-1);
            update(rt[i],1,n,temp,i,1);
        }
        vis[a[i]]=i;
    }
    while(q--) solve();
	return 0;
}
/*
a b a+b+c*2
a a+b*2+c*4 a+b+c*2
a+b+c*4

*/
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     佛祖保佑      永无BUG


Measured memory_bytes: 409184
/*-----rk_98-----*/
#include<bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define eps 1e-9
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
using namespace std;
int main()
{
    //fast();
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    for(ll i=0;i<n;i++)
    	cin>>arr[i];
    ll dp[n+2][k +20];
    memset(dp, 0 ,sizeof dp);
    dp[0][0]=1;
    dp[0][arr[0] + 1] =-1;
    for(ll i=1;i<n;i++)
    {
    	for(ll j =0; j<=k;j++)
    	{
    		if(j)
    			dp[i-1][j] = ( dp[i-1][j] + dp[i-1][j-1] ) % mod;
    		// if(dp[i-1][j] == 0) 
    		// 	break;
    		dp[i][j] = ( dp[i][j] + dp[i-1][j] ) % mod;
    		if( (j+ arr[i] + 1) <= (k+10) ) 
    			dp[i][j + arr[i] +1 ] = ( dp[i][j + arr[i] +1 ] - dp[i-1][j] + mod ) % mod;
    	}
    }
    for(ll i =1 ;i<=k;i++)
    	dp[n-1][i] = ( dp[n-1][i] + dp[n-1][i-1] ) % mod;
    cout<<dp[n-1][k]<<endl;    
}


Measured memory_bytes: 80000
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
	int n, k;
	int h[100010];
	cin >> n >> k;
	rep(i, n)cin >> h[i];
	sort(h, h + n);
	int ans = 1e9;
	for (int i = 0;i < n - k + 1;i++) {
		ans = min(ans, h[i + k - 1] - h[i]);
	}
	cout << ans << endl;
	getchar();getchar();
	return 0;
}

Measured memory_bytes: 640
n, m = gets.split.map(&:to_i)
query = m.times.map.with_index { |_, id| gets.split.map(&:to_i) << id }
pre = -1
cnt = 0
query.sort_by! { |s| s[1] }.sort_by! { |s| s[0] }.map! do |s|
  if s[0] != pre
    pre = s[0]
    cnt = 1
  else
    cnt += 1
  end
  s << cnt
end
query.sort_by { |s| s[2] }.each { |s| puts "%06d%06d" % [s[0], s[3]] }


Measured memory_bytes: 31920
a, b = [int(i) for i in input().split()]

if a < 0 and b < 0:
    if (b - a + 1) % 2 == 0:
        print("Positive")
    else:
        print("Negative")
elif a > 0 and b > 0:
    print("Positive")
else:
    print("Zero")


Measured memory_bytes: 2940
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x)  ((int)x.size ())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define sqrt(x) sqrt (abs(x))
#define y0 y3451
#define y1 y4562
#define j0 j25624
#define j1 j45624
#define makeunique(x) sort(all(x)), (x).resize (unique(all(x)) - (x).begin())

typedef pair <int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef long double ld;
typedef unsigned int uint;
typedef vector <string> vs;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;

template <class T> using _tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }
template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }
template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }

#define filename ""

const D pi = acos(-1.);
const int N = 1e5 + 20;
const int inf = 2e9 + 7;

ll n, mod;
vi g[N];
ll dp[N], d[N], ans[N];
ll t[4 * N];

void upd (int v, int tl, int tr, ll x, int pos) {
	if (tr == tl) { t[v] = x; re; }
	int c = (tl + tr) >> 1;
	if (pos > c) upd(2 * v + 2, c + 1, tr, x, pos);
	else upd(2 * v + 1, tl, c, x, pos);
	t[v] = t[2 * v + 1] * t[2 * v + 2] % mod;
}

void dfs(int v, int pr = -1) {
	dp[v] = 1;
	for (auto x : g[v])
		if (x != pr) {
			dfs(x, v);
			dp[v] = (dp[v] * (dp[x] + 1)) % mod;
		}				
}

void get(int v, int pr = -1)  {	
    upd(0, 0, n - 1, d[v], v);
	for (auto x : g[v]) 
		if (x != pr)
			upd(0, 0, n - 1, (dp[x] + 1) % mod, x);
	for (auto x : g[v]) 
		if (x != pr) {
			upd(0, 0, n - 1, 1, x);
			d[x] = (t[0] + 1) % mod;
			upd(0, 0, n - 1, (dp[x] + 1) % mod, x);
	}
    upd(0, 0, n - 1, 1, v);
	for (auto x : g[v])
		if (x != pr) 
			upd(0, 0, n - 1, 1, x);
	for (auto x : g[v])
		if (x != pr)
			get(x, v);	
}

int main() {
	cin >> n >> mod; 
	for (int i = 0; i < 4 * N; i++) t[i] = 1;
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		x--; y--;
		g[x].pb(y); 
		g[y].pb(x);
	}
	dfs(0);
	d[0] = 1;
	get(0);
	for (int i = 0; i < n; i++)
		printf("%I64d\n", dp[i] * d[i] % mod);
}

Measured memory_bytes: 21888
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String str = in.readLine();
    System.out.println(str.charAt(0)==str.charAt(1)&&
                       str.charAt(1)==str.charAt(2)?"No":"Yes");
  }
}

Measured memory_bytes: 24788
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    ll sum = 0;
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }
    ll ans = 1e18;
    ll temp = 0;
    rep(i,n-1){
        temp += a[i];
        ans = min(ans, abs(2*temp-sum));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1920
def getMode(target:list):
    cache = {}
    for x in target:
        if x in cache:
            cache[x] = cache[x] + 1
        else:
            cache[x] = 1
    return sorted(cache.items(), key=lambda x: x[1], reverse=True)


n = int(input())
v = [int(x) for x in input().split()]

guu = []
ki = []
for i, n in enumerate(v):
    if i % 2 == 0:
        guu.append(n)
    else:
        ki.append(n)

gMode = getMode(guu)
g = gMode[0][0]
kMode = getMode(ki)
k = kMode[0][0]

if g == k:
    if len(gMode) == 1 and len(kMode) == 1:
        k = k + 1
    elif len(gMode) == 1 or len(kMode) == 1:
        if len(gMode) == 1:
            k = kMode[1][0]
        else:
            g = gMode[1][0]
    elif gMode[0][1] == kMode[0][1]:
        if gMode[1][1] < kMode[1][1]:
            k = kMode[1][0]
        else:
            g = gMode[1][0]
    elif gMode[0][1] < kmode[0][1]:
        g = gMode[1][0]
    else:
        k = kMode[1][0]    

result = 0
for n in guu:
    if n != g:
        result += 1

for n in ki:
    if n!= k:
        result += 1

print(result)

Measured memory_bytes: 20828
#include<bits/stdc++.h>
#define int long long

using namespace std;

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

    int a, b;
    cin >> a >> b;
    
    if (max(a, b) > 9)
        cout << "-1\n";
    else
     cout << a * b << '\n';

    return 0;
}

//      *   *  *****  *   *  *   *
//     *   *  *      **  *  *   *
//    *****  *****  * * *  *   *
//   *   *      *  *  **  *   *
//  *   *  *****  *   *   ***
//     *****  *****  *****
//    *      *   *  *
//   *      *****  *
//  *      *  *   *
//  ***** *   *   *****


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
const int maxc = 10005;
int G[11][maxc], rG[11][maxc];
int main()
{
    int c, r;
    while(true){
        scanf("%d%d", &r, &c);
        if(r == 0 && c == 0) break;
        for(int i = 1; i <= r; i++) {
            for(int j = 1; j <= c; j++) {
                scanf("%d", &G[i][j]);
                rG[i][j] = G[i][j];
            }
        }
        int ans = 0;
        for(int i = 0; i < (1 << r); i++) {
            for(int j = 0; j < r; j++) {
                if((i >> j) & 1) {
                    for(int k = 1; k <= c; k++) {
                        G[j + 1][k] = 1 - G[j + 1][k];
                    }
                }
            }
            int nans = 0;
            for(int j = 1; j <= c; j++) {
                int sum = 0;
                for(int k = 1; k <= r; k++) {
                    sum += G[k][j];
                }
                nans += max(r - sum, sum);
            }
            ans = max(nans, ans);
            for(int j = 1; j <= r; j++) {
                for(int k = 1; k <= c; k++) {
                    G[j][k] = rG[j][k];
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



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

class node{
	public:
		node* left;
		node* right;
		node* p;
		int key;
		node(){
			left=NULL;
			right=NULL;
			p=NULL;
		}
		node(int k){
			left=NULL;
			right=NULL;
			p=NULL;
			key=k;
		}
};

node* root=NULL;
int a[500002];
int n=0;

void insert(node*);
void print();
void preorder(node*);
void midorder(node*);

void insert(node* z){
	node *y=NULL;
	node *x=root;
	while(x!=NULL){
		y=x;
		if(z->key<x->key)x=x->left;
		else x=x->right;
	}
	z->p=y;
	if(y==NULL){
		// delete root;
		root=z;
	// cout<<"root:"<<root->key<<endl;
	}else if(z->key<y->key)y->left=z;
	else y->right=z;
}

void print(){
	midorder(root);
	cout<<endl;
	preorder(root);
	cout<<endl;
}

void midorder(node* i){
	if(i==NULL)return;
	midorder(i->left);
	// if(i!=root)cout<<" "<<i->key;
	cout<<" "<<i->key;
	midorder(i->right);
}

void preorder(node* i){
	if(i==NULL)return;
	// if(i!=root)cout<<" "<<i->key;
	cout<<" "<<i->key;
	preorder(i->left);
	preorder(i->right);
}

int main(void){
	int q,k;
	string s;
	cin>>q;
	while(q--){
		cin>>s;
		if(s[0]=='i'){
			cin>>k;
			insert(new node(k));
		}else if(s[0]=='p'){
			print();
		}
	}
	return 0;
}

Measured memory_bytes: 26556
#include<bits/stdc++.h>
#include<math.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
using namespace std;

//const double pi = boost::math::constants::pi<double>();
ll mod=1000000007;

ll expo(ll base, ll exponent, ll mod) { //return base^exponent modulo modulus
    ll ans = 1;
    while(exponent !=0 ) {
        if((exponent&1) == 1) {
            ans = ans*base ;
            ans = ans%mod;
        }
        base = base*base;
        base %= mod;
        exponent>>= 1;
    }
    return ans%mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll tests=1;
   // cin>>tests;
    while(tests--)
    {
       ll n,i;
       string s,ans;
       cin>>n;
       cin>>s;
       ll j=int('A');
       //cout<<j<<"\n";
       vector<char>v(26);
       for(i=0;i<26;i++)
       {v[i]=char(i+j);}
       for(auto x:s)
       {
           ans.pb(v[(int(x)+n-j)%26]);
       }
        cout<<ans;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

bool ok(string s){
  if (s[0] != 'A')
    return 0;

  int c = 0;
  for (int i = 2; i < s.size() - 1; i++){
    if (s[i] == 'C')
      c++;
  }
  if (c != 1)
    return 0;


  int n = 0;
  for (int i = 0; i < s.size(); i++){
    if ('a' <= s[i] && s[i] <= 'z')
      n++;
  }

  if (n != s.size() - 2)
    return 0;


  return 1;
}

int main(void){
  string s;
  cin >> s;
  
  if (ok(s))
    cout << "AC" << endl;
  else 
    cout << "WA" << endl;

  return 0;
}


Measured memory_bytes: 256
while True:
    n = input()
    ans = []
    if n == 0: break
    tmp = [0] * (n+1)
    for i in range(n):
        ans.append(map(int, raw_input().split()))
        ans[i].append(sum(ans[i]))
        for j in range(len(ans[i])):
            tmp[j] += ans[i][j]
    ans.append(tmp)
    for a in ans:
        print "".join(map(lambda x: str(x).rjust(5), a))

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

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

int N, p[30000];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> N;
    REP(i, N) {
        int a;
        cin >> a;
        a--;
        p[a] = i + 1;
    }

    REP(i, N) {
        if (i != 0) cout << " ";
        cout << 30000 * i + 1;
    }
    cout << endl;

    REP(i, N) {
        if (i != 0) cout << " ";
        cout << 30000 * (N - i) + 1 + p[i];
    }
    cout << endl;

    return 0;
}


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

int main(int argc, const char * argv[]) {
    long long X;
    int A=0, B=0;
    cin >> X;
    
    for(int i=0; i<500; i++){
        for(int j=0; j<500; j++){
            long long Apow5=0, Bpow5=0;
            Apow5 = pow(j, 5);
            Bpow5 = pow(i, 5);
            
            if(X == Apow5-Bpow5){
                A=j;
                B=i;
                goto END;
            }
            
            Bpow5 = pow(-i, 5);
            if(X == Apow5-Bpow5){
                A=j;
                B=-i;
                goto END;
            }
        }
    }
    
    END:
    cout << A << " " << B << endl;
    
    return 0;
}

Measured memory_bytes: 4008
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 99999999999999999
#define MOD 1000000007 

void func()
{
    ll n;
    cin>>n;
    ll a[n];
    vector<ll> v(1000001);
    vector<ll> s(1000001);
    loop(i,0,n){
        cin>>a[i];
        v[a[i]]++;
    }
    sort(a,a+n);
    //set<ll> s;
    ll ans=0;
    loop(i,0,n){
        if(v[a[i]]>1){
            s[a[i]]++;
            continue;
        }
        bool flag=true;
        ll q=sqrt(a[i]);
        loop(j,1,q+1){
            if(a[i]%j==0){
                if(s[j]>0||s[a[i]/j]>0){
                    flag=false;
                    break;
                }
            }
        }
        if(flag){
            //cout<<a[i]<<"\n";
            ++ans;
        }
        s[a[i]]++;
    }
    cout<<ans<<"\n";
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }
}

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

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

    if (A == 0) {
        cout << 0 << endl;
    } else if (N <= A){
        cout << N << endl;
    } else if (N <= A + B) {
        cout << A << endl;
    } else {
        if (N % (A + B) <= A) {
            cout << (N / (A + B)) * A + N % (A + B) << endl;
        } else {
            cout << (N / (A + B))* A + A << endl;
        }
    }
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;



void main() {
    long n, m;
    scan(n, m);
    auto s = readln.chomp;
    auto t = readln.chomp;

    auto l = lcm(n, m);
    auto sg = l / m;
    auto tg = l / n;

    foreach (i ; 0 .. n / sg) {
        if (s[i*sg] != t[i*tg]) {
            writeln(-1);
            return;
        }
    }

    writeln(l);
}

long lcm(long a, long b) {
    return a / gcd(a, b) * b;
}

























void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b, c;
  cin >> a >> b;
  c = "asd";
  int count = 0;
  char x = 0;
  for (int i = 0; i < a.size(); i++) {
    c = a.substr(i, a.size()-1) + a.substr(0, i);
    if (c == b) {
      count++;
    }
    if (a == b) {
      count++;
      break;
    }
  }
  if (count == 0) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}
      

Measured memory_bytes: 3608
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, h: "List[int]"):
    dp = [float('inf')] * N
    dp[0] = 0

    for i in range(len(dp)):
        if i < N - 1:
            dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]))
        if i < N - 2:
            dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]))
    return dp[-1]


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    result = solve(N, h)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 20000
#include <bits/stdc++.h>
using namespace std;
long long s,w;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("test.inp","r",stdin);
    //freopen("test.out","w",stdout);
    cin>>s>>w;
    if (w>=s) cout<<"unsafe";
    else
    cout<<"safe";
}

Measured memory_bytes: 3648
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<double> P(N);
    rep(i, N) cin >> P[i];
    vector<vector<double>> dp(N + 1, vector<double>(N + 1));
    // dp[i][j]:=i-1枚目まで見て、表がj枚出る確率
    dp[0][0] = 1;
    rep(i, N) {
        rep(j, N) {
            dp[i + 1][j + 1] += dp[i][j] * P[i];
            dp[i + 1][j] += dp[i][j] * (1.0 - P[i]);
        }
    }
    double res = 0;
    for(int i = N / 2 + 1; i <= N; i++) {
        res += dp[N][i];
    }
    cout << fixed << setprecision(10) << res << endl;
    return 0;
}

Measured memory_bytes: 73812
h,w = (int(x) for x in input().split())


num  = 1
if h != 1 and w != 1:
    num = ((w // 2) + (w % 2))*( (h // 2) + ( h% 2) ) + ((w // 2) + (w % 2)-(w%2))*( (h // 2) + (h%2) -(h%2)) 
print(num)

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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    ll N,x; cin >> N >> x;
    VL a(N); REP(i,N) cin >> a[i];
    VVL b(N,VL(N,LINF)); REP(i,N) b[i][0] = a[i];

    ll ans = 0; REP(i,N) ans += a[i];
    REP(i,N-1){
        ll tmp = (i+1)*x;
        REP(j,N){
            chmin(b[(j+1)%N][i+1], min(a[(j+1)%N], b[j][i]));
            tmp += b[(j+1)%N][i+1];
        }
        chmin(ans, tmp);
    }
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t){
        Main();
    }
    return 0;
}

Measured memory_bytes: 31616
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
MAX_NUM = 10**6 + 1
MOD = 10**9+7

fac  = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv  = [0 for _ in range(MAX_NUM)]

fac[0]  = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1

for i in range(2,MAX_NUM):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def comb(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
plus=0
minus=0
for i in range(N):
  if i>=K-1:
    plus+=(A[i]*comb(i,K-1))%(10**9+7)
A.sort(reverse=True)
for i in range(N):
  if i>=K-1:
    minus+=(A[i]*comb(i,K-1))%(10**9+7)
answer=(plus-minus)%(10**9+7)
print(answer)

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

class RangeIndex {
public:
	RangeIndex(int n) {
		m_indexes.resize(n);
		for (auto &row : m_indexes) {
			row.resize(n, 0);
		}
		m_trains.resize(n);
		for (auto &row : m_trains) {
			row.resize(n, 0);
		}
	}
	void addTrain(const int l, const int r) {
		++m_trains[l - 1][r - 1];
	}
	void constructIndex() {
		const int n = static_cast<int>(m_trains.size());
		for (int i = 0; i < n; ++i) {
			m_indexes[i][i] = m_trains[i][i];
		}
		for (int i = 0; i < n; ++i) {
			for (int j = i + 1; j < n; ++j) {
				m_indexes[i][j] = m_trains[i][j] + m_indexes[i][j - 1];
			}
		}
		for (int k = 1; k < n; ++k) {
			for (int i = 0; i + k < n; ++i) {
				m_indexes[i][i + k] = m_indexes[i][i + k] + m_indexes[i + 1][i + k];
			}
		}
	}

	int getTrainsNum(const int p, const int q) const {
		return m_indexes[p - 1][q - 1];
	}
private:
	std::vector<std::vector<int>> m_trains;
	std::vector<std::vector<int>> m_indexes;
};

int main() {
	int n, m, q;
	std::cin >> n >> m >> q;
	RangeIndex index(n);
	for (int i = 0; i < m; ++i) {
		int l, r;
		std::cin >> l >> r;
		index.addTrain(l, r);
	}
	index.constructIndex();
	for (int i = 0; i < q; ++i) {
		int l, r;
		std::cin >> l >> r;
		std::cout << index.getTrainsNum(l, r) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 2944
N = int(input())
L = list(map(int, input().split()))

c = 0
for i, Li in enumerate(L):
    for j, Lj in enumerate(L):
        for k, Lk in enumerate(L):
            if i < j < k and len(set([Li, Lj, Lk])) == 3:
                max_e, *else_e = sorted([Li, Lj, Lk], reverse=True)
                if sum(else_e) > max_e:
                    c += 1

print(c)

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

using namespace std;

const int N = 8;
int l[N], n, A, B, C;

int main() {
	cin >> n >> A >> B >> C;
	for (int i = 0; i < n; ++i)
		cin >> l[i];
	int res = 1e9 + 7;
	int cntSs1 = 0, cnts2 = 0, cnts3 = 0;
	for (int S = 0; S < (1 << n); ++S)
		for (int s1 = 1; s1 < (1 << n); ++s1)
			if ((S | s1) == S) {
				cntSs1++;
				for (int s2 = 1; s2 < (1 << n); ++s2)
					if ((s2 & s1) == 0 && (s2 | S) == S) {
						cnts2++;
						int s3 = S & (~(s1 | s2));
						if (s3 == 0) continue;
						cnts3++;
						int mp = 0, a = 0, b = 0, c = 0, cnt = 0, ja = 0, jb = 0, jc = 0;
						for (int i = 0; i < n; ++i) {
							if (s1 & (1 << i)) a += l[i], cnt++, ja++;
							if (s2 & (1 << i)) b += l[i], cnt++, jb++;
							if (s3 & (1 << i)) c += l[i], cnt++, jc++;
						}
						mp = abs(a - A) + abs(b - B) + abs(c - C) + 10 * (ja + jb + jc - 3);
						res = min(res, mp);
					}
			}
	printf("%d", res);
	return 0;
}


Measured memory_bytes: 256
def cal(a,b):
    return a**5-b**5

def main():
    X = int(input())
    update = True
    for i in range(10**3):
        for j in range(10**3):
            if cal(i,j) == X:
                a,b = i,j
                update = False
                break
            if cal(i,-j) == X:
                a,b = i,-j
                update = False
                break
        if not update:
            break

    print(a,b)

if __name__ == "__main__":
    main()


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

int main()
{
	bool check=1;
	char a,b,c;
	scanf("%c%c%c",&a,&b,&c);
	if(!(a=='a'||b=='a'||c=='a'))check=0;
	if(!(a=='b'||b=='b'||c=='b'))check=0;
	if(!(a=='c'||b=='c'||c=='c'))check=0;
	if(check) printf("Yes");
	else printf("No");
	return 0;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#define  ONLINE_JUDGE 1
int main()
{
	/*
	#ifdef ONLINE_JUDGE
	freopen("C:/Users/wyx/Desktop/Amy/wangyixuan/c++/test data/data.txt", "r",stdin);
	#endif
	*/
	/*---------------Begin code---------------*/
	long long n;
	cin>>n;
	int ans[n],a;
	for(int i=0;i<n;i++)
	{
		ans[i]=0;
	}
	for(int i=1;i<n;i++)
	{
		cin>>a;
		ans[a-1]++; 
	}
	for(int i=0;i<n;i++)
	{
		if(i==n-1)
		{
			cout<<ans[i];
		}
		else
		{
			cout<<ans[i]<<endl;
		}
	}
	/*---------------End  code----------------*/
	/*#ifdef ONLINE_JUDGE
	fclose(stdin);
	#endif
	system("pause");
	*/
	return 0;
}

Measured memory_bytes: 4400
#include<bits/stdc++.h>
using namespace std;
int n,d[101][2];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d %d",&d[i][0],&d[i][1]);
	for(int i=1;i+2<=n;i++)
		if(d[i][0]==d[i][1]&&d[i+1][0]==d[i+1][1]&&d[i+2][0]==d[i+2][1])
		{
			puts("Yes");
			return 0;	
		} 
	puts("No");
	return 0;
}

Measured memory_bytes: 3680
h1, w1 = gets.strip.split.map(&:to_i)
h2, w2 = gets.strip.split.map(&:to_i)

a = Array.new(h1).map { Array.new(w1){0} }

h2.times do |i|
  w1.times do |j|
    a[i][j] = 1
  end
end

h1.times do |i|
  w2.times do |j|
    a[i][j] = 1
  end
end

count = 0
h1.times do |i|
  count += a[i].select { |d| d == 0 }.size
end

puts count

Measured memory_bytes: 1916