akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;

int n, k, a[100000];
ll cnt, mncnt, mn, mxcnt, mx;

int main() {
	cin >> n >> k;
	cnt = 0;
	lp(n) {
		cin >> a[i];
		cnt += max(a[i], 0);
	}
	mncnt = mxcnt = 0;
	lp(k) {
		mncnt += max(0, a[i]);
		mxcnt -= min(0, a[i]);
	}
	mn = min(mncnt, mxcnt);
	lp(n - k) {
		mncnt -= max(0, a[i]);
		mncnt += max(0, a[i + k]);
		mxcnt += min(0, a[i]);
		mxcnt -= min(0, a[i + k]);
		mn = min({ mn,mncnt,mxcnt });
	}
	cout << cnt - mn << endl;
	return 0;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list( map(int, input().split()))
b = list( map(int, input().split()))

sa = sum(a)
sb = sum(b)

al = sb-sa

if al<0:
    print('No')
    exit()

doub = 0
sing = 0

for i in range(n):
    diff = b[i]-a[i]
    if diff > 0:
        doub += -(-diff//2)
        sing += diff%2
    if diff < 0:
        sing += -diff

dnokori = al - doub
snokori = al - sing

if dnokori < 0 or snokori<0:
    print('No')
    exit()

if dnokori==0 and snokori==0:
    print('Yes')
    exit()

if dnokori==0:
    print('No')
    exit()

if snokori/dnokori == 2:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 4596
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;

class arc091_b {
public:
    void solve(istream& in, ostream& out) {
        int N, K;
        in >> N >> K;
        long long res = 0;
        if (K == 0) {
            res = 1LL * N * N;
        } else {
            for (int b = K + 1; b <= N; ++b) {
                for (int a = K; a <= N; a += b) {
                    if (a + b - K <= N)
                        res += b - K;
                    else
                        res += N - a + 1;
                }
            }
        }
        
        out << res << "\n";
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	arc091_b solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <sstream>
#include <algorithm>

#define INF 10000000

int n, m, st, gl, money, pole;
int roads[21][21];
int in[4];
std::string input;

int check( int start, int goal ){
	int cost[21];
	int used = 0;

	std::fill( cost, cost + 21, INF );
	cost[start] = 0;

	while(1){
		int v = -1;
		for( int i = 1; i <= n; i++ ){
			if( !(used & 1 << i ) && (v == -1 || cost[i] < cost[v]) ) v = i;
		}

		if( v == -1 )break;

		used = used | 1 << v;

		for( int i = 1; i <= n; ++i ){
			cost[i] = std::min( cost[i], cost[v] + roads[v][i] );
		}
	}

	return cost[goal];
}

int main(){
	for( int i = 0; i < 21; ++i )
		std::fill( roads[i], roads[i] + 21, INF );

	std::cin >> n >> m;

	for( int i = 0; i < m; ++i ){
		std::cin >> input;

		sscanf( input.c_str(), "%d,%d,%d,%d", in, &in[1], &in[2], &in[3] );

		roads[ in[0] ][ in[1] ] = in[2];
		roads[ in[1] ][ in[0] ] = in[3];
	}

	std::cin >> input;
	sscanf( input.c_str(), "%d,%d,%d,%d", &st, &gl, &money, &pole );

	money -= pole;

	int cost = check( st, gl );
	cost += check( gl, st );

	std::cout << money - cost << std::endl;
}

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

using namespace std;

int main()
{
    int r,c,n,i = 0;
    cin>>r>>c>>n;
    i = n/max(r,c);
    if(n%max(r,c) == 0)
    cout<<i;
    else
    cout<<i+1;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ii pair<int, int>
#define N 300123
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define pb push_back
#define fs first
#define sc second
#define oo 1000000123
#define sz(x) ((int)((x).size()))
#define OUT -oo
#define left(x) (x << 1)
#define right(x) ((x << 1) | 1)
#define mid(a, b) ((a + b) >> 1)

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    ll ans = 0, x;
    cin >> x;
    for(ll i = 1; i <= x; ++i){
        if(!(i % 3 ==0) && !(i % 5 == 0)) ans += i;
    }
    cout << ans << '\n';
    return 0;
}


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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000001;
using namespace std;
typedef long long ll;

int n,t,a;
int h[10000];

int main(){

  std::cin >> n >> t >> a;
  float res = MAX;
  int res_ans;
  rep(i,1,n+1){
    std::cin >> h[i];
    float temp = t-(h[i]*0.006);
    if(abs(a - temp) < res){
      res = abs(temp - a);
      res_ans = i;
    }
  }
  std::cout << res_ans << '\n';
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int Q;
  while (cin >> Q) {
    const int MAX = 100100;
    vector<int> isp(MAX, true);
    isp[0] = isp[1] = false;
    for (int p = 2; p * p < MAX; p++) {
      if (!isp[p]) continue;
      for (int kp = p * p; kp < MAX; kp += p) isp[kp] = false;
    }
    vector<int> sum(MAX + 1, 0);
    for (int i = 0; i < MAX; i++) {
      sum[i + 1] = sum[i];
      if (i % 2 == 1 && isp[i] && isp[(i + 1) / 2]) {
        ++sum[i + 1];
      }
    }
    for (int i = 0; i < Q; i++) {
      int l, r;
      cin >> l >> r;
      cout << sum[r + 1] - sum[l] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1408
/* Filename: AGC006B.java
 * Author: Mushiyo
 */

import java.util.Scanner;
import java.util.Arrays;

public class Main{

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

		while (input.hasNext()) {
			int N = input.nextInt();
			int x = input.nextInt();
			int rowNLen = 2 * N - 1;

			if (x == 1 || x == rowNLen) {
				System.out.println("No");
			} else {
				int[] ans = new int[rowNLen + 1];
				for (int i = 0; i < ans.length; ++i) {
					ans[i] = i;
				}

				int mid = N;
				int tmp = ans[mid];
				ans[mid] = x;
				ans[x] = tmp;
				//System.out.println(Arrays.toString(ans));

				tmp = ans[mid - 1];
				ans[mid - 1] = rowNLen;
				ans[rowNLen] = tmp;
				//System.out.println(Arrays.toString(ans));

				if (ans[mid + 1] != 1) {
					tmp = ans[mid + 1];
					ans[mid + 1] = 1;
					ans[1] = tmp;
				}
				//System.out.println(Arrays.toString(ans));
				System.out.println("Yes");
				StringBuilder ansOut = new StringBuilder();
				for (int i = 1; i < ans.length; ++i) {
					ansOut.append(String.format("%d\n", ans[i]));
				}
				System.out.print(ansOut);
			}
		}
	}
}


Measured memory_bytes: 96572
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  vector<int> v;
  for(int i=1;i<=N;i++){
    for(int j=5;j<=55555;j++){
      if(IsPrime(j) && j%5==1){
        v.push_back(j);
      }
    }
  }
  for(int i=0;i<N;i++){
    if(i==0){
      cout << v[i];
      continue;
    }
    cout << ' ' << v[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define all(v) (v).begin(),(v).end()
#define pb push_back
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

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


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

main() {
  int a, b, sum, remainder, product, quotient;
  char op;

  
  while(1) {

    scanf("%d %c %d", &a, &op, &b);

    if ( op == '?') break;
    if ( op == '+') {
      sum = a + b;
      printf("%d\n", sum);
    } else if ( op == '-') {
      remainder = a - b;
      printf("%d\n", remainder);
    } else if ( op == '*') {
      product = a * b;
      printf("%d\n", product);
    } else if ( op == '/') {
      quotient = a / b;
      printf("%d\n", quotient);
    } else break;

  }

  return 0;
}

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

using namespace std;

int main() {
  int x;
  cin >> x;

  for (int i = 600; i <= 2000; i += 200) {
    if (x < i) {
      cout << 11 - i / 200 << '\n';
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 3596
N, A, B, K = map(int, input().split())
mod = 998244353

# 階乗 & 逆元計算
factorial = [1]
inverse = [1]
for i in range(1, N+2):
    factorial.append(factorial[-1] * i % mod)
    inverse.append(pow(factorial[-1], mod-2, mod))


# 組み合わせ計算
def nCr(n, r):
    if n < r or r < 0:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % mod


ans = 0
for x in range(N+1):
    y = (K-A*x) / B
    if y == int(y):
        ans += nCr(N, x) * nCr(N, int(y)) % mod

print(ans % mod)


Measured memory_bytes: 81264
N, M = [int(_) for _ in input().split()]
H = [int(_) for _ in input().split()]

g = [True for _ in range(N)]
for _ in range(M):
    a, b = [int(_)-1 for _ in input().split()]
    if(H[a] <= H[b]):
        g[a] = False
    if(H[b] <= H[a]):
        g[b] = False
ans = g.count(True)
print(ans)


Measured memory_bytes: 20120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _0032
{
    class Program
    {
        static void Main(string[] args)
        {
            int choho = 0;
            int hishi = 0;
            string input;
            while ((input = Console.ReadLine())!= null)
            {
                int[] lines = input.Split(',').Select(int.Parse).ToArray();
                if (lines[0] == lines[1])
                    ++hishi;
                else if (Math.Pow(lines[0], 2) + Math.Pow(lines[1], 2) == Math.Pow(lines[2], 2))
                    ++choho;
            }
            Console.WriteLine(choho);
            Console.WriteLine(hishi);
        }
    }
}



Measured memory_bytes: 18400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

bool is_prime[100010];
int cum[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  for (int i = 2; i <= 100000; i++) {
    is_prime[i] = true;
    for (int j = 2; (ll)j * j <= i; j++) {
      if (i % j == 0) is_prime[i] = false;
    }
  }
  for (int i = 3; i <= 100000; i++) {
    if (is_prime[i] && is_prime[(i + 1) / 2]) {
      cum[i] = 1;
    }
  }
  for (int i = 1; i <= 100000; i++) {
    cum[i] += cum[i - 1];
  }

  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    cout << cum[r] - cum[l - 1] << endl;
  }

  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <deque>

using namespace std;

int main(void) {
    int H, W, Ch, Cw, Dh, Dw;
    cin >> H >> W;
    cin >> Ch >> Cw;
    cin >> Dh >> Dw;
    Ch--; Cw--; Dh--; Dw--;
    vector<string> S(H);
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }

    const int INF=1e9;
    const int di[] = {-1, 0, 1, 0};
    const int dj[] = {0, 1, 0, -1};

    vector<vector<int>> dist(H, vector<int>(W, INF));
    deque<pair<int, int>> q;
    dist[Ch][Cw]=0;
    q.emplace_back(Ch, Cw);
    while(!q.empty()) {
        int i = q.front().first;
        int j = q.front().second;
        int d = dist[i][j];
        q.pop_front();
        for (int m = 0; m < 4; m++) {
            int ni = i + di[m];
            int nj = j + dj[m];
            if (ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
            if (S[ni][nj] == '#') continue;
            if (dist[ni][nj] <= d) continue;
            dist[ni][nj] = d;
            q.emplace_front(ni, nj);
        }
        for (int m = -2; m <=2; m++) {
            for (int n = -2; n <= 2; n++) {
                int ni = i + m;
                int nj = j + n;
                if (ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
                if (S[ni][nj] == '#') continue;
                if (dist[ni][nj] <= d+1) continue;
                dist[ni][nj] = d + 1;
                q.emplace_back(ni, nj);
            }
        }
    }
    
    cout << (dist[Dh][Dw] == INF ? -1 : dist[Dh][Dw]) << endl;
    return 0;
}

Measured memory_bytes: 9572
fun main() = Thread(null, ::abc172c, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

fun abc172c() = SimpleFastIO().exec {
    val (n, m, k) = readLine().split(' ').map { it.toInt() }
    val aList = readLine().split(' ').map { it.toLong() }
    val bList = readLine().split(' ').map { it.toLong() }

    var takeB = m
    var timeSumA = 0L
    var timeSumB = bList.sum()
    var answer = 0

    for (takeA in 0..n) {
        while (timeSumA + timeSumB > k && takeB > 0) {
            timeSumB -= bList[takeB - 1]
            takeB--
        }

        if (timeSumA + takeB > k) break

        answer = Math.max(answer, takeA + takeB)

        if (takeA in aList.indices) timeSumA += aList[takeA]
    }

    println(answer)
}

@Suppress("unused", "HasPlatformType")
class SimpleFastIO {
    private val br: java.io.BufferedReader = System.`in`.bufferedReader()
    private val sb: StringBuilder = StringBuilder()
    fun readLine() = br.readLine()!!
    fun println() = sb.appendln()
    fun print(any: Any) = sb.append(any)
    fun println(any: Any) = sb.appendln(any)
    fun <T> print(any: Iterable<T>, separator: String) = sb.append(any.joinToString(separator))
    fun <T> println(any: Iterable<T>, separator: String) = sb.appendln(any.joinToString(separator))
    fun exec(action: SimpleFastIO.() -> Unit) = run { action() }.run { kotlin.io.println(sb) }
}


Measured memory_bytes: 85444
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  deque<int> dq;
  REP(i, n){
    string s; cin >> s;
    if(s == "insert"){
      int i; cin >> i;
      dq.push_front(i);
    }else if(s == "delete"){
      int d; cin >> d;
      auto itr = dq.begin();
      while(itr != dq.end()){
        if(*itr == d){
          dq.erase(itr);
          break;
        }else{
          itr++;
        }
      }
    }else if(s == "deleteFirst"){
      dq.pop_front();
    }else if(s == "deleteLast"){
      dq.pop_back();
    }
  }
  while(!dq.empty()){
    cout << dq.front();
    dq.pop_front();
    if(!dq.empty()){
      cout << " ";
    }else{
      cout << endl;
    }
  }
}


Measured memory_bytes: 7056
n, m = gets.chomp.split.map(&:to_i)

if n == 1 && m == 1
  p 1
elsif n == 1 || m == 1
  if n == 1
    p m - 2
  else
    p n - 2
  end
else
  p (n-2) * (m-2)
end


Measured memory_bytes: 1788
#!/usr/bin/env python3
import sys


def solve(N: int, S: "List[str]"):
    ret = 0
    a = 0
    b = 0
    ab = 0
    for s in S:
        i = 0
        for i in range(len(s) - 1):
            if s[i:i+2] == 'AB':
                ret += 1
        if s[0] == 'B':
            a += 1
        if s[-1] == 'A':
            b += 1
        if s[0] == 'B' and s[-1] == 'A':
            ab += 1
    ret += min(a, b)
    if a > 0 and a == b and a == ab:
        ret -= 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3696
#include "stdio.h"
#include "math.h"

#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=x && x<w && 0<=y && y<h)

const int INF = 10000000;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;

/** Problem1277 : Minimal Backgammon (途中)**/
char board[110];
int N, T, L, B;
double dp[110][110];

int main()
{
	while (cin>>N>>T>>L>>B, N||T||L||B) {
		fill(board, board+110, ' ');
		fill(dp[0], dp[0]+110*110, 0.0);
		
		rep(k, L) {
			int x; cin >> x;
			board[x] = 'L';
		}
		
		rep(k, B) {
			int x; cin >> x;
			board[x] = 'B';
		}
		
		dp[0][0] = 1.0;
		
		rep(t, T) {
			rep(n, N) {
				REP(i, 1, 7) {
					if (dp[t][n]==0) continue;
					
					int nn = n+i;
					if (nn>N) nn=N-(nn-N);
					if (board[nn]=='B') nn=0;
					dp[t+1+(board[nn]=='L')][nn] += dp[t][n] * (1.0/6.0);
				}
			}
		}
		
		double ans=0;
		rep(i, T+1) {
			ans+=dp[i][N];
		}
		printf("%.6f\n", ans);
	}
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define int long long
using namespace std;

int dp[2][2010];
bool vst[2][2010];

int depth = 0;

int dfs(int idx, int player, int Z, int W, const vector<int> &a) {
	if(idx == a.size()) {
		return abs(Z - W);
	}
	if(vst[player][idx]) {
		return dp[player][idx];
	}
	depth++;
	vst[player][idx] = true;
	int ops = 1 - player;
	int res = dfs(idx + 1, ops, W, a[idx], a);
	for(int i = idx; i < a.size(); ++i) {
		int tmp = dfs(i + 1, ops, W, a[i], a);
		if(player) {
			res = min(res, tmp);
		} else {
			res = max(res, tmp);
		}
	}
	depth--;
	// cout << string(depth, ' ') << player << "," << idx << "," << Z << "," << W << "," << res << endl;
	return dp[player][idx] = res;
}

signed main(){
	int N, Z, W;
	cin >> N >> Z >> W;
	vector<int> a(N);
	for(int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	dfs(0, 0, Z, W, a);
	cout << dp[0][0] << endl;
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef pair<int,int> pii;

signed main(void) {
  int i,j;
  int n,k;
  cin>>n>>k;
  vi a(n);
  a[0]=0;
  rep(i,n)cin>>a[i];
  vi pos(n);
  pos=a;
  if(pos[0]<0)pos[0]=0;
  rep(i,n-1)pos[i+1]=pos[i]+max(a[i+1],0LL);
  rep(i,n-1)a[i+1]+=a[i];

  int ans=0;
  rep(i,n+1-k){
    int tmp;
    if(i==0){
      tmp=max(a[i+k-1],0LL);
      tmp+=pos[n-1]-pos[i+k-1];
    }else if(i==n-k){
      tmp=max(a[n-1]-a[i-1],0LL);
      tmp+=pos[i-1];
    }else{
      tmp=max(a[i+k-1]-a[i-1],0LL);
      tmp+=pos[i-1];
      tmp+=pos[n-1]-pos[i+k-1];
    }
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
N, W = map(int, input().split())
value = []
weight = []

for _ in range(N):
    v, w = map(int, input().split())
    value.append(v)
    weight.append(w)

#初期化
inf = float("inf")
dp = [[-inf for i in range(W+1)] for j in range(N+1)]
for i in range(W+1):
    dp[0][i] = 0

#DP
for i in range(N):
    for w in range(W+1):
        if weight[i] <= w:
            dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]

print(dp[N][W])



Measured memory_bytes: 42484
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;

public class Main {
	public static void main(String[] args) {
		FastReader r = new FastReader();		
		String str = r.str();		
		print(str.substring(str.indexOf('A'), str.lastIndexOf('Z')).length()+1);
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}
	
	public static void rolling(long[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}
	
	public static String al(String s) {
		return s + "\n";
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		int ri() {
			return Integer.parseInt(str());
		}

		long rl() {
			return Long.parseLong(str());
		}

		double rd() {
			return Double.parseDouble(str());
		}

		String str() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		String[] rsa() {
			return str().split(" ");
		}

		int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		}

		long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		}

		char[] rca() {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		}
		
		String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		}

		int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		}

		long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		}
	}
}

class Node {
	public int val;
	public boolean visited;
	public Node(int v) { val=v; }
}

Measured memory_bytes: 25300
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<sstream>


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

#define PII pair<int,int>
#define PP pair< int,PII >


using namespace std;

int N[256][4];
int ans[256];
int used[256][4];

int main(){
	
	int n;
	scanf("%d", &n);
	rep(i,n)rep(j,3){scanf("%d", &N[i][j]);used[N[i][j]][j]++;}
	
	rep(i,n)rep(j,3)if(used[N[i][j]][j] == 1)ans[i]+=N[i][j];
	rep(i,n)printf("%d\n", ans[i]);
	return 0;
}

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

namespace PrimeNumber
{
    class Program
    {
        static void Main(string[] args)
        {

            var input = Console.ReadLine();
            long readNumber = int.Parse(input);
            bool isPrimeNumber = false;
            
            while(isPrimeNumber == false)
            {
                CountPrimeNumber(ref readNumber, ref isPrimeNumber);
            }

            Console.WriteLine(readNumber);                                 
        }

        static void CountPrimeNumber(ref long broughtNumber, ref bool isPrimeNumber)
        {
            isPrimeNumber = true;
            for (int i = 2; i < Math.Sqrt(broughtNumber); i++)
            {
                long primeNumber = broughtNumber % i;
                if (primeNumber == 0)
                {                    
                    isPrimeNumber = false;
                    broughtNumber++;
                    break;
                }                                
            }            
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main(void){
    ll q,h,s,d,n,ans=0;cin>>q>>h>>s>>d>>n;
    ll l1=min(q*4,min(q*2+h,min(h*2,s)));
    ll l2=min(d,l1*2);
    ans+=(n/2)*l2;n%=2;
    ans+=n*l1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
typedef long long ll;
const ll mod = 1e9+7;
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

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

    int n, m; cin >> n >> m;
    vector<int> broken(n, 0);
    rep(i, m) {
        int a; cin >> a;
        broken[a] = 1;
    }

    vector<int> dp(n+2);
    dp[n] = 1;
    for(int i = n-1; i >= 0; --i) {
        if(broken[i]) {
            dp[i] = 0;
            continue;
        } else {
            dp[i] = (dp[i+1] + dp[i+2])%mod;
        }
    }
    cout << dp[0] << endl;
    return 0;
}


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

using namespace std;

int main()
{
    long long int l,r,counter,counter_1;
    cin>>l>>r;
    if(r-l>=2019)
       {cout<<0<<endl;return 0;}
    else
    {
        counter=((l%2019)*((l+1)%2019))%2019;
        for(int i=l;i<r;i++)
        {
            for(int j=i+1;j<=r;j++)
            {
               counter_1=((i%2019)*(j%2019))%2019;
               if(counter_1<counter)
                  counter=counter_1;
            }
        }
    }
    cout<<counter<<endl;
    return 0;
}


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

int main(){
  multimap<string,int> Index;
  string s;
  int val;
  vector<int> thisisit;
  while(cin  >> s >> val){
    Index.insert(multimap<string,int>::value_type(s,val));
  }
 


  multimap<string,int>::iterator it = Index.begin();
  while(it != Index.end()){
    cout << it->first << endl;
    thisisit.clear();
    int fin = Index.count(it->first);
    for(int i=0;i<fin;i++,it++){
      thisisit.push_back(it->second);
    }
    partial_sort(thisisit.begin(),thisisit.begin()+fin,thisisit.end());
    for(int i=0;i<fin;i++){
      cout << thisisit[i];
      if(i != fin-1)cout << " "; 
    } 
   cout << endl;

  }





  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <climits>
using namespace std;
 
int n, m;
int *d, *c, *memo;
 
int rec(int machi, int nichi) {
	if(machi > nichi) return INT_MAX;
	if(machi == 0) return 0;
	if(memo[machi + nichi * n] != -1) return memo[machi + nichi * n];
	int a = rec(machi - 1, nichi - 1) + d[n - machi] * c[m - nichi];
	int b = rec(machi, nichi - 1);
	return memo[machi + nichi * n] = a > b ? b : a;
}
 
int main() {
	cin >> n >> m;
	d = new int[n];
	for(int i = 0; i < n; i++){
		cin >> d[i];
	}
	c = new int[m];
	for(int i = 0; i < m; i++){
		cin >> c[i];
	}
	memo = new int[n + m * n + 1];
	for(int i = 0; i < n + m * n + 1; i++){
		memo[i] = -1;
	}
	cout << rec(n, m) << endl;
}

Measured memory_bytes: 4392
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      string s;
      int a,b;
      cin >> a >> s >> b;
      
      if(s=="+"){
        cout << a+b <<endl;
      }else if(s=="-"){
        cout << a-b <<endl;
      }
        
    }

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define INF 9000000000000000000
#define ff first
#define ss second
#define mod 1000000007
#define endl "\n"
#define BS binary_search

int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int tc=1;
    //cin>>tc;
    while(tc--){
        int x;cin>>x;
        int y=1999-x;
        cout<<y/200+1<<endl;
    }
}


Measured memory_bytes: 3628
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

for i in range(n):
  if (i == 0):
    ans =b[a[0] - 1]
    y = a[0]
  else:
    x = a[i]
    if (x - y == 1):
      ans = ans + b[x - 1] + c[y - 1]
    else:
      ans = ans + b[x - 1]
    y = x

print(ans)


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

int main()
{
    string s;
    cin >> s;
    s.at(3) = '8';
    cout << s << "\n";
    return 0;
}


Measured memory_bytes: 256
# https://qiita.com/skcvim/items/9eed47f5483679fa66b1
# 行数
N, K = map(int, input().split())
A = [input().split()]
i = 1
while N-K > 0:
    N = N-K +1
    i = i+1

print(i)


    # if N != K:
    #     N = N-K-1
    #     i = i+1
    # else:
    #     N = N-K
    #     i = i-1

# if N == K:
#      print(1)
# elif N - K <= N/2 :
#     print(2)
# else:
#     print(N-K-1)

# 8 2
# 5
#
# 8 3
# 4
#
# 8 4
# 3
#
# 8 5
# 2
#
# 8 6
# 2
# 8 7

# 7 2
# 4
#
# 7 3
#


Measured memory_bytes: 10420
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b);

int main(void){
    int n;
    scanf("%d",&n);
    int d[n];
    for(int i = 0;i < n;i++){
        scanf("%d",&d[i]);
    }
    qsort(d, n, sizeof(int), compare_int);
    
    if (d[(n/2)-1] == d[n/2]){
        printf("0");
    } else {
        printf("%d",d[n/2] - d[(n/2)-1]);
    }
}

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

Measured memory_bytes: 892
# -*- coding: utf-8 -*-
import collections

def prime_factorize(ln):
    la = []
    while ln % 2 == 0:
        la.append(2)
        ln //= 2
    lf = 3
    while lf * lf <= ln:
        if ln % lf == 0:
            la.append(lf)
            ln //= lf
        else:
            lf += 2
    if ln != 1:
        la.append(ln)
    return la


n = int(input())
pf_n = prime_factorize(n)
count_pf_n = collections.Counter(pf_n)
result = 0
#print(count_pf_n)
for ci in count_pf_n.items():
#    print("key: " + str(ci[0]))
    num_ci = ci[1]
    for j in range(1, 9):
        if num_ci < j:
#            print("num: " + str(j-1))
            break
        num_ci -= j
        result += 1

print(result)

Measured memory_bytes: 65836
#include <iostream>

using namespace std;

int N;
int a[100005];

int cnt4, cnt2;

int main(void)
{
	cin >> N;
	for(int i = 1; i <= N; i++) cin >> a[i];
	
	for(int i = 1; i <= N; i++){
		if(a[i] % 4 == 0) cnt4++;
		else if(a[i] % 2 == 0) cnt2++;
	}
	
	if(cnt2 < 1) cnt2 = 1;
	if(N-1 <= 2 * cnt4 + (cnt2 - 1)) cout << "Yes" << endl;
	else cout << "No" << endl;
	
}

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

typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i += 2) {
        int count = 0;
        for (int j = 1; j <= i; ++j) {
            if (i % j == 0) count++;
        }
        if (count == 8) ans++;
    }
    cout << ans;
    return 0;
}


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

long long n, k, ans=1;

int main() {
    cin >> n >> k;
    for (int i=k; i<n+k; i++) {
        ans = (ans * i) % 1000000007;
    }
    for (int i=2; i<n+1; i++) {
        int u = 1000000005;
        long long f[31];
        f[0] = i;
        for (int j=0; u>0; j++){
            if (u%2 == 1) ans = (ans * f[j])%1000000007;
            u/=2;
            f[j+1] = (f[j]*f[j])%1000000007;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdio>

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define each(it,c) for(__typeof(c.begin()) it=c.begin(); it!=c.end(); it++)
#define INF 1<<30
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int, int> > vp;
typedef map<int,int> mpii;
typedef priority_queue<int, vi, greater<int> > pqi;

typedef long long ll;

int main(){
	int n,l; cin>>n>>l;
	vector<ll> a(n);
	vi b;
	ll su = 0;
	rep(i,n){
		cin>>a[i];
		su+=a[i];
	}
	int x=0;
	int y=n-1;
	int ma;
	bool f = false;
	rep(i,n-1){
		if(a[i]+a[i+1] >= l){
			ma = i;
			f = true;
		}
	}
	if(f){
		cout<<"Possible"<<endl;
		rep(i,n-1){
			if(i==ma){
				for(int j=n-1;j>ma+1;j--){
					cout<<j<<endl;
				}
				cout<<ma+1<<endl;
				return 0;
			}
			cout<<i+1<<endl;
		}
	}
	else{
		cout<<"Impossible"<<endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
int n, l[5000];

int pn(int il, int ir, int x) {
	int ans = il - 1;
	while (il <= ir) {
		int m = (il + ir) / 2;
		if (l[m] < x) {
			ans = m;
			il = m + 1;
		}
		else ir = m - 1;
	}
	return ans;
}
int main() {
	cin >> n; for (int i = 1; i <= n; ++i) cin >> l[i];
	sort(l + 1, l + n + 1);
	int ans = 0;
	for (int i=1; i<=n; ++i)
		for (int j = i + 1; j <= n; ++j) {
			int k = pn(j + 1, n, l[i] + l[j]);
			ans += k - j;
		}
	cout << ans;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> pii;
typedef  pair<int,string> pis;
double pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lop(i,n)   for(int i=0;i<int(n);i++)
#define rep(i,a,b) for(int i=a;i<=int(b);++i)
#define rng(i,a,b) for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define F          first
#define S          second       //  __builtin_popcount;
//freopen("output.txt","w",stdout),freopen("input.txt","r",stdin);
const ll M  = 1e9+7 ;
const int N = 300100;
const int inf = INT_MAX;
const double eps = 1e-7;
//////////////////////    Hi    ^_^  hack me if you can :P
 
int a[100];
int n, p;
int s;
ll mem[55][2];
ll dp ( int i, int s)
{
    if ( i == n) return s%2 == p;
    ll &r = mem[i][s%2];
    if (r!=-1)
    {
        return r;
    }
    return r = dp(i+1,(s+a[i])%2 )+dp(i+1,s%2);
}
int main()
{
    speed;
    cin >> n >> p;
    lop(i,n) cin >> a[i];
    ms(mem,-1);
    cout << dp(0,0);
 
    return 0;
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[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;
  }
}

ll nCk(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll nPk(ll n, ll k) {
  if (n == 0 || k == 0) return 1;
  return fac[n] * finv[n - k] % MOD;
}
class mint {
  long long x;

 public:
  mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint& a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint& a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint& a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint& a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint& a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint& a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint& a) { return (*this) *= a.inv(); }
  mint operator/(const mint& a) const {
    mint res(*this);
    return res /= a;
  }

  friend ostream& operator<<(ostream& os, const mint& m) {
    os << m.x;
    return os;
  }
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
int m;
COMinit();
cin>>n>>m;
mint ans=0;
ans+=(nPk(n,n)*nPk(m,m)%MOD);
if(n==m){
    ans*=2;
}
else if(abs(n-m)>1){
    ans=0;
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 123188
N,Q = list(map(int, input().split()))
S = list(input())
l = []
r = []
for _ in range(Q):
    L,R = list(map(int, input().split()))
    l.append(L)
    r.append(R)
flag = False
ac = [0]*N
count = 0

for j in range(N):
        if S[j] == 'A':
            flag = True
            ac[j] = count
            continue
        if S[j] == 'C' and flag:
            count += 1
        ac[j] = count
        flag = False


for i in range(Q):
    print(ac[r[i]-1]-ac[l[i]-1])


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

const int N = 102;
int a[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n,k;
	cin>>n>>k;
	for(int i=0;i<k;i++){
		int t;
		cin>>t;
		while(t--){
			int x;
			cin>>x;
			a[x]++;
		}
	}
	
	int ans = 0;
	for(int i=1;i<=n;i++){
		if(!a[i])ans++;
	}
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define LL long long
#define endl '\n'
using namespace std;

static const int MAX = 100;
static const int long long INFTY = (1LL << 32);

int n;
LL d[MAX][MAX];

void floyd()
{
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            if (d[i][k] == INFTY) {  // d[i][k]は通らないのでスキップ
                continue;
            }
            for (int j = 0; j < n; j++) {
                if (d[k][j] == INFTY) {  // d[k][j]を通らないのでスキップ
                    continue;
                }
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);  // (i, j)への経路(前回までは最短)と,(i, k)->(k, j)を比較する
            }
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int e, u, v, c;
    cin >> n >> e;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            d[i][j] = ((i == j)? 0 : INFTY);
        }
    }

    for (int i = 0; i < e; i++) {
        cin >> u >> v >> c;
        d[u][v] = c;
    }

    floyd();

    bool negative = false;
    for (int i = 0; i < n; i++) {
        if (d[i][i] < 0) {
            negative = true;
        }
    }

    if (negative) {
        cout << "NEGATIVE CYCLE" << endl;
    } else {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (j) cout << " ";
                if (d[i][j] == INFTY) {
                    cout << "INF";
                } else {
                    cout << d[i][j];
                }
            }
            cout << endl;
        }
    }

    return 0;
}


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

#define pb push_back
#define fst first
#define snd second
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(ll i=x;i<y;i++)
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll;
using namespace std;
const int nM = 100+10;
const int wM = 1e5+10;
ll arr[nM][wM];
int weights[nM];
ll vs[nM];

ll ks(int n,int w){
    if(arr[n][w] != -1) return arr[n][w];
    if(n == 0 || w == 0) return 0;
    else if(weights[n] > w) return ks(n-1,w);
    else {
        ll tmp1 = ks(n-1,w);
        ll tmp2 = vs[n] + ks(n-1,w-weights[n]);
        arr[n][w] = max(tmp1,tmp2);
        return arr[n][w];
    }
}

int main() {FIN;
    int n, w;
    cin >> n >> w;
    weights[0] = 0, vs[0] = 0;
    fore(i,1,n+1) cin >> weights[i] >> vs[i];
    fore(i,0,n+1) fore(j,0,w+1) arr[i][j] = -1;
    cout << ks(n,w);
    return 0;
}


Measured memory_bytes: 80128
#include<stdio.h>

int main(){
  int x,y,z,s,k,cnt=0;
  scanf("%d %d",&k,&s);
  for(int i=0;i<=k;i++){
    if(s-i<=2*k)
      for(int j=0;j<=k;j++)
        if(s-(i+j)<=k&&s-(i+j)>=0)
          cnt++;
  }
  printf("%d\n",cnt);
}

Measured memory_bytes: 128
MOD = 998244353
import collections
N = int(input())
D = list(map(int, input().split()))
mx = max(D)
c = collections.Counter(D)

if D[0] == 0 and c[0] == 1:
    ans = 1
    for i in range(1, mx+1):
        if i not in c:
            ans = 0
            break
        else:
            ans *= (c[i-1] ** c[i]) % MOD
            ans %= MOD
else:
    ans = 0

print(ans)


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


using namespace std;


main() {
	long long n, mi, n1, ma;
	cin >> n;
	n1 = n;
	vector<long long> a(n);
	for (long long i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	mi = a[0];
	ma = a[n - 1];
	vector<pair<long long, long long> > op;
	while (n1 > 2) {
		if (a[n - n1 + 1] > 0) {
			op.push_back({mi, a[n - n1 + 1]});
			mi -= a[n - n1 + 1];
		}
		else {
			op.push_back({ma, a[n - n1 + 1]});
			ma -= a[n - n1 + 1];
		}
		n1--;
	}
	if (ma - mi > mi - ma) {
		cout << ma - mi << "\n";
		for (pair<long long, long long> i: op) {
			cout << i.first << " " << i.second << "\n";
		}
		cout << ma << " " << mi;
	}
	else {
		cout << mi - ma << "\n";
		for (pair<long long, long long> i: op) {
			cout << i.first << " " << i.second << "\n";
		}
		cout << mi << " " << ma;
	}
}

Measured memory_bytes: 4336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,int>;
using T = tuple<string,int,int>;

int main(){
  int h,w; cin >> h >> w;
  if(h == 1 || w == 1){
    cout << 1 << endl;
    return 0;
  }
  ll ans = (w+1)/2;
  ans *= (h+1)/2;
  ll temp = w/2;
  temp *= h/2;
  ans += temp;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (d, time, speed) = getInts()
    println(
            if (time * speed >= d) "Yes"
            else "No"
    )
}

fun getInt() = readLine()!!.toInt()
fun getInts() = readLine()!!.split(" ").map { it.toInt() }

Measured memory_bytes: 36528
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <tuple>
#include <queue>
#define PII pair<int, int>
#define T3I tuple<int, int, int>
using namespace std;

typedef long long ll;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;

ll C(vector<ll> &A, ll mid)
{
    ll res = 0;
    ll n = A.size();
    for(int i = 0; i < n-1; ++i) {
        ll l = i+1, h = n-1;
        ll m = (l+h)>>1;
        //cout << i << ": " << res << endl;
        if(A[i] < 0) {
            while(h-l > 1) {
                if(A[i]*A[m] <= mid) {
                    h = m;
                }else {
                    l = m;
                }
                m = (l+h)>>1;
            }
            if(A[i]*A[l] <= mid) {
                res += n-1-i;
            }else if(A[i]*A[h] > mid) {
                continue;
            }else {
                res += n-h;
            }
        }else {
            while(h-l > 1) {
                if(A[i]*A[m] <= mid) {
                    l = m;
                }else {
                    h = m;
                }
                m = (l+h)>>1;
            }
            if(A[i]*A[l] > mid) {
                continue;
            }else if(A[i]*A[h] <= mid) {
                res += n-1-i;
            }else {
                res += l-i;
            }
        }
    }
    return res;
}

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

    ll n, k;
    cin >> n >> k;
    vector<ll> A(n);
    for(int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    ll l = (-1e18)-1, h = (1e18)+1;
    ll m = (l+h)>>1;
    while(h-l > 1) {
        //cout << m << "  " << C(A, m) << endl;
        if(C(A, m) < k) {
            l = m;
        }else {
            h = m;
        }
        m = (l+h)>>1;
    }
    cout << h << endl;
}


Measured memory_bytes: 1792
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, _] <- getIntList
    as <- getIntList
    print $ max (n - (sum as)) (-1) 

Measured memory_bytes: 4780
#include <stdio.h>
int main(void){
    int A, B, sum;
    scanf("%d %d", &A, &B);
    if(A>B){
        sum=2*A-1;
        printf("%d\n", sum);
    }
    else if(A<B){
        sum=2*B-1;
        printf("%d\n", sum);    
    }
    else {
        sum=A+B;
        printf("%d\n", sum);
    }
return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

string A[55],B[55];
int N,M;
int main () {
    cin >> N >> M;
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<M; i++) cin >> B[i];

    if( M > N ) {
        cout << "No" << endl;
        return 0;
    }
    for(int i=0; i<=N-M; i++) {
        for(int j=0; j<=N-M; j++) {
            bool flag = true;

            for(int k=0; k<M; k++) {
                for(int m=0; m<M; m++) {
                    if( A[k+i][m+j] != B[k][m] ) flag = false;
                }
            }
            if( flag ) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256