akhauriyash/Code-Regression huggingface dataset:
def main():
    abcd = list(input())
    flag = False
    for op1 in ['+', '-']:
        for op2 in ['+', '-']:
            for op3 in ['+', '-']:
                ans = abcd[0]+op1+abcd[1]+op2+abcd[2]+op3+abcd[3]
                if eval(ans) == 7:
                    flag = True
                    print(ans+'=7')
                    break
            if flag:
                break
        if flag:
            break

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
	int i, j, N, K, d, A, count[101] = {};
	scanf("%d %d", &N, &K);
	for (i = 1; i <= K; i++) {
		scanf("%d", &d);
		for (j = 1; j <= d; j++) {
			scanf("%d", &A);
			count[A]++;
		}
	}
	
	int ans = 0;
	for (i = 1; i <= N; i++) if (count[i] == 0) ans++;
	printf("%d\n", ans);	
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1732
/* � Ashiq Uddin Pranto
   Department of Computer Science and Engineering
   BATCH 27
   University Of Rajshahi,Bangladesh
*/
#include<bits/stdc++.h>

#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define matrix(x) vector<vector<x>>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a)   scanf("%d",&a)
#define sfl(a)  scanf("%lld",&a)
#define sff(a,b)    scanf("%d %d",&a,&b)
#define sffl(a,b)   scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff  first
#define ss  second
#define lcm(a, b)   ((a)*((b)/__gcd(a,b)))
#define all(a)  a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 1000000007
#define MOD(a,b) (a%b + b)%b

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


int main()
{
    //fastio
    ll n;
    sfl(n);
    vll a(n+5,0),sum(n+5,0);
    ll ans = 0;
    for(ll i=1;i<=n;i++)
    {
        sfl(a[i]);
        sum[i]=a[i];
        sum[i] = (sum[i]+sum[i-1])%mod;
        //sum[i]+=sum[i-1];
    }
    for(ll i=2;i<=n;i++)
    {
        ans+=((a[i]%mod)*(sum[i-1]%mod))%mod;
        ans = ans%mod;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 6436
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
mii=lambda:map(int,input().split())

n=int(input())

pos=[]
neg=[]
z=0

for i in mii():
    if i>=0: pos.append(i)
    else: neg.append(i)

if not pos:
    x=max(neg)
    neg.remove(x)
    pos.append(x)
if not neg:
    x=min(pos)
    pos.remove(x)
    neg.append(x)

merge=[]
while len(pos)>1:
    merge.append((neg[0],pos[-1]))
    neg[0]-=pos.pop(-1)
while len(neg)>0:
    merge.append((pos[0],neg[-1]))
    pos[0]-=neg.pop(-1)

print(pos[0])
for i,j in merge:
    print("%d %d"%(i,j))








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

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

  int bekijo[X+1];
  int tmp;
  int i, j;
  for(i=0; i<=X; i++) {
    bekijo[i] = 0;
  }
  bekijo[1] = 1;
  /* べき乗をリスト生成 */
  for(i=2; i<=X; i++) {
    if(bekijo[i]==1) {
      continue;
    }
    for(j=2; tmp=pow(i,j), tmp<=X; j++) {
      if(bekijo[tmp]==0) {
        bekijo[tmp] = 1;
      }
    }
  }

  for(i=X; 0<i; i--) {
    if(bekijo[i]==1) {
      cout << i <<  endl;
      break;
    }
  }

  return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n,wmax,vmax(100010); cin >> n >> wmax;  
  vector<int> w(n),v(n);
  for(int i = 0; i < n; ++i)cin >> w[i] >> v[i];
  vector<vector<ll>> dp(1+n,vector<ll>(vmax,100100100100100100));
  dp[0][0] = 0;
  for(int i = 1; i < n+1; ++i){
    for(int j = 0; j < vmax; ++j){
      if(j < v[i-1]) dp[i][j] = dp[i-1][j];
      else dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i-1]]+w[i-1]);
    }
  }
  ll ans = 0;
  for(int i = 0; i < vmax; ++i)if(dp[n][i]<=wmax)ChangeMax(ans,(ll)i);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 80256
#include <iostream>

using namespace std;

int main(){
  int N;
  std::string s;
  cin >> N >> s;
  int r_num=0;
  for(int i = 0;i<N; i++){
    if(s[i] == 'R'){
      r_num++;
    }
  }
  if(r_num > N-r_num){
    std::cout << "Yes" << std::endl;
  }
  else{
    std::cout << "No" << std::endl;
  }

  return 0;
}


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

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

int main() {
  // std::cout<<std::fixed<<std::setprecision(10);
  int a,b;cin>>a>>b;
  int ans = max(max(a+b, a*b),a-b);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	//"sort"
	"math"
	"regexp"

)
func abs(x int)int{
	return int(math.Abs(float64(x)))
}

func max(x...int) int{
	var res int = x[0]
	for i:=1;i<len(x);i++{
		res = int(math.Min(float64(res),float64(x[i])))
	}
	return res
}

type Sortby []int
func (a Sortby) Len()int {return len(a)}
func (a Sortby) Swap(i,j int) {a[i],a[j] = a[j],a[i]}
func (a Sortby) Less(i,j int)bool { return abs(a[i]) > abs(a[j]) }


func reg(x,y string)bool {
	r:= regexp.MustCompile(x)
	return r.MatchString(y)
}

var N int
func main(){
	fmt.Scan(&N)

	L := make([]int,N+1)
	L[0] = 2
	L[1] = 1
	for i:=2;i<=N;i++{
		L[i] = L[i-1] + L[i-2]
	}
	fmt.Println(L[N])
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    vector<string> v(n);rep(i,n)cin >> v[i];
    ll res=0,a=0,b=0,c=0;
    rep(i,n){
        rep(j,v[i].size()-1){
            if(v[i][j]=='A'&&v[i][j+1]=='B')res++;
        }
        if(*v[i].rbegin()=='A'&&v[i][0]=='B')c++;
        else if(*v[i].rbegin()=='A')a++;
        else if(v[i][0]=='B')b++;
    }
    if(c){
        res+=c-1;
        if(a>0)a--,res++;
        if(b>0)b--,res++;
    }
    cout << res+min(a,b) <<endl;
}

Measured memory_bytes: 3716
import sys
import math

N = 1000000
primes = [1] * N
primes[0] = 0
primes[1] = 0
primes[4::2] = [0] * len(primes[4::2])

for i in range(3,int(math.sqrt(N)),2):
    if primes[i]:
        primes[i*i::i*2] = [0] * len(primes[i*i::i*2])

for i in sys.stdin:
        n = int(i)
        print(sum(primes[0:n+1]))

Measured memory_bytes: 26348
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
const ll INF = 1e15;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int MAX = 510000;
const int MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
vector<ll> p, c, s;
ll sum, cnt, ans = -INF, imax,k;
int main(void) {
    int n; ll k; cin >> n >> k; p.resize(n), c.resize(n);
    rep(i, n) cin >> p[i], p[i]--;
    rep(i, n) cin >> c[i];
    rep(i, n) {
        sum = 0;
        int now = p[i];
        while (i != now) {
            sum += c[now];
            s.push_back(sum);
            now = p[now];
        }sum += c[i]; s.push_back(sum);
        if (k <= s.size()) chmax(ans, *max_element(s.begin(), s.begin() + k));
        else if (sum <= 0) chmax(ans, *max_element(ALL(s)));
        else {
            ll ans1 = sum * ((k / s.size()) - 1);
            ans1 += *max_element(ALL(s));
            ll ans2 = sum * (k / s.size()),r = k %s.size();
            if (r != 0) {
                ans2 += max(0LL, *max_element(s.begin(), s.begin() + r));
            }chmax(ans, max(ans1, ans2));
        }s.clear();
    }cout << ans << endl;
}

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

#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<numeric>
using namespace std;

template<class T>
auto comp_idx(T* ptr){
  return [ptr](int l_idx, int r_idx){
    return ptr[l_idx] < ptr[r_idx];
  };
}
int main() {
	int n;cin>>n;
	vector<string> s(n);
	vector<int> p(n);
	map<string,vector<pair<int,int>>> m;
	vector<string> ss;
	for(int i=0;i<n;i++){
		cin>>s[i]>>p[i];
		if(m.count(s[i])){
			m[s[i]].push_back(make_pair(p[i],i));
		}else{
			vector<pair<int,int>> v;
			v.push_back(make_pair(p[i],i));
			m[s[i]]=v;
			ss.push_back(s[i]);
		}
	}
	vector<int> idx(ss.size());
	for(int i=0;i<ss.size();i++){
		idx[i]=i;
	}
	sort(idx.begin(), idx.end(), [&ss](size_t i1, size_t i2) {
	        return ss[i1] < ss[i2];
	    });
	for(auto x:idx){
		auto tempv=m[ss[x]];
		vector<int> idx2(tempv.size());
		iota(idx2.begin(),idx2.end(),0);
		sort(idx2.begin(), idx2.end(), [&tempv](size_t i1, size_t i2) {
			        return tempv[i1] > tempv[i2];
			    });
		for(auto y:idx2){
			cout<<tempv[y].second+1<<endl;
		}

	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using std::cout;
using std::endl;
using std::cin;

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) {
			break;
		}
		int sa = 0,sb = 0;
		while (n--) {
			int a,b;
			cin >> a >> b;
			if (a > b) {
				sa += a + b;
			} else if (a < b) {
				sb += a + b;
			} else {
				sa += a;
				sb += b;
			}
		}
		cout << sa << " " << sb << endl;
	}
}

Measured memory_bytes: 2976
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

vector<pair<Int, pair<Int, Int> > > V; //<time, query(0=del,1=insert,2=calc), val   
int N, Q;

int main(void) {
    cin>>N>>Q;
    for(int i = 0;i < N;i++) {
        Int s,t,x;
        cin>>s>>t>>x;
        V.push_back(make_pair(s-x,make_pair(1, x)));
        V.push_back(make_pair(t-x,make_pair(0, x)));
    }

    for(int i = 0;i < Q;i++) {
        Int d;
        cin>>d;
        V.push_back(make_pair(d, make_pair(2, i)));
    }
    sort(V.begin(),V.end());

    vector<Int> ans(Q);
    multiset<Int> se;

    for(auto p: V) {
        Int query = p.second.first;
        Int val = p.second.second;
        if(query == 1)
            se.insert(val);
        else if(query == 0)
            se.erase(se.lower_bound(val));
        else {
            ans[val] = se.empty() ? -1 : *se.begin();
        }
    }

    for (auto v: ans)
        cout<<v<<endl;

    return 0;
}


Measured memory_bytes: 26724
#include<cstdio>
using namespace std;
int main(){
    int a,b;
    
    while(true){
        scanf("%d%d",&a,&b);
        if(a==0&&b==0)
            break;
        if(a>b)
            printf("%d %d\n",b,a);
        else
            printf("%d %d\n",a,b);
    }
    return 0;
}



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

int main() {
  int N; cin >> N;
  while(N--) {
    int y, m, d;
    cin >> y >> m >> d;
    int ans = 0;
    while(true) {
      if(y == 1000 && m == 1 && d == 1) break;
      if(y % 3 == 0) {
        if(d == 20) {
          m += 1;
          d = 1;
        }
        else {
          d += 1;
        }
      }
      else {
        if(m % 2 == 1) {
          if(d == 20) {
            m += 1;
            d = 1;
          }
          else {
            d += 1;
          }
        }
        else {
          if(d == 19) {
            m += 1;
            d = 1;
          }
          else {
            d += 1;
          }
        }
      }
      if(m == 11) {
        m = 1;
        y += 1;
      }
      ans++;
    }
    cout << ans << endl;
  }
}

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

int main(){
	int n; cin >> n;
	int h[100000]; for (int i = 0; i < n; i++) cin >> h[i];

	h[0]--;
	for (int i = 1; i < n; i++) {
		if (h[i - 1] > h[i]) {
			cout << "No" << endl; return 0;
		}
		if (h[i - 1] < h[i]) {
			h[i]--;
		}
	}

	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,a,b;
  cin>>n>>a>>b;
  cout<<min(a*n,b);
  return 0;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a=0,b=0,c,sb=1,f=0;
	char ch;
	ch=getchar();
	while(isdigit(ch))
	{
		a=a*10+(ch-48);
		ch=getchar();
	}
	while(!isdigit(ch))
	{
		ch=getchar();
	}
	while(isdigit(ch))
	{
		sb*=10;
		b=b*10+(ch-48);
		ch=getchar();
	}
	c=a*sb+b;
	for(int i=1;i<=320;i++)
	{
		if(i*i==c)
		{
			f=1;
		}
	}
	if(f)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	bool teisyutu[31];
	int in;

	for(int i = 0; i < 31; i++){
		teisyutu[i] = false;
	}
	teisyutu[0] = true;
	
	for(int i = 0; i < 28; i++){
		scanf("%d",&in);
		teisyutu[in] = true;
	}
	for(int i = 0; i <= 30; i++){
		if(!teisyutu[i]){
			printf("%d\n",i);
		}
	}

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <limits>
using namespace std;

int main(){
    string s;
    cin >> s;
    string ans;
    for(size_t i = 0; i < s.size(); i++)
    {
        if(s[i] == 'B'){
            if(i == 0) continue;
            else if(ans.empty()) continue;
            else ans.erase(ans.size()-1);
        }
        else{
            ans += s[i];
        }
    }
    
    
    cout << ans << endl;
    return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
char ans;

int main() {
    //couto.precision(10);
    vector<int> digit(9);
    for(int i = 0; i < 9; i++) {
        int ok = -1;
        int ng = 9;
        if(i == 0) ok = 0;
        while(ng - ok > 1) {
            int mid = (ok + ng) / 2;
            cout << "? ";
            for(int j = 0; j < i; j++) cout << digit[j];
            cout << mid;
            for(int j = 0; j < 9; j++) cout << "9";
            cout << endl;
            cin >> ans;
            if(ans == 'Y') ng = mid;
            else ok = mid;
        }
        digit[i] = ok + 1;
    }
    digit.push_back(0);
    while(digit.back() == 0) {
        vector<int> sub;
        for(int i = 0; i < digit.size(); i++) sub.push_back(digit[i]);
        ll a = 0;
        ll b = 0;
        for(int i = 0; i < sub.size(); i++) {
            a *= 10;
            a += sub[i];
        }
        for(int i = 0; i + 1 < sub.size(); i++) {
            b *= 10;
            b += sub[i];
        }
        ll query = (a + b) / 2;
        cout << "? " << query << endl;
        cin >> ans;
        if((ans == 'N') ^ (to_string(query) <= to_string(b))) break;
        digit.pop_back();
    }
    cout << "! ";
    for(int i = 0; i < digit.size(); i++) cout << digit[i];
    cout << endl;
    return 0;
}


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

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

#define cauto const auto&
#else

#endif

using namespace std;


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;
typedef vector<vector<long long> > 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 GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

ll dp[55][2];

void mainmain(){
	int n;
	cin>>n;
	int P;
	cin>>P;
	vint cnt(2);
	dp[0][0] = 1;
	rep(i,n){
		int a;
		cin>>a;
		a %= 2;
		dp[i+1][0] = dp[i][0];		
		dp[i+1][1] = dp[i][1];		
		if(a){
			dp[i+1][0] += dp[i][1];
			dp[i+1][1] += dp[i][0];
		}
		else{
			dp[i+1][0] *= 2;
			dp[i+1][1] *= 2;
		}
	}
	cout<<dp[n][P]<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

vector<ll> G[200010];

int main() {
	ll N, u, v;
	cin >> N;
	for (int i = 1;i < N;i++) {
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	ll ans = 0, cnt = 0, d = 0;
	for (ll i = 1;i <= N;i++) {
		cnt = i;
		for (auto j : G[i]) {
			if (j < i) {
				cnt -= j;
			}
		}
		d += cnt;
		ans += d;
		cnt = 0;
	}
	cout << ans << endl;
}


Measured memory_bytes: 15840
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<62;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

int main(){
    int H, W, M; cin >> H >> W >> M;
    //vector<int> h(M), w(M);
    //rep(i,M) cin >> h[i] >> w[i];
    vector<int> hs(H), ws(W);
    set<pair<int,int>> s;
    rep(i,M){
        int h, w;
        cin >> h >> w;
        --h; --w;
        hs[h]++;
        ws[w]++;
        s.emplace(h,w);
    }

    // 縦と横の最大出現回数を取得
    int mh = 0;
    int mw = 0;
    rep(i,H) mh = max(mh, hs[i]);
    rep(i,W) mw = max(mw, ws[i]);

    // 最大の出現回数のインデックスを取得
    vector<int> h_indices, w_indices;
    rep(i,H) if (mh == hs[i]) h_indices.push_back(i);
    rep(i,W) if (mw == ws[i]) w_indices.push_back(i);
    // 暫定で最大値を答えに設定 
    int ans = mh+mw;
    for(auto h_index : h_indices){
        for (auto w_index : w_indices){
            if (s.count(make_pair(h_index, w_index))>0) continue;
            // 重複がなかった場合は暫定を最大値として出力
            cout << ans << endl;
            return 0;
        }
    }
    // 重複がない箇所がなかった場合は、最大値-1を出力
    cout << --ans << endl;
    
}

Measured memory_bytes: 23844
/* ABC138-A
   Takatan */

#include<stdio.h>
int main(void){
        int number;
    char string[11];

    scanf( "%d" , &number);
    scanf( "%s" , string);
    if(number>=3200){ /* 比較 */
        printf( "%s\n" , string);
    }else{
        printf( "red\n" );
    }
    return 0;
}

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

using namespace std;

void checkCard();

void checkCard(std::vector<int>& cardNum, std::string cardType)
{
	bool u;
	for(int i = 1; i <= 13; i++)
	{
		u = false;
		
		for(int j = 0; j < cardNum.size(); j++)
		{
			if( cardNum[j] == i )
			{
				u = true;
				break;
			}
		}
		
		if( u == false ) 
			std::cout << cardType << " " << i << std::endl;
	}
}

int main(void)
{
	int n;
	
	std::cin >> n;
	
	std::vector<int> S, H, C, D;
	
	int tmp;
	std::string str;
	for(int i = 0; i < n; i++)
	{
		std::cin >> str >> tmp;
		
		if( str == "S" ) S.push_back( tmp );
		if( str == "H" ) H.push_back( tmp );
		if( str == "C" ) C.push_back( tmp );
		if( str == "D" ) D.push_back( tmp );
	}
	
	checkCard(S, "S");
	checkCard(H, "H");
	checkCard(C, "C");
	checkCard(D, "D");
	
	return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
 
 
int main(){
    int l; cin >> l;
    double a=(double)l/3;
    double b=a*a;
    printf("%lf",a*b);
return 0;
}

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

int main(){
	
	int i, n, t, s1, s2, min = -1;
	
	scanf("%d", &n);
	
	int w[n];
	
	for(i = 0; i < n; i++)
		scanf("%d", &w[i]);
	
	for(t = 0; t < n - 1; t++){
		s1 = 0;
		s2 = 0;
		for(i = 0; i <= t; i++)
			s1 += w[i];
		for(i = t + 1; i < n; i++)
			s2 += w[i];
		
		if(min < 0)
			min = abs(s1 - s2);
		else if(abs(s1 - s2) < min)
			min = abs(s1 - s2);
	}
	
	
	printf("%d", min);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    for(int a=1; a<=3500; a++){
        for(int b=1; b<=3500; b++){
            int u=n*a*b;
            int d=4*a*b-n*a-n*b;
            if(d>1 && u%d==0){
                cout<<a<<' '<<b<<' '<<u/d<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3544
let () = Scanf.scanf "%d %d %d" @@ fun k a b ->
  Printf.printf "%d\n" @@ max (1 + k) @@
  if b <= a && k <= a - 1 then min_int
  else a + (k - a + 1) / 2 * (b - a) + (k - a + 1) mod 2


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

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

    int N; cin>>N;
    vector<int> H(N);
    for (auto& h : H) cin>>h;

    auto p = H.back();
    bool ans = true;
    bool used = false;
    for (int i = N-2; i >= 0; i--) {
        auto d = H[i] - p;
        if (not used) {
            if (d > 1) {
                ans = false;
                break;
            }
            used = d == 1;
        } else {
            if (d > 0) {
                ans = false;
                break;
            }
            used = d >= 0;
        }
        p = H[i];
    }
    cout << (ans ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 640
/*---------------Go Code GO---------------*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using Order_Set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
//(order) Set.order_of_key(); (pointer) Set.find_by_order();

#define     PI              acos(-1.0)
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define     precision(a)    fixed<<setprecision(a)
#define     endl            '\n'
#define     Flush           cout<<flush
#define     LLMX            0x3fffffffffffffff


long long K;
queue<long long> qu;

int main()
{
    O_O;
    long long i,j,k,l,tst=0,ans=0, csno=0;
    cin>>K;
    for(i=1; i<10; i++) qu.push(i);

    for(i=0; i<K; i++)
    {
        k=qu.front();
        l=k%10;
        if(l!=0) qu.push(k*10+l-1);
        qu.push(k*10+l);
        if(l!=9) qu.push(k*10+l+1);
        qu.pop();
    }
    cout<<k<<endl;

    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

typedef long long ll;
ll a, b, sum;

int main()
{
	while(cin >> a >> b)
	{
		sum = 0;
		sum = a + b;
		if(sum >= 10) cout << "error" << endl;
		else cout << sum << endl;
	}
	return 0;
}


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

//stoi,stoll

int main() {
    string S; cin>>S;
    ll totalsum =0;

    for(int tmp=0;tmp<(1<<(S.size()-1));tmp++){
        bitset<9>b(tmp);
        string ex={S[0]}; //このstringの使い方

        for(int i=0;i<S.size()-1;i++){
            if(b.test(i)){
                ex.push_back('+');
            }
            ex.push_back(S[i+1]);
        }

        string ss="";

        for(int i=0;i<ex.size();i++){
            if(ex[i]=='+'){
                ll num =stoll(ss);
                totalsum+=num;
                ss="";
            }
            else{
                ss.push_back(ex[i]);
            }
        }
        ll num =stoll(ss);
        totalsum+=num;
    }
    cout<<totalsum<<endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define NIL -1
using namespace std;
struct _Node {
	int parent;
	int left;
	int right;
};
_Node T[100001];
int main(void)
{
	ios::sync_with_stdio(false);
	string a;
	cin >> a;
	if ((a[0] == a[1] && a[1] == a[2]))
	{
		cout << "Yes" << "\n";
	}
	else if ((a[1] == a[2] && a[2] == a[3]))
	{
		cout << "Yes" << "\n";
	}
	else
	{
		cout << "No" << "\n";
	}
}

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

using namespace std;

int main() {
	string s;
	cin >> s;
	deque<char> dq(s.begin(), s.end());
	int q; cin >> q;
	int now = 0;
	while(q--) {
		int t; cin >> t;
		if(t == 1) {
			now ^= 1;
		} else {
			int f; char c;
			cin >> f >> c; f--;
			if(f == now ) {
				dq.push_front(c);
			} else {
				dq.push_back(c);
			}
		}
	}
	if(now) reverse(dq.begin(), dq.end());
	for(char c:dq) cout << c;
}

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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;

int main(){
    if(fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c){
        cout<<"No\n";
    }
    else if(a==b){
        cout<<"Yes\n";
    }
    else if(b==c){
        cout<<"Yes\n";
    }
    else if(a==c){
        cout<<"Yes\n";
    }
    else
        cout<<"No\n";


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int main() {
	int X, Y;
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	X = c-a+1;
	Y = d-b+1;
	string s = "L";
	rep(i,Y) s += "U";
	rep(i,X) s += "R";
	rep(i,Y) s += "D";
	rep(i,X-1) s += "L";
	s += "D";
	rep(i,X) s += "R";
	rep(i,Y) s += "U";
	rep(i,X) s += "L";
	rep(i,Y-1) s += "D";
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,v;
int x[200010];
vector<pair<int,int> >tot;
vector<pair<int,int> >seg[20];
int fl[1<<20],fr[1<<20];
int main()
{
	scanf("%d%d",&n,&v);
	for(int i=1;i<=n;i++)scanf("%d",x+i);
	for(int i=1;i<=n;i++)
	{
		int j=i;
		while(j+1<=n && x[j+1]-x[j]<=v)j++;
		tot.push_back(make_pair(i,j));
		i=j;
	}
	if((int)tot.size()>20)
	{
		for(int i=1;i<=n;i++)puts("Impossible");
		return 0;
	}
	v/=2;
	int k;
	for(k=0;;k++,v/=2)
	{
		for(int i=1;i<=n;i++)
		{
			int j=i;
			while(j+1<=n && x[j+1]-x[j]<=v)j++;
			seg[k].push_back(make_pair(i,j));
			i=j;
		}
		sort(seg[k].begin(),seg[k].end());
		if(!v)break;
	}
	k++;
	for(int i=0;i<(1<<k);i++)fr[i]=n+1;
	for(int i=0;i<(1<<k);i++)
	{
		for(int j=0;j<k;j++)
		{
			if(i>>j&1)continue;
			int pl=lower_bound(seg[j].begin(),seg[j].end(),make_pair(fl[i]+2,0))-seg[j].begin();
			fl[i|(1<<j)]=max(fl[i|(1<<j)],fl[i]);
			if(pl)fl[i|(1<<j)]=max(fl[i|(1<<j)],seg[j][pl-1].second);
			int pr=lower_bound(seg[j].begin(),seg[j].end(),make_pair(fr[i],0))-seg[j].begin();
			fr[i|(1<<j)]=min(fr[i|(1<<j)],fr[i]);
			if(pr)fr[i|(1<<j)]=min(fr[i|(1<<j)],seg[j][pr-1].first);
		}
	}
	for(int i=0;i<(int)tot.size();i++)
	{
		bool ok=false;
		for(int j=0;j<(1<<k);j++)
		{
			if(fl[j]>=tot[i].first-1 && fr[((1<<k)-1)^j]<=tot[i].second+1)
			{
				ok=true;
				break;
			}
		}
		for(int j=tot[i].first;j<=tot[i].second;j++)puts(ok?"Possible":"Impossible");
	}
	return 0;
}

Measured memory_bytes: 9328
import java.util.Scanner;

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int ans = Math.min(b / a, c);

		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            int[] memo = new int[2001];

            for (int i = 0; i <= 1000; i++)
            {
                for (int j = 0; j <= 1000; j++)
                {
                    memo[i + j]++;
                }
            }

            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                int n = int.Parse(input);

                int ans = 0;

                int ab = Math.Max(n - 2000, 0);
                int cd = Math.Min(2000, n);

                int len = cd - ab;

                for (int i = 0; i <= len; i++, ab++, cd--)
                {
                    ans += memo[ab] * memo[cd];
                }
                sb.AppendLine(ans.ToString());
            }
            Console.Write(sb);
        }
    }
}

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

#define MAX 100005
#define int long long
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int32_t main(){
	int n;
	cin>>n;

	int arr[n];
	for(int i = 0; i < n; i++)cin>>arr[i];

	int dp[n];
	dp[0] = 0;
	dp[1] = abs(arr[1] - arr[0]);

	for(int j = 2; j < n; j++){
		//Jump from j - 1
		int temp1 = dp[j - 1] + abs(arr[j] - arr[j - 1]);

		//jump from j - 2
		int temp2 = dp[j - 2] + abs(arr[j] - arr[j - 2]);	
		
		dp[j] = min(temp1, temp2);	
	}

	cout<<dp[n - 1];
}

Measured memory_bytes: 1792
N = int(input())
X_list = list(map(int, input().split()))

min_n = min(X_list)
max_n = max(X_list)
min_cost = 10**16

for n in range(min_n,max_n+1):
    cost = 0
    for x in X_list:
        cost = cost + (x - n)**2
    min_cost = min(min_cost, cost)

print(min_cost)


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

int main(){
    int n,k;
    string s;
    cin>>n>>k;
    cin>>s;
    int cnt=0;
    for(int i=0;i<n-1;++i){
        if(s[i]!=s[i+1]) ++cnt;
    }

    cout<<n-1-max(cnt-2*k,0)<<endl;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int N;
string s;
string mx[50][51];
bool done[50][51];
void change(string& s,string t){
	if(s.size()>t.size()) return;
	if(s.size()<t.size()){
		s=t;
		return;
	}
	if(s<t) s=t;
	return;
}
string calc(int l,int r){
	if(done[l][r]) return mx[l][r];
	string best=mx[l][r];
	if(s[l]=='L'||s[l]=='?'){
		if(r-l>=6) if(s[l+1]=='('||s[l+1]=='?') if(s[r-1]==')'||s[r-1]=='?'){
			for(int c=l+3;c<=r-3;c++) if(s[c]==','||s[c]=='?'){
				string L=calc(l+2,c);
				string R=calc(c+1,r-1);
				if(L[0]!='i'&&R[0]!='i') change(best,L);
			}
		}
	}
	if(s[l]=='R'||s[l]=='?'){
		if(r-l>=6) if(s[l+1]=='('||s[l+1]=='?') if(s[r-1]==')'||s[r-1]=='?'){
			for(int c=l+3;c<=r-3;c++) if(s[c]==','||s[c]=='?'){
				string L=calc(l+2,c);
				string R=calc(c+1,r-1);
				if(L[0]!='i'&&R[0]!='i') change(best,R);
			}
		}
	}
	done[l][r]=1;
	if(best=="") best="invalid";
	return mx[l][r]=best;
}
int main(){
	cin>>s;
	N=s.size();
	rep(l,N){
		string t;
		for(int r=l+1;r<=N;r++){
			if(s[r-1]=='L'||s[r-1]=='R'||s[r-1]=='('||s[r-1]==')'||s[r-1]==',') break;
			if(s[r-1]=='?') t+='9';
			else t+=s[r-1];
			if(t[0]=='0'&&t.size()>1) break;
			mx[l][r]=t;
		}
	}
	cout<<calc(0,N)<<endl;
}

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

long n;
Graph G;

int dfs(long pos, vector<int> & color) {
    for (auto p : G[pos]) {
        if (color[p.first] != -1) 
            continue;

        if (p.second == 0) 
            color.at(p.first) = color.at(pos);
        else
            color.at(p.first) = 1 - color.at(pos);

        dfs(p.first, color);
    }
    
    return 0;
}

int main()
{    
    cin >> n;
    G = Graph(n);
    for (long i = 0; i < n -1 ; i++) {
        long u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        w %= 2;
        G[u].push_back(make_pair(v, w));
        G[v].push_back(make_pair(u, w));
    }

    vector<int> color(n, -1);
    color.at(0) = 0;
    dfs(0, color);

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

Measured memory_bytes: 10496
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt
  val a = Array.fill(n, m){ sc.nextInt }
  val b = Array.fill(m){ sc.nextInt }
  a.map(_.zip(b).map(x => x._1 * x._2).sum).map(println)
}

Measured memory_bytes: 59624
n = input()
b = raw_input().split()
s = list(b)

for i in range(n):
    for j in range(n - 1, i, -1):
        if b[j][1] < b[j - 1][1]:
            b[j], b[j - 1] = b[j - 1], b[j]

for i in range(n):
    mini = i
    for j in range(i, n):
        if s[j][1] < s[mini][1]:
            mini = j
    s[i], s[mini] = s[mini], s[i]

print(" ".join(b))
print("Stable")
print(" ".join(s))
print("Stable" if b == s else "Not stable")

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

int main(){
	int N; cin >> N;
	int A[N+2];
	A[0] = 0; A[N+1] = 0;
	for(int i=1; i<N+1; i++) cin >> A[i];

	int default_val = 0;
	for (int i=0; i<N+1; i++){
		default_val += abs(A[i+1] - A[i]);
	}

	for (int i=1; i<N+1; i++){
		int temp1 = abs(A[i] - A[i-1]) + abs(A[i+1] - A[i]);
		int temp2 = abs(A[i+1] - A[i-1]);
		if (temp1 == temp2){
			cout << default_val << endl;
		} else {
			cout << default_val - temp1 + temp2 << endl;
		}
	}
}

Measured memory_bytes: 1664
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
from bisect import bisect_right
dpa = [0]
for a in A:
    dpa.append(dpa[-1]+a)
dpb = [0]
for b in B:
    dpb.append(dpb[-1]+b)
ans = 0
for i in range(N+1):
    t = dpa[i]
    if t > K:
        break
    j = bisect_right(dpb, K-t)
    ans = max(ans, i + j - 1)
print(ans)

Measured memory_bytes: 126860
#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 all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

string s;
cin >> s;
int n = SZ(s);
rep(i,n-1) {
    if(s[i] == s[i+1]) {
        cout << i+1 << ' ' << i+2 << endl;
        exit(0);
    }
    if(i < n-2) {
        if(s[i] == s[i+2]) {
            cout << i+1 << ' ' << i+3 << endl;
            exit(0);
        }
    }
}
cout << "-1 -1" << endl;
return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){
  int left,c1,c2,c3,h;
  while(scanf("%d %d %d",&c1,&c2,&c3)!=EOF){
    h=20-(c1+c2);
    if(h>10){
      printf("YES\n");
      continue;
    }
    left=h;
    if(c1<h) left--;
    if(c2<h) left--;
    if(c3<h) left--;

    printf("%s\n",((double)left/7.0)>=0.5?"YES":"NO");
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>

int main() {

    int h, w;
    scanf("%d %d", &h, &w);
    char c[101];
    for (int i = 0; i < h; i++) {
        scanf("%s", c);
        printf("%s\n", c);
        printf("%s\n", c);
    }


    return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

const int n_max = 100005;

int n;
vector<int> Graph[n_max];
bool vis[n_max];
int dp[n_max ][2];

void solve(int v){
    vis[v] = true;
    dp[v][0] = 1;
    dp[v][1] = 1;
    itrfor(itr,Graph[v]){
        if(vis[*itr] == false){
            solve(*itr);
            dp[v][0] *= dp[*itr][1];
            dp[v][0] %= MOD;
            dp[v][1] *= (dp[*itr][0] + dp[*itr][1]) % MOD;
            dp[v][1] %= MOD;
        } 
    }

}



signed main(){
    cin >> n;
    REP(i,n-1){
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        Graph[x].push_back(y);
        Graph[y].push_back(x);
    }
    REP(i,n) REP(j,2) dp[i][j] = -1;
    REP(i,n) vis[i] = false;
    solve(0);
    cout << (dp[0][0] + dp[0][1]) % MOD << endl;

}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	cout << (b/a >= c ? c : b/a) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  //cout << s << endl;
  string ans = "No";
  if( (s[0] == s[1]) && (s[2] == s[3]) && (s[1] != s[2]) ) ans = "Yes";
  cout << ans << endl;
}

Measured memory_bytes: 256