akhauriyash/Code-Regression huggingface dataset:
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x) 	for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)	(a>b?a:b)
#define min(a,b)	(a<b?a:b)

/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  100005

void solve()
{
	ll n;
	cin>>n;
	ll ans=0;
	rep(i,1,n+1)
	{
		rep(j,1,n+1)
		{
			rep(k,1,n+1)
			{
				ans+=__gcd(i,__gcd(j,k));
			}
		}
	}
	cout<<ans<<endl;
	return;
}
int main()
{
	FAST
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	TIME
	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    s += '.';
    int ans = 0;
    int j = 0;
    for(int i = 0; i < n; i++){
        if(s[i] != s[i + 1]){
            ans = max(ans, min(i + 1, n - j));
            j = i + 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3768
#ifdef __GNUG__
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG // ArrayOutofBounds
#else
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#endif
#define rep(i, N) for (int i = 0; i < N; i++) //制御変数iを用いてN回転
using namespace std;
using ll = long long;
//0:上 1:左 2:下 3:右
const int di[] = { -1, 0, 1, 0};
const int dj[] = { 0, -1, 0, 1};

int main() {
    string S, T;
    cin >> S >> T;
    int ans = T.size();
    rep(i, S.size() - T.size() + 1) {
        int count = 0;
        rep(j, T.size()) {
            if (S[i + j] != T[j]) count++;
        }
        ans = min(ans, count);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
import java.io.*
import java.util.*

const val YES = "Yes"
const val NO = "No"
fun solve(N: Long, W: Array<String>){
    val lis = mutableListOf<String>()
    lis.add(W[0])
    for ( i in 1 until N.toInt() ){
        if (W[i][0] != W[i-1].last()) {println(NO); return}
        if (W[i] in lis) {println(NO); return}
        lis.add(W[i])
    }
    println(YES)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }

    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }

    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val W = StringArray(N.toInt())
    for (i in 0 until N.toInt()) {
        W[i] = sc.next()
    }
    solve(N, W)
}



Measured memory_bytes: 29700
#include <iostream>
#include <map>

using namespace std;


int main() {
	int N, M;
	cin >> N;
	map<string, int> s_map;
	map<string, int> t_map;
	string text;
	for (int i = 0; i < N; i++) {
		cin >> text;
		if (s_map.count(text) == 0) {
			s_map[text] = 1;
		} else {
			s_map[text]++;
		}
	}
	cin >> M;
	for (int i = 0; i < M; i++) {
		cin >> text;
		if (s_map.count(text) != 0) {
			s_map[text]--;
		}
	}
	int max_money = 0;
	for(auto x : s_map) {
	
		if (x.second > max_money) {
			max_money = x.second;
		}
	}
	cout << max_money << endl;
}

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

int main(){
    long long N;
    long long div = 1;
    cin >> N;
    for(int i=0;i<=(sqrt(N)-1);i++){
        double c= N%(i+1);
        if(c==0){
            div = i+1;
        }
    } 
    cout << div+(N/div)-2 << endl;
} 

Measured memory_bytes: 256
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long n, long long m, std::vector<long long> a){
    vector<i64> b;
    for(auto& x : a)
        b.emplace_back(x / 2);
    i64 lc = b[0];
    for(auto& x : b){
        i64 blc = lc;
        lc = lc * x / __gcd(x, lc);
        if(lc > m || (lc >= blc && (lc / blc) % 2 == 0) || (lc >= x && (lc / x) % 2 == 0)){
            cout << 0 << endl;
            return;
        }
    }
    cout << (m / lc) - (m / (lc * 2)) << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, M, std::move(a));
    return 0;
}


Measured memory_bytes: 2168
# 再帰関数で計算
import sys

def caracal(H,count,separate_number):
	if H == 1:
		return count
	else:
		H = int(H/2)
		count = count + (separate_number*2)
		# 攻撃時の分離数
		separate_number = separate_number * 2 
	return caracal(H,count,separate_number)




H = int(input())
print(caracal(H,1,1))

Measured memory_bytes: 3060
#include<stdio.h>

#define MAX 100005
#define NIL -1

typedef struct{
    int parent;
    int left;
    int right;
}node;

node T[MAX];
int n, D[MAX];

void print(int u){
    int i, c;
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("depth = %d, ", D[u]);

    if(T[u].parent==NIL){
        printf("root, ");
    }
    else if(T[u].left==NIL){
        printf("leaf, ");
    }
    else{
        printf("internal node, ");
    }

    printf("[");

    for(i=0, c=T[u].left; c!=NIL; i++, c=T[c].right){
        if(i){
            printf(", ");
        }
        printf("%d", c);
    }

    printf("]\n");

}

int rec(int u, int p){
    D[u]=p;
    if(T[u].right!=NIL){
        rec(T[u].right, p);
    }
    if(T[u].left!=NIL){
        rec(T[u].left, p+1);
    }


}

int main(void){
    int i, j, d, v, c, l, r;
    scanf("%d", &n);
    for(i=0; i<n; i++){
        T[i].parent=NIL;
        T[i].left=NIL;
        T[i].right=NIL;
    }
    for(i=0; i<n; i++){
        scanf("%d %d", &v, &d);
        
        for(j=0; j<d; j++){
            scanf("%d", &c);
            if(j==0){
                T[v].left=c;
            }
            else{
                T[l].right=c;
            }
            l=c;
            T[c].parent=v;
        }
    }
    for(i=0; i<n; i++){
        if(T[i].parent==NIL){
            r=i;
        }
    }

    rec(r,0);

    for(i=0; i<n; i++){
        print(i);
    }

    return 0;
}



Measured memory_bytes: 6376
#include <bits/stdc++.h>
using namespace std;
 
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
 
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const int N = 2e5 + 10;
int dp[N][2];

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

    for (int i = n-1; i >= 0; i--) {
        for (int one = 0; one < 2; one++) {
            dp[i][one] = 0;
            if (i+2 <= n) dp[i][one] = max(dp[i][one], 1 + dp[i+2][0]);
            if (!one || i == 0 || s[i-1] != s[i]) dp[i][one] = max(dp[i][one], 1 + dp[i+1][1]);
        }
    }
    cout << dp[0][0] << '\n';

    return 0;
}


Measured memory_bytes: 2180
n,p = map(int,raw_input().split())

a = map(int,raw_input().split())

odd = 0
even = 0

f = []

f.append(1)
f.append(1)

for i in range(2,51):
	f.append(f[i-1]*i)

for x in a:

	if x%2 == 1:
		odd+=1
	else:
		even+=1

ans = 0

poweven = pow(2,even)

if p == 1:

	for i in range(1,odd+1,2):
		ans += poweven*f[odd]//(f[i]*f[odd-i])

else:

	for i in range(0,odd+1,2):
		ans += poweven*f[odd]//(f[i]*f[odd-i])

print ans

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

int main() {
  int N;
  int A;
  int B;
  cin >> N >> A >> B;
  
  if (N*A >= B) {
    cout << B << endl;
  }
  
  else if(N*A <= B) {
    cout << N*A << endl;
  }

}


Measured memory_bytes: 3520
#include<iostream>
#include<map>

using namespace std;

int main() {
	int n; 
	cin >> n;
	map<int, int> a;
	for (int i = 0; i < n; i++) {
		int b;
      cin>>b;
		a[b]++;
	}

	cout << a.size() << endl;

	return 0;
}


Measured memory_bytes: 7684
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int h,w,k;
int x1,y11,x2,y2;
string s[1000001];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
bool in(int x,int y){
	re(x>=0&&x<h&&y>=0&&y<w);
}
int main(){
	ios::sync_with_stdio(0);
	cin>>h>>w>>k>>x1>>y11>>x2>>y2;
	vector<vi> v(h,vi(w));
	x1--,y11--,x2--,y2--;
	rep(i,h)
	cin>>s[i];
	rep(i,h)
	rep(j,w)
	v[i][j]=1e8;
	v[x1][y11]=0;
	queue<pii> q;
	q.push(m_p(x1,y11));
	while(!q.empty()){
		pii p=q.front();
		int x=p.fr,y=p.se;
		q.pop();
		rep(i,4)
		rep(j,k){
			int xx=x+dx[i]*(j+1),yy=y+dy[i]*(j+1);
			if(!in(xx,yy))
			break;
			if(s[xx][yy]=='@')
			break;;
			if(v[xx][yy]>v[x][y]+1){
				if(xx==x2&&yy==y2){
					cout<<v[x][y]+1;
					re 0;
				}
				v[xx][yy]=v[x][y]+1;
				q.push(m_p(xx,yy));
			}
			if(v[xx][yy]<=v[x][y]){
				break;
			}
		}
	}
	cout<<-1;
	re 0;
}


Measured memory_bytes: 42268
//This Code was made by Chinese_zjc_.
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <time.h>
// #include<windows.h>
#define int long long
#define double long double
using namespace std;
const double PI = acos(-1);
const double eps = 0.0000000001;
const int INF = 0x3fffffffffffffff;
int n, q, sum[500005], a, b, c;
int lowbit(int x)
{
    return x & (-x);
}
int query(int now)
{
    int res = 0;
    while (now)
    {
        res += sum[now];
        now -= lowbit(now);
    }
    return res;
}
void add(int now, int v)
{
    while (now <= n)
    {
        sum[now] += v;
        now += lowbit(now);
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin >> n >> q;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a;
        add(i, a);
    }
    for (int i = 1; i <= q; ++i)
    {
        cin >> a >> b >> c;
        if (a == 0)
        {
            ++b;
            add(b, c);
        }
        if (a == 1)
        {
            cout << query(c) - query(b) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 8240
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


const int MAX_N = 100000;
int N;
int a[MAX_N];

int main() {
  cin >> N;
  rep(i,N) cin >> a[i];

  int o = 0, e = 0, d = 0;
  rep(i, N) {
    if (a[i]%2 == 1) ++o;
    else if (a[i]%4 == 0) ++d;
    else ++e;
  }

  if (d >= o) cout << "Yes" << endl;
  else if (e == 0 && o == d+1) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int dp[300000][3];
int a[300000],b[300000],c[300000];
int main(){
	int n;
	cin>>n;
//	cout<<"N TAKEN\n";		
	for(int i=0;i<n;i++)
		{
			cin>>a[i];//cout<<"A";
			cin>>b[i];//c/err<<"B";
			cin>>c[i];//cerr<<"C";
		}
//	cerr<<"Input taken";
	dp[n-1][0]=a[n-1];
	dp[n-1][1]=b[n-1];
    dp[n-1][2]=c[n-1];
//    cerr<<"H";
	for(int i=n-2;i>=0;i--){
		dp[i][0]=a[i] + max(dp[i+1][1],dp[i+1][2]);
		dp[i][1]=b[i] + max(dp[i+1][0],dp[i+1][2]);
		dp[i][2]=c[i] + max(dp[i+1][1],dp[i+1][0]);
	}
	cout<<max(max(dp[0][1],dp[0][2]),dp[0][0]);
	return 0;
	cout<<"END";
}

Measured memory_bytes: 5120
N,M=map(int,input().split())

R=[]
for i in range(N):
    R.append(M+i)
#print(R)

n=10**9
for i in range(N):
    if abs(R[i])<abs(n):
        n=R[i]
#print(n)
if n>0:
    print(sum(R)-n)
else:
    print(sum(R)-n)
#print(sum(R))

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int n;
int a[101];

int selectionSort(){
	int ret = 0;
	rep(i, n - 1){
		int mini = i;
		REP(j, i + 1, n){
			if (a[j] < a[mini])mini = j;
		}
		if (mini != i)++ret;
		std::swap(a[i], a[mini]);
	}
	return ret;
}

int main(){
	std::cin >> n;
	rep(i, n)std::cin >> a[i];
	int ans = selectionSort();
	std::cout << a[0];
	REP(i, 1, n)std::cout << " " << a[i];
	std::cout << std::endl;
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int n,m,x;
int c[13];
int a[13][13];
int v[13];
int ans = 1000000000;
int main(){
    scanf("%d%d%d",&n,&m,&x);
    for (int i = 0; i < n; i++){
        scanf("%d",&c[i]);
        for (int j = 0; j < m; j++){
            scanf("%d",&a[i][j]);
        }
    }
    for (int M = 0; M < (1<<n); M++){
        int totalcost = 0;
        memset(v,0,sizeof(v));
        for (int i = 0; i < n; i++){
            if (M & (1<<i)){
                totalcost += c[i];
                for (int j = 0; j < m; j++){
                    v[j] += a[i][j];
                }
            }
        }
        bool can = true;
        for (int i = 0; can && i < m; i++){
            if (v[i] < x) can = false;
        }
        if (can){
            ans = min(ans,totalcost);
        }
    }
    if (ans == 1000000000) ans = -1;
    printf("%d",ans);
}


Measured memory_bytes: 3860
n = int(input())
f = []
for _ in range(n):
    f.append(list(map(int, input().split())))
p = []
for _ in range(n):
    p.append(list(map(int, input().split())))

result = -float("inf")

# opening schedule for my shop.
# start from 1(only open Mon.AM) to 1023(open all day)
for b in range(1, 1<<10):

    profit = 0
    # compare with other shops
    for i in range(n):

        common_opening = 0
        # compare time
        for j in range(10):

            if 1&(b>>j) and f[i][j] == 1:

                common_opening += 1
        profit += p[i][common_opening]

    result = max(result, profit)

print(result)


Measured memory_bytes: 3064
#![allow(unused_mut, non_snake_case,unused_imports)]
use std::iter;
use std::cmp::{max, min, Ordering};
use std::mem::{swap};
use std::collections::{HashMap,BTreeMap,HashSet,BTreeSet,BinaryHeap,VecDeque};
use std::iter::FromIterator;

//　高速 EOF要
//macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};}
//macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};}
//macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};}
// 低速 EOF不要
macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
fn main(){
    input!(N:usize,S:chars);
    let mut S:Vec<char> = S;
    S.push('x'); S.push('x');
    let mut ans = 0;
    let mut flag = false;
    for i in 0..N{
        if S[i] == 'x'{
            if flag{
                break;
            }
            flag = true;
        }else{
            flag = false;
        }
        ans +=1;
    }
    println!("{}",ans);
}


Measured memory_bytes: 5036
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>
#include <math.h>           // sqrt()

int
main(int argc, char **argv)
{
	double a, b, c, z;
	double ax, ay;
	double bx, by;
	double cx, cy;

	scanf("%lf,%lf", &ax, &ay);
	scanf("%lf,%lf", &bx, &by);

	double S = 0;
	bool first = true;
	while (scanf("%lf,%lf", &cx, &cy) != EOF)
	{
		if (first)
		{
			a = sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
			first = false;
		}
		else
			a = c;

		b = sqrt((bx - cx) * (bx - cx) + (by - cy) * (by - cy));
		c = sqrt((cx - ax) * (cx - ax) + (cy - ay) * (cy - ay));

		z = (a + b + c) / 2;
		S += sqrt(z * (z - a) * (z - b) * (z - c));
		bx = cx, by = cy;
	}

	printf("%.8f\n", S);
	return 0;
}

Measured memory_bytes: 656
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#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 {
#ifdef 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 << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int nax = 202020;
const int K = 61;
int dokad[K][nax];
int n;
ll k;

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> k;
	REP(i, n) {
		cin >> dokad[0][i];
		--dokad[0][i];
	}
	FOR(step, 1, K - 1) {
		REP(i, n) {
			dokad[step][i] = dokad[step - 1][dokad[step - 1][i]];
		}
	}
	int gdzie = 0;
	FORD(i, K, 0) {
		if (k & (1LL << i)) {
			gdzie = dokad[i][gdzie];
		}
	}
	cout << gdzie + 1 << endl;
}

Measured memory_bytes: 51552
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int inf  = 1LL << 60;

int solve(int n, int k){
  
  int m;
  
  if( n % k == 0 ){ m = (n/k)-1;}
  else{ m = n/k;}
  
  return min(n-m*k,(m+1)*k-n);
}
  

signed main(void){
  int n,k; cin >> n >> k;
  int ans = inf;
  if( n < k ){ ans = min(ans,min(n,solve(k-n,k)));}
  else if( n == k ){ ans = 0;} 
  else{ 
    ans = solve(n,k);
  }
  
  cout << ans << endl;
  
  return 0;
} 

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

#define cMOD 1000000007;

ll memo[201][100001];
vector<ll> s;

ll solve( ll i, ll value )
{
	if( memo[i][value] >= 0 ) return memo[i][value];
	if( i == 0 ) return memo[i][value] = value % s[i];
	return memo[i][value] = 
		( solve( i - 1, value % s[i] ) + 
		  solve( i - 1, value ) * i     ) % cMOD;
}

int main()
{
	ll n,x;
	cin >> n>>x;
	s.assign(n,0);
	REP(i, n) cin >> s[i];
	sort( ALL(s), less<ll>() );
	
	REP(i,n)REP(j,x+1) memo[i][j] = -1;
	cout << solve( n - 1, x ) << endl;
	return 0;
}

Measured memory_bytes: 156544
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> red(a);
    vector<int> gre(b);
    vector<int> col(c);
    rep(i, a) cin >> red[i];
    rep(i, b) cin >> gre[i];
    rep(i, c) cin >> col[i];
    sort(red.begin(), red.end());
    sort(gre.begin(), gre.end());
    sort(col.begin(), col.end());
    vector<int> total(x+y+c);
    rep(i, x) total.push_back(red[a-i-1]);
    rep(i, y) total.push_back(gre[b-i-1]);
    rep(i, c) total.push_back(col[i]);
    sort(total.rbegin(), total.rend());
    ll ans = 0;
    rep(i, x+y) ans += total[i];
    cout << ans;
}


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

using namespace std;

#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define dump(x) cerr << "~ " << #x << " = " << x << endl

#define eps 1e-14

int main() {

	fast_cin;
	
	long double a,b,c;

	cin >> a >> b >> c;

	a = sqrt(a);
	b = sqrt(b);
	c = sqrt(c);

	if(a+b+eps < c) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
T = [0]
coo = [(0, 0)]
for i in range(N):
    t, x, y = map(int, input().split())
    T.append(t)
    coo.append((x, y))

for i in range(N):
    dxdy = coo[i+1][0] - coo[i][0] + coo[i+1][1] - coo[i][1]
    rt = (T[i+1] - T[i]) % 2
    rdxdy = dxdy % 2
    if dxdy <= T[i+1] - T[i] and rt == rdxdy:
        pass
    else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 59480
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
  int N;
  cin >> N;
  int Ocnt = 0,Scnt = 0,Fcnt = 0;
  int a;
  for(int i = 0; i < N; i++){
    cin >> a;
    if(a%4==0) ++Fcnt;
    else if(a%2==0) ++Scnt;
    else ++Ocnt;
  }

  bool flag = false;

  if(Ocnt==0){
    flag = true;
  }else if(Ocnt<(N+1)/2){
    if(Fcnt>=Ocnt) flag = true;
  }else if(Ocnt == (N+1)/2){
    if(N%2==0){
      if(Fcnt==Ocnt) flag = true;
    }else{
      if(Fcnt==Ocnt-1) flag = true;
    }
  }

  if(flag) printf("Yes\n");
  else printf("No\n");

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int min_cycle(int start, int n, vector<vector<int>> &edges) {
    vector<int> costs(n, INT_MAX);
    queue<P> q;
    q.push(P(start, 0));
    while (!q.empty()) {
        P now = q.front();
        q.pop();

        for (int next : edges[now.first]) {
            if (costs[next] != INT_MAX)continue;

            costs[next] = now.second + 1;
            q.push(P(next, now.second + 1));

        }

    }
    return costs[start];
}

bool dfs(int goal, vector<vector<int>> &edges, vector<int> &route, int now, int depth) {
    if (now == goal && route.size() == depth) {
        return true;
    }
    if (depth == route.size()) {
        return false;
    }
    route.push_back(now);
    for (int next : edges[now]) {
        bool b = dfs(goal, edges, route, next, depth);
        if (b) return true;
    }

    route.pop_back();
    return false;

}


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

    vector<vector<int>> edges(n);
    rep(_, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edges[a].push_back(b);
    }

    P mic(INT_MAX, 0);
    rep(i, n) cmin(mic, P(min_cycle(i, n, edges), i));
    if (mic.first == INT_MAX) {
        cout << -1 << endl;
        ret();
    }

    vector<int> route;
    bool b = dfs(mic.second, edges, route, mic.second, mic.first);
    assert(b);
    assert(route.size() == mic.first);
    cout << mic.first << endl;
    for (int i : route) cout << i + 1 << endl;

}


Measured memory_bytes: 384
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
bool cal(string s){
	if(s[0]!='A') return false;
	int f=0,n=0;
	REP(i,1,s.size()){
		if(s[i]>='A' && s[i]<='Z') n++;
		if(i>1 && i<s.size()-1 && s[i]=='C') f=1;
	}
	return (f==1 && n==1);
}
int main()
{
	string s;
	cin>>s;
	if(cal(s)) cout<<"AC"<<endl;else cout<<"WA"<<endl;
}


Measured memory_bytes: 888
//============================================================================
// Name        : ALDS1_1_C.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cmath>
using namespace std;

int main() {
	int n,x,t=0;
	cin >> n;
	for(int i=0;i<n;++i){
		cin >> x;
		for(int j=2; j<(int)pow((double)x,0.5)+1; ++j) {
			if(x%j==0) {
				++t;
				break;
			}
		}
	}
	cout << (n-t) << endl;
	return 0;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD =998244353;
const int MAXN = 2 * 100 * 1000 + 10;
int fact[MAXN];
int puissance(int nombre , int pui)
{
	int tot = 1;
	while (pui > 0)
	{
		if (pui % 2 == 1)
		{
			tot = (tot * nombre) % MOD;
		}
		nombre = (nombre * nombre) % MOD;
		pui/=2;
	}
	return tot;
}

int bi(int N , int K)
{
	int haut = fact[N];
	int bas = (fact[K] * fact[N - K]) % MOD;
	return ((haut * puissance(bas , MOD - 2)) % MOD);
}
int32_t main()
{
	fact[0] = 1;
	for (int i = 1 ; i < MAXN ; i++)
	{
		fact[i] = (fact[i - 1] * i) % MOD;
	}

	int N , M , K;
	cin >> N >> M >> K;
	int actu = puissance(M , N);
	if (N == K - 1)
	{
		cout<<actu<<endl;
		return 0;
	}
	for (int i = 0 ; i < N - K -1; i++)
	{
		int neg = (bi(N - 1 , i) * ((puissance(M - 1, i)* M% MOD)) % MOD);
		actu = (actu + MOD - neg) % MOD;
	}
	cout<<actu<<endl;
}

Measured memory_bytes: 5188
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	long long int N,ans=0,K;
	cin >> N >> K;
	vector<pair<long long int, long long int>>A(N);
	for (long long int i = 0; i < N; i++)
	{
		cin >> A[i].first >> A[i].second;
	}
	sort(A.begin(), A.end());
	for (long long int i = 0; i < N; i++)
	{
		ans += A[i].second;
		if (ans >= K) {
			ans = i;
			break;
		}
	}
	cout << A[ans].first;
}


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

using namespace std;

int n;
short s[510], t[510], a[64][510][510];
unsigned long long u[510], v[510], ans[510][510], p[510];
int cntHor[510][64], cntVer[510][64];
bitset<64> hor[510], ver[510];

void gen(){
	p[0] = 1;

	for(int i = 1; i < 64; i++) p[i] = p[i - 1] << 1;
}

void Fail(){
	cout << "-1\n"; exit(0);
}

int main(){
	gen();
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin >> n;

	for(int i = 1; i <= n; i++) cin >> s[i];
	for(int i = 1; i <= n; i++) cin >> t[i];
	for(int i = 1; i <= n; i++) cin >> u[i];
	for(int i = 1; i <= n; i++) cin >> v[i];

	for(int k = 0; k < 64; k++){
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				if(s[i] == 0){
					if(u[i] & p[k]) a[k][i][j] = 1;
				} else {
					if(u[i] & p[k]);
					else a[k][i][j] = -1;
				}
			}
		}
	}

	for(int k = 0; k < 64; k++){
		for(int j = 1; j <= n; j++){
			for(int i = 1; i <= n; i++){
				if(t[j] == 0){
					if(v[j] & p[k]){
						if(a[k][i][j] == -1) Fail();

						a[k][i][j] = 1;
					}
				} else {
					if(v[j] & p[k]);
					else {
						if(a[k][i][j] == 1) Fail();
						a[k][i][j] = -1;
					}
				}
			}
		}
	}

	for(int k = 0; k < 64; k++){
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				if(s[i] == 0 && a[k][i][j] != 1) cntHor[i][k]++;
				if(t[j] == 0 && a[k][i][j] != 1) cntVer[j][k]++;

				if(a[k][i][j] == 1){
					if(s[i] == 1) hor[i][k] = true;
					if(t[j] == 1) ver[j][k] = true;
				}
			}
		}
	}

	for(int k = 0; k < 64; k++){
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				if(a[k][i][j] == 0){
					if(s[i] == 1 && (t[j] == 1 || cntVer[j][k] > 1) && !hor[i][k]){
						cntVer[j][k]--;
						a[k][i][j] = 1;
						hor[i][k] = true;
					} else if (t[j] == 1 && (s[i] == 1 || cntHor[i][k] > 1) && !ver[j][k]){
						cntHor[i][k]--;
						a[k][i][j] = 1;
						ver[j][k] = true;
					}
				}

				if(a[k][i][j] == 1) ans[i][j] += p[k];
			}
		}
	}

	for(int i = 1; i <= n; i++){
		unsigned long long x, y;
		x = ans[i][1], y = ans[i][1];
 
		for(int j = 1; j <= n; j++){
			x &= ans[i][j];
			y |= ans[i][j];
		}
 
		if(s[i] == 0 && u[i] != x) Fail();
		else if (s[i] == 1 && u[i] != y) Fail();
	}
 
	for(int j = 1; j <= n; j++){
		unsigned long long x, y;
		x = ans[1][j], y = ans[1][j];
 
		for(int i = 1; i <= n; i++){
			x &= ans[i][j];
			y |= ans[i][j];
		}
 
		if(t[j] == 0 && v[j] != x) Fail();
		else if (t[j] == 1 && v[j] != y) Fail();
	}

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			cout << ans[i][j] << " \n"[j == n];
		}
	}

	return 0;
}

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

#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

const int N = 310;

int n;
char A[N][N], B[N][N];

int main() {

	scanf("%d", &n);
	For(i, 0, n - 1) scanf("%s", A[i]);

	int ans = 0;
	For(a, 0, n - 1) {
		For(i, 0, n - 1) For(j, 0, n - 1) B[i][j] = A[(i + a) % n][j];

		bool flag = true;
		For(i, 0, n - 1) For(j, 0, n - 1) if (B[i][j] != B[j][i]) {
			flag = false;
			break;
		}
		if (flag) ans += n;
	}
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

const int MN = 100010;

vll dp(MN, 0);

vvi g(MN);
vi visited(MN, 0);

list<int> sorted_nodes;

void visit(int n){
    if(!visited[n]){
        visited[n] = 1;
        for(const auto& v: g[n]){
            visit(v);
        }
        sorted_nodes.emplace_front(n);
    }
    //reverse(ALL(sorted_nodes));
}

void topologicalSort(ll start_, ll end_){
    repr(i, start_, end_){
        visit(i);
    }
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, m;
    cin >> n >> m;
    vll x(m), y(m);
    rep(i, m){
        cin >> x[i] >> y[i];
        g[x[i]].emplace_back(y[i]);
    }
    topologicalSort(1, n+1);
    for(auto&& e: sorted_nodes){
        for(auto&& v: g[e]){
            chmax(dp[v], dp[e]+1);
        }
    }
    cout << *max_element(ALL(dp)) << endl;
    return 0;
}

Measured memory_bytes: 12928
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;


int main(){
	string s;
	int count=0;
	cin >> s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='x'){
			count++;
		}
	}
	if(count<=7){
		cout << "YES" <<endl;
	}else{
		cout << "NO" <<endl;
	}
	
}


Measured memory_bytes: 256
n=int(input())
A=[[0]*3 for i in range(n)]
for i in range(n):
    a,b=map(str,input().split())
    b=int(b)
    A[i][0],A[i][1],A[i][2]=a,-b,i+1
A.sort()

for i,a in enumerate(zip(*A)):
	if i==2:print(*a,sep='\n')


Measured memory_bytes: 3060
#include <iostream>
#include<bits/stdc++.h>
#include<string>
#define ll long long

using namespace std;
bool check(ll n)
{
    ll b=0;
    for(ll i=2;i<=n/2;i++)
    {
        if(n%i==0)
        {
            b=1;
            break;
        }
    }
    if(b==0)
     return true;
     else
      return false;
}

int main()
{
  ll x,p;
  cin>>x;
  bool possible=true;
  while(possible)
  {
      if(check(x))
      {
          possible=false;
      }
      x++;
  }
  cout<<x-1<<endl;
   
   return 0;
}

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

int main(void)
{
  int H, W;

  scanf("%d %d", &H, &W);
  
  char* c = malloc(W + 1);
  for (int i = 0; i < H; i++)
  {
    scanf("%s", c);
    puts(c), puts(c);
  }
  free(c);
  
  return 0;
}


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

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

typedef long long ll;

ll INF = 1000000000000000000;
ll MOD = 1e9+7;

int main(){
    ll N;cin >> N;
    vector<vector<ll>> F(N,vector<ll>(10));
    for(ll i = 0;i < N;i++){
        for(ll j = 0;j < 10;j++){
            cin >> F[i][j];
        }
    }
    vector<vector<ll>> P(N,vector<ll>(10));
    for(ll i = 0;i < N;i++){
        for(ll j = 0;j < 11;j++){
            cin >> P[i][j];
        }
    }
    ll ans = -1000000000000000;
    for(ll i = 1;i < (1 << 10);i++){
        bitset<10> S(i);
        ll memo = 0;
        vector<ll> L(N,0);
        for(ll j = 0;j < 10;j++){
            if(S.test(j)){ 
                for(ll k = 0;k < N;k++){
                    if(F[k][j]){
                        L[k]++;
                    }
                }
            }
        }
        for(ll j = 0;j < N;j++){
            memo += P[j][L[j]];
        }
        ans = max(ans,memo);
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string w[101];
	map<string,int> mp;
	for (int i=0;i<n;i++) cin>>w[i];
	for (int i=0;i<n;i++){
		int ww=0;
		if (i>0) ww=w[i-1].size();
		if (i>0&&ww>0&&w[i-1][ww-1]!=w[i][0]){
			cout<<"No"<<endl;
			return 0;
		}
		mp[w[i]]++;
	}
	for (int i=0;i<n;i++)
		if (mp[w[i]]>1){cout<<"No"<<endl;return 0;}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=3e3+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

ll dp[MAXn][MAXn];
ll d[MAXn];

int main()
{
    IOS();
    ll n;
    cin>>n;
    REP1(i,n)cin>>d[i];
    for(int ln = 1;ln <= n;ln ++)
    {
        for(int l = 1;l + ln - 1 <= n;l ++)
        {
            int r = l + ln - 1;
            if((n - ln) % 2 == 0)
            {
                dp[l][r] = max(dp[l][r-1] + d[r], dp[l+1][r] + d[l]);
            }
            else 
            {
                dp[l][r] = min(dp[l][r-1] - d[r], dp[l+1][r] - d[l]);
            }
        }
    }
    cout<<dp[1][n]<<endl;
}


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

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int L = A + B;
    int R = C + D;
    if (L > R){
        cout << "Left" << endl;
    } else if (L == R){
        cout << "Balanced" << endl;
    } else {
        cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<class T> struct FenwickTree {
  const int n;
  V<T> t;
  FenwickTree(int n) : n(n), t(n + 1) {}
  void add(int i, T x) { for (++i; i <= n; i += i & -i) t[i] += x; }
  T sum(int i) const {
    T s = 0;
    for (; i; i -= i & -i) s += t[i];
    return s;
  }
  T sum(int l, int r) const { return sum(r) - sum(l); }
};

// BEGIN CUT HERE
struct HeavyLightDecomposition {
  const int n;
  VV<> g;
  V<> sz, par, in, out, anc;
  HeavyLightDecomposition(VV<>& g, int r = 0) : n(g.size()), g(g), sz(n), par(n), in(n), out(n), anc(n) {
    dfs_sz(r, -1);
    anc[r] = r;
    dfs_hl(r);
  }
  void dfs_sz(int v, int p) {
    par[v] = p;
    for (auto&& w : g[v]) if (w == p) {
      swap(w, g[v].back());
      g[v].pop_back();
      break;
    }
    sz[v] = 1;
    for (auto&& w : g[v]) {
      dfs_sz(w, v);
      sz[v] += sz[w];
      if (sz[w] > sz[g[v][0]]) swap(w, g[v][0]);
    }
  }
  void dfs_hl(int v) {
    static int t = 0;
    in[v] = t++;
    for (int w : g[v]) {
      anc[w] = w == g[v][0] ? anc[v] : w;
      dfs_hl(w);
    }
    out[v] = t;
  }
  int lca(int u, int v) {
    while (true) {
      if (in[u] > in[v]) swap(u, v);
      if (anc[u] == anc[v]) return u;
      v = par[anc[v]];
    }
  }
};
// END CUT HERE

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  VV<> g(n);
  for (int v = 0; v < n; ++v) {
    int k; cin >> k;
    while (k--) {
      int c; cin >> c;
      g[v].push_back(c);
    }
  }
  HeavyLightDecomposition hld(g);
  FenwickTree<lint> ft(n);
  int q; cin >> q;
  while (q--) {
    int tp; cin >> tp;
    if (!tp) {
      int v, w; cin >> v >> w;
      ft.add(hld.in[v], w);
    } else {
      int v; cin >> v;
      int u = 0;
      lint res = 0;
      while (true) {
        if (hld.in[u] > hld.in[v]) swap(u, v);
        if (hld.anc[u] == hld.anc[v]) break;
        res += ft.sum(hld.in[hld.anc[v]], hld.in[v] + 1);
        v = hld.par[hld.anc[v]];
      }
      res += ft.sum(hld.in[u] + 1, hld.in[v] + 1);
      cout << res << '\n';
    }
  }
}


Measured memory_bytes: 20832
// ABC063A - 

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;

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

	if (A + B >= 10) {
		cout << "error" << endl;
	} else {
		cout << A + B << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        sc.close();

        Deque<Long> num = new ArrayDeque<>();
        for (int i = 1; i <= 9; i++) {
            num.add((long) i);
        }

        long x = 0;
        for (int i = 1; i <= k; i++) {
            x = num.poll();
            for (int j = -1; j <= 1; j++) {
                long d = x % 10 + j;
                if (d < 0 || d > 9) {
                    continue;
                }
                num.add(x * 10 + d);
            } 
        }
        System.out.println(x);
    }
}


Measured memory_bytes: 31700
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % moder;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), moder - 2, moder) % moder * mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int n, a[25], ma;
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	int ans = 1, ma = a[0];
	REP(i, n) {
		if (ma <= a[i]) {
			ans++;
			ma = a[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());

        if (1000 - (n % 1000) != 1000)
        {
            Console.WriteLine(1000 - (n % 1000));
        }
        else
        {
            Console.WriteLine(0);
        }
        Console.ReadLine();

    }

}

Measured memory_bytes: 17604