akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}



signed main(){

  int n,a,b;
  string str;

  string s[3];
  cinf(3,s);
  cout << (s[0][s[0].length()-1]==s[1][0]&&s[1][s[1].length()-1]==s[2][0] ? "YES" : "NO" ) fin;
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
S = sum(A)
b = 0
a = 0
c = 0
if N == 2:
    print(abs(A[0]-A[1]))
else:
    for i in range(len(A)):
        if S/2-0.5 > a:
            a += A[i]
        else:
            b = a + A[i]
            c = a - A[i-1]
            break
        if i == len(A)-1:
            b = a
            a = a-A[i]
        else:
            None
    print(min(abs(S - a*2), abs(S - b*2),abs(S-c*2)))



Measured memory_bytes: 26220
#include <stdio.h>
int main(){
    int n,ans,temp;
    while(true){
        scanf("%d",&n);
        if(n==0)return 0;
        ans=0;
        n/=4;
        while(n--){
            scanf("%d",&temp);
            ans+=temp;
        }
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, c, x;
  char b;
  cin >> a >> b >> c;
  if (b == '+'){
    x = a + c;
  }
  if (b == '-'){
    x = a - c;
  }
  cout << x <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

using namespace std;
using ll = long long;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}

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


//////////////////////////////////////////////////


int main() {
    int k, x; cin >> k >> x;
    if (500*k >= x) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	ll a,b;
	rl2(a,b);
	ll x=max(a+b,a-b);
	x=max(x,a*b);
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())

dict_ = {}

for i in range(n):
    s, p = input().split()
    if s in dict_:
        dict_[s].append([p, i+1])
    else:
        dict_[s] = [[p, i+1]]

for key, item in sorted(dict_.items()):
    for p, i in sorted(item, key=lambda x:int(x[0]), reverse=True):
        print(i)


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll a,b,c; cin>>a>>b>>c;
    ll m=max({a,b,c}),sum=a+b+c,ans;
    if(m%2==sum%2)  ans=(3*m-sum)/2;
    else ans=(3*(m+1)-sum)/2;
    cout<<ans<<endl;
    return 0;
}

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

namespace {
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define len(x) (int)((x).size())
#define X first
#define Y second

#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
  
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;

ll expmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
template<typename T> T sqr(const T& x) { return x*x; }
ll flog(const ll x) { return 63 - __builtin_clzll(x); }
template<typename T> void sort(T& t) { sort(all(t)); }
template<typename T> void undupe(vector<T>& v) { sort(v); v.erase(unique(all(v)), v.end()); }

struct _IOS { _IOS() { ios::sync_with_stdio(0); cin.tie(0); } } _IOS;
}

const ll MOD = 1e9 + 9;
const ll INF = 1e15;
const double EPS = 1e-8;

int N, M;
vvi adj;

vi vis;
vi col;
vi deg;
ll comp = 0, good = 0, bad = 0, wt = 0, bk = 0;
bool ok = true;

void dfs(int u, int c) {
  vis[u] = 1;
  col[u] = c;
  if (c) wt++;
  else bk++;
  for (int v : adj[u]) {
    if (col[v] == c) ok = false;
    if (!vis[v]) dfs(v, c^1);
  }
}

int main() {
  cin >> N >> M;
  adj.resize(N);
  deg.resize(N);
	FOR(i,0,M) {
    int u, v; cin >> u >> v; u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
    deg[u]++, deg[v]++;
  }
  
  ll A = 0;
  
  FOR(i,0,N) {
    if (deg[i] == 0) {
      A++;
    }
  }
	
  vis.assign(N, 0);
  col.assign(N, -1);
  
	FOR(u,0,N) if (!vis[u] && !(deg[u] == 0)) {
    comp++;
    ok = true;
    wt = 0, bk = 0;
    dfs(u, 0);
    if (ok) good++;
    else bad++;
  }
  
  ll ans = (bad*(bad + 2*good)) + (2*good*good) + (2*N*A - A*A);
  cout << ans << "\n";
}


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

ans = 10**10

for i in range(N - K + 1):  
  left = li[i]
  right = li[i + K - 1]
  ans = min(ans, min(abs(left), abs(right)) + right - left)

print(ans)

Measured memory_bytes: 14392
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>

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

int main() {

	int N, T, A, H[1234];
	scanf("%d%d%d", &N, &T, &A);

	rep(i, N) scanf("%d", &H[i]);


	double nearest = 123456789;
	int n = -1;

	rep(i, N) {
		if (abs(A - (T - H[i] * 0.006)) < nearest) {
			n = i;
			nearest = abs(A - (T - H[i] * 0.006));
		}
	}


	printf("%d\n", n + 1);

	return 0;
}


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

const int MAX_N = 100100;

vector<vector<int>> to;

int dfs(int v){ // tree-DP
  
  if(to[v].empty()){ //子なし→leaf→深さ0
    return 0;
  }
  
  vector<int> res;
  
  for(auto ne : to[v]){
    
    res.push_back(dfs(ne));
    
  }
  
  sort(res.rbegin(),res.rend());
  
  int r = 0;
  
  int cnt = 1;
  
  for(auto ne : res){
    r = max(r, ne+cnt);
    cnt++;
  }
  
  return r;
}
     
    

int main(){
  
  int N; cin >> N;
  
  to.resize(N);
  
  for(int i = 1; i < N; i++){
    int a; cin >> a; a--;
    to[a].push_back(i);
  }
  
  
  cout << dfs(0) << endl;
  
  return 0;
}

Measured memory_bytes: 15104
import sys
input = sys.stdin.readline
from collections import Counter
mod = 10**9+7
n = int(input())
a = list(map(int,input().split()))

def make_array_for_comb(N, mod=10**9+7):
    fact = [1,1]
    fact_inv = [1,1]
    inv = [0,1]
    for i in range(2, N+1):
        fact.append((fact[-1]*i) % mod)
        # モジュラ逆数の性質
        inv.append((-inv[mod%i] * (mod//i)) % mod)
        fact_inv.append((fact_inv[-1]*inv[i]) % mod)
    return fact, fact_inv

def comb(n, r, mod=10**9+7):
  if (r < 0) or (n < r):
      return 0
  r = min(r, n - r)
  return fact[n] * fact_inv[r] * fact_inv[n-r] % mod

fact, fact_inv = make_array_for_comb(n+1,mod)
c = Counter(a)
k = c.most_common()[0][0]
t = 0
for i,ai in enumerate(a):
  if ai == k:
    if t == 0:
      L = i
    elif t == 1:
      R = n-i
      break
    t += 1
    
print(n)
for i in range(1,n+1):
  print((comb(n+1,i+1,mod)-comb(L+R,i,mod))%mod)

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

long long int N, K, L, p, q, a, i, fi;
long long int parr[200000], rankr[200000], part[200000], rankt[200000];
map<pair<long long int, long long int>, vector<long long int> > mp;

void shokika(long long int* par, long long int* ran, long long int n){
    for(fi = 0; fi < n; ++fi){
        par[fi] = fi;
        ran[fi] = 0;
    }
}

inline long long int finr(long long int* par, long long int n){
    if(par[n] == n){
        return n;
    }else{
        return par[n] = finr(par, par[n]);
    }
}

inline void union_(long long int* par, long long int* ran, long long int x, long long int y){
    x = finr(par, x);
    y = finr(par, y);
    if(x == y) return;
    if(ran[x] < ran[y]){
        par[x] = y;
    }else{
        par[y] = x;
        if(ran[x] == ran[y])ran[x]++;
    }
}

inline bool same(long long int* par, long long int x, long long int y){
    return finr(par, x) == finr(par, y);
}

int main(){
    scanf("%lld%lld%lld", &N, &K, &L);
    shokika(parr, rankr, N);
    shokika(part, rankt, N);
    for(i = 0; i < K; ++i){
        scanf("%lld%lld", &p, &q);
        union_(parr, rankr, p - 1, q - 1);
    }
    for(i = 0; i < L; ++i){
        scanf("%lld%lld", &p, &q);
        union_(part, rankt, p - 1, q - 1);
    }
    for(i = 0; i < N; ++i){
        mp[make_pair(finr(parr, i), finr(part, i))].push_back(i);
    }
    for(i = 0; i < N; ++i){
        cout << mp[make_pair(parr[i], part[i])].size() << (i==N-1?"\n":" ");
    }
    return 0;
}


Measured memory_bytes: 26752
use std::cmp;
fn main() {
    let sc = std::io::stdin();
    let mut sc = Scanner { stdin: sc.lock() };
    let n: usize = sc.read();
    let a: usize = sc.read();
    let b: usize = sc.read();

    let segments = (n + b - 1) / b;
    if a + b - 1 > n || (n + b - 1) / b > a {
        println!("-1");
        return;
    }

    let mut ans = (1..(n + 1)).collect::<Vec<usize>>();
    for i in 0..segments {
        let from = i * b;
        let to = cmp::min(from + b, n);
        ans[from..to].reverse();
    }

    let mut a = a - segments;
    for i in (0..segments).rev() {
        if a == 0 {
            break;
        }
        let length = cmp::min(a + 1, b);
        let from = i * b;
        let to = cmp::min(from + length, n);
        ans[from..to].reverse();
        a -= (to - from) - 1;
    }

    for (i, a) in ans.into_iter().enumerate() {
        if i > 0 {
            print!(" ");
        }
        print!("{}", a);
    }

    println!();
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 10364
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        mut x: [i32;m],
    }

    if n >= m {
        println!("0");
        return;
    }

    x.sort();
    let mut d = vec![0; m - 1];
    for i in 0..m - 1 {
        d[i] = x[i + 1] - x[i];
    }
    d.sort();
    let mut ans = 0;
    for i in 0..m - 1 - n + 1 {
        ans += d[i];
    }
    println!("{}", ans);
}


Measured memory_bytes: 3388
// 解き直し.
// ABC 143解説.
// https://img.atcoder.jp/abc143/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

const int MAX = 301;
const LL INF = 1234567654321;
LL d1[MAX][MAX], d2[MAX][MAX];

int main(){
    
    // 1. 入力情報取得.
    int N, M, a, b;
    LL L, c;
    scanf("%d %d %lld", &N, &M, &L);
    for(int i = 0; i < MAX; i++) for(int j = 0; j < MAX; j++) if(i != j) d1[i][j] = INF, d2[i][j] = INF;
    for(int i = 0; i < M; i++){
        scanf("%d %d %lld", &a, &b, &c);
        a--, b--;
        d1[a][b] = c;
        d1[b][a] = c;
    }
    
    // 2. ワーシャル–フロイド法(※各町間の最短距離を保存).
    for(int k = 0; k < N; k++){
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++){
                d1[i][j] = min(d1[i][j], d1[i][k] + d1[k][j]);
            }
        }
    }
    
    // 3. 解説通り.
    // 3-1. 最短距離が, L以下の町の組に, 距離1 の 辺を張る(※もう一つグラフを作成).
    for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) if(d1[i][j] <= L) d2[i][j] = 1;
    
    // 3-2. ワーシャル–フロイド法(※各町間を移動するときの燃料補給回数を保存).
    for(int k = 0; k < N; k++){
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++){
                d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
            }
        }
    }
    
    // 4. Q個のクエリに回答.
    int Q, s, t;
    scanf("%d", &Q);
    for(int i = 0; i < Q; i++){
        scanf("%d %d", &s, &t);
        s--, t--;
        if(d2[s][t] == INF) printf("%d\n", -1);
        else                printf("%d\n", d2[s][t] - 1);
    }
    return 0;
    
}

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

const int MAX_N	= 100000;
int a[ MAX_N + 5 ];
bool b[ MAX_N + 5 ];

int main( int argc, char *argv[] )
{
int i;
int N;
int iCount;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	for( i = 1; i <= N; i++ ) cin >> a[ i ];

	iCount = 0;
	i = 1;
	while( ! b[ i ] )
	{
		iCount++;
		b[ i ] = true;
		i = a[ i ];
		if( i == 2 )
		{
			cout << iCount << endl;

			return 0;
		}
	}

	cout << - 1 << endl;

	return 0;
}




Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

const int N = 1e6+5;

int a[N], b[N], spf[N], prime[N];

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

void Sieve(){
    memset(prime, -1, sizeof prime);
    prime[0] = prime[1] = 0;
    for(int i = 2; i<=1000000; i++){
        if(prime[i] == -1){
            prime[i] = 1; spf[i] = i;
            for(int j = 2; i*j<=1000000; j++){
                prime[i*j] = 0;
                if(!spf[i*j]) spf[i*j] = i;
            }
        }
    }
    return;
}

int main(){

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    Sieve();

    int n; cin >>n;
    for(int i = 0; i<n; i++){
        cin >>a[i];
        b[i] = a[i];
    }

    bool ok = 1;
    set<int> fact;
    for(int i = 0; i<n && ok; i++){
        set<int> aux;
        while(a[i] > 1){
            aux.insert(spf[a[i]]);
            a[i] /= spf[a[i]];
        }
        set<int>::iterator it;
        for(it = aux.begin(); it != aux.end(); it++){
            if(fact.count(*it)){
                ok = 0; break;
            }
            else fact.insert(*it);
        }
    }
    if(ok) cout <<"pairwise coprime" <<endl;
    else{
        int g = b[0];
        for(int i = 1; i<n; i++){
            g = gcd(g, b[i]);
        }
        if(g == 1) cout <<"setwise coprime" <<endl;
        else cout <<"not coprime" <<endl;
    }

    return 0;
}


Measured memory_bytes: 19276
#%%
import fractions
A, B, C, D = map(int, input().split())

def count_q(a, b, m):

    if a % m == 0:
        q = b // m  - a // m + 1
    else:
        q = b // m - a // m
    return q

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

lcm = lcm(C, D)
qc = count_q(A, B, C)
qd = count_q(A, B, D)
qcd = count_q(A, B, lcm)

ans = (B - A + 1) - (qc + qd - qcd)
print(ans)


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

using namespace std;
const int MOD = 1000000007,MAX = 510000;
long int pow107 = (int)pow(10, 9) + 7,llimit = LONG_MAX,fac[MAX], finv[MAX], inv[MAX];
int ilimit = INT_MAX;

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long int COM(long int n,long int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

//long intの最大llimit
//intの最大ilimit
//10^9+7    pow107
//素数pn
//n乗jou
//階乗factorial
//コンビネーションFunc2
//コンビネーションCOMinit(),COM(n,m)

int main(){
    int h,w;
    cin >> h >> w;
    int d[3] = {-1,0,1};
    vector<string> vs;
    for(int i = 0; i < h; ++i){
        string s;
        cin >> s;
        vs.push_back(s);
    }
    for(int  i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(vs[i][j] == '#')
                continue;
            int c = 0;
            for(int k = -1; k <= 1; ++k){
                for(int l = -1; l <= 1; ++l){
                    if(i + k < 0 || j + l < 0 || i + k >= h || j + l >= w)
                        continue;
                    if(vs[i+k][j+l] == '#')
                        c++;
                }
            }
            vs[i][j] = char('0' + c);
        }
    }

    for(int i = 0; i < h; ++i){
        cout << vs[i] << endl;
    }



}

Measured memory_bytes: 256
from sys import stdin

N = int(stdin.readline().rstrip())
Ls = [int(x) for x in stdin.readline().rstrip().split()]

Ls.sort(reverse=True)

maxv = Ls[0]
sum = 0
for x in Ls[1:]:
    sum = sum + x
    
if maxv < sum:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
function evenstr(s)
	l = length(s)
	if l%2==0 && s[1:div(l,2)]==s[div(l,2)+1:l]
		return 1
	else
		return 0
	end
end

function main()
	s = chomp(readline())
	l = length(s)
	for i in 1:l-1
		if evenstr(s[1:l-i]) == 1
			print(l-i)
			break
		end
	end
end

main()

Measured memory_bytes: 110084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  unordered_map<string,int> m;
  rep(i, n){
    string s;
    cin >> s;
    sort(all(s));
    if(m.count(s)){
      ans += m[s];
      m[s]++;
    }
    else{
      m.insert(mp(s, 1));
    }
  }
  print(ans);
}

Measured memory_bytes: 10660
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int leng = S.length();
    int ans = 999;
    
    for (int i = 0; i < leng - 2; i++) {
      String sub = S.substring(i,i+3);
      int ab = Integer.parseInt(sub);
      if(ans > Math.abs(753-ab)){
        ans = Math.abs(753-ab);
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21716
N, K = map(int, input().split())
a = [int(i) for i in input().split()]

s = [0]
for i in range(N) :
    s.append(s[-1] + a[i])

sub = []
for i in range(N + 1) :
    for j in range(i + 1, N + 1) :
        sub.append(s[j] - s[i])

ret = 0
for i in range(40, -1, -1) :
    sub_ = []
    for sv in sub :
        if sv & (1 << i) :
            sub_.append(sv)
            
    if len(sub_) >= K :
        ret += (1 << i)
        sub = sub_
    
print(ret)

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

int main(int argc, const char * argv[]) {
    string str;
    int q, a, b;
    string order;
    int i, j;
    string str2;
    
    cin >> str;
    cin >> q;
    
    for(j=0;j<q;j++){
        cin >> order >> a >> b;
    
        if(order=="print"){
            for(i=a;i<=b;i++){
                cout << str[i];
            }
            cout << endl;
        }else if(order=="reverse"){
            while(a<b){
                swap(str[a],str[b]);
                a++;
                b--;
            }
        }else if(order=="replace"){
            cin >> str2;
            for(i=a;i<=b;i++){
                str[i]=str2[i-a];
            }
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long llong;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<int> a(n);
   rep(i, n) { cin >> a[i]; }
   llong s = 0;
   rep(i, n) { s += a[i]; }
   vector<int> x(n);
   x[0] = s;
   for (int i = 1; i <= n - 2; i += 2) {
      x[0] -= 2 * a[i];
   }
   for (int i = 1; i < n; i++) {
      x[i] = -x[i - 1] + 2 * a[i - 1];
   }
   rep(i, n) { cout << x[i] << endl; }
   return 0;
}

Measured memory_bytes: 2048
use std::cmp::{max, min};
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! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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")
    };
}
const MOVES: [(i32, i32); 4] = [(1, 0), (0, 1), (-1, 0), (0, -1)];
use std::collections::BinaryHeap;
fn main() {
    input!{
        n:i64,
        k:i64,
    }
    let ans = n - k + 1;
    println!("{}",ans );
}

Measured memory_bytes: 4352
def snk_cal(i):
    snk = i
    i = str(i)
    q = 0
    for j in range(len(i)):
        q += int(i[j])
    snk /= q
    return snk

K = int(input())
if K <= 9:
    for i in range(K):
        print(i+1)
else:
    for i in range(9):
        print(i+1)
    K -= 9
    snk = 9
    while K > 0:
        res = snk+1
        d = len(str(res))
        l = []
        for i in range(d):
            n = int(str(res)[:-i-1]+'9'*(i+1))
            l.append(snk_cal(n))
        i = l.index(min(l))
        snk = int(str(res)[:-i-1]+'9'*(i+1))
        print(snk)
        K -= 1
        

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

int main() {
	vector<int>a(2);
	for (int b = 0; b < 2; b++) {
		for (int c = 0; c < 4; c++) {
			int d;
			cin >> d;
			a[b] += d;
		}
	}
	cout << max(a[0], a[1]) << endl;
}

Measured memory_bytes: 3056
#pragma GCC optimize("03")
#include <bits/stdc++.h>
typedef long long ll;
const int inf=INT_MAX;
using namespace std;
int a,b,c,d,ans=0,n,m;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>a>>b>>c>>d;
    for(int i=max(a,c);i<min(b,d);i++) ans++;
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    string S;
    cin >> S;
    int len = S.length(), flag = true;
    for (int i = 0; i < len; ++i) {
        if (i % 2 == 0 and S[i] == 'L') flag = false;
        if (i % 2 == 1 and S[i] == 'R') flag = false;
    }
    cout << (flag?"Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 3584
// Problem : B - Easy Linear Programming
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define ll long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<ll,ll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=b;i>=a;i--)
#define maxn 1005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
using namespace std;
void solve()
{
	ll a,b,c,k;
	cin >> a >> b >> c>>k;
	if(a>=k)
	{
		cout << k;
		return;
	}
	if(a+b>=k)
	{
		cout << a;
		return;
	}
	cout << a-(k-(a+b));
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int a,b;
    cin>>a>>b;
    cout<<(a+b)/2<<endl;
    return 0;
}

Measured memory_bytes: 3068
n=int(input())
ichi=[0,0,0,0,0,0,0,0,0,0,0,0]
ni=[0,0,0,0,0,0,0,0,0,0,0,0]
san=[0,0,0,0,0,0,0,0,0,0,0,0]
yon=[0,0,0,0,0,0,0,0,0,0,0,0]
go=[0,0,0,0,0,0,0,0,0,0,0,0]
roku=[0,0,0,0,0,0,0,0,0,0,0,0]
nana=[0,0,0,0,0,0,0,0,0,0,0,0]
hachi=[0,0,0,0,0,0,0,0,0,0,0,0]
kyu=[0,0,0,0,0,0,0,0,0,0,0,0]
zyu=[0,0,0,0,0,0,0,0,0,0,0,0]
zyu_ichi=[0,0,0,0,0,0,0,0,0,0,0,0]
zyu_ni=[0,0,0,0,0,0,0,0,0,0,0,0]

while n>0:
    l=input().split()
    b=int(l[0])
    f=int(l[1])
    r=int(l[2])
    v=int(l[3])

    num=3*(b-1)+f

    if num==1:
        ichi[r-1]+=v
    elif num==2:
        ni[r-1]+=v
    elif num==3:
        san[r-1]+=v
    elif num==4:
        yon[r-1]+=v
    elif num==5:
        go[r-1]+=v
    elif num==6:
        roku[r-1]+=v
    elif num==7:
        nana[r-1]+=v
    elif num==8:
        hachi[r-1]+=v
    elif num==9:
        kyu[r-1]+=v
    elif num==10:
        zyu[r-1]+=v
    elif num==11:
        zyu_ichi[r-1]+=v
    else:
        zyu_ni[r-1]+=v
    n=n-1
m=1
A=" "+str(ichi[0])
B=" "+str(ni[0])
C=" "+str(san[0])
D=" "+str(yon[0])
E=" "+str(go[0])
F=" "+str(roku[0])
G=" "+str(nana[0])
H=" "+str(hachi[0])
I=" "+str(kyu[0])
J=" "+str(zyu[0])
K=" "+str(zyu_ichi[0])
L=" "+str(zyu_ni[0])
while m<10:
    A=A+" "+str(ichi[m])
    B=B+" "+str(ni[m])
    C=C+" "+str(san[m])
    D=D+" "+str(yon[m])
    E=E+" "+str(go[m])
    F=F+" "+str(roku[m])
    G=G+" "+str(nana[m])
    H=H+" "+str(hachi[m])
    I=I+" "+str(kyu[m])
    J=J+" "+str(zyu[m])
    K=K+" "+str(zyu_ichi[m])
    L=L+" "+str(zyu_ni[m])
    m=m+1
print(A)
print(B)
print(C)
print("####################")
print(D)
print(E)
print(F)
print("####################")
print(G)
print(H)
print(I)
print("####################")
print(J)
print(K)
print(L)



Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int []array_A=new int[n];
		int[]array_B=new int[n-1];
		int goukei=0;
		for(int i=0;i<n-1;i++){
			array_B[i]=scan.nextInt();
		}
		goukei+=array_B[0];
		goukei+=array_B[n-2];

		for(int i=1,j=0;i<n-1;i++,j++){
			if(array_B[j]<=array_B[j+1]){
				array_A[i]=array_B[j];
			}else{
				array_A[i]=array_B[j+1];
			}
			goukei+=array_A[i];
		}
		System.out.println(goukei);
	}
}


Measured memory_bytes: 23508
a,b,c,d,e,f=map(int,input().split())
w=set()
for x in range(0,f+1,100*a):
    for y in range(0,f+1-x,100*b):
        w.add(x+y)
s=set()
for x in range(0,f+1,c):
    for y in range(0,f+1-x,d):
        s.add(x+y)

max=-1
total=0
sugar=0
for x in w:
    for y in s:
        if 0<x+y<=f and y<=x*e//100:
            if max<y/(x+y):
                total=x+y
                sugar=y
                max=y/(x+y)
print(total,sugar)

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int main(){
	
	string str;cin >> str;
	
	ll now = 0;
	ll ans = 0;
	REP(i,str.size()){
		if(str[i] == 'W'){
			ans += now;
		}
		else {
			now++;
		}
	}
	cout << ans << endl;
		
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

vector<vector<ll>> g(100010); 
vector<ll> dist(100010);

int main(){
    ll n;
    cin >> n;

    ll a[n];
    rep(i, n)cin >> a[i];

    //初項を負の数で始めるケース
    ll ans = 0;
    ll sum;
    if(a[0] >= 0){
        sum = -1;
        ans += a[0] + 1;
    }
    else {
        sum = a[0];
    }

    for(ll i = 1; i < n; ++i){
        if((i&1 && sum+a[i] <= 0) || (!(i&1) && sum+a[i] >= 0)){
            ans += llabs(sum+a[i]) + 1;
            sum = -1*(sum/llabs(sum));
        }
        else {
            sum += a[i];
        }
    }

    //初項を正の数で始めるケース
    ll res = 0;
    if(a[0] <= 0){
        sum = 1;
        res += abs(a[0]) + 1;
    }
    else {
        sum = a[0];
    }

    for(ll i = 1; i < n; ++i){
        if((!(i&1) && sum+a[i] <= 0) || (i&1 && sum+a[i] >= 0)){
            res += llabs(sum+a[i]) + 1;
            sum = -1*(sum/llabs(sum));
        }
        else {
            sum += a[i];
        }
    }

    ans = min(ans, res);
    cout << ans << endl;
}

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

int main(){
  string A, B ,C;
  cin >> A >> B >> C;
  
  
  char a = A.at(0);
  char b = B.at(0);
  char c = C.at(0);
  
  cout << a << b << c << endl;
  
}

Measured memory_bytes: 256
def main():
    N, A = map(int, input().split())
    x = list(map(int, input().split()))
    dp = [[0] * (50*N + 1) for _ in range(N+1)]
    dp[0][0] = 1
    for k in range(N):
        for i in reversed(range(k+1)):
            for j in range(50 * N + 1 -x[k]):
                dp[i+1][j+x[k]] += dp[i][j]
    r = 0
    for i in range(1, N+1):
        r += dp[i][i*A]
    return r
print(main())


Measured memory_bytes: 65820
#include<bits/stdc++.h>
using namespace std;
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define pb push_back
#define F first
#define S second

#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define int long long
#define ll long long
const int M=1e9+7;

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

int expo(int x, int y) {int res=1;x=x%M;while(y>0){if(y&1)res=(1ll*res*x)%M;
	y=y>>1;x=(1ll*x*x)%M;} return res;}
	

signed main(){
	gearup;
	int t = 1;
	//cin >> t;
	while(t--){
		int r;
		cin >> r;
		long double ans = 2 * 3.141592 * r ;
		cout << ans;
	}
	return 0;
}


Measured memory_bytes: 3820
# N, W = 3, 8
# ARR = [
#     [3, 30],
#     [4, 50],
#     [5, 60],
# ]
#
# N, W, = 6, 15
# ARR = [
#     [6, 5],
#     [5, 6],
#     [6, 4],
#     [6, 6],
#     [3, 5],
#     [7, 2],
# ]


N,W = map(int,input().split())
ARR = []

for i in range(N):
    ARR.append(list(map(int,input().split())))

def calculate(n, w, arr):
    result = [[0] * (w + 1) for i in range(n + 1)]


    for i in range(n):
        width = arr[i][0]
        value = arr[i][1]
        for j in range(w + 1):

            if j >= width:
                result[i + 1][j] = max(result[i][j - width] + value, result[i + 1][j])

            result[i + 1][j] = max(result[i + 1][j], result[i][j])

    # print(result)
    print(result[n][w])


calculate(N, W, ARR)


Measured memory_bytes: 118768
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
int main() {
	fast;
	lli x,l,r;
	cin>>x>>l>>r;
	lli i,flag=0;
	for(i=l;i<=r;i++)
	{
		if(i%x==0)
		{
			flag=1;
			break;
		}
	}
	if(flag==1)
		cout<<"OK";
	else
		cout<<"NG";
	
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

using namespace std;
int N;
vector<int> P(100005);

int main() {
  cin >> N;
  int ma = 0;
  for (int i=0; i<N; i++) {
    int a;
    cin >> a;
    P.at(a)++;
    ma = max(a, ma);
  }
  int ans = 0;
  for (int i=0; i<=ma; i++) {
    int tmp = P.at(i);
    if (i>=1) {
      tmp+=P.at(i-1);
    }
    if (i<=ma-1) {
      tmp+=P.at(i+1);
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
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 Would
#define you
#define please

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

	int N, K;
	cin >> N >> K;

	ll kotae = 0;
	if (K) {
		for (int i = K + 1; i <= N; i++) {
			kotae += 1ll * (N / i) * (i - K);
			if (N % i >= K) kotae += N % i - K + 1;
		}
	}
	else {
		kotae = 1ll * N * N;
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int D,N;
	int[] T,A,B,C;
	int[][] dp;
    public void solve() {
    	D = nextInt();
    	N = nextInt();
    	T = new int[D];
    	A = new int[N];
    	B = new int[N];
    	C = new int[N];
    	dp = new int[D + 1][N];
    	for(int i = 0;i < D;i++){
    		T[i] = nextInt();
    	}

    	for(int i = 0;i < N;i++){
    		A[i] = nextInt();
    		B[i] = nextInt();
    		C[i] = nextInt();
    	}

    	for(int i = 0;i < D + 1;i++){
    		for(int j = 0;j < N;j++){
    			dp[i][j] = -1;
    		}
    	}
    	for(int i = 0;i < N;i++){
    		if(T[0] <= B[i] && T[0] >= A[i]){
    			dp[0][i] = 0;
    		}
    	}
    	for(int i = 1;i < D;i++){
    		for(int j = 0;j < N;j++){
    			for(int k = 0;k < N;k++){
    				if(dp[i - 1][j] >= 0){
    					if(T[i] <= B[k] && T[i] >= A[k]){
    						dp[i][k] = Math.max(dp[i][k],dp[i - 1][j] + Math.abs(C[j] - C[k]));
    					}
    				}
    			}
    		}
    	}
    	int ans = 0;
    	for(int i = 0;i < N;i++){
    		ans = Math.max(ans, dp[D - 1][i]);
    	}
    	out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 25600
/*author: hyperion_1724
  date: 
*/

//Required Libraries

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

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define veci vector<int>
#define vecl vector<long long>
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

	READV(N);
	READV(K);
	READAR(A,N);
	bool win[K+1];
	FORI(i,0,K+1)
	{
		win[i]=false;
	}
	FORI(i,0,K+1)
	{
		if (!win[i])
		{
			FORI(j,0,N)
			{
				if (i+A[j]<=K)
				{
					win[i+A[j]]=true;
				}
			}
		}
	}
	if (win[K])
	{
		cout<<"First"<<endl;
	}
	else
	{
		cout<<"Second"<<endl;
	}

	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int x = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
        if (-a + b <= 0) {
            System.out.println("delicious");
        } else if (-a + b <= x) {
            System.out.println("safe");
        } else{
            System.out.println("dangerous");
        }
    }
}

Measured memory_bytes: 21716
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	x := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x[i])
	}

	ans := "APPROVED"
	for i := 0; i < n; i++ {
		if x[i]%2 == 0 {
			if x[i]%3 != 0 && x[i]%5 != 0 {
				ans = "DENIED"
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<queue>
#include<set>
#include<unordered_map>
#include<stack>
#include<map>
#include<bitset>
#include <cstdlib>
#include<cstring>
#define ll long long;
#define pb push_back
const int MOD = 1e9 + 7;
const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
const double eps = 1e-11;
const double pi = acos(-1.0); 
const double PI = 3.1415926535897932384;
using namespace std;
#define ma = 2147483647;
#define mi = -2147483647;
int main()
{

	ios::sync_with_stdio(0); cin.tie(0);

	long double a, b, h, m;
	cin >> a >> b >> h >> m;

	double md = double( m) * 6.0;
	double hd = double(h) * 30.0 + (double(m) / 60.0 ) * 30.0;
	double de = md - hd;
	if (de < 0)de *= -1.0;
	if (de >= 180.0)
	de = 360.0 - de;
	double ans = sqrt(-2.0 * double(a) * double(b) * cos(de * PI / 180) + double(a) * double(a) + double(b) * double(b));

	//printf("%.20lf", ans);
	cout.precision(20);cout << ans;

	
	return 0;
}

Measured memory_bytes: 4236
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define FORl(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORDl(i, a, b) for (ll i = (a); i >= (b); i--)
using namespace std;
int num[200005];
int main () {
  int n;
  scanf("%d", &n);
  FOR(i, 1, n) {
    scanf("%d", &num[i]);
  }
  sort(num + 1, num + n + 1);
  ll ans = 0;
  FORD(i, n, n / 2 + 1) {
    if (i == n) ans += num[i];
    else if (i > n / 2 + 1) ans += num[i] * 2;
    else ans += num[i] * (1 + (~n & 1));
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 4608
from math import gcd
k = int(input())
s = 0
for x in range(1, k + 1):
    for y in range(1, k + 1):
        t = gcd(x, y)
        if t == 1:
            s += k
            continue
        for z in range(1, k + 1):
            s += gcd(t, z)
print(s)

Measured memory_bytes: 9176
#include <cstdlib>
#include <iostream>
#include <string>

int main() {
  int N;
  std::string A, B, C; std::cin >> N >> A >> B >> C;

  int num_ops = 0;
  for (int i = 0; i < N; ++i) {
    if (A[i] == B[i] && B[i] == C[i]) continue;
    else if (A[i] == B[i] ||
             B[i] == C[i] ||
             C[i] == A[i]) num_ops += 1;
    else num_ops += 2;
  }

  std::cout << num_ops << std::endl;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{

    int a, b;
    cin >> a >> b;

    cout << a * b << '\n';
    return 0;
}


Measured memory_bytes: 3620
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val p = readLine()!!.split(" ").map { it.toInt() }
    val q = readLine()!!.split(" ").map { it.toInt() }

    println(Math.abs(calculateIndex(p) - calculateIndex(q)))
}

private fun calculateIndex(numberArray: List<Int>): Int {
    val n = numberArray.size
    val array = IntArray(n) {it+1}.toMutableList()
    var index = 0
    for (i in 0 until n) {
        index += array.indexOf(numberArray[i]) * (factorial(numberArray.size - i - 1))
        array.remove(numberArray[i])
    }
    return index
}

private fun factorial(number: Int): Int {
    var ans = 1
    for (i in number downTo 1) {
        ans *= i
    }
    return ans
}

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


int main()
{
    string str;
    cin >> str;
    int q;
    cin >> q;
    for(int i = 0; i < q; ++i){
        string command;
        cin >> command;
        int a, b;
        cin >> a >> b;
        // cerr << command << endl;
        if(command == "replace"){
            string p;
            cin >> p;
            // cerr << "str:" << str << "p:" << p << endl;
            str.replace(a, b - a + 1, p);
        }else
        if(command == "reverse"){
            reverse(str.begin() + a, str.begin() + b + 1);
        }else{
            cout << str.substr(a, b - a + 1) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3228