akhauriyash/Code-Regression huggingface dataset:
# 3/1が index 曜日の時の １年間の 13th Fri の数
NUM_OF_13FRI = [2, 1, 2, 1, 2, 2, 2]

def weekOfDay(year, month, day)
    Time.gm(year, month, day).wday
end

y1,m1,d1,y2,m2,d2=gets.chomp.split(" ").map(&:to_i)

if d1 > 13
    if m1 == 12
        m1 = 1
        y1 += 1
    else
        m1 += 1
    end
end

if d2 >= 13
    if m2 == 12
        m2 = 1
        y2 += 1
    else
        m2 += 1
    end
end

period = (y2*100 - y1*100 + m2 - m1) / 280000
ret = period * 4816
y2 = y2 - period * 2800

y = y1
m = m1
while true do
    if y == y2 && m == m2
        puts ret
        break
    elsif m == 3 && y2 > y && m2 > 2
        ret += NUM_OF_13FRI[weekOfDay(y,3,1)]
        y += 1
    else
        ret += 1 if weekOfDay(y,m,13)==5

        m += 1
        if m == 13
            y += 1
            m = 1
        end
    end
end



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

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

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

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

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

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

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

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

fn main() {
    input!{
        n: usize,
        k: usize,
        p: [f64; n],
    }

    let mut max = 0.0;
    for j in 0..k {
        max = max + p[j] + 1.0;
    }
    let mut tmp = max;
    
    for i in 1..n-k+1 {
        tmp = tmp - p[i-1] + p[i+k-1];
//        println!("{}",tmp/2.0);
        if tmp > max {
            max = tmp;
        }
    }
    println!("{}",max/2.0);
}


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

int main() {
  int n,h,w;
  cin >> n >> h >> w;
  vector<int> a(n);
  vector<int> b(n);
  for(int i = 0;i < n;i++){
    cin >> a.at(i) >> b.at(i);
  }
  int c = 0;
  for(int j = 0;j < n;j++){
	if(a.at(j) >= h){
      if(b.at(j) >= w){
        c++;
      }
    }
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
import math

N = int(input())
h = list(map(int, input().split()))
dp = [float('INF')] * N

def chmin(a, b):
    if a >= b:
        return b
    else:
        return a

#初期値
dp[0] = 0

#Loop
for i in range(1, N):
    dp[i] = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if i > 1:
        dp[i] = chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]))
print(dp[-1])

Measured memory_bytes: 52544
package main

import (
	"fmt"
	"math"
)

func main(){
	var N, M, X ,Y int
	fmt.Scan(&N, &M, &X, &Y)
	x := make([] int,N)
	y := make([] int,M)

	for i := 0; i < N; i++{
		fmt.Scan(&x[i])
	}
	for i := 0; i < M; i++{
		fmt.Scan(&y[i])
	}
	Max := X
	for i := 0; i < N; i++{
		Max = int(math.Max(float64(Max),float64(x[i])))
	}
	
	Min := Y
	for i := 0; i < M; i++{
		Min = int(math.Min(float64(Min),float64(y[i])))
	}

	if Max < Min {
		fmt.Println("No War")
	} else {
		fmt.Println("War")
	}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int a[100010]={0};
int main(){
	int n,k,q;
	cin>>n>>k>>q;
	for(int i=1;i<=q;i++){
		int men;
		cin>>men;
		a[men]++; 
	}
	for(int i=1;i<=n;i++){
		//cout<<a[i]; 
		if(a[i]+(k-q)<=0) 
			cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
		
	}
	return 0;
} 

Measured memory_bytes: 1024
from copy import copy, deepcopy
from collections import Counter
from math import sqrt, floor, factorial
from itertools import permutations, combinations, combinations_with_replacement
from operator import mul
from functools import reduce
import bisect

MOD = 10**9 + 7
INF = float('inf')

A, B, C, K = list(map(int, input().split()))

if K <= A:
    print(K)
elif K <= A+B:
    print(A)
else:
    print(2*A+B-K)


Measured memory_bytes: 9712
N = int(input())

cities = list(map(int, input().split()))
savers = list(map(int, input().split()))

result = 0

for i in range(N):
  left = min(cities[i], savers[i])
  cities[i] -= left
  savers[i] -= left
  result += left
  
  right = min(cities[i + 1], savers[i])
  cities[i + 1] -= right
  savers[i] -= right
  result += right

print(result)

Measured memory_bytes: 19156
# -*- coding: utf-8 -*-
# D

import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)
from bisect import bisect_left

N = int(input())
S = input()
R = []
G = []
B = []

cnt_r, cnt_g, cnt_b = 0, 0, 0
for idx, s in enumerate(S):
    if s == 'R':
        R.append(idx+1)
        cnt_r += 1
    if s == 'G':
        G.append(idx+1)
        cnt_g += 1
    if s == 'B':
        B.append(idx+1)
        cnt_b += 1
# print(R, G, B)

if (cnt_r > 0) and (cnt_g > 0) and (cnt_b > 0):
    pass
else:
    print(0)
    sys.exit()

R0, G0, B0 = R, G, B

sum = 0

for i in range(6):
    if i == 0:
        R, G, B, temp = R0, G0, B0, 'B'
    elif i == 1:
        R, G, B, temp = R0, B0, G0, 'G'
    elif i == 2:
        R, G, B, temp = B0, R0, G0, 'G'
    elif i == 3:
        R, G, B, temp = B0, G0, R0, 'R'
    elif i == 4:
        R, G, B, temp = G0, R0, B0, 'B'
    elif i == 5:
        R, G, B, temp = G0, B0, R0, 'R'

    for s in R:
        if s > G[-1]:
            break
        idx1 = bisect_left(G, s)
        for g in G[idx1:]:
            if g > B[-1]:
                break
            idx2 = bisect_left(B, g)
            sum += len(B[idx2:])
            if 2 * g - s <= N:
                if S[2 * g - s - 1] == temp:
                    sum -= 1

print(sum)



Measured memory_bytes: 85544
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main() {
  ll N, M;
  string S, T;
  cin >> N >> M >> S >> T;
  ll lcm_nm = lcm(N, M);
  ll gcd_nm = gcd(N, M);
  ll n = N / gcd_nm;
  ll m = M / gcd_nm;
  ll s_i, t_i;
  bool fail_flag = false;
  for (int i = 0; i < gcd_nm; i++) {
    if (S[n * i] != T[m * i]) {
      fail_flag = true;
      break;
    }
  }
  if (fail_flag) {
    cout << -1 << endl;
  } else {
    cout << lcm_nm << endl;
  }
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
#define ll long long
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int main(){
	fastio();
	int n;
	cin>>n;
	int ans=0;
	set<int>s;
	for(int i=0;i<n;i++){
		int k;
		cin>>k;
		s.insert(k);
		if(*s.begin()==k) ans++;
	}
	cout<<ans;	
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;



int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=0,now=0;
    long long int a,b,c,d,gcd,hcf;
    //float f,g,h;
    //char now,pre;
    cin>>n>>k;
    int temp[n+1];
    for(i=0;i<n+1;i++) temp[i]=0;
    for(i=0;i<n;i++)
    {
        cin>>m;
        temp[m-1]++;
    }
    sort(temp,temp+n);
    for(i=0;i<n;i++)
    {
        if(temp[i]!=0) n1++;
    }
    if(n1<=k) cout<<0;
    else
    {
        n1-=k;
        for(i=0;i<n;i++)
        {
            if(n1==0) break;
            if(temp[i]!=0)
            {
                sum+=temp[i];
                n1--;
            }
        }
        cout<<sum;
    }
    return 0;
}




Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn check(s: &Vec<u32>) -> bool {
    let n = s.len();
    if s[0] == 0 {
        return false;
    }
    if s[n - 1] == 1 {
        return false;
    }
    for i in 0..n / 2 {
        if s[i] != s[n - i - 2] {
            return false;
        }
    }
    true
}

struct Tree {
    id: usize,
    child: Vec<Tree>,
}

impl Tree {
    fn new(id: usize) -> Tree {
        Tree {
            id: id,
            child: Vec::new(),
        }
    }

    fn add_child(&mut self, mut sorted_child_nums: Vec<usize>) {
        assert!(self.child.is_empty());
        if sorted_child_nums.len() == 0 {
            return;
        }
        if sorted_child_nums.len() == 1 {
            for i in 0..sorted_child_nums[0] - 1 {
                self.child.push(Tree::new(self.id + i + 1));
            }
            return;
        }

        let max_child_num = sorted_child_nums.pop().unwrap();
        let second_child_num = sorted_child_nums[sorted_child_nums.len() - 1];

        self.child.push(Tree::new(self.id + 1));
        self.child[0].add_child(sorted_child_nums);

        for i in second_child_num + 1..max_child_num {
            self.child.push(Tree::new(self.id + i));
        }
    }

    fn print(&self) {
        for ref child in self.child.iter() {
            println!("{0} {1}", self.id + 1, child.id + 1);
            child.print();
        }
    }
}

fn main() {
    let s = read::<String>()
        .chars()
        .map(|x| x.to_digit(10).unwrap())
        .collect::<Vec<u32>>();
    if !check(&s) {
        println!("-1");
        return;
    }
    let n = s.len();

    let mut odd_elements = Vec::new();
    let mut even_elements = Vec::new();

    for i in 1..n / 2 {
        let num = i + 1;
        if s[i] == 1 && num >= 1 {
            if num % 2 == 1 {
                odd_elements.push(num);
            } else {
                even_elements.push(num);
            }
        }
    }
    // println!("even elements {:?}", &even_elements);
    // println!("odd elements {:?}", &odd_elements);

    // make 0-indexed tree.
    let mut root = Tree::new(0);
    let mut idx_for_odd_max = 0;
    if !odd_elements.is_empty() {
        idx_for_odd_max = if let Some(&x) = odd_elements.iter().max() {
            x
        } else {
            1
        };
        let mut odd_root = Tree::new(1);
        odd_root.add_child(odd_elements);
        root.child.push(odd_root);
    }

    let mut idx_for_even_max = idx_for_odd_max;
    if !even_elements.is_empty() {
        idx_for_even_max = if let Some(&x) = even_elements.iter().max() {
            x + idx_for_odd_max
        } else {
            1 + idx_for_odd_max
        };
        let mut even_root = Tree::new(idx_for_odd_max + 1);
        even_root.add_child(even_elements);
        root.child.push(even_root);
    }

    for i in idx_for_even_max + 1..n {
        root.child.push(Tree::new(i));
    }

    root.print();
}


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

typedef long long ll;
ll INF=1e9+7;

int main(){
    int N;
    cin >> N;
    
    ll ans=1;
    for(int i=1; i<=N; i++){
        ans *= i;
        ans = ans%INF;
    }
    
    cout << ans << endl;
}



Measured memory_bytes: 256
from collections import deque
k = int(input())

q = deque()
for i in range(1, 10):
    q.append(i)
cnt = 0
while True:
    a = q.popleft()
    cnt += 1
    if cnt == k:
        print(a)
        exit()
    b = a % 10
    for i in (-1, 0, 1):
        if 0 <= b + i <= 9:
            q.append(a*10 + b+i)

Measured memory_bytes: 18672
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main(void){
	int x=1, count;

	for (count = 1; x != 0; count++){
		scanf("%d", &x);
		if (x != 0){
			printf("Case %d: %d\n",count, x);
		}
	}

	return 0;
}

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

int main(){
	long long int   N ;
	string S;
	vector<long long int> X(5);
  
  for(long long int i=0; i < 5; i++) cin >> X[i]; 
  for(long long int i=0; i < 5; i++){
  	if (X[i] == 0) {
      cout << ++i << endl;
      break;
    }
  }
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back

using namespace std;

int main(){

    int n;

    cin>>n;

    int a[n],s=1,sp=0,x=1,k=0;

    for(int i = 0;i<n;i++)
        cin>>a[i];
    s = a[0];
    for(int i = 1;i<n;i++){
        if(a[i]==s){
            x++;
        }
        else{
            sp=sp+(x/2);

            s = a[i];
            x = 1;
        }
    }

    sp = sp+(x/2);

    cout<<sp<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int bitCount(unsigned int bits){
    int count = 0;
    for(; bits != 0; bits >>=1){
        count += bits & 1;
    }
    return count;
}
int main(){
    int n, m;
    cin >> n >> m;
    vector<unsigned int> data(m, 0);
    for(int i = 0; i < m; ++i){
        int k;
        cin >> k;
        unsigned int sum = 0;
        for(int j = 0; j < k; ++j){
            int s;
            cin >> s;
            sum += pow(2, s-1);
        }
        data[i] = sum;
    }
    int all = pow(2, n);
    int ans = 0;
    vector<int> p;
    for(int i = 0; i < data.size(); ++i){
        int tmp_p;
        cin >> tmp_p;
        p.push_back(tmp_p);
    }
    for(unsigned int i = 0; i < all; ++i){
        for(int j = 0; j < data.size(); ++j){
            unsigned int flag = data[j] & i;
            int num = bitCount(flag);
            if(num%2 != p[j]){
                break;
            }else if(j == data.size()-1){
                ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define MAXN 200100
#define INF 999999999999999

ll n;
ll data[MAXN];
ll l = 0,r = 0;
ll ans = INF;

ll labs(ll a){
	return a>0 ? a : -a;
}
ll lmin(ll a,ll b){
	return a<b ? a : b;
}

int main(){
	cin >> n;
	for(int i = 1;i <= n;i++){
		int x;
		cin >> x;
		data[i] = x;
		r += (ll)x;
	}
	
	for(int i = 1;i <= n-1;i++){
		l += data[i]; r -= data[i];
		ans = lmin(ans,labs(l-r));
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1792
import math

N = int(raw_input())
A = [int(x) for x in raw_input().split()]
a = sum(A)/float(N)
tmp=99999999
ans=0
for i in range(N):
    if abs(a-A[i]) < tmp:
        tmp =abs(a-A[i])
        ans =i
print ans


Measured memory_bytes: 2568
import sys

number_days_next_sunday = {'SUN':7, 'MON':6, 'TUE':5, 'WED':4, 'THU':3, 'FRI':2, 'SAT':1}
weekday = input()

if weekday not in number_days_next_sunday:
    sys.exit(1)
    
print(number_days_next_sunday[weekday])

Measured memory_bytes: 3060
import java.io.*;
import java.util.*;
public class Main{
    static int cSize = 2001;
    static long[][] C = new long[cSize][cSize];    
    static {
        for(int i = 0; i < cSize; i++){
            Arrays.fill(C[i], -1);
            C[i][0] = C[i][i] = 1;
        }        
    }
    static long c(int n, int r){
        if(n < r)
            return 0;
        else if(C[n][r] > -1)
            return C[n][r];
        else
            if(n/2 < r)
                return C[n][r] = c(n, n-r);
            else
                return C[n][r] = (c(n-1, r-1)+c(n-1, r))%1000000007;
    }
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();        
        int N, K;
        {int[] a = r.ii(); N = a[0]; K = a[1];}
        StringBuilder sb = new StringBuilder();
        for(int i = 1; i <= K; i++){
            sb.append((c(N-K+1, i)*c(K-1, i-1))%1000000007+"\n");
        }
        print(sb);
    }

    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}


Measured memory_bytes: 81492
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N; cin >> N;
  bool ans = false;
  for(int i=1; i<=9; i++) {
    for(int j=1; j<=9; j++) {
      if(N == i*j) {
        ans = true;
        break;
      }
    }
  }
  if(ans==true) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3616
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]

ans = 0

for i in range(n):
    sum = 0
    for j in range(m):
        sum += a[i][j] * b[j]
    
    if sum + c > 0:
        ans += 1
    
print(ans)


Measured memory_bytes: 3060
a, b, c, x = Array.new(4) { |i| gets.to_i }

ans = 0

a.downto(0) do |c500|
  b.downto(0) do |c100|
    c.downto(0) do |c50|
      ans += 1 if 500*c500 + 100*c100 + 50*c50 == x
    end
  end
end

puts ans

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	
	int n; cin>>n;
	string s; cin>>s;
	//int n=s.length();
	int i=0,j=n-1;
	int op=0;
	while(i<j)
	{
		while(i<n && s[i]!='W')
		{
			i++;
		}
		while(j>=0 && s[j]!='R')
		{
			j--;
		}
		if(i<j)
		{
			op++;
			swap(s[i],s[j]);
		}
		
		
		
	}
	cout<<op;

}

Measured memory_bytes: 3740
# 2019-11-24 20:59:47(JST)
import sys
# import numpy as np
from string import ascii_uppercase as alphabet

alphabet = alphabet[-1] + alphabet[0:]

alpha_num = enumerate(alphabet, 0)

alpha_num = dict((alpha, num) for num, alpha in alpha_num)

def main():
    n, s = sys.stdin.read().split()
    n = int(n)

    t = ''
    for c in s:
        t += alphabet[(alpha_num[c] + n) % 26]
    
    print(t)


if __name__ == '__main__':
    main()


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

mt19937_64 llrand((int) chrono::steady_clock::now().time_since_epoch().count());

#define st first
#define nd second
#define pb push_back

#ifndef ONLINE_JUDGE
  #define db(x) cerr << #x << " == " << x << endl
  #define dbs(x) cerr << x << endl
  #define _ << ", " <<
#else
  #define db(x) ((void)0)
  #define dbs(x) ((void)0)
#endif

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;

const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

int s, w;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> s >> w;
  if(w >= s) cout << "unsafe\n";
  else cout << "safe\n";
}

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

public class Main {

	public static void main(String[] args)throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int A = Integer.parseInt(st.nextToken());
		int Q = Integer.parseInt(st.nextToken());
		String S = br.readLine();
		int []PrefixSumArr = new int[S.length() + 1];
		for(int i =1; i<S.length(); i++) {
			if(S.charAt(i-1)=='A' && S.charAt(i) == 'C') {
				PrefixSumArr[i]++;
			}
		}
		
		for(int i = 1; i<=S.length(); i++) PrefixSumArr[i] += PrefixSumArr[i-1];
		for(int i =0; i<Q; i++) {
			st = new StringTokenizer(br.readLine());
			int length = Integer.parseInt(st.nextToken());
			int row = Integer.parseInt(st.nextToken());
			int counter = PrefixSumArr[row-1] - PrefixSumArr[length-1];
			System.out.println(counter);
		}
			
		
	}

}


Measured memory_bytes: 58232
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, Y, Z;
    cin >> X >> Y >> Z;
    cout << (X-Z)/(Y+Z) << endl;

    return 0;
}


Measured memory_bytes: 256
q = int(input())
primes = [True for _ in range(100000)]
c = [0 for _ in range(100000)]

for i in range(2, 100000):
    if primes[i]:
        for j in range(2*i, 100000, i):
            primes[j] = False

#print(primes[:20])

for i in range(3, 100000, 2):
    if primes[i] and primes[(i+1)//2]:
        c[i] += 1

for i in range(3, 100000):
    c[i] += c[i-1]
#print(c[:20])

for i in range(q):
    l, r = map(int,input().split())
    print(c[r] - c[l-1])


Measured memory_bytes: 7248
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  int second = 0;
  bool flag = true;
  map<int, priority_queue<int, vector<int>, greater<int>>> q;
  REP(i, n)
  {
    cin >> a[i];
    q[a[i]].push(i);
    if (i != 0 && flag && a[i] == a[0])
    {
      flag = false;
      second = i;
    }
  }

  map<int, int> min_index;
  map<int, int> next;
  map<int, int> f;
  REP(i, n)
  {
    if (min_index[a[i]] == 0 && a[i] != a[0])
      min_index[a[i]] = i;
  }

  map<int, int> near_index;
  for (int i = n - 1; i >= 0; i--)
  {
    if (near_index[a[i]] == 0)
    {
      next[i] = a[i];
    }
    else if (near_index[a[i]] == n - 1)
    {
      next[i] = 0;
    }
    else
    {
      next[i] = next[near_index[a[i]] + 1];
    }
    near_index[a[i]] = i;
  }

  f[0] = second == 0 ? a[0] : next[second + 1];
  REP(i, n)
  {
    if (f[a[i]] != 0)
      continue;
    f[a[i]] = next[min_index[a[i]] + 1];
  }

  ll loop = 1;
  int tmp = f[0];
  REP(i, n)
  {
    if (tmp == 0)
      break;
    tmp = f[tmp];
    loop++;
  }

  // 解の構成
  tmp = 0;
  for (int i = 0; i < ((k - 1) % loop); i++)
  {
    tmp = f[tmp];
  }
  int init_index = tmp == 0 ? 0 : min_index[tmp] + 1;

  vector<int> ans;
  for (int i = init_index; i < n; i++)
  {
    bool updated = false;
    while (!q[a[i]].empty())
    {
      int po = q[a[i]].top();
      q[a[i]].pop();
      if (po > i)
      {
        i = po;
        updated = true;
        break;
      }
    }
    if (!updated)
    {
      ans.push_back(a[i]);
    }
  }

  REP(i, ans.size())
  {
    cout << ans[i];
    if (i != ans.size() - 1)
    {
      cout << " ";
    }
  }
  cout << endl;
}


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

int sum(int num){
  int sum=0;
  while(num){
	sum += num % 10;
    num /= 10;
  }
  
  return sum;
}

int main(){
  int n,x,y,min=1000;
  cin >> n;
  for(int i=1; i<=(n/2); i++){
    x = sum(i);
    y = sum(n-i);
    if(min > (x+y)){
      min = x+y;
    }
  }
  cout << min << endl;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h[10];
    for(int i=0; i<10; i++) {
        cin>>h[i];
    }
    for(int i=0; i<3; i++) {
        for(int j=9; j>i; --j) {
            if(h[j-1]<h[j]) swap(h[j-1], h[j]);
        }
    }
    for(int i=0; i<3; i++) cout<<h[i]<<'\n';
    return 0;
}



Measured memory_bytes: 3164
package main

import (
	"fmt"
)

func main() {
	var h1, m1, h2, m2, k int
	fmt.Scan(&h1, &m1, &h2, &m2, &k)
	fmt.Println((h2-h1)*60 + (m2 - m1) - k)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


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


int main(){
  vector<string> mem;
  string s;
  int n;
  bool flag=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    mem.push_back(s);
  }
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    for(int j=0;j<mem.size();j++){
      if(mem[j]==s){
	if(flag==0){
	  cout<<"Opened by "<<s<<endl;
	  flag=1;
	}else{
	  cout<<"Closed by "<<s<<endl;
	  flag=0;
	}
	//cout<<"flag is "<<flag<<endl;
	break;
      }
      if(j==mem.size()-1)cout<<"Unknown "<<s<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1220
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let s: String = read(&mut stdin_lock, &mut buf, b'\n');
    let mut cs: Vec<char> = s.chars().collect();
    cs.sort();
    let t: String = cs.into_iter().collect();
    let ans = if t == "abc" { "Yes" } else { "No" };
    println!("{}", ans);
}


Measured memory_bytes: 4352
using System;
using System.IO;
using System.Linq;

namespace AtCoder {
	class Program {
		public static void Main() {
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

			int[] a =  Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			Console.WriteLine($"{a[2]} {a[0]} {a[1]}");

			Console.Out.Flush();
		}
	}
}

Measured memory_bytes: 13396
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;


int main(){
	vector<int> input(5);
	while(cin >> input[0] >> input[1] >> input[2] >> input[3] >> input[4]){
		for(int i = 0; i < 5; i++){
			for(int j = i + 1; j < 5; j++){
				if(input[i] < input[j]){
					swap(input[i],input[j]);
				}
			}
		}

		for(int i = 0; i < input.size(); i++){
			if(i){
				cout << " ";
			}
			cout << input[i];
		}
		cout << endl;
	}
	return 0;
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;

void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    string s, t;
    cin >> s >> t;
    int ok = 0;
    FOR(i, 0, s.size() - 1)
        if(s[i] == t[i]) ok++;
    cout << ok;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
g = [[] for i in range(n)]
for i in range(n-1):
    a,b,c = inpl()
    g[a-1].append((b-1,c))
    g[b-1].append((a-1,c))
color = [-1] * n 
color[0] = 0
def dfs(node):
    for v,c in g[node]:
        if color[v] != -1:
            continue
        if (c) % 2:
            color[v] = 0 if color[node] else 1
        else: color[v] = 1 if color[node] else 0
        dfs(v)
dfs(0)

for i in color:
    print(i)

Measured memory_bytes: 158864
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    int N; ll K;
    cin >> N >> K;
    ll A[N];
    rep(i, N){
        cin >> A[i]; A[i]--;
    }
    map<ll, vector<int>> mp;
    ll sum = 0;
    mp[0].pb(0);
    rep(i, N){
        sum += A[i], sum %= K;
        mp[sum].pb(i+1);
    }
    ll ans = 0;
    for(auto &e: mp){
        ll i = 0;
        for(auto &v: e.second){
            i++;
            ll n = lower_bound(all(e.second), v+K) - e.second.begin();
            ans += n-i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 23680
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n,k=MI()
    h=LI()
    h.sort()
    if n<=k:
        print(0)
    else:
        x=n-k
        s = sum(h[:x])
        print(s)

if __name__ == "__main__":
    main()

Measured memory_bytes: 27812
if __name__ == "__main__":
    
    n = int(input())
    ops = []
    words = []
    for _ in range(n):
        op, word = input().split()
        ops.append(op)
        words.append(word)
    
    db = set()
    for op, word in zip(ops, words):
        if op=='insert':
            db.add(word)
        else:
            if word in db:
                print("yes")
            else:
                print("no")



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

int main(){
    int  n; cin >> n;
    string s; cin >> s;
    int x = 0, maxn = 0;

    for(auto c : s){
        if(c == 'I'){
            x++;
        }else{
            x--;
        }
        maxn = max(x, maxn);
    }

    cout << maxn << endl;
}

Measured memory_bytes: 256
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a, b, c;
    cin >>a >>b >>c;
    int ans = b + c - a;
    if(ans < 0)
        cout <<0;
    else 
        cout <<ans;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3,no-stack-protector")
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("avx")
// AtCoder新ジャッジ以降
// #pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

bool isOK(const vector<Int> &A, int index, Int key) {
    if (A[index] < key) {
        return true;
    } else {
        return false;
    }
}

int b_search(const vector<Int> &A, Int key) {
    int ng = -1;
    int ok = (int)A.size();

    while (ok - ng > 1) {
        int mid = ng + (ok - ng) / 2;

        if (isOK(A, mid, key)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    return ok;
}

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

    int n;
    cin >> n;
    vector<Int> a(n), ans(n, -1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    ans[0] = a[0];
    int color = 1;
    for (int i = 1; i < n; i++) {
        auto index = b_search(ans, a[i]);
        if (ans[index] == -1) {
            ans[color] = a[i];
            color++;
        } else {
            ans[index] = a[i];
        }
    }

    cout << color << endl;

    return 0;
}


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

using ll = long long;

template <typename T>
class fenwick_tree {
public:
    fenwick_tree(int n_) : n(n_), dat(n) {}

    void add(int i, T value) {
        for(; i < n; i |= i + 1) {
            dat[i] += value;
        }
    }

    T sum(int i) const {
        T res = 0;
        for(; i >= 0; i = (i & (i + 1)) - 1) {
            res += dat[i];
        }
        return res;
    }
    T sum(int l, int r) {
        return sum(r - 1) - sum(l - 1);
    }

private:
    const int n;
    vector<T> dat;
};


int main() {
    string s; cin >> s;
    const int n = s.size();
    vector<deque<int>> ps(26);
    for(int i = 0; i < n; ++i) {
        ps[s[i] - 'a'].push_back(i);
    }

    if(2 <= count_if(ps.begin(), ps.end(), [] (auto const& v) { return (v.size() & 1) == 1; })) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> p(n);
    for(int i = 0, j = 0; i < n; ++i) {
        const int c = s[i] - 'a';
        if(ps[c].empty()) continue;
        if(ps[c].size() == 1u) {
            p[i] = n / 2;
            ps[c].pop_back();
        } else {
            p[i] = j++;
            p[ps[c].back()] = n - p[i] - 1;
            ps[c].pop_front();
            ps[c].pop_back();
        }
    }

    ll ans = 0;
    fenwick_tree<ll> bit(n);
    for(int i = 0; i < n; ++i) {
        ans += bit.sum(p[i], n);
        bit.add(p[i], 1);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
    int idx = -1;
    for (int i = 0; i < N; i++) {
        if (A[i] > B[i] && (idx == -1 || B[i] < B[idx])) idx = i;
    }
    if (idx == -1) cout << "0\n";
    else cout << accumulate(begin(A), end(A), 0LL) - B[idx] << '\n';
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <numeric>
#include <set>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()

ll dx[4] = { 0, 1,  0, -1 };
ll dy[4] = { 1, 0, -1,  0 };
ll h, w;
string a[500];
ll ans = 0,c,d;
void dfsw(int x, int y);
void dfsb(int x, int y);

int main() {
	string s[500] = {};
	cin >> h >> w;
	REP(i,h) cin >> s[i];
	REP(k, h) a[k] = s[k];
	REP(i, h) {
		REP(j, w) {
			c = 0, d = 0;
			if (a[i][j] == '#') dfsb(i, j);
			ans += c * (d + 1);
		}
	}
	cout << ans << endl;
}

void dfsb(int x, int y) {
	a[x][y] = 'a';
	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i], ny = y + dy[i];
		if (nx >= 0 and ny >= 0 and nx < h and ny < w) {
			if (a[nx][ny] == '.') {
				dfsw(nx, ny);
				c++;
			}
		}
	}
}

void dfsw(int x, int y) {
	a[x][y] = 'a';
	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i], ny = y + dy[i];
		if (nx >= 0 and ny >= 0 and nx < h and ny < w) {
			if (a[nx][ny] == '#') {
				d++;
				dfsb(nx, ny);
			}
		}
	}
}



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

int main(){
while(1){
	int n,k,a[100002],sum=0,ans=0;
	scanf("%d%d",&n,&k);
	if(n==0&&k==0)break;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<k;i++){
		sum+=a[i];
	}
	ans=sum;
	for(int i=0;k<n;i++){
		sum-=a[i];
		sum+=a[k];
		if(ans<sum)ans=sum;
		k++;
	}
	printf("%d\n",ans);
}
}

Measured memory_bytes: 1560
#include <math.h>
#include <bits/stdc++.h>
#include <deque>
#include<vector>
#define ll long long
#define l long double
#define pi 3.14159265358979323846
#define mod 1000000007
#define vali 1000000000000000000
using namespace std;
int main()
{
    ll a,b;
    cin>>a>>b;
    ll s=b/2;
    ll s1=b%2;
    ll x,y;
    x=2*a-s;
    y=s-a;
    if(x>=0 && y>=0 && s1==0)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3624
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}
int dp[3001][3001][2];
int a[3001];
int n;
int ans(int l,int r,int p)
{
    int &res=dp[l][r][p];
    if(res!=-1)
        return dp[l][r][p];
    if(l==r)
    {
        if(p==0)
        {
            return res=a[l];
        }
        else
            return res=-a[l];
    }
    if(p==0)
    {
        res=max(ans(l+1,r,!p)+a[l],ans(l,r-1,!p)+a[r]);
    }
    else
        res=min(ans(l+1,r,!p)-a[l],ans(l,r-1,!p)-a[r]);
    return res;

}
int32_t main()
{
    IOS
  
  
  cin>>n;

  for(int i=0;i<n;++i)
    cin>>a[i];
    memset(dp,-1,sizeof(dp));
    cout<<ans(0,n-1,0);


}



Measured memory_bytes: 141184
N,C=map(int, input().split())
inarr=[[int(i) for i in input().split()] for _ in range(N)]
maxes=[[(0, 0)]*N,[(0, 0)]*N]
cums=[0]*(N+1)
cum = 0
cummax1 = (0, 0)
cummax2 = (0, 0)
for i, [a, v] in enumerate(inarr):
    cum += v
    if (cum - a) > cummax1[0]:
        cummax1 = (cum - a, a)
    if (cum - 2*a) > cummax2[0]:
        cummax2 = (cum - 2*a, a)
    maxes[0][i]=cummax1
    maxes[1][i]=cummax2
    cums[i+1]=cum

resmax = 0
for i, [b, v] in enumerate(inarr):
    oasum1, x = (0, 0) if i == 0 else maxes[0][i-1]
    oasum2, x = (0, 0) if i == 0 else maxes[1][i-1]
    ob = cums[N] - cums[i]
    resmax = max(resmax, ob + oasum1 - 2*(C-b), ob + oasum2 - (C-b))

print(max(resmax, maxes[0][N-1][0], 0))


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

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

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    (a *= a) %= MOD;
    n >>= 1;
  }
  return res;
}

const ll maxf = 10000000;
ll fact[maxf+5];
ll ifact[maxf+5];

void fact_init(){
  fact[0] = 1;
  for(ll i=1; i<=maxf; i++) fact[i] = (fact[i-1] * i) % MOD;
  ifact[maxf]=modpow(fact[maxf],MOD-2);
  for(ll i=maxf; i>=1; i--) ifact[i-1] = (ifact[i] * i) % MOD;
}

ll comb(ll n, ll r){
  if(n<r || n<0 || r<0) return 0;
  if(fact[0] == 0) fact_init();
  return ((fact[n] * ifact[n-r]) % MOD * ifact[r]) % MOD;
}

ll naive_comb(ll n, ll r){
  ll res = 1;
  for (ll i = n; i > n - r; i--) res = res * i % MOD;
  for (ll i = 1; i <= r; i++) res = (res * modpow(i, MOD-2)) % MOD;
  return res;
}

// 参考: https://drken1215.hatenablog.com/entry/2019/06/15/111500

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m,k; cin>>n>>m>>k;
  ll sum=0;
  // y軸方向の取りうる距離
  for(ll i=0; i<=n-1; i++){
    // x軸方向の取りうる距離
    for(ll j=0; j<=m-1; j++){
      // y軸方向の距離がiのとき、選べるマスの組数はn-i通り (x軸も同様に考える)
      // (配置する駒同士は区別されない)
      ll tmp=(n-i)*(m-j)%MOD*(i+j)%MOD;
      // i,jがともに0でないならば、そのような駒の配置の仕方は2パターン存在する
      // 例えば (x1,y1), (x2,y2) が i,j を成すなら、(x1,y2), (x2,y1) も同様に i,j を成す
      // 互いに区別される配置で同じ i,j の組合せがもう一組作れるので、i,j がともに0でない場合は2倍する
      if(i!=0 && j!=0) (tmp*=2)%=MOD;
      (sum+=tmp)%=MOD;
    }
  }
  ll ans=(sum*comb(n*m-2,k-2))%MOD;
  cout<<ans<<endl;
}

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

using namespace std;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if((abs(a-c)<=d) || ((abs(a-b)<=d)&&(abs(b-c)<=d)))cout << "Yes" << endl;
  else cout << "No" << endl; 
  return 0;
}

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

using namespace std;

#ifdef LOCAL
#define DBG_MACRO_NO_WARNING
#include <dbg.h>
#else
#define dbg(...) 0
#endif

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

const int MOD = 2019;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  string s;

  cin >> s; 
  
  int n = s.length();
  int suf = 0;
  int power_of_ten = 1;
  vector<int> cnt_suf(MOD);
  cnt_suf[0]++;
  long long answer = 0;
  // O(N)
  for (int i = n - 1; i >= 0; i--) {
    suf = (suf + (s[i] - '0') * power_of_ten) % MOD;
    power_of_ten = 10 * power_of_ten % MOD;
    // cout << i << " " << suf << " " << power_of_ten << endl;
    answer += cnt_suf[suf];
    cnt_suf[suf]++;
  }
  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 3696
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

S = input()
Sset = set(S)
# print(Sset)
if len(S) == len(Sset):
    print("yes")
else:
    print("no")


Measured memory_bytes: 8952
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var c = Str[0];
		var s1 = new HashSet<char>("AT");
		var s2 = new HashSet<char>("GC");
		if (s1.Contains(c)) { s1.Remove(c); WriteLine(s1.First()); }
		else { s2.Remove(c); WriteLine(s2.First()); }
	}
}


Measured memory_bytes: 13396
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){
  string X,Y;
  int l=0;
 int point;


  cin>>X>>Y;
 int N[X.size()+1][Y.size()+1];

 
  for(int i=0;i<=Y.size();i++){
  
      N[0][i]=i;

  }
 
 for(int i=1;i<=X.size();i++){
  
      N[i][0]=i;

  }
 
 

  for(int i=1;i<=X.size();i++){
    for(int j=1;j<=Y.size();j++){
      if(X[i-1]==Y[j-1]){
	point=0;
	
      }else{
	point=1;
      }
      N[i][j]=min(min(N[i-1][j]+1,N[i][j-1]+1),N[i-1][j-1]+point);
   

   
  }
  }
  cout<<N[X.size()][Y.size()]<<endl;
 return 0;
}



Measured memory_bytes: 7128