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

int main() {
  int a, b,c,d;
  cin >> a >> b>>c>>d ;
  
  if(a+b>c+d){
    cout<<"Left"<<endl;
  }
  else if(a+b==c+d){
  cout << "Balanced" << endl;
  }
  else{
    cout<<"Right"<<endl;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
string s;
int main()
{	
	SPEED;
	cin>>s;
	for(int j=0;j<s.length()-1;j++)
	{
		if(s[j]==s[j+1])
			return cout<<j+1<<" "<<j+2<<endl,0;
	}
	for(int j=0;j+2<s.length();j++)
	{
		ll freq[26]={0};
		for(int i=j;i<j+3;i++)
			freq[s[i]-'a']++;
		if(*max_element(freq,freq+26)==2)
			return cout<<j+1<<" "<<j+3<<endl,0;
	}
	cout<<-1<<" "<<-1<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>

int main(){
    int res = 0;
    int l, r, n; scanf("%d%d%d", &l, &r, &n);
    for (int i = l; i <= r; i++)
        if (i%n == 0) res++;
    printf("%d\n", res);

    return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();

        var s = sc.next();
        var list = new List<int>();
        int cnt = 0;

        for (int i = 0; i < s.Length; i++)
        {
            if (!list.Contains((int)s[i])) list.Add((int)s[i]);
            else if (i != s.Length - 1) cnt++;
        }

        if (list.Count == 2 && cnt == 1) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11104
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)

n,m = map(int,input().split())
l = []
for i in range(n):
    p = list(map(int,input().split()))
    l += p[1:]
g = gb(sorted(l))
res = 0
for k,v in g:
    q = len(list(v))
    if (q == n):
        res += 1
print(res)


Measured memory_bytes: 5076
n, x = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(1, n):
    b.append(a[i] + a[i - 1])
b.append(0)

res = 0
for i in range(n - 1):
    dif = max(b[i] - x, 0)
    minus = min(dif, a[i + 1])
    b[i + 1] -= minus
    b[i] -= dif
    res += dif

print(res)


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

int main() {
    string s;
    cin >> s;
    for(int i = 0; i < s.size() - 1; i++){
        if(s.at(i) == 'A' && s.at(i + 1) == 'C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define rep(i, x) for(int i = 0; i < (int)(x); i++)
#define reps(i,x) for(int i = 1; i <= (int)(x); i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x,y) memset(x,y,sizeof(x))
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define debug(x) cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define INF 999999999
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  int f = 0;
  int n = x;
  while (true){
    f += n%10;
    n /= 10;
    if (n==0) break;
  }

  cout << (x%f?"No":"Yes") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    string O,E;
    cin >> O >> E;
    for (int i = 0; i < O.size() + E.size(); ++i) {
        if(i%2 == 0){
            cout << O[i/2];
        }else{
            cout << E[(i-1)/2];
        }
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  vector<string>in(9);
  cout<<'R';
  rep(i,9)cin>>in[i];
  int x=1,y=0;
  int to=0;
  //int co=0;
  while(x||y){
    //co++;
    //if(co>50)break;
    //cout<<x<<" "<<y<<" "<<to<<endl;
    if(to==0){
      if(y!=0&&in[2*y-1][x]=='1'){
	y--;to=3;cout<<'U';
      }else if(x!=4&&in[2*y][x]=='1'){
	x++;cout<<'R';
      }else if(y!=4&&in[2*y+1][x]=='1'){
	y++;to=1;cout<<'D';
      }else if(x!=0&&in[2*y][x-1]=='1'){
	to=2;x--;cout<<'L';
      }
    }else if(to==1){
      if(x!=4&&in[2*y][x]=='1'){
	x++;to=0;cout<<'R';
      }else if(y!=4&&in[2*y+1][x]=='1'){
	y++;to=1;cout<<'D';
      }else if(x!=0&&in[2*y][x-1]=='1'){
	to=2;x--;cout<<'L';
      }else if(y!=0&&in[2*y-1][x]=='1'){
	y--;to=3;cout<<'U';
      }
    }else if(to==2){
      if(y!=4&&in[2*y+1][x]=='1'){
	y++;to=1;cout<<'D';
      }else if(x!=0&&in[2*y][x-1]=='1'){
	to=2;x--;cout<<'L';
      }else if(y!=0&&in[2*y-1][x]=='1'){
	y--;to=3;cout<<'U';
      }else if(x!=4&&in[2*y][x]=='1'){
	x++;to=0;cout<<'R';
      }
    }else if(to==3){
      if(x!=0&&in[2*y][x-1]=='1'){
	to=2;x--;cout<<'L';
      }else if(y!=0&&in[2*y-1][x]=='1'){
	y--;to=3;cout<<'U';
      }else if(x!=4&&in[2*y][x]=='1'){
	x++;to=0;cout<<'R';
      }else if(y!=4&&in[2*y+1][x]=='1'){
	y++;to=1;cout<<'D';
      }
    }
  }
  cout<<endl;
}

Measured memory_bytes: 1184
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
print(math.ceil(n / 2)/ n)

Measured memory_bytes: 74932
/*
	  - - 
这次如果Ac我吃土 
*/ 
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define pb push_back
#define mp make_pair
#define INF 9999999
#define LINF 9999999999999999
#define SINF "%"
#define uint unsigned int
#define msn(a,v) memset(a,v,sizeof(a))
#define ms(a) msn(a,0)
#define NONE -1
#define ll long long
#define ull unsigned ll
#define uchar unsigned char
#define sint short int
#define usint unsigned sint
#define xsize(a) sizeof(a)/1024/1024
#define fr(aaaaa,bbbbb) for(aaaaa = 1;aaaaa <= bbbbb;aaaaa++)
#define frr(aaaaa,bbbbb,ccccc) for(aaaaa = ccccc;aaaaa <= bbbbb;aaaaa++)
using namespace std;
#define MAXN 100100
#define MOD 1000000007

ll n,a,b;
ll data[MAXN];
ll dp[MAXN]; 

int main(){
	//freopen("C.txt","r",stdin);
	data[0] = -1000000000000000000;
	
	scanf("%lld %lld %lld",&n,&a,&b);
	if(a > b) swap(a,b);
	for(int i = 1;i <= n;i++)
		scanf("%lld",&data[i]);
	
	for(int i = 1;i <= n-2;i++)
		if(data[i+2] - data[i] < a){
			printf("0\n");
			return 0;
		}
	ms(dp);
	dp[0] = 1;
	ll now = 0;
	ll lastpos = 0;
	for(int i = 1;i <= n;i++){
		//在 (0,i] 之间找到最小的lastpos,使data[i]和data[lastpos]不可以被同时放到Y中 
		for(;lastpos < i  &&  data[i] - data[lastpos] >= b;lastpos++){
			now = (now + dp[lastpos]) % MOD;
		}
		dp[i] = now;
		if(data[i] - data[i-1] < a){
			now = 0;
			lastpos = i-1;
		}
	}
	
	for(int i = lastpos;i <= n;i++){
		now = (now + dp[i]) % MOD;
	}
	
	printf("%lld\n",now);
	
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
	char s[100];
	int k=0,l=0;
	scanf("%s",s);
	for(int i=0;i<100;i +=2)
	{
		if(s[i]=='L')
			k++;
	}
	for(int i=1;i<100;i +=2)
	{
		if(s[i]=='R')
			l++;
	}
	if((l==0)&&(k==0))
		printf("Yes");
	else
		printf("No");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int N, K;
const long long NMAX=100010;
vector<long long> h(NMAX, 0);
vector<long long> dp(NMAX, LLONG_MAX);

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

    REP(i, N) cin>>h[i];

    dp[0] = 0;
    REP(i,N-1){
        REP2(j, 1, K+1){
            if((i+j)>N) break;
            chmin(dp[i+j], dp[i]+abs(h[i+j]-h[i]));
        }
    }

    cout << dp[N-1] << endl;

   return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        int empty = a - b;
        
        if (c - empty < 0) {
            System.out.println(0);
        } else {
            System.out.println(c - empty);   
        }
    }
}


Measured memory_bytes: 21716
#include<iostream>
#include<cmath>
#include<queue>
#include<map>
#include<vector>
using namespace std;
typedef long long int LL;
const int INF=1e9+7;
vector<int> path[3];

void path_insert(int a,int b,int l){
	path[0].push_back(a);
	path[1].push_back(b);
	path[2].push_back(l);
}

int main(){
	int n,m,l;
	int i,j,k;
	cin>>l;
	l--;
	n=20,m=60;
	for(i=0;i<n-1;i++){
		if(l==0){
			n=i+1;
			break;
		}
		if(l%2==0)path_insert(i,INF,l/2);
		path_insert(i,i+1,0);
		path_insert(i,i+1,l/2+1);
		l=(l-1)/2;
	}
	m=path[0].size();
	cout<<n<<" "<<m<<endl;
	for(i=0;i<m;i++){
		path[0][i]++;
		if(path[1][i]==INF)path[1][i]=n;
		else path[1][i]++;
		cout<<path[0][i]<<" "<<path[1][i]<<" "<<path[2][i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
N = int(input())
p = [0, 0, 0]*N

p = [list(map(int, input().split())) for _ in range(N)]
p = sorted(p, key=lambda x:-x[2])
for cx in range(101):
	for cy in range(101):
		H = abs(p[0][0]-cx)+abs(p[0][1]-cy)+p[0][2]
		for i in range(N):
			# if H != abs(x[i]-cx)+abs(y[i]-cy)+h[i]:
			if p[i][2] != max(H-abs(p[i][0]-cx)-abs(p[i][1]-cy), 0):
				break
			if i == N-1:
				ans = [cx, cy, H]
				break
print(ans[0],ans[1],ans[2])


Measured memory_bytes: 3064
a, b, c, x, y = map(int, input().split())
ans = max(0, x)*a + max(0, y)*b # ABピザを一枚も買わなかった時
for i in range(100001):
    tmp = i*2*c + max(0, x-i)*a + max(0, y-i)*b
    if ans > tmp:
        ans = tmp
print(ans)


Measured memory_bytes: 2940
#include <cstdio>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i))
using ll = long long;
using namespace std;
constexpr int mod = 1e9+7;
int main() {
    int n; scanf("%d", &n);
    // count free sequences
    vector<ll> dp(2*n);
    vector<ll> acc(2*n+1);
    dp[0] = 1;
    acc[1] = 1;
    repeat_from (i,1,2*n) {
        int l = max(0, i-n-1);
        int r = max(0, min(n-1, i-2));
        dp[i] = (acc[r] - acc[l] + (i-1 < n-1 ? dp[i-1] : 0)) % mod;
        acc[i+1] = (acc[i] + dp[i]) % mod;
    }
    // compute the result
    ll result = 0;
    repeat (i,n-1) {
        result += dp[i] * (n-1) % mod * (n-1) % mod;
    }
    result += dp[n-1] * n % mod;
    repeat_from (i,n,2*n) {
        result += dp[i] % mod;
    }
    result %= mod;
    if (result < 0) result += mod;
    printf("%lld\n", result);
    return 0;
}


Measured memory_bytes: 31488
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
using namespace std;

int main() {

	int D, T, S;
	cin >> D >> T >> S;

	if (T * S >= D) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3632
N,K=map(int,input().split())
p=list(map(int,input().split()))
array=[]

a=sum(p[0:K])
array.append(a)

for n in range(N-K):
  a=a-p[n]+p[n+K]
  array.append(a)

ans=(max(array)+K)/2
print(ans)
  

Measured memory_bytes: 25060
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int w,h,c,x,y,i,g,a,b;
	scanf("%d %d %d",&w,&h,&c);
	x=w;	y=h;
	if(x<y)	swap(x,y);
	while(1)	{
		a=x%y;
		if(a==0)	break;
		x=y;	y=a;
	}
	b=(w/y)*(h/y)*c;
	printf("%d\n",b);
	return 0;
}


Measured memory_bytes: 2732
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn=1e5+100;
string s;
int n;
map<pair<string, string>, ll >m;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin>>n;
    cin>>s;
    for(int i=0; i<1<<n; i++)
    {
        string a, b;
        for(int j=0; j<n; j++)
        {
            if(i&(1<<j))a+=s[j];
            else b+=s[j];
        }
        reverse(all(a));
        m[{a, b}]++;
    }
    ll ans=0;
    for(int i=0; i<1<<n; i++)
    {
        string a, b;
        for(int j=0; j<n; j++)
        {
            if(i&(1<<j))a+=s[j+n];
            else b+=s[j+n];
        }
        reverse(all(b));
        ans+=m[{a, b}];
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 87040
# coding: utf-8
# Your code here!

# バスが運行することになる駅の組み合わせが存在する場合は Yes を、存在しない場合は No を出力せよ。

s = input()

if s == 'AAA' or s == 'BBB':
    print('No')
else:
    print('Yes')

Measured memory_bytes: 2940
using System;

class Program {
    static void Main( string[] args )
    {
        Console.ReadLine();

        string[] numbers = Console.ReadLine().Split();

        for ( int i = numbers.Length - 1; i > 0; --i ) {
            Console.Write( numbers[ i ] + " " );
        }

        Console.WriteLine( numbers[ 0 ] );
    }
}

Measured memory_bytes: 8776
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

struct BIT // 0-indexed
{
    ll n;
    vector<ll> bit;
    // 初期化
    void init(ll n_input)
    {
        n = n_input + 1;
        bit.resize(n + 1);
        for (ll i = 0; i <= n; i++)
        {
            bit[i] = 0;
        }
    }
    // v[0] + ... + v[k-1]
    ll sum(ll k)
    {
        ll res = 0;
        for (ll i = k - 1; i >= 0; i = (i & (i + 1)) - 1)
        {
            res += bit[i];
        }
        return res;
    }
    // v[i] + ... + v[j]
    ll sum_between(ll i, ll j)
    {
        return i <= j ? sum(j + 1) - sum(i) : 0;
    }
    // v[k] += x
    void add(ll k, ll x)
    {
        for (ll i = k; i < n; i |= i + 1)
        {
            bit[i] += x;
        }
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll lb = 0;
    ll ub = 1LL << 30;
    ll hansu = ((n * (n + 1) / 2) + 1) / 2;
    BIT b;
    while (ub - lb > 1)
    {
        ll mid = (ub + lb) / 2;
        ll tmp = 0;
        b.init(2 * n + 1);
        ll res = 0;
        b.add(tmp + n, 1);
        for (ll i = 0; i < n; i++)
        {
            if (a[i] >= mid)
            {
                tmp++;
            }
            else
            {
                tmp--;
            }
            res += b.sum(tmp + n + 1);
            b.add(tmp + n, 1);
        }
        if (res >= hansu)
        {
            lb = mid;
        }
        else
        {
            ub = mid;
        }
    }
    cout << lb << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define bg begin()
#define end end()
#define sz size()
#define vi vector<int>
#define vl vector<long long int>
int main(){
	fast;
ll n;
	cin>>n;
	string s;
	cin>>s;
	ll cnt=0;
	string t="";
	for(ll i=0;i<n;i++)
	{
		if(s[i]==')' && cnt==0)
			t='('+t;
		else if(s[i]==')') 
			cnt--;
		else	
			cnt++;
		t+=s[i];
	}
	while(cnt>0)
	{
		t+=')';
		cnt--;
	}
	cout<<t;
	return 0;
}



Measured memory_bytes: 3640
from itertools import groupby
 
class UnionFind:
 
    def __init__(self, n):
        self.n = n
        self.parents = list(range(n))
        self.rank = [0] * n
        self.size = [1] * n
 
    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        root_x = self.find(x)
        root_y = self.find(y)
        if self.rank[root_x] < self.rank[root_y]:
            self.parents[root_x] = root_y
            self.size[root_y] += self.size[root_x]
        else:
            self.parents[root_y] = root_x
            self.size[root_x] += self.size[root_y]
            if self.rank[root_x] == self.rank[root_y]:
                self.rank[x] += 1
    
    def is_same(self, x, y):
        return self.find(x) == self.find(y)
 
    def get_size(self, x):
        return self.size[self.find(x)]
 
    def get_group(self):
        arr = sorted([(self.find(node), node) for node in range(self.n)])
        groups = []
        for _, g in groupby(arr, key=lambda x: x[0]):
            groups.append([u[1] for u in g])
        return groups

    
N, M = map(int, input().split())
bridges = []
for _ in range(M):
    bridges.append(list(map(lambda x: int(x)-1, input().split())))
U = UnionFind(N)
F = [N * (N-1) // 2]
for i in range(M-1):
    if not U.is_same(*bridges[M-i-1]):
        F.append(F[i] - U.get_size(bridges[M-i-1][0]) * U.get_size(bridges[M-i-1][1]))
        U.union(*bridges[M-i-1])
    else:
        F.append(F[i])
F.reverse()
for f in F:
    print(f)

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


int main()
{
   vector<int> arr(5);
   int mindig = 10;
   for(int i=0;i<5;i++)
   {
      cin>>arr[i];
      if(arr[i]%10)
         mindig = min(mindig,arr[i]%10);
   }
   ll sum = 0;
   for(int i=0;i<5;i++)
   {
      if(arr[i]%10 == 0)
         sum += arr[i];
      else
      {
         sum += (10 - arr[i]%10) + arr[i];
      }
   }
   sum -= 10 - mindig;
   cout<<sum;
   return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
int main()
{
    int m, n,i;
    bool lag = true;
    scanf("%d%d",&m,&n);
    char a[m+n+2];
    scanf("%s",a);
    for(i = 0; a[i] != '\0';i++)
    {
        if(i == m)
        {
            if(a[i] != '-')
            {
                lag = false ;
                break;
            }
        }
        else
        {
            if(a[i] < 48 || a[i] > 57)
            {
                lag = false ;
                break;
            }
        }
    }
    printf(lag ? "Yes":"No");
    return 0;
}


Measured memory_bytes: 256
fun main(args : Array<String>) {
    val list = mutableListOf<Int>()
    (0..4).forEach {
        list.add(readLine()!!.toInt())
    }



    list.sortBy {
        val lastDigit = it.mod(10)

        if (lastDigit == 0) {
            -10
        } else {
           lastDigit * -1
        }
    }

    var sum = 0
    list.forEachIndexed { index, value ->
        if (index == list.size - 1) {
            sum += value
        } else {
            val mod = value.mod(10)

            if (mod == 0) {
                sum += value
            } else {
                sum += value + (10 - mod)
            }
        }
    }

    println(sum)
}


Measured memory_bytes: 33492
m, k = map(int, input().split())

if k >= 2**m:
    print(-1)
    exit()
if m == 0:
    if k == 0:
        print(0, 0)
    else:
        print(-1)
    exit()
if m == 1:
    if k == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)
    exit()

x, y = [i for i in range(k)], [j for j in range(k+1, 2**m)]
l = x+y
r = list(reversed(l))
ans = l+[k]+r+[k]
print(*ans)


Measured memory_bytes: 18368
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

string s,t,u;
cin >> s >> t >> u;

yn(s[SZ(s)-1] == t[0] && t[SZ(t)-1] == u[0],"YES","NO");

return 0;
}


Measured memory_bytes: 256
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int n;
vector<int>v[100005];
int dp[2][100005];
int mod=1e9+7;
int dfs(int pos,int par,int cl)
{
    if(v[pos].size()==1 && par!=0)
        return 1;
    int &ans=dp[cl][pos];
    if(ans!=-1)
        return ans;
    ans=1;
    for(int i:v[pos])
        if(i!=par)
        {
            if(cl==0)
                ans*=dfs(i,pos,0)+dfs(i,pos,1);
            else
                ans*=dfs(i,pos,0);
            ans%=mod;
        }
    dp[cl][pos]=ans%mod;
    return dp[cl][pos];
}
int32_t main() 
{
    IOS;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    if(n==1)
        return cout<<2,0;
    memset(dp,-1,sizeof(dp));
    print((dfs(1,0,0)+dfs(1,0,1))%mod);
}


Measured memory_bytes: 19008
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
typedef pair<int, int> pos;


int main()
{
	int h, w;
	cin >> h >> w;
	char map[55][55];
	int dist[55][55], dy[4] = { 0,0,1,-1 }, dx[4] = { 1,-1,0,0 }, count = 0;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> map[i][j];
			dist[i][j] = -1;
			if (map[i][j] == '.') {
				count++;
			}
		}
	}
	
	queue<pos> hold;
	hold.push(pos(1, 1));
	dist[1][1] = 1;
	bool reach = false;

	while (!hold.empty()) {
		pos temp = hold.front();
		hold.pop();
		if (temp.first == h && temp.second == w) {
			break;
		}
		for (int i = 0; i < 4; i++) {
			int ny = temp.first + dy[i], nx = temp.second + dx[i];
			if (1 <= ny && ny <= h && 1 <= nx && nx <= w && map[ny][nx] == '.'&& dist[ny][nx] == -1) {
				hold.push(pos(ny, nx));
				dist[ny][nx] = dist[temp.first][temp.second] + 1;
			}
		}
	}
	if (dist[h][w] == -1) {
		cout << -1 << endl;
	}
	else
		cout << count - dist[h][w] << endl;
	return 0;

}

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

int	main()
{
	const static int64_t	inf = static_cast<int64_t>(1e+12 + 1);
	int	N, M, P;
	cin >> N >> M >> P;
	vector<int64_t>	v_score(N, -inf);
	vector<tuple<int, int, int>> e_score(M);
	int	A, B, C;
	for (int i = 0; i < M; ++i) {
		cin >> A >> B >> C;
		--A; --B;
		e_score.at(i) = make_tuple(A, B, C - P);
		// if (!e_score.count(A))
		// 	e_score[A] = map<int, int64_t>();
		// if (!e_score.at(A).count(B))	
		// 	e_score.at(A)[B] = C - P;
		// else if (C - P > e_score.at(A).at(B))
		// 	e_score.at(A)[B] = C - P;
	}
	v_score.at(0) = 0;
	int64_t	score;
	bool	updated;
	for (int i = 0; i < N; ++i) {
		updated = false;
		for (int j = 0; j < M; ++j) {
			tie(A, B, C) = e_score.at(j);
			if (v_score.at(A) == -inf)
				continue;
			score = v_score.at(A) + C;
			if (score > v_score.at(B)) {
				v_score.at(B) = score;
				updated = true;
			}
		}
		if (!updated)
			break;
	}
	if (!updated) {
		if (v_score.at(N - 1) > 0)
			cout << v_score.at(N - 1) << endl;
		else
			cout << 0 << endl;
		return 0;
	}
	vector<bool>	has_upper(N, true);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M; ++j) {
			tie(A, B, C) = e_score.at(j);
			if (v_score.at(A) == -inf)
				continue;
			score = v_score.at(A) + C;
			if (score > v_score.at(B)) {
				v_score.at(B) = score;
				has_upper.at(B) = false;
			}
			if (!has_upper.at(A))
				has_upper.at(B) = false;
		}
	}
	if (has_upper.at(N - 1)) {
		if (v_score.at(N - 1) > 0)
			cout << v_score.at(N - 1) << endl;
		else
			cout << 0 << endl;
	} else
		cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL  
struct node{
  struct node *r;
  struct node *l;
  struct node *p;
  int key;
};
 
typedef struct node * Node;
Node root;
void insert(int k);
void inorderTreeWalk(Node x);
void preorderTreeWalk(Node x);
  
int main()
{
  char str[7];
  int m,i,x;
  scanf("%d",&m);
  for( i=0 ; i<m ; i++ ){
    scanf("%s",str);
    if(str[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(str[0]=='p'){
      inorderTreeWalk(root);
      printf("\n");
      preorderTreeWalk(root);
      printf("\n");
    }
  }
  return 0;
   
}

void insert(int k)
{
  Node x;
  Node y;
  Node z;
  y = NIL;
  x = root;
  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;
   
  while(x!=NIL){
    y=x;
    if(z->key<x->key) x = x->l;
    else x = x->r;
  }
  z->p = y;
 
  if(y==NIL) root = z;
  else if(z->key<y->key) y->l = z;
  else y->r = z;
}
 
void inorderTreeWalk(Node x)
{
  if(x==NIL) return;
  inorderTreeWalk(x->l);
  printf(" %d",x->key);
  inorderTreeWalk(x->r);
}
 
void preorderTreeWalk(Node x)
{
  if(x==NIL) return;
    printf(" %d",x->key);
    preorderTreeWalk(x->l);
    preorderTreeWalk(x->r);
   
}

Measured memory_bytes: 24040
#include "bits/stdc++.h"
    
using namespace std;
vector<long long >dp(100001,-1);
vector<long long>num;
long long  erg(int n){
	if(dp[n]!=-1){
		return dp[n];
	}
	if(n<0){
		return 2000000000000;
	}
	if(n==0){
		return 0;
	}
	long long cmp1=max(num[n],num[n-1])-min(num[n],num[n-1]),cmp2=max(num[n],num[n-2])-min(num[n],num[n-2]);
	dp[n]= min(erg(n-1)+cmp1,erg(n-2)+cmp2);
	return dp[n];
}
int main() {
	int menge,numm;
	cin>>menge;
	for(int i=0;i<menge;i++){
		cin>>numm;
		num.push_back(numm);
	}
cout<<erg(menge-1);
    return 0;
}

Measured memory_bytes: 4340
s_array = gets.chomp.split("")

ret = "Yes"
s_array.each_with_index do |e, i|
    if i.odd?
        if !["L", "U", "D"].include?(e)
            ret = "No"
            break
        end
    else
        if !["R", "U", "D"].include?(e)
            ret = "No"
            break
        end
    end
end

puts ret

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

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

    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < i; ++j)
        {
            for (int k = 0; k < j; ++k)
            {
                if (v[k] != v[j] and v[i] != v[j] and
                    v[k] + v[j] > v[i])
                {
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;

public class Main {
    public static void main(String[] args) {
      
      Scanner sc = new Scanner(System.in);
      int a = Integer.parseInt(sc.next());
      int b = Integer.parseInt(sc.next());
      int max = a + b;
      if (a - b > max) {
        max = a -b;
      }
      if (a * b > max) {
        max = a * b;
      }
      System.out.println(max);
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N; cin >> N;
  vector<pair<ll, ll>> p;
  REP(i, N) {
    ll x, y; cin >> x >> y;
    p.push_back(make_pair(x, y));
  }
  sort(all(p));
  map<pair<ll, ll>, ll> m;
  REP(i, N) {
    REP(k, N) {
      if(i == k) continue;
      auto x = make_pair(p[i].first - p[k].first, p[i].second - p[k].second);
      m[x]++;
    }
  }
  ll a = 0;
  for(auto x : m) {
    if(a < x.second) a = x.second;
  }
  cout << N - a << endl;
}

Measured memory_bytes: 3752
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

m = int(input())

print(abs(m-24)+24)






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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    
    ll n; cin>>n;
    vector<tuple<string,ll,ll>> a;
    for(ll i=1;i<=n;i++){
        string s;
        ll p;
        cin>>s>>p;
        p=-p;
        a.push_back(tie(s,p,i));
    }
    sort(all(a));

    rep(i,n){
        cout<< get<2>(a[i]) <<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++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;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;cin>>a;
    string ans;
    if(a<1200){
        ans = "ABC";
    }else if (a<2800)
    {
        ans = "ARC";
    }else {
        ans = "AGC";
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 61;
const lli INF = 1e18;
const lli MOD = 13;
const double EPS=1e-4;

bool m[N];
vi primes(1,2);
void sieve(){
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

// ---- コーディングはここから！ ('-')7


int main(){_
	int a; cin>>a;
	cout<<a+a*a+a*a*a<<ENDL;

}


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

int main() {
long double a,b;
cin >> a >> b;
long long ans = a*b;

cout << ans<<endl;
}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

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

int main(){
    int a;
    cin >> a;
    int i = a;
    for(;;i++){
        int x = int(sqrt(i));
        bool flag = true;
        for(int j = 2;j < x; j++){
            if(!(i % j)){
                flag = false;
                break;
            }
        }
        if(flag)break;
    }
    cout << i << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int64_t n;
    int64_t count = 0;
    int64_t sub = 0;
    cin >> n;

    vector<int> human(n);

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

    for (int i = 1; i < n; i++)
    {
        if (human[i] < human[i - 1])
        {
            sub = human[i - 1] - human[i];
            count += sub;
            human[i] = human[i] + sub;
        }
    }

    cout << count;

    return 0;
}

Measured memory_bytes: 3952
from collections import defaultdict
import pprint

N, M = [int(s) for s in input().split()]

citydict = defaultdict(list)

for _ in range(M):
    a, b = [int(s) for s in input().split()]
    citydict[a].append(b)
    citydict[b].append(a)

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


Measured memory_bytes: 3828
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  N = 1e6 + 5;

int main(){
	ll a;cin>>a;
	string s;cin>>s;
	ll b=0;
	for(auto c:s){
		if(c=='.') continue;
		b=b*10+(c-'0');
	}
	cout<<a*b/100<<'\n';
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
typedef long long ll;

int main(){
    int k;
    char a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    scanf("%d", &k);
    printf("%d\n", a[k-1]);

    return 0;
}


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

using namespace std;
long long n,a,b,c,dpa[300010],dpb[300010],dpc[300010];
int main()
{
    cin >>n;
    cin>>dpa[0]>>dpb[0]>>dpc[0];
    for(int i=1;i<n;i++)
    {
        cin >>a>>b>>c;
        dpa[i]=a+max(dpb[i-1],dpc[i-1]);
        dpb[i]=b+max(dpa[i-1],dpc[i-1]);
        dpc[i]=c+max(dpb[i-1],dpa[i-1]);
    }
    cout <<max(max(dpa[n-1],dpb[n-1]),dpc[n-1]);
    return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std ;
#define pb push_back
#define endl '\n'
#define x first
#define y second
int a[3][3];

int main(){
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	int n,b;
	cin>>n;
	while(n--){
		cin>>b;
		for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
		if(a[i][j]==b)
		a[i][j]=0;
	}
	for(int i=0;i<3;i++){
		int p=0,q=0;
		for(int j=0;j<3;j++){
			p+=a[i][j];
			q+=a[j][i];
		}
		if(p==0||q==0){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	if(a[0][0]+a[1][1]+a[2][2]==0||a[0][2]+a[1][1]+a[2][0]==0){
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
}

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

int sosu(int n){
int i;
if(n==1){return 0;}
if(n==2){return 1;}
for(i = 2; i<n; i++){
if(n%i == 0) return 0;
}
return 1;
}
int kaijo(int n, int m){
  int res=1,i;
  for(i=0;i<m;i++){
    res=res*n;
  }
  return res;
}
int main(){
  int i,j=1,x,y;
  long long int c=1,yk=1,tmp;
  int b[1002];

  for(i=0;i<1002;i++){
    b[i]=1;
  }
  for(i=0;i<9;i++){
    c=c*10;
  }
  c=c+7;

  scanf("%d",&x);

  for(i=1;i<=x;i++){
    if(sosu(i)==1){
      tmp=i;
      while(1){
        if(tmp>x){break;}
      y=x/tmp;
      b[i]=b[i]+y;
      j++;
      tmp=kaijo(i,j);
      }
      j=1;
    }
  }
  for(i=0;i<=x;i++){
    yk=yk*b[i];
    yk=yk%c;
  }

  printf("%I64d\n",yk);
  return 0;
}

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

int main() {
  string S,ans="No";
  cin >> S;
  if(S[2]==S[3] &&S[4]==S[5]) ans="Yes";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
x = int(input())
ans = 0
if x == 2:
    ans = 2
elif x == 3:
    ans = 3
else:
    for i in range(x,100004):
        check = True
        root = int(i ** 0.5) + 1
        for j in range(2,root):
            if i % j == 0:
                check = False
                break
            else:
                continue
        if check:
            ans = i
            break
print(ans)

Measured memory_bytes: 9388
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int n;
    cin >> n;

    vector<int> a;
    a.resize(n);
    int m = 1000000000;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        m = min(m, a[i]);
    }

    int g = a[0];
    for (int i=1; i<n; i++) {
        g = __gcd(g, a[i]);
    }

    cout << g << endl;
    return 0;
}

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

using namespace std;

#define ALL(x) x.begin(), x.end()

typedef long long int lld;
typedef pair<int, int> pii;

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

	int n = 0;
	cin >> n;
	double res = 0;

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

		res += pow(a, -1);
	}

	cout << pow(res, -1) << endl;


	return 0;
}

Measured memory_bytes: 256
//knapsack
#include<bits/stdc++.h>
using namespace std;
int n,w;
int weights[105];
long long values[105];
long long knapsack(){
	long long arr[n+1][w+1];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=w;j++){
			if(i==0 || j==0)arr[i][j]=0;
			else if(weights[i-1]>j)
				arr[i][j]=arr[i-1][j];
			else if(weights[i-1]<=j){
				arr[i][j]=max(arr[i-1][j],values[i-1]+arr[i-1][j-weights[i-1]]);
			}
		}
	}
	return arr[n][w];
}
int main(){
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin>>n>>w;
	for(int i=0;i<n;i++){
		cin>>weights[i]>>values[i];
	}
	cout<<knapsack()<<endl;
	return 0;
}

Measured memory_bytes: 79232
N,K = map(int, input().split())
P = list(map(int, input().split()))
A = []
#A.append(P[0])
for i in range(N):
    k=((1+P[i])*(P[i]))/(2*P[i])
    A.append(k)
c=0
for i in range(K):
    c+=A[i]
ans=c
#print(A)
for i in range(K,N):
    c=c-A[i-K]+A[i]
    if(ans<c):
        ans=c
print(ans)


Measured memory_bytes: 25060
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int P = 998244353;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
char s[MAXN], t[MAXN];
bool vis[MAXN];
int n, ans, val[MAXN];
void update(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}
int cnt(int x) {
	int ans = 0;
	for (int i = 1; i <= x; i++)
		ans = ((ans * 2) + (s[i] - '0')) % P;
	for (int i = 1, j = 1; i <= n; i++, j = (j == 2 * x) ? 1 : (j + 1))
		if (j <= x) t[i] = s[j];
		else t[i] = s[j - x] ^ 1;
	for (int i = 1; i <= n; i++) {
		if (s[i] > t[i]) return ans + 1;
		if (t[i] > s[i]) return ans;
	}
	return ans + 1;
}
int main() {
	read(n), scanf("%s", s + 1);
	for (int i = 1; i <= n; i++)
		if (n % i == 0 && (n / i) % 2 == 1) vis[i] = true;
	int ans = 1ll * cnt(n) * (2 * n) % P;
	for (int i = n - 1; i >= 1; i--) {
		if (!vis[i]) continue;
		int now = 2 * n;
		for (int j = i; j <= n; j += i)
			if (vis[j]) update(now, val[j]);
		val[i] = 2 * i;
		update(val[i], P - now);
		update(ans, 1ll * cnt(i) * val[i] % P);
	}
	writeln(ans);
	return 0;
}

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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}

int main(){
  int n;
  string s,t;
  cin >> n;
  cin >> s;
  cin >> t;

  int mslide = 0;
  rep(i,n){
    rep(j,n-i){
      if(s[i+j] != t[j]){
        break;
      }
      if(j == n-i-1){
        cout << n + i << endl;
        return 0;
      }
    }
  }
  cout << n * 2 << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	as := ReadInts(N)
	bs := ReadInts(N)

	var ar, br int
	for i := 0; i < N; i++ {
		a, b := as[i], bs[i]
		if a > b {
			ar += a - b
		} else {
			br += (b - a) / 2
		}
	}

	if ar > br {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 2352
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
a_min = min( x//500 ,a)
for ai in range(a_min+1):
    rem_a = x - (ai * 500)
    if rem_a == 0:
        cnt+=1
        break
    b_min = min( rem_a//100 ,b)
    for bi in range(b_min+1):
        rem_b = rem_a - (bi * 100)
        if rem_b == 0 :
            cnt+=1
            break
        if (rem_b % 50 == 0 and rem_b // 50 <= c ):
            cnt+=1
            continue
print(cnt)

Measured memory_bytes: 9196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  char x; cin >> x;
  if('a'<=x && x<='z') cout << 'a' << endl;
  else cout << 'A' << endl;
  return 0;
}


Measured memory_bytes: 3632