akhauriyash/Code-Regression huggingface dataset:
def main():
    A,B,C = map(int,input().split())
    if(A == B and B != C):
        print("Yes")
    elif(B == C and A != B):
        print("Yes")
    elif(A == C and A != B):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
inline int read() {
	int x=0,f=1; char ch=getchar();
	while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
	return x * f;
}
int ans;
int main()
{
	string s;
	cin>>s;
	int len = s.length() - 1;
	for(int i=0;i<=len/2;++i)
		if(s[i] != s[len-i]) ++ans;
	printf("%d\n",ans); 
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;

	static long n , s;
	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		n = fs.nextLong();
		s = fs.nextLong();
		
		if(n==s) {
			System.out.println(s+1);
			return;
		}
		
		if(n < s) {
			System.out.println(-1);
			return;
		}
		
		long rootn = 0;
		for(long i = 0; i*i<=n;i++) {
			rootn = i;
		}
		for(long i=2;i<=rootn;i++) {
			if(check(i)) {
				System.out.println(i);
				return;
			}
		}
		for(long i=rootn;i>=1;i--) {
			long b = (n + i - s)/i;
			if(check(b)) {
				System.out.println(b);
				return;
			}
		}
		System.out.println(-1);
		
	}
	
	static boolean check(long b) {
		long t = n;
		long res = 0;
		if(b==1) {
			return false;
		}
		while(t >= b) {
			res += t % b;
			t /= b;
		}
		res += t;
		return res == s;
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

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

int main(){
  char c;
  cin >> c;
  if(c=='A'){
    cout << 'T' << endl;
  }else if(c=='C'){
    cout << 'G' << endl;
  }else if(c=='G'){
    cout << 'C' << endl;
  }else{
    cout << 'A' << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int K = int.Parse(str[1]);
		long mod = 1000000007;
		long[,,]D = new long[N+1,N+1,N*N*2+1];
		D[0,0,0] = 1;
		for(var i=1;i<=N;i++){
			for(var j=0;j<=N;j++){
				for(var k=0;k<=K;k++){
                  	if(k-2*j>=0){
                      	if(j>0){
                          	if(j==N){
	                          	D[i,j,k] = (2*j+1)*D[i-1,j,k-2*j]+D[i-1,j-1,k-2*j]; 
                            } else {
                              	D[i,j,k] = (2*j+1)*D[i-1,j,k-2*j]+(j+1)*(j+1)*D[i-1,j+1,k-2*j]+D[i-1,j-1,k-2*j]; 
                            }
                        } else {
                         	D[i,j,k] = (2*j+1)*D[i-1,j,k-2*j]+(j+1)*(j+1)*D[i-1,j+1,k-2*j];
                        }
                    	D[i,j,k] %= mod;
                    }
				}
			}
		}
		long ans = D[N,0,K];
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 111200
package main

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

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
)

func main() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	n := scanInt()
	p := scanInts(n)

	ans := 0
	min := math.MaxInt64
	for i := 0; i < n; i++ {

		if p[i] < min {
			min = p[i]
		}

		if min >= p[i] {
			ans++
		}
	}

	fmt.Println(ans)
}

func scanInt() int {
	i, _ := strconv.Atoi(scanText())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanText(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

func scanText() string {
	scanner.Scan()
	return scanner.Text()
}

func scanTexts(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanText()
	}
	return s
}

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

func pow(x, y int) int {
	return int(math.Pow(float64(x), float64(y)))
}

func min(n []int) (min, idx int) {
	min = math.MaxInt64
	for i := 0; i < len(n); i++ {
		if n[i] < min {
			min = n[i]
			idx = i
		}
	}
	return
}

func max(n []int) (max, idx int) {
	max = math.MinInt64
	for i := 0; i < len(n); i++ {
		if n[i] > max {
			max = n[i]
			idx = i
		}
	}
	return
}


Measured memory_bytes: 3584
#include <stdio.h>

void printOut(int A[100], int N){
	
	for(int i = 0; i < N; i++){
		printf("%d", A[i]);
		if( i != N-1 ) printf(" ");
	}
	
}

int main(void){
	
	int N,key;
	int A[100];
	int i,j,k;
	
	scanf("%d", &N);
	
	for(i = 0; i < N; i++){
		scanf("%d", &A[i]);
	}
	
	for(i = 1; i < N; i++){
		printOut(A, N);
		printf("\n");
		key = A[i];
		j = i-1;
		while( j >= 0 && A[j] > key){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = key;
	}
	printOut(A, N);
	printf("\n");
	
}


Measured memory_bytes: 2144
// Header {{{
#include <bits/stdc++.h>

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}
ll t(char c){
    return c-'0';
}
ll f(ll bit ,ll i){
    return (bit>>i)&1 ? 1 : -1;
}
char g(ll bit ,ll i){
    return (bit>>i)&1 ? '+' : '-';
}
signed main() {
    string s;
    cin>>s;
    rep(bit,0,8){
        if (t(s[0]) + t(s[1]) * f(bit, 0) + t(s[2]) * f(bit, 1) + t(s[3]) * f(bit, 2)==7){
            cout<<s[0]<<g(bit,0)<<s[1]<<g(bit,1)<<s[2]<<g(bit,2)<<s[3] <<"=7"<<endl;
            return 0;
        }
    }
    return 0;
}


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

int main(void)
{
    int N;
    cin >> N;

    int H[N];
    cin >> H[0];
    int count = 0;
    int maxCount = 0;
    for (int i = 1; i < N; i++) {
        cin >> H[i];
        if (H[i-1] >= H[i]) {
            count++;
        }
        else {
            if (count > maxCount) {
                maxCount = count;
            }
            count = 0;
        }
    }
    if (count > maxCount) {
        maxCount = count;
    }
    cout << maxCount << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
int main()
{
  ll n,c,d[40][40],e[600][600],x,y[5][40],ans;
  cin >> n >> c;
  ans=INF;
  rep(i,c){
    rep(j,c){
      cin >> d[i][j];
    }
  }
  rep(i,n){
    rep(j,n){
      cin >> e[i][j];
    }
  }
  rep(l,n){
    rep(m,n){
      if((l+m)%3==0)y[0][e[l][m]-1]++;
      if((l+m)%3==1)y[1][e[l][m]-1]++;
      if((l+m)%3==2)y[2][e[l][m]-1]++;
    }
  }
  rep(i,c){
    rep(j,c){
      rep(k,c){x=0;
        if(i!=j&&i!=k&&k!=j){
          rep(l,c){
              x+=y[0][l]*d[l][i];
              x+=y[1][l]*d[l][j];
              x+=y[2][l]*d[l][k];
          }
        }else{x=INF;
             }
        if(ans>x)ans=x;
      }
    }
  }
  printf("%lld",ans);
}

Measured memory_bytes: 3072
X,Y,A,B,C=map(int,input().split())
ls_a=sorted(list(map(int,input().split())))
ls_b=sorted(list(map(int,input().split())))
ls_c=sorted(list(map(int,input().split())))
ls_x=ls_a[A-X:A]
ls_y=ls_b[B-Y:B]
ls_c.reverse()

ans=sum(ls_x)+sum(ls_y)
a=b=c=0
for _ in range(min([X+Y,C])):
  if a==len(ls_x):
    m=min([ls_y[b],ls_c[c]])
    if m==ls_y[b]:
      ans+=(-ls_y[b]+ls_c[c])
      b+=1
      c+=1
    else:
      break
  elif b==len(ls_y):
    m=min([ls_x[a],ls_c[c]])
    if m==ls_x[a]:
      ans+=(-ls_x[a]+ls_c[c])
      a+=1
      c+=1
    else:
      break
  else:    
    m=min([ls_x[a],ls_y[b],ls_c[c]])
    if m==ls_x[a]:
      ans+=(-ls_x[a]+ls_c[c])
      a+=1
      c+=1
    elif m==ls_y[b]:
      ans+=(-ls_y[b]+ls_c[c])
      b+=1
      c+=1
    else:
      break
print(ans)

Measured memory_bytes: 22720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
struct UnionFind{
	int par[4010],rank[4010];
	void init(){
		for(int i=0;i<4010;i++){
			par[i]=i;
			rank[i]=0;
		}
	}
	int find(int x){
		if(par[x]==x)return x;
		else return par[x]=find(par[x]);
	}
	void unite(int x,int y){
		x = find(x);
		y = find(y);
		if(x==y)return;
		if(rank[x]>rank[y])par[y]=x;
		else{
			par[x]=y;
			rank[y]++;
		}
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
}uf;
struct edge{
	int from,to;
	ll cost;
	edge(){}
	edge(int from,int to,ll cost):from(from),to(to),cost(cost){}
	bool operator < (const edge &a) const{
		return cost < a.cost;
	}
};
int N,M,Q;
vector<edge> es;
vector<edge> g[4010];
int par[15][4010];
ll cost[15][4010];
int depth[4010];
void add_edge(edge e){
	g[e.from].pb(e);
	swap(e.from,e.to);
	g[e.from].pb(e);
}
void dfs(int v,int p,int c,int d){
	depth[v]=d;
	par[0][v]=p;
	cost[0][v]=c;
	for(int i=0;i<g[v].size();i++){
		edge e = g[v][i];
		if(e.to==p)continue;
		dfs(e.to,v,e.cost,d+1);
	}
}
ll query(int u,int v){
	//cout << u << ' ' << v << endl;
	if(depth[u]>depth[v])swap(u,v);
	ll res = 0ll;
	for(int i=14;i>=0;i--){
		if(((depth[v]-depth[u])>>i)&1){
			res = max(res,cost[i][v]);
			v = par[i][v];
		}
	}
	if(u==v)return res;
	for(int i=14;i>=0;i--){
		if(par[i][u]!=par[i][v]){
			res = max(res,cost[i][u]);
			res = max(res,cost[i][v]);
			u = par[i][u];
			v = par[i][v];
		}
	}
	res = max(res,cost[0][u]);
	res = max(res,cost[0][v]);
	assert(par[0][u]==par[0][v]);
	return res;
}
int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		int a,b;
		ll c;
		cin >> a >> b >> c;
		a--;b--;
		es.pb(edge(a,b,c));
	}
	sort(all(es));
	uf.init();
	ll base = 0ll;
	for(int i=0;i<es.size();i++){
		if(uf.same(es[i].from,es[i].to))continue;
		base += es[i].cost;
		uf.unite(es[i].from,es[i].to);
		//cout << es[i].from << ' ' << es[i].to << ' ' << es[i].cost << endl;
		add_edge(es[i]);
	}
	dfs(0,-1,-1,0);
	/*for(int i=0;i<N;i++){
		printf("%d %d %lld\n",i,par[0][i],cost[0][i]);
	}*/
	for(int i=0;i<14;i++){
		for(int j=0;j<N;j++){
			if(par[i][j]==-1){
				par[i+1][j]=-1;
				cost[i+1][j]=cost[i][j];
			}else{
				par[i+1][j]=par[i][par[i][j]];
				cost[i+1][j]=max(cost[i][j],cost[i][par[i][j]]);
			}
		}
	}
	cin >> Q;
	for(int i=0;i<Q;i++){
		int S,T;
		cin >> S >> T;
		S--;T--;
		cout << base-query(S,T) << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long LL;
typedef vector<int>    VI;
typedef vector<bool>   VB;
typedef vector<string> VS;

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

vector<VB> tbls;
map<int, pair<int, int>> ps;
int n;

const int offsetx = 201;
const int offsety = 201;
const int INF = INT_MAX / 2;
const int DX[] = {-1, 0, 1, 0}, DY[] = {0, 1, 0, -1};

#define x first
#define y second

int main(void) {
	while (1) {
		tbls.clear();
		ps.clear();
		cin >> n;
		if (n == 0) break;
		tbls.resize(410, VB(410));
		tbls[offsety][offsetx] = true;
		ps[0] = MP(offsetx, offsety);
		REP (i, 1, n) {
			int s, d;
			cin >> s >> d;
			pair<int, int> p = ps[s];
			tbls[p.y + DY[d]][p.x + DX[d]] = true;
			ps[i] = MP(p.x + DX[d], p.y + DY[d]);
		}
		int min_x = INF, min_y = INF;
		int max_x = -1, max_y = -1;
		rep (y, 410) {
			rep (x, 410) {
				if(tbls[y][x]) {
					min_x = min(min_x, x);
					min_y = min(min_y, y);
					max_x = max(max_x, x);
					max_y = max(max_y, y);
				}
			}
		}
		cout << max_x - min_x + 1 << " " << max_y - min_y + 1 << endl;
	}
    return 0;
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
typedef pair<pill,int> PA;
//ll MOD;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	ll weight;
};
int N;
vi A;
ll results[314514];
map<int,int> cnt;
int cnt2[314514]={0};
int ans[314514];
int main(){
	cin>>N;
	rep(i,N){
		int x;
		cin>>x;
		A.pb(x);
		cnt[x]++;
	}
	for(auto i=cnt.begin();i!=cnt.end();++i){
		cnt2[i->second]++;
	}
	ll plus=(ll)0;
	rep(i,N+1){
		//cout<<cnt2[i]<<endl;
		//if(cnt2[i]>0)plus++;
		plus+=cnt2[i];
	}

	ll sum=0;
	results[0]=N+1;
	for(int i=1;i<=N;i++){
		sum+=plus;
		plus-=cnt2[i];
		results[i]=sum/i;
		//cout<<results[i]<<endl;
	}
	int aans=N;
	for(int i=1;i<=N;i++){
		while(results[aans]<i){
			aans--;
		}
		ans[i]=aans;
	}
	rep(i,N)cout<<ans[i+1]<<endl;

}


Measured memory_bytes: 19312
_ = int(input())
A = list(map(int, input().split()))
Q = int(input())

m = {}
sum = 0

for a in A:
  m[a] = m.get(a, 0) + 1
  sum += a

L = []
for _ in range(Q):
  B, C = list(map(int, input().split()))
  if m.get(B, 0) != 0:
    m[C] = m.get(C, 0) + m[B]
    sum += (C - B) * m[B]
    m[B] = 0
  L.append(sum)

for l in L:  
  print(l)

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		long[]a = new long[n];

		for(int i=0;i<n;i++) {
			a[i]=Long.parseLong(sc.next());
		}
		sc.close();
		if(n == 1) {
			if(a[0]%2==1) {
				System.out.println("first");
				return;
			}
		}

		String res = "second";
		Arrays.sort(a);
		for (int i = 0; i < n; i++) {
	        if (a[i] % 2 == 1) {
	        	res = "first";
	        	break;
	        }
	     }
	    System.out.println(res);
	}

}


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

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int cnt = 0;
    rep(i, n) {
        if (s[i] != t[i]) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3856
/********************************************
 *Author*        :ZZZZone
 *Created Time*  : 六  4/21 20:16:41 2018
 * Ended  Time*  : 六  4/21 20:39:09 2018
*********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
const int MAXN = 1e5;

LL x[MAXN+5], v[MAXN+5];
int n;
LL C;


struct Node{
	int pos;
	LL sum;
}fl, fr;
LL qr[MAXN+5], ql[MAXN+5];

void Init(){
	scanf("%d %lld", &n, &C);
	for(int i = 1; i <= n; i++){
		scanf("%lld %lld", &x[i], &v[i]);
	}
}

void Solve(){
	LL sum = 0;
	for(int i = 1; i <= n; i++){
		sum += v[i];
		ql[i] = max(ql[i-1], sum - x[i]);
	}
	//debug(fl.sum);
	//debug(fl.pos);
	sum = 0LL;
	for(int i = n; i >= 1; i--){
		sum += v[i];
		qr[i] = max(qr[i+1], sum - (C-x[i]));
	}
	sum = 0LL;
	LL ans1 = 0LL, ans2 = 0LL;
	for(int i = 0; i <= n; i++){
		LL tmp = max(ql[i] - x[i] + qr[i+1], ql[i]);
		/*
		debug(ql[i]);
		debug(qr[i+1]);
		debug(tmp);
		*/
		ans1 = max(ans1, tmp);
	}
	sum = 0LL;
	for(int i = n+1; i >= 1; i--){
		LL tmp = max(qr[i] - (C-x[i]) + ql[i-1], qr[i]);
		ans2 = max(ans2, tmp);
	}
	printf("%lld\n", max(ans1, ans2));
}

int main()
{
	Init();
	Solve();
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int i[11111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d=0;
  string s;
  cin >>a>>b;
  c=a+b,d=a-b,a=a*b;
  cout <<max(a,max(c,d))<<'\n';
  return (0);
}


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

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

typedef long long ll;

signed main()
{
    int n; cin >> n;
    set<string> s;
    rep(i,n){
        string tmp;
        cin >> tmp;
        s.insert(tmp);
    }

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

    return 0;
}


Measured memory_bytes: 19180
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin>>N;
	vector<int> arr;
	arr.resize(N);
	for(int i = 0; i < N; i++){
		cin>>arr[i];
	}
	//sort(arr.begin(), arr.end());
	int ans = -1;
	int found = 1;
	for(int i = 0; i < N; i++){
		if(arr[i] == found){
			ans++;
			found++;
		}
	}
	if(ans == -1){
	cout<<ans;
	}
	else{
		cout<<N-ans-1;
	}
}

Measured memory_bytes: 1024
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1<<25;
// const ll INF = 1LL<<50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


// --------------------------------------------------------

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

  string s;
  REP(i, 3) {
    cin >> s;
    cout << CHAR(s.front() - 'a' + 'A');
  }

  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    ll l, r;
    cin >> l >> r;
    ll d = r - l + 1;
    if(d >= 2019) {
        cout << 0 << endl;
        return 0;
    }
    l %= 2019;
    r %= 2019;
    if(r < l) r += 2019;
    int ans = INF;
    for(int i = l; i <= r; ++i) for(int j = i+1; j <= r; ++j) {
        chmin(ans, (i*j)%2019);
    } 
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
  int W,H,N;
  int x[100],y[100],a[100];
  int XU,XL=0,YU,YL=0,X,Y;
  
  scanf("%d %d %d",&W,&H,&N);
  XU=W;
  YU=H;
  for(int i=0;i<N;i++)
    scanf("%d %d %d",&x[i],&y[i],&a[i]);
  
  for(int i=0;i<N;i++){
    switch(a[i]){
      case 1:
        if(x[i]<XL) continue;
        XL=x[i];
        break;
      case 2:
        if(x[i]>XU) continue;
        XU=x[i];
        break;
      case 3:  
        if(y[i]<YL) continue;
        YL=y[i];
        break;
      case 4:
        if(y[i]>YU) continue;
        YU=y[i];
        break;
      default:
        continue;
    }
  }
  X=XU-XL;
  Y=YU-YL;
  if(X<0) X=0;
  if(Y<0) Y=0;
  printf("%d",X*Y);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;



int main()
{
    int n,sum,a;
    scanf("%d",&n);
    sum=-n;
    while(n--)
    {
        scanf("%d",&a);
        sum+=a;
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<numeric>
//#include <bits/stdc++.h>
#include<cstring>
#include<iostream>
#include<functional>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++)
		cin >> a[i];
	sort(a.begin(), a.end(),  greater<int>());

	

	int Alice = 0;
	int Bob = 0;

	for (int i = 0; i < N; i++) {
		if (i % 2 == 0)
			Alice += a[i];
		else
			Bob += a[i];

	}
	cout << Alice - Bob << endl;
	//cin >> N;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
N = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))

a = sum(x <= A for x in P)
b = sum(A + 1 <= x <= B for x in P)
c = N - a - b
print(min(a, b, c))


Measured memory_bytes: 3060
//8 Queens Problem
#include <stdio.h>

#define GRID_NUM 8
#define FREE -1
#define NOT_FREE 1

void printBoard(void);
void recursive(int);

//pos[]  Left  Naname
//neg[]  Right Naname
int ROW[GRID_NUM],COLUMN[GRID_NUM],pos[2*GRID_NUM-1],neg[2*GRID_NUM-1];
//exist?
int flag[GRID_NUM][GRID_NUM];

int main(){
	int k,i,j;
	int row,column;


	//init
	for(i=0;i<GRID_NUM;i++){
		ROW[i]=FREE;
		COLUMN[i]=FREE;
	}
	for(i=0;i<2*GRID_NUM-1;i++){
		pos[i]=FREE;
		neg[i]=FREE;
	}
	for(i=0;i<GRID_NUM;i++){
		for(j=0;j<GRID_NUM;j++){
			flag[i][j]=-1;
		}
	}

	//input
	scanf("%d",&k);

	for(i=0;i<k;i++){
		scanf("%d %d",&row,&column);
		flag[row][column]=1;
	}

	recursive(0);

	return 0;

}


void printBoard(){
	int i,j;
	for(i=0;i<GRID_NUM;i++){
		for(j=0;j<GRID_NUM;j++){
			if(flag[i][j]==1){
				if(ROW[i]!=j)return;
			}
		}
	}

	for(i=0;i<GRID_NUM;i++){
		for(j=0;j<GRID_NUM;j++){
			if(ROW[i]==j){
				printf("Q");
			}
			else{
				printf(".");
			}
		}
		printf("\n");
	}
}


void recursive(int num){
	int i,j;
	//queens put succes
	if(num==GRID_NUM){
		printBoard();
		return;
	}
	//(i,j) do not put
	for(i=0;i<GRID_NUM;i++){
		if(NOT_FREE==COLUMN[i] || NOT_FREE==pos[num+i] || NOT_FREE==neg[num-i+GRID_NUM-1]){
			continue;
		}
		//(i,j) put
		ROW[num]=i;
		COLUMN[i]=pos[num+i]=neg[num-i+GRID_NUM-1]=NOT_FREE;
		//next row
		recursive(num+1);
		//(i,j) remove
		ROW[num]=COLUMN[i]=pos[num+i]=neg[num-i+GRID_NUM-1]=FREE;
	}
	//queens put fail
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int n = (int)s.size();
  int Res = 0;
  for (int i = 0; i < n; i++) Res += s[i] == 'o';
  if (Res + (15 - n) >= 8) cout << "YES";
  else cout << "NO";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <fstream>
#include <queue>
#include <cstdio>
using namespace std;
#define fol(i,n) for (int i=0;i<n;i++)
#define db(a) cout << a<< endl;
typedef pair <int,int>P;
using namespace std;

int main(){
    int x,a,b;
    cin >> x>>a>>b;
    if (a<b&&(b-a)<=x) cout <<"safe"<<endl;
    else if (a>=b) cout << "delicious"<<endl;
    else cout << "dangerous" <<endl;
    return 0;
}


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

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

	set<int> st;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (st.find(x) == st.end()) {
			st.insert(x);
		}
		else {
			cout << "NO" << endl;
			break;
		}
		if (i == n - 1) cout << "YES" << endl;
	}
}

Measured memory_bytes: 9600
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        String T = scan.next();
        System.out.println(T+S);
    }
}


Measured memory_bytes: 23764
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

template<typename T> bool chmax( T &a, const T &b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T &b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


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

	cout << ( N / 3 ) << endl;

	return ( 0 );
}


Measured memory_bytes: 256
#include <stdio.h>
#define min(a, b) ((a) < (b) ? (a) : (b))

#ifdef ONLINE_JUDGE
static char _in_buf[100000], *_in_p1 = _in_buf, *_in_p2 = _in_buf;
#define getchar() (_in_p1 == _in_p2 && (_in_p2 = (_in_p1 = _in_buf) + fread(_in_buf, 1, 100000, stdin), _in_p1 == _in_p2) ? EOF : *_in_p1 ++)
#endif
#ifdef __cplusplus
extern "C" {
#endif
__attribute__((always_inline)) __inline__
void read(int *now) {
  int f = *now = 0; register char c = getchar();
  while ((c > 57 || c < 48) && ~c && c != '-') c = getchar();
  (c == '-') && ((f = 1), c = getchar());
  for (; c > 47 && c < 58; *now = (*now << 3) + (*now << 1) + c - '0', c = getchar());
  f && (*now = -*now);
}
#ifdef __cplusplus
}
#endif

#define N 262144
#define inf 0x3f3f3f3f

int n, x, y, l, r, p[N];
int tr[N << 1 | 5], tr1[N << 1 | 5], tr2[N << 1 | 5];
#define build(tr) for (i = N; -- i; ) \
                   tr[i] = min(tr[i << 1], tr[i << 1 | 1])
#ifdef __cplusplus
extern "C" {
#endif
__attribute__((always_inline)) __inline__
int query(int *t, int l, int r) {
  int res = inf; l += N - 1, r += N + 1;
  for (; l ^ r ^ 1; l >>= 1, r >>= 1)
    (~l & 1) && (res = min(res, t[l + 1])), 
    (r & 1) && (res = min(res, t[r - 1]));
  return res;
}
#ifdef __cplusplus
}
#endif

struct node {
  int a, b, c, d;
} tp, q[N];
int sz = 0;
#ifdef __cplusplus
extern "C" {
#endif
__attribute__((always_inline)) __inline__
int cmp(struct node a, struct node b) {
  if (a.a ^ b.a) return a.a - b.a;
  if (a.b ^ b.b) return a.b - b.b;
  if (a.c ^ b.c) return a.c - b.c;
  return a.d - b.d;
}
__attribute__((always_inline)) __inline__
void swap(struct node *a, struct node *b) { struct node c = *a; *a = *b; *b = c; }
__attribute__((always_inline)) __inline__
void heap_push(struct node x) {
  q[++ sz] = x;
  for (int i = sz, j = i >> 1; j; i = j, j >>= 1)
    if (cmp(q[j], q[i]) > 0) swap(q + i, q + j);
}
__attribute__((always_inline)) __inline__
void heap_pop() {
  q[1] = q[sz --];
  for (int i = 1, j = i << 1; j <= sz; i = j, j <<= 1) {
    ((j | 1) <= sz && cmp(q[j | 1], q[j]) < 0) && (j |= 1);
    if (cmp(q[i], q[j]) > 0) swap(q + i, q + j);
    else break;
  }
}
__attribute__((always_inline)) __inline__
void push(int l, int r) {
  if (l > r) return; int x = query(l & 1 ? tr1 : tr2, l, r);
  heap_push((struct node){x, query(l & 1 ? tr2 : tr1, p[x] + 1, r), l, r});
}
#ifdef __cplusplus
}
#endif

int main() {
  register int i;
  for (read(&n), i = 1; i <= n; ++ i)
    read(&x), p[x] = i, tr[i + N] = x, 
    tr1[i + N] = i & 1 ? x : inf, tr2[i + N] = i & 1 ? inf : x;
  build(tr); build(tr1); build(tr2);
  for (push(1, n); sz; ) {
    x = q[1].a, y = q[1].b, l = q[1].c, r = q[1].d;
    printf("%d %d ", x, y), heap_pop();
    push(l, p[x] - 1), push(p[x] + 1, p[y] - 1), push(p[y] + 1, r);
  }
  putchar('\n');
}

Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;  
#define PI 3.1415
int main(void)  
{  
   	long long n,a[200003];
   	cin>>n;
   	memset(a,0,sizeof(a));
   	for(int i=0;i<n-1;i++)
   	{
   		int g;
   		cin>>g;
   		a[g]++;
	   }
	   for(int i=1;i<=n;i++)
	   {
	   	cout<<a[i]<<"\n";
	   }
    return 0;     
}  

Measured memory_bytes: 5196
#include<stdio.h>

#define MAX 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];
              
int prim(){
  int u,minv;
  int d[MAX],p[MAX],color[MAX];
  int i,v,e,m=0,sum=0;
  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;
  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && M[u][v]!=INFTY){
	if(d[v]>M[u][v]){
	  d[v]=M[u][v];
	  p[v]=u;
	  color[v]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    if(p[i]!=-1) sum+=M[i][p[i]];
  }
  return sum;
}

int main(){
  int i,e,j;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      M[i][j]=(e==-1)?INFTY:e;
    }
  }
  printf("%d\n",prim());

  return 0;
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
   
    int max=-1;
    for(int i=0;i<n;i++){
        if(a[i]>max)max=a[i];
    }
    double median;
        median=(double)max/2;
    int min=1000000000;
    int min_num;
    for(int i=0;i<n;i++){
        double d=abs(a[i]-median);
        if(a[i]==max)continue;
        if(d<min){
            min=d;
            min_num=i;
        }    
    }
    cout<<max<<" "<<a[min_num]<<"\n";
    return 0;
}


Measured memory_bytes: 640
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn adder (i: usize, j: usize) -> isize{
    let mut pow: usize = 1;
    for k in 1..i {
        pow *= 10;
    }
    (pow * j) as isize
}

fn main(){
    input!{
        n: usize,
        a:[usize;n]
    }
    let mut count = vec![0u64;n];
    for (i, val) in a.iter().enumerate() {
        count[*val-1] += 1;
    }
    let mut cnv = vec![0u64;n];
    for (i, val) in count.iter().enumerate(){
        cnv[i] = {val*(val-1)/2};
    }
    let mut ans = 0u64;
    for val in cnv.iter(){
        ans += *val;
    }
    for val in a.iter(){
        println!("{}", ans - cnv[*val-1] + (count[*val-1]-1)*(count[*val-1]-2)/2);
    }
}


Measured memory_bytes: 14844
/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(int i=1;i<=n;i++)
#define   FOR(i,a,b)      for(int i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
#define   ret             return 
#define   sz(x)           (LL)x.size()
LL n,i,j,ans = 0,k;
string s ; 
LL dp[1000000][5] ; 
LL a[1000000][5] ;
LL f(LL ind,LL pre) 
{  if(ind>n) ret 0 ; 
    
   if(pre!=1 and dp[ind][1]==-1)
   dp[ind][1] = a[ind][1] + f(ind+1,1) ; 
   if(pre!=2 and dp[ind][2]==-1)
   dp[ind][2] = a[ind][2] + f(ind+1,2) ; 
   if(pre!=3 and dp[ind][3]==-1)
   dp[ind][3] = a[ind][3] + f(ind+1,3) ;
   if(pre!=-1) ret max(dp[ind][1]*(pre!=1),max(dp[ind][2]*(pre!=2),dp[ind][3]*(pre!=3))) ; 
   ret max(dp[ind][1],max(dp[ind][2],dp[ind][3])) ;  
} 
int main()
{   // Read the constraints,highlights,Time Limit,Test Cases
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n ; 
    memset(dp,-1,sizeof(dp)) ; 
    REP(i,n) REP(j,3) cin>>a[i][j] ; 
    cout<<f(1,-1) ; 
}
//Check for 0,1 and other corner cases.

Measured memory_bytes: 48256
#include <bits/stdc++.h>
using namespace std;
int64_t times2(int64_t n) {
	int64_t output = 1;
	for (int64_t i = 0; i < n; ++i) {
		output *= 2;
	}
	return output;
}

int main() {
	//input
	int N, M, Q;
	cin >> N >> M >> Q;

	vector<int> a(Q);
	vector<int> b(Q);
	vector<int> c(Q);
	vector<int> d(Q);
	for (int i = 0; i < Q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}

	//calculation
	queue<vector<int>> pattern;
	int64_t all = N + M - 1;
	for (int64_t num = 0; num < times2(all); num++) {
		bitset<20> b(num);
		vector<int> A_temp(N);
		int branch = 0;
		int ball = 0;
		for (int i = 0; i < all; i++) {
			if (b.test(i)) {
				if (branch < N) {
					A_temp[branch] = ball;
				}
				branch++;
			} else {
				ball++;
			}
		}
		if (branch == N) {
			pattern.push(A_temp);
		}
	}

	int output = 0;

	while (!pattern.empty()) {
		vector<int> A = pattern.front();
		int temp_sum = 0;
		for (int i = 0; i < Q; i++) {
			if (A[b[i]] - A[a[i]] == c[i]) {
				temp_sum += d[i];
			}
		}
		if (output < temp_sum) {
			output = temp_sum;
		}
		pattern.pop();
	}


	//output
	cout << output << endl;


	return 0;
}


Measured memory_bytes: 10188
#include<bits/stdc++.h>
using namespace std;
int TEST=0,CASE=1;
#define         pf              printf
#define         si(x)           scanf("%d",&x)
#define         si2(x,y)        scanf("%d %d",&x,&y)
#define         si3(x,y,z)      scanf("%d %d %d",&x,&y,&z)
#define         sl(x)           scanf("%lld",&x)
#define         sl2(x,y)        scanf("%lld %lld",&x,&y)
#define         sl3(x,y,z)      scanf("%lld %lld %lld",&x,&y,&z)
#define         sd(x)           scanf("%lf ",&x)
#define         pb(x)           push_back(x)
#define         mp(x,y)         make_pair(x,y)
#define         clr(x,y)        memset(x,y,sizeof(x))
#define         all(x)          x.begin(),x.end()
#define         MX              401000
#define         left            (indx<<1)
#define         right           left+1
#define         mid             ((l+r)>>1)
#define         call            left,l,mid
#define         lnd             tree[left]
#define         calr            right,mid+1,r
#define         rnd             tree[right]
#define         cnd             tree[indx]
#define         speed           (ios::sync_with_stdio(false),cin.tie(0))
#define         fpoint(x)       (cout.precision(x),cout<<fixed)
#define         FOR(i,n)       	for(int i=1;i<=n;++i)
#define         FOR0(i,n)      	for(int i=0;i<n;++i)
#define		dx		xx+dirx[i]
#define		dy		yy+diry[i]
long long int         mod  =    1000000007LL;
const long double     pi   =    2.0*acos(0.0);
typedef long long int ll;
typedef long double ld;
int dirx[9]={0,0,0,-1,+1,+1,+1,-1,-1};
int diry[9]={0,-1,+1,0,0,-1,+1,-1,+1};
struct vpair{
        int a,b;
        vpair(int a,int b){this->a=a,this->b=b;}
};
bool cmp(int &a,int &b){
        return a<b;                ///ascending order
        return a>b;                ///descending order
}
int n,m,a,b,c,d,k,x,y,z,ans=0,total=0;
int arr[300001];
string s;
vector<int> v;
int main(void){
	cin>>s;
	n=s.length();
	stack<int> st;
	for(int i=0;i<n;i++){
		if(s[i]=='0'){
			if(st.size()>0){
				if(st.top()==1){
					st.pop();
					ans+=2;
				}else st.push(0);
			}else st.push(0);
		}else{
			if(st.size()>0){
				if(st.top()==0){
					st.pop();
					ans+=2;
				}else st.push(1);
			}else st.push(1);
		}
	}
	cout<<ans<<endl;
        return 0;
}

/**
"G:\Work Station\OnlineJudge\Atcoder\C.cpp"
**/


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

int main() {
	int n;
	cin >> n;
	cout << 10 - n / 200 << endl;
	return 0;
}


Measured memory_bytes: 3620
int main() {
  int x, y, z;

  scanf("%d%d", &x, &y);

  if(x < y){
    z = x;
    x = y;
    y = z;
  }

  for(;y != 0;){
    z = y;
    y = x % y;
    x = z;
  }

  printf("%d\n", x);
    

  return 0;
}

Measured memory_bytes: 1800
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;

int main(){
  int n; cin >> n;
  int a[n][n], d[n][n];
  rep(i, n)rep(j, n) cin >> a[i][j], d[i][j] = a[i][j];
  rep(k, n)rep(i, n)rep(j, n) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
  rep(i, n)rep(j, n)if(d[i][j]!=a[i][j]){
    cout << "-1" << endl;
    return 0;
  }
  rep(k, n)rep(i, n)rep(j, n)if(i!=k && j !=k && d[i][j]==d[i][k]+d[k][j]) a[i][j] = 0;
  long ans = 0;
  rep(i, n-1)For(j, i+1, n) ans += a[i][j];
  cout << ans << endl;
}

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

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

using namespace std;

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

	int count = 0;
	int searchNum = 1;
	rep(i, a.size()) {
		if (a[i] == searchNum) {
			searchNum++;
		}
		else count++;
	}
	if (searchNum == 1)cout << -1;
	else cout << count;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Text;

namespace atcoder_BegginerContest93_Question2
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            StringBuilder s = new StringBuilder();

            for (int i = input[0]; i < input[0] + input[2]; i++)
            {
                if (i <= input[1])
                {
                    s.AppendLine(i.ToString());
                }
            }

            for (int i = input[1] - input[2] + 1; i <= input[1]; i++)
            {
                if (input[0] + input[2] <= i)
                {
                    s.AppendLine(i.ToString());
                }
            }

            Console.WriteLine(s);
        }
    }
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()

int n, p;

ll dp[100][2];
int a[100];

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> p;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    dp[0][0] = 1;
    for(int i = 1;i <= n;i++){
        for(int j = 0;j < 2;j++){
            int to = (j + a[i]) & 1;
            dp[i][to] += dp[i - 1][j];
            dp[i][j] += dp[i - 1][j];
        }
    }
    cout << dp[n][p] << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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;}
using ll = long long;
constexpr long long INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;

constexpr int MAX = 2001;
long long fac[MAX], inv[MAX], finv[MAX];
void CombInit(){
    fac[0] = inv[0] = finv[0] = 1;
    fac[1] = inv[1] = finv[1] = 1;
    for(int i=2; i<MAX; ++i){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    CombInit();

    cout << fac[n+k-1] * finv[k-1]%MOD * finv[n]%MOD << '\n';
    return 0;
}


Measured memory_bytes: 3248
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cstdlib>
#include <typeinfo>

using namespace std;

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


int i,j;

int main(void){
    
    int a,b,c;
    cin >> a >> b >> c;
    
    FOR(i,a*b){
        
        //cout<<(a*i)%b<<" ";
        
        if((a*i)%b==c){
            cout<<"YES";
            return 0;
        }
    }
    
    cout<<"NO";
    return 0;
    
}


Measured memory_bytes: 256