akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <vector>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
typedef  long long ll;
const int maxn=1e5+50;
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;
const int HASH=131;

ll a[3000]={0,0,0,1,1};

int main()
{
    int n;
    cin>>n;
    if(n>4)
    {
        for(int i=5;i<=n;i++)
        {
            a[i]=(a[i-3]+a[i-1])%MOD;
        }
    }
    cout<<a[n]<<endl;
    return 0;
}


Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		while(true){
		String s;
		if((s=Console.ReadLine())==null)break;
		int N=int.Parse(s);
		//var d=Array.ConvertAll(Console.ReadLine().Split(' '),elem=>int.Parse(elem));
		int[] d=new int[N];
		var ss=Console.ReadLine().Split(' ');
		for(int i=0;i<N;i++)d[i]=int.Parse(ss[i]);
		Array.Sort(d);
		int ans=0;
		for(int i=0;i<N;i++)ans+=(N-i)*d[i];
		Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 5960
def larger(x, y):
	if len(x) > len(y):
		return x
	elif len(x) < len(y):
		return y
	else:
		if x > y:
			return x
		return y

matchuse = [5000000000000000, 2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = map(int, input().split())
A = list(map(int, input().split()))
dp = [[]]
for i in range(0, 10):
	dp[0].append('')
made = []
for i in range(0, N+1):
	lst = []
	for j in range(0, M):
		lst.append(False)
	made.append(lst)
made[0][0] = True
for i in range(1, N+1):
	lst = []
	for j in range(0, M):
		next = ''
		if i - matchuse[A[j]] >= 0:
			index = i - matchuse[A[j]]
			for k in range(0, M):
				if made[index][k]:
					next = larger(next, dp[index][k]+str(A[j]))
		lst.append(next)
		if next != '':
			made[i][j] = True
	dp.append(lst)
ans = ''
for i in range(0, M):
	ans = larger(ans, dp[N][i])
print(ans)

Measured memory_bytes: 918280
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}
fn main() {
    let (n, m, c) = read_three();
    let b:Vec<i32> = read_vec();
    let mut ans = 0;
    for i in 0..n {
        let a: Vec<i32> = read_vec();
        let mut num = c;
        for j in 0..m {
           num += a[j as usize] * b[j as usize]; 
        }
        if num > 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
n,k = map(int,input().split())
a = list(map(int,input().split()))

#dp[i]: [上からi番目を決定したときの最大値,smaller]
#smaller: {0:次の桁はK以下になるようにする,1:次の桁は何でもok}
dp = [[0,0] for _ in range(42)]

for i in range(1,42):
    if dp[i-1][1] == 1:
        dp[i][1] = 1
    
    #ctr:i行目が1のAの個数
    ctr = 0
    for j in range(n):
        if (a[j]>>(41-i))&1 == 1:
            ctr += 1

    if ctr >= n-ctr:
        #i行目は0にする
        dp[i][0] = dp[i-1][0] + ctr*(2**(41-i))
        if (k >> (41-i))&1 == 1:
            dp[i][1] = 1
    else:
        #i行目は1にしたい
        if dp[i][1] == 1:
            #1にする
            dp[i][0] = dp[i-1][0]+(n-ctr)*(2**(41-i))
        else:
            if (k >> (41-i))&1 == 1:
                #1にする
                dp[i][0] = dp[i-1][0]+(n-ctr)*(2**(41-i))
            else:
                #1にできないので0にする
                dp[i][0] = dp[i-1][0] + ctr*(2**(41-i))

print(dp[41][0])

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

#define reg register

using namespace std;

const int MAXN=2e5+1;

string s,b("");
int n,q,rev[MAXN]= {0},tot=0;
struct INS {
	int f,no;
	char c;
} ins[MAXN];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>s>>q;
	n=s.length();
	reg int t,f;
	reg char c;
	for(reg int i=1,t; i<=q; ++i) {
		cin>>t;
		rev[i]=rev[i-1];
		if(t==1) ++rev[i];
		else {
			cin>>f>>c;
			++tot;
			ins[tot].f=f,ins[tot].c=c,ins[tot].no=i;
		}
	}
	if(rev[q]&1) reverse(s.begin(),s.end());
	for(reg int i=1; i<=tot; ++i) {
		if((rev[q]-rev[ins[i].no])&1) {
			if(ins[i].f==1) s+=ins[i].c;
			else b+=ins[i].c;
		} else {
			if(ins[i].f==1) b+=ins[i].c;
			else s+=ins[i].c;
		}
	}
	reverse(b.begin(),b.end());
	cout<<b<<s<<endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  string s;
  cin >> s;
  int n = s.size();
  if (s[0] != s[n-1] && n % 2 == 1) {
    puts("First");
  } else if (s[0] != s[n-1] && n % 2 == 0) {
    puts("Second");
  } else if (s[0] == s[n-1] && n % 2 == 0) {
    puts("First");
  } else {
    puts("Second");
  }

  return 0;
}


Measured memory_bytes: 512
package main
 
import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"math"
)
 
func run() {
	n := nextFloat()
	k := nextFloat()



	count := 0
	count2 := 0
	count3 := 0

	for i := 1; i < int(math.Pow(n,0.5))+1; i++ {
      if(int(n) % i == 0 && int(k) % i == 0 ){
			for j := 2; j < int(math.Pow(float64(i),0.5))+1; j++ {
				if( i % j == 0){
					count2 ++
				}
			}
			if count2 > 0 {
				count3++
				count2 =0
			}
			count ++
		}
      if(int(n) % i == 0 && int(k) % (int(n)/i) == 0 && i * i != int(n)){
        for j := 2; j < int(math.Pow(float64(int(n)/i),0.5))+1; j++ {
              if( (int(n)/i) % j == 0){
					count2 ++
				}
			}
			if count2 > 0 {
				count3++
				count2 =0
			}
			count ++
		}
	}

	Println(count - count3)	
}

// --- template ---
// Thanks https://gist.github.com/halllllll/853ab587fd82ee3ffe6f7fb7fb499695
 
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
 
// Caution: You will get unexpected result if a single token is larger than this size.
const BufferSize = 64 * 1024 * 1024
 

func gcd(a, b int) int {
    if b == 0 {
        return a
    } else {
        return gcd(b, a % b)
    }
}

func Print(a ...interface{}) (n int, err error) {
	return fmt.Fprint(out, a...)
}
 
func Printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, format, a...)
}
 

func readIntArray(n int) ([]int) {
	v := make([]int, 0)
	for i := 0; i < n; i++ {
		v = append(v, nextInt())
	}
	return v
}
 
func Println(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(out, a...)
}
 
func next() string {
	sc.Scan()
	return sc.Text()
}
 
func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		log.Fatal(err)
	}
	return a
}
 
func nextFloat() float64 {
	a, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}

 
func main() {
	sc.Buffer(make([]byte, 0, BufferSize), BufferSize)
	sc.Split(bufio.ScanWords)
	run()
	out.Flush()
}


Measured memory_bytes: 2688
h, w = list(map(int, input().split(' ')))
field = []
for i in range(h):
    field.append(input())
 
dp = []
for i in range(h):
    dp.append([(0, 0)] * w)
for i in range(h):
    for j in range(w):  # 2e3 * 2e3
        if field[i][j] == '#':
            x, y = 0, 0
        else:
            if i == j == 0:
               x, y = 1, 1
            else:
                y = (dp[i-1][j][0] + 1) if i-1 >= 0 else 1
                x = (dp[i][j-1][1] + 1) if j-1 >= 0 else 1
        dp[i][j] = (y, x)
ans = 0 if field[0][0] == '#' else 1  
 
for i in range(h-1, -1, -1):
    for j in range(w-1, -1, -1):
        if field[i][j] != '#':
            y = dp[i+1][j][0] if i+1 < h else dp[i][j][0]
            x = dp[i][j+1][1] if j+1 < w else dp[i][j][1]
            dp[i][j] = (max(dp[i][j][0], y), max(dp[i][j][1], x))
        ans = max(dp[i][j][0] + dp[i][j][1] - 1, ans)
print(ans)

Measured memory_bytes: 241796
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    vector<int> a(n);
    int cnt = 0;
    bool zero = false;
    rep(i,n){
        cin >> a[i];
        if(a[i]<0) cnt++;
        if(a[i] == 0) zero = true;
    }

    ll all = 0;
    int min_ = inf; 
    rep(i,n){
        if(a[i]<0) a[i] = (-1)*a[i];
        all += a[i];
        min_ = min(min_,a[i]);
    }

    ll ans;
    if(!zero && cnt%2 != 0){
        ans = all - (2*min_);
    }else{
        ans = all;
    }

    cout << ans <<endl;
    return 0;


}

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

#define ARG4(_1, _2, _3, _4, ...) _4
#define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define REP(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i, 0, a)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i)
#define ALL(c) (c).begin(), (c).end()
#define TEN(n) ((ll)(1e##n))
#define pb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define let const auto
#define USE1(T) template <typename T>
#define USE2(T, U) template <typename T, typename U>
#define I_ inline
#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

USE1(T) using duo = std::pair<T, T>;
USE1(T) using vec = std::vector<T>;
using ll = long long;
// clang-format off
USE2(T,U) I_ bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE2(T,U) I_ bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE1(T=int) I_ T in(){T x;std::cin>>x;return x;}
USE1(T=int) I_ vec<T> in(int n){vec<T> v;v.reserve(n);rep(i,n)v.pb(in<T>());return v;}
USE1(T) vec<T> ndvec(T v,int n){return vec<T>(n, v);}
USE2(T,...Ts) auto ndvec(T v,int n,Ts...ns)->vec<decltype(ndvec(v,ns...))>{return ndvec(ndvec(v,ns...),n);}
USE1(T) I_ void pr(T x){std::cout<<x<<'\n';}
USE2(T,...Ts) I_ void pr(T x,Ts...xs){std::cout<<x<<' ';pr(xs...);}
I_ int rd(){int x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;}
I_ void wr(int x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);}
struct IoSetup {
  IoSetup(){
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.precision(10);
    std::cerr.precision(10);
  }
} iosetup;
// clang-format on
// }}}
using namespace std;
const int inf = 1001001001;
const ll infll = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};

signed main() {
  ll A = in(), B = in(), C = in();
  pr(min({abs((A - A / 2 - A / 2) * B * C), abs((B - B / 2 - B / 2) * A * C),
          abs((C - C / 2 - C / 2) * B * A)}));
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main(void){
    string s,t;
    cin>>s>>t;
    int s_size = s.size();
    int t_size = t.size();
    int s_size_t_size = s_size - t_size;
    int pos(-1);
    for(int i(s_size_t_size);i>=0;i--){
        bool flag(false);
        for(int j(0);j<t_size;j++){
            if(s[i+j] != '?' && s[i+j] != t[j]){
                flag = true;
            }
        }
        if(!flag){
            pos = i;
            break;
        }
    }
    if(pos>=0){
        for(int i(0);i<s_size;i++){
            if(i<pos && s[i] != '?')cout<<s[i];
            else if(i<pos && s[i] == '?')cout<<'a';
            else if(i>=pos && s[i] != '?')cout<<s[i];
            else if(i>=pos && s[i] == '?' && i<= pos+t_size-1)cout<<t[i-pos];
            else cout<<'a';
        }
        cout<<endl;
    }
    else cout<<"UNRESTORABLE"<<endl;
    return 0;
}

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

int main(void){
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> v(m);
    for(int i=0; i<m; i++){
        cin >> v.at(i).first >> v.at(i).second;
    }

    sort(v.begin(), v.end(), [](auto a, auto b){return a.second < b.second;});

    int ans = 0, p = 0;
    for(int i=0; i<m; i++){
        if(v.at(i).first < p){
            continue;
        }else{
            p = v.at(i).second;
            ans++;
        }
    }

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

Measured memory_bytes: 1024
#include <iostream>
#define MOD 1000000007
using namespace std;
int N,M;
int rez=1;
int main()
{
    cin>>N>>M;
    if(N>M)swap(N,M);
    if(M-N>1){cout<<0;return 0;}
    if(M==N)rez=2;
    int fa=1;
    for(int i=1;i<=M;i++)
    {
        fa=(1LL*fa*i)%MOD;
        if(i==N)rez=(1LL*fa*rez)%MOD;
        if(i==M)rez=(1LL*fa*rez)%MOD;
    }
    cout<<rez;
    return 0;
}


Measured memory_bytes: 256
import sys
import os
from itertools import combinations_with_replacement

def file_input():
    f = open('../Beginner_Contest_165/input.txt', 'r')
    sys.stdin = f

def main():
   # file_input()
    # input()
    N,M,Q=map(int, input().split())
    Q_set=[list(map(int, input().split())) for _ in range(Q)]

    ans=0

    for A in list(combinations_with_replacement(range(1,M+1),N)):
        # print(A)
        score=0
        for Q in Q_set:
            if A[Q[1]-1]-A[Q[0]-1]==Q[2]:
                score+=Q[3]
        if ans<score:
            ans=score

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21464
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] p = new int[N];
            string[] input = Console.ReadLine().Split(' ');
            for (int i = 0; i < N; i++)
            {
                p[i] = int.Parse(input[i]);
            }
            int count = 0;
            for (int i = 1; i < N-1; i++)
            {
                int[] sub_array = new int[3];
                sub_array[0] = p[i - 1];
                sub_array[1] = p[i];
                sub_array[2] = p[i + 1];
                if (sub_array.Max() != sub_array[1] && sub_array.Min() != sub_array[1]) count++;
            }
            Console.WriteLine(count.ToString());
        }
    }
}   

Measured memory_bytes: 13268
"use strict";

function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0], 10);
  var H = input[1].split(" ").map(function (v) {
    return parseInt(v, 10);
  });
  var result = 0;
  var max = 0;

  for (var i = 0; i < N; i++) {
    if (H[i] >= max) {
      result++;
      max = H[i];
    }
  }

  console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

void solve(long long W, long long H, long long x, long long y) {
    cout << W * H / 2.0 << endl;
    if (W / 2.0 == x && H / 2.0 == y) {
        cout << "1" << endl;
    } else {
        cout << "0" << endl;
    }
}

int main() {
    long long W;
    scanf("%lld", &W);
    long long H;
    scanf("%lld", &H);
    long long x;
    scanf("%lld", &x);
    long long y;
    scanf("%lld", &y);
    solve(W, H, x, y);
    return 0;
}


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

int main() {
  ll n;
  cin >> n;
  vector<ll> s(n);
  for(ll i=0;i<n;i++) {
    cin >> s[i];
  }
  sort(s.begin(),s.end());
  ll q;
  cin >> q;
  ll ans=0;
  for(ll i=0;i<q;i++) {
    ll p;
    cin >> p;
    ll l=-1,r=n;
    ll temp=(l+r)/2;
    while(l+1<r) {
      if(s[temp]<=p) {
        l=temp;
      }
      else {
        r=temp;
      }
      temp=(l+r)/2;
    }
    if(l>-1&&s[l]==p) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//解説AC
int gcd(int a, int b){
   if (a%b == 0)return(b);
   else return(gcd(b, a%b));
}
int num[1000010];
int main(){
  int n;
  cin>>n;
  vector<int>a(n);
 
  rep(i,n){
    int x;
    cin>>x;
    a[i]=x;
    num[x]++;
  }
  bool pairwise=true;
  for(int i=2;i<1000010;i++){
    int kazu=0;
    for(int j=i;j<1000010;j+=i){
      kazu+=num[j];
    }
    if(kazu>1)pairwise=false;
  }
  if(pairwise){
    cout<<"pairwise coprime"<<endl;
    return 0;
  }
  int g=0;
  rep(i,n)g=gcd(g,a[i]);
  if(g==1) cout<<"setwise coprime"<<endl;
  else cout<<"not coprime"<<endl;
  return 0;
}

Measured memory_bytes: 11044
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 19 + 7
EPS = 10 ** -10

N, X, T = MAP()

ans = ceil(N, X) * T
print(ans)


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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

void solve(long long T, long long X) {
  printf("%.10lf\n", 1.0 * T / X);
}

int main() {
  long long T;
  scanf("%lld", &T);
  long long X;
  scanf("%lld", &X);
  solve(T, X);
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] d = new int[n];
		for (int i = 0; i < n; i++) {
			d[i] = Integer.parseInt(sa[i]);
		}

		int m = Integer.parseInt(br.readLine());
		sa = br.readLine().split(" ");
		int[] t = new int[m];
		for (int i = 0; i < m; i++) {
			t[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		Arrays.sort(d);
		Arrays.sort(t);
		int i = 0;
		int j = 0;
		while (i < m) {
			if (j == n || d[j] > t[i]) {
				System.out.println("NO");
				return;
			}
			if (d[j] == t[i]) {
				i++;
			}
			j++;
		}
		System.out.println("YES");
	}
}


Measured memory_bytes: 71576
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int n, W;
vector<int> v, w;
ll memo[110][100100];

ll dp(int i, int j){
    if(i == -1) return 0;
    if(memo[i][j] != 0) return memo[i][j];

    ll res = 0;
    if(j - w[i] >= 0){
        res = max(res, dp(i - 1, j - w[i]) + v[i]);
    }
    res = max(res, dp(i - 1, j));

    return memo[i][j] = res;
}

int main(void){
    cin >> n >> W;
    v.resize(n);
    w.resize(n);
    for(int i = 0; i < n; i++){
        cin >> w[i] >> v[i];
    }

    cout << dp(n - 1, W) << endl;
    
}

Measured memory_bytes: 80128
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

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

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << min(A, B) + min(C, D) << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 256
import math

X = int(input())


def is_prime(n):
    if n == 1:
        return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


while True:
    if is_prime(X):
        print(X)
        exit()
    X += 1

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int tx[] = {0,1,1,1,0,-1,-1,-1};
const static int ty[] = {-1,-1,0,1,1,1,0,-1};
 
static const double EPS = 1e-8;

static const char ranks[32] = {'2','3','4','5','6','7','8','9','T','J','Q','K','A'};

int get_rank(char _c){
  for(int i=0;i<strlen(ranks);i++){
    if(ranks[i] == _c) return i;
  }
  return -1;
}

int main(){
  char Trump[2];

  while(~scanf("%s",Trump)){
    if(Trump[0] == '#') break;

    int led = 0;
    vector<vector<string> > cards;
    bool used[4][13];
    memset(used,false,sizeof(used));

    for(int dir=0;dir<4;dir++){
      vector<string> tmp_cards;
      for(int i=0;i<13;i++){
	string str;
	cin >> str;
	tmp_cards.push_back(str);
      }
      cards.push_back(tmp_cards);
    }

    int win[2] = {0,0};
    for(int turn=0;turn<13;turn++){

      int best_dir[3] = {-1,-1,-1}; //trump,led,other
      int best_rank[3] = {-1,-1,-1};//trump,led,other
      
      //search suit(SHDC)
      char led_suit = cards[led][turn][1];
      for(int dir=0;dir<4;dir++){
	int rank = get_rank(cards[dir][turn][0]);
	char suit = cards[dir][turn][1];

	if(suit == Trump[0]){
	  if(best_rank[0] < rank){
	    best_rank[0] = rank;
	    best_dir[0] = dir;
	  }
	}
	else if(suit == led_suit){
	  if(best_rank[1] < rank){
	    best_rank[1] = rank;
	    best_dir[1] = dir;
	  }
	}
	else if(suit != Trump[0]){
	  if(best_rank[2] < rank){
	    best_rank[2] = rank;
	    best_dir[2] = dir;
	  }
	}
      }
      
      for(int i=0;i<3;i++){
	if(best_dir[i] != -1){
	  win[best_dir[i] % 2]++;
	  // printf("%d\n",best_dir[i]);
	  led = best_dir[i];
	  break;
	}
      }
    }
    
    printf("%s %d\n",win[0] > win[1] ? "NS" : "EW",max(win[0],win[1])-6);
  }
}

Measured memory_bytes: 1204
#include<iostream>
#define lli long long

using namespace std;

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

	cout << "0 0 " << (lli)1e9 << " 1 " << ((lli)1e9 - N % (lli)1e9)%(lli)1e9  << " " << N / (lli)1e9 + (N%(lli)1e9==0? 0:1);

}


Measured memory_bytes: 256
s = input()
q = int(input())
qs = [input().split() for i in range(q)]
n = False
left= right = ""
for operation in qs:
    if operation[0] == '1':
        n = not n
    if operation[0] == '2':
        t , f, c = operation
        f = int(f)
        if n:
            f = 1 if f != 1 else 2
        if f == 1:
            left=c+left
        elif f == 2:
            right+=c
s = left+s+right
print(s[::-1] if n else s)

Measured memory_bytes: 41524
//BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 100005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string s, t, u;
    int a, b;

    cin>>s>>t;
    cin>>a>>b;
    cin>>u;

    if(u == s)
        a--;
    else if(u == t)
        b--;

    cout<<a<<" "<<b<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 60;

template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

int n;
double dp[310][310][310] = {};

double rec(int x, int y, int z) {
  if (x==0 and y==0 and z==0) return 0;
  if (dp[x][y][z] != 0) return dp[x][y][z];

  double ret = 1.0;
  if(x) ret += rec(x-1, y, z) * x / n;
  if(y) ret += rec(x+1, y-1, z) * y / n;
  if(z) ret += rec(x, y+1, z-1) * z / n;
  return dp[x][y][z] = ret * n / (x+y+z);
}

int main() {
  cin>>n;
  int x=0, y=0, z=0;
  rep(i, n){
    int a; cin>>a;
    if (a==1) ++x;
    if (a==2) ++y;
    if (a==3) ++z;
  }
  rec(x, y, z);
  cout<<fixed<<setprecision(10);
  print(dp[x][y][z]);

  return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    bool diff = false;
    long long ans = 0;
    int big = 1E9 + 6;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        ans += a;
        if (a > b && b < big)
            big = b;
        diff = diff || (a != b);
    }
    ans -= big;
    if (!diff)
        ans = 0;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
//const int INF = 100100100;
const int INF = (1LL<<32);
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;


int a, b, c, d, e, f;

double conc(double water, double suger) {
	if (water == 0 and suger == 0)
		return 0.0;
	return (((double)suger*(double)100) / ((double)water + (double)suger));
}


signed main() {
	ios::sync_with_stdio(false);
	cin >> a >> b >> c >> d >> e >> f;
	vector<int> water;
	vector<int> suger;
	for (int i = 0; i <= f; i++) {
		for (int j = 0; j <= f; j++) {
			int y = i * c + j * d;
			if (y <= f) {
				suger.pb(y);
			}
			int x = i * 100 * a + j * 100 * b;
			if (x <= f) {
				water.pb(x);
			}
		}
	}
	double mxc = 0;
	int aw = 0, as = 0;
	for (int i = 0; i < water.size(); i++) {
		for (int j = 0; j < suger.size(); j++) {
			if (water[i] + suger[j] <= f) {
				double lc = conc((double)water[i], (double)suger[j]);
				double limitc = (double)e * (double)water[i] / 100.0;
				if (suger[j] <= limitc) {
					if (mxc <= lc) {
						mxc = lc;
						aw = water[i];
						as = suger[j];
					}
				}
			}
		}
	}
	cout << aw + as << ' ' << as << '\n';
	return 0;
}



Measured memory_bytes: 2420
//==========================================
// ABC142a
//
// 2019/09/28
//==========================================

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

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

  double ans;
  if(n%2==0) cout << 0.5 << endl;
  else
  {
    double dn=(double)n;
    ans = (dn+1)/2/dn;
    cout << ans << endl;
  }


  return 0;
}

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

const int mod = 2019;

int main ()
{
    string number;
    cin >> number;
    
    int n = number.size();
    long long answer = 0;
    int suffix = 0;
    map <int, int> MAP;
    int power_of_ten = 1;
    MAP[0] = 1;
    for (int i=n-1; i>=0; i--){
        int digit = number[i] - '0';
        suffix = (suffix + digit*power_of_ten)%mod;
        power_of_ten *= 10;
        power_of_ten %= mod;
        answer += MAP[suffix];
        MAP[suffix]++;
    }
    
    cout << answer << endl;
}

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

int main(){
  int y, m, d;
  
  scanf("%d/%d/%d", &y, &m, &d);
  
  int ymd = 10000*y + 100*m + d;
  if(ymd <= 20190430) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
  
  return 0;
}

Measured memory_bytes: 3644
#pragma comment(linker, "/STACK:640000000")
#include <bits/stdc++.h>

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);

const int maxn = (int)1e5 + 10;

int a[maxn];

int main() {
	#ifdef LOCAL
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	#endif

	int n; scanf("%d", &n);

	for (int i = 0; i < n; i++) scanf("%d", &a[i]);

	sort(a, a + n);

	int res = -1;
	for (int i = 0; i < n - 1; i++) {
		if (res == -1 || max(a[n - 1] - res, res) > max(a[n - 1] - a[i], a[i])) {
			res = a[i];
		}
	}

	cout << a[n - 1] << " " << res << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxm = 200002;
const long long mo = 1e9 + 7;

int n, a, b;
long long inv[maxm];

long long fast_pow(int p) {
    long long res = 1, w = 2;
    while (p > 0) {
        if (p & 1)
            res = res * w % mo;
        p >>= 1;
        w = w * w % mo;
    }
    return res;
}

long long combination(int n, int a) {
    long long res = 1;
    if (a > n-a)
        a = n-a;

    for (int i = 0; i < a; ++i)
        res = res * (n - i) % mo;
    
    for (int i = 2; i <= a; ++i)
        res = res * inv[i] % mo;
    
    return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
    cin >> n >> a >> b;

    inv[1] = 1;
    for (int i = 2; i <= b; ++i) {
        inv[i] = (mo - mo/i) * inv[mo%i] % mo;
        // cout << i << ": " << 6LL * inv[i] % mo << endl;
    }
    
    long long ans = ((fast_pow(n) - 1 + mo - combination(n, a)) % mo + mo - combination(n, b)) % mo;

    cout << ans << endl;

    // cout << fast_pow(n) << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int n,i;
string s;
int main() {
	cin>>n>>s;
	for(int i=0;i<s.size();i++){
		s[i]+=n;
		if(s[i]>'Z')s[i]-=26;
		cout<<s[i];
	}
	cout<<endl;
	
	
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
int main()
{
	ll gen;
	int num;
	scanf("%lld%d", &gen, &num);
	vector<pii>qs;
	for (int i = 0; i < num; i++)
	{
		ll z;
		scanf("%lld", &z);
		qs.push_back(make_pair(z, -1));
	}
	int query;
	scanf("%d", &query);
	for (int i = 0; i < query; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		qs.push_back(make_pair(za, zb));
	}
	sort(qs.begin(), qs.end());
	ll mina = 0;
	ll lb = 0, ub = gen;
	ll bef = 0;
	int d = 0;
	for (int i = 0; i < qs.size(); i++)
	{
		if (qs[i].second == -1)
		{
			ll t = qs[i].first - bef;
			if (d == 0)
			{
				if (t < lb)lb -= t, ub -= t;
				else if (t < ub)mina += t - lb, lb = 0, ub -= t;
				else lb = ub = 0;
			}
			else
			{
				if (t < gen - ub)lb += t, ub += t;
				else if (t < gen - lb)lb += t, ub = gen;
				else lb = ub = gen;
			}
			d ^= 1;
			bef = qs[i].first;
		}
		else
		{
			ll t = qs[i].first - bef;
			ll z;
			if (qs[i].second < mina)z = lb;
			else if (qs[i].second <= mina + ub - lb)z = lb + (qs[i].second - mina);
			else z = ub;
			if (d == 0)z = max(z - t, 0LL);
			else z = min(z + t, gen);
			printf("%lld\n", z);
		}
	}
}

Measured memory_bytes: 6256
from sys import stdin

INF = float('inf')

MAX = 100000
n, W = map(int, raw_input().strip().split())
inp = stdin.readlines()

dp = [[INF for i in xrange(MAX + 1)] for j in xrange(n)]

i = 0
for line in inp:
    wi, vi = map(int, line.strip().split())

    if i == 0:
        dp[0][vi] = wi
        dp[0][0] = 0
    else:
        for V in xrange(vi):
            dp[i][V] = dp[i - 1][V]
        
        dp[i][vi] = wi
        
        for V in xrange(vi, MAX + 1):
            dp[i][V] = min(dp[i][V], dp[i - 1][V], dp[i - 1][V - vi] + wi)

    i += 1

ans = 0
for v in xrange(MAX + 1):
    if dp[n - 1][v] <= W: ans = max(ans, v)

print ans

Measured memory_bytes: 289628
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18+2;
const int MX=103;
int N, M, k;
int arr[MX];
string s[MX];
bool cmp(string &a, string &b)
{
    return a+b <= b+a;
}
int main()
{
    int L;
    cin>>N>>L;
    for(int i=0; i<N; i++)
    {
        cin>>s[i];

    }
    if(N > 1)
    sort(s, s+N);
    for(int i=0;i<N;i++) cout<<s[i];
    return 0;
}



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

int n;
double l;
vector<pair<int,int> > ev;

bool simulate(double pump) {
    double tank = l,vol = pump;
    int t = 0;

    //first day
    for(int i=0; i<ev.size(); ++i) {
        tank = min(tank + vol * (ev[i].first - t), l);
        if(tank <= 0) return false;
        vol += ev[i].second;
        t = ev[i].first;
    }
    tank = min(tank + vol * (86400 - t), l);

    //second day
    double sf = tank;
    vol = pump; t = 0;

    for(int i=0; i<ev.size(); ++i) {
        tank = min(tank + vol * (ev[i].first - t), l);
        if(tank <= 0) return false;
        vol += ev[i].second;
        t = ev[i].first;
    }
    tank = min(tank + vol * (86400 - t), l);

    return (tank >= sf);
}

const double eps = 1e-7;

int main() {
    int s,t,u;
    while(cin>>n>>l) {
        if(n == 0 && l == 0.0) break;
        ev.clear();
        double lo = 0.0,hi = l;
        for(int i=0; i<n; ++i) {
            cin>>s>>t>>u;
            ev.push_back(make_pair(s,-u));
            ev.push_back(make_pair(t,u));
            hi = max((double)u, hi);
        }

        while(lo + eps < hi) {
            double mid = (lo + hi)/2;
            if(simulate(mid)) hi = mid;
            else lo = mid;
        }
        printf("%.6f\n", lo);
    }
}

Measured memory_bytes: 2456
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int blood[]=new int[4];
        while(sc.hasNext()){
        	String n=sc.next();
        	String[] type=n.split(",");
        	if(type[1].equals("A"))blood[0]++;
        	if(type[1].equals("B"))blood[1]++;
        	if(type[1].equals("AB"))blood[2]++;
        	if(type[1].equals("O"))blood[3]++;
        }   
        for(int i=0;i<4;i++){
        	System.out.println(blood[i]);
        }
        
    }
}

Measured memory_bytes: 17160
#include <iostream>
#include <string>
#define llint long long
#define inf 1e18

using namespace std;

llint n, m;
llint p[3], a[100005];
string t;
llint dp[100005][3];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	cin >> p[0] >> p[1] >> p[2];
	cin >> t;
	t = "#" + t;
	
	for(int i = 1; i <= n; i++){
		if(t[i] == 'r') a[i] = 0;
		if(t[i] == 's') a[i] = 1;
		if(t[i] == 'p') a[i] = 2;
	}
	
	for(int i = 0; i <= n; i++){
		for(int j = 0; j < 3; j++){
			dp[i][j] = -inf;
		}
	}
	dp[0][0] = 0;
	
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 3; k++){
				if(i-m > 0 && j == k) continue;
				llint cost = 0;
				if((j-a[i]+3)%3 == 2) cost = p[j];
				if(i-m > 0) dp[i][j] = max(dp[i][j], dp[i-m][k] + cost);
				else dp[i][j] = max(dp[i][j], cost);
			}
		}
	}
	/*for(int i = 0; i <= n; i++){
		for(int j = 0; j < 3; j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	
	llint ans = 0;
	for(int i = 0; i < m; i++){
		if(n-m <= 0) break;
		llint tmp = 0;
		for(int j = 0; j < 3; j++) tmp = max(tmp, dp[n-i][j]);
		ans += tmp;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h> //G - Longest Path
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int maxn = 100100;


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

int dp[maxn]; //dp[i] = maior caminho começando de i
int n,m,ans;
vector<int> filho[maxn];

void dfs(int x)
{
	int best = 0;

	for(int i=0;i<filho[x].size();++i)
	{
		int y = filho[x][i];
		if(dp[y] == 0)
			dfs(y);		
		best = max(best,dp[y]);
	}

	dp[x] = best + 1;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cin>>n>>m;

	for(int i=1;i<=n;++i) dp[i] = 0;

	for(int i=1;i<=m;++i)
	{
		int a,b;
		cin>>a>>b;
		filho[a].pb(b);
	}
	
	for(int i=1;i<=n;++i)
		if(dp[i] == 0) dfs(i);

	int best = 0;
	for(int i=1;i<=n;++i)
		best = max(best,dp[i]);
	cout<<best-1<<"\n";

}

Measured memory_bytes: 12168
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define FLOOR(x) ((int)floor(((double)x)))
#define CEIL(x) ((int)ceil(((double)x)))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;


int N;
llint a[200010], b[200010];
llint modB[30][200010];


void makeModAB(){
	rep(i, 0, 29){
		rep(j, 0, N) modB[i][j] = b[j]%(1LL<<(i+1));
		sort(RNG(modB[i], N));
	}
}


llint solve(){
	llint ans = 0;
	rep(i, 0, 29){
		llint cnt = 0;
		rep(j, 0, N){
			llint modA = a[j]%(1LL<<(i+1));
			llint T = 1LL<<i;
			int l = lb(RNG(modB[i], N), T-modA)-&modB[i][0];
			int r = lb(RNG(modB[i], N), 2*T-modA)-&modB[i][0];
			cnt += r-l;
			l = lb(RNG(modB[i], N), 3*T-modA)-&modB[i][0];
			r = lb(RNG(modB[i], N), 4*T-modA)-&modB[i][0];
			cnt += r-l;
		}
		if(cnt%2 == 1) ans += (1LL<<i);
	}
	return ans;
}


signed main(){
	cin >> N;
	rep(i, 0, N) cin >> a[i];
	rep(i, 0, N) cin >> b[i];

	makeModAB();

	cout << solve() << endl;

	return 0;
}

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

int main( void )
{
    char tmp;
    unsigned char i = 0;
    unsigned char k = 0;
    unsigned char Num = 0;
    
    int j = 0;
    int v = 0;

    while( (tmp = getchar()) != '\n' )
    {
        Num = (Num * 10) + (tmp - '0');
    };
   
    int Array[Num];

    for(k=0; k<Num; k++ )
    {
        Array[k]=0;
    
        do{
            tmp = getchar();
            printf("%c",tmp);
            
            if(tmp == '\n')
            {
                break;
            }
            
            if( tmp != ' ' )
            {
                Array[k] = Array[k] * 10 + (tmp - '0');
            }
        }while(tmp != ' ' && tmp != '\n');
    }

    for( i = 1; i < Num; i++ )
    {
        v = Array[i];
        j = i - 1;
     
        while( j >= 0 && Array[j] > v )
        {
            Array[j+1] = Array[j];
            j--;
            Array[j+1] = v;
        }
    
        for(k=0; k<Num; k++ )
        {
            printf("%d",Array[k]);
            if( k == Num-1 )
            {
               printf("\n");
            }
            else
            {
               printf(" ");
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 1752
import sys
input = sys.stdin.readline

n, m = map(int, input().split())

# INF = float("inf")
INF = 10 ** 8
dp = [INF] * ((1<<n) + 1)
dp[0] = 0

for i in range(m):
    a, b = map(int, input().split())
    c = sum(1<<(ci-1) for ci in map(int, input().split()))

    for j in range(1<<n):
        if dp[j] + a < dp[j | c]:
            dp[j | c] = dp[j] + a
        # dp[j | c] = min(dp[j] + a, dp[j | c])


if dp[(1<<n) - 1] == INF:
    ans = -1
else:
    ans = dp[(1<<n) - 1]

print(ans)


Measured memory_bytes: 3188
s = list(input())
n = len(s)
if s == s[::-1] and s[:(n-1)//2] == s[:(n-1)//2][::-1] and s[(n+3)//2-1:n] == s[(n+3)//2-1:n][::-1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int a[10005],b[10005];
ll sum1,sum2,delta,qwq;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i],sum1+=a[i];
    for(int i=1;i<=n;i++)
        cin>>b[i],sum2+=b[i];
    if(sum1>sum2)
    {
        cout<<"No";
        return 0;
    }
    delta=sum2-sum1;
    for(int i=1;i<=n;i++)
        if(b[i]>a[i])
            qwq+=(b[i]+1-a[i])/2;
    if(qwq>delta)cout<<"No";
    else cout<<"Yes";
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
    int k,s,ans=0;
    cin>>k>>s;
        for(int j=0;j<=k;j++){
            for(int l=0;l<=k;l++){
               if(j+l<=s&&s-(j+l)<=k)ans++;
            }
        }      
    cout<<ans<<endl;
}

Measured memory_bytes: 384