akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cfloat>
#define zero(x) (((x)>0?(x):-(x))<eps)

#define pause cout << " press ansy key to continue...",  cin >> chh
#define file_r(x) freopen(x,  "r",  stdin)
#define file_w(x) freopen(x,  "w",  stdout)
#define lowbit(x) ((x) & (-x))
#define repit(i, c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repe(i, u) for (int i = head[u]; i != -1; i = nxt[i])
#define repd(i, n) for (int i = (n - 1); i >= 0; i--)
#define FOR(i, n, m) for (int i = (n); i <= (m); i++)
#define FORD(i, n, m) for (int i = (n); i >= (m); i--)
#define pb push_back
#define X first
#define Y second
#define ins insert
#define rb rbegin
#define be begin
#define er erase
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define SZ(c) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define sqr(r) ((r) * (r))
#define dis(x1, y1, x2, y2) (((x1) - (x2)) * ((x1) - (x2)) + ((y1) - (y2)) * ((y1) - (y2)))
#define FASTIO ios::sync_with_stdio(false);cin.tie(0)

#define sc(x) cout << #x" = " << x << endl, system("pause")
#define sc2(x, y) cout << #x" = " << x << " " << #y" = " << y << endl, system("pause")
#define sc3(x, y, z) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << endl, system("pause")
#define sc4(x, y, z, w) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << " " << #w" = " << w << endl, system("pause")

#define in(n) scanf("%d", &n)
#define in2(n, m) scanf("%d %d", &n, &m)
#define in3(x, y, z) scanf("%d %d %d", &x, &y, &z)

using namespace std;
int chh;

typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<int, pii> pi3;
typedef vector< pair<int, int> > vpii;
typedef long long LL;

LL n, m;

int main() {
    while (cin >> n >> m) {
        if (m <= 2 * n) cout << m / 2;
        else {
            cout << n + (m - n * 2) / 4 << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <algorithm>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using usize = std::size_t;

auto main() -> i32 {
	i64 a, v, b, w, t;
	scanf("%ld%ld%ld%ld%ld", &a, &v, &b, &w, &t);
	i64 x = std::abs(a - b);
	i64 y = v - w;
	if (y <= 0 || x > y * t) {
		puts("NO");
	} else {
		puts("YES");
	}
	return 0;
}


Measured memory_bytes: 1624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;

int main()
{
    int H, W;
    cin >> H >> W;
    int N;
    cin >> N;
    vint a(N+1);
    vvint c(W, vint(H));
    rep(i, N)
    {
        cin >> a[i+1];
    }
    pair<int, int> pos = {0,0};
    bool down = true; //downの向きをy軸正とする
    rep2(color,1, N+1)
    {
        
        while (a[color] > 0 and pos.first < W and pos.first >= 0 and pos.second < H and pos.second >= 0)
        {
            c[pos.first][pos.second] = color;
            
            if(down)
            {
                if (pos.second == H-1)
                {
                    down = !down;
                    pos.first++;
                }
                else
                pos.second++;
            }
            else
            {
                if(pos.second == 0)
                {
                    down = !down;
                    pos.first++;
                }
                else
                {
                    pos.second--;
                }
                        }
            
            a[color]--;

        }
    }
    rep(y,H)
    {
        rep(x,W)
        {
            cout << c[x][y] << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll n;
    cin >> n;
    vector<ll> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }

    ll ans = 0;
    for(int i = 0; i < n-2; i++){
        vector<ll> a;
        a.push_back(p[i]);
        a.push_back(p[i+1]);
        a.push_back(p[i+2]);
        sort(all(a));
        if(a[1] == p[i+1]){ans++;}
    }

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 256
import numpy as np
import math
n, d = map(int, input().split())
x = []
for i in range(n):
    x.append(np.array(list(map(int, input().split()))))

count = 0
for i in range(n):
    for j in range(n):
        if i != j:
            d = np.linalg.norm(x[i] - x[j])
            if math.floor(d) == d:
                count += 1
print(count//2)


Measured memory_bytes: 20664
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<string.h>
#include<functional>
#include<set>
#include<string>
#include<bitset>
//aoj 0121
using namespace std;
char zzzt[8]={0,1,2,3,4,5,6,7};
char bj[8];
bitset<80000000> vis;
struct pt{
	int ztt;
	int lwz;
	int step;
};
int bs;
pt dl[1<<16];
int front=1,back=1;
int tt;
int ddd[8]={10000000,1000000,100000,10000,1000,100,10,1};
void bfs()
{
	tt=0;
	front=1;
	back=1;
	bs=0;
//	memset(vis,0,sizeof(vis));
	vis.reset();
	
	int cs=atoi(bj);
	vis[cs]=1;
	pt lsss;
	lsss.ztt=cs;
	lsss.lwz=strchr(bj,'0')-bj;
	lsss.step=0;
	dl[back]=lsss;
	back++;
	while(front<back)
	{
		pt ls1=dl[front];
		front++;
		if(ls1.ztt==1234567)
		{
			bs=ls1.step;
			tt=1;
			return;
		}
		pt lsjr;
		int kkk[4]={-1,1,-4,4};
		char sss[9];
//		sprintf(sss,"%08d", ls1.ztt);
		int tt=ls1.ztt;
		for(register int i=7;i>=0;i--){
			sss[i]=tt%10;
			tt/=10;
		}
		for(register int i=0;i<4;i++){
			lsjr.lwz=ls1.lwz+kkk[i];
			if((ls1.lwz==3&&lsjr.lwz==4) || (ls1.lwz==4&&lsjr.lwz==3)) continue;
			if(lsjr.lwz>=0&&lsjr.lwz<=7){
/*				
					int  a,b;
					a=ls1.ztt/ddd[ls1.lwz]%10;
					b=ls1.ztt/ddd[lsjr.lwz]%10;
					lsjr.ztt=ls1.ztt+(b-a)*ddd[ls1.lwz]+(a-b)*ddd[lsjr.lwz];
*/
				char t=sss[lsjr.lwz];
				sss[lsjr.lwz]=sss[ls1.lwz];
				sss[ls1.lwz]=t;
				lsjr.ztt=0;
				for(register int i=0;i<=7;i++){
					lsjr.ztt*=10;
					lsjr.ztt+=sss[i];
				}
				t=sss[lsjr.lwz];
				sss[lsjr.lwz]=sss[ls1.lwz];
				sss[ls1.lwz]=t;
				if(!vis[lsjr.ztt])
					{
						lsjr.step=ls1.step+1;
						vis[lsjr.ztt]=1;
						dl[back]=lsjr;
						back++;
					}
			}
		}
	}
}
int main()
{
//	freopen("in","r",stdin);
	while(1)
	{
		if(scanf("%c",&bj[0])==EOF)
		{
			return 0;
		}
		scanf("%*c");
		for(int i=1;i<=6;i++)
		{
			scanf("%c%*c",&bj[i]);
		}
		scanf("%c",&bj[7]);
		bfs();
		if(tt)
		{
			printf("%d\n",bs);
		}else{
			printf("-1\n");
		}
		while(getchar()!='\n');
	}
	return 0;
}



Measured memory_bytes: 12720
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

int main() {
  int n;
  cin >> n;
  set<int> s;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (!s.emplace(a).second) s.erase(a);
  }
  cout << s.size() << endl;
}



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

int main() {
	int n;
	int cards[4][13] = {};

	char suit;
	int temp;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> suit;

		switch (suit) {
		case 'S':
			cin >> temp;
			cards[0][temp-1] = 1;
			break;
		case 'H':
			cin >> temp;
			cards[1][temp-1] = 1;
			break;
		case 'C':
			cin >> temp;
			cards[2][temp-1] = 1;
			break;
		case 'D':
			cin >> temp;
			cards[3][temp-1] = 1;
			break;
		}
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			switch (i) {
			case 0:
				if (cards[i][j] != 1) {
					printf("S %d\n", j + 1);
				}
				break;
			case 1:
				if (cards[i][j] != 1) {
					printf("H %d\n", j + 1);
				}
				break;
			case 2:
				if (cards[i][j] != 1) {
					printf("C %d\n", j + 1);
				}
				break;
			case 3:
				if (cards[i][j] != 1) {
					printf("D %d\n", j + 1);
				}
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3116
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define len(x) ((int)(x).size())
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;

const ll LINF = 1e18;
const int INF = 1e9;
const int MOD = 1e9+7;

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

ll sq(ll x){ return x*x;}

int main(){

	fastio;
    int n;
    cin >> n;
    vector<ll> v(n);
    for(ll& x : v) cin >> x;
    ll menor = LINF;
    for(int i = 1; i <= 100; i++){
    	ll total = 0;
    	for(int x : v){
    		total += sq(x-i);
    	}
    	menor = min(menor, total);
    }
    cout << menor << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String s = sc.next();
			StringBuilder sb = new StringBuilder(s);
			if(sb.reverse().toString().equals(s)){
				System.out.println("Yes");
			}
			else{
				System.out.println("No");
			}
		}

	}


	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 21844
import itertools
from collections import defaultdict

N, M, Q = map(int, input().split())


seq = list(range(1, M+1))
dlist = defaultdict(list)
dres  = defaultdict(int)
Na    = 0

for i,v in enumerate(itertools.combinations_with_replacement(seq, N)):
    dlist[i] = v
    Na += 1


for i in range(Q):
    ai, bi, ci, di = map(int, input().split())
    for j in range(Na):
        tmp = dlist[j]
        if tmp[bi-1] - tmp[ai-1] == ci:
            dres[j] += di
print(max([dres[i] for i in range(Na)]))

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

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

    if (s[0] == 'A')
        cout << 'T' << endl;
    if (s[0] == 'C')
        cout << 'G' << endl;
    if (s[0] == 'G')
        cout << 'C' << endl;
    if (s[0] == 'T')
        cout << 'A' << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forn(i,a,b) for(long long i=a;i<=b;i++)
#define fork(i,a,b,k) for(long long i=a;i<=b;i+=k)
using namespace std;
typedef long long ll;
ll n,h[100005],dp[100005];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	forn(i,1,n)cin>>h[i];
	dp[1]=0;
	dp[2]=abs(h[2]-h[1]);
	forn(i,3,n){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n];
}

Measured memory_bytes: 1792
while 1:
    n, l, r = map(int, input().split())
    if n == 0: break

    a = []
    for i in range(n):
        a.append(int(input()))

    gusu = False
    if len(a) % 2 == 0: gusu = True

    count = 0
    for x in range(l, r + 1):
        for i in range(len(a)):
            comp = a[i]
            if x % comp == 0:
                if i % 2 == 0:
                    count += 1
                    break
                else: break
        else:
            if gusu: count += 1
    print(count)



Measured memory_bytes: 5600
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) (a*a)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int hist[256];

int main() {
	string str;
	cin >> str;
	LL n = str.length();
	LL ret = (n*(n - 1)) / 2+ 1;
	REP(i, n) hist[str[i]]++;
	FOR(i, 'a', 'z' + 1) {
		LL x = hist[i];
		ret -= (x*(x - 1)) / 2;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<queue>
using namespace std;
int N,M,A;
bool dp[100][100][11][11][4];
string s[100];
int dx[4]={0,-1,0,1},dy[4]={1,0,-1,0};
main()
{
	cin>>N>>M>>A;
	deque<pair<pair<int,int>,pair<pair<int,int>,int> > >Q;
	int gx,gy;
	for(int i=0;i<N;i++)
	{
		cin>>s[i];
	}
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<M;j++)
		{
			if(s[i][j]=='S'&&i+1<N&&s[i+1][j]!='#')
			{
				dp[i+1][j][A][A][3]=true;
				Q.push_back(make_pair(make_pair(i+1,j),make_pair(make_pair(A,A),3)));
			}
			else if(s[i][j]=='G')
			{
				gx=i;
				gy=j;
			}
		}
	}
	while(!Q.empty())
	{
		int x=Q.front().first.first,y=Q.front().first.second;
		int a=Q.front().second.first.first,b=Q.front().second.first.second;
		int dir=Q.front().second.second;
		Q.pop_front();
		if(x==gx&&y==gy)
		{
			cout<<2*A-a-b<<endl;
			return 0;
		}
		for(int r=-1;r<=1;r++)
		{
			if(s[x][y]!='.'&&r!=0)continue;
			int nr=(dir+r+4)%4;
			int tx=x+dx[nr],ty=y+dy[nr];
			int na=a-(dir%2==0?r==-1:r==1);
			int nb=b-(dir%2==0?r==1:r==-1);
			if(0<=tx&&tx<N&&0<=ty&&ty<M&&0<=na&&0<=nb&&s[tx][ty]!='#')
			{
				if(!dp[tx][ty][na][nb][nr]&&(s[tx][ty]!='S'||nr%2!=1))
				{
					dp[tx][ty][na][nb][nr]=true;
					if(r==0)Q.push_front(make_pair(make_pair(tx,ty),make_pair(make_pair(na,nb),nr)));
					else Q.push_back(make_pair(make_pair(tx,ty),make_pair(make_pair(na,nb),nr)));
				}
			}
		}
	}
	cout<<-1<<endl;
}



Measured memory_bytes: 5484
use proconio::{input, fastout};

fn calc(abcd: &Vec<Vec<usize>>, v: &mut Vec<usize>, ans: &mut usize) {
    let mut tmp = 0;
    for i in 0..abcd.len() {
        let a = abcd[i][0];
        let b = abcd[i][1];
        let c = abcd[i][2];
        let d = abcd[i][3];

        if v[b] == c + v[a] {
            tmp += d;
        }
    }

    if tmp > *ans {
        *ans = tmp;
    }

}

fn rec(n: usize, m: usize, abcd: &Vec<Vec<usize>>, v: &mut Vec<usize>, ans: &mut usize) {
    if n==0 {
        calc(abcd, v, ans);
    } else {
        let l = v[v.len() - 1];
        for i in l..m+1 {
            v.push(i);
            rec(n-1, m, abcd, v, ans);
            v.pop();
        }
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        m: usize,
        q: usize,
        abcd: [[usize; 4]; q],
    }

    let mut v = vec![1];
    let mut ans = 0;
    rec(n, m, &abcd, &mut v, &mut ans);
    println!("{}", ans);
}


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

typedef long long ll;

const int MAX_N = 200005;

int n, A[MAX_N], B[MAX_N], C[3 * MAX_N], KMP[3 * MAX_N];

int f(int k) {
    k %= n;
    if(k == 0) {
        k = n;
    }
    return k;
}

int main() {
    cin >> n;
    
    for(int i = 1; i <= n; i++) {
        cin >> A[i];
    }
    
    for(int i = 1; i <= n; i++) {
        cin >> B[i];
    }
    
    if(n == 1) {
        cout << "0 " << (A[1] ^ B[1]);
        return 0;
    }
    
    for(int i = 1; i <= n - 1; i++) {
        C[i] = A[i] ^ A[i + 1];
    }
    C[n] = -1;
    for(int i = n + 1; i <= 3 * n; i++) {
        C[i] = B[f(i)] ^ B[f(i + 1)];
    }
    
//     for(int i = 1; i <= 3 * n; i++) {
//         cout << C[i] << " ";
//     }
//     cout << "\n";
    
    KMP[1] = 0;
    for(int i = 2; i <= 3 * n; i++) {
        int d = KMP[i - 1];
        while(d > 0 && C[d + 1] != C[i]) {
            d = KMP[d];
        }
        KMP[i] = d;
        if(C[d + 1] == C[i]) {
            KMP[i]++;
        }
    }
    
//     for(int i = 1; i <= 3 * n; i++) {
//         cout << KMP[i] << " ";
//     }
//     cout << "\n";
    
    vector<pair<int, int> > out;
    for(int i = 2 * n; i < 3 * n; i++) {
        if(KMP[i] == n - 1) {
            int k = i - 2 * n + 1;
            k = n - k;
            out.push_back(make_pair(k, A[1 + k] ^ B[1]));
        }
    }
    sort(out.begin(), out.end());
    
    for(pair<int, int> p : out) {
        cout << p.first << " " << p.second << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 11624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

int N;

int A,B;

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

    int dif = abs(A - B);

    if(dif % 2 == 0)
    {
        cout << "Alice";
    }
    else
    {
        cout << "Borys";
    }
    return 0;
}

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

int main(void){
    
  int N,max;
  string S;
  cin >> N >> S;

  for(int i=1;i<N;i++){
      string l,r;
      set<char> set_l;
      set<char> set_r;
      set<char> result;
      
      l = S.substr(0,i);
      r = S.substr(i);
     
      for(int j=0;j<l.size();j++) set_l.insert(l[j]);
      for(int j=0;j<r.size();j++) set_r.insert(r[j]);
      
      set_intersection(set_l.begin(),set_l.end(),set_r.begin(), set_r.end(),inserter(result, result.end()));
      if(i == 1) max = result.size();
      else{ if(max < result.size()) max = result.size();}
  }
  
  cout << max << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const int N=3e5+20;
const double eps=1e-10;
//题意:两个人A,B都有string,长度为n,从A开始,每次轮流从中取出一个,A想让字典序小,B想让字典序尽量大,问最后组成长度为n的string?
//n/2轮,A肯定从前n/2小选,B肯定从前n/2大选
//情况1:如果a最小比b最大还小,则b肯定先用最小的占高位
//情况1:如果a最小比b最大还大,则a用最大的占领最低位 
int a,b,c;
int main()
{
	while(cin>>a>>b>>c)
	{
		if(c>=a&&c<=b)
			puts("Yes");
		else
			puts("No");
	}
	
	return 0;
}

Measured memory_bytes: 256
///not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair<int, pair<int, int> >
#define pf push_front

const int maxn = 1000* 100 + 5;
int ans[maxn],
mx = 0;
vector <int> aj[maxn],
ind[maxn];
bool mrk[maxn];

void dfs(int v, int x){
    mrk[v] = true;
    xmax(mx, SZ(aj[v]));
    int p = 1;
    for(int j = 0; j < SZ(aj[v]); j ++){
        int u = aj[v][j], i = ind[v][j];
        if(!mrk[u]){
            if(p == x)
                p ++;
            ans[i] = p;
            dfs(u, p);
            p ++;
        }
    }
    return;
}

int32_t main(){
    int n;
    cin >>n;
    for(int i = 0; i < n - 1; i ++){
        int u, v;
        cin >>u >>v;
        u --;
        v --;
        aj[v].pb(u);
        aj[u].pb(v);
        ind[v].pb(i);
        ind[u].pb(i);
    }
    dfs(0, 0);
    cout <<mx <<endl;
    for(int i = 0;i < n - 1; i ++){
        cout <<ans[i] <<' ';
    }
    return false;
}


Measured memory_bytes: 13696
#include<iostream>

using namespace std;

int main(){
	int n;
	cin >> n;
	int m=0,a=0,c=0,x=0;
	cin >>m;
	for(int i=1;i<n;i++)
	{
		cin>>a;
		if(a<=m)
			c++;
		else 
		{
			x=max(x,c);
			c=0;
		}
		m=a;
	}
	x=max(x,c);
	cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <limits.h>
using namespace std;

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


Measured memory_bytes: 256
package main
import "fmt"

func main() {
  var (
    A int
    B int
    C int
    D int
    train int
    bus int
  )
  fmt.Scan(&A)
  fmt.Scan(&B)
  fmt.Scan(&C)
  fmt.Scan(&D)

  if A > B {
    train = B
  } else {
    train = A
  }

  if C > D {
    bus = D
  } else {
    bus = C
  }

  fmt.Println(train + bus)
  
}


Measured memory_bytes: 512
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()



int main()
{
  string a;
  cin >> a;
  cout << (a[2] == a[3] && a[4] == a[5] ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<string>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
	int N;
	int M;
	cin >> N >> M;
	vector<int>L(M);
	vector<int>R(M);
	
	for(int i = 0;i<M;i++){
		cin >> L[i]>> R[i];
	}	
	
	int Lmax = 0;
	int Rmin = 1000001;
	
	for(int i = 0;i<M;i++){
		if(Lmax<L[i]){
			Lmax = L[i];
		}
		if(Rmin>R[i]){
			Rmin = R[i];
		}
	}
	
	int ans = Rmin - Lmax + 1;
	
	if(ans>0){
		std::cout << ans <<endl; 	
		return 0;
	}else{
		std::cout << "0" <<endl; 	
		return 0;
	}
	
}

Measured memory_bytes: 3980
#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 MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  string T;
  cin >> T;
  REP(i,T.size()){
    if(T.at(i)=='?'){
      T.at(i)='D';
    }
  }
  int ans = 0;
  REP(i,T.size()){
    if(T.at(i)=='D'){
      ans++;
    }
  }
  REP(i,T.size()-1){
    if(T.at(i)=='P'&&T.at(i+1)=='D'){
      ans++;
    }
  }
  cout << T << endl;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define N 500003
#define MOD 1000000007
using namespace std;


int main()
{
    int n;
    cin>>n;
    int a[n][3];
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++)
            cin>>a[i][j];
    }
    int dp[n][3]={0};
    for(int i=0;i<3;i++){
        dp[0][i]=a[0][i];
    }
    for(int i=1;i<n;i++){

        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j!=k)
                dp[i][j]=max(a[i][j]+dp[i-1][k],dp[i][j]);
            }
        }
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

}


Measured memory_bytes: 2560
#include<iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include<set>
using namespace std;
int main()
{
    int N;
    int ans = 1;
    cin >> N;
    string S;
    cin >> S;
    for (int i = 1; i < N; i++){
        if (S[i - 1] != S[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;    
}


Measured memory_bytes: 512
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


n = I()
d = IR(n)
print(len(set(d)))


Measured memory_bytes: 67856
"use strict";

function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0], 10);
  var A = [];

  for (var i = 0; i < N; i++) {
    A.push(parseInt(input[i + 1], 10));
  }

  var mod = 998244353;
  var S = A.reduce(function (p, c) {
    return p + c;
  }); // R, Gにしないパターン

  var dp = new Array(N + 1); // R, G, Bにするパターン

  var dp1 = new Array(N + 1);

  for (var _i = 0; _i <= N; _i++) {
    dp[_i] = new Array(S + 1).fill(0);
    dp1[_i] = new Array(S + 1).fill(0);
  }

  dp[0][0] = 1;
  dp1[0][0] = 1;

  for (var _i2 = 0; _i2 <= N; _i2++) {
    for (var j = 0; j <= S; j++) {
      var diff = j - A[_i2 - 1];

      if (_i2 > 0 && diff >= 0) {
        // Rにするパターン
        dp[_i2][j] += dp[_i2 - 1][diff];
        dp1[_i2][j] += dp1[_i2 - 1][diff];
      }

      if (_i2 > 0) {
        // Gにするパターン
        dp[_i2][j] += dp[_i2 - 1][j]; // G or Bにするパターン

        dp1[_i2][j] += 2 * dp1[_i2 - 1][j];
      }

      dp[_i2][j] %= mod;
      dp1[_i2][j] %= mod;
    }
  }

  var total = 1;

  for (var _i3 = 0; _i3 < N; _i3++) {
    total *= 3;
    total %= mod;
  }

  var sum = 0;
  var sum1 = 0;

  for (var _i4 = parseInt(S / 2, 10); _i4 <= S; _i4++) {
    if (_i4 >= S / 2) {
      sum += dp1[N][_i4];
    }

    if (_i4 === S / 2) {
      sum1 += dp[N][_i4];
    }

    sum %= mod;
    sum1 %= mod;
  }

  console.log((total - 3 * sum % mod + 3 * sum1 % mod + mod) % mod);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 665384
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n, k, c; cin>>n>>k>>c;
    string s; cin>>s;

    vector<int> sdp(n+1), gdp(n+1);
    sdp[0] = gdp[n] = 0;
    rep(i,n) {
        if (s[i] == 'x') {
            sdp[i+1] = sdp[i];
            continue;
        }
        int mae = max(0ll, i-c);
        sdp[i+1] = max(sdp[mae]+1, sdp[i]);
    }

    for (int i = n-1; i >= 0; --i) {
        if (s[i]=='x') {
            gdp[i] = gdp[i+1];
            continue;
        }
        int mae = min(n, i+c+1);
        gdp[i] = max(gdp[mae]+1, gdp[i+1]);
    }

    // print(sdp);
    // print(gdp);
    if (sdp[n] == k) {
        map<int,int> mp;
        int cur = 0;
        rep(i,n) {
            if (s[i] == 'x') continue;
            if (cur!=sdp[i+1]) {
                cur = sdp[i+1];
                mp[i]++;
            }
        }
        cur = 0;
        for (int i = n-1; i >= 0; --i) {
            if (s[i]=='x') continue;
            if (cur != gdp[i]) {
                cur = gdp[i];
                mp[i]++;
            }
        }
        for (auto &&e: mp) {
            if (e.second==2) cout << e.first+1 << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 12676
<?php
  fscanf(STDIN,"%d %d",$n,$m);
  $l_list = [];
  $r_list = [];
  for($i=0; $i<$m; $i++){
    fscanf(STDIN,"%d %d",$l,$r);
    $l_list[] = $l;
    $r_list[] = $r;
  }
  if(max($l_list)>min($r_list)){
    echo "0\n";
  }else{
    echo (abs(max($l_list)-min($r_list))+1)."\n";
  }

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

struct TNode
{
	int Index;
	TNode* Parent;
	TNode* Left;
	TNode* Right;
	
	TNode();
};

TNode::TNode()
{
	Index  = -1;
	Parent = NULL;
	Left   = NULL;
	Right  = NULL;
}

typedef std::vector<TNode> TBinaryTree;
void Initialize(TBinaryTree& BinaryTree)
{
	for(unsigned int i = 0; i < BinaryTree.size(); ++i){
		BinaryTree[i].Index = i + 1;
	}
}

typedef std::vector<TNode*> TOrder;

void InputNodes(TBinaryTree& Tree, TOrder& PreOrder, TOrder& InOrder)
{
	for(unsigned int i = 0; i < Tree.size(); ++i){
		int Index;
		std::cin >> Index;
		PreOrder[i] = &(Tree[Index - 1]);
	}
	for(unsigned int i = 0; i < Tree.size(); ++i){
		int Index;
		std::cin >> Index;
		InOrder[i] = &(Tree[Index - 1]);
	}
}

TOrder::iterator GetPreOrderNext(TOrder::iterator Node, int Count)
{
	TOrder::iterator Next = Node;
	for(int i = 0; i < Count; ++i) ++Next;
	return Next;
}

void ReconstructTree(TOrder::iterator PreOrderPos,
	                 TOrder::iterator PreOrderLast,
	                 TOrder::iterator InOrderBegin,
	                 TOrder::iterator InOrderLast)
{
	if(PreOrderPos == PreOrderLast) return;
	TOrder::iterator Position = std::find(InOrderBegin, InOrderLast + 1, *PreOrderPos);
	TOrder::iterator Left  = GetPreOrderNext(PreOrderPos, 1);
	TOrder::iterator Right = GetPreOrderNext(PreOrderPos, 1 + distance(InOrderBegin, Position));
	if(Position != InOrderBegin){
		(*PreOrderPos)->Left = *Left;
		(*Left)->Parent = *PreOrderPos;
		ReconstructTree(Left, Right - 1, InOrderBegin, Position - 1);
	}
	if(Position != InOrderLast){
		(*PreOrderPos)->Right = *Right;
		(*Right)->Parent = *PreOrderPos;
		ReconstructTree(Right, PreOrderLast, Position + 1, InOrderLast);
	}
}

void OutputPostOrder(const TNode* Root, const TNode* End)
{
	if(Root == NULL) return;
	OutputPostOrder(Root->Left, End);
	OutputPostOrder(Root->Right, End);
	std::cout << Root->Index;
	if(Root != End){
		std::cout << " ";
	}else{
		std::cout << std::endl;
	}
}

int main()
{
	int Count;
	std::cin >> Count;
	TBinaryTree BinaryTree(Count);
	Initialize(BinaryTree);
	TOrder PreOrder(Count);
	TOrder InOrder(Count);
	
	InputNodes(BinaryTree, PreOrder, InOrder);
	
	ReconstructTree(PreOrder.begin(), PreOrder.end() - 1, InOrder.begin(), InOrder.end() - 1);
	
	TNode* Root = *(PreOrder.begin());
	OutputPostOrder(Root, Root);
	
	return 0;
}

Measured memory_bytes: 3108
#![allow(dead_code, unused_variables, unused_macros, unused_imports)]

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

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let mut ans: i64 = a.iter().map(|a| a.abs()).sum();
    let minus_cnt = a.iter().filter(|&a| *a < 0).count();
    if minus_cnt % 2 == 1 {
        if let Some(min) = a.iter().map(|a| a.abs()).min() {
            ans -= 2 * min;
        }
    }
    println!("{}", ans);
}


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


int main(void)
{	
	int x,t,ans=0;
	scanf("%d %d",&x,&t);
	
	ans=x-t;
	
	if(ans>=0){
		printf("%d\n",ans);
	} else{
		printf("0\n");
	}
	return 0;
}


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

const int MAX = 110000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<ll> nums(N);
    for (int i = 0; i < N; i++)
    {
        ll A;
        cin >> A;
        nums.at(i) = A;
    }
    COMinit();
    sort(nums.begin(), nums.end());
    if(nums.at(0) < 0){
        ll firstNum = nums.at(0);
        for(int i = 0; i < N; i++){
            nums.at(i) += firstNum;
        }
    }
    ll max = 0;
    for (int i = K - 1; i < N; i++)
    {
        max = (max + COM(i, K - 1) * nums.at(i)) % MOD;
    }
    ll min = 0;
    for (int i = 0; i < N - K + 1; i++)
    {
        min = (min + (COM(N - i - 1, K - 1) * nums.at(i))) % MOD;
    }
    ll answer = (max - min + MOD) % MOD;

    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 100001
vector<vector<int> > arr(max1);


int main(){	
	int n;
	cin>>n;
	vector<int> a(n);
	int freq[max1]={0};
	long long int sum=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		sum+=a[i];
		freq[a[i]]+=1;
	}
	int q;
	cin>>q;
	while(q--){
		long long int b,c;
		cin>>b>>c;
		sum+=freq[b]*(c-b);
		cout<<sum<<endl;
		freq[c]+=freq[b];
		freq[b]=0;

	}



}

Measured memory_bytes: 6396
n = int(input())
a, b = map(int, input().split())
P = list(map(int, input().split()))

x = 0
y = 0
z = 0
for p in P:
    if p <= a:
        x += 1
    elif a+1 <= p <= b:
        y += 1
    else:
        z += 1
print(min([x, y, z]))

Measured memory_bytes: 9168
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int[] c = {sc.nextInt(),sc.nextInt(),sc.nextInt()};
		Arrays.sort(c);
		System.out.println(c[0]+c[1]);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35892
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <stack>
using namespace std;

int ans;
vector<int> s;
void solve(stack<int> stk, const string& str, unsigned int p)
{
	if (str.size() == p) {
		if (stk.top() == 15)
			++ans;
		return;
	}

	int st = 0;
	for (; p < str.size(); ++p) {
		if (str[p] == '0')
			break;
		stk.push(s[str[p] - '0' - 1]);
		++st;
	}

	int a = stk.top();
	stk.pop();
	int b = stk.top();
	stk.pop();

	stk.push(a|b);
	solve(stk, str, p+1);
	stk.pop();

	stk.push(a&b);
	solve(stk, str, p+1);
	stk.pop();

	stk.push(a^b);
	solve(stk, str, p+1);
	stk.pop();
}

int main()
{
	for ( ; ; ) {
		string tree;
		getline(cin, tree);
		if (tree == "END")
			break;

		for (string::iterator it = tree.begin(); it != tree.end(); ) {
			if ((*it) == '(' || (*it) == ' ') {
				it = tree.erase(it);
			} else if ((*it) == ')') {
				*it = '0';
			} else {
				++it;
			}
		}

		int n;
		cin >> n;
		s.clear();
		for (int i = 0; i < n; ++i) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			s.push_back(a*8 + b*4 + c*2 + d);
		}
		
		ans = 0;
		solve(stack<int>(), tree, 0);
		cout << ans << endl;

		// skip '\n'
		getline(cin, tree);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int h,n;
int si[10005][4];
int dp[10005][5];
int main(void){
   cin>>h>>n;
   for(int i=0;i<n;i++){
       int a,b;
       cin>>a>>b;
       for(int j=b;j>=b-1;j--){
           for(int k=a;k>=a-1;k--){
               if(k>=0&&j>=0&&k<3&&j<h-1)si[j+1][k]=1;
           }
       }
   }
   
   for(int i=1;i<h;i++){
       if(si[i][0]==1||si[i][2]==1)si[i][3]=1;
   }
   
   
   
   for(int i=1;i<=h;i++){
       if(si[i][0]==0)dp[i][0]=max(dp[i-1][2],dp[i-1][4])+1;
       if(si[i][1]==0)dp[i][1]=dp[i-1][4]+1;
       if(si[i][2]==0)dp[i][2]=max(dp[i-1][0],dp[i-1][4])+1;
       if(si[i][3]==0)dp[i][3]=dp[i-1][4]+2;
       for(int j=0;j<5;j++)dp[i][4]=max(dp[i][4],dp[i-1][j]);
   }
   cout<<dp[h][4]<<endl;
}

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

ll f[110][2],bin[110];
int h[110],n,tt;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline ll pls(const ll &x,const ll &y) { return (x+y<mod)?x+y:x+y-mod; }
inline ll mns(const ll &x,const ll &y) { return (x-y<0)?x-y+mod:x-y; }
inline ll ksm(ll x,ll y) { ll res=1;for (;y;y>>=1,x=x*x%mod) if (y&1) res=res*x%mod;return res; }

inline void pre_gao()
{
	bin[0]=1;
	for (int i=1;i<=n;i++) bin[i]=bin[i-1]*2%mod;
}

inline void solve(int l,int r)
{
	int id=++tt,mn=h[l];
	for (int i=l;i<=r;i++) mn=min(mn,h[i]);
	ll g[110][2];
	memset(g,0,sizeof(g));
	g[l-1][0]=0;g[l-1][1]=2;
	for (int i=l;i<=r;i++)
	{
		if (h[i]==mn)
		{
			g[i][0]=pls(g[i-1][0]*2%mod,(i==l)?0:g[i-1][1]);
			g[i][1]=g[i-1][1];
		}
		else
		{
			int j=i;
			for (;j<=r&&h[j]>mn;j++);j--;
			for (int k=i;k<=j;k++) h[k]-=mn;
			int now=tt+1;solve(i,j);
			g[j][0]=pls(g[i-1][0]*pls(f[now][0],f[now][1]*2%mod)%mod,(i==l)?f[now][0]:g[i-1][1]*pls(f[now][0],f[now][1])%mod);
			g[j][1]=g[i-1][1]*f[now][1]%mod;
			i=j;
		}
	}
	f[id][0]=g[r][0];f[id][1]=g[r][1]*ksm(2,mn-1)%mod;
}

int main()
{
	n=rd();pre_gao();
	for (int i=1;i<=n;i++) h[i]=rd();
	solve(1,n);
	printf("%lld\n",pls(f[1][0],f[1][1]));
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

const int N = 3010;
const long long inf = (1 << 50);

int n, i, j, v[N], x, y;
long long m[N][N], M[N][N];

inline long long minim(long long x, long long y) {
    return (x < y ? x : y);
}

inline long long maxim(long long x, long long y) {
    return (x > y ? x : y);
}

int main() {
	cin >> n;
	for (i = 1; i <= n; ++i) {
        cin >> v[i];
	}
	for (i = 1; i <= n; ++i) {
		M[i][i] = v[i];
        m[i][i] = -v[i];
		for (j = i + 1; j <= n; ++j) {
            M[i][j] = -inf;
            m[i][j] = inf;
		}
	}
	for (i = 2; i <= n; ++i)
		for (x = 1, y = i; y <= n; ++x, ++y) {
			M[x][y] = maxim(m[x + 1][y] + v[x], m[x][y - 1] + v[y]);
			m[x][y] = minim(M[x + 1][y] - v[x], M[x][y - 1] - v[y]);
		}
    cout << M[1][n] << "\n";
    return 0;
}


Measured memory_bytes: 141568
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  
  solve <$> replicateM 4 (getl toInt) >>= print

solve :: [Int] -> Int
solve [n,k,x,y] 
  | n > k = k * x + (n-k) * y
  | otherwise = n * x

toInt :: String -> Int
toInt = read

getl :: (String -> a) -> IO a
getl f = f <$> getLine


Measured memory_bytes: 508
def main(): 

    n = int(input())
    a = [int(input()) for _ in range(n)]

    max_v = 0
    max_sv = 0

    for i in range(n):
        if a[i] > max_v:
            max_sv = max_v
            max_v = a[i]
        elif a[i] > max_sv:
            max_sv = a[i]

    for i in range(n):
        if a[i] != max_v:
            print(max_v)
        else:
            print(max_sv)




if __name__ == "__main__":
    main() 

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

int main() {
int N;
string S;
cin >> N >> S;
string judge = "No";
int count = 0;
if (N % 2 == 0) {
    for (int i = 0; i < N / 2; i++) {
        if (S.at(i) == S.at(i + N / 2)) {
            count++;
        }
    }
    if (count == N / 2) {
        judge = "Yes";
    }
}
cout << judge << endl;
}

Measured memory_bytes: 256
import java.util.*
import java.math.*
import java.lang.Math.*

val readString: ()->String = {readLine()!!}
val readInt: ()->Int = {readLine()!!.toInt()}
val readLong: ()->Long = {readLine()!!.toLong()}
val readIntArray: ()->IntArray = {readLine()!!.split(' ').map{it.toInt()}.toIntArray()}
val readLongArray: ()->LongArray = {readLine()!!.split(' ').map{it.toLong()}.toLongArray()}
val errPrintln: (String)->Unit = {msg -> System.err.println(msg)}
val MOD = 1e9.toLong()+7
val INF = Int.MAX_VALUE/2
val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)


fun zAlgo(S: String): IntArray {
    val N = S.length
    if (N == 0) return IntArray(0)
    val ln = IntArray(N){0}
    ln[0] = N
    var i = 1
    var w = 0
    while (i < N) {
        while (i+w < N && S[w] == S[i+w]) {
            w++
        }
        ln[i] = w
        if (w == 0) {
            i++
        } else {
            var j = 1
            while (i+j < N && j+ln[j] < w) {
                ln[i+j] = ln[j]
                j++
            }
            i += j
            w -= j
        }
    }
    return ln
}


fun solve(S: String): Int {
    val N = S.length
    var res = 0

    for (i in 0 until N) {
        val wd = S.substring(i)
        val ln = zAlgo(wd)

        for (j in 1 until ln.size) {
            res = max(res, min(j, ln[j]))
        }
    }

    return res
}


fun main(args: Array<String>) {
    val N = readInt()
    val S = readString()

    val ans = solve(S)

    println(ans)
}


Measured memory_bytes: 56524
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <numeric>

using namespace std;

struct {
    constexpr int operator()(const int a, const int b) const {
        return a == 0 ? b : operator()(b % a, a);
    }
} gcdes;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> A;
    A.reserve(n);
    copy_n(istream_iterator<int>(cin), n, back_inserter(A));

    vector<int> pre;
    pre.reserve(n);
    partial_sum(A.begin(), A.end(), back_inserter(pre), gcdes);

    vector<int> post(n);
    partial_sum(A.rbegin(), A.rend(), post.rbegin(), gcdes);

    int ans = max(pre[n - 2], post[1]);
    for (int i = 1; i < n - 1; ++i) {
        ans = max(ans, gcdes(pre[i - 1], post[i + 1]));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ld long double
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

////////////////////////////////////////////////////////


int main() {
    ll n; cin >> n;
    Vl a(n);
    rep(i, 0, n) cin >> a[i];
    Vl dp(n, 0);
    
    ll ans = 0;
    if(a[0] > 0) dp[0] = a[0];
    else {
        dp[0] = 1;
        ans += abs(1 - a[0]);
    }
    rep(i, 1, n){
        ll sum = dp[i-1] + a[i];
        if(dp[i-1] < 0){
            if(sum > 0) dp[i] = sum; //ok
            if(sum <= 0){
                ll ai = 1 - dp[i-1];
                ans += abs(ai - a[i]);
                dp[i] = 1;
            }
        }
        if(dp[i-1] > 0){
            if(sum < 0) dp[i] = sum; //ok
            if(sum >= 0){
                ll ai = -1 - dp[i-1];
                ans += abs(ai - a[i]);
                dp[i] = -1;
            }
        }
    }

    rep(i, 0, n) dp[i] = 0;
    ll cnt = 0;
    if(a[0] < 0) dp[0] = a[0];
    else {
        dp[0] = -1;
        cnt += abs(-1 - a[0]);
    }
    rep(i, 1, n){
        ll sum = dp[i-1] + a[i];
        if(dp[i-1] < 0){
            if(sum > 0) dp[i] = sum; //ok
            if(sum <= 0){
                ll ai = 1 - dp[i-1];
                cnt += abs(ai - a[i]);
                dp[i] = 1;
            }
        }
        if(dp[i-1] > 0){
            if(sum < 0) dp[i] = sum; //ok
            if(sum >= 0){
                ll ai = -1 - dp[i-1];
                cnt += abs(ai - a[i]);
                dp[i] = -1;
            }
        }
    }

    chmin(ans, cnt);
    co(ans);

    return 0;
}


Measured memory_bytes: 4844
#include <iostream>
#include <vector>

using namespace std;

struct edge {
  int dest;
  int weight; // = dest minus curr
};

class UF {
public:
  vector<edge> v;
  UF(int n) { v = vector<edge>(n, {-1, 0}); }

  void uf_union(int x, int y, int y_minus_x) {
    auto x_res = uf_find(x);
    auto y_res = uf_find(y);
    int loc_x = x_res.dest;
    int loc_y = y_res.dest;
    if (loc_x == loc_y)
      return;
    if (v[loc_x].dest <
        v[loc_y].dest) { // x's set has more elements -- join y to x
      v[loc_x].dest += v[loc_y].dest;
      v[loc_y] = {loc_x, x_res.weight - y_res.weight - y_minus_x};
    } else {
      v[loc_y].dest += v[loc_x].dest;
      v[loc_x] = {loc_y, y_res.weight - x_res.weight + y_minus_x};
    }
  }
  void uf_union(int x, int y) { uf_union(x, y, 0); }

  edge uf_find(int x) {
    if (v[x].dest < 0)
      return {x, 0};
    edge tmp = uf_find(v[x].dest);
    tmp.weight += v[x].weight;
    v[x] = tmp;
    return v[x];
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  UF uf(n);
  int c, x, y;
  while (cin >> c >> x >> y) {
    if (c == 0) {
      int z;
      cin >> z;
      uf.uf_union(x, y, z);
    }
    if (c == 1) {
      edge x_res = uf.uf_find(x);
      edge y_res = uf.uf_find(y);
      if (x_res.dest != y_res.dest) {
        cout << "?" << endl;
      } else {
        cout << x_res.weight - y_res.weight << endl;
      }
    }
  }
}


Measured memory_bytes: 3600