akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;
int n,ans;
int a[2010];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            for(int k=j+1;k<=n;k++)
            {
                if(a[i]+a[j]>a[k])
                ans++;
                else
                break;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}





Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    Q, H, S, D = Scanner.map_int()
    N = Scanner.int()
    ans = 0
    H = min(Q * 2, H)
    S = min(H * 2, S)
    if S * 2 <= D:
        ans = S * N
    else:
        ans += D * (N // 2)
        ans += (N % 2) * S
    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 200001;
int n, v[N], k;
ll cm[N];

int main(){
    scanf("%d%d", &n, &k);
    for(int i = 0; i<n; ++i){
        scanf("%d", v+i);
        int df = 0;
        if(i)cm[i] += cm[i-1], df = v[i] - v[i-1];
        else cm[i] += abs(v[i]);
        cm[i] += df;
    }
    ll an = 1e18;
    for(int i = 0; i<=n-k; ++i){
       ll sm = cm[i+k-1] - cm[i] + abs(v[i]);
       an = min(an, abs(sm));
    }
    reverse(v, v+n);
    memset(cm, 0, sizeof cm);
    for(int i = 0; i<n; ++i){
        int df = 0;
        if(i)cm[i] += cm[i-1], df = abs(v[i] - v[i-1]);
        else cm[i] += abs(v[i]);
        cm[i] += df;
    }
    for(int i = 0; i<=n-k; ++i){
       ll sm = cm[i+k-1] - cm[i] + abs(v[i]);
       an = min(an, abs(sm));
    }
    if(!k)an = 0;
    printf("%lld\n", an);
}

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

int main() {
	int H, W, N, sr, sc;
	string S, T;
	cin >> H >> W >> N >> sr >> sc >> S >> T;
	int L = 1, R = W, U = 1, D = H;
	for (int i = N - 1; i >= 0; i--) {
		if (i < N - 1) {
			switch (T[i]) {
			case 'U':
				D = min(D + 1, H);
				break;
			case 'D':
				U = max(U - 1, 1);
				break;
			case 'L':
				R = min(R + 1, W);
				break;
			case 'R':
				L = max(L - 1, 1);
				break;
			}
			if (L > R || U > D) {
				cout << "NO" << endl;
				return 0;
			}
		}
		switch (S[i]) {
		case 'U':
			U++;
			break;
		case 'D':
			D--;
			break;
		case 'L':
			L++;
			break;
		case 'R':
			R--;
			break;
		}
		if (R < 1 || L > W || D < 1 || U > H) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << (L <= sc && sc <= R && U <= sr && sr <= D ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3888
//Author- VMAX


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld     long double 
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define      gcd(a,b)    __gcd(a,b)
#define bs            binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(),x.end()
#define re return 0;
// *#######################################################################################*

/*
bool isp(ll n)
{
    ll i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            return false;
        }
        
    }
}
  */
  ll powerm(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;    
  
    x = x % p; 
   
    if (x == 0) return 0;
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
   
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
  long long lcm(long long a, long long b){//最小公倍数を求める
   return a * b / gcd(a, b);
}
/*
ll po(ll z,ll z1)
{
    ll rer=0;
    rer=     ((z*(z-1))/2+(z1*(z1-1))/2);
    return rer;

}
*/

//ll ss[2][(1<<22)+10];
       int main()
       {
       
        fast
        
         ll n;
          cin>>n;
          ll a[n],i;
          f(i,n)
          {
              cin>>a[i];
          }
          sort(a,a+n,greater<ll>());
          ll s=a[0];
          i=1;
          ll z=n-2,c=0;
          while(z>0)
          { 
               if(c<2){
              s+=a[i];
              c++;
               }
               if(c==2)
               {
                   c=0;
                   i++;
               }
               
              z--;
          }

o(s)



          re
}


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

const int MAX = 1000005;

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<int> s(MAX);
	rep(i, n) s[a[i]]++;
	bool ok = true;
	for (int i = 2; i < MAX; i++) {
		int cnt = 0;
		for (int j = i; j < MAX; j += i) cnt += s[j];
		if (cnt > 1) ok = false;
	}
	if (ok) {
		cout << "pairwise coprime" << endl;
		return 0;
	}
	int g = 0;
	rep(i, n) g = gcd(g, a[i]);
	if (g == 1) cout << "setwise coprime" << endl;
	else cout << "not coprime" << endl;
	return 0;
}

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


int main(){
  int n,x,t;
  cin >> n >> x >> t;
  if(n%x==0)
    cout << n/x*t << endl;
  else
    cout << (n/x+1)*t << endl;
}

Measured memory_bytes: 3576
//
// Created by Akifumi Ohata on 2017/10/01.
//


#include<iostream>
#include <vector>
#include <numeric>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;

using ll =  long long int;

int main() {
    ios::sync_with_stdio(false);

    int N;

    ll MOD=1000000007;


    cin >> N ;




    vector<int> Array(N,0);

   // ll value_A=0;
    for(int iter=0;iter<=N-1;iter++){
        cin >>Array[iter];
        //value_A+=Array[iter];
    }

    ////
    ll value_S=0;
    ll value_A=std::accumulate(Array.begin(), Array.end(), 0LL);

    ll Diff= 9223372036854775807LL;//;=1000000000000000000LL

    for(int k=0;k<=N-2;k++){


        value_S+=Array[k];
        value_A-=Array[k];



        Diff=min(Diff,abs(value_S-value_A));

    }











    cout  << Diff << endl ;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
using namespace std;
 
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair
 
static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}


int main(){
	int a,b;
cin>>a>>b;
cout<<"a ";
if(a==b) cout<<"==";
else if(a>b) cout<<">";
else cout<<"<";
cout<<" b"<<endl;

	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<int,int>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
#define YesNo(a) cout<<((a)?"Yes":"No")<<endl;
#define YESNO(a) cout<<((a)?"YES":"NO")<<endl;



int main(){
	
	int N;
	cin >> N;
	vector<P> A(N);
	FOR(i,0,N){
		cin >> A[i].first;
		A[i].second = i;
	}
	SORT(A);
	FOR(i,0,N){
		cout << TO(i==0,""," ") << A[i].second+1; 
	}
	cout << endl;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  ll n, k, ans = 0;
  cin >> n >> k;
  for (ll i = k; i <= n + 1; ++i) ans += n * i - i * i + i + 1, ans %= MOD;

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


Measured memory_bytes: 3620
import sys
input = sys.stdin.readline
LLL = 1<<20

N, M = map(int, input().split())
R = []
for _ in range(N):
    a, b = map(int, input().split())
    R.append((a*2, b, 0))
for i in range(M):
    l, r = map(int, input().split())
    R.append((l*2-1, 2, i))
    R.append((r*2+1, 3, i))

R.sort(key=lambda x:x[0])
nodeid = 0
bf = -1
d = []
eid2lid = dict()
id2eid = dict()
G = [set()]
for x, f, i in R:
    if f <= 1:
        d.append(int(f != bf and bf != -1))
        bf = f
        nodeid += 1
        G.append(set())
    else:
        if f == 3:
#            print(x2id, l)
            lid = eid2lid[i]
            if nodeid != lid:
                G[nodeid].add((lid, i+1))
                G[lid].add((nodeid, i+1))
#                id2eid[lid*LLL+nodeid] = i
#            id2eid[(n2, n1)] = i
        eid2lid[i] = nodeid
d.append(int(bf==1))

xxs = [-1]*(nodeid+1)
g2 = [set() for _ in range(nodeid+1)]
vs = set()
cut_edges = set()
for i in range(nodeid+1):
    if i in vs:
        continue
    stack = [i]
    dfs_vs = []
    vs.add(i)
    while stack:
        v = stack.pop()
        dfs_vs.append(v)
        for u, j in G[v]:
            if u in vs:
                continue
            g2[v].add((u, j))
            stack.append(u)
            vs.add(u)
    for v in dfs_vs[::-1]:
        r = d[v]
        for u, j in g2[v]:
            ff = xxs[u]
            if ff:
                cut_edges.add(j)
            r = (r+ff)%2
        xxs[v] = r if v != 0 else 0
    if xxs[i]:
        print(-1)
        break
else:
    print(len(cut_edges))
    print(*sorted(cut_edges))


Measured memory_bytes: 162904
/**-------------------------
|--------From A.R.A--------|
-------------------------**/

#include <bits/stdc++.h>

#define ll            long long int
#define pb            push_back
#define ull           unsigned long long int
#define endl          "\n"
#define sz(c)         (c).size()
#define sall(c)       sort((c).begin(),(c).end())
#define rsall(c)      sort((c).rbegin(),(c).rend())
#define rev(c)        reverse((c).begin(),(c).end())
#define FOR(i,n)      for(ll i=0;i<n;i++)
#define max3(a,b,c)   max(max(a,b),c)
#define min3(a,b,c)   min(min(a,b),c)
#define input(a,i,n)  for(ll i=0;i<n;i++){      cin>>a[i];}
#define output(a,i,n) for(ll i=0;i<n;i++){cout<<a[i]<<" ";}

using namespace std;
int64_t R=1;
void solution(){
    string s;
    cin>>s;
    if(s[sz(s)-1]=='s') s+="es";
    else{s+='s';}
    cout<<s<<endl;
}
int main()
{
   // cin>>R;
    FOR(i,R){solution();}
    return 0;
}


Measured memory_bytes: 3632
R,G,B,N=[int(i) for i in input().split()]
cnt=0

for r in range(1+int((N+0.5)/R)):
  for g in range(1+int((N-r*R+0.5)/G)):
    if (N-r*R-g*G)%B == 0:
      cnt+=1
print(cnt)


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

using namespace std;

int res, p[15], n, m;
vector <int> edge[15];
bool st[15];

bool check() {
	for (int i = 0; i < m; i++) {
		int cnt = 0;
		for (int j = 0; j < edge[i].size(); j++) {
			cnt += st[edge[i][j]];
		}
		if (cnt % 2 != p[i]) return 0;
	}
	return 1;
}

void solve(int id) {
	if (id == n) {
		if (check()) res++;
		return;
	}
	
	st[id] = 1;
	solve(id + 1);
	st[id] = 0;
	solve(id + 1);
}

int main() {
	scanf("%d%d", &n, &m);
	
	for (int i = 0; i < m; i++) {
		int x;
		scanf("%d", &x);
		for (int j = 0; j < x; j++) {
			int y;
			scanf("%d", &y);
			y--;
			edge[i].push_back(y);
		}
	}
	
	for (int i = 0; i < m; i++) scanf("%d", &p[i]);
	
	solve(0);
	
	printf("%d\n", res);
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    string S, T;
    map<char, char> fwd, rev;
    cin >> S >> T;
    rep(i, S.size()) {
        if(fwd.find(S[i]) == fwd.end()) {
            fwd[S[i]] = T[i];
        } else {
            if(fwd[S[i]] != T[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        if(rev.find(T[i]) == rev.end()) {
            rev[T[i]] = S[i];
        } else {
            if(rev[T[i]] != S[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3900
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

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

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

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

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

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

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

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

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
}

use std::char;

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input!{
        source = src,
        c: chars,
    }

    let n: u32 = match c[0].to_digit(36) {
        Some(x) => x + 1,
        None => 0,
    };

    let nn: char = match char::from_digit(n, 36) {
        Some(x) => x,
        None => c[0],
    };

    return nn.to_string();
}

Measured memory_bytes: 4352
// 2020-07-04 23:45:06
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

int dp[105][55][55], v[55];
int rec(int k, int l, int r) {
  if(dp[k][l][r] >= 0) return dp[k][l][r];
  chmax(dp[k][l][r], 0);
  if(k == 0) return dp[k][l][r];
  if(l == r) return dp[k][l][r];
  chmax(dp[k][l][r], rec(k-1, l+1, r) + v[l]);
  chmax(dp[k][l][r], rec(k-1, l, r-1) + v[r-1]);
  if(k >= 2) {
    if(v[l] < 0) chmax(dp[k][l][r], rec(k-2, l+1, r));
    if(v[r-1] < 0) chmax(dp[k][l][r], rec(k-2, l, r-1));
  }
  return dp[k][l][r];
}
void answer() {
  int n, k;
  cin >> n >> k;
  repc(ki, k) repc(li, n) repc(ri, n) dp[ki][li][ri] = -1;
  rep(i, n) cin >> v[i];
  cout << max(0, rec(k, 0, n)) << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 4740
#include <bits/stdc++.h>
#define pb push_back
#define int long long
typedef long long ll;
using namespace std;
const int MAX = 2e5 + 5;
int id[MAX], nodes, edges;
typedef pair<ll,ll> pll;
pair <long long, pair<int, int> > p[MAX];

void initialize()
{
    for(int i = 0;i < MAX;++i)
        id[i] = i;
}

int root(int x)
{
    while(id[x] != x)
    {
        id[x] = id[id[x]];
        x = id[x];
    }
    return x;
}

void union1(int x, int y)
{
    int p = root(x);
    int q = root(y);
    id[p] = id[q];
}

long long kruskal(vector< pair<long long, pair<int, int> > > p)
{
    int x, y;
    long long cost, minimumCost = 0;
    edges = p.size();
    for(int i = 0;i < edges;++i)
    {
        // Selecting edges one by one in increasing order from the beginning
        x = p[i].second.first;
        y = p[i].second.second;
        cost = p[i].first;
        // Check if the selected edge is creating a cycle or not
        if(root(x) != root(y))
        {
            minimumCost += cost;
            union1(x, y);
        }
    }
    return minimumCost;
}
ll n,D;
ll a[200005];
const ll inf = 1e16;
map<ll,ll> mp;
map<ll,ll> rmp;
ll N;
void solve(ll l,ll r, vector< pair<ll , pll > > &e)
{
        ll mid = (l + r) /2;
        ll id1=-1;
        ll id2=-1;
        if(l == r) return;
        ll mnm = 1e16;
        for(ll i=l;i<=mid;i++) {
                if(mnm > a[i] - i*D) {
                        mnm = a[i] - i*D;
                        id1 = i;
                }
        }
        mnm = 1e16;
        for(ll i=mid+1;i <= r; i++) {
                if(mnm > a[i] + i*D) {
                        mnm = a[i] + i*D;
                        id2 = i;
                }
        }
        for(ll i=mid+1;i<=r;i++) {

                e.pb(make_pair(a[i] + a[id1] + (i - id1)*D , make_pair(i , id1)));
        }
        for(ll i=l;i<=mid;i++) {

                e.pb(make_pair(a[i] + a[id2] + (id2 - i)*D , make_pair(i , id2)));
        }
        solve(l,mid, e);
        solve(mid+1, r, e);
}
int32_t main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL); cout.tie(NULL);
        cin >> n >>D;
        initialize();
        vector< pair<ll,ll> > v;
        vector<ll> aa;
        for(ll i=1;i<=n;i++) {
                cin >> a[i];
                v.pb(make_pair(a[i] , i));
                aa.pb(a[i]);
        }
        sort(aa.begin(), aa.end());
        ll sz = unique(aa.begin(), aa.end()) - aa.begin();
        aa.resize(sz);
        for(ll i=0;i<sz;i++) {
                mp[aa[i]] = i+1;
                rmp[i+1] = aa[i];
        }
        N=5*sz;
        sort(v.begin(), v.end());
        vector< pair<ll , pll > > e;
        solve(1 , n , e);
        sort(e.begin(), e.end());
        ll ans = kruskal(e);
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 204504
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
	    List<int> nk = IO.GetIntList();
	    int n = nk[0];
	    int k = nk[1];
	    List<int> rsp = IO.GetIntList();
	    string strT = IO.GetString();
	    //tと同じ数字を出せば勝てる
	    List<int> t = strT.Select(x => {
	        if(x=='r')return 2;
	        if(x=='s')return 0;
	        return 1;
	    }).ToList();
	    //出す手
	    List<int> ans = new List<int>();
	    for(int i=0;i<n;i++){
	        int x = t[i];
	        int prev=-1;
	        if(i-k>=0)prev=ans[i-k];
	        //Console.WriteLine("i:"+i+" k:"+k+" x:"+x+" p:"+prev+" n:"+next);
	        if(x!=prev){
	            //前の値とも、後ろの値とも違ければ勝てる手を出す
	            ans.Add(x);
	        }else{
	            //前と一緒なら勝てないので、後ろを邪魔しないように、前とも後ろとも違う手を出す.
	            ans.Add(3);
	        }
	    }
	    int point = 0;
	    for(int i=0;i<n;i++){
	        //Console.WriteLine("ideal:"+t[i]+" real:"+ans[i]);
	        if(t[i]==ans[i])point += rsp[t[i]];
	    }
	    Console.WriteLine(point);
	}
    
}

static class IO
{
    static public string GetString() { return Console.ReadLine(); }
    static public int GetInt() { return int.Parse(Console.ReadLine()); }
    static public long GetLong() { return long.Parse(Console.ReadLine()); }
    static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
    static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
    static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
    static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
    static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
}


Measured memory_bytes: 15584
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
    n := nextInt()
    hour := n / (60 * 60)
    n = n % (60 * 60)
    minute := n / 60
    second := n % 60
    fmt.Printf("%d:%d:%d\n", hour, minute, second)
}


Measured memory_bytes: 1100
#include <iostream>
#include <cstdio>
#include <cstring>
#define il inline
#define ri register
#define ll long long
#define Size 200050
using namespace std;
struct point{
	int next,to,w;
}ar[Size];
int head[Size],art,a[Size],
	fa[Size],in[Size],a1[Size],a1t,
	out[Size],sum;
il bool dfs(int);
il void read(int&),link(int,int,int);
int main(){
	ll ans(0);int n,m;read(n),read(m);
	for(int i(1),u,v;i<=m;++i)
		read(u),read(v),link(u,v,1),
			link(v,u,2),++in[v],++out[u];
	memset(a,-1,sizeof(a));
	for(int i(1),j;i<=n;++i){
		if(~a[i])continue;
		a1t=sum=a[i]=0;
		bool pd(dfs(i)),pd1(false);
		for(j=1;j<=a1t;++j)
			if(in[a1[j]]&&out[a1[j]])
			{pd1=true;break;}sum>>=1;
		if(pd1){
			if(pd)ans+=(ll)a1t*a1t;
			else{
				int a2[3]{};for(j=1;j<=a1t;++j)++a2[a[a1[j]]];
				ans+=(ll)a2[0]*a2[1]+(ll)a2[1]*a2[2]+(ll)a2[2]*a2[0];
			}
		}else ans+=sum;
	}return printf("%lld",ans),0;
}
il bool dfs(int x){
	a1[++a1t]=x;bool pd(false);
	for(int i(head[x]),i1;i;i=ar[i].next)
		if(++sum,!~a[i1=ar[i].to]){
			a[i1]=(a[x]+ar[i].w)%3;
			pd|=dfs(i1);
		}else if(a[i1]^(a[x]+ar[i].w)%3)pd|=1;
	return pd;
}
il void link(int u,int v,int w){
	ar[++art]={head[u],v,w},head[u]=art;
}
il void read(int&x){
	x^=x;ri char c;while(c=getchar(),c<'0'||c>'9');
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
}


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

const int INF=1e9+5;

int main()
{
    int n,k;
    cin>>n;
    cin>>k;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];

    vector<int> dp(n,INF);
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n&&j<=i+k;j++)
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
#include <cmath>
#include <iostream>

using namespace std;

template<class T> inline void chmin(T &x, const T &y) {if (x > y) x = y;}

const int INF = 1e9+7;

int n, h[100100];

int dp[100100];

int main()
{
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> h[i];
  
  for (int i = 1; i <= n; ++i) dp[i] = INF;
  
  for (int i = 0; i < n-1; ++i) {
    chmin(dp[i+1], dp[i] + abs(h[i]-h[i+1]));
    chmin(dp[i+2], dp[i] + abs(h[i]-h[i+2]));
  }
  
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> iv;
 
const int INF = 1e8;
const int N = 5010;
 
int a,b;
 
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>a>>b;
 
    if(a <= 8 && b<=8)
        cout<<"Yay!\n";
    else
        cout<<":(\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,s,mx,mn,md;
    cin>>a>>b>>c;
    s=a+b+c;
    mx=max({a,b,c});
    mn=min({a,b,c});
    md=s-(mx+mn);
    cout<<abs(md-mn)+abs(md-mx)<<endl;
}


Measured memory_bytes: 3604
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
k = I()
print('ACL'*k)

Measured memory_bytes: 68308
import java.util.*;

class Main{

    /**
     * https://atcoder.jp/contests/dp/tasks/dp_c
     */

    public static void main(String[] args) {
        
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] dp = new int[3];

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

            int[] temp = new int[3];
            int[] h = new int[3];
            for(int j = 0; j < 3; j++){
                h[j] = in.nextInt();
            }

            for(int k = 0; k < 3; k++){
                for(int x = 0; x < 3; x++){
                    if(k!=x)
                        temp[x] = Math.max(temp[x], dp[k] + h[x]);
                }
            }
            dp = temp;
        }
        System.out.println(Math.max(dp[0], Math.max(dp[1], dp[2])));
    }
}

Measured memory_bytes: 88424
def resolve():
    N = int(input())
    S = input()
    maxcnt = 0
    cnt = 0
    for s in S:
        if s == "I":
            cnt += 1
        elif s == "D":
            cnt -= 1
        maxcnt = max(maxcnt, cnt)
    print(maxcnt)

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 38384
// Charan Sriramula
 
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;
 
const ll lg=22;
const ll N=1e6+5;
const ll M=5e8;
const ll INF=1e18;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;
 
#define is(n) scanf("%d",&n)
#define io(n) printf("%d\n",n)
#define ls(n) scanf("%lld",&n)
#define lo(n) printf("%lld\n",n)
 
#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
 
inline ll mul(ll a, ll b, ll p){ return (a * 1ll * b) % p; }
inline ll sub(ll a, ll b, ll p){ ll c = a - b; if(c < 0) c += p; return c; }
inline ll add(ll a, ll b, ll p){ ll c = a + b; if(c > p) c -= p; return c; }
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

int main()
{
    ll n;
    cin>>n;
    ll sum=0;
    for(ll i=1;i<=n;i++)
    {
        ll x;
        cin>>x;
        sum+=(x!=i);
    }
    if(sum<=2){cout<<"YES"<<endl;exit(0);}
    cout<<"NO"<<endl;
}

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



int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N){
    cin >> A.at(i);
  }
  //入力処理完了
  int cnt = 0;
  int ans = 100;
  for(int i = 0; i < N;i++){
    cnt = 0;
    while(A.at(i) %2 == 0){//Aの配列が2で割り切れなくなるまで
      A.at(i) = A.at(i) / 2;
      cnt++;
    }
    if(cnt < ans){
      ans = cnt;
    }
  }
  cout << ans << endl;


}





Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  int a;
  cin>>a;
  vector<ll>vec(a,0);
  vec.at(0)=1;
  vec.at(a-1)=0;
  vector<ll>veco(a);
  int b;
  cin>>b;
  for(ll i=0;i<b;i++){
    ll c;
    cin>>c;
    ll d;
    cin>>d;
    if(veco.at(c-1)==0){
      veco.at(c-1)+=1;
      vec.at(c-1)=d;
    }
    else{
      if(vec.at(c-1)!=d){
        cout<<-1<<endl;
        return 0;
      }
    }
  }
  if(vec.at(0)==0&&a>1){
    cout<<-1<<endl;
    return 0;
  }
  for(ll i=0;i<a;i++){
    cout<<vec.at(i);
  }
  return 0;
}
      
    



Measured memory_bytes: 3600
a,b,c = map(int, input().split())
integer=list(map(int,input().split()))
q_list=[]
ok=0
for x in range(a):
    q_list+=[list(map(int,input().split()))]
for y in range(a):
    ans=0
    for z,p in zip(q_list[y],integer):
        ans+=z*p
    ans+=c
    if ans>0:
        ok+=1
print(ok)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int64_t bin_pow(int64_t a,int64_t n)
{
  int64_t ans=1;
  while(n>0){
    if(n&1) ans=ans*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return ans%mod;
}

int64_t inv_mod(int64_t a)
{
  return bin_pow(a,mod-2);
}

int64_t fact(int64_t a)
{
  int64_t ans=1;
  for (int i = 2; i <= a; ++i)
  {
    ans*=i;
    ans%=mod;
  }
  return ans;
}

int64_t comb(int64_t n,int64_t r)
{
  return fact(n)*inv_mod(fact(r)*fact(n-r)%mod)%mod;
}

int main()
{
  int64_t x,y;
  cin>>x>>y;
  double a=(2*y-x)/3.0,b=(2*x-y)/3.0;
  if(a<0 || b<0 || (x+y)%3!=0 )
  {
    cout<<0<<endl;
    return 0;
  }
  cout<<comb((a+b),a);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i) 
#endif

#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());

using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int EPS = 1e-9;
const int MOD = 1e9+7;

string getOpString(int b){
  if(b == 0){
    return "+";
  }else{
    return "-";
  }
}

int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int in;
  vector<int> value(4);
  cin >> in;
  REP(i,4){
    value[3-i] = in % 10;
    in /= 10;
  }
  DUMP(value);
  vector<int> op(3,0);
  while(op[0] < 2){
    op[1] = 0;
    while(op[1] < 2){
      op[2] = 0;
      while(op[2] < 2){
	int ans = value[0];
        REP(i,3){
	  if(op[i] == 0){
	    ans += value[i+1];
	  }else{
	    ans -= value[i+1];
	  }
	  DUMP(ans);
	}
	DUMP(op);
	DUMP(ans);
	if(ans == 7){
	  cout << value[0] << getOpString(op[0]) << value[1];
	  cout << getOpString(op[1]) << value[2] << getOpString(op[2]);
	  cout << value[3] << "=7" << endl;
	  return 0;
	}
	op[2]++;
      }
      op[1]++;
    }
    op[0]++;
  }
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

int solve(int n, long k, const std::vector<int>& destinations)
{
  std::vector<int> visited(n, -1);
  visited[0] = 0;
  int current = 0;
  for (long i = 0; i < k; ++i) {
    current = destinations[current];
    if (visited[current] == -1) {
      visited[current] = i + 1;
      continue;
    }

    long interval = i + 1 - visited[current];
    long a = (k - i - 1) % interval;
    std::cerr << "i=" << i << ", visited=" << visited[current] << ", interval=" << interval << ", a=" << a << std::endl;
    for (long j = 0; j < a; ++j) {
      current = destinations[current];
    }
    return current + 1;
  }
  return current + 1;
}

int main()
{
  int n;
  long k;
  std::cin >> n >> k;
  std::vector<int> destinations(n);
  for (auto& d : destinations) {
    std::cin >> d;
    d -= 1;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, k, destinations) << std::endl;
}


Measured memory_bytes: 4816
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            int cnt = 0;
            for (int i = 0; i < s.length() - 1; i++) {
                if (s.charAt(i) != s.charAt(i + 1)) cnt++;
            }
            out.println(cnt);
        }

    }
}



Measured memory_bytes: 25868
#include<iostream>
#include<algorithm>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,m,g,d; char b;
	END:while(cin>>n>>m>>g>>d,n){
		int hl[d][n-1],rtr[d+1],tr[d]; m--,g--; rtr[d]=g;
		rep(i,d)rep(j,n-1)cin>>b,hl[i][j]=b-'0';
		rep(i,d){
			rtr[d-i-1]=rtr[d-i];
			if(rtr[d-i-1]<n-1&&hl[d-i-1][rtr[d-i-1]])rtr[d-i-1]++;
			else if(rtr[d-i-1]>0&&hl[d-i-1][rtr[d-i-1]-1])rtr[d-i-1]--;
		}
		if(rtr[0]==m){
			cout<<0<<endl; continue;
		}
		rep(i,d){
			tr[i]=i>0?tr[i-1]:m;
			if(tr[i]<n-1&&hl[i][tr[i]])tr[i]++;
			else if(tr[i]>0&&hl[i][tr[i]-1])tr[i]--;
			else if(abs(tr[i]-rtr[i])==1&&
				(rtr[i]==n-1||!hl[i][rtr[i]])&&(rtr[i]==0||!hl[i][rtr[i]-1])
			){
				cout<<i+1<<" "<<min(tr[i],rtr[i])+1<<endl;
				goto END;
			}
		}
		cout<<1<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void){
  int i,j,n,c=0,b=0,s=0;
  char in[100];
  int ten[100]={0};
  
  scanf("%d",&n);
  while(c!=n){
    scanf("%s",in);
    switch(in[1]-'A'){
    case 8:b++;break;  //i hit
    case 20:s++;break;  //u out   
    case 14:ten[c]+=b+1;b=0;break;//o homerun
    }
    if(b==4){ten[c]++;b=3;}
    if(s==3){c++;b=0;s=0;}
  }

  for(i=0;i<n;i++){
    printf("%d\n",ten[i]);
  }
  return 0;

}

Measured memory_bytes: 592
#include<iostream>
#include<sstream>
#include<vector>

using namespace std;

int main(){
	ostringstream out;

	int N,W,H,S,T,x,y;
	while(cin >> N, N){
		cin >> W >> H;
		vector<vector<bool> > map(W,vector<bool>(H));
		for(int i=0;i<N;i++){
			cin >> x >> y;
			map[x-1][y-1]=true;
		}
		cin >> S >> T;

		int m=0;
		for(int ix=0;ix<=W-S;ix++)
		for(int iy=0;iy<=H-T;iy++){
			int n=0;
			for(int s=0;s<S;s++)
			for(int t=0;t<T;t++)
				if(map[s+ix][t+iy])n++;
			m=m>n?m:n;
		}

		out << m << endl;

	}


	cout << out.str();
	return 0;
}

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

mod = 10**9+7



# (i, j, k+1)に置くのが、条件(l,x)に適しているか
def check(i, j, l, x):
    return (x == 3 and l <= i) or (x == 2 and i < l <= j) or (x == 1 and j < l)


N, M = map(int, input().split())
LRX = [list(map(int, input().split())) for _ in range(M)]

LX = [[] for _ in range(N+2)]
for l, r, x in LRX:
    LX[r].append((l, x))

dp = [[[0]*(j+1) for j in range(i+1)] for i in range(N+2)]
# dp[i][j][k] (k <= j <= i) 
# 三色それぞれ、最後に使ったindex(1-indexed)がi,j,k

dp[0][0][0] = 1

for i in range(N+1):
    for j in range(i, N+1):
        for k in range(j, N+1):
            
            # 一番前の色を置く
            ok = True
            for l, x in LX[k+1]:
                if not check(j, k, l, x):
                    ok = False
                    break
            if ok:
                dp[k+1][k][j] = (dp[k+1][k][j] + dp[k][j][i]) % mod
            
            # 最後
            ok = True
            for l, x in LX[k+1]:
                if not check(i, j, l, x):
                    ok = False
                    break
            if ok:
                dp[k+1][j][i] = (dp[k+1][j][i] + dp[k][j][i]) % mod
            
            # 二番目
            ok = True
            for l, x in LX[k+1]:
                if not check(i, k, l, x):
                    ok = False
                    break
            if ok:
                dp[k+1][k][i] = (dp[k+1][k][i] + dp[k][j][i]) % mod
        

ans = 0
for a in range(N+1):
    for b in range(a,N+1):
        ans = (ans + dp[N][b][a]) % mod

print(ans)


Measured memory_bytes: 118948
#include<cstdio>
#include<cmath>
int main()
{
	int a,b,c;
	char ch;
	scanf("%d %c %d",&a,&ch,&b);
	if(ch=='+')
	c=a+b;
	else if(ch=='-') c=a-b;
	printf("%d\n",c);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>

using namespace std;

#define ll long long

int main() {
    
    ll n;
    cin >> n;
    double x[n],y[n];
    for (ll i=0;i<n;i++){
        cin >> x[i] >> y[i];
    }
    double ans=0;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            if(i==j) continue;
            else{
                ans+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
            }
        }
    }
    printf("%.12f\n",ans/n);
   
}



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

int main(void) {
  string S;
  cin >> S;

  string Cmp[4] = {"dream", "dreamer", "erase", "eraser"};
  while (S != "") {
    bool flag = false;
    for (int i = 0; i < 4; i++) {
      if (equal(S.end() - Cmp[i].size(), S.end(), Cmp[i].begin())) {
        S.erase(S.end() - Cmp[i].size(), S.end());
        flag = true;
        break;
      }
    }
    if (!flag) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,i;
  ll a[200005],s=0,ls;
  
  cin >> n;
  for (i=0;i<n;i++){
    cin >> a[i];
    s+=a[i];
  }
  
  i=1;
  ls=a[0];
  while (i<n && ls*2<s){
    ls+=a[i];
    i++;
  }
  
  ll v1,v2;
  v1=ls*2-s;
  ls-=a[i-1];
  v2=s-ls*2;
  
  cout << min(v1,v2) << endl;
  
  return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<Integer> list = new ArrayList<Integer>();
		for (String s : Arrays.asList(br.readLine().trim().split("\\s+"))) list.add(Integer.parseInt(s));

		int a = list.get(0), b = list.get(1);

		System.out.println(""+(a*b)+" "+(2*a+2*b));
	}
}

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

typedef long long ll;

void getPi(string s, vector<int> &pi) {
    pi = vector<int>(s.size(), 0);
    int j = 0;
    for(int i = 1; i < s.size(); i++) {
        while(j && s[i] != s[j]) j = pi[j - 1];
        if(s[i] == s[j]) pi[i] = ++j;
    }
}

string S, T, A, B;
ll L, R;
vector<int> pi;
vector<ll> fibo;
vector<vector<ll> > fcnt;

void Fibonacci() {
    //cout << A << ' ' << B << endl;
    fibo.push_back(A.size());
    fibo.push_back(B.size());
    for(int i = 2;; i++) {
        ll a = fibo[i - 2];
        ll b = fibo[i - 1];
        fibo.push_back(a + b);
        if(fibo[i] >= 1e18) break;
    }
    fcnt = vector<vector<ll> >(fibo.size(), vector<ll>(26, 0));
    for(int i = 0; i < A.size(); i++) {
        fcnt[0][ A[i] - 'a' ]++;
    }
    for(int i = 0; i < B.size(); i++) {
        fcnt[1][ B[i] - 'a' ]++;
    }
    for(int i = 2; i < fibo.size(); i++) {
        for(int j = 0; j < 26; j++) {
            fcnt[i][j] = fcnt[i - 1][j] + fcnt[i - 2][j];
        }
    }
}

vector<ll> solve(ll x) {
    if(x < 0) return vector<ll>(26, 0);
    if(x + 1 <= B.size()) {
        vector<ll> ret(26, 0);
        for(int i = 0; i <= x; i++) {
            ret[ B[i] - 'a' ]++;
        }
        return ret;
    }

    int s = 0, e = fibo.size() - 1;
    int r;
    while(s <= e) {
        int m = (s + e)>>1;

        if(fibo[m] <= x + 1) {
            r = m;
            s = m + 1;
        }
        else e = m - 1;
    }
    vector<ll> ret(26, 0);
    for(int i = 0; i < 26; i++) {
        ret[i] += fcnt[r][i];
    }

    vector<ll> tmp = solve(x - fibo[r]);
    for(int i = 0; i < 26; i++) {
        ret[i] += tmp[i];
    }
    return ret;
}

int main() {
    cin>>S>>L>>R;
    L--; R--;

    for(int i = 0; i < S.size() / 2; i++) T.push_back(S[i]);
    getPi(T, pi);

    A = T;
    for(int i = 0; i < (int)T.size() - pi[T.size() - 1]; i++) A.push_back(T[i]);
    B = A;
    for(int i = 0; i < T.size(); i++) B.push_back(T[i]);

    //cout << pi[T.size() - 1] << ' ' << T.size() << endl;

    //cout << A << ' ' << B << endl;

    Fibonacci();

    vector<ll> Y = solve(R);
    vector<ll> X = solve(L - 1);

    for(int i = 0; i < 26; i++) {
        printf("%lld ", Y[i] - X[i]);
    }
}


Measured memory_bytes: 1644
N = int(input())
K = list(map(int, input().split()))

b = max(K)
s = min(K)
INF = 10**18
t = [INF]*(b+1)
for i in range(s,b+1):
  a = 0
  for j in range(len(K)):
	  a += (K[j] - i)**2
  t[i] = a
print(min(t))

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

#define ll long long
const int inf = 1e9+7;
const ll INF = 1e18+7;

using namespace std;

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

  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  cout<<abs(a[1]-a[0])+abs(a[1]-a[2])<<"\n";
}


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

using namespace std;
long long MOD = 1000000007LL;
template<class T>
T gcd(T x, T y) {
	return y ? gcd(y, x % y) : x;
}

template<class T>
vector<T> enum_div(T n) {
	vector<T> ret;
	for (T i = 1; i * i < n; ++i) {

		if (n % i == 0) {
			ret.push_back(i);

			if (i != 1 && i * i != n) {
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}

template<class T>
map<T, int> prime_factorization(T n) {
	map<T, int> ret;

	for (long long i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}

	if (n != 1)ret[n] = 1;
	return ret;
}

template<class T>
long long C(T n, T r) {
	static map<pair<T, T>, long long> _map;
	if (n < r) return 0;

	if (n == r || r == 0) {
		_map[make_pair(n, r)] = 1ll;
	}
	else if (_map[make_pair(n, r)] == 0) {
		_map[make_pair(n, r)] = (C(n - 1, r) + C(n - 1, r - 1));
	}

	_map[make_pair(n, r)] %= MOD;
	return _map[make_pair(n, r)];
}

int main() {
	int x;
	int sumP = 0;
	for (int i = 0; i < 2; ++i) {
		cin >> x;
		if (x == 1) {
			sumP += 300000;
		}
		else if (x == 2) {
			sumP += 200000;
		}
		else if (x == 3) {
			sumP += 100000;
		}
	}

	if (sumP == 600000) {
		sumP += 400000;
	}
	cout << sumP << endl;

	return 0;
}

Measured memory_bytes: 256