akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
using namespace std;
int n,m,x;
int c[15],a[15][15],b[15],d[15],len,sum=100000000,cost;
void init(){
	int i,j;
	scanf("%d%d%d",&n,&m,&x);
	for(i=1;i<=n;i++){
		scanf("%d",&c[i]);
		for(j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	}
}
void dfs(int step){
	int i,j,k;
	if(step==len+1){
		for(k=1;k<=m;k++)d[k]=0;
		for(j=1;j<=len;j++)
			for(k=1;k<=m;k++)
				d[k]+=a[b[j]][k];
		for(k=1;k<=m;k++)
			if(d[k]<x)return;
		cost=0;
		for(j=1;j<=len;j++)cost+=c[b[j]];
		sum=min(sum,cost);
		return ;
	}
	for(i=b[step-1]+1;i<=n;i++)
		b[step]=i,dfs(step+1);
}
int main(){
	init();
	for(len=1;len<=n;len++)
		b[0]=0,dfs(1);
	if(sum==100000000)printf("-1\n");
	else printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
//#define all(v) v.begin(), v.end()
//bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
//bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
//const ll MAX_N=500010;
int main() {
  ll A, B, M;
  cin >> A >> B >> M;
  ll a[A], b[B], x[M], y[M], c[M];
  rep(i, A) cin >> a[i];
  rep(i, B) cin >> b[i];
  rep(i, M) cin >> x[i] >> y[i] >> c[i];
  ll ma=a[0], mb=b[0], mc=a[x[0]-1]+b[y[0]-1]-c[0];
  
  rep(i, A-1) ma=min(ma,a[i+1]);
  rep(i, B-1) mb=min(mb,b[i+1]);
  rep(i, M-1) mc=min(mc,a[x[i+1]-1]+b[y[i+1]-1]-c[i+1]);
  cout << min(ma+mb,mc) << endl;
  return 0;
}

Measured memory_bytes: 4096
#include <iostream>

using namespace std;

#define w first
#define v second

pair<int, int> obj[105];
long long dp[100005];

int main()
{
    int n, g;
    cin >> n >> g;
    for(int i = 1; i <= n; ++i)
        cin >> obj[i].w >> obj[i].v;
    for(int i = 1; i <= n; ++i){
        for(int j = g; j >= obj[i].w; --j)
            dp[j] = max(dp[j], dp[j - obj[i].w] + 1LL * obj[i].v);
    }
    cout << dp[g];
    return 0;
}


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

using namespace std;

int n=0;
pair<int, int> arr[10];
double dist=0;
int cnt=0;

double d(int x1, int y1, int x2, int y2)
{
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main()
{
	cin >> n;
	for (int i=0; i<n; i++)
	{
		cin >> arr[i].first >> arr[i].second;		
	}
	sort(arr, arr+n);
	do
	{
		for (int i=0; i<n-1; i++)
		{
			dist+=d(arr[i].first, arr[i].second, arr[i+1].first, arr[i+1].second);
		}
		cnt++;
	}	
	while (next_permutation(arr, arr+n));
	dist/=cnt;
	cout << fixed << setprecision(8) << dist;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int h = sc.nextInt();
		int w = sc.nextInt();

		int row = 0;
		int clm = 0;
		outer:
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (sc.next().equals("snuke")) {
					row = i;
					clm = j;
					break outer;
				}
			}
		}

		System.out.println("" + (char)('A' + clm) + (row + 1));

		sc.close();
	}
}



Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int lhs, rhs;
  cin >> lhs;
  cin >> rhs;
  vector<int> ops(3);
  ops[0] = lhs - rhs;
  ops[1] = lhs + rhs;
  ops[2] = lhs * rhs;
  auto mv = max_element(ops.begin(), ops.end());
  //cout << lhs << " " << rhs << endl;
  cout << *mv << endl;
  return 0;
}

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

using namespace std;

int main()
{
    string s, p;
    int ptr = 0;
    int i, len_s, len;
    cin >> s >> p;
    len_s = s.length();
    len = p.length();

    do
    {
        for (i = 0; i < len && s[(ptr+i)%len_s] == p[i]; i++) ;
        if (i == len) {
            cout << "Yes" << endl;
            return 0;
        }
        ptr = (ptr + 1)%len_s;
    } while(ptr);
    cout << "No" << endl;
    return 0;
}


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

def main():
    n = int(input())
    a_list = list(map(int, input().split()))

    odd_cnt = 0
    even_cnt = 0
    four_cnt = 0
    for i in a_list:
        if i % 2 == 0 and i % 4 != 0:
            even_cnt += 1
        elif i % 4 == 0:
            four_cnt += 1
        else:
            odd_cnt += 1
    if even_cnt == 0:
        if four_cnt >= odd_cnt - 1:
            print('Yes')
        else:
            print('No')
    else:
        if four_cnt >= odd_cnt:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 15020
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/21
Solved on 2019/3/
@author: shinjisu
"""


# ABC 082 C Good Sequence
#import math
#import numpy as np

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
    data = zeros(n)
    for i in range(n):
        data[i] = getInt()
    return data
"""

def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替

def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    #mat = zeros((n, m))
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    d.dmp((N), 'N')
    A = getIntList()
    d.dmp((A), 'A')
    A.sort()
    d.dmp((A), 'A')
    i = 0
    dlt = 0
    while i < N:
        k = 1
        while i+k < N and A[i] == A[i+k]:
            k += 1
            if i+k == N:
                break
        if A[i] < k:
            dlt += k - A[i]
        elif A[i] > k:
            dlt += k
        i += k   
        d.dmp((dlt), 'dlt')
    return dlt


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)


Measured memory_bytes: 14280
n,*a=map(int,open(0).read().split())
from collections import Counter
x=Counter(a)
MOD=10**9+7
# print(x)
if n%2==1:
  ng=False
  if x[0]!=1:ng=True
  for i in range(1,n):
    if i%2==0 and x[i]==2:continue
    if i%2==1 and x[i]==0:continue
    ng=True
  if ng:
    print(0)
  else:
    print(pow(2,n//2,MOD))

if n%2==0:
  ng=False
  for i in range(n):
    if i%2==0 and x[i]==0:continue
    if i%2==1 and x[i]==2:continue
    ng=True  
  
  if ng:
    print(0)
  else:
    print(pow(2,n//2,MOD))
    

Measured memory_bytes: 14692
#include<bits/stdc++.h>
using namespace std;
int a,b,c,sum;
int main(){
	cin>>a>>b>>c;
	if(a>=b and a>=c)sum=b+c;
	else if(b>=a and b>=c)sum=a+c;
	else sum=a+b;
	cout<<sum<<endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort( ALL(v) )

using namespace std;
using ll = long long;
using P = pair<int,int>;

const int AMAX = 100000;
ll cnt[AMAX + 1]{};
int main()
{


    ll n,k;
    cin >> n >> k;
    for(ll i = 0 ; i<n ; i++)
    {
        ll a,b;
        cin >> a>>b;
        cnt[a]+=b;
    }

    ll curr = 0 ;
    for(ll ans = 1 ; ans<=AMAX ; ++ans)
    {
        curr+=cnt[ans];
        if(curr>=k)
        {
            cout<<ans<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
typedef char CHAR;
typedef unsigned char UCHAR;
typedef short SHORT;
typedef unsigned short USHORT;
typedef int INT;
typedef unsigned int UINT;
typedef long long LLONG;
typedef unsigned long long ULLONG;

#define LengthOf(x)    (sizeof(x) / sizeof(x[0]))


#if 1
//No.3
int main()
{
	INT N;
	map<string, int> S;

	cin >> N;
	for (int i = 0; i < N; ++i) {
		string str;
		cin >> str;
		S.insert(pair<string, int>(str, 0));
	}

	cout << S.size();

	return 0;
}
#endif

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


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


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>

using namespace std;

long long kobaisu(long long a, long long b)
{

	long long r, x, tmp;

	x = a * b;

	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return x / b;
}



int main() {
	long long A, B, C, D;
	cin >> A >> B >> C >> D;
	long long amariC, amariD, amariCD, ans;
	amariC = B / C - (A - 1) / C;
	amariD = B / D - (A - 1) / D;
	amariCD = B / kobaisu(C, D) - (A - 1) / kobaisu(C,D);
	ans = B - (A - 1) - amariC - amariD + amariCD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#ifndef CLASS_MODINT
#define CLASS_MODINT

#include <cstdint>

template<std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::int64_t n_) : n((n_ >= 0 ? n_ : mod - (-n_) % mod) % mod) {};
	static constexpr std::uint32_t get_mod() { return mod; }
	std::uint32_t get() const { return n; }
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint inv() const { return (*this).pow(mod - 2); }
	modint pow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
};

#endif // CLASS_MODINT

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
using modulo = modint<1000000007>;
modulo calc(int pos, int pre, int depth, vector<vector<int> > &G, int K) {
	int cnt = 0;
	modulo ans = 1;
	for (int i : G[pos]) {
		if (i == pre) continue;
		ans *= calc(i, pos, depth + 1, G, K);
		++cnt;
	}
	for (int i = K - min(depth + 1, 2); i >= K - min(depth + 1, 2) - cnt + 1 && i >= 0; --i) {
		ans *= i;
	}
	return ans;
}
int main() {
	int N, K;
	cin >> N >> K;
	vector<vector<int> > G(N);
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b; --a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	modulo ans = calc(0, -1, 0, G, K);
	cout << (ans * K).get() << endl;
	return 0;
}

Measured memory_bytes: 11520
def solve():
    n = int(input())
    print(dfs('0', n))


def dfs(s, n):
    if int(s) > n:
        return 0
    r = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        r += dfs(s+c, n)
    return r


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9072
import sys
import functools
import threading

sys.setrecursionlimit(10000000)


def main():
    N = int(input())
    H = [-1] + [int(x) for x in input().split(" ")]
    table = [-1 for i in range(N + 1)]

    @functools.lru_cache(maxsize=None)
    def solve(n):

        if n == 1:
            return 0
        elif n == 2:
            return abs(H[2] - H[1])
        else:
            return min(
                solve(n - 1) + abs(H[n] - H[n - 1]), solve(n - 2) + abs(H[n] - H[n - 2])
            )

    print(solve(N))


if __name__ == "__main__":

    sys.setrecursionlimit(1024 * 1024)
    threading.stack_size(128 * 1024 * 1024)
    threading.Thread(target=main).start()


Measured memory_bytes: 281856
// 基本テンプレート
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

vector<int> blocks[200010];
set< pair<int, int> > exists;
 
signed main() {
    int H, W, N; cin >> H >> W >> N;
    for(int i=0; i<N; i++) {
        int x, y; cin >> x >> y;
        x--; y--;
        blocks[y].emplace_back(x);
        exists.emplace(x, y);
    }

    for(int i=0; i<W; i++) {
        blocks[i].emplace_back(H);
        sort(blocks[i].begin(), blocks[i].end());
    }

    int r = 0, c = 0, sum = 0, ans = 1 << 28;
    for(int i=0; i<W; i++) {
        // c 行目にあるものの中で、r 行目よりも後ろにあって最も近いもの
        int nearest = *upper_bound(blocks[c].begin(), blocks[c].end(), r);
        chmin(ans, sum + nearest - r);

        if(c + 1 == W) continue;

        // c + 1 行目にあるものの中で、r + 1 行目以降で最も近いもの
        int nr = r + 1, nc = c + 1;
        while(nr < nearest and exists.count(make_pair(nr, nc))) nr++;
        if(nr == nearest) break;

        sum += nr - r;
        r = nr, c = nc;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 24704
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


  
int main(){
  int n,a,b;
  cin>>n>>a>>b;
  
  int ans;
  ans = min(a*n,b);
  cout<<ans<<endl;
  return 0;
}


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

int main() {
	long long N, K;
	string S;
	cin >> N >> K >> S;
	vector<long long> V(N);
	for (int i = 0; i < N; i++) V[i] = (S[i] - 'A' + i % 2) % 2;
	long long COUNT = 0;
	for (int i = 0; i < N; i++) {
		if (V[i] == 0) COUNT += 2;
		else COUNT++;
		if (K < COUNT) {
			if (V[i] == 0) COUNT -= 2;
			else COUNT--;
			string ANS = "";
			for (int j = i; j < N; j++) {
				ANS += 'A' + (V[j] + (j - i) % 2) % 2;
			}
			if (K - COUNT == 1) ANS[0]++;
			for (int j = 0; j < i; j++) {
				ANS += 'A' + (i + j + 1) % 2;
			}
			cout << ANS << endl;
			return 0;
		}
	}
	string ANS = "";
	if (N % 2 == 0) {
		for (int i = 0; i < N; i++) ANS += 'A' + (i + 1) % 2;
	}
	else {
		if (K % 2 == COUNT % 2) {
			for (int i = 0; i < N; i++) ANS += 'A' + (i % 2);
		}
		else {
			ANS += 'B';
			for (int i = 1; i < N; i++) ANS += 'A' + (i % 2);
		}
	}
	cout << ANS << endl;
}

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

int main(){
    while(1){
    int n=0,y=0,c=0;
    double m=0;
    cin>>n;
    if(n==0)break;
    cin>>y;
    for(int i=0;i<n;i++){
        double b=0,r=0,t=0,s=0;
        cin>>b>>r>>t;
        if(t==1){
            s=1+y*(r/100);
        }
        else if(t==2){
            s=pow(1+r/100,y);
        }
        if(s>m){
            m=s;
            c=b;
        }
    }
        cout<<c<<endl;
    }
    return 0;
}

Measured memory_bytes: 1232
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long Int;

#ifndef M_PI
#define M_PI 3.14159265358979323846264338327950288
#endif

int main() {
    double a, b, x, ans;
    scanf("%lf %lf %lf", &a, &b, &x);

    if (x <= a * a * b / 2) {
        ans = atan(a * b * b / (2 * x)) * 180 / M_PI;
    } else {
        ans = atan(2 * (a * a * b - x) / (a * a * a)) * 180 / M_PI;
    }
    printf("%.16f\n", ans);
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main{
    public static long []dp = new long[110000];
    public static void main(String []args){
        Scanner in = new Scanner(System.in);

        int n; n = in.nextInt();
        long []heights = new long[n];

        for(int i = 0; i < n; i ++)
            heights[i] = in.nextLong();

        dp[0] = 0;
        for (int i = 1; i < n; i ++){
            if(i != 1)
                dp[i] = Math.min(dp[i-1]+Math.abs(heights[i]-heights[i-1]), dp[i-2]+Math.abs(heights[i]-heights[i-2]));
            else
                dp[i] = dp[i-1]+Math.abs(heights[i]-heights[i-1]);
        }

        System.out.println(dp[n-1]);
    }
}

Measured memory_bytes: 49816
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

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

int n, m, q;
vi a(100), b(100), c(100), d(100);
int ans = 0;

void dfs(vll v){
  if (v.size() == n){
    int sum =  0;
    rep(i, q){
      if (v[b[i]-1] - v[a[i]-1] == c[i]){
        sum += d[i];
      }
    }
    ans = max(ans, sum);
  }
  else{
    for (int i = v.back(); i <= m; i++){
      v.emplace_back(i);
      dfs(v);
      v.pop_back();
    }
  }
}

int main(){
  cin >> n >> m >> q;
  rep(i, q){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  vll v = {1};
  dfs(v);
  cout << ans << endl;
}

Measured memory_bytes: 3624
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ

int main(){
	int a,b;scanf("%d%d",&a,&b);
	int ret=0;
	if(a<=3)ret+=4-a;
	if(b<=3)ret+=4-b;
	if(a==1&&b==1)ret+=4;
	ret*=100000;
	printf("%d\n",ret);
}


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

int main()
{
    int N;
    cin >> N;
    map<int,int> mp;

    for(int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        mp[tmp]++;
    }

    int count = 0;

    for(auto e:mp)
    {
        count++;
    }

    cout << count << endl;

}

Measured memory_bytes: 256
def solve(n, m, c, b_list, a_matrix):
    ans = 0
    for i in range(n):
        val = c
        for j in range(m):
            val += b_list[j] * a_matrix[i][j]
        if val > 0:
            ans += 1
    print(ans)

n, m, c = map(int, input().split())
b_list = list(map(int, input().split()))
a_matrix = []

for i in range(n):
    a_matrix.append(list(map(int, input().split())))

solve(n, m, c, b_list, a_matrix)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) > abs(x - b))
	{
		cout << "B";
	}
	else
	{
		cout << "A";
	}
	cout << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#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++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




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

    double pi = 3.1415926535;




    cout << N * 2 * pi << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
#define dbl double
dbl dp[3000][3000],p[3000],sum=0.0;

main()
{ int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>p[i];
	
	dp[1][0]=1-p[1];
	
	for(int i=2;i<=n;i++)
	dp[i][0]= dp[i-1][0]*(1-p[i]);
	dp[1][1]= p[1];
	
	for(int i=2;i<=n;i++)
	for(int j=1;j<=n;j++)
	dp[i][j]= dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i]);
	
	for(int i=1;i<=n;i++)
{//cout<<i<<" ";
		for(int j=0;j<=n;j++)
	{// cout<<dp[i][j]<<" ";
	if(j>n/2 and i==n)
	sum+= dp[i][j];
}
//cout<<endl;
}
	
	cout<<setprecision(15)<<sum;
}

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

int GCD(long x, long y){
    if(x<y){
        long tmp;
        tmp=x;
        x =y;
        y =tmp;
    }

    long r=x%y;
    while(r!=0){
        x=y;
        y=r;
        r=x%y;
    }

    return y;
}

int main(){
    long a,b;
    cin >> a >> b;
    long gcd;
    gcd=GCD(a,b);
    cout << a*b/gcd << endl;

    return 0;
}

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

int main(){
  int N;cin>>N;
  int s=0;
  int res=0;
  for(int i=0;s<N;i++){
    s+=i;
    res=i;
  }
  int a=s-N;
  for(int i=1;i<res+1;i++){
    if(i!=a)
      cout<<i<<endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

char A[1000001];

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


	int N = getint();

	rep(i, N) {
		int a = getint();
		A[a] += A[a] + 1;
	}

	if (A[1]) {
		if (A[1] == 1) co(1);
		else co(0);
		return 0;
	}
	if (A[2]) {
		int kotae = (A[2] == 1);
		for (int i = 3; i <= 500000; i += 2) {
			if (A[i]) {
				kotae += (A[i] == 1);
				for (int j = i + i; j <= 1000000; j += i) {
					A[j] = 0;
				}
			}
		}
		for (int i = 500001; i <= 1000000; i += 2) kotae += (A[i] == 1);
		co(kotae);
		return 0;
	}

	int kotae = 0;
	for (int i = 2; i <= 500000; i++) {
		if (A[i]) {
			kotae += (A[i] == 1);
			for (int j = i + i; j <= 1000000; j += i) {
				A[j] = 0;
			}
		}
	}
	for (int i = 500001; i <= 1000000; i++) kotae += (A[i] == 1);
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 4236
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > using vec = std::vector< T >;
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, K;
  cin >> N >> K;
  vec< int > x(N);
  REP(i, N) { cin >> x[i]; }
  int ans = INF;
  REP(i, N - K + 1) {
    ans = min(ans, x[i + K - 1] - x[i] + min(abs(x[i]), abs(x[i + K - 1])));
  }
  cout << ans << "\n";

  // print();
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<functional>
#include<algorithm>
#include<iostream>
#define rep(i,a) for(i=0;i<a;i++)
#define rep2(i,a) for(i=1;i<a;i++)
using namespace std;
int main(void) 
{
	int gyoretu[102][102];
	int r,c,i,j,sum;
	cin>>r>>c;
	rep(i,r)rep(j,c) cin>>gyoretu[i][j];
	rep(i,r) {
		sum=0;
		rep(j,c) sum+=gyoretu[i][j];
		gyoretu[i][j]=sum;
	}
	rep(i,c+1) {
		sum=0;
		rep(j,r)sum+=gyoretu[j][i];
		gyoretu[j][i]=sum;
	}
	rep(i,r+1) {
		cout<<gyoretu[i][0];
		rep2(j,c+1) {
			/*if(gyoretu[i][j]==10000) printf("%6d",gyoretu[i][j]);
			else if(gyoretu[i][j]>=1000) printf("%5d",gyoretu[i][j]);
			else if(gyoretu[i][j]>=100) printf("%4d",gyoretu[i][j]);
			else if(gyoretu[i][j]>=10)printf("%3d",gyoretu[i][j]);
			else printf("%2d",gyoretu[i][j]);*/
			if(j==c+1) cout<<gyoretu[i][j];
			else cout<<" "<<gyoretu[i][j];
		}
		cout<<endl;
	}
	return 0;
}
			

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

int N, T;
int A[100010];

int main() {
    cin >> N >> T;
    for (int i = 0; i < N; ++i) cin >> A[i];

    int m = A[0];
    map<int, int, greater<int>> bucket;
    for (int i = 1; i < N; ++i) {
        m = min(m, A[i]);
        int cost = A[i] - m;

        auto itr = bucket.find(cost);
        if (itr != bucket.end()) {
            bucket[cost] = bucket[cost] + 1;
        } else {
            bucket.insert(make_pair(cost, 1));
        }
    }

    cout << bucket.begin()->second << endl;
    return 0;
}


Measured memory_bytes: 5376
#include <stdio.h>
#include<vector>
#include<iostream>
#include<string>
#include<deque>
#include<queue>
#include<stack>
#include<list>
using namespace std;


int main() {
	list<int> arr[1000];
	list<int>::iterator itr;
	int n, q, t, x;
	int query;
	cin >> n >> q;
	for (int i = 0; i < q; i++)
	{
		cin >> query >> t;
		switch (query)
		{
		case 0:
			cin >> x;
			arr[t].push_back(x);
			break;
		case 1:
			for (itr = arr[t].begin(); itr != arr[t].end(); itr++)
			{
				if (itr != arr[t].begin())cout << " ";
				cout << *itr;
			}
			cout << endl;
			break;
		case 2:
			cin >> x;
			arr[x].splice(arr[x].end(), arr[t]);
			break;
		}
	}


	return 0;
}


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

#include <math.h>
#include <stdlib.h>


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



int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    string s; cin >> s;

    int ans = 0;
    for(int i = 0; i < n-2; i++){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
    }
    cout << ans << endl;

    return 0;
}


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

int n,a[100004],dp[100004];

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	fill(dp,dp+n,INF);
dp[0]=0;

	for(int i=0;i<n;i++){
		dp[i+1]=min(dp[i]+abs(a[i]-a[i+1]),dp[i+1]);
		dp[i+2]=dp[i]+abs(a[i]-a[i+2]);
	}
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
n,k = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
ans = 0
for en in range((k//2)+1):
    if en > n:
        break
    if k-en > n:
        tmp = d[:]
        tmp.sort()
        ans = max(ans, sum(tmp[en:]))
        continue
    for dl in range(k-en+1):
        tmp = d[:dl]+d[n-(k-en-dl):]
        tmp.sort()
        for j in range(en+1):
            ans = max(ans, sum(tmp[j:]))
print(ans)


Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	ans := 0
	for i := 1; i <= 9; i++ {
		for j := 0; j <= 9; j++ {
			for h := 0; h <= 9; h++ {
				x := i*10000 + j*1000 + h*100 + j*10 + i
				if a <= x && x <= b {
					ans++
				}
			}
		}
	}
	fmt.Println(ans)
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main() {
int x,y;
cin>>x>>y;
rep(i,x+1){
  if(i*2+(x-i)*4==y){
    cout<<"Yes"<<endl;
    return 0;
  }
}
cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  while (cin >> N) {
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
      cin >> A[i];
    }
    sort(A.begin(), A.end());
    // (low, high]
    int low = -1, high = N - 1;
    while (high - low > 1) {
      int mid = (low + high) / 2;
      ll sum = 0;
      for (int i = 0; i <= mid; i++) {
        sum += A[i];
      }
      bool ok = true;
      for (int i = mid + 1; i < N; i++) {
        if (A[i] > sum * 2) {
          ok = false;
          break;
        }
        sum += A[i];
      }
      if (ok) {
        high = mid;
      } else {
        low = mid;
      }
    }
    int ans = N - high;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 1536
bg=[]
num=[]
t=0
for i in range(3):
    a=input().split()
    for m in range(3):
        bg.append(int(a[m]))
n=int(input())
for k in range(n):
    num.append(int(input()))
ns=[0,0,0,0,0,0,0,0,0]
for j in range(9):
    if bg[j] in num:
        ns[j]=1
nm=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
for l in nm:
    if ns[l[0]]+ns[l[1]]+ns[l[2]]==3:
        t=1
        break
if t==0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    rr = []

    while True:
        n,m = LI()
        if n == 0 and m == 0:
            break
        a = sorted([LI()[::-1] for _ in range(n)], reverse=True)
        r = 0
        for i in range(n):
            ai = a[i]
            if ai[1] <= m:
                m -= ai[1]
                ai[1] = 0
            else:
                ai[1] -= m
                m = 0
            r += ai[0] * ai[1]
        rr.append(r)


    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 10232
L, R = map(int, input().split())
MOD = 2019

ans = 2019
if R - L >= MOD:
  ans = 0
else:
  r = R % MOD
  l = L % MOD
  if l > r:
    ans = 0
  else:
    for i in range(l, r):
      for j in range(i+1, r+1):
        ans = min(ans, (i * j)%MOD)
print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main() {
    int N;
    cin >> N;
    if(N%2) cout << 2*N << endl;
    else cout << N << endl;
}


Measured memory_bytes: 3596
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
----
local H, W, N = read.nnn()
local big = math.max(H, W)
print(math.ceil(N / big))


Measured memory_bytes: 888
n = gets.chomp.to_i
p = gets.chomp.split(/\s/).map(&:to_i)

count = 0

(0..n-3).each do |i|
  if p[i] < p[i + 1] && p[i + 1] < p[i + 2] ||
     p[i] > p[i + 1] && p[i + 1] > p[i + 2]
    count += 1
  end
end

puts count

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define int long long int
using namespace std;
int check(int a[], int n, int num) {
    int c1=0, c2=0;
    for(int i=0;i<n;i++) {
        if(a[i] < num)
            c1++;
        else
            c2++;
    }
    return (c1==c2);
}
void solve() {
    int n;
    cin >> n;
    int a[n];
    int max=0;
    for(int i=0;i<n;i++) {
        cin >> a[i];
        if(a[i] > max)
            max = a[i];
    }
    sort(a, a+n);
    int count=0;
    cout << a[n/2] - a[n/2-1] << '\n';
    return ;
} 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

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

int main() {
  int n; cin >> n;
  
  vector<vector<int>> grids(2, vector<int>(n));
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < n; j++) {
      cin >> grids[i][j];
    }
  }
  
  vector<int> accumulations(n, 0);
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) accumulations[i] += grids[0][j];
    for (int k = i; k < n; k++) accumulations[i] += grids[1][k];
  }
  
  int answer = *max_element(accumulations.begin(), accumulations.end());
  
  cout << answer << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a % 2 != 0 && b % 2 != 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }

}


Measured memory_bytes: 22228
//c++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define len(x) ((int)(x).size())

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
const ll MOD = 1000000007;
//const ll MOD = 998244353;
double EPS = 1e-10;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.9lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 2000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}



ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}



ll R, C, K;
ll V[3010][3010];
ll dp[3010][3010][10];
void solve(){
  cin >> R >> C >> K;
  rep(i, K){
    ll r, c, v;
    cin >> r >> c >> v;
    r--;
    c--;
    V[r][c] = v;
  }
  rep(i, 3010)rep(j, 3010)rep(k, 10) dp[i][j][k] = -INFL;
  dp[0][0][0] = 0;
  rep(i, R){
    rep(j, C){
      rep(k, 4){
        dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k]);
        dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k]);
        if(k != 3){
          dp[i][j+1][k+1] = max(dp[i][j+1][k+1], dp[i][j][k] + V[i][j]);
          dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k] + V[i][j]);
        }
      }
    }
  }
  ll ans = -INFL;
  rep(i, R+1){
    rep(j, C+1){
      rep(k, 4){
        ans = max(ans, dp[i][j][k]);
      }
    }
  }
  cout << ans << endl;
}

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


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

int main() {
  int N;
  cin>>N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
 

  int ans=0;
  int b=0;
  
  for (int i = 0; i < N-1; i++) {
    if(H.at(i)>=H.at(i+1)){
      b++;
    }
    else{
      ans=max(ans,b);
      b=0; 
    }
  }
  cout<<max(ans,b)<<endl;
  
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = getInt(sc);
		int b = getInt(sc);
		int h = getInt(sc);
		int m = getInt(sc);

		double angleA = (double) (360.0 / 720.0) * ((double) h * 60.0 + (double) m);

		double angleB = (double) (360.0 / 60.0) * (double) m;
		double angle = Math.abs(angleA - angleB);
		if (angle == 0) {
			System.out.println(Math.abs(b - a));
		} else if (angle == 180) {
			System.out.println((double) (a + b));
		} else {
			double cos = Math.cos(Math.toRadians(angle));
			System.out.println(Math.sqrt(a * a + b * b - 2.0 * a * b * cos));
		}

	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


Measured memory_bytes: 36024
h,w = map(int,input().split())
#典型的なBFS
s = ["#"*(w+2) for _ in range(h+2)]
road = []
setroad = set([])
#額縁コーティング
for i in range(1, h+1):
	s[i] = "#"+input()+"#"

for i in range(h+2):
	for j in range(w+2):
		if s[i][j]==".":
			road.append((i,j))
			setroad.add((i,j))


#
def isroad(n, m):
	if (n, m) in setroad:
		return True
	else:
		return False


# 全探索
ans = 0

for shokix, shokiy in road:
	kaisuu = 0
	listtansaku = []
	settansaku = set([])
	listmada = [(shokix, shokiy)]
	setmada = set([(shokix,shokiy)])
	while len(setmada) != 0:
		for i, j in listmada[:]:
			listtansaku.append((i,j))
			settansaku.add((i,j))
			listmada.remove((i, j))
			setmada.remove((i, j))
			for k,l in [(i+1,j),(i-1,j),(i,j+1),(i,j-1)]:
				if isroad(k,l):
					if not (k,l) in setmada:
						if not (k,l) in settansaku:
							listmada.append((k,l))
							setmada.add((k,l))
		kaisuu += 1
	kaisuu -= 1
	if kaisuu >= ans:
		ans = kaisuu
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;
const double e = 0.000000001;

int main(){
  double t,x; cin >> t >> x;
  cout << (double)t/x ;
  return 0;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>

using namespace std;

typedef long long int lli;

int gcd(int a, int b){
	return b != 0 ? gcd(b, a%b) : a;
}

int lcm(int a, int b){
	return a*b / gcd(a, b);
}

#define N_MAX 200000
#define MOD 1000000007

int N;
bool func(int width, int pos, char *S, char *T)
{
	int left = 1, right = width;

	for (int i = N - 1; i >= 0; i--){
		if ('L' == T[i]){
			right = min(width, right + 1);
		}
		else if ('R' == T[i]){
			left = max(1, left - 1);
		}

		if ('L' == S[i]){
			left++;
		}
		else if ('R' == S[i]){
			right--;
		}
		if (left > right){
			return false;
		}
	}

	if (left <= pos && pos <= right){
		return true;
	}
	return false;
}

void change(char *S)
{
	for (int i = 0; i < N; i++){
		if ('L' == S[i]){
			S[i] = 'U';
		}
		else if ('R' == S[i]){
			S[i] = 'D';
		}
		else if ('U' == S[i]){
			S[i] = 'L';
		}
		else if ('D' == S[i]){
			S[i] = 'R';
		}
	}

	return;
}

void solv()
{
	int H, W; scanf("%d%d%d", &H, &W, &N);
	pair<int, int> start; scanf("%d%d", &start.first, &start.second);
	char S[N_MAX + 10], T[N_MAX + 10]; scanf("%s%s", S, T);

	if (!func(W, start.second, S, T)){
		printf("NO");
		return;
	}

	change(S); change(T);
	if (!func(H, start.first, S, T)){
		printf("NO");
		return;
	}

	printf("YES");
	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 512
n, m, k = gets.split(" ").map(&:to_i)
## 二項係数 C(n,k) mod pの計算 (pは素数)##

#適切な値に設定する
MOD = 10**9 + 7
MAX = n*m-2

$fact = Array.new(MAX + 1) # i! mod p
$finv = Array.new(MAX + 1) # (i!)^(-1) mod p
$inv = Array.new(MAX + 1) # i^(-1) mod p

def com_init()
  $fact[0] = $fact[1] = 1
  $finv[0] = $finv[1] = 1
  $inv[1] = 1
  2.upto(MAX) do |i|
    $fact[i] = $fact[i-1] * i % MOD
    $inv[i] = MOD - $inv[MOD % i] * (MOD/i) % MOD
    $finv[i] = $finv[i-1] * $inv[i] % MOD
  end
end

# C(n,k) mod p
def com(n,k)
  return 0 if n < k || n < 0 || k < 0
  $fact[n] * (($finv[n-k] * $finv[k]) % MOD )% MOD
end

def f(n)
  ((n-1)*n*(n+1)/6) %MOD
end

com_init
puts (m**2 * f(n) + n**2 * f(m)) * com(m*n-2, k-2) %MOD


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

using namespace std;

long gcd(long a, long b) {
	for (; b; swap(a, b))
		a %= b;
	return a;
}
int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		long a, b, c, d;
		cin >> a >> b >> c >> d;
		if (a < b || d < b) {
			cout << "No\n";
			continue;
		}
		if (b <= c) {
			cout << "Yes\n";
			continue;
		}
		long g = gcd(b, d);
		long cc = (a - c + g - 1) / g, bb = (a - b) / g;
		cout << (cc - bb > 1 ? "No" : "Yes") << '\n';
	}
	cout << flush;
	return 0;
}


Measured memory_bytes: 256
n, x, y = list(map(int, input().split()))
x -= 1
y -= 1

cnt = [0] * n

dist = []
for i in range(n):
    dist.append([-1] * n)
for i in range(n):
    dist[i][x] = abs(i-x)
    dist[i][y] = abs(i-y)
    dist[x][i] = abs(i-x)
    dist[y][i] = abs(i-y)

for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        dis = min(j - i, dist[j][y] + 1 + dist[i][x], dist[j][x] + 1 + dist[i][y])
        cnt[dis] += 1
for i in range(1, n):
    print(cnt[i])


Measured memory_bytes: 36852
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a, b, k;
	cin >> a >> b >> k;

    long long aa=a;
    a = (a-k<0 ? 0 : a-k);
    k = (k-aa<0 ? 0 : k-aa);
    b = (b-k<0 ? 0 : b-k);
	cout << a << " " << b << endl;
}

Measured memory_bytes: 256