akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#define MOD 1000000007
using namespace std;
int main(void){
    int n, t[100000], a[100000], v;
    long long ans = 1;
    cin >> n;
    for(int i=0;i<n;i++)cin >> t[i];
    for(int i=0;i<n;i++)cin >> a[i];
    if(t[n-1] != a[0])ans = 0;
    v = n-2;
    for(int i=1;i<n;i++){
        v--;
        if(t[i] <= t[i-1])ans *= t[i];
        ans %= MOD;
        if(t[i] == t[n-1])break;
    }
    for(int i=n-2;i>=0;i--){
        v--;
        if(a[i] <= a[i+1])ans *= a[i];
        ans %= MOD;
        if(a[i] == a[0])break;
    }
    if(v <= -2)ans = 0;
    while(v-- > 0){
        ans *= a[0];
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
//use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define pi acos(-1.0)
/*
#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second*/
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)


int main()
{

    int i,x,n,v,ans,val;

    set<int> s;

    rep(i,-2,105)
        s.insert(i);

    cin>>x>>n;

    rep(i,1,n+1)
    {
        cin>>v;

        s.erase(v);
    }

    ans=INT_MAX;

    for(auto u : s)
    {
        if(abs(u-x)<ans)
        {
            ans = abs(u-x);
            val = u;
        }

    }

    cout<<val;

    return 0;
}

Measured memory_bytes: 3636
import fractions
import functools

def lcm(n1, n2):
    return n1 * n2 // fractions.gcd(n1, n2)

N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
    A[i] //= 2

lcmA = functools.reduce(lcm, A)
gcdA = functools.reduce(fractions.gcd, A)
if (lcmA // gcdA) % 2 == 0:
    print(0)
else:
    print((M // lcmA + 1) // 2)



Measured memory_bytes: 16320
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
double kyori(P a, P b) {
	double kyori;
	kyori = sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));
	return kyori;
}
int main(void) {
	int n;
	cin >> n;
	vector<P>p(n);
	vector<ll>b(n);
	int x, y;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		p[i] = make_pair(x, y);
	}

	for (int i = 1; i <= n; i++) {
		b[i-1] = i;
	}
	
	double sum = 0;
	do {
		for (int i = 0; i < n - 1; i++) {
			sum += kyori(p[b[i] - 1], p[b[i + 1] - 1]);
		}
		
	} while (next_permutation(b.begin(), b.end()));
	int index = 1;
	for (int i = n; i >= 1; i--) {
		index *= i;
	}
	cout << fixed<<setprecision(10)<<sum / index << endl;
	return 0;
}


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

int N;
vector<int> win[100100];

// 1-indexed
int dp[100100];
int rec(int root) {

  if (dp[root] != -1) return dp[root];

  int child = win[root].size();
  if (child == 0) return dp[root] = 0;

  int mn = 1 << 30, mx = -1, cnt = 0;
  vector<int> d;
  for (auto& des: win[root]) d.push_back(rec(des));
  sort(d.rbegin(), d.rend());
  for (int i = 0; i < d.size(); ++i) d[i] += i + 1;

  int ret = -1;
  for (auto& e: d) if (e > ret) ret = e;

  return dp[root] = ret;

}

signed main() {

  cin >> N;
  for (int i = 2; i <= N; ++i) {
    int A;  cin >> A;
    win[A].push_back(i);
  }

  memset(dp, 0xff, sizeof(dp));

  cout << rec(1) << endl;

  // for (int i = 0; i < 10; ++i) cerr << i << " : " << dp[i] << endl;

}


Measured memory_bytes: 17024
#include<stdio.h>
#include<string.h>
  char ha[1<<21],k[256];
int main(int argc,char *argv[]){
  int flg;
  int val,s,t;
  char c;
  k['T'] = 1;
  k['G'] = 2;
  k['C'] = 3;
  k['A'] = 4;
   
  scanf("%d", &val);
  getchar();
  while (val--) {
    s = 0;
    t = 1;
    flg = ( c = getchar() ) == 'i';
    while ( ( c = getchar() ) != ' ' );
    while ( ( c = k[getchar()] ) != 0 ) {
      s += c * t;
      t *= 4;
    }
    if (flg) ha[s] = 1; else puts( ha[s] ? "yes" : "no" );
  }
  return 0;
}
 

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

int main(){
  int a,b;
  cin >> a >> b;
  string s;
  cin >> s;
  
  bool flag = true;
  for(int i = 0; i < a; i++){
    if(!isdigit(s[i])) flag = false;
  }
  if(s[a] != '-') flag = false;
  for(int i = a + 1; i < a + b + 1; i++){
    if(!isdigit(s[i])) flag = false;
  }
  
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
def main():    
    _ = int(input())
    h = list(map(int,input().split()))
    c = 0
    ans = 0
    for i in range(len(h)-1):
        if h[i] >= h[i+1]:
            c += 1
        else:
            if c > ans:
                ans = c
            c = 0
    if c > ans:
        ans = c
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 14252
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<ctime>
#include<cmath>
#include<cstdlib>
#include<utility>
#include<bitset>
using namespace std;
const int maxn=110;
int n,f[maxn][10],p[maxn][11],ans=-1000000000;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<10;j++)
		{
			cin>>f[i][j];
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<11;j++)
		{
			cin>>p[i][j];
		}
	}
	for(int i=1;i<1024;i++)
	{
		int tmp=0;
		for(int j=0;j<n;j++)
		{
			int cnt=0;
			for(int k=0;k<10;k++)
			{
				if((i&(1<<k))&&(f[j][k]))
				{
					++cnt;
				}
			}
			tmp+=p[j][cnt];
		}
		ans=max(ans,tmp);
	}
	cout<<ans<<endl;
	return 0;
}


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

#define ll long long
#define eb emplace_back
#define fi first
#define se second

using namespace std;

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	ll l, r, d;
	cin >> l >> r >> d;
	ll res = 0;
	for (ll i = l; i <= r; ++i) {
		res += (i % d == 0);
	}
	cout << res << "\n";
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    int a[q];
    rep(i,q)cin >> a[i];

    // 全部1つの配列でやる
    int f_[m+1] = {};
    srep(i,1,m+1)f_[i] = 1001001 + i;
    rep(i,q)f_[a[i]] = -i;
    vector<P> v_;
    srep(i,1,m+1)v_.push_back(P(f_[i], i));
    sort(v_.begin(), v_.end());
    int flag_ = 1;
    rep(i,m)if(v_[i].second != i+1)flag_ = 0;
    if(flag_){
        cout << "Yes" << endl;
        return 0;
    }

    // 後ろから貪欲
    vector<P> v;
    map<int,int> mp;
    drep(i,q){
        int aa = a[i];
        if(mp.find(aa) == mp.end()){
            v.push_back(P(aa, 1));
            mp[aa] = v.size() - 1;
        }else{
            int ite = mp[aa];
            if(ite == 0){
                v[ite].second++;
                if(v[ite].second > n)v[ite].second = n;
            }else{
                v[ite].second++;
                if(v[ite].second > v[ite-1].second)v[ite].second = v[ite-1].second;
            }
        }
    }

    /*
    cout << v.size() << endl;
    rep(i,v.size())cout << v[i].first << ' ' << v[i].second << endl;
    */
    int flag = 1;

    /*
    int mex = 1;
    int cnt[m+1] = {};
    rep(i,v.size()){
        cnt[v[i].first] = v[i].second;
    }
    srep(i,1,m+1){
        if(cnt[i] >= n)mex++;
        else break;
    }
    int last = -1;
    drep(i,v.size()){
        if(v[i].first <= mex){
            last = i;
            break;
        }
    }
    */


    /*
    drep(i,v.size()){
        // if(i == last)break;
        if(i == v.size() - 1 && v[i].first <= mex)continue;
        if(v.size() == m && i == v.size() - 1)continue;
        if(v[i].second != n)flag = 0;
    }
    */

    int use[m+1] = {};
    int mex2 = 1;
    rep(i,v.size()){
        if(v[i].second == n){
            use[v[i].first] = 1;
            continue;
        }else{
            while(use[mex2] == 1)mex2++;
            if(v[i].first == mex2){
                use[mex2] = 1;
            }else{
                flag = 0;
                break;
            }
        }
    }

    if(flag)yn;
    return 0;
}




Measured memory_bytes: 10496
#include<stdio.h>

using namespace std;

int main(){
	char in[3];
	int sum = 0;
	scanf("%s",in);
	for (int i = 0; i < 3; ++i){
		sum += (in[i]-'a');
	}
	if(sum == 3)
		printf("Yes\n");
	else printf("No\n");	
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            var split = Console.ReadLine().Split(' ');
            int A = Int32.Parse(split[0]);
            int B =Int32.Parse(split[1]);
            int C = Int32.Parse(split[2]);
            string output = "No";
            if (A <= C)
                if (B >= C)
                    output = "Yes";

            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int op(int r, int w){
	return max(r, w);
}


int main()
{
	int k, s;
	cin >> k >> s;
	int ans = 0;
	rep(i, k+1)
	{
		rep(j, k+1) {
			int z = s - i - j;
			if(0 <= z && z <= k)
				ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3600
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		for(int i=0; i<k; i++){
			if(i%2==0){
				a /= 2;
				b += a;
			}
			else{
				b /= 2;
				a += b;
			}
		}
		System.out.println(a + " " + b);
	}
}

Measured memory_bytes: 23892
def resolve():
    N = int(input())
    arr = list(map(int, input().split()))
    f = True
    for num in arr:
        if not num % 2 and not (num % 3 == 0 or num % 5 == 0):
            print('DENIED')
            f = False
            break
    if f:
        print('APPROVED')


resolve()

Measured memory_bytes: 3060
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm> 
#include<climits>
#include<stack>
#include<queue>
#include<set>
#include<cctype>
#include<bitset> 
using namespace std;

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int mod = 1000000007;
const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
}


int main(){
    map<string,vector<int>> mp;
    map<string,int> mp2;
    set<string> se;

    int n;cin >> n;
    REP(i,n){
        pair<string,int> p;
        cin >> p.first >> p.second;
        mp[p.first].push_back(p.second);
        mp2[p.first+to_string(p.second)]=i+1;
        se.insert(p.first);
    }

    for(auto s:se){
        auto vec = mp[s];
        sort(all(vec),greater<>());
        for(auto v:vec)cout << mp2[s+to_string(v)] << endl;  
    }

	return 0;
}

Measured memory_bytes: 256
table = [input() for i in range(9)]
def isWall(x,y,dir):
	# 右
    if dir == 0:
        return x < 4 and table[y][x] == '1'
    # 下
    elif dir == 1:
        return y < 8 and table[y + 1][x] == '1'
	# 左
    elif dir == 2:
        return x > 0 and table[y][x - 1] == '1'
	# 上
    elif dir == 3:
        return y > 0 and table[y - 1][x] == '1'
    
ans = ""
x = y = dir = 0

while 1:
    # 正面の壁
    dir = (dir + 3) % 4
    while not isWall(x,y,dir):
        # 伝う壁
        dir = (dir + 1) % 4
    # 移動
    if dir == 0:
        x += 1
        ans += 'R'
    elif dir == 1:
        y += 2
        ans += 'D'
    elif dir == 2:
        x -= 1
        ans += 'L'
    elif dir == 3:
        y -= 2
        ans += 'U'
    if x == 0 and y == 0:
        break
print(ans)


Measured memory_bytes: 5572
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n;
  cin>>n;
  vector<int> a(n),b(n),c(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  for(int i=0;i<n;i++){
    cin>>c[i];
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  ll d=0;
  for(int i=0;i<n;i++){
    d+=(lower_bound(a.begin(),a.end(),b[i])-a.begin())*(c.end()-upper_bound(c.begin(),c.end(),b[i]));
  }
  cout<<d<<endl;
}

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

int main() {
	// your code goes here
	int n,a;
	cin>>n>>a;
	int sum=n/500;
	n=n%500;
	if(a==0&&n%500!=0)
	cout<<"No"<<endl;
	else
	{
	if(n<=a)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val p = readLine()!!.split(" ").map { it.toInt() }
    var ans = 0
    var index = 0
    while (index < N) {
        if (p[index] == index + 1) {
            ans += 1
            index += 2
        } else {
            index++
        }
    }
    println(ans)
}


Measured memory_bytes: 49856
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
//template<class T> void SO(T& ve){sort(T.begin(),T.end());}
int main(void){
	int x,t;cin>>x>>t;cout<<max(0,x-t)<<endl;
}


Measured memory_bytes: 888
#include <cstdio>
using namespace std;
int main() {
  int N;
  int ans = 0;
  scanf("%d", &N);
  int h[N];
  for (int i=0; i<N; i++) {
    scanf("%d", &h[i]);
  }
  for (int i=0; i<N; i++) {
    while (h[i] > 0) {
      ans++;
      for (int j=i; j<N; j++) {
        if (h[j] == 0) break;
        h[j]--;
      }
    }
  }
  printf("%d\n", ans);
}


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

using namespace std;

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

  int n;
  cin >> n;

  int64_t ans = 1, bef = 2;
  for (int i = 1; i < n; ++i) {
    int64_t tmp = ans;
    ans += bef;
    bef = tmp;
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
//#include<stack>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int P(string s)
{
  int i=0,n=s.size()-1;
  while(i<n)
  {
    if(s[i]!=s[n])
       return 0;
    i++;
    n--;
  }
  return 1;
}
int main()
{
  string str;
  cin>>str;
  int n=str.size();
  int t=((n-1)/2);
  int k=((n+3)/2)-1;
  if(P(str) && P(str.substr(0,t)) && P(str.substr(k,n-k)))
  cout<<"Yes";
  else
    cout<<"No";
    return 0;
  
}

Measured memory_bytes: 256
# Fast IO (only use in integer input)

import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def main():

    N = int(input())
    Resident = []
    for i in range(N):
        x,y,p = map(int,input().split())
        Resident.append((x,y,p))

    minCost = [float("inf")] * (N+1)

    preCalRange = 1 << N

    horizontalLineDistance = []
    verticalLineDistance = []

    for i in range(preCalRange):
        railRoad = bin(i)[2:]
        railRoad = '0' * (N - len(railRoad)) + railRoad
        horizontalLineDistance.append([])
        verticalLineDistance.append([])
        for j in range(N):
            horizontalLineDistance[i].append(min(abs(Resident[j][0]),abs(Resident[j][1])))
            verticalLineDistance[i].append(min(abs(Resident[j][0]),abs(Resident[j][1])))
            for k in range(N):
                if railRoad[k] == '1' and abs(Resident[j][0] - Resident[k][0]) < horizontalLineDistance[i][j]:
                    horizontalLineDistance[i][j] = abs(Resident[j][0] - Resident[k][0])
                if railRoad[k] == '1' and abs(Resident[j][1] - Resident[k][1]) < verticalLineDistance[i][j]:
                    verticalLineDistance[i][j] = abs(Resident[j][1] - Resident[k][1])

    loopCount = 1 << N
    for i in range(loopCount):
        numNewRailroad = bin(i)[2:].count('1')
        j = i
        while j >= 0:
            j &= i
            goodList1 = horizontalLineDistance[j]
            goodList2 = verticalLineDistance[i - j]
            cost = 0
            for k in range(N):
                cost += Resident[k][2] * min(goodList1[k], goodList2[k])
            if minCost[numNewRailroad] > cost:
                minCost[numNewRailroad] = cost
            j -= 1
    for elem in minCost:
        print(elem)

main()

Measured memory_bytes: 90764
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int road = A*1 + B*1 - 1; 

        System.out.println(A * B - road);
    }
}


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

namespace Questionnaire
{
	class Program
	{
		static int Main ( string[] args )
		{
			while (true)
			{
				//????????????
				string[] inputStr = Console.ReadLine ().Split (' ');

				int studentCount = int.Parse (inputStr[0]);
				int placeCount = int.Parse (inputStr[1]);

				//?¶??¶???????
				if (studentCount == 0 && placeCount == 0)
				{
					break;
				}

				int[] CountArray = new int[placeCount];

				for (int student = 0; student < studentCount; student++)
				{
					string[] content = Console.ReadLine ().Split (' ');

					for (int place = 0; place < content.Length; place++)
					{
						if ("1".Equals (content[place]))
						{
							CountArray[place]++;
						}
					}
				}

				List<Contents> list = new List<Contents> (placeCount);

				for (int lp = 0; lp < placeCount; lp++)
				{
					list.Add (new Contents (CountArray[lp], lp + 1));
				}

				//????????????
				list.Sort (( x, y ) => y.Count.CompareTo (x.Count));
				for (int lp = 0; lp < list.Count; lp++)
				{
					for (int lp2 = list.Count - 1; lp < lp2; lp2--)
					{
						if (list[lp].Count == list[lp2].Count)
						{
							if (list[lp].Index > list[lp2].Index)
							{
								var tmp = list[lp];
								list[lp] = list[lp2];
								list[lp2] = tmp;
							}
						}
					}
				}


				//????????????
				for (int lp = 0; lp < list.Count; lp++)
				{
					if (lp + 1 != list.Count)
					{
						Console.Write (list[lp].Index + " ");
					}
					else
					{
						Console.Write (list[lp].Index);
					}
				}
				Console.WriteLine ();
			}

			return 0;
		}
	}
}

class Contents
{
	public Contents ( int count, int index )
	{
		this.Count = count;
		this.Index = index;
	}

	public int Count { private set; get; }
	public int Index { private set; get; }
}

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

class Main{

	public static void main(String[] arg) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");

		double a = Double.parseDouble(str[0]);
		double b = Double.parseDouble(str[1]);
		double degree = Double.parseDouble(str[2]);

		double revrad = Math.PI * ( (180-degree)/180);

		double cx = b * Math.cos(revrad) + a;
		double cy = b * Math.sin(revrad);

		double sq = (a*cy) / 2;
		double len = Math.sqrt( (Math.pow(cx, 2) + Math.pow(cy, 2) )  ) + a + b;

		System.out.printf("%.5f %.5f %.5f\n",sq ,len ,cy);
	}
}

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

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  cout << (char)(a.front()-32) << (char)(b.front()-32) << (char)(c.front()-32) << endl;

  return 0;
}

Measured memory_bytes: 256
K=int(input())
L=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(L[K-1])

Measured memory_bytes: 3316
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;

const ll INF = 1LL << 32;

int main() {
  ll n, c;
  cin >> n >> c;
  const ll time = 101010LL;
  vvll arr(c, vll(time, 0));
  for (ll i = 0; i < n; i++) {
    ll s, t, ci;
    cin >> s >> t >> ci;
    s--;
    ci--;
    arr[ci][s]++;
    arr[ci][t]--;
  }


  for (ll i = 0; i < c; i++) {
    for (ll j = 1; j <= time; j++) {
      arr[i][j] += arr[i][j-1];
    }
  }

  for (ll i = 0; i < c; i++) {
    for (ll j = 0; j < time; j++) {
      if (arr[i][j] >= 1) arr[i][j] = 1;
    }
  }

  ll ans = 0;
  for (ll i = 0; i < time; i++) {
    ll cnt_i = 0;
    for (ll j = 0; j < c; j++) {
      cnt_i += arr[j][i];
    }  // j
    chmax(ans, cnt_i);
  }  // i

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 24832
#include <iostream>
using namespace std;
int main(){
  int n;
  int f=0;
  string s;
  cin >> n;
  cin >> s;
  if(n%2==1){
    cout << "No" << endl;
  }else{
    for(int i=0;i<n/2;i++){
      if(s[i]!=s[i+n/2]){
        f=1;
      }
    }
    if(f==0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef int int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {

  i64 N, M, i, j;
  cin >> N >> M;
  vvi E(N);
  REP(0, M, i) {
    i64 A, B;
    cin >> A >> B;
    E[A-1].pb(B-1);
  }

  vi ans;
  REP(0, N, i) {
    //cout << "begin " << i << endl;
    vi prev(N, -1);
    set<i64> q;
    q.insert(i);
    prev[i] = -2;
    while(!q.empty()) {
      i64 cur = *q.begin();
      //cout << "visit " << prev[cur] << " -> " <<  cur << endl;
      q.erase(q.begin());
      for(auto n: E[cur]) {
	if(prev[n] == -1) {
	  prev[n] = cur;
	  q.insert(n);
	}
	else if(prev[n] == -2) {
	  // backtrack
	  i64 k = cur;
	  vi candidate;
	  while(k != -2) {
	    candidate.pb(k);
	    //cout << "backtrack " << k << " -> " << prev[k] << std::endl;
	    k = prev[k];
	  }
	  
	  if(ans.size() == 0 || ans.size() > candidate.size()) {
	    ans = candidate;
	  }
	}
      }
    }
  }

  if(ans.size() == 0) {
    cout << "-1" << endl;
  }
  else {
    cout << sz(ans) << endl;
    REP(0, sz(ans), j) {
      cout << ans[j] + 1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
 
using namespace std;
 
typedef long long ll;
 
const int N = 200005;
 
 
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	
	s[k-1] = tolower(s[k-1]);
	
	cout<<s;
	
	return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define r_0 return 0
#define ld long double

using namespace std;

    const ll N = 1e3 + 7;
    const ll mod = 1e9 + 7;
    const ld eps = 1e-9;



void solve(){
    ll x;
    cin >> x;
    if(x >= 400 && x <= 599){
        cout << 8;
    }
    if(x >= 600 && x <= 799){
        cout << 7;
    }
    if(x >= 800 && x <= 999){
        cout << 6;
    }
    if(x >= 1000 && x <= 1199){
        cout << 5;
    }
    if(x >= 1200 && x <= 1399){
        cout << 4;
    }
    if(x >= 1400 && x <= 1599){
        cout << 3;
    }
    if(x >= 1600 && x <= 1799){
        cout << 2;
    }
    if(x >= 1800 && x <= 1999){
        cout << 1;
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tt = 1;
    //cin >> tt;
    while(tt --){
            solve();
    }
}

/**

**/


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef vector<vector<int> > V;
const int h = 4,w = 4;
int dx[]={0,0,-1,1},dy[]={1,-1,0,0};
V mp(h,vector<int>(w));
bool onmp(int x,int y){return x>=0&&y>=0&&x<w&&y<h;}

struct dat{int x,y,dir,cost;};
void drop(int x,int y){
  int D[4][4];
  memset(D,-1,sizeof(D));
  queue<dat> Q;
  mp[y][x] = 0;
  for(int i=0;i<4;i++)Q.push((dat){x+dx[i],y+dy[i],i,1});
  
  while(!Q.empty()){
    dat t = Q.front();Q.pop();
    x = t.x, y = t.y;
    int I = t.dir, cost = t.cost;
    if(!onmp(x,y))continue;  
    if(!mp[y][x]||(mp[y][x]>=5&&cost!=D[y][x]))Q.push((dat){x+dx[I],y+dy[I],I,cost+1});
    else if(++mp[y][x]==5){
      D[y][x] = cost;
      for(int i=0;i<4;i++)Q.push((dat){x+dx[i],y+dy[i],i,cost+1});
    }
  }
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)if(mp[i][j]>=5) mp[i][j]=0;
}

bool check(){
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)if(mp[i][j]) return 0;
  return 1;
}

map<V,int> mem;
int dfs(int cnt=0){
  if(check()) return 0;
  if(cnt>=5) return 1e9;
  if(mem.count(mp)) return mem[mp];
  
  int res=1e9;
  for(int y=0;y<h;y++)
    for(int x=0;x<w;x++){
      if(mp[y][x]==0)continue;
      V tmp = mp;
      if(++mp[y][x]==5)drop(x,y);
      res=min(res,1+dfs(cnt+1));
      mp = tmp;
    }
  return mem[mp] = res;
}

int main(){
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)cin>>mp[i][j];
  
  if(dfs()>5) cout<<-1<<endl;
  else cout<<dfs()<<endl;
  return 0;
}

Measured memory_bytes: 4648
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int result;
        if(k % 2 == 0){
            result = (k / 2) * (k / 2);
        } else {
            result = (k / 2) * (k / 2 + 1);
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 23636
const val P = 1000000007L

// Find (x, y, r) such that r = gcd(a,b) and ax + by = r.
fun extendedGCD(a: Long, b: Long): Triple<Long, Long, Long> {
  var x0 = 1L
  var y0 = 0L
  var z0 = a
  var x1 = 0L
  var y1 = 1L
  var z1 = b
  while (true) {
    if (z1 == 0L) return Triple(x0, y0, z0)
    val q = z0 / z1
    val x2 = x0 - q * x1
    val y2 = y0 - q * y1
    val z2 = z0 - q * z1
    x0 = x1
    x1 = x2
    y0 = y1
    y1 = y2
    z0 = z1
    z1 = z2
  }
}

fun inverseMod(a: Long, m: Long): Long {
  val (x, y, r) = extendedGCD(a, m)
  if (r != 1L) return 0  // No inverse.

  return (x + m) % m
}

class FiniteField(xRaw: Long) {
  private var x = if (xRaw >= 0) xRaw % P else (P - ((-xRaw) % P)) % P
  constructor(xi: Int): this(xi.toLong())
  operator fun plusAssign(o: Long) {
    x += o
    x %= P
  }
  operator fun plusAssign(o: FiniteField) {
    this += o.x
  }
  operator fun minusAssign(o: Long) {
    x += P - o
    x %= P
  }
  operator fun minusAssign(o: FiniteField) {
    this -= o.x
  }
  operator fun timesAssign(o: Long) {
    x *= o
    x %= P
  }
  operator fun timesAssign(o: FiniteField) {
    this *= o.x
  }
  operator fun divAssign(o: Long) {
    x *= inverseMod(o, P)
    x %= P
  }
  operator fun divAssign(o: FiniteField) {
    this /= o.x
  }
  override fun toString() = x.toString()
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val factorialTable = Array(n, { FiniteField(0L) })
  factorialTable[0] = FiniteField(1)
  for (k in 1..(n - 1)) {
    factorialTable[k] = FiniteField(1)
    factorialTable[k] *= factorialTable[k - 1]
    factorialTable[k] *= k.toLong()
  }

  val fTable = Array(n, { k ->
    if (2 * k < n) FiniteField(0)
    else {
      val f = FiniteField(1)
      f *= factorialTable[k]
      f *= factorialTable[k - 1]
      f /= factorialTable[2 * k - n]
      f
    }
  })

  var ans = FiniteField(0)
  for (k in 1..(n - 1)) {
    val count = FiniteField(0)
    count += fTable[k]
    count -= fTable[k - 1]
    count *= k.toLong()
    ans += count
  }
  println(ans)
}

Measured memory_bytes: 148120
d = list(map(int,(input().strip().split(' '))))
N = d[0]
T = d[1]
min = 100000000
for i in range(0, N):
    d = list(map(int,input().strip().split(' ')))
    c = d[0]
    t = d[1]
    if t <= T:
        if min >= c:
            min = c
if min == 100000000:
    print("TLE")
else:
    print(min)


Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<fstream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<set>
#include<string>
#include<queue>
#include<map>
#include<iomanip>
#include<cassert>
#include<complex>
#include<functional>
#include<list>
#include<cmath>
#include<stack>
#include<assert.h>
#define LL long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define F first
#define S second
using namespace std;
int h,n,a[1100],b[1100];
int dp[11000];
int main(){
  cin>>h>>n;
  for(int i=0;i<n;i++)
    cin>>a[i]>>b[i];
  memset(dp,1e9+7,sizeof(dp));
  dp[h]=0;
  for(int i=h;i>0;i--){
  	if(dp[i]==1e9+7)
  	  continue;
  	for(int j=0;j<n;j++){
  	  if(i-a[j]<=0){
  	    dp[0]=min(dp[0],dp[i]+b[j]);
  	    continue;
	  }
	  dp[i-a[j]]=min(dp[i-a[j]],dp[i]+b[j]); 
	}
  }
  cout<<dp[0];
  return 0;
}

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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod =998244353;
const ll INF = 1LL << 60;

//a^n mod を計算する
long long modpow(long long a, long long n, long long mod){
	long long res = 1;
	while(n > 0){
		if(n & 1) res = res * a % mod;
		a = a * a % mod ;
		n >>= 1;
	}
	return res;
}

//ここから書き始める

int main()
{
	cout << setprecision(10);
	ll n ;cin >>n ;
	map<ll,ll> tree;
	rep(i,n){
		ll a;cin >> a;//入力で距離を与える
		if(i==0){
			//距離は0じゃないといけない!!
			if(a!=0){
				cout << 0 << endl;//1個目の距離が0じゃない木は存在しない
				return 0 ;
			}else{
				tree[a] = 1;
			}
		}
		//i != 0 の ときは map にどんどんぶち込んでいく。
		else{
			if(tree.count(a)){
				tree[a]++;
			}else tree[a] = 1;
		}
	}
	//一回マップの中を見てみる
	ll ans = 1;
	rep(i,n){
		if(i==0){
			if(tree[i] != 1){//0は1個しかダメ。
				cout << 0 << endl;
				return 0;
			}
		}
		else if(tree[i] != 0){
			ans *= modpow(tree[i-1],tree[i],mod);
			ans %= mod;
		}
		else{
			For(j,i+1,n){
				if(tree[j]!=0){
					cout << 0 << endl;
					return 0 ;
				}
			}
			break;
		}
				
		
	}
	cout << ans << endl;
}


Measured memory_bytes: 6528
#include<stdio.h>
int main(){
    int x;
    scanf("%d",&x);
    int ans = 8;
    for(int i = 400; i < 2000; i += 200){
        if(i <= x && x < i + 200)
            printf("%d\n",ans);
        ans--;
    }
    return 0;
}

Measured memory_bytes: 1716
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
 
typedef long long ll;
typedef long double ld;
typedef pair<int, ll> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int MX = 200005;
map<ll, int> mp;
ll res = 0, acu = 0;
int n, a;

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    cin >> n;
    for (int i = 0; i < n; i++) {
    	mp[acu]++;
    	cin >> a;
    	acu += a;
    	if (mp.find(acu) != mp.end())
    		res += mp[acu];
    }

    cout << res << endl;

    return 0;
}


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

void Log(int A[], int n)
{
    for (int i = 0; i < n; ++i) {
        cout << A[i];
        if (i != n - 1) {
            cout << " ";
        }
    }
    cout << endl;
}

int SelectionSort(int A[], int n)
{
    int cnt = 0;
    for (int i = 0; i < n - 1; ++i) {
        int minA = A[i];
        int idx = i;
        for (int j = i + 1; j < n; ++j) {
            if (A[j] < minA) {
                minA = A[j];
                idx = j;                
            }
        }
        if (i != idx) {
            swap(A[i], A[idx]);
            ++cnt;
        }
    }
    return cnt;
}

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

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

    int cnt = SelectionSort(A, n);
    Log(A, n);
    cout << cnt << endl;

    return 0;
}


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

int main() {
	int s[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin >> k;
	cout << s[k-1] << endl;
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll int, null_type,less<ll int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
        ll i,j,k,l,m,n;
        cin>>n;
        vector<double> v(n);
        cin>>v;
        double dp[3000][3000];
        clr(dp,0);
        dp[0][0]=1-v[0];
        dp[0][1]=v[0];
        for(i=1;i<n;i++)
        {
            dp[i][0]=dp[i-1][0]*(1-v[i]);
            for(j=1;j<=i+1;j++)
            {
                dp[i][j]=dp[i-1][j]*(1-v[i]);
                dp[i][j]+=dp[i-1][j-1]*(v[i]);
                // cout<<dp[i][j]<<" ";
            }
            // cout<<endl;
        }
        double ans;

        for(i=(n+1)/2;i<=n;i++)
        {
            ans+=dp[n-1][i];
        }
        cout<<setprecision(10)<<ans;
    }
    return 0;
}

Measured memory_bytes: 70656
import Control.Applicative
import Prelude

solver ::Int->[Int]
solver k
    |k == 0 = [1,1]
    |k == 1 = [0,3]
    |50 >= k = replicate k k
    |otherwise = replicate (50-r) (m-r) ++ ( replicate r (m+51-r))
    where
        m = (k `div` 50) + 49
	r = k `mod` 50

soln k 
    |1 >= k = 2
    |50 >= k = k
    |otherwise = 50


main :: IO ()
main = do
    -- 整数の入力
    k <- readLn :: IO Int
    print $ soln k
    putStrLn $ unwords.(map show) $ solver k



Measured memory_bytes: 508
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int bitcount(int inp);
int bitcount(int inp){
    int res=0;
    while(inp!=0){
        res+=inp&1;
        inp=inp>>1;
    }
    return res;
}

int main()
{
    int n, m;
    cin >> n >> m;
    // int k[m];
    int k;
    int a[m];
    int p[m];
    int temp;
    int tempb=1;
    int all=1 << n;
    for (int i = 0; i < m; i++)
    {
        cin >> k;
        a[i]=0;
        // cout << k <<endl;
        for (int j = 0; j < k; j++)
        {
            cin >> temp;
            temp--;
            tempb=1 << temp;
            a[i]=a[i]^tempb;
        }
        // cout << bitcount(a[i]) << endl;
    }
    for (int i = 0; i < m; i++)
    {   
        cin >> p[i];
    }

    int res=0;
    for(int i=0;i<all;i++){
        temp=1;
        for(int j=0;j<m;j++){
            if(bitcount(a[j]&i)%2!=p[j]){
                temp=0;
                break;
            }
        }
        // cout << i << endl;
        if(temp==1){
            
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
#define MAX_RANK 60

ll hakidashi(vector<ll> a){
    int n = a.size();
    ll rank = 0;
    int j = 0;
	for (int i = MAX_RANK - 1; i >= 0; i--) {
		for (j = rank; j < n; j++) {
			if (a[j] & (1LL << i)) break;
		}
		if (j == n) {
			continue;
		}

		if (j > rank) a[rank] ^= a[j];
		for (j = rank + 1; j < n; j++) {
			a[j] = min(a[j], a[j] ^ a[rank]);
		}

		rank++;
	}
	ll x = 0;
	for (int i = 0; i < n; i++) {
		x = max(x, x ^ a[i]);
	}

    return x;
}

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

	ll allxor = 0;
	rep(i,n) allxor ^= a[i];
	rep(i,n) a[i] &= ~allxor;

	ll ans = (hakidashi(a) * 2) + allxor;
    cout << ans << endl;
	return 0;
}


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

int knap(int w[],int v[],int n,int tot)
{
    if(n==0||tot<=0) return 0;
    if(w[n-1]>tot)        return knap(w,v,n-1,tot);
    int c1 = knap(w,v,n-1,tot-w[n-1]) + v[n-1];
    int c2 = knap(w,v,n-1,tot);

    return max(c1,c2);
}

int knap2(int w[],int v[],int n,int Wt)
{
    int dp[n+1][Wt+1];

    for(int i=0 ; i<=n ; i++)
    {
        for( int j=0 ; j<=Wt ; j++)
        {
            if(i==0||j==0)
                dp[i][j]=0;
            else
                if(w[i-1]<=j)
                dp[i][j] = max(dp[i-1][j-w[i-1]] + v[i-1], dp[i-1][j]);
            else
                dp[i][j]=dp[i-1][j];    //if(w[i] > j then copy from above cell
        }
    }
    return dp[n][Wt];
}
using ll = long long ;
ll knap3(ll w[],ll v[],ll n,ll Wt)
{
    ll dp[n+1][Wt+1];

    for(int i=0 ; i<=n ; i++)
    {
        for( int j=0 ; j<=Wt ; j++)
        {
            if(i==0||j==0)
                dp[i][j]=0;
            else
                if(w[i-1]<=j)
                dp[i][j] = max(dp[i-1][j-w[i-1]] + v[i-1], dp[i-1][j]);
            else
                dp[i][j]=dp[i-1][j];    //if(w[i] > j then copy from above cell
        }
    }
    return dp[n][Wt];
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n,tot;
    cin>>n>>tot;

    ll w[n],v[n];

    for(int i=0 ; i<n ; i++)
        cin>>w[i]>>v[i];

    cout<<knap3(w,v,n,tot);

}




Measured memory_bytes: 79232
import java.util.*;
import java.io.*;

public class Main {
	
	List<Integer> prime;
	public List<Integer> initialize(){
		List<Integer> list = new ArrayList<Integer>();
		list.add(2); list.add(3);
		for(int i = 5; i < 102; i += 2){
			for(Integer x : list){
				if( x > Math.sqrt(i) ){
					list.add(i);
					break;
				}
				if( i%x == 0 ){
					break;
				}
			}
		}
		return list;
	}
	public  void solve() throws IOException{
		prime = new ArrayList<Integer>(initialize());
		int n;
		while( (n = nextInt() ) != 0 ){
			boolean flag = false;
			n = (n%2 == 0) ? n-1 : n;
		out:for(int i = n;; i -= 2){
				for(Integer x : prime){
					if( x > Math.sqrt(i) ){
						if( flag ){
							writer.println(i + " " + (i+2));
							break out;
						} else {
							flag = true;
							break;
						}
					}
					if( i%x == 0 ){
						flag = false;
						break;
					}
				}
			}
		}
		writer.flush();
	}
	public static void main (String args[]) throws IOException{
		new Main().run();
	}
	
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	
	public void run() throws IOException{
		try{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}
	public int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}		
	public String nextToken() throws IOException{
		while( tokenizer == null || !tokenizer.hasMoreTokens() ){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

Measured memory_bytes: 11000
#include<bits/stdc++.h>
#define pb push_back
#define pp pop_back()
#define mp make_pair
#define fr first
#define sc second
#define sz size()
#define smin(x,y) ((x)=min((x),(y)))
#define smax(x,y) ((x)=max((x),(y)))
#define all(x) x.begin(),x.end()
#define CS ios_base::sync_with_stdio(false);
#define show(x) cerr << #x << " is " << x <<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi; 
int32_t main()
{
	ll a,b; cin>>a>>b;
	if(a>0) return cout << "Positive\n" , 0;
	b = min(b,0ll);
	if(b==0) return cout <<"Zero"<<endl,0;
	a+=(int)(2e9);
	b+=(int)(2e9);
	a = b-a+1;
	if(a&1) cout << "Negative";
	else cout<<"Positive";
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256