akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
    ll n,a,b;cin>>n>>a>>b;
    if(b<a){cout<<0<<endl; return 0;}
    cout<<max(0ll,(n-2)*(b-a)+1)<<endl;
}

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

int main()
{
	int i, h;
	int mh[3] = {0};

	for(i=0;i<10;i++){

		cin>>h;
		if(0<=h && h<=10000)
		if(mh[0] < h){
			mh[2] = mh[1];
			mh[1] = mh[0];
			mh[0] = h;
		}
		else if(mh[1] < h){
			mh[2] = mh[1];
			mh[1] = h;
		}
		else if(mh[2] < h) mh[2] = h;

	}
	for(i=0;i<3;i++)	cout<<mh[i]<<endl;

	

	return 0;
}

Measured memory_bytes: 1164
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

template <class Weight>
struct edge {
  size_t src, dst;
  Weight cost;

  edge(size_t src, size_t dst, Weight cost=1):
    src(src), dst(dst), cost(cost)
  {}

  bool operator <(const edge<Weight> &rhs) const {
    if (cost != rhs.cost) return cost < rhs.cost;
    if (src != rhs.src) return src < rhs.src;
    return dst < rhs.dst;
  }
};

template <class Weight>
struct graph: public std::vector<std::vector<edge<Weight>>> {
  graph(size_t n): std::vector<std::vector<edge<Weight>>>(n) {}

  void connect_with(size_t src, size_t dst, Weight cost=1) {
    (*this)[src].emplace_back(src, dst, cost);
    (*this)[dst].emplace_back(dst, src, cost);
  }

  void connect_to(size_t src, size_t dst, Weight cost=1) {
    (*this)[src].emplace_back(src, dst, cost);
  }
};

template <class Tp>
constexpr Tp inf = (Tp(1) << (8*sizeof(Tp)-3));

template <class Weight>
std::vector<Weight> shortest(const graph<Weight>& g, size_t s) {
  // based-on Bellman-Ford algorithm
  size_t V = g.size();
  std::vector<Weight> res(V, inf<Weight>);
  res[s] = 0;

  for (size_t i = 1; i < V; ++i)
    for (size_t v = 0; v < V; ++v)
      for (const auto& e: g[v])
        if (res[e.dst] > res[e.src] + e.cost)
          res[e.dst] = res[e.src] + e.cost;

  for (size_t v = 0; v < V; ++v)
    for (const auto& e: g[v])
      if (res[e.dst] > res[e.src] + e.cost)
        res[e.dst] = -inf<Weight>;
  
  return res;
}

int main() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);

  graph<intmax_t> g(N);
  for (size_t i = 0; i < M; ++i) {
    size_t a, b;
    intmax_t c;
    scanf("%zu %zu %jd", &a, &b, &c);
    --a;
    --b;
    g.connect_to(a, b, -c);
  }

  intmax_t res = shortest(g, 0)[N-1];
  if (res == -inf<intmax_t>) return puts("inf"), 0;
  printf("%jd\n", -res);
}


Measured memory_bytes: 888
<?php
$n = (int)trim(fgets(STDIN));
$s = trim(fgets(STDIN));


$black_cnt = [0];
$white_cnt = [0];

// 累積和
for ($i=0; $i < $n; $i++) { 
	$tmp = $s[$i];
	if ($tmp === '#') {
		$black_cnt[$i+1] = $black_cnt[$i]+1;
		$white_cnt[$i+1] = $white_cnt[$i];
	}else{
		$black_cnt[$i+1] = $black_cnt[$i];
		$white_cnt[$i+1] = $white_cnt[$i]+1;
	}
}
$black_cnt[$n+1] = $black_cnt[$n];
$white_cnt[$n+1] = $white_cnt[$n];
// echo implode(' ', $white_cnt) . PHP_EOL;
// echo implode(' ', $black_cnt) . PHP_EOL;

$min = $n;
for ($i=0; $i <= $n; $i++) { 
	$tmp = $black_cnt[$i] - $black_cnt[0] + $white_cnt[$n+1] - $white_cnt[$i+1];
	$min = min($min, $tmp);
	// echo $min . PHP_EOL;
}
echo $min;

Measured memory_bytes: 23152
C=[list(map(int,input().split())) for i in range(3)]
for a1 in range(101):
  b1=C[0][0]-a1
  b2=C[0][1]-a1
  b3=C[0][2]-a1
  a2=C[1][0]-b1
  a3=C[2][0]-b1
  if b1>=0 and b2>=0 and b3>=0 and a2>=0 and a3>=0:
    if a2+b2==C[1][1]:
      if a2+b2==C[1][1]:
        if a2+b3==C[1][2]:
          if a3+b1==C[2][0]:
            if a3+b2==C[2][1]:
              if a3+b3==C[2][2]:
                print('Yes')
                exit()
print('No')



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vi vector <ll> 
#define qu queue <ll>
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e9;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


void solve()
{
    ll n, k; cin >> n >> k;
    ll a = n%k;
    nout(min(a,k-a));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3660
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, X = map(int, raw_input().split())
L = map(int, raw_input().split())
ans = 1
cur = 0
for num in L:
    cur += num
    if cur <= X:
        ans += 1
print ans

Measured memory_bytes: 2812
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long h = sc.NextLong();
        long w = sc.NextLong();
        long a = sc.NextLong();
        long b = sc.NextLong();

        for (int i = 0; i < h; i++)
        {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < w; j++)
            {
                if (i < b ^ j < a)
                {
                    sb.Append(0);
                }
                else
                {
                    sb.Append(1);
                }
            }
            Console.WriteLine(sb.ToString());
        }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 31808
# Handstand 2

N = int(input())
count = 0

count_list = [[0]*10 for i in range(10)]

# 1~Nまでの先頭iと末尾jの頻度を全て算出する
for a in range(1,N+1):
    a_str = str(a)
    a_i, a_j = int(a_str[0]), int(a_str[-1]) # 各数の先頭桁を求める
    count_list[a_i][a_j] = count_list[a_i][a_j] + 1

# count_listから全ての組み合わせ数を計算
for i in range(1,10):
    for j in range(1,10):
        count = count + count_list[i][j]*count_list[j][i]

print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<ll,int> P;

int main(){
    string s;
    cin >> s;
    vector<int> cnt(2,0);
    rep(i,s.size()){
        cnt[s[i] -'0']++;
    }
    cout << min(cnt[0], cnt[1])*2 << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    String[] S = sc.nextLine().split(" ");
    List<Integer> list = new ArrayList<>();
    for(int i = 0; i < N*2; i++){
      list.add(Integer.parseInt(S[i]));
    }
    
    Collections.sort(list);
    int ans = 0;
    for(int i = 0; i < N*2; i++){
      if(i%2 == 0){
        ans += list.get(i);
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22612
import sys

stdin = sys.stdin
 
ni = lambda:int(ns())
na = lambda:list(map(int,stdin.readline().split()))
ns = lambda:stdin.readline().rstrip()  # ignore trailing spaces

N, M = na()
S = ns()

answer = [] # 後ろからできるだけ遠くに行く
S = S[::-1]
cur = 0
while cur < N:
    for i in range(M, 0, -1):
        if cur+i <= N and S[cur+i] == '0':
            answer.append(i)
            cur += i
            break
    else:
        print(-1)
        exit()
print(*answer[::-1])

Measured memory_bytes: 6408
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
int N, K;
int A[5010] = {};
bool dp[5010][5010] = {}; // dp[i番目まで][和がちょうどj] = 可能？
bool necessary(int m){ // m番目を除いて[K-A[m], K)の値を作れるか？
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= K; j++){
            dp[i][j] = false;
        }
    }
    dp[0][0] = true;
    for(int i = 1; i <= N; i++){
        if(i == m){
            for(int j = 0; j < K; j++){
                dp[i][j] = dp[i-1][j];
            }
        }
        else{
            for(int j = 0; j < K; j++){
                if(dp[i-1][j]) {
                    dp[i][j] = true;
                    dp[i][min(j+A[i], K)] = true;
                }
            }
        }
    }
    bool ans = false;
    for(int a = max(K - A[m], 0); a < K; a++){
        if(dp[N][a]){ans = true;}
    }
    return ans;
}
int main() {
    cin >> N >> K;
    for(int i = 1; i <= N; i++){
        cin >> A[i];
    }
    sort(A, A+N+1);
    // a<bでaが必要かつbが不必要とすると矛盾．
    // aが属し，K<=(Sの元の和)<K+aなるSを1つとる．bがSの元のときはSそのものが，
    // bがSの元でないときはSからaを除きbを加えたものが反例．
    if(necessary(1)){cout << 0 << endl;}
    else if(!necessary(N)){cout << N << endl;}
    else{
        int L = 1, R = N;
        while(R - L > 1){
            int M = (L + R) / 2;
            if(necessary(M)){R = M;}
            else{L = M;}
        }
        cout << L << endl;
    }
}


Measured memory_bytes: 24704
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>	
#include <utility>
#include <cinttypes>
#include <string>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <deque>
using namespace std;

int main(){
    cout<<std::fixed<<setprecision(10);
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int n,m;
    long long sum = 0ll;
    vector<int> a;
    vector<pair<int,int>> bc;
    cin>>n;
    cin>>m;
    a.reserve(n);
    bc.reserve(m);
    for (int i=0;i<n;i++){
        int ai;
        cin>>ai;
        a.push_back(ai);
    }
    for (int i=0;i<m;i++){
        int bi,ci;
        cin>>bi;
        cin>>ci;
        bc.push_back(pair<int,int>(bi,ci));
    }
    sort(a.begin(),a.end());
    sort(bc.begin(),bc.end(),[](pair<int,int>p1, pair<int,int>p2) -> int { return ( p1.second > p2.second ); } );
    int start = 0;
    for (int i=0;i<m;i++){
        for (int j=0;j<bc[i].first;j++){
            if (a[start]<bc[i].second){
                sum += bc[i].second;
                start ++;
                if (start >= n){
                    goto finish;
                }
            } else {
                break;
            }
        }
    }
    for (int i=start;i<n;i++){
        sum += a[i];
    }
finish:
    cout<<sum<<"\n";
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		int[] kou = new int[120];
		for (int i = 0; i < 120; i++) {
			kou[i] = 0;
		}

		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		int n = Integer.parseInt(str);

		for (int i = 0; i < n; i++) {
			String line = sc.nextLine();
			String[] kari1 = line.split(" ");
			int[] kari2 = new int[4];
			for (int j = 0; j < 4; j++) {
				kari2[j] = Integer.parseInt(kari1[j]);
			}

			int number = (kari2[0] - 1) * 30 + (kari2[1] - 1) * 10
					+ (kari2[2] - 1);
			kou[number] += kari2[3];
		}

		for (int i = 0; i < 120; i++) {
			if (i == 119) {
				System.out.print(" ");
				System.out.println(kou[i]);
			} else if ((i + 1) % 30 == 0) {
				System.out.print(" ");
				System.out.println(kou[i]);
				System.out.println("####################");
			} else if ((i + 1) % 10 == 0) {
				System.out.print(" ");
				System.out.println(kou[i]);
			} else {
				System.out.print(" ");
				System.out.print(kou[i]);
			}
		}

	}
}

Measured memory_bytes: 26892
def solution():
    a, b, c, k = map(int, input().split())

    ans = 0
    diff = a - k
    if diff >= 0:
        print(k)
        return

    diffb = b - (-diff)
    if diffb >= 0:
        print(k-(-diff))
        return
    k = k-(-diff)

    print(k-(-diffb))

solution()


Measured memory_bytes: 61684
#include <bits/stdc++.h>
using namespace std;
const int N = 202, INF = 1000000009;

int dp[N][N][N];
bool cc[N][N][N];

int rec(int a, int b, int c)
{
    if (a >= N || b >= N || c >= N)
        return INF;
    if (cc[a][b][c])
        return dp[a][b][c];
    cc[a][b][c] = true;
    if (a == b && b == c)
    {
        return dp[a][b][c] = 0;
    }
    dp[a][b][c] = INF;
    dp[a][b][c] = min(dp[a][b][c], rec(a + 2, b, c) + 1);
    dp[a][b][c] = min(dp[a][b][c], rec(a, b + 2, c) + 1);
    dp[a][b][c] = min(dp[a][b][c], rec(a, b, c + 2) + 1);
    dp[a][b][c] = min(dp[a][b][c], rec(a + 1, b + 1, c) + 1);
    dp[a][b][c] = min(dp[a][b][c], rec(a + 1, b, c + 1) + 1);
    dp[a][b][c] = min(dp[a][b][c], rec(a, b + 1, c + 1) + 1);
    return dp[a][b][c];
}

int main()
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    printf("%d\n", rec(a, b, c));
    return 0;
}


Measured memory_bytes: 40448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

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

int h, w;
int sx, sy;
vector<string> s;
vector<vector<int>> steps;

void bfs() {
	queue<pint> q;
	steps[sy][sx] = 0;
	q.push({ sx,sy });
	while (!q.empty()) {
		pint it = q.front(); q.pop();
		int x = it.first;
		int y = it.second;
		for (int k = 0; k < 4; k++) {
			int nx = x + dx[k];
			int ny = y + dy[k];
			if (nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
			if (s[ny][nx] == '#') continue;
			if (steps[ny][nx] != INF32) continue;
			steps[ny][nx] = steps[y][x] + 1;
			q.emplace(nx, ny);
		}
	}
	return;
}

int main() {
	int K;
	cin >> h >> w >> K;
	s.resize(h);
	steps.resize(h);
	for (int i = 0; i < h; i++) {
		cin >> s[i];
		steps[i].resize(w, INF32);
	}
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (s[i][j] == 'S') sy = i, sx = j;
		}
	}

	bfs();
	set<pint> se;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (steps[i][j] <= K) se.insert({j, i});
		}
	}

	int ans = INF32;
	for (auto it : se) {
		int x = it.first;
		int y = it.second;
		int M = min(x, min(y, min(h-1 - y, w-1 - x)));
		ans = min(ans, (M + K - 1) / (K));
	}
	cout << ans+1 << endl;
	return 0;
}

Measured memory_bytes: 33024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String strThreeNum = br.readLine();
		Integer a = Integer.parseInt(strThreeNum.split(" ")[0]);
		Integer b = Integer.parseInt(strThreeNum.split(" ")[1]);
		Integer c = Integer.parseInt(strThreeNum.split(" ")[2]);
		if (a < b && b < c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 17012
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import collections
import math

#### START
A, B = map(int,input().split())
S = input()

if len(S) == A+B+1 and S[A] == "-" and len([ s for s in S if s in [ str(i) for i in range(10)]]) == A+B:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  vvll a(n, vll(n));
  REP(i, n) REP(j, n) cin >> a[i][j];
  vll dp(1LL<<n); dp[0] = 1;
  rep(S, 1, 1LL<<n) {
    ll i = __builtin_popcount(S);
    REP(j, n) if (((S>>j)&1)==1 && a[i-1][j]==1) dp[S] = (dp[S]+dp[S^(1LL<<j)]) % MOD;
  }
  cout << dp[(1LL<<n)-1] << endl;
  return 0;
}


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

int main(){
    int n; cin >> n;
    int ans = 0;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    for(int i = 0; i < n; i++){
        int mid; cin >> mid;
        a[i] = mid;
    }
    for(int i = 0; i < n; i++){
        int mid; cin >> mid;
        b[i] = mid;
    }
    for(int i = 0; i < n-1; i++){
        int mid; cin >> mid;
        c[i] = mid;
    }
    int d = 0;
    for(int i = 0; i < n; i++){
        if(a[i] == d+1){
            ans += c[d-1];
        }
        d = a[i];
        ans += b[d-1];
        //cout << ans << endl;
    }  
    cout << ans << endl;
}

Measured memory_bytes: 256
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
	int a,b,c;
	cin>>a>>b>>c;

	double S=0,L=0,h=0,d;

	d=(acos(-1.0)*c)/180.0;
	S=a*b*sin(d)/2.0;
	L=a+b+sqrt(a*a+b*b-2*a*b*cos(d));
	h=b*sin(d);

	printf("%lf\n%lf\n%lf\n",S,L,h);

	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main() {
    char s[3];
    cin >> s;

    int counter = 0, max_counter = 0;
    for (int i=0; i<3; i++) {
        if (s[i] == 'R') {
            counter++;
        } else {
            counter = 0;
        }
        if (max_counter <= counter) {
            max_counter = counter;
        }
    }
    cout << max_counter << endl;
}

Measured memory_bytes: 3196
#include<stdio.h>
#include<algorithm>
using namespace std;
#define NIL -1
#define MAX 100005

struct Node { int parent, left, right; };
struct Node T[MAX];
int D[MAX];

void setDepth(int u, int d) {
  D[u] = d;
  if (T[u].left != NIL) setDepth(T[u].left, d+1);
  if (T[u].right != NIL) setDepth(T[u].right, d);
}

void printChildren(int u) {
  int c = T[u].left;
  printf("[");
  if (c != NIL) {
    printf("%d", c);
    c = T[c].right;
  }
  while (c != NIL) {
    printf(", %d", c);
    c = T[c].right;
  }
  printf("]\n");
}

int main() {
	int n;
  scanf("%d", &n);
  for ( int i = 0; i < n; i++ ) {
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
  }
  int id, k;
  for ( int i = 0; i < n; i++ ) {
    scanf("%d %d", &id, &k);
    int c, oldc;
    for (int i = 0; i < k; i++) {
      scanf("%d", &c);
      if (i == 0) {
        T[id].left = c;
        T[c].parent = id;
        oldc = c;
      } else {
        T[oldc].right = c;
        T[oldc].parent = id;
        oldc = c;
        if (i == k-1) {
          T[oldc].parent = id;
        }
      }
    }
  }

  for ( int i = 0; i < n; i++ ) {
    if (T[i].parent == NIL) {
      setDepth(i, 0);
      break;
    }
  }

  for ( int i = 0; i < n; i++ ) {
    printf("node %d: parent = %d, depth = %d, ", i, T[i].parent, D[i]);
    if (T[i].parent == NIL) {
      printf("root, ");
    } else if (T[i].left == NIL) {
      printf("leaf, ");
    } else {
      printf("internal node, ");
    }
    printChildren(i);
  }

  return 0;
}



Measured memory_bytes: 4272
import sys

def mul4(v1, v2, v3, v4):
    return (v1 * v2) - (v3 * v4)

for i in sys.stdin:
    a, b, e, c, d, f = tuple(map(float, i.split()))
    det = mul4(a, d, c, b)
    print("{:.3f} {:.3f}".format(
        mul4(d, e, b, f) / det or 0.0,
        -mul4(c, e, a, f) / det or 0.0)
    )

Measured memory_bytes: 7248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,k;
	scanf("%lld %lld",&n,&k);
	n%=k;
	if(abs(n-k)<n) n=abs(n-k);
	printf("%lld",n);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{ll to,cost;};
const int inf = 1<<27;
const ll INF = 1LL<<60;
const int COMBMAX = 1001001;
const ll MOD = 1000000007;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (ll)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (ll)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
ll mpow(ll a, ll n, ll mod = MOD){ll res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void YesNo(bool j){cout << (j ? "Yes" : "No") << endl; return;}
void yesno(bool j){cout << (j ? "yes" : "no") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> ll bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);} 
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> void sortTwoVecter(vector<T1> &f, vector<T2> &s, bool isReverse = false){
    vector<pair<T1, T2>> p;
    rep(i, f.size()) p.emplace_back(make_pair(f[i], s[i]));
    if (!isReverse) sort(p.begin(), p.end());
    else sort(p.rbegin(), p.rend());
    rep(i, f.size()) tie(f[i], s[i]) = p[i];
    return;
}

ll f(ll n, ll m){
    while(n % m == 0) n /= m;
    return n;
}

int main(){
    ll N; cin >> N;
    if (N == 2){
         cout << 1 << endl;
         return 0; 
    }
    ll ans = 2;
    for(ll i = 2; i <= pow(N, 0.5); i++){
        if ((N - 1) % i == 0){
            ans++;
            if (i * i == N - 1) continue;
            ans++;
        }else if (N % i == 0){
            if (f(N, i) % i == 1) ans++;
            if (i * i == N) continue;
            if (f(N, (N / i)) % (N / i) == 1) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
import std.stdio;
import std.algorithm;
import std.string;
import std.array;
import std.functional;
import std.conv;
import std.math;

void main(){
    while(true){
	auto s = readln();
	if(stdin.eof()) break;
	int n = to!int(s.chomp());
	int[4001] arr;
	for(int i=0;i<=1000;i++){
	    for(int j=0;j<=1000;j++){
		arr[i+j]++;
	    }
	}
	int ans;
	for(int i=0;i<=n;i++){
	    ans += arr[i] * arr[n-i];
	}
	writeln(ans);
    }
}

Measured memory_bytes: 2500
# https://atcoder.jp/contests/abc087/tasks/arc090_a

import itertools
import collections
import bisect

def main():
    N = int(input())
    A1 = list(map(int, input().split()))
    A2 = list(map(int, input().split()))

    for i in range(N-1):
        A1[i+1] += A1[i]
    for i in range(N-1, 0, -1):
        A2[i-1] += A2[i]
    # print(A1)
    # print(A2)

    ans = 0
    for i in range(N):
        ans = max(ans, A1[i] + A2[i])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>
#include <math.h>
#include <algorithm>
#include <queue>
#include <map>
#include <list>
//#include <bits/stdc++.h>


using namespace std;

#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
typedef long long ll;

int main(){
    int a,b,c,d;
    cin >> a >> b >> c;
    (c-(a-b))>=0 ? d = (c-(a-b)) : d = 0 ;
    cout << d << endl;  
    return 0;
}

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

map<string, int> memo;

int main(void) {
    int n;

    scanf("%lld", &n);
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;

        memo[s] += 1;
    }int maxv = 0;
    for (const auto& x : memo) {
        int v = x.second;
        if (v > maxv) maxv = v;
    }
    for (auto it = memo.begin(); it != memo.end(); it++) {
        if (it -> second == maxv) {
            cout << it -> first << endl;
        }
    }

    return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int n;
    Scd(n);
    int a;
    int a2 = 0;
    int a4 = 0;
    int a1 = 0;
    Rep(i,n){
        Scd(a);
        if( a % 2 )
            a1++;
        else
        if( a % 4 )
            a2++;
        else
            a4++;
    }


    bool ans = true;

    ans = ( a1 <= a4+1 && !( a1 == a4+1 && a2 > 0 ));

    YesNo(ans);
    return 0;
}



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

ans = 0
for i in range(1, min(N, K)+1):
    for j in range(i+1):
        take_list = []
        for k in range(j):
            take_list.append(V[k])
        for k in range(1, i-j+1):
            take_list.append(V[-k])
        take_list.sort()
        for l in range(K-i):
            if len(take_list) >= 1:
                if take_list[0] < 0:
                    take_list.pop(0)
                else:
                    break
        ans = max(ans, sum(take_list))

print(ans)

Measured memory_bytes: 3064
n,y=map(int,input().split())

ans = False
for i in range(n+1):
    for j in range(n+1-i):
        if i*10000+j*5000+(n-i-j)*1000==y:
            a=i
            b=j
            c=n-i-j
            ans=True
if ans == True:
    print(a,b,c)
else:
    print('-1 -1 -1')

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <queue>
#include <time.h>

using namespace std;

#define INT_MAX 2147483647
typedef long long ll;

ll gcd(ll m, ll n);		//最大公倍数
ll lcm(ll m, ll n);		//最小公倍数

int main(void) {

	int ans = 0;
	int a, b, c;
	cin >> a >> b >> c;
	ans = a * b / 2;
	

	cout << ans << endl;

	return 0;

}

// 2番目から3要素だけ抜き出した部分文字列を取得する
//std::string result = s.substr(2, 3);  

#if 1
//最大公倍数
ll gcd(ll m, ll n)
{
	ll temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}
#endif

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root,NIL;

Node treeMinimum(Node x){
  while(x->left!=NIL)
    x=x->left;
      return x;
}

Node treeMaximum(Node x){
while(x->right!=NIL)
  x=x->right;
      return x;
}

Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key) u=u->left;
    else u=u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  if(x->right!=NIL)
    return treeMaximum(x->right);

 Node  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left==NIL || z->right==NIL) y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL) x=y->left;
  else x=y->right;

  if(x!=NIL) x->parent=y->parent;
  if(y->parent==NIL) root=x;
  else if (y==y->parent->left) y->parent->left=x;
  else y->parent->right=x;
  if(y!=z) z->key=y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key) x=x->left;
    else x=x->right;
  }
    z->parent=y;

    if(y==NIL) root=z;
    else if (z->key<y->key) y->left=z;
    else y->right=z;
  }

void inorder(Node u){
if(u==NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node u){
if(u==NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25208
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

      string s;
      cin >> s;
      rp(i,s.length()) if(s[i] == '9') {cout << "Yes"<<endl; return 0;}
      cout << "No"<<endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0

for a in range(0, A+1):
    for b in range(0, B+1):
        for c in range(0, C+1):
            total = (a*500)+(b*100)+(c*50) 
            if total == X:
                count = count + 1

print(count)
            
    

Measured memory_bytes: 3060
s = list(input())
flag = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == 'L':
            print('No')
            flag = 1
    else:
        if s[i] == 'R':
            print('No')
            flag = 1
    if flag == 1:
        break
if flag == 0:
    print('Yes')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int INF=1e9;
int main(){
	int N;cin>>N;
	if(N==1){ cout<<"Yes"<<endl; return 0; }
	int H[N];
	rep(i,0,N) cin>>H[i];
	for(int i=N-2;i>=0;i--){
		if(H[i]<=H[i+1]) continue;
		else if(H[i]==H[i+1]+1) H[i]--;
		else{ cout<<"No"<<endl; return 0; }
	}cout<<"Yes"<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<atcoder/fenwicktree>
using namespace std;
using namespace atcoder;
int main(){
    int n, q;
    cin >> n >> q;
    fenwick_tree<long long> a(n);
    for(int i = 0; i < n; i++){
        int p;
        cin >> p;
        a.add(i,p);
    }
    for(int i = 0; i < q; i++){
        int t;
        cin >> t;
        if(t == 0){
            int p, x;
            cin >> p >> x;
            a.add(p, x);
        }
        else{
            int l, r;
            cin >> l >> r;
            cout << (long long) a.sum(l, r) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 8204
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Program{
    static void Main(string[] args){
      string s = Console.ReadLine();
      string ans;
      switch (s) {
        case "A":
          ans = "T";
          break;
        case "T":
          ans = "A";
          break;
        case "G":
          ans = "C";
          break;
        case "C":
          ans = "G";
          break;
        default:
          throw new ArgumentException();
      }
      Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;



int main(void){
    string s;
    cin>>s;
    stack<char>st;
    int n =s.length();
    for(int i=0;i<n;i++){
        if(s[i]=='S')st.push(s[i]);
        else{
            if(st.empty())st.push(s[i]);
            else{
                char t = st.top();
                if(t=='T')st.push(s[i]);
                else st.pop();
            }
        }
    }
    string ans ="";
    while(!st.empty()){
        char t = st.top();
        st.pop();
        ans.push_back(t);
    }
    reverse(ans.begin(),ans.end());
    cout<<ans.size()<<endl;
    return 0;
}


Measured memory_bytes: 1028
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
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(){
  string T; cin >> T;
  int N = sz(T);
  rep(i,N){
    if(T[i]=='?'){T[i]='D';
    }
  }
  cout << T << endl;
  return 0;
}


Measured memory_bytes: 3756
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) < *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
	uint64_t result = 1;

	for (uint64_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

#define UF_ROOT ((size_t)1000000)

static size_t uf[100000];
static size_t treeSize[100000];
static size_t A[100000], B[100000];
static uint64_t count[100000];

static size_t getRoot(size_t i) {
	if (uf[i] == UF_ROOT) {
		return i;
	}

	const size_t root = getRoot(uf[i]);

	uf[i] = root;

	return root;
}

static bool hasSameRoot(const size_t a, const size_t b, size_t * const aRoot, size_t * const bRoot) {
	*aRoot = getRoot(a);
	*bRoot = getRoot(b);

	return *aRoot == *bRoot;
}

static bool addEdge(const size_t a, const size_t b, size_t unifiedTreeOrgSize[2])
{
	size_t aRoot, bRoot;
	
	if (hasSameRoot(a, b, &aRoot, &bRoot)) {
		return false;
	}

	uf[aRoot] = bRoot;

	unifiedTreeOrgSize[0] = treeSize[aRoot];
	unifiedTreeOrgSize[1] = treeSize[bRoot];

	treeSize[bRoot] += treeSize[aRoot];
	treeSize[aRoot] = 0;

	return true;
}

static uint64_t countInc(const size_t N) {
	uint64_t count = (uint64_t)N * ((uint64_t)N - 1) / 2;

	for (size_t i = 0; i < N; i++) {
		if (uf[i] == UF_ROOT) {
			count -= (uint64_t)(treeSize[i])*((uint64_t)(treeSize[i] - 1)) / 2;
		}
	}

	return count;
}

int main(void) {
	size_t N, M;

	scanf("%zu %zu\n", &N, &M);
	for (size_t i = 0; i < M; i++) {
		scanf("%zu %zu", &A[i], &B[i]);
		if (i < M - 1) {
			scanf("\n");
		}

		A[i]--;
		B[i]--;
	}

	for (size_t i = 0; i < N; i++) {
		uf[i] = UF_ROOT;
		treeSize[i] = 1;
	}

	size_t prevTreeSize[2] = { 1, 1 };
	bool unified = false;

	for (size_t i = 0; i < M; i++) {
		if (i == 0) {
			count[M - i - 1] = (uint64_t)N * ((uint64_t)N - 1) / 2;
		}
		else {
			count[M - i - 1] = count[M - i];

			if (unified) {
				count[M - i - 1] = count[M - i - 1] + combU64((uint64_t)(prevTreeSize[0]), 2) + combU64((uint64_t)(prevTreeSize[1]), 2) - combU64((uint64_t)(prevTreeSize[0] + prevTreeSize[1]), 2);
			}
		}

		unified = addEdge(A[M - i - 1], B[M - i - 1], prevTreeSize);
	}

	for (size_t i = 0; i < M; i++) {
		printf("%"PRIu64"\n", count[i]);
	}

	return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 5200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int n, m;
ll d[maxn];
int a[maxn][maxn];
ll tag[maxn][maxn];
inline void add(int x0,int x1,int y0,int y1,int v) {
	tag[x0][y0] += v;
	tag[x1 + 1][y0] -= v;
	tag[x0][y1 + 1] -= v;
	tag[x1 + 1][y1 + 1] += v;
}
int st[15][maxn];
inline void solve(int * a) {
	const auto max = [&](int x,int y) {
		return a[x] > a[y] ? x : y;
	};
	const auto rgmx = [&](int x,int y) {
		const int lg = std::__lg(y - x + 1);
		return max(st[lg][x], st[lg][y - (1 << lg) + 1]);
	};
	std::function<void(int, int)> solve = [&](int l,int r) {
		if(l > r) return ;
		int o = rgmx(l, r);
		solve(l, o - 1);
		solve(o + 1, r);
		add(l, o, o, r, a[o]);
	};
	rep(i, 1, n) st[0][i] = i;
	rep(i, 1, 14) for(int j = 1;j + (1 << i) - 1 <= n;++j) {
		st[i][j] = max(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
	}
	solve(1, n);
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	rep(i, 2, n) cin >> d[i], d[i] += d[i - 1];
	rep(i, 1, n) rep(j, 1, m) cin >> a[j][i];
	rep(j, 1, m) solve(a[j]);
	ll ans = 0;
	rep(i, 1, n) rep(j, 1, n) {
		tag[i][j] += tag[i - 1][j] + tag[i][j - 1] - tag[i - 1][j - 1];
	}
	rep(i, 1, n) rep(j, i, n) {
		ans = std::max(ans, tag[i][j] + d[i] - d[j]);
	}
	cout << ans << '\n';
}


Measured memory_bytes: 211200
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
vll arr(55556);
vll pr(0);
ll n;
void Eratosthenes(){
	for(ll i = 2; i < 55556; i++){
		arr[i] = 1;
	}
	for(int i = 2; i < sqrt(55556); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) < 55556; j++){
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for(int i = 2; i < 55556; i++){
		if(arr[i]){
			pr.pb(i);//cout << i << endl;
		}
	}
}
int main(){
  cin>>n;
  Eratosthenes();
  vll ans(0);
  ll cu=0;
  rep(i,sz(pr)){
    if(sz(ans)==n) break;
    if(pr[i]%5==1){
      ans.pb(pr[i]);
    }
  }
  rep(i,n) cout<<ans[i]<<" ";
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;

  if(a + b >= c){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl; 
  }
 
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) throws Exception{    
        Scanner sc = new Scanner(System.in);
        // code
       
        String s = sc.next();
        
        char c = s.charAt(0);
        
        String ans;
        if(c == 'a'){
        	ans = "vowel";
        }else  if(c == 'i'){
        	ans = "vowel";
        }else  if(c == 'u'){
        	ans = "vowel";
        }else  if(c == 'e'){
        	ans = "vowel";
        }else  if(c == 'o'){
        	ans = "vowel";
        }else{
        	ans = "consonant";
        }
        
        System.out.println(ans);
        
        sc.close();
    }
    
    
    
    
 
}

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


int main(){


    int n, i, p;

    string s;

    vector< pair< string, int > > w;

    map< pair< string, int >, int > mp;


    cin >> n;


    for( i = 1 ; i <= n ; i = i + 1 ){

         cin >> s >> p;

         w.push_back( pair< string , int >( s, -p ) );

         mp[ w.at(i - 1) ]  = i;

         }


    sort( w.begin(), w.end() );


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

         cout << mp[ w.at(i) ] << endl;

         }


    return 0;

    }


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

using namespace std;

int main() {
    double n, m, d;
    cin >> n >> m >> d;
    cout << setprecision(12) << fixed << (d == 0 ? 1 : 2) * (m - 1) * (n - d) / (n * n) << endl;
}


Measured memory_bytes: 3768
//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    static long TIME_START, TIME_END;
    public static void main(String[] args) throws IOException {
        MyScanner sc = new MyScanner(System.in);
//        MyScanner sc = new MyScanner(new FileInputStream("Test.in"));
        PrintWriter pw = new PrintWriter(System.out);
        TIME_START = System.currentTimeMillis();
        Task.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
//        pw.println("Time used: " + (TIME_END - TIME_START) + ".");
        pw.close();
    }

    public static class Task {

        public static void solve(MyScanner sc, PrintWriter pw) throws IOException {
            int n = sc.nextInt();
            int count2 = 0;
            int count1 = 0;
            for (int i = 0; i < n; i++) {
                int a = sc.nextInt();
                if (a % 4 == 0) count2++;
                else if (a % 2 == 0) count1++;
            }
            if (count2 >= n / 2) {
                pw.println("Yes");
            } else {
                int rest = n - (count2 * 2);
                if (count1 >= rest) {
                    pw.println("Yes");
                } else {
                    pw.println("No");
                }
            }
        }
    }

    static class MyScanner {
        StringTokenizer st;
        BufferedReader br;

        public MyScanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public MyScanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(s);}

        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {return br.readLine();}

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

        public boolean ready() throws IOException {return br.ready();}
    }
}


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

Measured memory_bytes: 256
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

a,b,c,d=map(int,input().split())
a-=1
b_1=b//c
b_1+=b//d
b_1-=b//lcm(c,d)
a_1=a//c
a_1+=a//d
a_1-=a//lcm(c,d)
print((b-b_1)-(a-a_1))

Measured memory_bytes: 38384
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();
		
		String im[]=new String[h];
		for (int i = 0; i < h; i++) {
			im[i]=sc.next();
		}
	    
		for (int i = 0; i < h; i++) {
			System.out.println(im[i]);
			System.out.println(im[i]);
		}
}
}

Measured memory_bytes: 12020