akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int r1 = 0, r2 = 0, s1 = 0, s2 = 0;
	for (int i = 0; i < n; i++) {
		if (i & 1) {
			r1 += max(0ll , s1 + a[i] + 1);
			s1 = min(s1 + a[i], -1ll);
			r2 += max(0ll, 1 - (s2 + a[i]));
			s2 = max(s2 + a[i], 1ll);
		}
		else {
			r1 += max(0ll, 1 - (s1 + a[i]));
			s1 = max(s1 + a[i], 1ll);
			r2 += max(0ll, s2 + a[i] + 1);
			s2 = min(s2 + a[i], -1ll);
		}
	}
	cout << min(r1, r2) << endl;
	return 0;
}


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

using namespace std;
const int maxn = 30;
int n,a[maxn];
int main(){
    cin >> n;
    for(int i = 1;i <= n; ++i) cin >> a[i];
    int ans = 0;
    for(int i = 2;i < n; ++i){
        if(a[i] < a[i+1] && a[i] > a[i-1]) ans++;
        if(a[i] > a[i+1] && a[i] < a[i-1]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int n;
    cin>>n;
    map<string,int>cnt;
    for(int i=1;i<=n;i++){
        string s;
        cin>>s;
        cnt[s]++;
    }
    cout<<"AC x "<<cnt["AC"]<<endl;
    cout<<"WA x "<<cnt["WA"]<<endl;
    cout<<"TLE x "<<cnt["TLE"]<<endl;
    cout<<"RE x "<<cnt["RE"]<<endl;
}



Measured memory_bytes: 3628
import scala.io.StdIn

object Main {

  def main(args: Array[String]) {
    val n: Int = StdIn.readLine().toInt
    val ws: List[Int] = StdIn.readLine().split(' ').toList.map(_.toInt)

    val sums: List[Int] = ws.foldLeft(Nil: List[Int])((acc, w) =>
      acc match {
        case Nil => List(w)
        case sum :: tail => sum + w :: acc
      })
    val sum = sums.head
    val diffs = sums.map(s => (sum - s * 2).abs)
    val ans = diffs.foldLeft(sum)((min, d) => if (min < d) min else d)
    println(ans)

  }

}



Measured memory_bytes: 25548
#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>;

bool	issmall(char c)
{
	return (c >= 'a' && c <= 'z');
}

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

	int h, w;
	cin >> h >> w;
	rep(i, h)
	{
		string	s;
		cin >> s;
		rep(j, 2)
			cout << s << endl;
	}
}


Measured memory_bytes: 256
def remain(S, T, A, B, U):
  if U == S:
    A -= 1
  elif U == T:
    B -= 1
  return (A, B)

S, T = input().split()
A, B = list(map(int, input().split()))
U = input()
A, B = remain(S, T, A, B, U)
print(A, B)

Measured memory_bytes: 3060
from collections import Counter
N=int(input())
S=[]
T=[]
for n in range(N):
    s=input()
    S.append(s)
M=int(input())
for m in range(M):
    t=input()
    T.append(t)
d_s=Counter(S)
d_t=Counter(T)
if len(d_s-d_t)==0:
    print(0)
else:
    u=sorted((d_s-d_t).items(), key=lambda x:x[1], reverse=True)
    #print(u)
    print(u[0][1])
    #print("s-t:{}\tmax:{}".format(d_s-d_t, max(d_s-d_t)))
    #print((d_s-d_t)[max(d_s-d_t)])


Measured memory_bytes: 3316
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

S = stdin.readline().rstrip()

for i, s in enumerate(S):
    # 奇数
    if (i+1) % 2 != 0:
        if s in ["R", "U", "D"]:
            pass
        else:
            print("No")
            exit()

    else:
        if s in ["L", "U", "D"]:
            pass
        else:
            print("No")
            exit()


print("Yes")

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

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    set<string> st;
    for (int i = 0; i < N; i++) {
        string S;
        cin >> S;
        st.insert(S);
    }
    cout << st.size() << endl;
}

Measured memory_bytes: 19204
# -*- coding: utf-8 -*-

a,b,c = map(int, raw_input().split())
num = a
cnt = 0
check = []
while(not(num%b in check)):
    if(num%b == c):
        print('YES')
        exit()        
    check.append(num%b)
    num += a
    cnt += 1  
print('NO')

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;
    double ans=0.000000000;
    rep(i,n){
        double x;
        string s;
        cin>>x>>s;
        if(s=="BTC"){
            x *= 380000;
        }
        ans += x;
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

ll sum(ll n) {
  return n*(n+1)/2;
}

int main() {
  int a, b; cin >> a >> b;
  
  cout << sum(b-a) - b << endl;
}

Measured memory_bytes: 256
f,h=range,input
R,C,K=map(int,h().split())
l=lambda:[-~C*[0]for i in f(R+1)]
G=l()
for i in'_'*K:r,c,v=map(int,h().split());G[r][c]=v
F=[l()for i in f(4)]
for r in f(1,R+1):
	for x in f(1,4):
		for c in f(1,C+1):F[x][r][c]=max(F[x-1][r][c],max(F[x-1][r][c-1],(x<2)*F[3][r-1][c])+G[r][c],F[x][r][c-1])
print(F[3][R][C])

Measured memory_bytes: 428672
N = int(input())

ans = [0]*(10**4+1)

for x in range(1, 10**2):
    for y in range(1, 10**2):
        for z in range(1, 10**2):
            n = x**2+y**2+z**2+x*y+y*z+z*x
            if n <10**4+1:
                ans[n] += 1

for i in range(1, N+1):
    print(ans[i])


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

const long long M = 7 + (long long) 1e9;
const long long DM = 100002;

int main(){
    string S;
    cin >> S;

    long long ans[DM][2]={}; // # digit, smaller flag,
    ans[0][0]=1; ans[0][1]=0; 
    int smaller,bit;
    int N = (int) S.size();


    for(int i=1; i<=N; i++){
        bit = (int) ( S[i-1] - '0' );

        ans[i][0] = ( (bit+1) * ans[i-1][0] )%M; // # doubled only if bit == 1
        ans[i][1] = ( (ans[i-1][1]*3)%M  + bit*ans[i-1][0] )%M; // # if S[i] == 1; new smaller cases        

    }

    cout << ( ans[N][0] + ans[N][1] )%M << endl;

    return 0;
}

Measured memory_bytes: 5212
X,Y = (x for x in input().split())
dic = {"A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F":15}

if dic[X] > dic[Y]:
  print('>')
elif dic[X] == dic[Y]:
  print('=')
else:
  print('<')

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

//  文字列を置換する
std::string Replace(std::string String, std::string From, std::string To )
{
    std::string::size_type  Pos( String.find( From ) );

    while( Pos != std::string::npos )
    {
        String.replace( Pos, From.length(), To );
        Pos = String.find( From, Pos + To.length() );
    }

    return String;
}

int main()
{
    string s;
    cin >> s;
    s = Replace(s,","," ");
    cout<<s<<endl;
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int>H(N);
	for (int n = 0;n<N;++n) {
		cin >> H[n];
	}	
	int ans = 0;
	int high = 0;
	for (int n = 0; n < N; ++n) {
		if (high<=H[n]) {
			ans++;
			high = H[n];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3560
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
vint a,b;
int foo(int x,int y,int z){
	if(x==-1) return (y==0?1:0);
	int MA=0,MI=0;
	for(int i=x;i>=0;i--){
		if(a[i]>0) MA+=a[i]*9;
		else if(a[i]<0) MI+=a[i]*9;
	}
	if(y>0&&y+MI>0) return 0;
	if(y<0&&y+MA<0) return 0;
	int ret=0;
	for(int i=0;i<10;i++){
		if(z&(1<<i)||(!i&&b[x])) continue;
		ret+=foo(x-1,y+a[x]*i,z|(1<<i));
	}
	return ret;
}


void mainmain(){
	for(int n;cin>>n,n;){
		vint x(10,0);
		vint y(300,-1);
		int cnt=0;
		vint z(10,0);
		rep(i,n){
			string s;
			cin>>s;
			int t=(i==n-1?-1:1);
			int c=1;
			for(int j=s.size()-1;j>=0;j--){
				if(y[s[j]]==-1) y[s[j]]=cnt++;
				x[y[s[j]]]+=t*c;
				c*=10;
			}
			if(s.size()>1){
				z[y[s[0]]]=1;
			}
		}
		a=x;
		b=z;
		cout<<foo(cnt-1,0,0)<<endl;
	}	
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1224
n = input()
num = map(int, raw_input().split())
ma = max(num)
mi = min(num)
l = list()
if ma*mi < 0:
    if ma > abs(mi):
        index = num.index(ma)
    else:
        index = num.index(mi)
    for i in xrange(n):
        l.append("%d %d" % (index+1, i+1))
    b = num[index]
else:
    b = 0
    for i in num:
        if i:
            b = i
            break

if b == 0:
    pass
elif b < 0:
    for i in xrange(n-1, 0, -1):
        l.append("%d %d" % (i+1, i))
else:
    for i in xrange(0, n-1):
        l.append("%d %d" % (i+1, i+2))

print len(l)
for i in l:
    print i


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1, 0);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<long long int> ssize(n+1, 0);
    for(int i = 1; i <= n; i++){
        ssize[i] = ssize[i-1] + a[i-1];
    }
    vector<vector<long long int>> memo(n, vector<long long int>(n, 0));
    for(int i = n-1; i >= 0; i--){
        for(int j = i+1; j < n; j++){
            long long int coans = 1100100100100100;
            for(int k = i; k < j; k++){
                coans = min(coans, memo[i][k] + memo[k+1][j]);
            }
            memo[i][j] = coans + ssize[j+1]-ssize[i];
        }
    }
    cout << memo[0][n-1] << endl;
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int n,x,dep[2222],lf[2222],val[2222],pa[2222],cnt,ans[44444],ts[2222],cnp,nw,mx,mxi;
bool banned[2222],can[2222];
int used[2222],usedp[2222];
vector<int> g[2222];
void Init(int i,int fa)
{
	pa[i]=fa;dep[i]=dep[fa]+1;
	for (int j=0;j<g[i].size();j++)
	{
		Init(g[i][j],i);
	}
}
void dfs(int i)
{
	int cnt=0,pv;
	for (int j=0;j<g[i].size();j++)
	{
		int to=g[i][j];
		if (banned[to]) continue;
		cnt++;pv=to;
		dfs(to);
	}
	if (cnt>1) return;
	if (cnt==1 && !can[pv]) return;
	can[i]=1;
	if (!cnt) lf[i]=i;
	else lf[i]=lf[pv];
}
void push(int v)
{
	ans[++cnt]=v;
	int p=v;
	memcpy(ts,val,sizeof(val));
	memcpy(usedp,used,sizeof(used));
	while(1)
	{
		if (!p) 
		{
			ts[v]=val[p];
			usedp[v]=used[p];
			break;
		}
		ts[pa[p]]=val[p];
		usedp[pa[p]]=used[p];
		p=pa[p];
	}
	memcpy(val,ts,sizeof(ts));
	memcpy(used,usedp,sizeof(usedp));
}
int main()
{
//	freopen("cin.in","r",stdin);
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		scanf("%d",&x);
		g[x].push_back(i); 
	}
	for (int i=0;i<n;i++) scanf("%d",&val[i]);
	Init(0,-1);
	while(!banned[0])
	{
		memset(can,0,sizeof(can));
		dfs(0);
		cnp=0;
		for (int i=0;i<n;i++) 
		{
			if (can[i]) cnp++;
		}
		memset(used,0,sizeof(used));
		nw=0;
		while(nw<cnp)
		{
			if (can[val[0]])
			{
				x=lf[val[0]];
				while(1)
				{
					if (used[x]!=1) break;
					if (val[x]<val[0]) break;
					x=pa[x];
				}
				push(x);
				used[x]=1;
				nw++;
			}
			else
			{
				mx=0;
				for (int i=0;i<n;i++)
				{
					if (banned[i] || used[i]) continue;
					if (dep[i]>mx)
					{
						mx=dep[i];
						mxi=i;
					}
				}
				push(mxi);
				used[mxi]=2;
			}
		}
		for (int i=0;i<n;i++) 
		{
			if (can[i]) banned[i]=1;
		}
	}
	printf("%d\n",cnt);
	for (int i=1;i<=cnt;i++) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main() {
ll N, M;cin >> N >> M;

if(M < 2*N){cout << M/2;exit(0);}

cout << (2*N + M)/4;

}


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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}

lli pow1(lli x, lli y) {
  lli ans = 1;
  while(y>0) {
    if(y&1) {
      ans = (ans * x) % MOD;
    }
    x = (x * x) % MOD;
    y = y>>1;
  }
  return ans;
}

lli inv(lli x) {
  return pow1(x, MOD-2);
}

lli C(lli x, lli y) {
  lli ans = 1;
  rep(i,y+1,x+1) {
    ans = ans * i;
    ans %= MOD;
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  preprocess();
  int n; cin>>n;
  string st; cin>>st;
  int b, w;
  b = w = 0;
  vi ar;
  if(st[0] == 'W') {
    cout<<0<<endl;
    return 0;
  }
  ar.pb(0);
  rep(i,1,2*n) {
    if(st[i] == st[i-1]) {
      ar.pb(!ar.back());
    }
    else ar.pb(ar.back());
  }
  lli ans = 1;
  int c = 0, flag = 0;
  debug(ar);
  int c0, c1;
  c0 = c1 = 0;
  for(auto x: ar) {
    if(x) c1++;
    else c0++;
  }
  if(c0 != c1) {
    cout<<0<<endl;
    return 0;
  }
  for(int i = 2*n-1; i>=0; i--) {
    if(ar[i] == 1) c++;
    else {
      ans *= c;
      ans %= MOD;
      c--;
      if(c<0) flag = 1;
    }
  }
  rep(i,1,n+1) {
    ans = (ans * i) % MOD;
  }
  if(flag) cout<<0<<endl;
  else cout<<ans<<endl;
}



Measured memory_bytes: 1680
#include <iostream>
using namespace std;
int main() {
  int n,p,q,r;
  cin>>n;
  int a[100][100]={};
  for (int i=0;i<n;i++){
    cin>>q>>p;
    if (p!=0){
      for (int j=0;j<p;j++){
	cin>>r;
	a[i][r-1]=1;
      }
    }
  }
  for (int i=0;i<n;i++){
    for (int j=0;j<n;j++){
      cout<<a[i][j];
      if (j!=n-1)cout<<" "; 
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include <map>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
map<int,int>vis;
vis[a]=1;
vis[b]=1;
int arr[3]={1,2,3};
for(int i=0; i<3; ++i)
{
if(!vis[arr[i]])
{
cout<<arr[i];
return 0;
}
}
}


Measured memory_bytes: 3156
N, K = map(int, input().split())

MOD = 10 ** 9 + 7

def factorial_mod(n, mod):
    a = 1
    for i in range(1, n + 1):
        a *= i
        a %= mod
    return a


def comb_mod(n, k, mod):
    if k > n:
        return 0
    fact_n = factorial_mod(n, mod)
    fact_k = factorial_mod(k, mod)
    fact_n_k = factorial_mod(n - k, mod)
    return (fact_n * pow(fact_k, mod - 2, mod) * pow(fact_n_k, mod - 2, mod)) % mod

for i in range(1, K + 1):
	res = comb_mod(N - K + 1, i, MOD) * comb_mod(K - 1, i - 1, MOD)
	res %= MOD
	print(res)

Measured memory_bytes: 43760
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

struct Edge {
  int to, id;
  Edge(int t, int i): to(t), id(i) {};
};

vector<vector<Edge>> to;
vector<int> es;
bool dfs(int now, int prev, int last) {
  if (now == last) {
    es.clear();
    return true;
  }
  for (auto e : to[now]) {
    if (e.to == prev)
      continue;
    if (dfs(e.to, now, last)) {
      es.push_back(e.id);
      return true;
    }
  }
  return false;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  to.resize(n);
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    to[a].emplace_back(b, i);
    to[b].emplace_back(a, i);
  }
  int m;
  cin >> m;
  vector<ll> eset(m);
  rep(i, m) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    dfs(u, -1, v);
    for (auto e : es)
      eset[i] |= 1LL<<e;
  }
  ll ans = 0;
  rep(i, 1<<m) {
    ll mask = 0;
    rep(j, m) {
      if (i>>j&1)
        mask |= eset[j];
    }
    int rem = n-1-__builtin_popcountll(mask);
    if (__builtin_popcount(i)%2)
      ans -= 1LL<<rem;
    else
      ans += 1LL<<rem;
  }
  cout << ans << endl;
  return 0;
}

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

int calc(char x) {
  string w = s;
  int ct = 0;
  while (1) {
    bool flag = true;
    for(auto c: w) {
      if (c != x) {
        flag = false;
        break;
      }
    }

    if (flag) break;
    for (int i = 0; i + 1 < w.size(); ++i) {
      if (w[i] == x || w[i + 1] == x) w[i] = x;
    }
    w.pop_back();
    ct++;
  }

  return ct;
}
int main() {
  cin >> s;
  int ret = INT_MAX;
  for (char x = 'a'; x <= 'z'; ++x) {
    ret = min(ret, calc(x));
  }

  cout << ret << endl;
}

Measured memory_bytes: 256
N, M = map(int, raw_input().split())
A = [raw_input() for _ in range(N)]
B = [raw_input() for _ in range(M)]


def check(i, j):
    for k in range(M):
        if A[i+k][j:j+M] != B[k]:
            return False
    return True


for i in range(N-M+1):
    for j in range(N-M+1):
        if check(i, j):
            print "Yes"
            exit()
print "No"


Measured memory_bytes: 2568
#include<iostream>
#include<map>
using namespace std;
map<char, int> s;
int main()
{
	string s1;
	while(cin>>s1)
	{
		int flag = 0;
		for(int i = 0; i < s1.size(); i++)
		{
			if(s.count(s1[i]) == 1)
			{
				flag  = 1; 
				cout<<"no"<<endl;
				break;
			}
			else
				s[s1[i]] = 0;
		}
		if(flag)
			continue;
		cout<<"yes"<<endl;
	}
	return 0;
}

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

using namespace std;

double speed_limit(int cond_j, double time, int* t, int* v) {
  if (time < t[cond_j-1]) {
    return v[cond_j] + t[cond_j-1] - time;
  } else if (time < t[cond_j]) {
    return v[cond_j];
  } else {
    return v[cond_j] + time - t[cond_j];
  }
}

int main() {
  int i, j;
  int N;
  int t[210] = {};
  int v[110] = {};
  cin >> N;
  for (i = 1; i < N+1; i++) {
    cin >> t[i];
    t[i] = t[i-1]+t[i];
  }
  for (i = 1; i < N+1; i++) {
    cin >> v[i];
  }
  double velocity[80010] = {};
  for (i = 1; i < 2*t[N]; i++) {
    velocity[i] = min(i*0.5, t[N] - i*0.5);
    for (j = 0; j < N+1; j++) {
      velocity[i] = min(velocity[i], speed_limit(j, i*0.5, t, v));
    }
  }
  //for (i = 0; i < 2*t[N]; i++) {
  //  cout << velocity[i] << endl;
  //}
  double ans = 0;
  for (i = 0; i < 2*t[N]; i++) {
    ans += velocity[i];
  }
  ans = ans/2;
  cout << setprecision(17) << ans << endl;
  return 0;
}
  


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

int main() {
	int n, w[101];
	cin >> n;

	w[0] = 0;
	for (int i = 1; i <= n; i++) {
		cin >> w[i];
		w[i] += w[i - 1];
	}

	int res = 114514810;
	for (int i = 1; i < n; i++) {
		int tmp = abs((w[n] - w[i]) - (w[i] - w[0]));
		if (0 <= tmp) {
			res = min(res, tmp);
		}
	}

	cout << res << endl;



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) (a).begin(),(a).end()
#define ms(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10) 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge{ int from, to, cost; };

int n, m;
int c[20]; int x[20005];
int memo[20005][300];

int dp(int y, int i)
{
	if (i == n) return 0;
	if (memo[i][y] != INF) return memo[i][y];
	int res = INF;
	REP(j, m)
	{
		int tmp = y;
		tmp += c[j];
		if (tmp > 255) tmp = 255;
		if (tmp < 0) tmp = 0;
		res = min(res, dp(tmp,i+1)+(tmp-x[i])*(tmp-x[i]));
	}
	return memo[i][y] = res;
}

int main()
{
	while (cin >> n >> m, n)
	{
		REP(i, 20005)REP(j, 300) memo[i][j] = INF;
		REP(i, m) cin >> c[i];
		REP(i, n) cin >> x[i];
		cout << dp(128, 0) << endl;
	}
	return 0;
}

Measured memory_bytes: 26236
N = int(input())
alist = list(map(int, input().split()))
k = 1
if 0 in alist:
    print(0)
else:
    for i in range(0,N):
        k = k*alist[i]
        if k > 1000000000000000000:
            k= -1
            break
    print(k)

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

using namespace std;

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

#define chmax(a,x) a=max(a,x)

vector<bool> F[5];

bool eraser(int idx) {
  
  rep(i, 5) {
    if((int)F[i].size() <= idx) { return false; }
    if(!F[i][idx]) { return false; }
  }
  
  rep(i, 5)
    F[i].erase(F[i].begin()+idx);
  
  rep(i, 5) {
    while(1) {
      if(!F[i].empty() && !F[i].back()) { F[i].pop_back(); }
      else { break; }
    }
  }
  
  return true;
}

int main() {
  
  for(int N; cin>>N && N;) {
    rep(i, 5) F[i].clear();
    rep(i, N) {
      int type, len, pos; cin >> type >> len >> pos; pos --;
      if(type == 1) {
	int mx = -1;
	REP(i, pos, pos+len) { chmax(mx, int(F[i].size())); }
	REP(i, pos, pos+len) {
	  REP(j, F[i].size(), mx) {
	    F[i].push_back(false);
	  }
	  F[i].push_back(true);
	}
	eraser(mx);
      }
      else {
	rep(i, len) { F[pos].push_back(true); }
	int cnt = 0;
	rep(i, len) { if(!eraser((int)F[pos].size()-1-cnt)) cnt++; }
      }
    }
    int sum = 0;
    rep(i, 5) rep(j, F[i].size()) sum += F[i][j];
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
N = int(input())
B = [int(i) for i in input().split()]

A=[]

A.append(B[0])
A.append(B[0])

for i in range(1,N-1):
  A.append(B[i])
  if A[i] > B[i]:
    A[i] = B[i]

print(sum(A))

Measured memory_bytes: 3064
N = int(input())
if 0<=N and N<= 9:
  print(N)
elif 10<=N and N<=99:
  print(9)
elif 100<=N and N<=999:
  print(9+N-99)
elif 1000<=N and N<=9999:
  print(909)
elif 10000<=N and N<=99999:
  print(909+N-9999)
else:
  print(90909)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n;
void dfs(string s, char mx) {
  if (s.size() == n) {
    cout << s << endl;
    return;
  }
  for (char c = 'a'; c <= mx+1; c++) {
    string t = s;
    t += c;
    dfs(t, max(mx, c));
  }
}

int main () {
  cin >> n;
  dfs("",'a'-1);
  return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int ans=0;
  int h,w;
  cin>>h>>w;
  if(h==1 || w==1) cout<<1<<endl;
  
  else cout<<((h*w)+1)/2<<endl;

  return 0;
}


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

int main(){
  string s;
  cin >> s;
  
  for(int i = 0;i < s.size();i++){
  if(s.at(i) == ','){
  s.at(i) = ' ';
  }
  cout << s.at(i);
  }

  cout << endl;
  
}

Measured memory_bytes: 256
import math
from functools import reduce
from collections import defaultdict


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_max = max(A)

    is_pairwise_coprime = True

    D = [-1] * (A_max + 1)
    for i in range(2, A_max + 1):
        if D[i] == -1:
            D[i] = i
            for j in range(i*i, A_max+1, i):
                D[j] = i

    def factorization(n):
        # assert 0 < n <= A_max
        primes_ = defaultdict(int)
        temp = n
        while temp > 1:
            primes_[D[temp]] += 1
            temp = temp // D[temp]

        return primes_

    P = [False]*(A_max+1)

    # primes = set({})
    for i in range(N):
        for p in factorization(A[i]).keys():
            # if p in primes:
            if P[p]:
                is_pairwise_coprime = False
                break
            else:
                # primes.add(p)
                P[p] = True

    gcd_ = reduce(math.gcd, A)

    if is_pairwise_coprime:
        print('pairwise coprime')
    elif gcd_ == 1:
        print('setwise coprime')
    else:
        print('not coprime')


if __name__ == '__main__':
    main()


Measured memory_bytes: 202412
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 110;

int n;
int cnt[26];
char s[3][N];

int main() {


  scanf("%d", &n);
  for (int i = 0; i < 3; ++i)
    scanf("%s", s[i]);
  int ans = 0;
  for (int j = 0; j < n; ++j) {
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < 3; ++i)
      ++cnt[s[i][j] - 'a'];
    ans += 3 - *max_element(cnt, cnt + 26);
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double N = sc.nextInt();
		double a = 0;
		if(N==1) {
			a = 1;
		}else if(N%2==0) {
			a = 0.5;
		}else {
			double b = (N+1)/2;
			a = b/N;
		}
		System.out.println(a);
	}

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#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 << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 1000002
mt19937 myrand(time(0));

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    ll x,k,d;
    cin>>x>>k>>d;
    if(x<0){
        ll cnt=abs(x)/d;
        if(cnt>=k){
            x+=(k*d);
            cout<<abs(x)<<endl;
        }
        else{
            x+=(cnt*d);
            k-=cnt;
            ll y=x+d;
            if(k%2==0) cout<<abs(x)<<endl;
            else cout<<y<<endl;
        }
    }
    else if(x>0){
        ll cnt=x/d;
        if(cnt>=k){
            x-=(k*d);
            cout<<x<<endl;
        }
        else{
            x-=(cnt*d);
            k-=cnt;
            ll y=x-d;
            if(k%2==0) cout<<x<<endl;
            else cout<<abs(y)<<endl;
        }
    }
    else{
        if(k&1) cout<<d<<endl;
        else cout<<0<<endl;
    }
    return 0;
}


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

const int mod = 1000000007;
int N, M;
int dp[3002][3002][2];

int main() {
    scanf("%d %d", &N, &M);
    N--;
    M--;

    for(int m = 0; m <= M; m++) {
        for(int r = 0; r <= N; r++) {
            for(int z = 0; z < 2; z++) {
                if(m == 0) {
                    dp[m][r][z] = z | (r == 0);
                    continue;
                }
                dp[m][r][z] = 2 * dp[m - 1][r][ z | (r == 0) ] % mod;
                if(r != 0) dp[m][r][z] = (dp[m][r][z] + dp[m - 1][r - 1][ z | (r == 0) ]) % mod;
                if(r != N) dp[m][r][z] = (dp[m][r][z] + dp[m - 1][r + 1][ z | (r == 0) ]) % mod;
            }
        }
    }

    int ans = 0;
    for(int i = 0; i <= N; i++) {
        ans += dp[M][i][0];
        ans %= mod;
    }
    ans = 4LL * ans % mod;
    printf("%d", ans);
}


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

using namespace std;

#define int long long
#define vi vector <int>
#define all(v) v.begin(), v.end()
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define forn(i, from, n) for (int i = (int)(from); i < (int)(n); ++i)

const int INF = 1e9 + 9;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

#ifdef LOCAL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    int n, k;
    cin >> n >> k;
    vi v(n);
    forn(i, 0, n)
        cin >> v[i];
    vi dp(n, INF);
    dp[0] = 0;
    forn(i, 1, n){
        forn(j, max(0ll, i - k), i)
            dp[i] = min(dp[i], dp[j] + abs(v[j] - v[i]));
    }
    cout << dp[n - 1];
    return 0;
}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

using ll = long long;
using ull = unsigned long long;
using veci = vector<int>;
using vecll = vector<ll>;
using vecull = vector<ull>;

// エラトステネスの篩によって素数表を作成する。
// O(n * log log N)
template<class T> inline vector<bool> eratos(T n) {
    vector<bool> isprime(n);
    for(int i = 0; i < n; ++i) {
        isprime[i] = true;
    }

    isprime[0] = isprime[1] = false;

    long double nsqrt = sqrtl(n);
    for (ull i = 2; i < nsqrt; ++i) {
        if (isprime[i]) {
            ull j = i + i;
            while (j <= n) {
                isprime[j] = false;
                j += i;
            }
        }
    }

    return isprime;
}

int Q;

int main(void) {

    vector<bool> isPrime = eratos(100000);
    vecll total(100000, 0);



    for(int i = 3; i < 100000; i += 2) {
        total[i] = total[i - 2];
        
        if (isPrime[i] && isPrime[(i + 1) / 2]) total[i]++;
    }

    cin >> Q;
    
    rep(i, Q) {
        int l, r;
        cin >> l >> r;

        cout << total[r] - total[max(0, l - 2)] << endl;

    }


    return 0;
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {

    protected static String process(String data) {
        StringBuilder sb = new StringBuilder();
        final String[] lines = splitForLines(data);

        for (String line : lines) {
            final int[] split = split(line);
            int n = split[0];
            int x = split[1];

            if (n == 0 && x == 0) {
                break;
            }

            sb.append(howManyWays(n, x)).append('\n');
        }

        return sb.toString();
    }

    static int howManyWays(int n, int x) {
        int count = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                for (int k = 1; k <= n; k++) {
                    if (i >= j || j >= k || i >= k) {
                        continue;
                    }
                    if ((i + j + k) != x) {
                        continue;
                    }
                    count++;
                }
            }
        }
        return count;
    }

    private static String readAll(InputStream is) {
        InputStreamReader r = null;
        BufferedReader br = null;

        try {
            r = new InputStreamReader(is);
            br = new BufferedReader(r);
            StringBuilder sb = new StringBuilder();
            String s;

            while ((s = br.readLine()) != null) {
                sb.append(s).append('\n');
            }

            return sb.toString();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                }
            }
            if (r != null) {
                try {
                    r.close();
                } catch (IOException e) {
                }
            }
        }
    }

    private static String[] splitForLines(String lines) {
        return lines.split("\\n");
    }

    private static int[] split(String s) {
        final String[] s0 = s.split(" ");
        int[] ia = new int[s0.length];

        for (int i = 0; i < s0.length; i++) {
            ia[i] = Integer.parseInt(s0[i]);
        }

        return ia;
    }

    public static void main(String[] args) {
        System.out.print(process(readAll(System.in)));
    }
}

Measured memory_bytes: 18596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			int t = sc.nextInt();
			int l = sc.nextInt();
			int b = sc.nextInt();
			if (n == 0) {
				break;
			}
			boolean[] lose = new boolean[n+1];
			boolean[] back = new boolean[n+1];
			for(int i=0;i<l;i++) {
				lose[sc.nextInt()] = true;
			}
			for(int i=0;i<b;i++) {
				back[sc.nextInt()] = true;
			}
			double[][] dp = new double[t+1][n+1];
			dp[0][0] = 1;
			for(int i=0;i<t;i++) {
				for(int j=0;j<n;j++) {
					for(int k=1;k<=6;k++) {
						int next = j + k;
						if (next > n) {
							next = n - (next - n);
						}
						if (lose[next]) {
							if (i < t - 1) {
								dp[i+2][next] += dp[i][j] / 6;
							}
						}else if(back[next]) {
							dp[i+1][0] += dp[i][j] / 6;
						}else{
							dp[i+1][next] += dp[i][j] / 6;
						}
					}
				}
			}
			double sum = 0;
			for(int i=0;i<=t;i++) {
				sum += dp[i][n];
			}
			System.out.printf("%.7f\n",sum);
		}
	}

}

Measured memory_bytes: 29792
n,m = map(int,input().split())
XYZ = [list(map(int,input().split())) for _ in range(n)]

ans = []
for i in range(8):
    temp = format(i,"03b")
    a,b,c = temp
    X = -1 if a =="0" else 1
    Y = -1 if b =="0" else 1
    Z = -1 if c =="0" else 1
    
    testcase = []
    for x,y,z in XYZ:
        testcase.append(x*X+y*Y+z*Z)
    testcase.sort(reverse = True)
    ans.append(sum(testcase[:m]))
print(max(ans))


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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double EPS = 1e-8, INF = 1e12, PI = acos(-1.0);
typedef complex<double> P;
namespace std{
	bool operator<(const P& a, const P& b){
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
inline double cross(const P& a, const P& b){ return imag(conj(a)*b); }
inline double dot(const P& a, const P& b){ return real(conj(a)*b); }
struct L : public vector<P>{
	L(const P &a, const P &b) {
		push_back(a); push_back(b);
	}
};
typedef vector<P> G;

inline int ccw(P a, P b, P c) {
	b -= a; c -= a;
	if(cross(b, c) > 0)   return +1;		// counter clockwise
	if(cross(b, c) < 0)   return -1;		// clockwise
	if(dot(b, c) < 0)     return +2;		// c--a--b on line
	if(norm(b) < norm(c)) return -2;		// a--b--c on line
	return 0;
}

int n, x[8], y[8];
vector<pi> t[8][8];
map<vi, int> dp;

int root(vi &p, int x){
	return x == p[x] ? x : p[x] = root(p, p[x]);
}

int rec(vi v){
	if(dp.count(v)) return dp[v];
	
	int &res = dp[v];
	int fin = 0;
	rep(i, n) fin = max(fin, v[i]);
	if(fin == 0) return 0;
	
	res = inf;
	rep(i, n) rep(j, i){
		vi uf, to(n, -1);
		rep(k, fin + 1) uf.pb(k);
		
		for(pi p : t[i][j]){
			int a = root(uf, v[p.first]), b = root(uf, v[p.second]);
			if(a != b) uf[b] = a;
		}
		int sz = 0;
		rep(k, n) if(to[root(uf, v[k])] < 0) to[root(uf, v[k])] = sz++;
		
		vi nxt;
		rep(k, n) nxt.pb(to[root(uf, v[k])]);
		
		if(v != nxt) res = min(res, rec(nxt) + 1);
	}
	return res;
}
int main(){
	cin >> n;
	rep(i, n) cin >> x[i] >> y[i];
	rep(i, n) rep(j, i){
		P p((x[i] + x[j]) / 2.0, (y[i] + y[j]) / 2.0), q(x[j] - x[i], y[j] - y[i]);
		q *= P(0, 1);
		t[i][j].pb(mp(i, j));
		rep(k, n) rep(l, k) if(k != i || l != j){
			P r((x[k] + x[l]) / 2.0, (y[k] + y[l]) / 2.0), s(x[l] - x[k], y[l] - y[k]);
			s *= P(0, 1);
			if(abs(cross(q, s)) < EPS && abs(cross(p - r, q)) < EPS){
				
				t[i][j].pb(mp(k, l));
			}
		}
	}
	vi init;
	rep(i, n) init.pb(i);
	cout << rec(init) << endl;
	return 0;
}

Measured memory_bytes: 3660
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		br.close();
		
//		for(int i=1;i<n+1;i++) {
		long result = (long)n*(n-1)/2;
		System.out.println(result);				
//		}

	}

}


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

int main() {
    string c1, c2;
    cin >> c1;
    cin >> c2;
    if (c1[1] == c2[1] && c1[0] == c2[2] && c1[2] == c2[0]){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


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

double dp[3003][3003];

void solve(){
   int n; cin >> n;
   double data[n+5], ans = 0;
   for(int i = 1; i <= n; i++) cin >> data[i];
   
   dp[0][0] = 1;
   for(int i = 1; i <= n; i++){
      dp[i][0] = dp[i-1][0]*(1.0-data[i]);
      for(int j = 1; j <= n; j++){
         dp[i][j] = dp[i-1][j-1]*data[i] + dp[i-1][j]*(1-data[i]);
      }
   }
   
   for(int i = 1; i <= n; i++) {
      if(2*i < n) continue;
        ans += dp[n][i];
   }
   cout << setprecision(12) <<  ans << '\n';

}

signed main(){

  int t = 1; //cin >> t;
  while(t--){      
     solve();
  }

  //cout << "Time-Taken: " << ((t2 - t1) / (double)CLOCKS_PER_SEC) << endl;      
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main()
{
  int n, d;
  cin >> n >> d;
  d = 2*d+1;
  cout << (n-1)/d+1 << endl;
  return 0;
}

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

int main() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int flag = 0;
	while(1) {
		if(flag==0) {
			c-=b;
			if(c<=0) {
				cout<<"Yes";
				return 0;	
			}
			flag = 1;
		}
		else{
			a-=d;
			if(a<=0) { 
				cout<<"No";
				return 0;
			}
			flag = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int a [] = new int [n];

		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int ans = 0;

        for (int i = 0; i < n; i++){
            ans = ans + a[i];
        }

		System.out.println(ans-n);


		sc.close();
	}

}


Measured memory_bytes: 24676
#include <cmath>
#include <iostream>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

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

const int MIN = 200001;
const int MOD = 1000000007;
const long long MAX = 1e15 + 9;

using namespace std;

template <class T>
T even(T n)
{
	return !(n % 2);
}
template <class T>
T div_three(T n)
{
	return !(n % 3);
}
template <class T>
T div_five(T n)
{
	return !(n % 5);
}

int main() {
	int a, p;
	
	cin >> a >> p;
	
	cout << ((a * 3 + p) / 2) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2e9


int main()
{
    lli n,m,k;
    cin >> n >> m >> k;
    vector<lli>v1(n),v2(m);
    for(lli i=0;i<n;i++)
        cin >> v1[i];
    for(lli i=0;i<m;i++)
        cin >> v2[i];
    vector<lli>v3(n),v4(m);
    lli temp=0;
    for(lli i=0;i<n;i++)
    {
        temp+=v1[i];
        v3[i]=temp;
    }
    temp=0;
    for(lli i=0;i<m;i++)
    {
        temp+=v2[i];
        v4[i]=temp;
    }
    lli ans=0;
    lli p=0;
    for(lli i=0;i<n;i++)
    {
        p+=v1[i];
        if(p>k)
            break;
        lli rem=k-p;
        lli ind=lower_bound(v4.begin(),v4.end(),rem+1)-v4.begin();
        ans=max(ans,i+1+ind);
    }
    p=0;
    for(lli i=0;i<m;i++)
    {
        p+=v2[i];
        if(p>k)
            break;
        lli rem=k-p;
        lli ind=lower_bound(v3.begin(),v3.end(),rem+1)-v3.begin();
        ans=max(ans,i+1+ind);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9592
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

const int INF=1<<25;

int n;
int m[15][15];
int dp[15][1<<15];

int rec(int s,int v)
{
	if(dp[v][s]>=0)return dp[v][s];
	else if(s==(1<<n)-1&&v==0)return dp[v][s]=0;
	
	int res=INF;
	for(int u=0;u<n;u++)
	{
		if(!(s>>u&1)&&m[v][u]!=INF)res=min(res,rec(s|1<<u,u)+m[v][u]);
	}
	return dp[v][s]=res;
}

int main()
{
	int e,s,t,d;cin>>n>>e;
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)m[i][j]=INF;
	for(int i=0;i<e;i++)
	{
		cin>>s>>t>>d;
		m[s][t]=d;
	}
	
	memset(dp,-1,sizeof(dp));
	int ans=rec(0,0);
	if(ans!=INF)cout<<rec(0,0)<<endl;
	else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 5008