akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{

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

        int N = sc.nextInt();
        
        int[] B = new int[N-1];
        for(int i = 0; i < N-1; i++){
            B[i] = sc.nextInt();
        }
        sc.close();
        long sum = 0;
        for(int i = 0; i < N; i++){
            if(i == 0)
                sum += B[i];
            else if(i != N-1) {
                sum += Math.min(B[i], B[i-1]);
            } else {
                sum += B[i-1];
            }
        }

        System.out.println(sum);
    }
}

Measured memory_bytes: 23124
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;

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

ll max_i[200005];
ll min_i[200005];

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

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

    ll sum=0;
    for(int i=k;i<=n+1;i++){
        sum += (max_i[n-i+1]-min_i[i-1]+1)%MOD;
        sum %= MOD;
    }
    cout << sum << endl;

}

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

main(){

  ll n;
  cin>>n;
  vector<string> s(n);
  rep(i,n)cin>>s[i];

  rep(i,n)sort(s[i].begin(),s[i].end());
  map<string,ll> cnt;
  rep(i,n)cnt[s[i]]++;
  ll ans=0;
  auto f=[](ll n){return n*(n-1)/2;};
  for(auto elm:cnt){
    ans+=f(elm.second);
  }
  cout<<(ans)<<endl;

}

Measured memory_bytes: 18176
R,G,B,N=map(int, input().split())
rmax=N//R
gmax=N//G
ans=0
for r in range(rmax+1):
  for g in range(gmax+1):
    if N-(r*R+g*G)>=0 and (N-(r*R+g*G))%B==0:
      ans+=1
print(ans)

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

#define pii pair<int,int>
#define MAXN 110
#define MAXS 100100

vector<pii> vec;
long long tab[MAXS][MAXN];
int n;

long long dp(int w, int ind){
    if(w == 0 || ind == n) return 0;
    if(tab[w][ind] >= 0) return tab[w][ind];
    long long coloca = (w - vec[ind].first >= 0)? vec[ind].second + dp(w-vec[ind].first, ind+1) : 0;
    long long nao_coloca = dp(w, ind+1);
    tab[w][ind] = max(coloca, nao_coloca);
    return max(coloca, nao_coloca);
}

int main(){
    int r;
    scanf("%d%d", &n, &r);
    vec.resize(n);
    memset(tab,-1,sizeof tab);
    for(int i = 0, p, v; i < n; i++){
        scanf("%d%d", &p ,&v);
        vec[i] = make_pair(p, v);
    }
    printf("%lld\n", dp(r, 0));
}

Measured memory_bytes: 86400
#include <stdio.h>

int main(){
	char ch;
	while(1){
		scanf("%c", &ch);
		if(ch == '\n')break;
		if(islower(ch)){
			ch = toupper(ch);
		} else if(isupper(ch)){
			ch = tolower(ch);
		} else {
			;
		}
		printf("%c", ch);
	}
	printf("\n");
	return 0;
}

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

int main() {
  int sum =0;
  int dif =0;
  vector<int> n(5);
  vector<int> m(5);
  for(int i =0;i<5;i++)
    cin >> n[i];
  
  for(int i =0;i<5;i++){
    if(n[i]%10!=0){
      m[i] = (n[i]/10+1)*10;
      dif = max(dif,m[i]-n[i]);
    }
    else
      m[i]=n[i];
    sum += m[i];
  }
  cout << sum - dif << endl;
}

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

int main(){
  
	int h,w;
  	cin >> h >> w;
  	string board[50];
  	
  	for(int i = 0; i < h ; i++) cin >> board[i];
  	
  	const int dx[8] ={ 1, 0,-1, 0, 1,-1,-1, 1};
  	const int dy[8] ={ 0, 1, 0,-1, 1, 1,-1,-1};
  	
  	for(int i = 0; i < h; i++){
    	for(int j = 0; j < w;j++){
        	if(board[i][j]=='#')continue;
          	
          	int num = 0;
          	for(int d = 0; d < 8; ++d){
            	const int ni = i + dy[d];
              	const int nj = j + dx[d];
            	
              	if(ni < 0 or h <= ni)continue;
              	if(nj < 0 or w <= nj)continue;
              	if(board[ni][nj]=='#') num++;
            }
            
            board[i][j] = char(num + '0');
            
            
		}
          
    }
  	
  	for(int i = 0; i < h ; ++i) cout << board[i] <<endl;
  	return 0;
  	
  	

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

// const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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 ctoi(char c){return c-'0';}


// TODO: write
int main() {
  ll n,m;cin>>n>>m;
  string s,t;cin>>s>>t;
  ll num = lcm(n,m);
  
  map<int,char> tmp;
  rep(i,n){
    tmp[i*(num/n)] = s[i];
  }
  
  rep(i,m){
    if(tmp[i*(num/m)] != t[i] && tmp[i*(num/m)] != '\0'){
      print(-1);
      return 0;
    }
  }

  print(num);
  return 0;
}



Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define MP make_pair
#define FR first
#define SE second
using namespace std;

const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
    if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
    if(H==T) return -1;return *H++;
}
inline int read()
{
    int x=0;char c=Get();
    while(!isdigit(c)) c=Get();
    while(isdigit(c)) x=x*10+c-'0',c=Get();
    return x;
}

const int N=200010;
struct Edge{int to,next;} e[N<<1];
int fa[N],sz[N],n,m,h[N],sum=0;
pair<int,int> circle[N];
bool parity[N],odd[N];
int cnt[2];

int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}

void add_edge(int u,int v)
{
    e[++sum].to=v;
    e[sum].next=h[u];
    h[u]=sum;
}

void dfs(int u,int fa)
{
    parity[u]=parity[fa]^1;
    for(int t=h[u];t;t=e[t].next)
        if(e[t].to!=fa) dfs(e[t].to,u);
}

int main()
{
    int u,v,tot=0;
    n=read();m=read();
    for(int i=1;i<=n;i++) fa[i]=i,sz[i]=1;
    for(int i=1;i<=m;i++)
    {
        u=read();v=read();
        if(find(u)!=find(v))
        {
            add_edge(u,v);
            add_edge(v,u);
            u=find(u);v=find(v);
            fa[u]=v;sz[v]+=sz[u];
        }
        else circle[++tot]=MP(u,v);
    }
    for(int i=1;i<=n;i++)
        if(fa[i]==i) dfs(i,0);
    for(int i=1;i<=tot;i++)
        if(parity[circle[i].FR]==parity[circle[i].SE])
            odd[find(circle[i].FR)]=1;
    int alone=0;
    long long ans=0;
    for(int i=1;i<=n;i++)
    {
        if(fa[i]!=i) continue;
        if(sz[i]==1) alone++,ans+=n;
        else cnt[odd[i]]++;
    }
    ans+=1ll*(n-alone)*alone;
    ans+=2ll*cnt[0]*cnt[0];
    ans+=1ll*cnt[1]*(cnt[1]+2*cnt[0]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>

using namespace std;

int main()
{
    long long n,c, d[32][32], clr[502][502],cnt[3][32];
    long long ans=9999999999999999;
    memset(cnt, 0, sizeof(cnt));
    cin>>n>>c;
    for (int i=1; i<=c; i++) for (int j=1; j<=c; j++) cin>>d[i][j];
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
            cin>>clr[i][j];
            cnt[(i+j)%3][clr[i][j]]++;
        }
    }
    for (int i=1; i<=c; i++)
    {
        for (int j=1; j<=c; j++)
        {
            for (int k=1; k<=c; k++)
            {
                if (!(i!=j && j!=k && i!=k)) continue;
                long long cost=0;
                for (int l=1; l<=c; l++)
                {
                    cost+=d[l][i]*cnt[0][l];
                    cost+=d[l][j]*cnt[1][l];
                    cost+=d[l][k]*cnt[2][l];
                }
                ans=min(ans, cost);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

class DAG
{
    int n;
    vector<vector<int>> adj;
    vector<int> visited;
    vector<int> dp;
    void dfs(int v)
    {
        if (visited[v] == 2)
        {
            is_acyclic = false;
            return;
        }
        else if (!visited[v])
        {
            visited[v] = 2;
            for (int s : adj[v])
            {
                dfs(s);
            }
            visited[v] = 1;
            sorted.push_back(v);
        }
    }

public:
    vector<int> sorted;
    DAG(int n) : n(n), adj(n), visited(n), dp(n) {}
    bool is_acyclic = true;
    int longest_path = 0;

    void add_arc(int a, int b)
    {
        assert(0 <= a && a < n && 0 <= b && b < n);
        adj[a].push_back(b);
    }

    void tsort()
    {
        for (int i = 0; i < n; i++)
        {
            if (!visited[i])
                dfs(i);
        }
        reverse(sorted.begin(), sorted.end());
    }
    void build()
    {
        for (auto i : sorted)
        {
            for (auto j : adj[i])
            {
                dp[j] = max(dp[j], dp[i] + 1);
                longest_path = max(longest_path, dp[j]);
            }
        }
    }
};
vector<int> v[1000];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    DAG dag(n*n);
    rep(i, n)
    {
        rep(j, n - 1)
        {
            int x;
            cin >> x;
            v[i].push_back(--x);
        }
    }
    rep(i, n)
    {
        rep(j, n - 2)
        {
            int t = min(i, v[i][j]) * (n) + max(i, v[i][j]);
            dag.add_arc(t, min(i, v[i][j + 1]) * (n) + max(i, v[i][j + 1]));
        }
    }
    dag.tsort();
    if (dag.is_acyclic == false)
    {
        cout << -1 << endl;
    }
    else
    {
        dag.build();
        cout << dag.longest_path+1 << endl;
    }
}


Measured memory_bytes: 57456
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
    ($line:expr, $name:ident, $t:tt) => {
        let $name = value!($line, $t);
    };
}

macro_rules! values_def {
    ($lines:expr, $n:expr, $name:ident, $t:tt) => {
        let $name = {
            let mut vec = Vec::new();
            for i in 0..$n {
                let mut next = $lines.next().unwrap().split_whitespace();
                vec.push(value!(next, $t));
            }
            vec
        };
    };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(s:#));
    s.chars().filter(|&c| c == '1').count().to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "111100" => "4",
    test2: "001001" => "2",
    test3: "000000" => "0",
}


Measured memory_bytes: 4352
#include <iostream>
#include <climits>
#include <cmath>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <utility>
#include <sstream>
#include <algorithm>
#include <stack>
#include <set>
#include <list>
#include <map>
#include <queue>
#include <vector>
#include <stdint.h> //uint32_t

typedef long long ll;
typedef double lf;

#define ull unsigned long long

#define FileIn(file) freopen("input.txt", "r", stdin)
#define FileOut(file) freopen("output.txt", "w", stdout)
#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0)

#define For(i, a, b) for (__typeof (a) i=a; i<=b; i++)
#define Rof(i, b, a) for (__typeof (a) i=b; i>=a; i--)
#define Rep(i, n) for (__typeof (n) i=0; i<n; i++)
#define Forit(i, s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define all(ar) ar.begin(), ar.end()
#define fill(ar, val) memset(ar, val, sizeof(ar))
#define clr(a) memset(a, 0, sizeof a)
#define sfll(a) scanf("%lld", &a)
#define pfll(a) printf("%lld", a)
#define sflf(a) scanf("%lf", &a)
#define pflf(a) printf("%lf", a)
#define sff(a) scanf("%f", &a)
#define pff(a) printf("%f", a)
#define sf(a) scanf("%d", &a)
#define pf(a) printf("%d", a)
#define nl cout << '\n';
#define SP cout << ' ';
#define gc getchar
#define chk cout << "##########\n"
#define debug1(x) cout << #x << ": " << x << endl
#define debug2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl
#define debug3(x, y, z) cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z << endl

#define PB push_back
#define max(a, b) (a < b ? b : a)
#define min(a, b) (a > b ? b : a)
#define sq(a) a * a
#define INF 0x7fffffff
#define MOD 1000000007
#define PI acos(-1.0)
#define MAX 100000000

using namespace std;

/********************* Code starts here ************************/

int main() {
    __FastIO;
    int n{};
    cin >> n;
    vector<int> arr(n);
    vector<int> DP(n);
    for(int i = 0; i < n; i++) cin >> arr[i];
    for(int i = 0; i < n; i++){
        if(i == 0) DP[i] = 0;
        else if(i == 1) DP[i] = abs(arr[i] - arr[i - 1]);
        else{
            DP[i] = min(DP[i - 1] + abs(arr[i] - arr[i - 1]), DP[i - 2] + abs(arr[i] - arr[i - 2]));
        }
    }
    cout << DP[n - 1];
}


Measured memory_bytes: 1024
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.List
import           Data.Maybe

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

main = do
  nums <- readInts
  putStrLn $ solve nums

solve (a:b:c:_)
  | a + b + c >= 22 = "bust"
  | otherwise = "win"


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


typedef long long ll;
typedef pair<ll,int> P;

struct edge {int to; ll cost; };

int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n;
  cin >> n;
  int ans[4]={};
  for(int i=0; i<n; i++){
    string s;
    cin >> s;
    if(s=="AC") ans[0]++;
    if(s=="WA") ans[1]++;
    if(s=="TLE") ans[2]++;
    if(s=="RE") ans[3]++;
  }
  cout << "AC x " << ans[0] << endl;
  cout << "WA x " << ans[1] << endl;
  cout << "TLE x " << ans[2] << endl;
  cout << "RE x " << ans[3] << endl;
  return 0;
}


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

ll n, s, ans = -1;

inline ll read() {
	ll s = 0, f = 1;
	char ch;
	for(; ch < '0' || ch > '9'; ch = getchar())	if(ch == '-')	f = -1;
	for(; ch >= '0' && ch <= '9'; ch = getchar())	s = (s << 1) + (s << 3) + ch - '0';
	return s * f;
}

inline ll f(ll b, ll n) {
	ll ans = 0;
	while(n)	ans += n % b, n /= b;
	return ans;
}

int main() {
	n = read(), s = read();
	ll u = sqrt(n) + 1;
	for(ll i = 2; i <= u; ++i)	if(f(i, n) == s) { ans = i; break; }
	if(n == s) { ans = n + 1; }
	if(ans == -1 && n > s) {
		ll c = n - s;
		u = c / (u - 1) + 1;
		for(ll i = u; i >= 1; --i) {
			ll b = c / i + 1;
			if(!(c % i) && s >= i && (s - i) < b && i < b) {
				ans = b;
				break;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
A,B,K=map(int,input().split())
if A+K-1<B-K+1:
  for i in range(A,A+K):
    print(i)
  for i in range(B-K+1,B+1):
    print(i)
else:
  for i in range(A,B+1):
    print(i)

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

vector< int64_t > divisor(int64_t n) {
    vector< int64_t > ret;
    for(int64_t i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

int main() {
    int n; cin >> n;
    vector<int> A(n);
    unordered_map<int, int> m;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
        m[A[i]]++;
    }
    int ans = 0;
    for (const auto &a: A) {
        auto d = divisor(a);
        bool ok = true;
        if (m[a] != 1) continue;
        for (const auto &p: d) {
            if (m.find(p) != m.end()) {
                if (p != a) ok = false;
                break;
            }
        }
        if (ok) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12076
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<functional>
#include <bitset>
#include<algorithm>
#include<fstream>
#include<string>
#include <cstring>
#include<stdio.h>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<vector>
#include<assert.h>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
// never lose hope ..
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define eps 1e-8
using namespace std;
double const  PI = 3.141592653;
const int OO = 1000000000 + 9;

void fast() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL), cout.tie(NULL);
}
struct s {
	int x, y, z;
};

int n;
int v[(int)1e5][4];
int dp[(int)1e5][4];

int solve(int i = 0, int pre = 4) {
	if (i >= n)return 0;
	if (dp[i][pre] != -1)return dp[i][pre];
	int ch1, ch2, ch3;
	ch1 = ch2 = ch3 = 0;
	if (pre != 1) {
		ch1 = solve(i + 1, 1) + v[i][1];
	}
	if (pre != 2) {
		ch2 = solve(i + 1, 2) + v[i][2];
	}
	if (pre != 3) {
		ch3 = solve(i + 1, 3) + v[i][3];
	}
	return dp[i][pre] = max({ ch1,ch2,ch3 });
}


int main()
{
	fast();

	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> v[i][1] >> v[i][2] >> v[i][3];
	}
	memset(dp, -1, sizeof(dp));
	cout << solve();

	return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <vector>

#define ll long long

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

    int size = S.size();
    bool is_kaibun = true;
    int a = (size + 3) / 2 - 1;
    for(int i=0; i < (size-1)/2; i++) {
        if(S[i] != S[a + i]) {
            is_kaibun = false;
        }
    }

    if(is_kaibun) {
        std::cout << "Yes" << std::endl;
    }
    else {
        std::cout << "No" << std::endl;
    }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
signed main(){
	int a,b;
	cin>>a>>b;
	if(a<=0&&0<=b)cout<<"Zero"<<endl;
	else if(a<0){
		if((b-a)%2==0)cout<<"Negative"<<endl;
		else cout<<"Positive"<<endl;
	}
	else cout<<"Positive"<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <utility>
#include <map>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<int> vecint;
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)

#define MAX_V 200
#define INF 1e+9





int main() {
	ll ans;
	int i, j, k;

	ll A[100000] = { 0 };
	ll B[100000] = { 0 };
	int N;
	cin >> N;
	rep(i, 0, N) {
		cin >> A[i] >> B[i];
	}
	ll tmp=0;
	for (i = N - 1; i >= 0; i--) {
		A[i] += tmp;
		ll Add = (A[i] % B[i]);
		if (Add != 0)
			tmp += B[i] - Add;

	}
	ans = tmp;

	cout << ans;
	return 0;
}



Measured memory_bytes: 1792
fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main(args: Array<String>) {
    val (a, b, c, d) = longList()

    val area = b - a + 1

    val cC = b / c - (a - 1) / c
    val dC = b / d - (a - 1) / d

    val cd = lcm(c, d)
    val cdC = b / cd - (a - 1) / cd
    println((area - (cC + dC - cdC)).toString())
}

tailrec fun gcd(a: Long, b: Long): Long {
    return if (b == 0L) {
        a
    } else {
        gcd(b, a % b)
    }
}

fun lcm(a: Long, b: Long): Long {
    return a * b / gcd(a, b)
}


Measured memory_bytes: 37812
#include <iostream>
#include <iomanip>
#include <string>
#define REP(i,n) for(int i=0;i<(n);++i)
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
using namespace std;
typedef long long int LL;
 
int main(){
  string S;
  cin >> S;
  int len = S.size();
  int l = len / 2, r = len - l;
  for(; l > 0; --l) {
    if(S[l-1] != S[l]) break;
  }
  for(; r < len; ++r) {
    if(S[r-1] != S[r]) break;
  }
  int ret = MIN(r, len-l);
  cout << ret << endl;
}

Measured memory_bytes: 512
n=int(input())
an=[]
an=[int(input()) for i in range(n)]
s_an=sorted(an,reverse=True)
m_an=max(an)
m_an2=s_an[1]
for i in an:
    if m_an==i:
        print(m_an2)
    else:
        print(m_an)

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

typedef int Capacity;
struct Edge {
    int src, dst;
    Capacity cap;
    Edge(int src_, int dst_, Capacity cap_) :
        src(src_), dst(dst_), cap(cap_) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

struct Dinic {
    int n, s, t;
    vector<int> level, vis, iter;
    vector<vector<Capacity>> cap, flow;
    vector<vector<int>> g;
    Capacity inf;
    Dinic(int n)
        : n(n), cap(n, vector<Capacity>(n)), flow(n, vector<Capacity>(n)),
          g(n, vector<int>()), inf(numeric_limits<Capacity>::max()/8){}
    Dinic(const Graph &graph){
        *this = Dinic(graph.size());
        rep(i,n) for(auto &e : graph[i]) addEdge(e.src, e.dst, e.cap);
    }
    void addEdge(int u, int v, Capacity c){
        cap[u][v] += c; cap[v][u] += c; flow[v][u] += c;
        g[u].push_back(v); g[v].push_back(u);
    }
    Capacity solve(int s, int t){
        this->t = t, this->s = s;
        Capacity res = 0, aug = 1;
        while(aug > 0){
            levelize();
            vis.assign(n, false); iter.assign(n, 0); aug = 0;
            Capacity tmp = 1;
            while(tmp > 0) aug += (tmp = augment(s, inf));
            res += aug;
        }
        return res;
    }
    void levelize(){
        level.assign(n, inf); level[s] = 0;
        queue<int> q; q.emplace(s);
        while(q.size()){
            int v = q.front(); q.pop();
            for(const int &d : g[v]){
                if(level[d] <= level[v] + 1 || cap[v][d] - flow[v][d] == 0) continue;
                level[d] = level[v] + 1; q.emplace(d);
            }
        }
    }
    Capacity augment(int v, const Capacity &lim){
        vis[v] = true;
        if(v == t) return lim;
        for(int &i = iter[v]; i < (int)g[v].size(); i++){
            const int &d = g[v][i];
            if(vis[d] || flow[v][d] == cap[v][d] || level[v] + 1 != level[d]) continue;
            Capacity aug = augment(d, min(lim, cap[v][d] - flow[v][d]));
            flow[v][d] += aug; flow[d][v] -= aug;
            if(aug > 0) return aug;
        }
        return 0;
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    Graph g(N);
    rep(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        g[a].emplace_back(a,b,c);
    }
    Dinic dinic(g);
    cout << dinic.solve(0,N-1) << endl;
}

Measured memory_bytes: 1356
n, m = map(int, input().split())
 
num = [-1] * n
ans = -1
f = 1
 
for _ in range(m):
  s, c = map(int, input().split())
  if s == 1 and c == 0:
    if n == 1:
      ans = 0
    f = 0
    break
    
  i = num[s - 1]
  if i == -1:
    num[s-1] = c
  elif i == c:
    continue
  else:
    f = 0
    break
  
if num[0] == -1:
  if n == 1:
    num[0] = 0
  else:
    num[0] = 1
  
if f:
  num = [0 if n == -1 else n for n in num]
  ans = ''.join(map(str, num))
  
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String s = sc.next();

        if (a >= 3200) {
            System.out.println(s);
        } else {
            System.out.println("red");
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

int main() {
    char a,b,c;
    int cnt = 0;
    cin >> a >> b >> c;
    if(a == '1'){
        cnt++;
    }
    if(b == '1'){
        cnt++;
    }
    if(c == '1'){
        cnt++;
    }
    cout << cnt << endl;
    
}



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

using ll = long long;

#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 ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  string s; std::cin >> s;
  int ans = 0, len = s.size();
  rep(i, len) ans += s[i]-'0';
  chmax(ans, s[0]-'0'-1 + (len-1)*9);
  std::cout << ans << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main(void){
    int n;
    scanf("%d",&n);
    int p[n],ans=0;
    for(int i=0;n>i;++i)
    scanf("%d",&p[i]);
    for(int i=1;n-1>i;++i){
        if((p[i-1]<p[i]&&p[i]<p[i+1])||(p[i+1]<p[i]&&p[i]<p[i-1]))
        ++ans;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


mod = 10 ** 9 + 7
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
heapq.heapify(A)

change = {}
for i in range(M):
    b, c = list(map(int, input().split()))
    if c in change:
        change[c] += b
    else:
        change[c] = b

for key in sorted((change.keys()), reverse=True):
    for num in range(change[key]):
        min_ = heapq.heappop(A)
        if min_ < key:
            heapq.heappush(A, key)
        else:
            heapq.heappush(A, min_)
            print(sum(A))
            exit()
# A = np.array(A, np.int64)
print(sum(A))


Measured memory_bytes: 32428
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 200005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define pb push_back
# define mp make_pair
//# define int ll
using namespace std;

ll n,T,x,ans,t[maxn];

int32_t main(){_
    //freopen("input","r",stdin);
	cin >> n >> T;
	for(int i = 1;i <= n;i++)
	{
		cin >> x;
        if(x - 1 >= t[i - 1])ans -= x - t[i - 1];
        t[i] = x + T;
	}
	ans += t[n];
	rc(ans);
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  int i;
  int count=0;
  for(i=a;i<=b;i++)
  {
    if(c%i==0)
    {
      count++;
    }
  }
  cout<<count<<endl;
  return 0;
}



Measured memory_bytes: 3088
#!/usr/bin/perl
use POSIX qw(floor);

my ($n,$d) = map { $_ - 0 } split(/\s+/,<STDIN>);

my $d2 = $d * $d;
my $cnt = 0;
for(my $i=0;$i<$n;$i++){
  my ($x,$y) = map { $_ - 0 } split(/\s+/,<STDIN>);
  $cnt++ if $x * $x + $y * $y <= $d2;
}

print "$cnt\n";



Measured memory_bytes: 6616
#include<stdio.h>
#include<math.h>

int main() {
	int i, j, k;
	int	n, m, h, g, a, b, c, d, l, r;
	int f = 2020;
	int w;

	scanf("%d %d", &l, &r);


	if (r - l > 2019) {
		f = 0;
		goto end;
	}

	for (i = l;i < r;i++) {
		w = i % 2019;
		if (w == 0) {
			f = 0;
			goto end;
		}
		for (j = i + 1;j < r + 1;j++) {
			h = j % 2019;
			if (h == 0) {
				f = 0;
				goto end;
			}
			g = (w*h) % 2019;
			if (g == 0) {
				f = 0;
				goto end;
			}
			if (g < f) {
				f = g;
			}
		}
	}

	end:

	printf("%d", f);


	return 0;
}

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

template <typename T>
inline T read(){
	T x=0,f=1;char c=getchar();
	while(!isdigit(c)){	if(c=='-') f=-f;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint
#define readint read<int>()
#define readlint read<lint>()
const int inf=1e9+1e7,MAXN=2e5+1e1;
const lint Mod=998244353;

lint dp[MAXN],sum[MAXN];
int l[MAXN],r[MAXN],n,k;

lint Abs(lint x){
	return (x<0 ? (x%Mod+Mod)%Mod : x%Mod);
}

int main(void){

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	scanf("%d%d",&n,&k),dp[1]=1;
	for(int i=1;i<=k;i++) l[i]=readint,r[i]=readint;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k;j++){
			if(l[j]>=i) continue;
			int L=max(1,i-r[j]),R=i-l[j];
			dp[i]=Abs(dp[i]+Abs(sum[R]-sum[L-1]));
			// printf("i = %d, L = %d, R = %d\n",i,L,R);
		}
		sum[i]=Abs(sum[i-1]+dp[i]);
	}
	printf("%lld\n",dp[n]);

	return 0;
}

Measured memory_bytes: 6944
import math

N = 5
ARR = [2, 4, 4, 0, 2]

N = 7
ARR = [6, 4, 0, 2, 4, 0, 2]
#
# N = 8
# ARR = [7, 5, 1, 1, 7, 3, 5, 3]
#
N = int(input())
ARR = list(map(int, input().split()))


def calculate(n, arr):
    if n % 2 == 0:
        n = n // 2
        start = 1
        finalResult = pow(2, n, 1000000000 + 7)
    else:
        n = n // 2 + 1
        start = 0
        finalResult = pow(2, (n - 1), 1000000000 + 7)

    result = {}
    for i in range(n):
        index = start + 2 * i
        if index == 0:
            result.__setitem__(0, 1)
        else:
            result.__setitem__(index, 2)

    isOk = True
    for i in range(len(arr)):
        if result.get(arr[i]) == None:
            isOk = False
            break

        if result.get(arr[i]) == 0:
            isOk = False
            break

        result.__setitem__(arr[i], result.get(arr[i])-1)

    if isOk == False:
        print(0)
        return

    if sum(result.values()) == 0:
        print(finalResult)
    else:
        print(0)


calculate(N, ARR)


Measured memory_bytes: 20616
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
lis=p[:x]+q[:y]+r
lis.sort(reverse=True)
ans=0
for i in range(x+y):
  ans+=lis[i]
print(ans)


Measured memory_bytes: 23328
N, Y = map(int, input().split())

flg = False
for a in range(N + 1):
    if flg:
        break
    for b in range(N + 1):
        c = N-a-b
        if c < 0:
            continue
        total = a*10000 + b*5000 + c*1000
        if total == Y:
            print(str(a) + " " + str(b) + " " + str(c))
            flg = True
            break

if flg == False:
    print("-1 -1 -1")

Measured memory_bytes: 3064
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define FOR(i, n) for (int(i) = 0; (i) < n; (i)++)
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define MOD 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed;
    cout.precision(10);
    // Those who cannot acknowledge themselves, will invariably fail
    int n;
    cin >> n;
    int count = 0;
    int mx = 0;
    for(int i = 0;i<n;i++)
    {
        int t;
        cin >> t;
        if(t >= mx)
        {
            count++;
        }
        mx = max(mx,t);
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin


def main():
    h, w = map(int, input().split())
    a = [next_str() for _ in range(h)]

    for i in range(h + 2):
        print("#", end="")
        if not 0 < i <= h:
            print("#" * w, end="")
        else:
            print(a[i - 1], end="")
        print("#")


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

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

int main() {
	int N;
	cin >> N;
	int t, x, y;
	int _t = 0, _x = 0, _y = 0;
	bool flg = true;

	for (int i = 0; i < N; i++)
	{
		cin >> t >> x >> y;
		int xy = abs(x - _x) + abs(y - _y);
		int tt = t - _t;
		if (tt >= xy && (tt - xy) % 2 == 0) continue;
		else {
			flg = false;
			break;
		}
		_t = t;
		_x = x;
		_y = y;
	}

	if (flg) cout << "Yes" << endl;
	else     cout << "No" << endl;
	return 0;
}


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

bool isReverseble (string str){
    bool result = true;
    int len = str.length();
    for (int i = 0;i<str.length()/2;i++)
    {
        if(str[i]!=str[len-i-1]){

            result =false;
            }
    }
    return result;

}

int main(){
    string S;cin >> S;
    int len = S.length();
    int first = (len -1)/2;
    int second = (len+3)/2;
    // cout << first << second << endl;
    string firstStr = S.substr(0,first);
    string secondStr=  S.substr(second-1,first);
    bool result =true;
    if(isReverseble(S)&&(isReverseble(firstStr)&&isReverseble(secondStr))){cout << "Yes"<<endl;}
    else{cout <<"No"<<endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
template<typename T> inline void add(T& a, T b) { a += b; if (a >= MOD) a -= MOD; }

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

  int N; cin >> N;
  ll ans = 0;
  rep1(i, N) {
    if(i%5 == 0 || i%3 == 0) {
      continue;
    }
    ans += i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int T;

int m1, d1;
int m2, d2;

int main()
{
	scanf("%d%d", &m1, &d1);
	scanf("%d%d", &m2, &d2);
	
	if (m1 == m2)
	{
		printf("0\n");
		return 0;
	}
	
	printf("1\n");

		
	return 0;
}


Measured memory_bytes: 128
import sys
s = input()

for i in range(len(s)):
  if (i+1) % 2 != 0:
    if s[i] == 'L':
      print('No')
      sys.exit()
      
  if (i+1) % 2 == 0:
    if s[i] == 'R':
      print('No')
      sys.exit()
print('Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

const int NMAX = 1000005;
bool isend[NMAX];
int child[NMAX][26];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    rep(i, n) reverse(whole(s[i]));
    auto comp = [](string a, string b) {
        if (a.size()==b.size()) return a<b;
        return a.size()<b.size();
    };
    sort(whole(s), comp);

    //TRIE
    int nxt = 1;
    vector<vector<int>> path(n);
    rep(i, n) {
        int node = 0;
        for (char c: s[i]) {
            path[i].pb(node);
            if (child[node][c-'a']==0) {
                child[node][c-'a'] = nxt++;
            }
            node = child[node][c-'a'];
        }
        isend[node] = true;
    }

    ll ans = 0;

    rep(i, n) {
        set<char> suf;
        rrep(j, s[i].size()) {
            suf.insert(s[i][j]);
            int node = path[i][j];
            for (char c: suf) {
                if (isend[child[node][c-'a']]) ans++;
            }
        }
    }
    ans -= n;
    
    cout << ans << endl;
    return 0;
}


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

int main(){
    int N; cin >> N;
    vector<long long>A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    int cnt = 0;
    for(int i = 0; i < N; i++){
        while(i + 1 < N && A.at(i) == A.at(i + 1)) i++;

        if(i + 1 < N && A.at(i) < A.at(i + 1)){
            while(i + 1 < N && A.at(i) <= A.at(i + 1)) i++;
        }
        else if(i + 1 < N && A.at(i) > A.at(i + 1)){
            while(i + 1 < N && A.at(i) >= A.at(i + 1)) i++;
        }
        cnt++;

    }

cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int N; cin >> N;
  vector<vector<int>> happy(N,vector<int>(3));
  for(int i=0; i<N; i++) cin >> happy[i][0] >> happy[i][1] >> happy[i][2];
  vector<vector<int>> dp(N,vector<int> (3,0));
  dp[0] = happy[0];
  for(int i=1; i<N; i++) {
     for(int j=0; j<3; j++) {
       for(int k=0; k<3; k++) {
         if(j==k) continue;
         chmax(dp[i][j],dp[i-1][k]+happy[i][j]);
       }
     }
  }
  cout << *(max_element(dp[N-1].begin(),dp[N-1].end())) << endl;
}


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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define eof !cin.eof()
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define ull unsigned long long
#define ll long long
#define ld long double
#define sz(a) a.size()
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define x first
#define y second
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ii pair <int, int>
#define iii pair <int, ii>
#define vi vector <int>
#define vit vector <int> :: iterator
#define vlt vector <ll> :: iterator
#define vl vector <ll>
#define vii vector <ii>
#define viii vector <iii>
#define vd vector <double>
#define vull vector <ull>
#define vc vector <char>
#define vs vector <string>
#define vb vector <bool>
#define vvi vector <vector <int>>
#define vvl vector <vector <ll>>
#define EPS 1e-10
#define INF 1000000000
#define mod 1000000007
#define reset(a, nilai) memset(a, nilai, sizeof(a))
#define minof min_element
#define maxof max_element
using namespace std;

ll n, k;
int main () {
	IOS;
	
	scanf("%lld%lld", &n, &k);
	vector <ll> a(n), f(n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}
	for (int i = 0; i < n; i++) {
		scanf("%lld", &f[i]);
	}
	sort(all(a)); sort(rall(f));
	ll find = 0, out = 1e18L;
	while (find < out) {
		ll mid = find + (out - find) / 2, sum = 0;
		for (int i = 0; i < n; i++) {
			sum += max(0LL, (a[i] * f[i] - mid + f[i] - 1) / f[i]);
		}
		if (sum <= k) {
			out = mid;
		} else {
			find = mid + 1;
		}
	}
	printf("%lld\n", out);
	return 0;
}


Measured memory_bytes: 3456
n = int(input())
list1 = []
for i in range(n):
  s, p = input().split()
  list1.append([s, int(p), i])
ans = []
for j, (k, v, i) in enumerate(sorted(list1, key=lambda x:(x[0], -x[1]))):
  #print(k, v, i, j)
  ans.append([s, p, i, j])
for a, b, c, d in sorted(ans, key=lambda x:(x[3])):
  print(c+1)

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main() {
  int n;
  cin>>n;
  
  int A[n];
  rep(i,n) cin>>A[i];
  
  bool M[2020];
  rep(i,2020) M[i]=false;
  
  for(int i=0;i<(1<<n);i++){
    int sum=0;
    for(int j=0;j<n;j++){
      if(i&(1<<j)) sum+=A[j];
    }
    M[sum]=true;
  }
  
  int q;
  cin>>q;
  int x;
  rep(i,q){
    cin>>x;
    if(M[x]) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 3116
#include<cstdio>
#define mod 1000000007
using namespace std;

int main(void){
    int n;
    char s1[55];
    char s2[55];
    scanf("%d",&n);
    scanf("%s",s1+1);
    scanf("%s",s2+1);
    long long ans=1;
    int before=0;
    for(int i=1;i<=n;i++){
        if(s1[i]==s2[i]){
            if(before==0)ans*=3;
            else if(before==2)ans*=1;
            else if(before==1)ans*=2;
            before=1;
        }else{
            if(before==0)ans*=6;
            else if(before==1)ans*=2;
            else if(before==2)ans*=3;
            before=2;i++;
        }
        ans%=mod;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i =0;i<n;i++)cin >> a[i];
	int ans = 0;
	for(int i =0;i<n;i++)
	{
		if(i+1==a[a[i]-1])ans++;
	}
	cout<<ans/2<<endl;
	return 0;
}

Measured memory_bytes: 640
N = int(input())
W = list(map(int,input().split()))
dif = 100000000

for i in range(1,N):
    pre = W[:i+1]
    post = W[i+1:]
    if dif > abs(sum(pre) - sum(post)):
        dif = abs(sum(pre) - sum(post))
        
print(dif)

Measured memory_bytes: 3060
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void exec(InputStream in, PrintStream out){
        Scanner sc = new Scanner(in);
        out.println(sc.nextInt() == sc.nextInt() ? "Yes" : "No");
    }

    public static InputStream makeInputStream(String body) {
        return new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8));
    }

    public static void test(String in, String out) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        exec(makeInputStream(in), new PrintStream(baos));
        String result = new String(baos.toByteArray());
        System.out.println("-----------" + (out.equals(result) ? "【OK】" : "NG..."));
        System.out.println("[in]");
        System.out.println(in);
        System.out.println("[result]");
        System.out.println(result);
        if (!out.equals(result)) {
            System.out.println("[expected]");
            System.out.println(out);
        }
    }

    public static void main(String[] args) {
        exec(System.in, System.out);
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pb push_back
    #define sz(x) (int)x.size()
    typedef pair<int,int>pii;
    const int mxN=2e5,M=1e9+7;
    int m,k;
    // LONG LONG CASE
    int main(){
        ios_base::sync_with_stdio(0);
        cin.tie(0);    
        cin>>m>>k;
        if(k>=1<<m)cout<<-1;
        else if(m==0){
            if(k==0)cout<<0<<" "<<0;
            else cout<<-1;
        }
        else if(m==1){
            if(k!=0)cout<<-1;
            else cout<<"0 0 1 1";
        }
        else{
            vector<int>v;
            for(int i=0;i<(1<<m);i++){
                if(i!=k)v.pb(i);
            }
            v.pb(k);
            for(int i=(1<<m)-1;i>=0;i--){
                if(i!=k)v.pb(i);
            }
            v.pb(k);
            for(int u:v){
                cout<<u<<" ";
            }
        }
        
    }

Measured memory_bytes: 2932
n,t = list(map(int,input().split()))

ans = 0
min_t = 10000
for i in range(n):
    c,s = map(int,input().split())
    if s <= t and c<=min_t:
        min_t = min(c,min_t)
        ans = c
    
if min_t == 10000:
    print("TLE")
else:
    print(ans)
    

Measured memory_bytes: 38256