akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3


def next_line():
    return input()


def next_int():
    return int(input())


def next_int_array_one_line():
    return list(map(int, input().split()))


def next_int_array_multi_lines(size):
    return [int(input()) for _ in range(size)]


def next_str_array(size):
    return [input() for _ in range(size)]


def main():
    r, c, k = map(int, input().split())
    dp = [[[0] * (c+1) for i in range(r+1)] for i in range(4)]
    v = [[0] * (c+1) for i in range(r+1)]
    for i in range(k):
        row, col, val = map(int, input().split())
        v[row][col] = val

    for row in range(1, r + 1):
        for col in range(1, c + 1):
            for num in range(0, 4):
                if num == 0:
                    dp[num][row][col] = dp[3][row-1][col]  # simple down
                else:
                    
                    dp[num][row][col] = max(dp[num-1][row][col],  # str
                                            dp[num][row][col-1],  # right x
                                            dp[3][row-1][col] + \
                                            v[row][col],  # down o
                                            dp[num-1][row][col-1] + \
                                            v[row][col],  # right o
                                            )
    print(dp[3][r][c])


if __name__ == '__main__':
    main()


Measured memory_bytes: 430020
#include<iostream>
#include<string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main(){
  string s;
  cin>>s;
  bool isgood=true;
  if(s[0] ==s[1])isgood=false;
  if(s[1] ==s[2])isgood=false;
  if(s[2] ==s[3])isgood=false;
  if(isgood) 
    cout<< "Good" <<endl;
  else
    cout<< "Bad" <<endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		BigInteger a = scn.nextBigInteger();
		BigInteger b = scn.nextBigInteger();
      	if(a.compareTo(b)>0){
          System.out.println("GREATER");
        }else if(a.compareTo(b)<0){
          System.out.println("LESS");
        }else{
          System.out.println("EQUAL");
        }
	}
}

Measured memory_bytes: 35956
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]

def bunkai(x):
    for i in reversed(range(1, int(x**0.5//1)+1)):
        #print(i)
        if x%i == 0:
            return list((i, x//i))
    return list((1, S))


S = ii()
lim = 10**9
'''
#print(bunkai(S))
a, b = bunkai(S)[0], bunkai(S)[1]
if a==b:
    print(0, 0, bunkai(S)[0], 0, 0, bunkai(S)[1])
    exit()
for i in range(1, 10**18-S):
    if bunkai(i)[0]<=lim and bunkai(i)[1]<=lim and bunkai(S+i)[0]<=lim and bunkai(S+i)[1]<=lim:
        print(0, 0, bunkai(i)[0], bunkai(S+1)[1], bunkai(S+1)[0], bunkai(i)[1])
        exit()
'''
s12 = S**0.5
a = int(s12)
keta = len(str(a))
b = 10**keta
if float(a)==s12:
    print(0, 0, a, 0, 0, a)
    exit()
for i in range(a+1, b+1):
    ii = i**2
    if bunkai(ii)[0]<=lim and bunkai(ii)[1]<=lim and bunkai(ii-S)[0]<=lim and bunkai(ii-S)[1]<=lim:
        print(0, 0, i, bunkai(ii-S)[1], bunkai(ii-S)[0], i)
        exit()

Measured memory_bytes: 3316
#include<cstdio>
#define mod 1000000007
#define maxn 200005
#define N 2000
int n,fact[N*4+5],inv[N*4+5],ans,cnt[N*2+5][N*2+5],dp[N*2+5][N*2+5],inv2;
void init()
{
	fact[0]=1;
	for(int i=1;i<=N*4;i++) fact[i]=1ll*fact[i-1]*i%mod;
	inv[1]=1;
	for(int i=2;i<=N*4;i++) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	inv[0]=1,inv2=inv[2];
	for(int i=1;i<=N*4;i++) inv[i]=1ll*inv[i-1]*inv[i]%mod;
}
int F(int a,int b) { return 1ll*fact[a+b]*inv[a]%mod*inv[b]%mod; }
int main()
{
	scanf("%d",&n);
	init();
	for(int i=1;i<=n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		cnt[N+a][N+b]++,dp[N-a][N-b]++;
		ans=(ans+mod-F(a*2,b*2))%mod;
	}
	for(int i=0;i<=N*2;i++)
		for(int j=0;j<=N*2;j++)
		{
			if(i) dp[i][j]+=dp[i-1][j];
			if(j) dp[i][j]+=dp[i][j-1];
			dp[i][j]%=mod;
			ans=(ans+1ll*dp[i][j]*cnt[i][j]%mod)%mod;
		}
	/*for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			ans=(ans+F(a[i]+a[j],b[i]+b[j]))%mod;*/
	printf("%lld\n",1ll*ans*inv2%mod);
}

Measured memory_bytes: 96768
from itertools import combinations

N = int(input())
L = list(map(int, input().split()))


def isRectangle(pair):
    if len(pair) < 3:
        return False
    if pair[0] == pair[1] or pair[1] == pair[2] or pair[2] == pair[0]:
        return False
    return (
        pair[0] + pair[1] > pair[2]
        and pair[1] + pair[2] > pair[0]
        and pair[0] + pair[2] > pair[1]
    )


c = list(combinations(L, 3))

count = 0
for i in range(len(c)):
    if isRectangle(c[i]):
        count += 1
print(count)

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

int main(){
  
  int N;
  cin >> N;
  
  long long sum = 0;
  int x = N/15;
  for( int i = 1; i <= x; i++) sum += 60+120*(i-1);
  
  for( int i = 15*x+1; i <= N; i++){
     if( i % 3 != 0 && i % 5 != 0 ) sum += i;
  }
  
  printf("%lld\n",sum);
  return 0;
}

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

const int SIZE_N = 100000; 
bool marked[SIZE_N];

class UnionFind {
public:
	vector<int> par;
	UnionFind(int n) :par(n) {
		for (int i=0; i<n; ++i) par[i] = i;
	}
	int root(int x) {
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}
	void unite(int x, int y) {
		x = root(x);
		y = root(y); 
		if (x == y) return;
		par[y] = x;
	}
	// bool same(int x, int y) {
	// 	return root(x) == root(y);
	// }
};

int main() {
	int N, Q;
	while (cin >> N >> Q, N) {
		vector<int> p(N);
		for (int i=1; i<N; ++i) {
			cin >> p[i];
			p[i] --;
		}
		fill(marked, marked+SIZE_N, false);
		marked[0] = true;
		vector<pair<char,int>> qu(Q);
		for (int i=0; i<Q; ++i) {
			cin >> qu[i].first >> qu[i].second;
			qu[i].second --;
			if (qu[i].first == 'M') {
				if (marked[qu[i].second]) {
					qu[i].first = '_';
					continue;
				}
				marked[qu[i].second] = true;
			}
		}
		UnionFind uf(N);
		for (int i=1; i<N; ++i) {
			if ( ! marked[i]) uf.unite(p[i], i);
		}
		long long ans = 0;
		for (int i=Q-1; i>=0; --i) {
			if (qu[i].first == 'Q') {
				ans += uf.root(qu[i].second) + 1;
			} else if (qu[i].first == 'M') {
				if (qu[i].second != 0) uf.unite(p[qu[i].second], qu[i].second);
			}
		}
		cout << ans << endl;
	}
}


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

int main(){
  int a,b;
  cin >> a >> b;
  if(a <= 8 && b <= 8) puts("Yay!");
  else puts(":(");
  return 0;
}


Measured memory_bytes: 256
program sequence_sum
  implicit none
  integer(8) :: n, x, m, num, a(0:100000) = 0
  integer :: b(0:100000) = 0, period, offset, rem, i, j
  read(*,*) n, x, m
  if (n == 1) then
    write(*,'(i0)') x
    stop
  end if
  a(1) = x
  b(int(x)) = 1
  do i = 2, int(m) + 1
    x = mod(x * x, m)
    a(i) = a(i - 1) + x
    if (i == n) then
      write(*,'(i0)') a(i)
      stop
    end if
    j = x
    if (b(j) > 0) then
      offset = b(j) - 1
      period = i - offset - 1
      exit
    end if
    b(j) = i
  end do
  num = (n - offset) / period
  rem = int(n - offset - num * period)
  write(*,'(i0)') (a(offset + period) - a(offset)) * num + a(offset + rem)
end program sequence_sum

Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <string>
#include <map>

void solve() {
    int n;
    std::cin >> n;

    std::map<std::string, int> cnt;
    while (n--) {
        std::string s;
        std::cin >> s;
        if (!cnt.count(s)) cnt[s] = 0;
        ++cnt[s];
    }

    int max = -1;
    std::vector<std::string> ans;
    for (auto p : cnt) {
        if (p.second < max) continue;
        if (p.second > max) {
            max = p.second;
            ans.clear();
        }
        ans.push_back(p.first);
    }

    for (auto s : ans) std::cout << s << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define contains(c, i) ((c).find(i) != (c).end())
#define present(i, c) (find(all(c), i) != (c).end())

#define trav(x, c) for(auto &x : c)
#define rep(i, n) for(int i = 0; i < n; i++)
#define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e)))

#define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); }
void cerr_(istream_iterator<string> it) { (void) it; }
template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); }

template<class T, class S>  ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; }
template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }

//=========================

int h, w, k;
vs m;

int check() {
    int n = 0;
    rep(i, h) rep(j, w) if(m[i][j] == '#') n++;
    return n;
}

void run_test() {
	cin >> h >> w >> k;
    m.clear();
    rep(i, h) {
        string s; cin >> s;
        m.pb(s);
    }
    vs t = m;
    int ans = 0;
    rep(r, (1 << h)) rep(c, (1 << w)) {
        m = t;
        rep(i, h) rep(j, w) if((r & (1 << i)) || (c & (1 << j))) m[i][j] = 'R';
        if(check() == k) ans++;
    }
    cout << ans << endl;
}

//=========================

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); }
	// int t_; cin >> t_; while(t_--) run_test();
	run_test();
	return 0;	
}


Measured memory_bytes: 3656
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int x;
    cin >> x;
    
    int sum = 0;
    int i = 0;
    while( sum <= x ) {
        ++i;
        sum += 100;
        if( sum > x ) break;
        int tmp = i * 5 + sum;
        if( x - tmp <= 0 ) {
            cout << 1 << endl;
            return 0;

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
using namespace std;
vector<int> G[N];
int n,k,f[N],g[N],ans;
void dfs(int t)
{
	int i;
	for(i=0;i<G[t].size();i++){
		dfs(G[t][i]);
		if(g[G[t][i]]==k-1&&t>1) ans++;
		else g[t]=max(g[t],g[G[t][i]]+1);
	  }
}
int main()
{
	int i;
	scanf("%d %d",&n,&k);
	for(i=1;i<=n;i++)
		scanf("%d",&f[i]);
	if(f[1]!=1) f[1]=ans=1;
	for(i=2;i<=n;i++)
		G[f[i]].push_back(i);
	dfs(1);
	cout<<ans;
	return 0;
}


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

#define INF 1e9
using namespace std;

#define REPR(i, n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

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

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

typedef long long ll;
typedef long double ld;
bool is_integer( ld x ){
    return floor(x)==x;
}
int main() {
    ll N;
    cin >> N;
    ll score = N + 1;
    FOR(i,1, ll(sqrt(N)) + 1) {
        if ( N%i == 0) chmin(score,abs((N/i)+i));

    }

    ////////////////////
    // Write your code.
    ////////////////////

    cout << score-2 << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] bounds = new int[n];
		int count = 1;
		for(int i = 0; i < n; i++){
			bounds[i] = sc.nextInt();
			if(i > 0){
				bounds[i] += bounds[i - 1];
			}
			if(bounds[i] <= x){
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 23124
#pragma comment(linker, "/STACK:1024000000,1024000000")
//#include<bits/stdc++.h>
#include <algorithm>  
#include <iostream>  
#include <cstdlib>  
#include <cstring>  
#include <string>
#include <cstdio>  
#include <climits>
#include <cmath> 
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <sstream>
#define inf 0x3f3f3f3f
#define ll long long
#define fora(i,a,n) for(int i=a;i<=n;i++)
#define fors(i,n,a) for(int i=n;i>=a;i--)
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define sci2(x,y) scanf("%d%d",&x,&y)
#define scl2(x,y) scanf("%lld%lld",&x,&y)
const int maxn = 100024;
const int mod = 1e9 + 7;
const double eps = 1e-8;
using namespace std;
typedef pair<int, int> pr;
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
	//freopen("out.txt","w",stdout);
#endif
	int n, m;
	cin >> n >> m;
	cout << n - m + 1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct node{
	int num,g;
}a[10];

int f(int x){
	return x%10;
}

bool cmp(node x,node y){
	if(x.g!=0&&y.g!=0)
		return x.g<y.g;
	return x.g>0;
}

int main()
{
	for(int i=1;i<=5;i++){
		scanf("%d",&a[i].num);
		a[i].g=f(a[i].num);
	}
	sort(a+1,a+6,cmp);
//	for(int i=1;i<=5;i++)
//		cout<<a[i].num<<endl;
	for(int i=2;i<=5;i++){
		if(a[i].g!=0){
			a[i].num+=10-a[i].g;
		}
	}
	int ans=0;
	for(int i=1;i<=5;i++)
		ans+=a[i].num;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
// 2020-08-24 20:49:48
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

vector<int> G[10];
int n, m, ans, cur;
void bfs(int u) {
  if((cur >> u) & 1) return;
  cur |= (1 << u);
  if(__builtin_popcount(cur) == n) ans++;
  for(int v : G[u]) bfs(v);
  cur &= ~(1 << u);
}
void answer() {
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  ans = 0, cur = 0;
  bfs(0);
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3600
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			int n = sc.nextInt();
			ArrayList<Long> a = new ArrayList<>(n);
			for (int i = 0; i < n; i++) {
				a.add(sc.nextLong());
			}

			Collections.sort(a);
			Collections.reverse(a);

			long sum =0;
			for (int i = 1; i < a.size(); i++) {
				sum += a.get(i/2);
			}
			System.out.println(sum);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}

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

int main() {
  int K,N;
  cin >> K >>N;
  int A[N],dif,max;
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  max = (K - A[N-1]) + A[0];
  for(int i = 1; i < N; i++){
    if(A[i]-A[i-1] > max){
      max = A[i] - A[i-1];
    }
  }
  cout << K - max << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n=s.size();
    vector<int> left(n+1);
    vector<int> right(n+1);
    int prev=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='<')
        {
            left[i+1]=prev+1;
            prev++;
        }
        else
        {
            left[i+1]=0;
            prev=0;
        }
    }
    prev=0;
    for(int i=n-1;i>=0;i--)
    {
        if(s[i]=='>')
        {
            right[i]=prev+1;
            prev++;
        }
        else
        {
            right[i]=0;
            prev=0;
        }
    }
    long long ans=0;
    for(int i=0;i<=n;i++)
    {
        ans+=max(left[i],right[i]);
    }
    cout<<ans;
    return 0;
}




Measured memory_bytes: 7720
#include <bits/stdc++.h>
#define OP_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fo(i,a,b) for(int i = a; i < b; i++)
#define foi(i,a,b) for(int i = a; i>=b; i--)
#define fi first
#define si second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

const ll INF = 1e18L + 5;
const int MAXN = 1005;
const ll modn = 1e9+7;

double solve(vd &p){
  int n = p.size();
  double dp[n+1][n+1];
  double ans = 0.0;
  fo(i,0,n+1){
    fo(j,0,n+1){
      dp[i][j] = 0.0;
    }
  }
  dp[0][0] = 1.0;
  fo(i,1,n+1){
    fo(j,0,i+1){
      if(j > 0){
	dp[i][j] += dp[i-1][j-1]*p[i-1];
      }
      dp[i][j] += dp[i-1][j]*(1.0-p[i-1]);
    }
  }
  fo(i,0,n+1){
    if(i > n-i){
      ans += dp[n][i];
    }
  }
  return ans;
}

int main(){
  OP_IO;
  vd hprob;
  int n;
  cin>>n;
  hprob.resize(n,0.0);
  fo(i,0,n){
    cin>>hprob[i];
  }
  cout<<setprecision(12)<< solve(hprob)<<endl;
  return 0;
}


Measured memory_bytes: 70656
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main(){
    int n;
    cin >> n;
    set <ll> s;
    for (int i = 0; i < n; i++) {
        ll temp;
        cin >> temp;
        s.insert(temp);
    }
    if ((int)s.size() == n) puts("YES");
    else puts("NO");
    return 0;
}




Measured memory_bytes: 9600
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(void)
{
  int n, k;
  cin >> n >> k;
  n -= k;
  if(k==1) n = 0;
  cout << n << endl;
  return 0;
}


Measured memory_bytes: 256
program main
    implicit none
    character(10) a,b,c
    integer k
    read(*,*) a,b
    k=len_trim(a)
    c=b(1:k)
    c=trim(c)
    if(c==a) then
        write(*,*) 'Yes'
    else
        write(*,*) 'No'
    end if
end program main
 



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

int main(){
  int N,A,B;
  cin >> N;
  A=N/4,B=N/7;
  bool a=false;
  for(int i=0;i<A+1;i++){
    for(int j=0;j<A+1;j++){
      if(4*i+7*j==N){
        a=true;
        break;
      }
    }
  }
  if(a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
last = -1
sum = 0
for ai in a:
    sum += b[ai-1]
    if ai - last == 1:
        sum += c[ai-2]
    last = ai
print(sum)

Measured memory_bytes: 3064
import java.util.Scanner;

class Main{
    public static void main(String[]args){
        Scanner cin=new Scanner(System.in);
        long num1 = cin.nextInt();
        long num2 = cin.nextInt();
        long count = (num1 == 1 && num2 == 1) ? 1
        	 	   : (num1 == 1 || num2 == 1) ? num1 * num2 - 2
        	 	   : (num1 - 2) * (num2 - 2);

        System.out.println(count);
    }
}

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

vector<string>vst;
int n,m,k,ans=0,dp1[8][75],dp2[8][75][75];

int on(int x,int ps)
{
    return x | (1<<ps);
}

bool ck(int x,int ps)
{
    return (bool)(x & (1<<ps));
}


long long solve2(int col,int mask1,int mask2)
{


    if(col==m)
    {

        int ttl=0;

        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(ck(mask1,i)==false && ck(mask2,j)==false)
                {
                    if(vst[i][j]=='#')ttl++;  if(ttl>k)break;
                }
            }

            if(ttl>k)break;
        }

        if(ttl==k)return 1;
        else{  return 0; }

    }
    else if(dp2[col][mask1][mask2]!=-1)return dp2[col][mask1][mask2];
    else
    {

        int a,b,c,d; a=on(mask2,col);

        b=solve2(col+1,mask1,a);
        c=solve2(col+1,mask1,mask2);

        dp2[col][mask1][mask2]=b+c;  return dp2[col][mask1][mask2];

    }


}


long long solve1(int row,int mask1)
{

    if(row==n)
    {
        int z=solve2(0,mask1,0);
        return z;

    }
    else if(dp1[row][mask1]!=-1)return dp1[row][mask1];
    else
    {

        int p,q,r,s,t,u;

        p=on(mask1,row);

        q=solve1(row+1,p);
        r=solve1(row+1,mask1);

        dp1[row][mask1]=q+r;  return dp1[row][mask1];


    }


}


int main()
{


    int i,j,a,b,c=0,ans;
    string str;

    scanf("%d %d %d",&n,&m,&k);
    for(i=1;i<=n;i++)
    {
        cin>>str;  vst.push_back(str);

    }


    memset(dp1,-1,sizeof dp1);
    memset(dp2,-1,sizeof dp2);


    ans=solve1(0,0);

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



    return 0;
}





Measured memory_bytes: 3964
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {

	string	s;
	int K;

	cin >> s;
	cin >> K;

	vector<string> vec;
	int mb = min(K, (int)s.size());

	for (int i = 0; i < (int)s.size(); i++) {
		for (int j = 1; j <= mb; j++) {
			string key = s.substr(i, j);
			vec.push_back(key);
		}
	}
	
	sort(vec.begin(), vec.end());
	unique(vec.begin(), vec.end());

	cout << vec[K - 1] << endl;
	return 0;
}



Measured memory_bytes: 1660
import sys
import bisect
input = sys.stdin.readline

a,b,q = map(int,input().split())

s = [-1 for i in range(a)]
t = [-1 for i in range(b)]

for i in range(a):
	S = int(input())
	s[i] = S
    
for i in range(b):
	T = int(input())
	t[i] = T
    
s.sort()
t.sort()
for i in range(q):
	x = int(input())

	slidx = bisect.bisect_left(s, x) -1
	tlidx = bisect.bisect_left(t, x) -1
	sl = -20000000000
	tl = -20000000000
	sr = 20000000000
	tr = 20000000000
	if slidx >= 0:
		sl = s[slidx]
	if tlidx >= 0:
		tl = t[tlidx]

	if slidx < a-1:
		sr = s[slidx+1]
	if tlidx < b-1:
		tr = t[tlidx+1]
	sl = x - sl
	tl = x - tl
	sr = sr - x
	tr = tr - x
	#print([sl,tl,sr,tr])
	dist = min( [max(sl,tl), max(sr,tr), min(sr, sl)*2 + min(tr,tl), min(tr,tl)*2 + min(sr,sl)])
	print(dist)

Measured memory_bytes: 13712
import functools, operator


def read():
    N, A, B = list(map(int, input().strip().split()))
    return N, A, B


table = []

def solve(N, A, B, MOD=10**9+7):
    n = (pow(2, N, MOD) + MOD - 1) % MOD
    a = nCk(N, A, MOD)
    b = nCk(N, B, MOD)
    return (n + MOD + MOD - a - b) % MOD


def factorial(n, MOD=10**9+7):
    return functools.reduce(lambda x, y: (x*y) % MOD, range(1, n+1))



def modinv(n, p):
    """
    逆元のmod pを求める
    """
    if n >= p:
        raise ValueError('p must be larger than n')
    return pow(n, p-2, p)


def nCk(n, k, MOD=10**9+7):
    r = 1
    kmin = min(k, n-k)
    for i in range(1, kmin+1):
        r = (r * modinv(i, MOD)) % MOD
    for i in range(n-kmin+1, n+1):
        r = r * i % MOD
    return r

if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))


Measured memory_bytes: 3572
#include <iostream>
#include <limits.h>
#include <vector>
using namespace std;

const int WEIGHT_MAX = 5000;

int u_weight[] = { 200, 300, 500, 1000, 1200, 1500 };
int u_price[] = { 380, 550, 850, 1520, 1870, 2244 };

int main()
{
	vector< int > dp( WEIGHT_MAX + 1, INT_MAX );
	dp[ 0 ] = 0;

	for( int i = 0; i < 6; ++i ){
		for( int j = 0; j + u_weight[ i ] <= WEIGHT_MAX; ++j ){
			dp[ j + u_weight[ i ] ] = min( dp[ j + u_weight[ i ] ], ( dp[ j ] + u_price[ i ] < 0 ? INT_MAX : dp[ j ] + u_price[ i ] ) );
		}
	}

	int weight;

	while( cin >> weight && weight ){
		cout << dp[ weight ] << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#define LL long long
#define PP std::pair<int,int>
int A, B;
char ans[110][110];
int D[3] = { 1,0,-1 };
int main() {
	std::cin >> A >> B;
	if (A == 1) {
		ans[100][100] = '#';
	}
	for (int i = 2; i <= 100; i += 3) {
		for (int j = 2; j <= 100; j += 3) {
			for(int k=0;k<3;k++)
				for (int l = 0; l < 3; l++) {
					if (A > 1) {
						ans[i + D[k]][j + D[l]] = '#';
					}
					else if (B > 1) {
						ans[i + D[k]][j + D[l]] = '.';
					}
				}
			if (A > 1) {
				ans[i][j] = '.';
				A--;
			}
			else if (B > 1) {
				ans[i][j] = '#';
				B--;
			}
		}
	}
	std::cout << 100 << " " << 100 << std::endl;
	for (int i = 1; i <= 100; i++) {
		for (int j = 1; j <= 100; j++) {
			std::cout << (ans[i][j] ? ans[i][j] : '.');
		}
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <functional>

using std::endl;

#define ll long long int
#define FOR(a, s, n) for(int a = s; a < n; ++a)
#define LEP(a, n) for(int a = 0; a < n; ++a)
#define INF 1145141919810
#define MOD 1000000007
#define OUT std::cout
#define IN std::cin
#define itn int
#define fro for
#define sdt std
#define asn ans

struct edge
{
	ll min;
	ll max;
};

int Data[223456], tmp[223456];
int N, K, buf;

int main()
{
	IN >> N >> K;

	LEP(a, N)
	{
		IN >> buf;

		Data[buf - 1]++;

	}

	std::sort(Data, Data + N);
	std::reverse_copy(Data, Data + N, tmp);

	buf = 0;

	LEP(a, K)
	{
		buf += tmp[a];
	}

	OUT << N - buf << endl;

	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		int n = sc1.nextInt();
		int ans = 0;

		for (int i = 0 ; i < n ; i++ ) {
			int a = sc1.nextInt();

			while (true) {
				if ( a % 2 == 0) {
					a = a/2;
					ans++;
				}
				else {
					break;
				}
			}
		}

		System.out.println(ans);

		sc1.close();
	}

}

Measured memory_bytes: 35616
import math

a, b, Cd = map(int, input().split())
Cr = math.radians(Cd)

S = a * b * math.sin(Cr) * 0.5

c2 = a ** 2 + b ** 2 - 2 * a * b * math.cos(Cr)

c = math.sqrt(c2)

L = a + b + c

h = 2 * S / a

print(S)
print(L)
print(h)

Measured memory_bytes: 7864
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
ll Max = 10 + 1e12;
int N = 5 + 1e5;


int main()
{
	int l, r; cin >> l >> r;
	ll ans = Max;
	if (r / 2019 - l / 2019 > 0) {
		cout << 0;
	}
	else {
		for (ll i = l;i <= r;i++) {
			for (ll j = l;j <= r;j++) {
				if (i == j) continue;
				ans = min(ans, (i * j) % 2019);
			}
		}
		cout << ans;
	}
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
string s;
int K;
ll dp[110][2][5];//dp[i][j][k] 上i桁　flag k:0でない数字の数


int main(){cout<<fixed<<setprecision(20);
           //桁dp
           cin>>s>>K;
           int n=s.size();
           dp[0][0][0]=1;
           rep(i,1,n+1){
             rep(k,0,4){
               int h=s[i-1]-'0';
                rep(l,0,10){
                  //0>0
                  if(l==h&&h==0)dp[i][0][k]+=dp[i-1][0][k];
                  else if(l==h&&h!=0&&k-1>=0)dp[i][0][k]+=dp[i-1][0][k-1];
                  //0>1
                  if(l<h){
                    if(l==0)dp[i][1][k]+=dp[i-1][0][k];
                    else{
                     if(k-1>=0)dp[i][1][k]+=dp[i-1][0][k-1]; 
                    }
                  }
                  //1>1
                  if(l==0){
                    dp[i][1][k]+=dp[i-1][1][k];
                  }
                  else{
                   if(k-1>=0) dp[i][1][k]+=dp[i-1][1][k-1];
                  }
                }
             }
           }
           cout<<dp[n][0][K]+dp[n][1][K]<<endl;
}

Measured memory_bytes: 3632
import scala.io.StdIn

object Main extends App {
  val aryN_T  = StdIn.readLine().split(" ").map(_.toInt)
  val n = aryN_T(0)
  val t = aryN_T(1)

  val aryTi:Array[Int]  = StdIn.readLine().split(" ").map(_.toInt)

  println(total(0, 1, t, n))

  def total(cur:Int, idx: Int, time: Int ,limit: Int): Int = {
    if(idx == limit) cur + time
    else
    {
      val tmp = aryTi(idx) - aryTi(idx - 1)
      if(time > tmp) total(cur + tmp, idx + 1, time,limit)
      else total(cur + time, idx + 1, time,limit)
    }

  }
}

Measured memory_bytes: 52592
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n;
  cin>>n;
  vector<Int> as(n),bs(n);
  for(Int i=0;i<n;i++) cin>>as[i]>>bs[i];

  vector<Int> cs(n),ds(n);
  for(Int i=0;i<n;i++){
    cs[i]=as[i];
    ds[i]=bs[i];
  }
  sort(cs.begin(),cs.end());
  sort(ds.begin(),ds.end());

  if(n&1){
    cout<<ds[n/2]-cs[n/2]+1<<newl;
    return 0;
  }

  Int m=n/2;
  Int x=cs[m-1]+cs[m+0];
  Int y=ds[m-1]+ds[m+0];
  cout<<y-x+1<<newl;
  return 0;
}


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

int main(){
  int x; cin >> x;
  cout << (x == 0 ? 1 : 0) << endl;
  return 0;
}


Measured memory_bytes: 3584
var
 n,i,x,y,z:longint;
begin
 readln(n);
 for i:=1 to n do
  begin
   readln(z,x,y);
   if x+y>z then
    begin
     writeln('No');
     halt;
    end
    else
   if ((x+y) mod 2=0) and (odd(z)) then
    begin
     writeln('No');
     halt;
    end
    else
   if ((x+y) mod 2=1) and (z mod 2=0) then
    begin
     writeln('No');
     halt;
    end;
  end;
 writeln('Yes');
end.

Measured memory_bytes: 128
def main():
    N = int(input())
    S = input()

    le = 0
    ri = N - 1
    cnt = 0
    while le < ri:
        if S[le] == 'R':
            le += 1
            continue

        if S[ri] == 'W':
            ri -= 1
            continue

        cnt += 1
        le += 1
        ri -= 1

    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9476
#include<iostream>
#include<cstring>

using namespace std;

int main()
{
	char S[110];
	cin >> S;

	int l = strlen(S);

	int count = 0;
	for(int i = 0; i < l/2; i++ )
	{
		if (S[i] != S[l-i-1])
			count++;
	}
	cout << count << "\n";
	return 0;
}

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


int main() {
	int N, M;
	cin >> N >> M;
	vector<int> food(M, 0);
	for(int i = 0; i < N; i++){
		int k;
		cin >> k;
		for(int j = 0; j < k; j++){
			int a;
			cin >> a;
			food.at(a - 1)++;
		}
	}
	int ans = 0;
	for(int i = 0; i < M; i++){
		if(food.at(i) == N){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

bool f[1300001] = {};
long long int len[1300001] = {};

int main() {

  long long int k = 0;

  for ( long long int i = 2; i < 1300000; i++ ) {

    if ( f[i] == false ) {

      len[k] = i - k;
      for ( long long int j = 2; j * i < 1300000; j++ ) {
	f[j*i] = true;
      }
      k = i;

    }else {

      len[i] = k;

    }

  }

  while( true ) {

    long long int n;
    cin >> n;
    if ( n == 0 ) break;

    if ( f[n] == false ) {
      cout << 0 << endl;
    }else {
      cout << len[len[n]] << endl;
    }

  }

  return 0;

}

Measured memory_bytes: 12584
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class I,class V=typename I::value_type>V sum_up(const I&l,const I&r){V v;for(I i=l;i!=r;i++)v=i==l?*i:v+*i;return v;}
template<class I,class T=iterator_traits<I>>I operator+(I it,int n){for(int i=0;i<n;i++)it++;return it;}
template<class I,class T=iterator_traits<I>>I operator-(I it,int n){for(int i=0;i<n;i++)it--;return it;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    X--, Y--;
    vector<int> ans(N, 0);
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            int L = j - i;
            L = min(L, abs(i - X) + 1 + abs(Y - j));
            L = min(L, abs(i - Y) + 1 + abs(X - j));
            ans[L]++;
        }
    }
    for(int i = 1; i < N; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}



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

int main(){
    int n; cin >> n;
    int n_copy = n;
    cout << n << ":";
    for (int i = 2; i*i < n_copy; i++)
    {
        while (n % i == 0)
        {
            cout << " " << i;
            n /= i;
        }
    }
    if (n != 1)
    {
        cout << " " << n;
    }
    
    cout << endl;
}


Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
		int i = sc.nextInt();
        int o = i % 10;
        switch (o) {
            case 2:
            case 4:
            case 5:
            case 7:
            case 9:
                System.out.println("hon");
                break;
            case 0:
            case 1:
            case 6:
            case 8:
                System.out.println("pon");
                break;
            case 3:
                System.out.println("bon");
                break;
        }
    }
}



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

int main(){

  int A, B, count = 0, n1,n2,n3;
  cin >> A >> B;
  
  for (int i = A; i <= B; i++){

    n1 = i/1000;
    n2 = i%100 /10;
    n3 = i%10;
    if (n1 == n3*10 + n2)
      count++;
    A++;
  
  }
  cout << count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    ll N = 100000;
    vector<bool> isPrime(N+1, true);
    isPrime[0] = isPrime[1] = false;
    for(ll i=2; i*i<=N; i++){
        if(!isPrime[i]) continue;
        for(ll j=2*i; j<=N; j+=i)
            isPrime[j] = false;
    }
    vector<ll> primeSum(N+1, 0);
    for(ll i=2; i<=N; i++){
        primeSum[i] = primeSum[i-1] + (isPrime[i] & isPrime[(i+1)/2]);
    }
    int q;  cin >> q;
    REP(i, q){
        ll l, r;    cin >> l >> r;
        cout << primeSum[r] - primeSum[l-1] << endl;;
    }
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = sc.nextLong();

        long sum = a + b + x;

        if(sum<22){
            System.out.println("win");
        }else{
            System.out.println("bust");

        }


    }
}


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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    vector<vector<int> > a(N, vector<int>(3));
    rep(i,N) 
    {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }

    vector<vector<ll> >dp(N, vector<ll>(3,0));
    rep(i,3) dp[0][i] = a[0][i];

    REP(i, 1, N)
    {
        rep(j, 3)
        {
            rep(k, 3)
            {
                if( j==k )continue;
                else chmax(dp[i][j], dp[i-1][k] + a[i][j]);
            }
        }
    }
    /*
    cout << endl;
    rep(i, N)
    {
        rep(j, 3) cout << dp[i][j] << " ";
        cout << endl;
    }
    */
    cout << max(dp[N-1][0], max( dp[N-1][1], dp[N-1][2] ) ) << endl;
}


Measured memory_bytes: 11136
s = []
for i in range(3):
    array = list(map(int,input().split()))
    s.append(array)
N = int(input())
t = [int(input()) for i in range(N)]
 
for i in range(N):
    for j in range(3):
        for l in range(3):
            if t[i] == s[j][l]:
                s[j][l] = 0
 
if sum(s[0]) == 0 or sum(s[1]) == 0 or sum(s[2]) == 0 or s[0][0]+s[1][0]+s[2][0] == 0 or s[0][1]+s[1][1]+s[2][1] == 0 or s[0][2]+s[1][2]+s[2][2] == 0 or s[0][0]+s[1][1]+s[2][2] == 0 or s[2][0]+s[1][1]+s[0][2] == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
N, M = map(int, input().split())
KA = [list(map(int,input().split())) for _ in range(N)]

lst = [0]*M

for i in range(N):
    for j in range(KA[i][0]):
        lst[KA[i][j+1]-1] += 1

ans = lst.count(N)
print(ans)


Measured memory_bytes: 8996
#include<bits/stdc++.h>
#define ll long long int
#define ss second
#define ff first
#define Mem(x,val) memset(x,val,sizeof x)
#define pb push_back
#define all(v) v.begin(),v.end()
#define unik(v)  v.erase(unique(v.begin(),v.end()),v.end())
#define cerr(x) cerr << __LINE__ << " th Line : " << #x << " = " << x << "\n"
#define debug(a,b) cerr << #a<<" = "<<a<<"   |   "<<#b<<" = "<<b<<'\n'
#define endl '\n'
#define SZ(a) ((int)a.size())
using namespace std;
typedef pair<int, int> pi32;
typedef pair<ll, ll> pi64;
typedef vector<int> vi32;
typedef vector<ll> vi64;
typedef vector<pi32> vp32;
typedef vector<pi64> vp64;
const ll mod = 1e9 + 7;
const int MX = 1e3+7;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	string s;cin>>s;
	cout<<s.substr(0,3)<<endl;
	
	return 0;
}


Measured memory_bytes: 3612
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n,nq;
int cnt[MAXN];

void run() {
	scanf("%d%d",&n,&nq);
	REP(i,n) cnt[i]=0;
	REP(i,nq) { int a,b; scanf("%d%d",&a,&b); --a,--b; ++cnt[a],++cnt[b]; }
	REP(i,n) if(cnt[i]%2==1) { printf("NO\n"); return; }
	printf("YES\n");
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
   int n;
   cin >> n;
   if(n == 1 ||
      n == 2 ||
      n == 3 ||
      n == 5 ||
      n == 6 ||
      n == 9 ||
      n == 10 ||
      n == 13 ||
      n == 17){
          cout << "No" << endl;
      }
      else{
          cout << "Yes" << endl;
      }
}


Measured memory_bytes: 256
#include <stdio.h>

void bubble_sort(int *data, int n);

int main(void)
{
	int mountain[10];
	int i;
	
	for (i = 0; i < 10; i++) scanf("%d", &mountain[i]);
	
	bubble_sort(mountain, 10);
	
	for (i = 0; i < 3; i++) printf("%d\n", mountain[i]);
	
	return (0);
}

void bubble_sort(int *data, int n)
{
	int i, j;
	for (i = 0; i < n - 1; i++){
		for (j = 0; j < n - i - 1; j++){
			if (data[j] < data[j + 1]){
				data[j] += data[j + 1];
				data[j + 1] = data[j] - data[j + 1];
				data[j] = data[j] - data[j + 1];
			}
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main()
{ string s1;
 string s2;
 int count=0;
 cin>>s1;
 cin>>s2;
 for(int i=0;i<3;i++)
 {  
   if(s1[i]==s2[i])
      count++;
 }
      cout<<count;
      return 0;
}

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

int main()
{
    int n;
    
    cin >> n;
    
    for (int i = 1; i <= n; ++i)
    {
        int x = i;
        
        if (x % 3 == 0)
        {
            cout << " " << i;
        }
        else
        {
            do 
            {
                if (x % 10 == 3)
                {
                    cout << " " << i;
                    break;
                }
                else
                {
                    x /= 10;
                }
            } while (x);
        }
    }
    
    cout << endl;
    return 0;
}


Measured memory_bytes: 3076
<?php
// Your code here!
$n = trim(fgets(STDIN));
$str = trim(fgets(STDIN));
$abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
for($j = 0; $j < strlen($str); $j++){
  for($i = 0; $i < 30; $i++){
    if($abc[$i] == $str[$j]){
      echo $abc[$i+$n];
      break;
    }
  }
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define f0(i,b)   for(int i=0;i<(b);i++)
#define f1(i,b)   for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define forr(i,n)    for(i=0; i<n; i++)
#define whilee(i,t)  while(i!=t)
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld\n",a)

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);
//scanf("%d",&x);
//printf("%d\n",x);

//vector <int> A;
//deque <int> A;
//queue <int> A;
//stack <int> A;
//set <int> A;
//map <int,int> A;
//pair <int,int> A ;
//vector <pair <int,int>> A ;
//bitset<32> bset1;
//char ch;
//string S, T, U;
ll i, j, k, a, b, c, d, f, g, h, l, m, n, p, q, r, s, t, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);//NULL
    cout.tie(nullptr);//NULL

    cin>>n;

    x=100000;
    while(n--)
    {
        x*=21;
        y=ceil(x/(double)20);
        c =((y%1000==0)? 0 : (1000-(y%1000)));
        x=y+c;
    }
    cout<<x<<endl;
    return 0;
}



Measured memory_bytes: 3144