akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void) {
	int N = 0,i,o;
	scanf("%d", &N);
	if (65 <= N&&N<=90) {
		printf("1\n");
	}else if (97 <= N&&N <= 122) {
		printf("2\n");
	}else {
		printf("0\n");
	}
	return 0;
}


Measured memory_bytes: 2136
#pragma once

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ll mod = 1000000007;

int main(void)
{
	ll h, n;
	cin >> h >> n;
	vector<ll> as(n);
	rep(i, n)cin >> as[i];
	ll sum = 0;
	rep(i, n) sum += as[i];
	if (sum >= h) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
// ※※※ 解答不能 ※※※
// 正解者のソースを学習する(一部改変).
// hbi1998氏
// https://atcoder.jp/contests/agc038/submissions/7637627
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 110000;

struct Edge {
    int u, v, t;
    Edge(int u = 0, int v = 0, int t = 0) : u(u), v(v), t(t) {}
} E[N];

int root[N];

int find_root(int u) {
    if (u == root[u]) return root[u];
    return root[u] = find_root(root[u]);
}

int main(){
    int n, q;
    LL m;
    scanf("%d %lld %d", &n, &m, &q);
    for(int i = 0; i < q; i++) scanf("%d %d %d", &E[i].u, &E[i].v, &E[i].t), E[i].u++, E[i].v++;
    for(int i = 1; i <= n; i++) root[i] = i;
    for(int i = 0; i < q; i++){
        if(E[i].t == 0){
            int a = find_root(E[i].u), b = find_root(E[i].v);
            if(a == b) continue;
            root[a] = b, m--;
        }
    }
    int cnt = 0;
    for(int i = 0; i < q; i++){
        if(E[i].t == 1){
            cnt++;
            int a = find_root(E[i].u), b = find_root(E[i].v);
            if(a == b){
                printf("%s\n", "No");
                return 0;
            }
        }
    }
    int now = 0;
    for(int i = 1; i <= n; i++) now += (root[i] == i);
    if((cnt && now <= 2) || (m < now - (cnt == 0) || m > (LL)now * (now - 1) / 2)){
        printf("%s\n", "No");
        return 0;
    }
    printf("%s\n", "Yes");
    return 0;
}

Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner stdIn = new Scanner(System.in)) {
			Main m = new Main();
			while (true) {
				int h = stdIn.nextInt();
				int w = stdIn.nextInt();
				if (h > 300 || w > 300) {
					throw new RuntimeException("Out of Range Error");
				}
				if (h == 0 && w == 0) {
					break;
				}
				m.setChar('#');
				m.DrawSquare(h, w);
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}

	private Character displayChar;
	/**
	 * Draw square by define character
	 * @param height Square of height
	 * @param width  Square of width
	 */
	protected void DrawSquare(int height, int width) {
		if (height < 0 || width < 0) {
			throw new RuntimeException("Error:Minus Value Input");
		}
		for (int i = 1; i <= height; i++) {
			for (int j = 1; j <= width; j++) {
				System.out.print(this.displayChar);
			}
			System.out.println("");
		}
		System.out.println("");
	}

	/**
	 * Define character to draw square
	 * @param displayChar Set a character
	 */
	protected void setChar(Character displayChar) {
		this.displayChar = displayChar;
	}
}

Measured memory_bytes: 38204
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int coin = 0;
    for(int i=1; ; i++){
        coin += a;
        if(i%7 == 0) coin += b;
        if(coin >= c){
            cout << i << endl;
            break;
        }
    }
    return 0;
}


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

int main() 
{
    ll a;
    cin>>a;
    a%=10;
    if(a==2 || a==4 || a==5 || a==7 || a==9) cout<<"hon";
    else if(a==0 || a==1 || a==6 || a==8) cout<<"pon";
    else cout<<"bon";
}

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

int main(){
	int M1,D1,M2,D2;
	cin >>M1>>D1>>M2>>D2;
	if(M1==M2){
    	cout << 0 << endl; 
    }
	
 	else {
      cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a;
    int b;
    cin >> a;
    cin >> b;
    if (a<b){
        cout << "a < b";}
    else if(a>b){
        cout << "a > b";}
    else if(a==b){
    cout << "a == b";}
    cout <<endl;
    
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n,m;
  cin>>n>>m;
  vector<vector<int>> s;
  REP(i,m) {
    int k;
    cin>>k;
    vecint v(k);
    REP(j,k) {
      int t;
      cin>>t;
      --t;
      v[j] = t;
    }
    s.push_back(v);
  }
  vecint p(m);
  REP(i,m) cin>>p[i];
  int cnt=0;
  REP(i,1<<n) {
    bool ok = true;
    REP(j,m) {
      int sum = 0;
      REP(k,s[j].size()) {
        if ((i>>s[j][k])&1) {
          ++sum;
        }
      }
      if ((sum%2) != p[j]) ok=false;
    }
    if(ok) ++cnt;
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#include <random>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=b;--i)
#define range(i,a,b,c) for(int i=a;\
                    c>0?i<b:\
                    i>b;\
                    i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep) {
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

template<class InputIterator>
int sum(InputIterator begin, InputIterator end) {
	return accumulate(begin, end, 0ll);
}

string reverse_str(string s) {
	reverse(all(s));
	return s;
}

int W, a, b;

void solve() {
	cin >> W >> a >> b;
	cout << max((ll)0, abs(a - b) - W) << endl;
}

signed main() {
	srand(time(NULL));
	int T = (int)1e15;
	solve();
	cout << fixed << setprecision(15);
	rep(i, T) {
		char s[MAX];
		if (scanf("%s", s) == EOF) break;
		int n = strlen(s);
		for (int i = n - 1; i > -1; i--) {
			ungetc(s[i], stdin);
		}
		solve();
	}
	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;
using namespace std;
#define int long long
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                    \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifndef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define prec fixed << setprecision(12)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define test  \
	int t;    \
	cin >> t; \
	while (t--)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;
int _x[] = {0, 0, -1, 1, -1, 1, -1, 1};
int _y[] = {-1, 1, 0, 0, 1, -1, -1, 1};

void solve()
{
	string s;
	cin >> s;
	int ans = 0;
	rep(i, 0, sz(s) - 1)
		ans += s[i] - '0';
	if (ans % 9)
		cout << "No";
	else
	{
		cout << "Yes";
	}
}

int32_t main()
{
	ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin.tie(NULL);
	// test
	solve();
	return 0;
}


Measured memory_bytes: 3736
N,Q=map(int,input().split())
S=input()
X=[0]*N
for i in range(N-1):
	if S[i:i+2]=="AC":
		X[i+1]=X[i]+1
	else:
		X[i+1]=X[i]
for i in range(Q):
	L,R=map(int,input().split())
	print(X[R-1]-X[L-1])

Measured memory_bytes: 6060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define quick ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
int main()
{
	quick;
	char a;
	cin>>a;
	if(a=='A')
	{
		cout<<'T'<<endl;
		return 0;
	}
	if(a=='T')
	{
		cout<<'A'<<endl;
		return 0;
	}
	if(a=='C')
	{
		cout<<'G'<<endl;
		return 0;
	}
	if(a=='G')
	{
		cout<<'C'<<endl;
		return 0;
	}
}


Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 998244353;
pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}};

ll min(ll a, ll b){
	if (a < b)
		return a;


		return b;
}

ll max(ll a, ll b) {
	if (a < b)
		return b;
	
	return a;
}



ll N;

ll dp[300][90005];
ll dp2[300][90005];
vector<ll> a;

ll modpow(ll a, ll b) {
	if (b == 0) return 1;

	if (b % 2 == 1) { return (a * modpow(a, b - 1)) % mod; }

	if (b % 2 == 0) { ll retval = modpow(a, b / 2); return (retval * retval) % mod; }
}


int main() {
	cin >> N;
	a.resize(N);
	ll S = 0;
	rep(i, N) {
		cin >> a[i];
		S += a[i];
	}

	dp[0][a[0]] = 1;
	dp[0][0] = 2;
	dp2[0][a[0]] = 1;
	dp2[0][0] = 1;
	for(int i = 1; i < N; i++) {
		rep(j, 300 * N + 1) {

			if (j - a[i] >= 0) {
				dp[i][j] = dp[i-1][j - a[i]] + 2 * dp[i-1][j];
				dp2[i][j] = dp2[i - 1][j - a[i]] + dp2[i - 1][j];
			}
			else {
				dp[i][j] = 2 * dp[i - 1][j];
				dp2[i][j] = dp2[i - 1][j];
			}

			dp[i][j] %= mod;
			dp2[i][j] %= mod;

		}
	}

	ll ans = 0;
	
	ll sum = 0, sum2 = 0;

	for (int j = S / 2 + (S % 2); j <= 300 * N + 1; j++) {
		sum += dp[N-1][j];
		sum %= mod;
	}

	
	if (S % 2 == 1)
		ans = modpow(3, N) +(mod - ((3 * sum) % mod));
	else
		ans = modpow(3, N) +(mod - ((3 * sum) % mod)) + 3 * dp2[N - 1][S / 2];


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

Measured memory_bytes: 421504
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	vector<int> t;
	int ans = 0;
	for (int i = 0; i < 5; ++i) {
		int a, b;
		cin >> a;
		b = a % 10;
		ans += a - b;
		if (b) {
			t.push_back(b);
			ans += 10;
		}
	}
	if (!t.empty()) {
		sort(t.begin(), t.end());
		ans -= 10 - t.front();
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int a;
  cin >> a;
  cout << a+a*a+a*a*a << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include<string.h>
int main() {
    char ar[10000];
    int x,n,i,m;
        scanf("%d",&x);
        scanf("%s",&ar);
        for(i=0;i<=strlen(ar)-1;i++){
            
            n=ar[i];
            m=n;
            n=n+x;
            if(n<91){
            printf("%c",n);}
            else{
            n=(m-90)+64+x;
            printf("%c",n);}
            
            
        }
}

Measured memory_bytes: 128
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
  
already = [0] * N
A = [-float("inf")] * N

for i in range(N):#スタート地点
  if already[i] == 0:
    already[i] = 1
    q = [i + 1]
    now = i + 1
    score = []
    T = True
    while T:
      now = P[now - 1]
      score.append(C[now - 1])
      if now in q:
        T = False
      else:
        q.append(now)
        already[now - 1] = 1
    
    #A.append(q)
    #S.append(score)
    #print(q)#ループのルート
    #print(score)#ループ中のスコア
    roop = sum(score)
    if len(q) >= K:
      aa = -float("inf")
      for j in range(len(q)):
        time = 0
        bb = 0
        p = j
        while time != K:
          time += 1
          bb += score[p]
          aa = max(aa, bb)
          p += 1
          if p == len(q):
            p = 0
      A[i] = aa      
    else:  
      if roop <= 0:
        aa = -float("inf")
        for j in range(len(q)):
          time = 0
          bb = 0
          p = j
          while time != len(q):
            time += 1
            bb += score[p]
            aa = max(aa, bb)
            p += 1
            if p == len(q):
              p = 0
        A[i] = aa            
      else:
        ll = int(K / len(q)) 
        rr = K % len(q)
        aa = -float("inf")
        for j in range(len(q)):
          time = 0
          bb = ll * roop
          p = j
          while time != len(q):
            time += 1
            bb += score[p]
            if time == rr + 1:
              bb -= roop
            aa = max(aa, bb)
            p += 1
            if p == len(q):
              p = 0
        A[i] = aa           
        

#print(A)      
print(max(A))      
      
      
    
    
    


Measured memory_bytes: 74952
char s[2];m[21][21];main(n,x,y,c){for(;scanf("%d",&n),n;){for(memset(m,0,sizeof(m));n--;m[x][y]=1)scanf("%d%d",&x,&y);for(scanf("%d",&n),x=y=10;n--;)for(scanf("%s%d",s,&c),m[x][y]=0;c--;m[x][y]=0)*s=='W'?x--:*s=='E'?x++:*s=='S'?y--:y++;for(x=0;x<21;x++)for(y=0;y<21;y++)if(m[x][y])goto z;z:puts(x-21?"No":"Yes");}exit(0);}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
int flag[200002][2];

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		if(a==0){
			flag[b][0]=1;
		}
		if(b==0){
			flag[a][0]=1;
		}
		if(a==n-1){
			flag[b][1]=1;
		}
		if(b==n-1){
			flag[a][1]=1;
		}
	}
	bool res=false;
	for(int i=1;i<n-1;i++){
		if(flag[i][0]==1 && flag[i][1]==1)res=true;
	}
	printf("%s\n",res?"POSSIBLE":"IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main ()
{
    string a,b,c;
    int temp;
    char n;
    cin>>a>>b>>c;
    n=a[0];
    temp=int(n);
    temp=temp-32;
    n=char(temp);
    cout<<n;

    n=b[0];
    temp=int(n);
    temp=temp-32;
    n=char(temp);
    cout<<n;

    n=c[0];
    temp=int(n);
    temp=temp-32;
    n=char(temp);
    cout<<n;
    return 0;
}


Measured memory_bytes: 3592
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s;
        String[] a;
        int[] b=new int[3];
        int ch=0,hi=0;
        while(sc.hasNextLine()){
            s=sc.nextLine();
            a=s.split(",");
            for(int i=0;i<3;i++){
                b[i]=Integer.parseInt(a[i]);
            }
            if(b[0]*b[0]+b[1]*b[1]-b[2]*b[2]==0){
                ch++;
            }else if(b[0]==b[1]){
                hi++;
            }
        }
        System.out.println(ch);
        System.out.println(hi);
    }
}

Measured memory_bytes: 17140
var
 i:longint;
 s,s1,s2:string;
begin
 readln(s);
 readln(s1);
 for i:=1 to length(s1) do
  s2:=s2+s[i]+s1[i];
 if length(s)>length(s1) then s2:=s2+s[length(s)];
 writeln(s2);
end.

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

struct edge{
  int to;
  int cost;
};

using P = pair<int,int>;

const int MAX_N = 1e3;
const int INF = 1e9;
vector<edge> G[MAX_N];
vector<int> dist(MAX_N,INF);
vector<int> par(MAX_N,-1);

void dijkstra(int s){
  priority_queue<P,vector<P>,greater<P>> PQ;
  for(int i=0; i<MAX_N; i++){
    dist[i] = INF;
    par[i] = -1;
  }
  dist[s] = 0;
  PQ.push(P(0,s));
  
  while(PQ.size()){
    P p = PQ.top();
    PQ.pop();
    int v = p.second; //from
    if(dist[v] < p.first){ //現在わかっている距離が更新できない
      continue;
    }
    for(int i=0; i<G[v].size(); i++){
      edge e = G[v][i];
      if(dist[e.to] > dist[v] + e.cost){
        dist[e.to] = dist[v] + e.cost;
        par[e.to] = v;
        PQ.push(P(dist[e.to], e.to));
      }
    }
  }
}

vector<int> restore(int start, int end){
  int now = end;
  vector<int> use(0);
  use.push_back(end);
  while(par[now] != -1){
    use.push_back(par[now]);
    now = par[now];
  }
  //reverse(use.begin(),use.end());
  return use;
}


int main(){
  int N, M;
  cin >> N >> M;
  for(int i=0; i<M; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    edge add;
    add.to = b;
    add.cost = 1;
    G[a].push_back(add);
  }
  
  bool flag = false;
  vector<int> ans;
  
  for(int i=0; i<N; i++){
    if(flag){
      break;
    }
    dijkstra(i);
    for(int j=0; j<N; j++){
      if(flag){
        break;
      }
      if(j == i){
        continue;
      }
      for(int k=0; k<G[j].size(); k++){
        if(G[j][k].to == i && dist[j] != INF){
          ans = restore(i,j);
          map<int,int> in;
          map<int,int> out;
          for(int l=0; l<ans.size(); l++){
            in[ans[l]] = 0;
            out[ans[l]] = 0;
          }
          for(int l=0; l<ans.size(); l++){
            for(int m=0; m<G[ans[l]].size(); m++){
              if(in.count(G[ans[l]][m].to)){
                in[G[ans[l]][m].to]++;
                out[ans[l]]++;
              }
            }
          }
          bool check = true;
          //cout << ans.size() << endl;
          for(int l=0; l<ans.size(); l++){
            //cout << in[ans[l]] << " " << out[ans[l]] << endl;
            if(in[ans[l]] != 1 || out[ans[l]] != 1){
              check = false;
            }
          }
          if(check){
            flag = true;
            break;
          }
        }
      }
    }
  }
  
  if(flag){
    cout << ans.size() << endl;
    for(int i=0; i<ans.size(); i++){
      cout << ans[i]+1 << endl;
    }
  }
  else{
    cout << -1 << endl;
  }
  
  
}

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

int main(){
    /* A 
    int n,x,t;
    cin >> n >> x >> t;
    int ans;
    if(n%x!=0)ans=(n/x+1)*t;
    else ans=n/x*t;
    cout << ans << endl;*/

    /* B*/
    string s;
    cin >> s;
    int ans=0;
    for(int i=0;i<s.size();i++){
        ans += s.at(i) - '0';
    }
    cout << ((ans%9==0)? "Yes":"No") << endl;

    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<ll>> vec(n, vector<ll>(3));
    for(auto& i : vec){
        for(auto& j : i){
            cin >> j;
        }
    }
    ll ans = 0, sum = 0;
    for(int bit = 0b000; bit <= 0b111; bit++){
        vector<ll> v(n, 0);
        for(int i=0; i<n; i++){
            for(int j=0; j<3; j++){
                if((bit >> j) & 1){
                    v[i] -= vec[i][j];
                }else{
                    v[i] += vec[i][j];
                }
            }
        }
        sort(v.rbegin(), v.rend());
        ans = max(ans, accumulate(v.begin(), v.begin()+m, 0LL));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 64 * 15 + 208;

int main() {
    ll n, t, q;
    cin >> n >> t >> q;
    vector<ll> v(n+2), u(n+2), ans(n+2, -INF<ll>);
    v[0] = -INF<ll>; u[0] = 1;
    v[n+1] = INF<ll>; u[n+1] = 2;
    for (int i = 1; i <= n; ++i) {
        cin >> v[i] >> u[i];
    }
    int l = 0, m = 1;
    ll tmp = 0;
    for (int i = 0; i <= n+1; ++i) {
        if(m == u[i]) continue;
        if(u[i] == 2){
            tmp = (v[i]+v[i-1])/2;
            m = 2;
        }else {
            for (int j = l; j <= i-1; ++j) {
                ans[j] = tmp;
            }
            l = i;
            m = 1;
        }
    }
    if(ans[n+1] == -INF<ll>) for (int j = l; j <= n+1; ++j) {
        ans[j] = tmp;
    }
    for (int i = 0; i < q; ++i) {
        ll x;
        cin >> x;
        if(abs(v[x]-ans[x]) < t) printf("%lld\n", ans[x]);
        else printf("%lld\n", v[x] + (v[x] > ans[x] ? -t : t));
    }
    return 0;
}



Measured memory_bytes: 5128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


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

  long long int N, x;

  cin >> N >> x;

  long long int a[N];

  REP(i, N) cin >> a[i];

long long int tot=0;
 REPS(i, 1, N){
   if(a[i]+a[i-1]>x){
     long long int temp;
     temp = a[i]+a[i-1]-x;
     tot += temp;
     a[i]=a[i]-min(temp, a[i]);
   }
 }

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


Measured memory_bytes: 1024
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt() + sc.nextInt();
        int c = sc.nextInt() + sc.nextInt();
        if(a == c) {
            System.out.println("Balanced");
        } else if(a > c){
            System.out.println("Left");
        } else {
            System.out.println("Right");
        }
    }
}

Measured memory_bytes: 22100
#include<cstdio>
#include<cmath>

int Money =100000;
int n;
int main()
{
	scanf("%d",&n);
	for(int i =0;i<n;i++)
	{
		Money*=1.05;
	 	int amari = Money%1000;
		if(amari!=0)Money=Money-amari+1000;
	}
	printf("%d\n",Money);
	return 0;
}

Measured memory_bytes: 0
even' :: String -> String
even' s = [s !! (2*i) | i<-[0..length s],2*i<length s]
odd' ::String -> String
odd' s = [s !! (2*i+1) | i<-[0..length s],2*i+1 < length s]



main = do
    s <- getLine
 --   putStrLn (even' s)
--    putStrLn (odd' s)
    if 'L' `elem` (even' s) || 'R' `elem` (odd' s)
        then putStrLn ("No")
        else putStrLn  ("Yes")


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int m1, d1; cin >> m1 >> d1;
    int m2, d2; cin >> m2 >> d2;
    cout << (m1 != m2) << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

int main() {
  int n;
  cin >> n;
  map<P, int> mp;
  for (int i = 1; i <= n; ++i) {
    int t = i % 10;
    int h = (to_string(i))[0] - '0';
    ++mp[{h, t}];
  }

  ll ans = 0;
  for (auto p : mp) {
    int h = p.first.first;
    int t = p.first.second;
    int cnt = p.second;
    ans += (ll)cnt * mp[{t, h}];
  }

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


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

int main(){
  string S;
  cin>>S;
  long long int K;
  cin>>K;
  
  for(int i=0;i<S.size();i++){
    K-= pow(S.at(i)-'0',50000000000000);
    if(K<=0){
      cout<<S.at(i)<<endl;
      return 0;
    }
  }
  
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<random>
#include<numeric>
#include<string>
#include<cstring>
typedef long long ll;
typedef long double ld;
using namespace std;
ll dx[] = { 0,0,1,-1 };
ll dy[] = { 1,-1,0,0 };

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b)*b;
}
ll prime(ll x) {
	ll i;
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i*i <= x; i += 2) {
		if (x%i == 0) return 0;
	}
	return 1;
}

int main() {
	ll N;
	cin >> N;
	ll a[N + 10];
	for (ll i = 0; i < N; i++) {
		cin>>a[i];
	}
	ll ans = 0;
	ll sum = 0;
	map<ll, ll>cnt;
	cnt[0] = 1;
	for (ll i = 0; i < N; i++) {
		sum += a[i]; 
		ans += cnt[sum];
		cnt[sum]++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 14336
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#include<stack>
using namespace std;
int main(void) {
	int k;
	int n;
	cin >> k >> n;
	if (k * 500 >= n) {
		cout << "Yes"<< endl;
		return 0;
	}
	cout << "No" << endl;

	return 0;
}
	
	



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k,a,b;
  cin>>k>>a>>b;
  bool c=false;
  for(int i=1;i<1000;i++){
    if(k*i>=a && k*i<=b){
      c=true;
    }
  }
  if(c) cout<<"OK"<<endl;
  else cout<<"NG"<<endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

unordered_map <string, bool> mp;
const int N = 10;
vector <ll> v;
ll to_num(string s)
{
	ll res = 0;
	for(int i = 0; i < s.size(); i++) {
		res *= 10;
		int x = s[i] - '0';
		res += x;
	}
	return res;
}
void rec(string s)
{
	if(s.size() > N || mp[s])
	return;
	
	mp[s] = true;
	if(s.size() > 0)
	v.pb(to_num(s));
	
	if(s.size() == 0) {
		for(int i = 1; i < 10; i++) {
			s += char(i + '0');
			rec(s);
			s.pop_back();
		}
	}
	else {
		int x = s.back() - '0';
		for(int i = max(0, x - 1); i <= min(9, x + 1); i++) {
			s += char(i + '0');
			rec(s);
			s.pop_back();
		}
	}
}
int main()
{
	boost;
	rec("");
	sort(all(v));
	int k;
	cin >> k;
	cout << v[k - 1] << '\n';
}


Measured memory_bytes: 25272
import java.util.*;
public class Main {// Main
    public static void main(String[] args){
    	Scanner in = new Scanner(System.in);
    	String S = in.nextLine();
    	char[] chs = {'C','O','D','E','F','E','S','T','I','V','A','L','2','0','1','6'};
    	char[] input = S.toCharArray();
    	int count = 0;
    	for(int i=0; i<16; i++){
    		if(chs[i]!=input[i])count++;
    	}
    	System.out.println(count);
    }
}

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

int main() {
 // ここにプログラムを追記
  int a,b,x;
  
  cin >> a >> b;
  x = a*b%2;
  
  if(x)
    cout << "Odd" << endl;
  else
    cout << "Even" << endl;
}


Measured memory_bytes: 3536
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

struct node{
	int x;
	int y;
	int h;
};

using namespace std;
typedef long long int ll;

int main()
{
	int n;
	cin>>n;
	vector<node> points(n);
	int pivot = 0;
	for(int i = 0; i < n; i++){
		cin>>points[i].x>>points[i].y>>points[i].h;
		if( points[i].h > 0) pivot = i;
	}
	//cout<<"pivot"<<pivot<<endl;
	for(int x = 0; x <= 100; x++){
		for(int y = 0; y <= 100; y++){
			int H = points[pivot].h + abs(x-points[pivot].x) + abs(y-points[pivot].y);
			bool ans = true;
			for(int i = 0; i < n; i++){
				if( points[i].h != max(H - abs(x - points[i].x) - abs(y - points[i].y),0)){
					ans = false;
					break;
				}
			}
			if(ans == true){
				cout<<x<<" "<<y<<" "<<H<<endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3152
n=int(input())
a = list(map(int, input().split()))
b=sorted(a,reverse=True)
s=b[0]
t=2
if n==2:
  print(s)
else:
    for i in range(1,n):
        for _ in range(2):
            s+=b[i]
            t+=1
            if t==n:
                break
        else:
            continue
        break
    print(s)



Measured memory_bytes: 94084
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      s = 500*i + 100*j + 50*k
      if s == x:
        count += 1
print(count)

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

const double pi = acos(-1);

int main()
{
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double hd = pi * 2 * (h / 12.0 + m / 60.0 / 12.0);
    double md = pi * 2 * (m / 60.0);
    double d = hd - md;
    if(d < 0) d += pi * 2;
    if(d >= pi) d = pi * 2 - d;
    double ans = sqrt(a * a + b * b - 2 * a * b * cos(d));
    cout << fixed << setprecision(15) << ans << endl;
}


Measured memory_bytes: 4200
/* いもす法 */
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

int main(){
    int n;
    cin >> n;
    vector<P> work(n);

    REP(i, n) {
        int a, b;
        cin >> a >> b;
        work[i] = make_pair(b, a);
    }

    sort(work.begin(), work.end());

    int jikan = 0;
    REP(i, n) {
        jikan += work[i].second;
        if(work[i].first < jikan) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

const ll INF = 1ll<<60;

 
int main(){
    string s, t;
    cin >> s >> t;
    vec<vec<int>> dp(s.size()+1, vec<int>(t.size()+1));
    rep(i, s.size()+1) dp[i][0] = 0;
    rep(j, t.size()+1) dp[0][j] = 0;
    rep(i, s.size()) rep(j, t.size()) {
        if (s[i]==t[j]) dp[i+1][j+1] = dp[i][j] + 1;
        else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
    }
    int m, n;
    m = s.size(); n = t.size();
    vec<int> ans;
    while(true) {
        if (dp[m][n]==0) break;
        if (s[m-1] == t[n-1]) {
            ans.push_back(m);
            m--, n--;
        } else {
            if (dp[m-1][n] > dp[m][n-1]) {
                m--;
            } else {
                n--;
            }
        }
    }
    string res = "";
    rep(i, ans.size()) res += s[ans[ans.size()-i-1]-1];
    cout << res << endl;
}

Measured memory_bytes: 35584
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

bool p[100000] = {};
vector<ll> ans;

int main() {
	ll n = 100000;
	rep(i, 0, n)p[i] = true;
	p[0] = false;
	p[1] = false;
	for (int i = 2; i*i < n; i++) {
		if (p[i]) {
			for (int j = 2; i*j < n; j++) {
				p[i*j] = false;
			}
		}
	}
	rep(i, 0, n) {
		if (p[i] && p[(i + 1) / 2]) {
			ans.push_back(i);
		}
	}

	ll s[100001] = {};
	rep(i, 0, ans.size()) {
		s[ans[i]]++;
	}
	rep(i, 1, 100001) {
		s[i] += s[i - 1];
	}

	ll q; cin >> q;
	rep(i, 0, q) {
		ll l, r; cin >> l >> r;
		cout << s[r] - s[l - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 2044
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
int n,a[200005];
ll f[200005],g[200005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]==a[i-1])i--,n--;
	}
	f[0]=1;
	for(int i=1;i<=n;i++)
	{
		f[i]=f[i-1]+g[a[i]];
		if(f[i]>MOD)f[i]-=MOD;
		g[a[i]]=f[i];
	}
	printf("%lld\n",f[n]);
	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <bitset>
#include <vector>
#define LOT 12

using namespace std;

struct key {
	int cost;
	bitset<LOT> ts;
};

int main(void) {
	int nots,temp,N,M;
	cin >> N >> M;
	vector<key> ks(M);
	for (int i = 0; i < M; ++i) {
		cin >> ks[i].cost >> nots;
		ks[i].ts = bitset<LOT>(0);
		for (int j = 0; j < nots; ++j) {
			cin >> temp;
			ks[i].ts.set(temp-1);
		}
	}
	int lim = (1 << N);
	vector<int> dp(lim,(1 << 28));
	dp[0] = 0;
	bitset<LOT> now;
	for (int i = 0; i < M; ++i) {
		for (int j = 0; j < lim; ++j) {
			if (dp[j] < (1 << 28)) {
				now = bitset<LOT>(j);
				dp[(now|ks[i].ts).to_ulong()] = min(dp[j]+ks[i].cost,dp[(now|ks[i].ts).to_ulong()]);
			}
		}
	}

	if (dp[lim-1] < (1 << 28)) {
		cout << dp[lim-1] << endl;
	}
	else {
		cout << -1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string vec[N];
  
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }
  
  sort(vec,vec+N);
  int ans = 1; 

  for (int i = 0; i < N-1; i++) {
    if(vec[i] != vec[i+1]){
        ans++;
    }
  }
  
  cout << ans <<endl;
}

Measured memory_bytes: 9880
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int ,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int N,L;cin>>N>>L;

  vector<string>v;
  for(int i=0;i<N;i++){
    string s; cin>>s;
    v.push_back(s);
  }

  sort(v.begin(),v.end());

  for(auto x:v)cout<<x;
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
# ABC 143 D - Triangles
# https://atcoder.jp/contests/abc143/tasks/abc143_d

n = gets.chomp.to_i
l = gets.chomp.split(/ /).map(&:to_i).sort

# puts sticks.inspect
# puts ""

count = 0
0.upto(n - 3) do |i|
  # a = l[i]
  (i + 1).upto(n - 2) do |j|
    # b = l[j]
    candidates = l[(j + 1)..(n - 1)]
    # puts "--------"
    # puts "a: #{a.length}, b: #{b.length}, a - b: #{a.length - b.length}"
    # puts candidates.inspect
    t = l[i] + l[j]
    c_over_index = candidates.bsearch_index { |c| c >= t }
    if c_over_index.nil?
      count += (n - 1) - j
    else
      count += c_over_index
    end
  end
end

puts count


Measured memory_bytes: 1912
n,k = gets.split.map &:to_i

MOD = 998244353

step = []

p = Array.new(n, 0)
p[0] = 1
p[1] = 0

k.times{
	l,r = gets.split.map &:to_i
	step << [l,r+1]
	
	if l == 1 then
		p[1] = 1
	end
}

(2...n).each{ |x|
	p[x] = p[x-1]
	step.each{ |l,r|
		if x - r >= 0 then
			p[x] = (p[x] - p[x - r]) % MOD
		end
		if x - l >= 0 then
			p[x] = (p[x] + p[x - l]) % MOD
		end
	}
}

puts p[n-1]

Measured memory_bytes: 15956
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < (int) n; i++)
#define forin(i, a, b) for(int i = a; i < (int) b; i++) 
#define rofin(i, a, b) for(int i = a; i > b; i--)
#define v vector
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define debug(i) cout << #i << ": " << i << endl
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;


int main() {
    crap;
    int N;
    cin >> N;
    vector<ld> p(N + 1);
    vector<vector<ld>> dp(N+1, vector<ld>(N+1));
    for(int i = 1; i <= N; i++) cin >> p[i];

    dp[0][0] = 1;
    
    for(int i = 1; i <= N; i++) {           // i: total number of coins tossed so far
        for(int j = 0; j <= i; j++) {       // j: number of heads so far
            if(j==0) {
                dp[i][j] = dp[i-1][j] * (1 - p[i]);
            } else if(j==i) {
                dp[i][j] = dp[i-1][j-1] * p[i];
            } else {
                dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1 - p[i]);
            }
        }
    }

    ld sol = 0;
    for(int i = N; i > N / 2; i--) {
        sol += dp[N][i];
    }

    cout << setprecision(10) << sol << endl;
}

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

typedef long long ll;
int dp[123456][3];
int main()
{
  int n;
  cin >> n;
  vector<int>a(n),b(n),c(n);
  for(int i=0;i<n;i++)
  {
      cin >>a[i] >> b[i] >> c[i];
  }
  for(int i=1;i<=n;i++)
  {
      dp[i][0] = max(dp[i-1][1]+a[i-1],dp[i-1][2]+a[i-1]);
      dp[i][1] = max(dp[i-1][0]+b[i-1],dp[i-1][2]+b[i-1]);
      dp[i][2] = max(dp[i-1][0]+c[i-1],dp[i-1][1]+c[i-1]);
  }
  cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));

    return 0;
}



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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void)
{
    ll n;
    cin>>n;
    vector<ll> a(n), l(n+1);
    l[0]=0;
    ll sum=0;
    rep(i,0,n){
        cin>>a[i];
        sum+=a[i]%INF;
        l[i+1]=l[i]+a[i];
    }

    ll ans=0;
    rep(i,0,n){
        ll sum=(l[n]-l[i+1])%INF;
        ans+=a[i]*sum;
        ans%=INF;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if(n <= k){
        cout << (n*x) <<endl;
    } else{
        int ans = k * x;
        n-=k;
        ans += n * y;
        cout <<  ans << endl;
    }


    return 0;
}

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

int main(){
    int n;
    cin >> n;
    ll a, b;
    cin >> a >> b;
    ll ans = 0;
    ll pre_x;
    rep(i, n) {
        ll x;
        cin >> x;
        if ( i == 0 ) {
            pre_x = x;
            continue;
        }
        if ( ( x - pre_x ) * a > b ) {
            ans += b;
        } 
        else {
            ans += ( x - pre_x ) * a;
        }
        pre_x = x;
    }
    if ( a >= b ) {
        cout << b * ( n - 1 ) << endl;
    }
    else {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
H = [list(map(int,input().split())) for i in range(N)]

dpA=[0]*N
dpB=[0]*N
dpC=[0]*N

dpA[0]=H[0][0]
dpB[0]=H[0][1]
dpC[0]=H[0][2]

for num in range(1,N):
  dpA[num]=max(dpB[num-1],dpC[num-1])+H[num][0]
  dpB[num]=max(dpC[num-1],dpA[num-1])+H[num][1]
  dpC[num]=max(dpA[num-1],dpB[num-1])+H[num][2]

print(max(dpA[N-1],dpB[N-1],dpC[N-1]))

Measured memory_bytes: 42356
#include "bits/stdc++.h"

#pragma warning(disable : 4996)

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
//#define int long long;

double dist(double x1, double y1, double x2, double y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
ll idist(ll x1, ll y1, ll x2, ll y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
using namespace std;

signed main() {
  string a;
  ll c = 0;
  cin >> a;
  rep(i, a.length()) {
    if (a[i] == '0')c += 0;
    if (a[i] == '1')c += 1;
    if (a[i] == '2')c += 2;
    if (a[i] == '3')c += 3;
    if (a[i] == '4')c += 4;
    if (a[i] == '5')c += 5;
    if (a[i] == '6')c += 6;
    if (a[i] == '7')c += 7;
    if (a[i] == '8')c += 8;
    if (a[i] == '9')c += 9;
  }
  if (c % 9 == 0) {
    cout << "Yes";
  } else {
    cout << "No";
  }

}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

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

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

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

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector< int > dp(2);
  for(int i = 0; i < N; i++) {
    int C = S[i] == '#';
    vector< int > dp2(2, inf);
    for(int j = 0; j < 2; j++) {
      for(int k = 0; k < 2; k++) {
        if(j == 1 && k == 0) continue;
        chmin(dp2[k], dp[j] + (C ^ k));
      }
    }
    dp.swap(dp2);
  }
  cout << min(dp[0], dp[1]) << endl;
}



Measured memory_bytes: 720
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

ll dp[5010][5010];
ll tmp[5010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    ll a[N];
    REP(i, 0, N) {
        cin >> a[i];
    }
    dp[0][0] = 1;
    REP(j, 0, N) {
        REP(k, 0, K) {
            dp[j + 1][k] += dp[j][k];
            dp[j + 1][min(k + a[j], K)] += dp[j][k];
        }
        dp[j + 1][K] += dp[j][K];
    }
    ll ans = 0;
    REP(i, 0, N) {
        REP(j, 0, K + 1) {
            tmp[j] = dp[N][j];
        }
        bool ok = true;
        REP(j, 0, K) {
            if (j < K - a[i]) {
                tmp[j + a[i]] -= tmp[j];
            } else {
                if (tmp[j] != 0) {
                    ok = false;
                }
            }
        }
        if (ok) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 196096