akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_map>

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

using namespace std;

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

ll evalNow(vector<vector<int>> s, vector<int> c, vector<int> t, int d, vector<int> last) {
    ll ans = 0;
    ans += s[d][t[d]-1];
    last[t[d]-1] = d+1;
    rep(j, 26) {
        ans -= c[j]*(d+1 - last[j]);
    }
    return ans;
}

ll evalAll(vector<vector<int>> s, vector<int> c, vector<int> t, int d) {
    ll ans = 0;
    vector<int> last(26,0);
    rep(i, d) {
        ans += s[i][t[i]-1];
        last[t[i]-1] = i+1;
        rep(j, 26) {
            ans -= c[j]*(i+1 - last[j]);
        }
    }
    return ans;
}

int main(){
    int d; cin >> d;
    vector<int> c(26);
    rep(i, 26) {
        cin >> c[i];
    }
    vector<vector<int>> s(d, vector<int>(26,0));
    rep(i, d) {
        rep(j, 26) {
            cin >> s[i][j];
        }
    }
    vector<int> t(d);
    ll ans = 0;
    vector<int> last(26,0);

    rep(i, d) {
        // cin >> t[i];
        ll tmpmax = -10000000;
        ll candidate = -1;
        rep(j, 26) {
            t[i] = j+1;
            if(tmpmax < evalNow(s,c,t,i,last)) {
                tmpmax = evalNow(s,c,t,i,last);
                candidate = j+1;
            }
        }
        last[t[i]-1] = i + 1;
        // cout << tmpmax << endl;
        t[i] = candidate;
        // ans += evalNow(s,c,t,i, last);
        // cout << ans << endl;
        // cout << evalAll(s, c, t, i+1) << endl;
    }
    rep(i, d) {
        cout << t[i] << endl;
    }
}


Measured memory_bytes: 3728
import java.util.Arrays;
import java.util.Scanner;

/*

*/

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];

        int count = 0;
        boolean flg = false;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
            if (a[i] == 0) {
                flg = true;
            }
        }
        if (flg) {
            System.out.println(0);
            return;
        }

        long ans = 1;
        long tmp = 1000000000000000000L;
        long std = 1000000000000000000L;
        for (int i = 0; i < n; i++) {
            ans = ans * a[i];
            tmp = tmp / a[i];
            if (std < ans || ans < 0 || tmp == 0) {
                System.out.println("-1");
                return;
            }
        }

        System.out.println(ans);

    }
}

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

struct Node{
	int key,priority;
	struct Node *right, *left;
};

struct Node *root,*nil;

struct Node *treeMinimum(struct Node *x){
	while(x->left!=nil){
		x=x->left;
	}
	return x;
}

struct Node *treeMaximum(struct Node *x){
	while(x->right!=nil){
		x=x->right;
	}
	return x;
}

struct Node *find(struct Node *u,int k){
	struct Node *ret=nil;
	if(u->key==k){
		return u;
	}
	else if(u->key>k){
		if(u->left!=nil){
			return  find(u->left,k);
		}
	}
	else if(u->right!=nil){
		return  find(u->right,k);
	}
	return ret;
}

struct Node *rightRotate(struct Node *t)
{
 struct Node *s=t->left;
  if(t==root){
  root=s;
  }
  t->left=s->right;
  s->right=t;
  return s;
}

struct Node *leftRotate(struct Node *t)
{
  struct Node *s=t->right;
  if (t==root){
  root=s;
  }
  t->right = s->left;
  s->left = t;
  return s;
}
struct Node *treeDelete2(struct Node *t, int key);

struct Node *treeDelete(struct Node *t,int key){
if (t==nil){
    return nil;
    }
  if (key <t->key){
    t->left=treeDelete(t->left,key);
    }
  else if (key > t->key){
    t->right=treeDelete(t->right, key);
    }
  else{
    return treeDelete2(t, key);
    }
  return t;
}

struct Node *treeDelete2(struct Node *t, int key)
{
  if (t->left==nil && t->right==nil){
    return nil;
    }
  if (t->left == nil){
    t=leftRotate(t);
    }
  else if (t->right == nil){
    t=rightRotate(t);
    }
  else {
    if (t->left->priority > t->right->priority)
      t = rightRotate(t);
    else
      t = leftRotate(t);
  }
  return treeDelete(t, key);
}
struct Node *insert(struct Node *t,int key,int priority){
	if (t==nil) {
    struct Node *z;
    z=(struct Node*)malloc(sizeof(struct Node));
    z->key=key;
    z->priority=priority;
    z->left = nil;
    z->right=nil;
    if (root==nil) {
      root = z;
    }
    return z;
  }
  if (key==t->key){
  return t;
  }
  if (key<t->key){
    t->left=insert(t->left, key, priority);
    if (t->priority < t->left->priority)
      t=rightRotate(t);
  } else {
    t->right=insert(t->right,key,priority);
    if (t->priority<t->right->priority)
      t=leftRotate(t);
  }
  return t;
	
}

void inorder(struct Node *u){
 if (u->left!=nil){
 inorder(u->left);
 }
  printf(" %d", u->key);
  if (u->right!=nil){
  inorder(u->right);
  }
}

void preorder(struct Node *u){
 printf(" %d", u->key);
  if(u->left!=nil){
  preorder(u->left);
  }
  if(u->right!=nil){
  preorder(u->right);
  }
}

void print(){
  if (root==nil){
  return;
  }
  preorder(root);
  printf("\n");
  inorder(root);
  printf("\n");
}

int main(void){
	int n,i,y;
	scanf("%d",&n);
	int d;
	struct Node *t;
	root=nil;
	char string[10];
	
	for(i=0;i<n;i++){
		scanf("%s %d",string,&d);
		if(string[0]=='i'){
			scanf(" %d",&y);
			insert(root,d,y);
		}
		else if(string[0]=='p'){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if(string[0]=='f'){
			t=find(root,d);
			if(t!=nil){
				printf("yes\n");
			} 
			else{
				printf("no\n");
			}
		}
		else if(string[0]=='d'){
			t=find(root,d);
			if(t!=nil){
				treeDelete(root,d);
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 7988
use itertools::Itertools;

fn main() {
    proconio::input! {
    a:String,
  }
    let a=a.chars().collect_vec();
    let mut b = 0;
    let mut c = 0;
    for i in 1..a.len()/2 {
        for j in 0..i {
            if a[j] != a[j+i] {
                c+=1;
            }
        }
        if c==0 {b=i}
        c=0
    }
    println!("{}",b*2);
}

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

int main()
{
    string str;
    cin >> str;
    string result = "";
    if(str == "Sunny")
    {
        result = "Cloudy";
    }
    else if(str == "Cloudy")
    {
        result = "Rainy";
    }
    else
    {
        result = "Sunny";
    }
    cout << result << endl;
}

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

struct point{double x, y;};

void koch(int n, point a, point b){
    if(n == 0) return;
    point s,t,u;
    double th = M_PI * 60.0 / 180.0;
    s.x = (a.x * 2.0+ b.x * 1.0) / 3.0;
    s.y = (a.y * 2.0+ b.y * 1.0) / 3.0;
    t.x = (a.x * 1.0+ b.x * 2.0) / 3.0;
    t.y = (a.y * 1.0+ b.y * 2.0) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(n-1,a,s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n-1,s,u);
    printf("%.8f %.8f\n", u.x,u.y);
    koch(n-1,u,t);
    printf("%.8f %.8f\n", t.x,t.y);
    koch(n-1,t,b);
}

int main(){
    point a,b;
    int n;

    scanf("%d", &n);

    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;

    printf("%.8f %.8f\n",a.x, a.y);
    koch(n,a,b);
    printf("%.8f %.8f\n",b.x, b.y);

    return 0;

}


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

int main()
{
	int n, t;
	cin >> n >> t;
	vector<pair<int, int>> ab(n);
	for (auto& i : ab) {
		cin >> i.first >> i.second;
	}

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

	int ret = 0;
	vector<vector<int>> dp(n + 1, vector<int>(t + 1, 0));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < t; ++j) {
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			if (j + ab[i].first < t) {
				dp[i + 1][j + ab[i].first] = max(dp[i + 1][j + ab[i].first], dp[i][j] + ab[i].second);
			}
		}
		ret = max(ret, dp[i][t-1] + ab[i].second);
	}

	cout << ret << endl;

	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    string S;
    cin >> S;

    ll ans = 0;
    REP(i, 3){
        if(S[i] == '1'){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

struct object
{
    int weight, value;
    object(){};
};

int main()
{
    int no_of_objects, capacity;
    cin >> no_of_objects >> capacity;

    vector<object> O(no_of_objects + 1);
    for (int i = 1; i <= no_of_objects; i++)
    {
        cin >> O[i].weight >> O[i].value;
    }

    long long total_value = 0;
    for (int i = 1; i <= no_of_objects; i++)
    {
        total_value += O[i].value;
    }

    int answer = 0;
    vector<long long> minimum_weight(total_value + 1, -1);
    total_value = 0;
    minimum_weight[0] = 0;

    for (int i = 1; i <= no_of_objects; i++)
    {
        total_value += O[i].value;

        for (int v = total_value; v >= O[i].value; v--)
        {
            if (minimum_weight[v - O[i].value] != -1)
            {
                long long weight_required = minimum_weight[v - O[i].value] + O[i].weight;

                if (weight_required <= capacity)
                {
                    answer = max(answer, v);
                }

                if (minimum_weight[v] == -1 || minimum_weight[v] > weight_required)
                {
                    minimum_weight[v] = weight_required;
                }
            }
        }
    }

    cout << answer;

    return 0;
}


Measured memory_bytes: 1024
n = int(input())
p = list(map(int,input().split()))
check = {}
cnt = 0
ans = [i+1 for i in range(n)]
for i in range(n):
    if(p[i]==ans[i]):
        continue
    elif(p[i]!=ans[i]):
        check[i] = p[i]
        if(cnt<3):
            cnt += 1
        else:
            break
if(cnt==0):
    print("YES")
elif(cnt==2):
    print("YES")
else:
    print("NO")
        
        
    

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

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

	vector<vector<int>> happiness(n, vector<int>(3));
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 3; j++)
			cin >> happiness[i][j];
	}

	vector<vector<int>> dp(n, vector<int>(3));
	dp[0][0] = happiness[0][0];
	dp[0][1] = happiness[0][1];
	dp[0][2] = happiness[0][2];

	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < 3; k++)
			{
				if (k != j)
					dp[i][j] = max(dp[i][j], dp[i - 1][k] + happiness[i][j]);
			}
		}
	}
	cout << *max_element(dp[n - 1].begin(), dp[n - 1].end()) << "\n";
}

Measured memory_bytes: 11136
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

from fractions import gcd
import math
A, B = [int(x) for x in input().split()]
N = gcd(A, B)
a = prime_factorize(N)
print(len(set(a))+1)


Measured memory_bytes: 66156
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,same,i,j;
    string s,t;
    cin >> n >> s >> t;
    for(i=0;i<n;i++){
        same = 1;
        for(j=0;j<n-i;j++){
            if(s.at(i+j)!=t.at(j)) same = 0;
        }
        if(same) break;
    }
    cout << n+i << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
long long a[2],b[2],c[2];
int main(){
	long long i,j,n;
	cin >> n;
	for(i=0;i<2;i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	long long mx = n;
	for(i=0;i<=n;i++){
		for(j=0;j<=n - i;j++){
			if(i%a[0]!=0 || j%b[0]!=0) continue;
			int k = (n - i - j)%c[0];
			mx = max(mx,a[1]*(i/a[0]) + b[1]*(j/b[0]) + max(c[0],c[1])*(n - i - j - k)/c[0] + k);
		}
	}
	if(a[0]<=a[1] && b[0]<=b[1] && c[0]<=c[1]){
		cout << mx << endl;
		return 0;
	}
	if(a[0]>=a[1] && b[0]>=b[1] && c[0]>=c[1]){
		for(i=0;i<=n;i++){
			for(j=0;j<=n - i;j++){
				if(i%a[1]!=0 && j%b[1]!=0) continue;
				long long k = (n - i - j)%c[1];
				mx = max(mx,a[0]*(i/a[1]) + b[0]*(j/b[1]) + c[0]*(n - i - j - k)/c[1] + k);
			}
		}
		cout << mx << endl;
		return 0;
	}
	if(a[0]<a[1]){
		a[0] = c[0]; a[1] = c[1];
	}else if(b[0]<b[1]){
		b[0] = c[0]; b[1] = c[1];
	}
	long long ans = mx;
	for(i=0;i<=mx;i++){
		if(i%a[1]!=0) continue;
		int j = (mx - i)%b[1];
		ans = max(ans,a[0]*(i/a[1]) + max(b[0],b[1])*(mx - i - j)/b[1] + j);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define mo 1000000007
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int power(ll a, int b){
	ll c=1;
	while (b){
		if (b&1) c=c*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return c;
}
#define N 200005
#define M N*8
int n, m, a[N], b[N];
int f[M], g[M], flag[M], sum[M], p[M];
void pushup(int t){
	f[t]=min(f[t<<1], f[(t<<1)+1]);
	if (p[t<<1]+g[t<<1]<p[(t<<1)+1]+g[(t<<1)+1])
		p[t]=p[t<<1],
		g[t]=g[t<<1];
	else
		p[t]=p[(t<<1)+1],
		g[t]=g[(t<<1)+1];
}
void build(int t, int l, int r){
	if (l==r){
		f[t]=p[t]=-l;
		g[t]=l;
		return;
	}
	int mid=l+r>>1;
	build(t<<1,l,mid);
	build((t<<1)+1,mid+1,r);
	pushup(t);
}
void pushdown(int t, int l, int r){
	if (flag[t]){
		int mid=l+r>>1;
		f[t<<1]=f[(t<<1)+1]=f[t];
		p[t<<1]=p[(t<<1)+1]=f[t];
		g[t<<1]=l;
		g[(t<<1)+1]=mid+1;
		sum[t<<1]=sum[(t<<1)+1]=0;
		flag[t<<1]=flag[(t<<1)+1]=1;
		flag[t]=sum[t]=0;
	}
	if (sum[t]){
		f[t<<1]+=sum[t];
		p[t<<1]+=sum[t];
		sum[t<<1]+=sum[t];
		f[(t<<1)+1]+=sum[t];
		p[(t<<1)+1]+=sum[t];
		sum[(t<<1)+1]+=sum[t];
		sum[t]=0;
	}
}
void add(int t, int l, int r, int le, int ri){
	if (le<=l && r<=ri){
		f[t]++;
		p[t]++;
		if (!flag[t]) sum[t]++;
		return;
	}
	pushdown(t, l, r);
	int mid=(l+r)>>1;
	if (le<=mid) add(t<<1, l, mid, le, ri);
	if (ri>mid) add((t<<1)+1, mid+1, r, le, ri);
	pushup(t);
}
void upd(int t, int l, int r, int le, int ri, int x){
	if (le<=l && r<=ri){
		flag[t]=1;
		sum[t]=0;
		f[t]=p[t]=x;
		g[t]=l;
		return;
	}
	pushdown(t, l, r);
	int mid=(l+r)>>1;
	if (le<=mid) upd(t<<1, l, mid, le, ri, x);
	if (ri>mid) upd((t<<1)+1, mid+1, r, le, ri, x);
	pushup(t);
}
int query(int t, int l, int r, int x){
	if (r<=x) return f[t];
	pushdown(t,l,r);
	int mid=l+r>>1;
	int mi=9999999;
	if (x>mid) mi=min(query((t<<1)+1, mid+1, r, x), mi);
	mi=min(query(t<<1,l,mid,x), mi);
	return mi;
}
int main(){
	n=read(), m=read();
	for (int i=1;i<=n;i++) a[i]=read(), b[i]=read();
	build(1,1,m);
	for (int i=1;i<=n;i++){
		int mi=a[i]>1?query(1,1,m,a[i]-1):999999;
		upd(1,1,m,a[i],b[i],mi+1);
		if (a[i]>1) add(1,1,m,1,a[i]-1);
		if (b[i]<m) add(1,1,m,b[i]+1,m);
		if (f[1]>=999999) puts("-1");
		else printf("%d\n", p[1]+g[1]);
	}
    return 0;
}
/*
4 4
3 4
1 1
2 3
2 4
*/

Measured memory_bytes: 15488
import collections

BIGINT = int(1e9 + 7)

N, M = map(int, input().split())
invalid = {int(input()) for _ in range(M)}
dp = collections.defaultdict(int)
dp[0] = 1
for i in range(1, N + 1):
    if i in invalid:
        dp[i] = 0
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % BIGINT

print(dp[N])



Measured memory_bytes: 60376
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

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

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

const ll MOD = 1000000007;

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

    int asc[n], desc[n];
    rep(n){
        int is_w = (s[i] == 'W');
        if(i){
            asc[i] = asc[i-1] + is_w;
        }else{
            asc[i] = is_w;
        }
    }
    for(int i=n-1;i>=0;i--){
        int is_w = (s[i] == 'W');
        if(i != n-1){
            desc[i] = desc[i+1] + is_w;
        }else{
            desc[i] = is_w;
        }
    }

    int ans = n;
    rep(n){
        int tmp = 0;
        if(i) tmp += asc[i-1];
        if(i != n-1) tmp += n-i-1-desc[i+1];
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3076
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    total = 0
    mi = f_inf
    cnt_minus = 0
    for a in A:
        if a < 0:
            cnt_minus += 1
        if mi > abs(a):
            mi = abs(a)
        total += abs(a)
    print(total if cnt_minus % 2 == 0 else total - mi * 2)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 20172
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef struct _data {
	int x;
	int y;
} data;

int  main()
{
	string s;
	cin >> s;
	int len = s.size();
	string a = s;
	string b = s.substr(0, (len - 1)/2);
	string c = s.substr(((len+3)/2) - 1, len - 1);
	int cnt = 0;
	reverse(a.begin(), a.end());
	if (a == s) cnt++;
	reverse(b.begin(), b.end());
	if (b == s.substr(0, (len - 1)/2)) cnt++;
	reverse(c.begin(), c.end());
	if (c == s.substr(((len+3)/2) - 1, len - 1)) cnt++;
	if (cnt == 3) cout << "Yes\n";
	else cout << "No\n";
	return (0);
}

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

using namespace std;

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

  int n, m;
  cin >> n >> m;
  vector<int> dp(1 << n, 1e9);
  dp[0] = 0;
  vector<pair<int, int>> sh;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    int mask = 0;
    while (b--) {
      int c;
      cin >> c;
      mask |= (1 << (c - 1));
    }
    sh.emplace_back(a, mask);
  };
  for (int mask = 0; mask < (1 << n); ++mask) {
    for (int j = 0; j < m; ++j) {
      dp[mask | sh[j].second] = min(dp[mask | sh[j].second], dp[mask] + sh[j].first);
    }
  }
  cout << (dp[(1 << n) - 1] == 1e9 ? -1 : dp[(1 << n) - 1]);

  return 0;
}

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

int main() {
    int n; cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    rep(i, n) cin >> s.at(i) >> t.at(i);
    string x; cin >> x;

    ll sum = 0;
    rep(i,n) sum += t.at(i);
    ll res = 0;
    for(int i=0; i<n; i++){
        if(x==s.at(i)){
            res += t.at(i);
            cout << sum - res << endl;
            return 0;
        }
        else{
            res += t.at(i);
        }
    } 
}

Measured memory_bytes: 256
#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,a,n) for(int i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
int main()
{
    fio;
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll k;
        cin>>k;
        ll a,b;
        cin>>a>>b;
        ll flag=0;
        repp(i,a,b+1)
        {
            if(i%k==0)
            {
                flag=1;
                break;
            }
        }
        if(flag)
        cout<<"OK"<<endl;
        else
        cout<<"NG"<<endl;
    }
}

Measured memory_bytes: 3640
/*
 * @Author: Luisvacson
 * @LastEditors: Luisvacson
 * @Descriptions: None
 * @Date: 2020-04-19 20:54:53
 * @LastEditTime: 2020-04-19 20:58:03
 * @FilePath: \VSC\C++\Practice\AC abc163 B.cpp
 */
#include<bits/stdc++.h>
using namespace std;

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

    int x,sum=0;
    for(i=1;i<=m;++i) scanf("%d",&x),sum+=x;

    printf("%d\n",sum<=n?n-sum:-1);
    return 0; 
}

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

int main()
{   
    int N; 
    cin >> N;
    if(N==1){
        cout<<"Yes"<<endl;
        cout<<2<<endl;
        cout<<"1 1"<<endl;
        cout<<"1 1"<<endl;
        return 0;
    }
    for(int n=2;n*(n+1)/2<=N;n++){
        if(N != n*(n+1)/2) continue;

        cout<<"Yes"<<endl;
        cout<<(n+1)<<endl;

        cout<<n;
        for(int i=0;i<n;i++){cout<<" "<<(0*(n-1)+1+i);}
        cout<<endl;
        cout<<n;
        for(int i=0;i<n;i++){cout<<" "<<(1*(n-1)+1+i);}
        cout<<endl;
        cout<<n;
        for(int i=0;i<n-1;i++){cout<<" "<<(2*(n-1)+1+i);}
        cout<<" "<<1;
        cout<<endl;

        vector<vector<int>> l(n-2, vector<int>());
        for(int i=1;i<n-1;i++){
            l.at(i-1).push_back(0*(n-1)+1+i);
            l.at(i-1).push_back(1*(n-1)+1+i);
            l.at(i-1).push_back(2*(n-1)+1+i);
        }
        for(int i=1;i<n-1;i++){
            for(int j=i+1;j<n-1;j++){
                l.at(i-1).push_back(3*(n-1)+(j-1)+(n-3)*(i-1)-i*(i-1)/2);
                l.at(j-1).push_back(3*(n-1)+(j-1)+(n-3)*(i-1)-i*(i-1)/2);
            }
        }
        for(int i=1;i<n-1;i++){
            cout<<l.at(i-1).size();
            for(auto v: l.at(i-1)){
                cout<<" "<<v;
            }
            cout<<endl;
        }

        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 2304
/**In the name of Allah, the Most Merciful, the Most Merciful.**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 9223372036854775806
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 2*acos(0.0)
#define EPS 1e-9
ll max(ll a,ll b) {if(a>b) return a; else return b;}
ll min(ll a,ll b) {if(a<b) return a; else return b;}

int main()
{
    int n;
    string s;
    cin>>n>>s;
    vector<int> w,r;
    for(int i=0;i<n;i++){
        if(s[i]=='W') w.pb(i);
        else r.pb(i);
    }
    reverse(r.begin(),r.end());

    int i=0,j=0,x=w.size(),y=r.size();
    int cnt=0;
    while(i<x && j<y && w[i]<r[j]){
        i++;
        j++;
        cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}




Measured memory_bytes: 4684
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}


void solve()
{
	int a, b, c;	
	cin >> a >> b >> c;
	for(ll i = 1; i <= 1000; ++i){
		if((i * a) % b == c){
			cout << "YES";
			return;
		}
	}
	cout << "NO";
}



 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,m,k,sum=0,cnt;


int main() {
	
  while(1){
    cin>>n>>m;
    cnt=0;
    if(n==0 && m==0) break;
      for (int i=1;i<=n-2;i++){
        for (int j=i+1;j<=n-1;j++){
          for (int k=j+1;k<=n;k++){
            sum=k+j+i;
            if (sum==m) cnt++;
          }
        }
      }
     cout<<cnt<<endl;
  }
 
   
  return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
static const int MAX = 200000;

int N, M;
int A[MAX], B[MAX], C[MAX/2], color[MAX/2];
vector<int> V[MAX/2];

void bfs(){
    queue<int> Q;
    Q.push(0);
    color[0] = 1;
    int a = 0;
    int b = 0;
    while( !Q.empty() ){
        a = Q.front(); Q.pop();
        for(int i = 0; i < V[a].size(); i++){
            if(color[V[a][i]] == 0){
                b = V[a][i];
                color[b] = 1;
                C[b] = a;
                Q.push(b);
            }
        }
    }
}

int main(){
    cin >> N >> M;
    rep(i,M){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
        V[A[i]].push_back(B[i]);
        V[B[i]].push_back(A[i]);
    }

    bfs();
    cout << "Yes" << endl;
    for(int i = 1; i < N; i++){
        cout << C[i]+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 12348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};



int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int p,q,r;cin >> p >> q >> r;
	cout << min(p+q,min(p+r,r+q)) << endl;
}

Measured memory_bytes: 256
object Main{
  def main(args: Array[String]){
    if (sys.env.getOrElse("TEST", "")=="1"){

    }else{
      val input=io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }


  def solve(input:String):String={
    if(input.split(" ").map(_ .toInt).product %2 == 0){"Even"}else{ "Odd"}
  }
}

Measured memory_bytes: 25532
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<string>
using namespace std;
using P = pair<pair<string, int>, int>;
int n;
vector<P> v;
int main()
{
    cin >> n;
    REP(i, n) {
        string c;
        int s;
        cin >> c >> s;
        v.push_back(make_pair(make_pair(c, -s), i + 1));
    }
    sort(v.begin(), v.end());
    REP(i, n) {
        // DD(v[i].first.first, v[i].first.second);
        cout << v[i].second << endl;
    }
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void){
	int m,f,b,o;
	scanf("%d %d %d",&m,&f,&b);
	if(m>b){
		printf("0\n");
	}
	else if(m+f>=b){
		o=b-m;
		printf("%d\n",o);
	}
	else {
		printf("NA\n");
	}
	return 0;
}


Measured memory_bytes: 2124
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<map>
#include<algorithm>

int main() {
	int n;
	cin >> n;
	map<string, int>mp;
	rep(i, n) {
		string s;
		cin >> s;
		mp[s]++;
	}
	int mx = 0;
	for (auto p : mp) {
		mx = max(mx, p.second);//一番多いのが何回かを探し、mxにいれる
	}
	for (auto p : mp) {
		if (p.second!= mx) {
			continue;
		}
		cout << p.first << endl;
	}
	return 0;
}

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

using ll = long long;
#define repi(n) for (int i = 0; i < (n); i++)
#define repj(n) for (int j = 0; j < (n); j++)
#define repk(n) for (int k = 0; k < (n); k++)
#define repl(n) for (int l = 0; l < (n); l++)
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define repr(i, a, b) for (auto i = (a); i < (b); i++)
#define repv(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = max((t), (v)))
#define updatemin(t, v) (t = min((t), (v)))
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}

int main() {
  int n;
  cin >> n;
  repi(10) {
    if (n <= 111 * i) {
      cout << 111 * i << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll q,h,s,d,n;
	cin>>q>>h>>s>>d>>n;
	ll min1,min2;
	min1 = min({4*q,2*h,s});
	min2 = min(2*min1,d);
	ll ans = (n/2)*min2;
	if(n&1)ans+=min1;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<long long>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
int MOD=1e9+7;
int INF=1e9+7;
//
int main(){
  long long N;
  long long A[100000];
  long long B[100000];
  cin>>N;
  FOR(i,0,N){
    cin>>A[i]>>B[i];
  }
  long long cnt=0;
  ROF(i,0,N){
    if((A[i]+cnt)%B[i]==0){
      continue;
    }else{
      cnt+=(((A[i]+cnt)+B[i]-1)/B[i])*B[i]-(A[i]+cnt);
    }
  }
  cout<<cnt<<endl;
  return 0;
}


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

using namespace std;

#define MAX 5050
typedef long long ll;
const ll MOD = ((1e9) + 7);

int dp[MAX][MAX];

int main()
{
    int N, L;
    cin >> N >> L;
    vector<int> x(N), a(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i]; 
    }
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < L; i++) {
        dp[0][i] = 1;
    }

    for (int i = 0; i < N; i++) {        
        for (int j = x[i]; j < L; j += a[i]) {
            if (j > 0) {
                dp[i+1][j] += dp[i][j-1];
            } else {
                dp[i+1][j] = dp[i][j];
            }
            dp[i+1][j] %= MOD;
            if (a[i] == 0) break;
        }
        
        for (int j = x[i]; j < L; j++) {
            dp[i+1][j+1] += dp[i+1][j];
            dp[i+1][j+1] %= MOD;
        }      
    }
    
    cout << dp[N][L-1] << endl;
    return 0;
}

Measured memory_bytes: 70068
#include <bits/stdc++.h>
using namespace std;
int main() {
     int N;
     cin >> N;
     vector<int> L(N);
     for(int i = 0; i < N; i++){
          cin >> L[i];
     }

     sort(L.begin(),L.end());
     int sum = 0;
     for(int i = 0; i < (N - 1); i++) sum += L[i];

     if(L[N-1] < sum) cout << "Yes" << endl;
     else cout << "No" << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define f first
#define sec second
#define pb push_back
#define pf push_front
#define pbb pop_back
#define vi vector<ll>
#define vii vector< pair<ll,ll> >
#define pi pair<ll,ll>
#define map map<ll,ll>
#define set set<ll>
const int m=1e9+7;
int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int m=-1;
    int count=1;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        if(i==0){
            m=x;
        }
        else{
            if(x<=m){
            count++;
            m=min(m,x);}
        }
    }
    cout<<count<<endl;
}
   

Measured memory_bytes: 256
// https://ei1333.github.io/luzhiled/
// http://beet-aizu.hatenablog.com/entry/2017/01/04/113233
// http://www.prefield.com/algorithm/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#define in1(A) REP(i,A.size()) in(A[i]);
#define in2(A,B) REP(i,A.size()) in(A[i],B[i]);
#define in3(s,t,u) REP(i,sz(s)){in(s[i] , t[i] , u[i]);}
#define in4(s,t,u,v) REP(i,sz(s)){in(s[i] , t[i] , u[i] , v[i]);}
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離 
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} 
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
//-------------------------------------------------------------------------------------------------
int main(){
    init();
    ins(s); //ACGT
    ll ans=0,t=0;
    REP(i,s.size()){
        if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C') t++;
        else t=0;
        chmax(ans,t);
    }
    out(ans);
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	t, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return t
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

func pattern1(l []int) int {
	n := (l[0]*l[3])+(l[1]*l[4])
	return n
}
func pattern2(l []int) int {
	n :=2*l[2]*max(l[3],l[4])
	return n
}
func pattern3(l []int) int {
	n := 2*l[2]*min(l[3],l[4])+(doch(l))
	return n
}


func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func doch(l[] int) int {
	if l[3]>l[4] {
		return l[0] * (l[3]-l[4])
	}else{
		return l[1] * (l[4]-l[3])
	}
}


func main() {
	len := 5
	l := scanNums(len)
	fmt.Println(min(pattern1(l),pattern2(l), pattern3(l)))

}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll a[11][11];
signed main() {
	ll n, d, ans = 0, p = 0, ta = 0;
	cin >> n >> d;
	rep(i, n) { rep(j, d)cin >> a[i][j]; }
	rep(i, n - 1) {
		for (int j = i + 1; j < n; j++) {
			rep(k, d) {
				ans += pow(a[i][k] - a[j][k], 2);
			}
			for (int l = 1; l <= 150; l++) {
				if (l * l == ans)p++;
			}
			if (p == 1)ta++;
			ans = 0, p = 0;
		}
	}
	cout << ta << endl;
	ggr
}

Measured memory_bytes: 256
const [nStr, aStr, qStr, ...bcStrs] = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/)
let s = 0;
const aMap = aStr.split(/\s/).reduce((acc, curr) => {
  const v = Number(curr)
  acc[v] = (acc[v] || 0) + 1
  s += v
  return acc
}, [])
for (const bc of bcStrs) {
  if (!bc) {
    continue
  }
  const [b, c] = bc.split(/\s/).map(Number)
  const originalB = aMap[b] || 0
  s += (c - b) * originalB
  console.log(s)
  aMap[c] = (aMap[c] || 0) + originalB
  aMap[b] = 0
}

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

// Function to get the missing number
void solve(){
    long long n;
    cin>>n;
    int a = n%10;
    if (a==2||a==4||a==5||a==7||a==9){
        cout<<"hon";
        }
    else if (a==1||a==0||a==6||a==8){
        cout<<"pon";
    }
    else{
        cout<<"bon";
    }}


// Driver Code
int main()
{
    solve();
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;


const double PI = acos(-1.0);

struct PT {
  ll x, y;
  int id;
  PT() {}
  PT(ll x_, ll y_): x(x_), y(y_), id(-1) {}
  ll len2() const {
    return x * x + y * y;
  }
  double len() const {
    return sqrt(len2());
  }
  PT operator - (const PT &b) const {
    return PT(x - b.x, y - b.y);
  }
  ll operator * (const PT &b) const {
    return x * b.x + y * b.y;
  }
  ll operator % (const PT &b) const {
    return x * b.y - y * b.x;
  }
  bool operator < (const PT &b) const {
    return tie(x, y) < tie(b.x, b.y);
  }
};

const int MAXN = 123;
PT in[MAXN];
double ans[MAXN];

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    in[i].x = x;
    in[i].y = y;
    in[i].id = i;
  }
  sort(in, in + N);
  vector<PT> st;
  for (int i = 0; i < N; i++) {
    while (SZ(st) >= 2 && (st[SZ(st) - 1] - st[SZ(st) - 2]) % (in[i] - st[SZ(st) - 1]) < 0)
      st.pop_back();
    st.PB(in[i]);
  }
  for (int i = N - 2; i >= 0; i--) {
    while (SZ(st) >= 2 && (st[SZ(st) - 1] - st[SZ(st) - 2]) % (in[i] - st[SZ(st) - 1]) < 0)
      st.pop_back();
    st.PB(in[i]);
  }
  for (int i = 0; i < N; i++)
    ans[i] = 0;
  st.PB(st[1]);
  for (int i = 1; i < SZ(st) - 1; i++) {
    PT A = st[i - 1] - st[i];
    PT B = st[i + 1] - st[i];
    double tmp = A * B / (A.len() * B.len());
    //double ang = PI - acos(clamp(tmp, -1.0, 1.0)); // C++ 17 required
    double ang = PI - acos(min(max(tmp, -1.0), 1.0));
    ans[st[i].id] = ang / (2 * PI);
  }
  for (int i = 0; i < N; i++)
    printf("%.10f\n", ans[i]);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s,r;
	int i,train,n;
	cin >> n;
	while(n--)
	{
		cin >> s;

		r="";
		train=0;
		r+=s[0];

		for(i=1;i<s.size(); i+=3)
		{
			if(s[i]=='-')
			{
				if(train==r.size()-1)
					r.push_back(s[i+2]);
				++train;
			}
			else
			{
				if(train==0)
					r.insert(r.begin(),s[i+2]);
				else
					--train;
			}
		}
		cout << r << endl;
	}
	return 0;
}

Measured memory_bytes: 0
N = int(input())
count = 0
D1_arr = []
D2_arr = []
for i in range(N):
    D1, D2 = map(int, input().split())
    D1_arr.append(D1)
    D2_arr.append(D2)
for i in range(N-2):
    if D1_arr[i] == D2_arr[i] and D1_arr[i+1] == D2_arr[i+1] and D1_arr[i+2] == D2_arr[i+2]:
        count += 1
if count >= 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9092
// AOJ 0010 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0010&lang=jp)
#include<cstdio>
#include<cmath>
#define rep(i,a) for(int i=0;i<(a);++i)

int n;

double sqr( double x )
{ return x*x; }

int main()
{
	scanf( "%d", &n );
	while( n-- )
	{
		double x1, y1, x2, y2, x3, y3;
		scanf( "%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3 );

		double a = sqrt(sqr(x3-x2)+sqr(y3-y2)), b = sqrt(sqr(x1-x3)+sqr(y1-y3)), c = sqrt(sqr(x2-x1)+sqr(y2-y1));
		double cosA = (sqr(b)+sqr(c)-sqr(a))/(2*b*c), cosB = (sqr(c)+sqr(a)-sqr(b))/(2*c*a), cosC = (sqr(a)+sqr(b)-sqr(c))/(2*a*b);
		double sinA = sqrt(1-sqr(cosA)), sinB = sqrt(1-sqr(cosB)), sinC = sqrt(1-sqr(cosC));
		double sin2A = 2*sinA*cosA, sin2B = 2*sinB*cosB, sin2C = 2*sinC*cosC;
		double px = (sin2A*x1+sin2B*x2+sin2C*x3)/(sin2A+sin2B+sin2C), py = (sin2A*y1+sin2B*y2+sin2C*y3)/(sin2A+sin2B+sin2C);

		printf( "%.3f %.3f %.3f\n", px, py, sqrt(sqr(x1-px)+sqr(y1-py)) );
	}

	return 0;
}

Measured memory_bytes: 1076
//#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){
    int w,a,b;
    cin >> w >> a >> b;
    if(a+w<=b){
        cout << b-(a+w);
    }else if(b+w<=a){
        cout << a -(b+w);
    }else{
        cout << 0;
    }
    return 0;
}

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

int main() {
    int n,temp,odd=0;
    cin>>n;
    rep(i,n) {
        cin>>temp;
        if (temp%2==1) odd++;
    }
    if (odd%2==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct data{int num,l,r;};
vector<data> At,Bt;
 
bool check(int s,int t, string &str){
  stack <char> st;
  for(int i=s;i<=t;i++){
    if(str[i]=='(') st.push(str[i]);
    if(str[i]==')'&&st.empty())return 0;  
    if(str[i]==')') st.pop();
  }
  return st.empty();
}
 
int get_num(string &str,int &idx){
  int res=0;
  while(isdigit(str[idx]))res=res*10+str[idx++]-'0';
  return res;
}
 
 
int get_root(int s,int t,string &str){
  stack <char> st;
  for(int i=s;i<=t;i++){
    if(st.empty()&&isdigit(str[i])) return i;
    if(str[i]=='(') st.push(str[i]);
    if(str[i]==')') st.pop();
  }
  assert(0);
}
 
 
void make_tree(int s,int t,vector<data>&tree,string &str,int idx){
    while(s<t&&check(s,t,str)) s++,t--;
  if(s>=t)return;
  s--,t++;
 
  int root=get_root(s,t,str);
  tree.push_back((data){-1,-1,-1});
  tree[idx].l=tree.size()-1;
  make_tree(s,root-2,tree,str,tree.size()-1);
 
  tree[idx].num=get_num(str,root);
 
  tree.push_back((data){-1,-1,-1});
  tree[idx].r=tree.size()-1;
  make_tree(root+1,t,tree,str,tree.size()-1);
}
 
string make_str(int a,int b){
  if(a==-1||b==-1||At[a].num<0||Bt[b].num<0) return "";
  int num=At[a].num+Bt[b].num;
  string str;
  if(num==0)str="0";
  while(num) str=(char)((num%10)+'0')+str,num/=10;
 
  return "("+make_str(At[a].l,Bt[b].l)+")"+"["+str+"]"+"("+make_str(At[a].r,Bt[b].r)+")";
 
}
int main(){
  string A,B;
  cin>>A>>B;
  At.push_back((data){-1,-1,-1});
  Bt.push_back((data){-1,-1,-1});
  make_tree(0,A.size()-1,At,A,0);
  make_tree(0,B.size()-1,Bt,B,0);
  cout <<make_str(0,0)<<endl;  
  return 0;
}

Measured memory_bytes: 3188
from itertools import product

N = int(input())

MOD = 10**9 + 7

# dp[s][i][j][k] = str[s:s+3]が(i,j,k)となる個数の数え上げ
dp = [[[[0] * 4 for _ in range(4)] for _ in range(4)] for _ in range(N-2)]

# 初期条件
for i in range(4):
    for j in range(4):
        for k in range(4):
            if i==0 and j==1 and k==2: continue #AGC
            if i==0 and j==2 and k==1: continue #ACG
            if i==1 and j==0 and k==2: continue #GAC
            dp[0][i][j][k] = 1

# 先頭から末尾に向けてループ
for i in range(N-3):
    # 確定している文字列 (ppp,pp,p)
    for ppp in range(4):
        for pp in range(4):
            for p in range(4):
                # 次の文字 (n)
                for n in range(4):
                    if pp==0 and p==1 and n==2: continue #AGC
                    if pp==0 and p==2 and n==1: continue #ACG
                    if pp==1 and p==0 and n==2: continue #GAC
                    if ppp==0 and p==1 and n==2: continue #A?GC
                    if ppp==0 and pp==1 and n==2: continue #AG?C
                    dp[i+1][pp][p][n] += dp[i][ppp][pp][p]
                    dp[i+1][pp][p][n] %= MOD

ans = sum(sum(sum(a) for a in b) for b in dp[-1])
print(ans % MOD)

Measured memory_bytes: 3444