akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
dp = [[-10**18]*3 for _ in range(N)]
dp[0][0] = A[0]
dp[1][1] = A[1]

if N>=3:
    dp[2][2] = A[2]

for i in range(2, N):
    dp[i][0] = dp[i-2][0]+A[i]
    dp[i][1] = max(dp[i][1], dp[i-2][1]+A[i])
    
    if i>=3:
        dp[i][1] = max(dp[i][1], dp[i-3][0]+A[i])
    
    dp[i][2] = max(dp[i][2], dp[i-2][2]+A[i])
    
    if i>=3:
        dp[i][2] = max(dp[i][2], dp[i-3][1]+A[i])
    
    if i>=4:
        dp[i][2] = max(dp[i][2], dp[i-4][0]+A[i])

if N%2==0:
    print(max(dp[N-2][0], dp[N-1][1]))
else:
    print(max(dp[N-3][0], dp[N-2][1], dp[N-1][2]))

Measured memory_bytes: 112196
#include <bits/stdc++.h>
#define ll long long
#define M 1000000007 
#define MM 998244353
#define PI 3.14159265 
using namespace std;
 
int main()
{
	int a, b, c;

	cin >> a >> b >> c;

	if (b*c >= a)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}

  	return 0;
}

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

using namespace std;

int n;
vector<int> arr , ans;

bool left() {
    queue<int> aval;
    for (int i = 0 ;i < arr.size() ;i++) {
        if (!~arr[i]) {
            aval.push(i);
            continue;
        }

        if (aval.size() < arr[i] - 1) return 0;

        for (int j = 0 ;j < arr[i] - 1;j++) {
            ans[aval.front()] = arr[i];
            aval.pop();
        }
    }

    return 1;
}

bool right() {
    queue<int> aval;
    for (int i = arr.size() - 1 ; ~i ;i--) {
        if (!~arr[i]) {
            aval.push(i);
            continue;
        }

        if (aval.size() < n - arr[i]) return 0;

        for (int j = 0 ;j < n - arr[i] ;j++) {
            ans[aval.front()] = arr[i];
            aval.pop();
        }
    }

    return 1;
}

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

    arr = ans = vector<int> (n * n , -1) ;

    int x;
    for (int i = 1 ;i <= n ;i++) {
        scanf("%d" , &x);
        arr[x - 1] = ans[x - 1] = i;
    }

    if (!left() || !right()) {
        puts("No");
        return 0;
    }

    puts("Yes");
    for (int i = 0 ;i < ans.size() ;i++)
        printf("%d " , ans[i]);
}

Measured memory_bytes: 3308
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  int C = 0;
  
  for(int i=0; i<N; i++){
    int l, r;
    cin >> l >> r;
    C += r-l+1;
  }
  cout << C << endl;
}

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

int main(void){
	int m, i, j, k, l, h, len, aft_len;
	char str[201], *first, *last, str_first[200], str_last[200];
	first = str;
	last = str;
	
	//シャッフルする文字列を、境界のインデックスで二つに分けてそれぞれを別の配列に保存する、という方法もアリかも
	do{
		scanf("%s\n", str);
		if(str[0] == '-'){
			break;
		}
		len = strlen(str);
		scanf("%d\n", &m);
		for(i = 0; i < m; i++){
			scanf("%d\n", &h);
			last += h;
			aft_len = len-h;
			strncpy(str_first, first, h);
			strncpy(str_last, last, aft_len);
			for(j = 0; j < aft_len; j++){
				str[j] = str_last[j];
			}
			for(k = aft_len, l = 0; k < len; k++, l++){
				str[k] = str_first[l];
			}
			last = str;
		}
		printf("%s\n", str);
	}while (1);
	return 0;
}



Measured memory_bytes: 2064
fun calc141B(s:String): String{
    val a = s.filterIndexed{i, c -> i % 2 == 0}.all { "RUD".contains(it) } &&
            s.filterIndexed{i, c -> i % 2 == 1}.all { "LUD".contains(it) }
    return if (a) "Yes" else "No"
}


fun main(args:Array<String>) {
    val S = readLine()!!
    println(calc141B(S))
}


Measured memory_bytes: 33724
extern crate core;

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

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

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

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

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

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

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

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

fn solve(input: String) -> String {
    input!(input=>(n:usize)(s:#));
    let s = s.chars().collect::<Vec<_>>();
    let mut max = 0;
    //0-i、i+1-n-1
    for i in 0..n {
        let mut count = 0;
        for c in "abcdefghijklmnopqrstuvwxyz".chars() {
            if s.clone().into_iter().take(i).find(|&x| x == c).is_some()
                && s.clone().into_iter().skip(i).find(|&x| x == c).is_some()
            {
                count += 1;
            }
        }
        max = std::cmp::max(max, count);
    }
    max.to_string()
}

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

tests! {
    test1: "6\naabbca" => "2",
    test2: "10\naaaaaaaaaa" => "1",
    test3: "45\ntgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir" => "9",
}


Measured memory_bytes: 4352
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;


	public class Main {
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
	        
			int n = sc.nextInt();
			
			String[] S = new String[n];
			
			for(int i=0;i<n;i++) {
				char[] s = sc.next().toCharArray();
				Arrays.sort(s);
				String str = new String(s);
				S[i] = str;
				
			}
			
			Arrays.sort(S);
			long ret = 0;
			long one = 1;
			Map<String,Long> m = new HashMap<String,Long>();
			
			for(int i=0;i<n;i++) {
				m.merge(S[i], one, Long::sum);
			}
			
			for(Map.Entry<String, Long> e:m.entrySet()) {
				ret+=e.getValue()*(e.getValue()-1)/2;
			}
			
			System.out.println(ret);
		}
		
	}


Measured memory_bytes: 56584
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };
typedef tuple<ll, ll, ll>T;
typedef pair<ll,ll>pll;

double dp[3030][3030];

int main(){
	int n;
	cin >> n;
	vector<double>p(n);
	rep(i, 0, n)cin >> p[i];

	dp[0][0] = 1;
	rep(i, 1, n+1)rep(j, 0, i + 1) {
		if (j > 0) {
			dp[i][j] = p[i-1] * dp[i - 1][j - 1] + (1.0 - p[i-1])*dp[i - 1][j];
		}
		else {
			dp[i][j] = (1-p[i - 1]) * dp[i-1][j];
		}
	}

	double ans = 0;
	rep(j,0,n+1){
		if (j > n - j) {
			ans += dp[n][j];
		}
	}
	printf("%.20f",ans);
	cout << endl;
	
	return 0;
}



Measured memory_bytes: 70272
n,m = map(int, input().split())
k = [list(map(int, input().split())) for i in range(n)]
food_list = [0] * m
for i in range(n):
    for j in range(len(food_list)):
        if j+1 in k[i][1:]:
            food_list[j] += 1
        else:
            continue
cnt = 0
for i in range(len(food_list)):
    if food_list[i] == n:
        cnt += 1
    else:
        continue
print(cnt)

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

bool return_start(int v, int start, int goal, vector<int> *es) {
    int prev = start;
    while (v != start && v != goal) {
        for (int n: es[v]) {
            if (n != prev) {
                prev = v;
                v = n;
                break;
            }
        }
    }
    return (v == start);
}

bool has_three(vector<int> four_neighber, vector<int> *es) {
    int start = four_neighber[0];
    for (int v: es[start]) {
        if (return_start(v, start, four_neighber[1], es)) {
            return true;
        }
    }
    return false;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> es[n];
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        es[a].push_back(b);
        es[b].push_back(a);
    }
    vector<int> four_neighber;
    bool flag = false;
    //for (auto v: es) {
    for (int i = 0; i < n; i++) {
        vector<int> v = es[i];
        int len = v.size();
        if (len & 1) {
            cout << "No" << endl;
            return 0;
        }
        if (len >= 6) {
            flag = true;
        } else if (len == 4) {
            four_neighber.push_back(i);
        }
    }
    if (flag) {
        cout << "Yes" << endl;
    } else {
        int count4 = four_neighber.size();
        if (count4 <= 1) {
            cout << "No" << endl;
        } else if (count4 >= 3) {
            cout << "Yes" << endl;
        } else {
            if (has_three(four_neighber, es)) {
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 5760
n, k = map(int, input().split())
dat_x = list(map(int, input().split()))
l = 0
r = k - 1
total = 0
for i in range(1, k):
    # print("{0} - {1}".format(dat_x[i] , dat_x[i - 1] ))
    # print("abc: {0}".format(abs(dat_x[i] - dat_x[i - 1])))
    total += abs(dat_x[i] - dat_x[i - 1])

total += min(abs(dat_x[l]), abs(dat_x[r]))

m = total
# print("m = {0}".format(m))

#print("check: {0}, {1} = {2}".format(l, r, total))
r += 1
l += 1

while r < n:
    #print("!!!!!!!!")
    #print(dat_x[l])
    #print(dat_x[l-1])
    total -= min(abs(dat_x[l-1]), abs(dat_x[r-1]))
    #print("check-0: {0}, {1} = {2}".format(l, r, total))
    total -= abs(dat_x[l] - dat_x[l - 1])
    #print("check-1: {0}, {1} = {2}".format(l, r, total))
    total += abs(dat_x[r] - dat_x[r - 1])
    #print("check-2: {0}, {1} = {2}".format(l, r, total))
    total += min(abs(dat_x[l]), abs(dat_x[r]))

    m = min(m, total)
    r += 1
    l += 1

print(m)


Measured memory_bytes: 14480
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){
    int n,q;
    cin>>n>>q;
    vector<list<int>> v(n);
    rep(i,0,q){
        //cout<<i<<endl;
        int cmd;cin>>cmd;
        if(cmd==0){
            int t,x;cin>>t>>x;v[t].push_back(x);
        }else if(cmd==1){
            int t;cin>>t;
            for(list<int>::iterator it = v[t].begin();it != v[t].end();it++){
                if(it != v[t].begin()) cout << " ";
                cout << *it;
            }
            cout<<endl;
        }else {
            int s,t;cin>>s>>t;
            v[t].splice(v[t].end(),v[s]);
        }
    }
    

}



/*
1 2 3 4 5

6
*/



Measured memory_bytes: 18728
#include<stdio.h>

int search(int A[], int n, int key){
  int i = 0;
  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}

int main(){
  int i,n,A[10000+1],q,key,sum = 0;

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

  scanf("%d",&q);
  for(i = 0; i<q;i++){
    scanf("%d",&key);
    if(search(A,n,key)) sum++;
  }
  printf("%d\n",sum);
  return 0;
}



Measured memory_bytes: 2140
MOD = 1000000007
def main():
    n, m = [int(x) for x in input().split()]
    pattern = [1]
    broken = -1
    brokencnt = 0
    if brokencnt < m:
        broken = int(input())
        brokencnt += 1
    for i in range(1, n + 1):
        if i == broken:
            pattern.append(0)
            if brokencnt < m:
                broken = int(input())
                brokencnt += 1
            continue
        if i == 1:
            pattern.append(pattern[i - 1])
        if i > 1:
            pattern.append((pattern[i - 1] + pattern[i - 2]) % MOD)
    print(pattern[n])
main()

Measured memory_bytes: 7060
#include <iostream>

using namespace std;
int main()
{
    long long int a,s = 1;
    
    cin >> a;
    
    for(int i = 1; i <= a;++i)
    {
        s *= i;
        s = s%1000000007;
    }
    cout << s << "\n";
    
    return 0;
}


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

public class Main {
    static Deque<String> list = new ArrayDeque<>();

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] sp = new String[2];

        int n = Integer.parseInt(br.readLine());
        for (int i = 0; i < n; i++) {
            sp = br.readLine().split(" ");
            if (sp[0].equals("insert")) {
                list.addFirst(sp[1]);
            } else if (sp[0].equals("delete")) {
                list.remove(sp[1]);
            } else if (sp[0].equals("deleteFirst")) {
                list.removeFirst();
            } else if (sp[0].equals("deleteLast")) {
                list.removeLast();
            }
        }
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringBuilder ans = new StringBuilder();
        ans.append(list.poll());
        for (String s : list) {
            ans.append(" ");
            ans.append(s);
        }
        bw.write(ans.toString());
        bw.newLine();
        bw.close();
        br.close();
    }
}



Measured memory_bytes: 228256
# -*- coding: utf-8 -*-
S = input()
T = input()

Smap = {}
Tmap = {}

for c in S:
    if c in Smap:
        Smap[c] += 1
    else:
        Smap[c] = 1

Sval = list(Smap.values())
Sval.sort()

for c in T:
    if c in Tmap:
        Tmap[c] += 1
    else:
        Tmap[c] = 1

Tval = list(Tmap.values())
Tval.sort()

# print(Sval)
# print(Tval)
if Sval == Tval:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3684
N, M, C = map(int, input().split())

B = list(map(int, input().split()))
A = []
for _ in range(N):
    A_i = list(map(int, input().split()))
    A.append(A_i)
    
    
ans = 0
for A_i in A:
    cal = lambda x, y : x * y
    mul_ab = map(cal, A_i, B)
    sum_ab = sum(mul_ab)
    sum_c = sum_ab + C
    if sum_c > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3064
//ll _(){
//    ll n;
//    cin >> n;
//    ll m = 1;
//    while(m*(m+1)/2 < n)
//        ++m;
//    return m;
//}
//
//
//
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define all(v) (v).begin(), (v).end()
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
ll _(){
    ll n;
    cin >> n;
    ll m = 1;
    while(m*(m+1)/2 < n)
        ++m;
    return m;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        cout << _() << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#include <numeric>
#define INF 1000000000
#define LLINF 2000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  string s,t;
  cin >> s >> t;
  if(s.length() == 1 + t.length()){
    cout << "No" << endl;
    return 0;
  }
  LOOP(i,s.length()){
    if(s[i]!=t[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
	int n,k[1000],p[1000],i,a;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&k[i],&p[i]);
		if(k[i]>=p[i]){
			a=k[i]%p[i];
			if(a==0){
				printf("%d\n",p[i]);
			}
			if(a!=0){
				printf("%d\n",a);
			}
		}
		else if(k[i]<=p[i]){
			printf("%d\n",k[i]);
		}
	}
	return 0;
}

			


Measured memory_bytes: 2768
s = input()
t = input()


def check_match(a, b):
  m = len(a)
  for i in range(m):
    if not (a[i] == '?' or a[i] == b[i]):
      return False
  return True


def calc_possible_s(s, t):
  """
  Args:
    s, t (str)
  Returns:
    list[str]
  """
  buf = []
  n, m = len(s), len(t)
  assert n >= m
  for i in range(n-m+1):
    # compare s[i:i+m] and t. 
    if check_match(s[i:i+m], t):
      buf.append(s[:i].replace('?', 'a') + t + s[i+m:].replace('?', 'a'))
  return buf


if len(t) > len(s):
  print('UNRESTORABLE')
else:
  possible_s = calc_possible_s(s, t)
  if possible_s:
    print(min(possible_s))
  else:
    print('UNRESTORABLE')

Measured memory_bytes: 38384
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
    // X側の原点に一番近いところに移動する回数
    ll cnt0 = X / D;
    if (K < cnt0)
    {
        cout << abs(X - D * K);
        return 0;
    }
    // 原点を往復する回数
    K -= cnt0;
    if (K > 0)
    {
        if (K % 2)
        {
            cout << D - X % D;
        }
        else
        {
            cout << X % D;
        }
        return 0;
    }
    else
    {
        cout << abs(X - D * cnt0);
        return 0;
    }

    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int H, W;
vector<string> M;

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

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

int bfs(int x, int y) {
    if(M[y][x] == '#') return 0;

    vector<vector<bool>> visited(30, vector<bool>(30, false));
    queue<P> q;
    q.push(make_pair(make_pair(x, y), 0));
    visited[y][x] = true;
    int cost = 0;
    while (!q.empty()) {
        P p = q.front();
        q.pop();

        rep(k, 4) {
            int nx = p.first.first + dx[k];
            int ny = p.first.second + dy[k];
            if (nx < 0 || W <= nx || ny < 0 || H <= ny || M[ny][nx] == '#') continue;
            if (visited[ny][nx]) continue;
            visited[ny][nx] = true;
            P np = make_pair(make_pair(nx, ny), p.second + 1);
            chmax(cost, p.second + 1);
            q.push(np);
        }
    }

    return cost;
}

int main() {
    cin >> H >> W;
    M.resize(H);
    rep(i, H) cin >> M[i];

    int ans = 0;
    rep(j, H) {
        rep(i, W) {
            chmax(ans, bfs(i, j));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            execute(sc);

        }
    }

    static void execute(Scanner sc) {
        int n = Integer.parseInt(sc.nextLine());
        if (n == 0) {
            return;
        }
        Map<String, Long> map = new LinkedHashMap<String, Long>();
        long price, count, rs;
        for (int i = 0; i < n; i++) {
            rs = 0;
            String[] line = sc.nextLine().split(" ");
            if (map.containsKey(line[0])) {
                rs = (Long) map.get(line[0]);
            }
            price = Long.parseLong(line[1]);
            count = Long.parseLong(line[2]);
            map.put(line[0], price * count + rs);
        }
        boolean exists = false;
        for (String key : map.keySet()) {
            if (map.get(key) >= 1000000) {
                System.out.println(key);
                exists = true;
            }
        }
        if (!exists) {
            System.out.println("NA");
        }
    }
}



Measured memory_bytes: 31968
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='C'){
			for(int j=i+1;j<s.size();j++){
				if(s[j]=='F'){
					cout<<"Yes"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
int A,B,C,D;
scanf("%d",&A);
scanf("%d",&B);
scanf("%d",&C);
scanf("%d",&D);
while(A>0&&C>0)
{
C=C-B;
A=A-D;
if(C<=0)
A=A+D;
}
if(A<=0)
printf("No");
else
printf("Yes");
return 0;
}

Measured memory_bytes: 1728
#include<stdio.h>
#include<string.h>
int main()
{
	char a[200];
	int i,b;
	gets(a);
	b=strlen(a);
	printf("%c",a[0]);
	for(i=0;i<b;i++)
	{
		if(a[i]==' ')
		{
			printf("%c",a[i+1]);
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-

while True:
    m, f, r = map(int, raw_input().split())
    if m == f == r == -1:
        break
    elif m == -1 or f == -1:
        print 'F'
    elif m+f >= 80:
        print 'A'
    elif m+f >= 65:
        print 'B'
    elif m+f >= 50:
        print 'C'
    elif m+f >= 30:
        if r >= 50:
            print 'C'
        else:
            print 'D'
    else:
        print 'F'

Measured memory_bytes: 6436
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int q(int a,int b){
    cout << "? " << a << " " << b << endl;
    int t;
    cin >> t;
    return t;
}



int main(){
    int n,s,t;
    cin >> n >> s >> t;
    map<pair<int,int>,int >mp; 
    int dist = q(s,t);
    vector<pair<int,int> > v;
    for(int i=1;i<=n;i++){
        if(i==s||i==t)continue;
        int dsi = q(s,i);
        int dit = q(i,t);
        if(dsi+dit==dist){
            v.push_back(MP(dsi,i));
            mp[MP(s,i)] = dsi;
            mp[MP(i,t)] = dit;
        }
    }
    sort(v.begin(),v.end());
    int m = v.size();
    vector<int>res;
    res.push_back(s);
    res.push_back(v[0].second);
    int id = v[0].second;
    for(int i=1;i<m;i++){
        int next = v[i].second;
        int d = q(id,next);
        if(mp[MP(s,id)]+d == mp[MP(s,next)]){
            res.push_back(next);
            id = next;
        }
    }
    res.push_back(t);
    cout << "! ";
    for(int i=0;i<res.size();i++){
        cout << res[i];
        if(i!=res.size()-1){
            cout << " ";
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4652
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}



using Graph = vector<vector<int>>;


int main() {
	ll N;
	cin >> N;
	vector<ll> H(N + 1);
	rep(i, N) {
		cin >> H.at(i);
	}
	ll an = 0;
	rep(i, N) {
		while (H.at(i) > 0) {
			an++;
			for (ll j = i; j < N; j++) {
				if (H.at(j) == 0) {
					break;
				}
				else {
					H.at(j)--;
				}
			}
			
		}
	}
	cout << an << endl;
}

Measured memory_bytes: 256
// Problem : Rabbo Loves Jumping
// Contest : CodeChef - ketek[i] QuickMatch 25
// URL : https://www.codechef.com/KQKM2020/problems/HRJMP
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

/*/ Author:Amar1503/*/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define fio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ull unsigned long long
#define ll long long
#define inf 1e9
#define mninf INT_MIN
#define Mod 1000000007
#define endl "\n"
#define cp(x) cout<<(x)<<" "
#define cl(x) cout<<(x)<<endl
#define ct(x,y) cout<<(x)<<" "<<(y)<<endl;
#define nl   cout<<endl
//const double PI=3.1415926535897932384626433832;
//looping
#define For(i,a,b) for(int i=a;i<b;i++)
#define test(t)  int (t); cin>>(t); while((t)--)
#define array(a,n) int (n); cin>>(n); int a[n]; for(int i=0;i<(n);i++) cin>>a[i];
#define trace(x) clog<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) clog<<#x<<": "<<x<<"     "<<#y<<" "<<y<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define printv(v)  for(int i=0;i<(v).size();i++) cout<<v[i]<<" "
//containers
#define F first
#define S second
#define pb emplace_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define itr(it, a) for(auto it = (a).begin(); it != (a).end(); it++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ers(v)   sort(all(v)); (v).erase(unique(all(v)),(v).end())
#define printmatrix(a,n,m) for(int i=0;i<n;i++){ for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
typedef pair <int, int> pii;
typedef vector < pair <int, int> > vpii;
// cout<<"\nTime Elapsed : " << 1.0*clock() /CLOCKS_PER_SEC << " s\n";
int dx[8]={1,-1,0,0,1,1,-1,-1};
int dy[8]={0,0,1,-1,1,-1,1,-1};
#define int long long
const ll INF=1e18L+5;
/*/----------------------------Code begins----------------------------------/*/
int32_t main(){
fio;
int n,W;
cin>>n>>W;
vector<pair<int,int> > v(n);
int totalval=0;
for(int i=0;i<n;i++){
	cin>>v[i].F>>v[i].S;
	totalval+=v[i].S;
}
vector<int> dp(totalval+1,INF);//because w are <=W and there are 100 of them
//dp[i] is the minimum wt with values exactly equal to i
dp[0]=0;// as for 0 val minwt is 0;
for(int i=0;i<n;i++){
	int wt=v[i].F,val=v[i].S;
	for(int val_already=totalval-val;val_already>=0;val_already--){
		dp[val_already+val]=min(dp[val_already+val],dp[val_already]+wt);
	}
}
int mx=mninf;
for(int i=0;i<=totalval;i++){
	if(dp[i]<=W){
		mx=max(mx,i);
	}
}
cout<<mx;
}








Measured memory_bytes: 1024
#include <stdio.h>
int main(void) {
	int n, x, d, i, L[1000];
	scanf("%d", &n);
	scanf("%d", &x);
	for (i = 0; i < n; i++) {
		scanf("%d", &L[i]);
	}
	d = 0;
	for (i = 0; i <= n; i++) {
		if (d > x) {
			break;
		}
		d = d + L[i];
	}
	printf("%d", i);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
signed main(){
    int n , h , a , b[100005] , m=0  , c , t=0;
    cin>>n>>h;
    for(int i=0;i<n;i++){
        cin>>a>>b[i];
        m=max(a,m);
    }
    sort(b,b+n,greater<int>());
    for(int i=0;i<n&&b[i]>m&&h>0;i++){
        t++;
        h-=b[i];
    }
    
    c=max(h/m,0) , h=h%m;
    if(h>0){
        c++;
    }
    cout<<t+c<<endl;
    return(0);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
int d;
  cin >> d;
  if(d==22){cout <<"Christmas Eve Eve Eve"  << endl;}
  if(d==23){cout <<"Christmas Eve Eve"   << endl;}
  if(d==24){cout <<"Christmas Eve"   << endl;}
  if(d==25){cout <<"Christmas" << endl;}
}


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

using namespace std;

long double dp[3001][3001];
long double a[3001];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    dp[1][1] = a[1];
    dp[1][0] = 1 - a[1];
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            if (j == 0) {
                dp[i][j] = dp[i - 1][j] * (1 - a[i]);
            } else {
                dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i];
            }
        }
    }
    long double ans = 0;
    for (int i = (n + 1) / 2; i <= n; i++) {
        ans += dp[n][i];
    }
    cout << setprecision(10) << fixed << ans << "\n";
    return 0;
}


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

#define rep(i,x) for(int i = 0; i < x; i++)
#define rrep(i,x) for(int i = 1; i <= x; i++)
using ll = long long;
using namespace std;
const int INF = 1001001001;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n + k, 0);
    rep(i, n) cin >> h[i];
    vector<int> dp(n + k, INF);
    dp[0] = 0;
    rep(i, n){
        rrep(j, k){
            int ni = i + j;
            dp[ni] = min(dp[ni], dp[i] + abs(h[ni] - h[i]));
        }
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  int n,m; cin >>n>>m;
  vector<vector<string>> vec(n);
  vector<int> ans(n,0);
  rep(i,m) {
    int a;
    string b;
    cin >>a>>b;
    vec[a-1].push_back(b);
  }
  int decrease=0;
  rep(i,n){
    for(int j=0;(j<vec[i].size());j++){
      if(vec[i][j]=="AC") break;
      ans[i]++;
    }
    if(ans[i]==vec[i].size()) {
      ans[i]=0;
      decrease++;
    }
  }
 
    int Ans=0;
    rep(i,n) Ans+=ans[i];
    cout <<n-decrease<<" "<<Ans<<endl;
}
    
  

Measured memory_bytes: 13952
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 19 11:55:12 2020

@author: 17664
"""
kaibun = input()
joken1 = kaibun[:(len(kaibun)-1)//2]
# print(joken1)
joken2 = kaibun[(len(kaibun)+2)//2:]
# print(joken2)

ans = 'No'

if kaibun == kaibun[::-1] and joken1 == joken1[::-1] and joken2 == joken2[::-1]:
    ans = 'Yes'
    
print(ans)

Measured memory_bytes: 3060
N  = int(input())
S = list(input())
D = [0]*(N-1)
for i in range(1, N):
  A = S[:i]
  B = S[i:]
  A1 = set(A)
  B1 = set(B)
  C = A1 & B1
  D[i-1] = len(C)
print(max(D))


Measured memory_bytes: 38384
<?php
  list($n, $k) = explode(" ", trim(fgets(STDIN)));

  $h = [];
  for ($i=0; $i<$n; $i++) {
    list($h[]) = explode(" ", trim(fgets(STDIN)));
  }

  rsort($h);

  $min = $h[0]-$h[$k-1];
  for ($i=1; $i<$n-$k+1; $i++) {
    $min = min($min, $h[$i]-$h[$k-1+$i]);
  }

  echo $min;

Measured memory_bytes: 23040
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define th third
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a)  (a).begin(),(a).end()
#define elif else if

long long dp[100010];

signed main(){
  int n;
  cin>>n;
  V<int> h(n);
  fo(i,n){
    cin>>h[i];
  }


  fo(i,100010){
    dp[i]=10000000000000;
  }
  dp[0]=0;
  for(int i=1; i<n; i++){
    if(i==1)
      dp[1]=abs(abs(h[0]-h[1]));
    else
      dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long ans=0;
		int[] a=new int[n];
		for(int i=0; i<n; i++){
			a[i]=sc.nextInt();
		}
		if(a[0]!=0){
			System.out.println(-1);
			return;
		}
		for(int i=1; i<n; i++){
			if(a[i-1]+1<a[i]){
				System.out.println(-1);
				return;
			}else if(a[i-1]>=a[i]){
				ans+=a[i-1];
			}
		}
		ans+=a[n-1];
		System.out.println(ans);
	}
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 10000000000;

using namespace std;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	long long g = gcd(a, b);
	return a / g * b;
}

int main() {
	ll n; cin >> n;
	vector <ll> cap(5);
	rep(i, 5)cin >> cap[i];

	sort(cap.begin(), cap.end());
	ll x = cap[0];

	ll ans = (n + (x - 1)) / x;
	cout << ans + 4 << endl;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    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")
  };
}

const MOD: i64 = 1e9 as i64 + 7;

fn main() {
  input! {
    k: chars,
    d: usize
  }
  let n = k.len();
  let mut same = vec![vec![0i64; d]; 2];
  let mut less = vec![vec![0i64; d]; 2];
  let k: Vec<_> = k.into_iter().map(|x| x.to_digit(10).unwrap() as usize).collect();
  same[0][0] = 1;
  for (i, &x) in k.iter().enumerate() {
    for rem in 0 .. d {
      same[(i + 1) % 2][rem] = 0;
      less[(i + 1) % 2][rem] = 0;
    }
    for rem in 0 .. d {
      same[(i + 1) % 2][(rem + x) % d] += same[i % 2][rem];
      same[(i + 1) % 2][(rem + x) % d] %= MOD;
      for digit in 0 .. 10 {
        if digit < x {
          less[(i + 1) % 2][(rem + digit) % d] += same[i % 2][rem];
        }
        less[(i + 1) % 2][(rem + digit) % d] += less[i % 2][rem];
        less[(i + 1) % 2][(rem + digit) % d] %= MOD;
      }
    }
  }
  let ans = (same[n % 2][0] + less[n % 2][0] + MOD - 1) % MOD;
  println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n;
	cin >> n;
	vll l(2 * n);
	for (ll i = 0; i < 2 * n; i++) cin >> l[i];
	sort(all(l));
	ll ans = 0;
	for (ll i = 0; i < n; i++) ans += l[2 * i];
	cout << ans << endl;
}


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

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int dp[110][4][4][4];

int main() {
    int n; cin >> n;
    dp[0][0][0][0] = 1;
    rep(l,n) {
        rep(m,4) {
            rep(i,4)rep(j,4)rep(k,4) {
                if (l>=2 && j == 0 && k == 1 && m == 2) continue;
                if (l>=2 && j == 0 && k == 2 && m == 1) continue;
                if (l>=2 && j == 1 && k == 0 && m == 2) continue;
                if (l>=3 && i == 0 && j == 1 && m == 2) continue;
                if (l>=3 && i == 0 && k == 1 && m == 2) continue;
                dp[l+1][j][k][m] += dp[l][i][j][k];
                dp[l+1][j][k][m] %= mod;
            }
        }
    }
    ll ans = 0;
    rep(i,4)rep(j,4)rep(k,4) {
        ans += dp[n][i][j][k];
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}






Measured memory_bytes: 256
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
sys.setrecursionlimit(1000000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    def Base_10_to_n(X, n):
        X_dumy = X
        out = ''
        while X_dumy>0:
            out = str(X_dumy%n)+out
            X_dumy = int(X_dumy/n)
        return out
    n,k = map(int,input().split())
    print(len(str(Base_10_to_n(n,k))))
#endline===============================================
if __name__ == "__main__":
    main()

Measured memory_bytes: 66156
#include <iostream>
#include <string.h>
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, L, T;
	cin >> N >> L;
	T = N * (2 * L + N - 1) / 2;
	if (L > 0) {
		T -= L;
	}
	else if (L < 0) {
		if (N + L <= 0) T -= L + N - 1;
	}
	cout << T;

	return 0;
}


Measured memory_bytes: 256
a=list(map(int,input().split()))
if a[1]-a[0]+1<=2*a[2]:
    for i in range(a[0],a[1]+1):
        print(i)
else:
    for j in range(a[2]):
        print(a[0]+j)
    for k in reversed(range(a[2])):
        print(a[1]-k)

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

int main() {
	auto optimize_cpp_stdio = []() {
		std::ios::sync_with_stdio(false);
		std::cout.tie(nullptr);
		std::cin.tie(nullptr);
		return 0;
	}();

	int n, k;
	std::cin >> n >> k;
	std::vector<int> a(n);
	for (int i = 0; i < n; i++)
		std::cin >> a[i];
	std::vector<int64_t> v;
	for (int i = 0; i < n; i++) {
		int64_t sum = 0;
		for (int j = i; j < n; j++) {
			sum += a[j];
			v.push_back(sum);
		}
	}
	const int MAX_B = 64;
	static int count[MAX_B];
	int64_t ans = 0;
	int p = MAX_B - 1;
	while (true) {
		memset(count, 0, sizeof count);
		for (int64_t it : v)
			for (int j = 0; j <= p; j++)
				if (it >> j & 1) count[j]++;
		while (0 <= p && count[p] < k) p--;
		if (p == -1) break;
		auto new_end = std::remove_if(v.begin(), v.end(), [&](int64_t x) { return ~x >> p & 1; });
		v.erase(new_end, v.end());
		for (int64_t& it : v)
			it ^= 1ll << p;
		ans += 1ll << p;
	}
	std::cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 6512
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

	return b
}

func main() {
	n, m := nextInt(), nextInt()
	roads := map[int]int{}

	for i := 0; i < m; i++ {
		roads[nextInt()-1]++
		roads[nextInt()-1]++
	}

	for i := 0; i < n; i++ {
		fmt.Println(roads[i])
	}
}


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

#define 	ll 						long long int
#define 	pb 						push_back
#define 	mp 						make_pair
#define 	fast 					ios_base::sync_with_stdio(false);cin.tie(NULL);
#define 	ff 						first
#define 	ss 						second
#define 	nil 					-10e+9
#define 	initial 				0
#define 	waiting 				1
#define 	visit 					2
#define 	inf  					10e+9
#define 	mx   					200005
#define 	mxx  					1000005
#define 	mod  					1000000007
#define 	pr   					pair<ll,ll>
#define 	pp_queue 			priority_queue<pr,vector<pr>, greater<pr> >
#define 	dp_queue 			priority_queue<int,vector<int>, greater<int> >
#define 	sp_queue 			priority_queue<int>
#define 	fr(i,p,q)			for(int i=p;i<q;++i)
#define 	frr(i,p,q) 		for(int i=p;i<=q;++i)
#define 	mem(a,b) 			memset(a,b,sizeof(a))
#define 	len(a)   			(int)a.size()
#define 	input  				freopen("input.txt", "r", stdin);
#define 	output 				freopen("output.txt", "w", stdout);
#define 	debug(arr,j,n) fr(i,j,n) cout<<arr[i]<<" ";

ll power(ll a,ll b){ll aa=1;while(b){if(b&1){aa=aa*a;aa%=mod;}a=a*a;a%=mod;b/=2;}return aa;}

using namespace std;

int main()
{
  int a,b,c;
	cin>>a;
	string s;
	cin>>s;
	if(a<3200) cout<<"red\n";
	else
	cout<<s<<"\n";
	//cout<<(a+b+c)<<" "<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
#define int long long
#define mod 1000000007
typedef pair<int, int> P;
P next(P a,int h,int w) {
	int x;
	int y = a.second;
	if(y&1)x = a.first - 1;
	else x = a.first + 1;
	if (x == -1) {
		x = 0;
		y++;
	}
	else if (x == w) {
		x = w - 1;
		y++;
	}
	return P(x, y);
}

int c[114][114], a[10001];
int ans[10005];
signed main() {
	int h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];

	int now = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < a[i]; j++){
			ans[now] = i + 1;
			now++;
		}
	}
	for (int i = 0; i < h; i++) {
		if (i % 2 == 0) {
			for (int j = 0; j < w; j++) {
				if (j)cout << ' ';
				cout << ans[i*w + j];
			}
		}
		else {
			for (int j = w - 1; j > -1; j--) {
				if (j != w - 1)cout << ' ';
				cout << ans[i * w + j];
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 384