akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

using P = pair<i64, i64>;
using T = pair<i64, P>;
signed main() {
  while (true) {
    i64 w, h;
    cin >> w >> h;
    if (w == 0) break;
    vector<vector<string>> field(h, vector<string>(w));
    vector<vector<i64>> left(h, vector<i64>(w, inf<i64>));
    vector<vector<i64>> right(h, vector<i64>(w, inf<i64>));
    priority_queue<T, vector<T>, greater<T>> que;
    REP(i, h) {
      REP(j, w) {
        cin >> field[i][j];
        if (field[i][j] == "S") {
          que.push({0, {i, j}});
          left[i][j] = 0;
          right[i][j] = 0;
        }
      }
    }
    vector<pair<i64, i64>> RIGHT({
      {-2,1},
      {-1,1},{-1,2},
      {0,1},{0,2},{0,3},
      {1,1},{1,2},
      {2,1},
    });
    vector<pair<i64, i64>> LEFT({
      {-2,-1},
      {-1,-1},{-1,-2},
      {0,-1},{0,-2},{0,-3},
      {1,-1},{1,-2},
      {2,-1},
    });
    while (que.size()) {
      i64 c, i, j;
      c = que.top().first;
      i = que.top().second.first;
      j = que.top().second.second;
      que.pop();
      for (P d : RIGHT) {
        i64 ii = i + d.first;
        i64 jj = j + d.second;
        if (0 <= ii && ii < h && 0 <= jj && jj < w) {
          if ("0" <= field[ii][jj] && field[ii][jj] <= "9") {
            i64 d = field[ii][jj][0] - '0';
            if (right[ii][jj] > left[i][j] + d) {
              right[ii][jj] = left[i][j] + d;
              que.push({right[ii][jj], {ii, jj}});
            }
          } else if (field[ii][jj] == "T") {
            if (right[ii][jj] > left[i][j]) {
              right[ii][jj] = left[i][j];
            }
          }
        }
      }
      for (P d : LEFT) {
        i64 ii = i + d.first;
        i64 jj = j + d.second;
        if (0 <= ii && ii < h && 0 <= jj && jj < w) {
          if ("0" <= field[ii][jj] && field[ii][jj] <= "9") {
            i64 d = field[ii][jj][0] - '0';
            if (left[ii][jj] > right[i][j] + d) {
              left[ii][jj] = right[i][j] + d;
              que.push({left[ii][jj], {ii, jj}});
            }
          } else if (field[ii][jj] == "T") {
            if (left[ii][jj] > right[i][j]) {
              left[ii][jj] = right[i][j];
            }
          }
        }
      }
    }
    i64 ans = inf<i64>;
    REP(i, h) {
      REP(j, w) {
        if (field[i][j] == "T") {
          ans = min({ans, left[i][j], right[i][j]});
          // cout << i << ", " << j << ": " << left[i][j] << ", " << right[i][j] << endl;
        }
      }
    }
    cout << (ans == inf<i64> ? -1 : ans) << endl;
  }
}



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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b > c + d) {
      cout << "Left" << endl;
  }
  else if (a + b < c + d) {
      cout << "Right" << endl;
  }
  else {
      cout << "Balanced" << endl;
  }
}

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

int main ()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans=0;
    if (k>a)
    {
        ans+=min(a,k);
        k-=a;
        if (k>b)
        {
            k-=b;
            ans-=k;
        }        
    }
    else
    {
        ans+=min(a,k);
    }
    cout<<ans<<endl;

	//test cases
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<algorithm>
using namespace std;
int dp[210000];
int d[11][11];
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<b;i++)for(int j=0;j<a;j++)scanf("%d",&d[i][j]);
	
	int now=c;
	for(int i=0;i<b-1;i++){
		for(int j=0;j<210000;j++)dp[j]=-99999999;
		dp[0]=0;
		int to=now;
	
		for(int k=0;k<a;k++){
			for(int j=0;j<=now;j++){
				dp[j+d[i][k]]=max(dp[j+d[i][k]],dp[j]+d[i+1][k]);
			}
		}
		for(int j=0;j<=now;j++)to=max(to,dp[j]+now-j);
		now=to;
	}
	printf("%d\n",now);
}


Measured memory_bytes: 3576
n = int(input())
p = list(map(int,input().split()))
pp = sorted(p)
def f(n,p,pp):
    flag =0
    for i in range(n):
        if p[i] != pp[i]:
            if flag == 2:
                return("NO")           
            else:
                flag += 1
    return("YES")
print(f(n,p,pp))

Measured memory_bytes: 3060
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000
const int mod = INF+7;

int main(){
  int N;
  cin >> N;
  vector<int> B(N-1);
  rep(i,N-1){
    cin >> B[i];
  }
  vector<int> A(N);
  A[N-1]=B[N-2];
  for(int i=N-2; i>0; i--){
    A[i]=min(B[i-1], B[i]);
  }
  A[0]=B[0];

  int sum=0;
  rep(i,N){
    sum+=A[i];
  }

  printf("%d\n", sum);
}


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

typedef long long ll;

int main() {
    string S, T;
    cin >> S >> T;
    int ans = 1e9;
    rep(i, S.size() - T.size() + 1) {
        int change = 0;
        rep(j, T.size()) {
            if (S[i + j] != T[j]) change++;
        }
        ans = min(ans, change);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main(){

	int table[31];

	int youbi = 5;
	for(int day = 1; day <= 30; day++){
		table[day] = youbi;
		youbi++;
		if(youbi == 8)youbi = 1;
	}

	int X;
	scanf("%d",&X);

	switch(table[X]){
	case 1:
		printf("mon\n");
		break;
	case 2:
		printf("tue\n");
		break;
	case 3:
		printf("wed\n");
		break;
	case 4:
		printf("thu\n");
		break;
	case 5:
		printf("fri\n");
		break;
	case 6:
		printf("sat\n");
		break;
	case 7:
		printf("sun\n");
		break;
	}

	return 0;
}

Measured memory_bytes: 3148
#include<iostream>
#include<stdio.h>
#include<string.h>
#define N 320
using namespace std;
int g[N],a[N][N],f[N],l[N];
int n,m;
int check(int x){
	memset(g,0,sizeof(g));
	int tot=m;
	for(int i=1;i<=n;i++)l[i]=1;
	while(tot){
		memset(f,0,sizeof(f));
		for(int i=1;i<=n;i++)f[a[i][l[i]]]++;
		int flag=1;
		for(int i=1;i<=m;i++)if(f[i]>x)g[i]=1,tot--,flag=0;
		for(int i=1;i<=n;i++)while(g[a[i][l[i]]])l[i]++;
		if(flag)return true;
	}
	return false;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)scanf("%d",&a[i][j]);
	int l=1,r=n;
	check(1);
	while(r-l>3){
		int mid=(l+r)/2;
		if(check(mid))r=mid;
		else l=mid+1;
	}
	for(int i=l;i<=r;i++){
		if(check(i)){
			printf("%d\n",i);
			return 0;
		}
	}
}

Measured memory_bytes: 640
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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


fn main() {
    input! {
        n: usize,
        k: usize,
        p: [usize; n],
    }

    let mut m = 0.0 as f64;
    let mut ans = 0.0 as f64;

    for (i, j) in p.iter().enumerate() {
        if i >= k {
            m -= (1 + p[i - k]) as f64 / 2.0;
        }
        m += (1 + p[i]) as f64 / 2.0;
        ans = ans.max(m);
    }
    println!("{:.9}", ans);
}


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

int main(){
  constexpr char block= '#';
  int H,W;
  cin >> H >> W;

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

  vector<vector<int>> dp(H, vector<int>(W));
  dp.at(0).at(0)= (data.at(0).at(0)==block) ? 1
                                            : 0;
  for(int j=1; j<W; j++){
    dp.at(0).at(j)= (data.at(0).at(j)==block && data.at(0).at(j-1) != block) ? dp.at(0).at(j-1)+ 1
                                                                             : dp.at(0).at(j-1);
  }
  for(int i=1; i<H; i++){
    dp.at(i).at(0)= (data.at(i).at(0)==block && data.at(i-1).at(0) != block) ? dp.at(i-1).at(0)+ 1
                                                                             : dp.at(i-1).at(0);
  }

  for(int i=1; i<H; i++){
    for(int j=1; j<W; j++){
      int diff_x= (data.at(i).at(j)==block && data.at(i-1).at(j) != block) ? 1
                                                                           : 0;

      int diff_y= (data.at(i).at(j)==block && data.at(i).at(j-1) != block) ? 1
                                                                           : 0;

      dp.at(i).at(j)= min(dp.at(i-1).at(j)+ diff_x, dp.at(i).at(j-1)+ diff_y);
    }
  }
  
  cout << dp.back().back() << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc057.contest.atcoder.jp/tasks/abc057_c>
問題文============================================================
 整数 N が与えられます。
 ここで、2 つの正の整数 A,B に対して、
 F(A,B) を「10 進表記における、A の桁数と B の桁数のうち大きい方」と定義します。
 例えば、F(3,11) の値は、3 は 1 桁、11 は 2 桁であるため、F(3,11)=2 となります。
 2 つの正の整数の組 (A,B) が N=A×B を満たすように動くとき、F(A,B) の最小値を求めてください。
=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    int ans = INF;
    for(ll A = 1; A*A <= N; A++){
        if(N%A == 0){
            ll B = N/A;
            ans = min(ans,max((int)to_string(A).length(),(int)to_string(B).length()));
        }
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

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

    int ans = 0;
    while (true) {
        S.pop_back(); ans += 1;
        if (S.size() % 2 != 0) continue;
        if (S.substr(0, S.size()/2) == S.substr(S.size()/2, S.size())) break;
    }
    cout << S.size() << endl;
}

Measured memory_bytes: 256
n = int(input())
data = input().split()
print(" ".join(data))
for i in range(1, n):
    j = i - 1
    data = list(map(int, data))
    while j >= 0 and data[j] >data[j+1]:
        data[j], data[j+1] = data[j+1], data[j]
        j -= 1
    print(" ".join(map(str, data)))



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

int main() {
  int N,M;
  cin >> N;
  vector<string> SN(N);
  for (int i=0; i<N; i++){
    cin >> SN.at(i);
  }
  cin >> M;
  vector<string> SM(M);
  for (int i=0; i<M; i++){
    cin >> SM.at(i);
  }
  int Amax=0;
  int Achk=0;
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if( SN.at(i)==SN.at(j) ){
        Achk++;
        //cout << SN.at(j) << Achk << endl;
      }
    }
    for(int j=0; j<M; j++){
      if( SN.at(i)==SM.at(j) ){
        Achk--;
      }
    }
    if(Amax<Achk) Amax=Achk;
    Achk=0;
  }
  cout << Amax << endl;
  return 0;
}


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

int main() {
	int A;
	long long B, N;
	cin >> A >> B >> N;

	if (N < B) {
		cout << static_cast<long long>(A * N / B);
	}
	else {
		cout << static_cast<long long>(A * (B - 1) / B);
	}

	return 0;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
int n,k;
int dist[200005];
int c;
int ans=-1;
int main(){
	//freopen("input.txt","r",stdin);
	cin>>k>>n;
	c=k;
	for(int i=1;i<=n;i++) cin>>dist[i];
	sort(dist+1,dist+n+1);
	for(int i=1;i<=n-1;i++){
		ans=max(ans,dist[i+1]-dist[i]);
	}
	ans=max(ans,c-dist[n]+dist[1]); //n是double不能当作index 
	cout<<c-ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
import sys
from bisect import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
L = sorted(map(int, input().split()))

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        ans += bisect_right(L, L[i] + L[j] - 1, j + 1) - j - 1
print(ans)

Measured memory_bytes: 43868
#include<iostream>
#include<string>
using namespace std;
int main(){

  int n, a, sum=0;
  cin >> n;
  int m;
  m = n;
  while(m>0){
    a = m % 10;
    m = m / 10;
    sum = sum + a;
  }

  if(n%sum==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define ll long long
#define mod 1000000007
using namespace std;

int main(){

  int n, i = 0;
  string s[2];
  cin >> n >> s[0] >> s[1];
  ll ans;
  for(int i = 0; i < s[0].size(); i++){
    if(!i){
      if(s[0][i] != s[1][i]) ans = 6, i++;
      else ans = 3;
    }else{
      if(s[0][i] != s[1][i]){
        if(s[0][i-1] != s[1][i-1]) ans = (ans * 3) % mod;
        else ans = (ans * 2) % mod;
        i++;
      }else{
        if(s[0][i-1] == s[1][i-1]) ans = (ans * 2) % mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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


def solve(K: int, N: int, A: "List[int]"):
    max = K - A[N-1] + A[0]
    for i in range(N-1):
        p = A[i+1] - A[i]
        if p > max:
            max = p
    print(K-max)

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

if __name__ == '__main__':
    main()


Measured memory_bytes: 26228
# -*- coding: utf-8 -*-
"""
Created on Sat Sep  8 18:33:41 2018
ABC109B
@author: maezawa
"""
import collections
n = int(input())
words = []
for i in range(n):
    words.append(input())

samew = collections.Counter(words)
sn = sorted(samew.values())
if sn[0] != 1 or len(set(sn)) != 1:
    print('No')
else:
    ans = 'Yes'
    for i in range(n-1):
        if words[i][-1] == words[i+1][0]:
            continue
        else:
            ans = 'No'
            break
    print(ans)
        

Measured memory_bytes: 3572
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc054.contest.atcoder.jp/tasks/abc054_d>
問題文============================================================
 イルカは、微量の物質Cを生成したいと考えています。
 物質Cを生成するためには、タイプAの物質とタイプBの物質の混合比が Ma:Mb となる溶液を用意する必要があります。
 しかし、イルカは薬品を1つも持っていないため、薬局へ薬品を買いに行くことにしました。
 薬局では、N 種類の薬品を取り扱っており、各薬品 i の在庫はちょうど1つです。
 各薬品 i は、タイプAの物質 ai グラム、タイプBの物質 bi グラム含んでおり、価格 ci 円で売られています。
 イルカは、いくつかの薬品を薬局で買います。買った薬品は全て使わなければなりません。
 物質Cを生成するために、必要な最小予算を求めてください。
 薬局で売られている薬品の組み合わせで、物質Cを生成できない場合はそれを報告してください。
=================================================================

解説=============================================================

================================================================
*/

#define MAX_N 40
#define MAX_AB 10
// 40 * 400 * 400 = 4^3 * 10^5
int dp[MAX_N+1][MAX_N*MAX_AB+1][MAX_N*MAX_AB+1];
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    int N,Ma,Mb; cin >> N >> Ma >> Mb;
    vector<int> a(N),b(N),c(N);
    for(int i = 0; i < N;i++) cin >> a[i] >> b[i] >> c[i];

    for(int i = 0; i <= N;i++)
        for(int j = 0; j <= MAX_N*MAX_AB;j++)
            for(int k = 0; k <=MAX_N*MAX_AB;k++) dp[i][j][k] = INF;
    
    dp[0][0][0] = 0;
    
    for(int i = 0; i < N;i++){
        for(int j = 0; j <= MAX_N*MAX_AB;j++){
            for(int k = 0; k <=MAX_N*MAX_AB;k++){
                if(dp[i][j][k] == INF) continue;
                dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
                dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
            }
        }
    }
    
    int ans = INF;
    for(int i = 1; i <= MAX_N*MAX_AB;i++){
        for(int j = 1; j <= MAX_N*MAX_AB;j++){
            if(i*Mb == j*Ma){
                ans = min(ans,dp[N][i][j]);
            }
        }
    }
    if(ans == INF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
	return 0;
}


Measured memory_bytes: 25984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    map<string,int> MA;
    while(N--){
        string S;cin>>S;
        MA[S]++;
    }
    
    cout<<"AC x "<<MA["AC"]<<endl;
    cout<<"WA x "<<MA["WA"]<<endl;
    cout<<"TLE x "<<MA["TLE"]<<endl;
    cout<<"RE x "<<MA["RE"]<<endl;
}


Measured memory_bytes: 3660
#include <stdio.h>
#include <algorithm>
using namespace std;

int ans[101][10];

int pow(int a,int n){
	if(n <= 0){
		return 1;
	}
	return a * pow(a,n - 1);
}

int main(){
	int m,n;
	int num;
	int sum;
	for(int i = 0; i < 101; i++){
		for(int j = 0; j < 10; j++){
			ans[i][j] = 0;
		}
	}
	for(int i = 0; i < 1023; i++){
		num = 0;
		sum = 0;
		for(int j = 0; j < 10; j++){
			if((i / pow(2,j)) % 2 == 1){
				num++;
				sum += j;
			}
		}
		ans[sum][num]++;
	}
	
	scanf("%d %d",&m,&n);
	while(m != 0 || n != 0){
		printf("%d\n",ans[n][m]);
		scanf("%d %d",&m,&n);
	}
		return 0;

}

Measured memory_bytes: 1032
#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;

ll f(ll n){
  ll ret = 1;
  for(int i = 1; i <= n; ++i){
    ret *= i;
    ret %= MOD;
  }
  return ret % MOD;
}

int main() {
  ll n,m;cin >> n>> m;
  if(n<m){swap(n, m);}
  ll ans= 0;
  if(n-m>1){
    ans= 0;
  }
  else if(n-m==1){
    ans=f(n)*f(m)%MOD;
  }
  else{
    ans=2LL*f(n)*f(n)%MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();
        boolean flag = true;
        int count =0;
        double deposit = 100.0;
        while(flag){
            deposit = Math.floor(deposit*1.01);
            count++;
            if(deposit>=X){
                System.out.println(count);
                break;
            }
        }
    }
}

Measured memory_bytes: 35808
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    XYH = [list(map(int, input().split())) for _ in range(n)]

    info = []
    for x, y, h in XYH:
        if h == 0:
            continue
        info.append([x, y, h])

    if len(info) == 1:
        print(*info[0])
        exit()

    for Cx in range(100 + 1):
        for Cy in range(100 + 1):
            tmp = set()
            for x, y, h in info:
                if h == 0:
                    continue
                H = h + abs(x - Cx) + abs(y - Cy)
                tmp.add(H)
            if len(tmp) == 1:
                print(Cx, Cy, *list(tmp))
                exit()


if __name__ == '__main__':
    resolve()


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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> G(n+1);
    vector<P> vp;
    rp(i,n-1){
        int a,b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
        vp.push_back(make_pair(a,b));
    }
    int K=0;
    for(int i=1; i<=n; i++) K=max(K,(int)G[i].size());
    map<P,int> mp;
    queue<int> que;
    vector<int> cs(n+1,0);
    vector<int> used(n+1,0);
    que.push(1);
    used[1]=1;
    while(!que.empty()){
        int v=que.front(); que.pop();
        int csv=1;
        for(auto p:G[v]){
            if(csv==cs[v]) csv++;
            if(used[p]) continue;
            que.push(p);
            used[p]=1;
            cs[p]=csv;
            mp[make_pair(v,p)]=mp[make_pair(p,v)]=csv;
            csv++;
        }
    }
    cout << K << endl;
    for(auto pairs:vp){
        cout << mp[pairs] << endl;
    }
    return 0;
}

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

int main(){
  int s, s1, s2, s3, sum;
  cin >> s;
  
  s1 =  s / 100;
  s2 = (s - s1 * 100) / 10 ;
  s3 =  s - s1 * 100 - s2 * 10;

  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <unordered_map>
#include <algorithm>

using namespace std;

namespace {
	struct EndPoint
	{
		EndPoint(int _x, pair<int, int> _y) : x(_x), y(_y) {}
		bool operator<(const EndPoint& rhs) const { return x < rhs.x; }

		int x;
		pair<int, int> y;
	};
}

template<size_t N>
struct FenwickTree
{
	FenwickTree() : a(N, 0) {}

	int sum(int x)
	{
		int s = 0;
		for (; x>0; x -= x&-x) {
			s = (s + a[x]);
		}
		return s;
	}

	void add(int x, int i)
	{
		for (; x<N; x += x&-x) {
			a[x] = (a[x] + i);
		}
	}

	vector<int> a;
};

static int countIntersection(const vector<EndPoint>& X)
{
	int num_int = 0;
	FenwickTree<500000> bit;
	for (size_t i = 0; i < X.size(); i++) {
		if (X[i].y.second < -500000) {
			bit.add(X[i].y.first + 1, 1);
		}
		else if (X[i].y.second > 500000) {
			bit.add(X[i].y.first + 1, -1);
		}
		else {
			num_int += bit.sum(X[i].y.second + 1) - bit.sum(X[i].y.first + 1);
		}
	}

	return num_int;
}

int main()
{
	int n = 0;
	cin >> n;

	vector<int> x, y;
	vector<pair<int, int> > c;
	for (int i = 0; i < n; i++) {
		int x1, y1, x2, y2;
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		x.push_back(x1);
		x.push_back(x2);
		y.push_back(y1);
		y.push_back(y2);
		c.push_back(make_pair(x1, y1));
		c.push_back(make_pair(x2, y2));
	}

	sort(x.begin(), x.end());
	x.erase(unique(x.begin(), x.end()), x.end());
	sort(y.begin(), y.end());
	y.erase(unique(y.begin(), y.end()), y.end());
	unordered_map<int, int> mx, my;
	for (int i = 0; i < x.size(); i++) {
		mx[x[i]] = i;
	}
	for (int i = 0; i < y.size(); i++) {
		my[y[i]] = i;
	}

	vector<EndPoint> X;
	for (int i = 0; i < n; i++) {
		int x1 = mx[c[i * 2].first], y1 = my[c[i * 2].second], x2 = mx[c[i * 2 + 1].first], y2 = my[c[i * 2 + 1].second];
		if (y1 == y2) {
			X.push_back(EndPoint(min(x1, x2) * 4 - 1, make_pair(y1 * 4, -1000000)));
			X.push_back(EndPoint(max(x1, x2) * 4 + 1, make_pair(y1 * 4, 1000000)));
		}
		else {
			X.push_back(EndPoint(x1 * 4, make_pair(min(y1, y2) * 4 - 1, max(y1, y2) * 4 + 1)));
		}
	}

	sort(X.begin(), X.end());
	cout << countIntersection(X) << endl;
	return 0;
}


Measured memory_bytes: 15344
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = n / 1000;
        int b = (n - a * 1000) / 100;
        int c = (n - a * 1000 - b * 100) / 10;
        int d = n % 10;
        if (a + b + c + d == 7)
            System.out.println(a + "+" + b + "+" + c + "+" + d + "=" + 7);
        else if (a + b + c - d == 7)
            System.out.println(a + "+" + b + "+" + c + "-" + d + "=" + 7);
        else if (a + b - c + d == 7)
            System.out.println(a + "+" + b + "-" + c + "+" + d + "=" + 7);
        else if (a - b + c + d == 7)
            System.out.println(a + "-" + b + "+" + c + "+" + d + "=" + 7);
        else if (a + b - c - d == 7)
            System.out.println(a + "+" + b + "-" + c + "-" + d + "=" + 7);
        else if (a - b + c - d == 7)
            System.out.println(a + "-" + b + "+" + c + "-" + d + "=" + 7);
        else if (a - b - c + d == 7)
            System.out.println(a + "-" + b + "-" + c + "+" + d + "=" + 7);
        else if (a - b - c - d == 7)
            System.out.println(a + "-" + b + "-" + c + "-" + d + "=" + 7);
    }
}


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

#define int long long

#define mod (int)1000000007
#define inf (int)1000000007

#define rep(i, n) for(int i = 0; i < (n); i++)
#define trep(i, n) for(int i = 0; i <= (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define trrep(i, n) for(int i = (n); i >= 0; i--)
#define For(i, s, t) for(int i = (s); i < (t); i++)
#define tfor(i, s, t) for(int i = (s); i <= (t); i++)
#define rfor(i, s, t) for(int i = (t) - 1; i >= (s); i--)
#define trfor(i, s, t) for(int i = (t); i >= (s); i--)

int bb[5555];

int dd[5555][222];
int dd2[5555];

signed main() {
  int n, m;
  cin >> n >> m;
  rep(i, n - 1) {
    cin >> bb[i];
  }
  bb[n - 1] = 0;
  rep(i, n) {
    rep(j, m) {
      cin >> dd[i][j];
    }
  }
  rep(i, n) {
    dd2[i] = 0;
  }
  rep(i, m) {
    int now = 0;
    rep(j, n) {
      if(dd[j][i] > now) {
        dd2[j] += dd[j][i] - now;
        now = dd[j][i];
      }
    }
  }
  int ma = 0;
  rep(i, n) {
    int now = 0;
    For(j, i, n) {
      now += dd2[j];
      ma = max(ma, now);
      now -= bb[j];
    }
    rep(j, m) {
      int nn = 0;
      For(k, i + 1, n) {
        if(dd[k][j] > dd[i][j]) {
          dd2[k] += dd[i][j] - nn;
          break;
        }
        else if(dd[k][j] > nn){
          dd2[k] += dd[k][j] - nn;
          nn = dd[k][j];
        }
      }
    }
  }
  cout << ma << endl;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define N 100010
using namespace std;
int n,a[N],fir[N],to[N<<1],nxt[N<<1],c[N<<1],tot(1),d[N],root,s[N],ok(0);

template <class Aqua>
inline void read(Aqua &s){
	s=0; char c=getchar();
	while (!isdigit(c)) c=getchar();
	while (isdigit(c)) s=s*10+c-'0',c=getchar();
}

inline void add(int u,int v){
	to[++tot]=v; nxt[tot]=fir[u]; fir[u]=tot; d[v]++;
}

void dfs(int x,int fa){
	if (ok) return;
	int fl=0; s[x]=0;
	for (int i=fir[x];i && !ok;i=nxt[i])
		if (to[i]!=fa){
			fl=1;
			dfs(to[i],x);
			c[i]=c[i^1]=2*a[to[i]]-s[to[i]];
			s[x]+=c[i];
			if (c[i]<0)
				ok=1;
		}
	if (!fl)
		s[x]=a[x];
	if (!fa)
		if (s[x]!=2*a[x])
			ok=1;
}

int main(){
	read(n);
	for (int i=1;i<=n;i++)
		read(a[i]);
	int u,v;
	for (int i=1;i<n;i++){
		read(u),read(v);
		add(u,v),add(v,u);
	}
	if (n==2){
		if (a[1]==a[2])
			puts("YES");
		else
			puts("NO");
		return 0;
	}
	for (int i=1;i<=n;i++)
		if (d[i]!=1)
			root=i;
	dfs(root,0);
	if (ok){
		puts("NO"); return 0;
	}
	for (int i=1;i<=n && !ok;i++)
		if (d[i]!=1){
			int s=0;
			for (int j=fir[i];j;j=nxt[j])
				s+=c[j];
			if (s&1)
				ok=1;
			for (int j=fir[i];j;j=nxt[j])
				if (c[j]>s/2)
					ok=1;
		}
	if (ok)
		puts("NO");
	else
		puts("YES");
	return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	long long X, K, D;
	cin >> X >> K >> D;

	X = abs(X);

	long long q = X / D;
	long long r = X % D;

	if (q >= K)
	{
		cout << X - (K * D);
		return 0;
	}

	long long remain_move = K - q;

	if (remain_move % 2 == 0)
	{
		cout << r;
	}
	else
	{
		cout << D - r;
	}

	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
// #pragma GCC optimize("O2")
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef multiset <ll> mms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
typedef complex<double> cd;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define all(v) v.begin(),v.end()
#define deb(x) cout << #x << " " << x << endl;
#define ff first
#define ss second
#define pb(v) push_back(v)
#define lb(v) lower_bound(v)
#define ub(v) upper_bound(v)
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define rev(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b) {
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s) {
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
void pv(mv v) {
	forl(i,v.size()) cout<<v[i]<<" ";
	cout<<"\n";
}
void pa(ll *v, ll size) {
	forl(i,size) cout<<v[i]<<" ";
	cout<<"\n";
}
void removeDups(mv &v) {
	sort(all(v));
	mv::iterator it = unique(v.begin(), v.end());
	v.resize(distance(v.begin(), it));
}
inline ld kthRoot(ld n, ll k) {
	return pow(k, (1.0 / k) * (log(n) / log(k)));
}
ll power(ll x, ll y, ll p) {
	ll res=1;
	x=x%p;
	while(y>0) {
		if(y&1) res = (res*x)%p;
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x, ll mod) {
	if(x>=mod) x%=mod;
}

ll mod = 1e9 + 7;

string s;
void thisIsMain() {
	cin>>s;
	if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R') {
		cout<<"3\n";
		return ;
	}
	if((s[0] == 'R' && s[1] == 'R') || (s[2] == 'R' && s[1] == 'R')) {
		cout<<"2\n";
		return ;
	}
	if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R') cout<<"1\n"; else cout<<"0\n";
}

int main(void)
{
	fastio
	ll t = 1;
	// cin>>t;
	while(t--) thisIsMain();
	return 0;
}

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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N, K, Q; cin >> N >> K >> Q;
    vector<int> vec(N , K-Q);
    vector<int> a(Q);
    for(int i = 0 ; i < Q; ++i){
        cin >> a[i];
        --a[i];
    }

    for(int i = 0; i < Q; ++i){
        vec[a[i]]++;
    }

    for(int i = 0 ; i < N; ++i){
        if(vec[i] > 0){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }


    return 0;
}



Measured memory_bytes: 1408
import math

n,d = map(int,input().split())
x = [[0]*d for _ in range(n)]

for i in range(n):
    x[i] = list( map( int, input().split() ) )

count = 0
for i in range(n):
    for j in range(n):
        if i <= j:
            continue
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k])**2
        dist = math.sqrt(dist)
        if dist % 1 == 0:
            count += 1

print(count)


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int main()
{
    char s[15],t[15],u[15];
    int a,b;
    scanf("%s %s",s,t);
    scanf("%d %d",&a,&b);
    scanf("%s",u);
    if(strcmp(s,u)==0) printf("%d %d\n",a-1,b);
    else printf("%d %d\n",a,b-1);
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000007;




int main() {
	
	int n;
	cin >> n;
	
	vector<pair<int, int>> v;
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		v.push_back({ a,b });
	}

	sort(ALL(v));

	int ans = 0;

	REP(i, n) {
		REP(j, n) {
			if (i == j)continue;
			int p = v[j].first - v[i].first;
			int q = v[j].second - v[i].second;
			int cnt = 0;
			REP(k, n) {
				REP(l, n) {
					if (v[k].first + p == v[l].first&&v[k].second + q == v[l].second)cnt++;
				}
			}
			ans = max(ans, cnt);
		}
	}

	cout << n - ans << endl;
}


Measured memory_bytes: 256
import bisect
n = int(input())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
list_c = list(map(int, input().split()))
list_a.sort()
list_b.sort()
list_c.sort()
len_c = len(list_c)
result = 0
for one_b in list_b:
  place_a = bisect.bisect_left(list_a, one_b)
  place_c = bisect.bisect_right(list_c, one_b)
  result += place_a * (len_c - place_c)
print(result)

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

int main(){
  int N,W,v,w;
  long long int ans[10001] = {0},max = 0;
  cin >> N >> W;
  // 一つずつ商品を入れていく
  for(int k = 0;k < N;k++){
    cin >> v >> w;
    if(w <= W){
      for(int i = W;i >= w;i--){
        //条件より、スペースが負や品物の数が負である状況はありえない
        if(ans[i] < ans[i - w] + v){
          ans[i] = ans[i - w] + v;
        }
      }
    }
  }
  for(int k = 0;k <= W;k++){
    if(max < ans[k])max = ans[k];
  }
  cout << max << endl;
}



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

using namespace std;

int main() {
	int x,y,z,k;
	cin >> x >> y >> z >> k;
	vector<long long> vx(x), vy(y), vz(z);
	for (int i=0;i<x;++i) cin >> vx[i],vx[i]=-vx[i];
	for (int i=0;i<y;++i) cin >> vy[i],vy[i]=-vy[i];
	for (int i=0;i<z;++i) cin >> vz[i],vz[i]=-vz[i];
	vector<long long> first_pair(x*y);
	int l = 0;
	for (int i=0;i<x;++i)
		for (int j=0;j<y;++j) first_pair[l++] = vx[i]+vy[j];
    sort(first_pair.begin(), first_pair.end());
    sort(vz.begin(), vz.end());
	vector<long long> total_pair;
	set<pair<long long, pair<int,int>>> Q;
	Q.insert({first_pair[0] + vz[0], {0,0}});
	while (!Q.empty() && total_pair.size()<k) {
		auto head = *Q.begin();
		Q.erase(Q.begin());
		total_pair.push_back(head.first);
		int i = head.second.first, j=head.second.second;
		if ((j+1) < z) Q.insert({first_pair[i] + vz[j+1], {i,j+1}});
		if ((i+1) < first_pair.size()) Q.insert({first_pair[i+1] + vz[j], {i+1,j}});
	}
	sort(total_pair.begin(), total_pair.end());
	for(int i=0;i<k;++i) cout << -total_pair[i] <<"\n";
	return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
  string s;
  cin >> s;
  
  if(s=="SUN") cout << 7 << endl;
  else if(s=="MON") cout << 6 << endl;
  else if(s=="TUE") cout << 5 << endl;
  else if(s=="WED") cout << 4 << endl;
  else if(s=="THU") cout << 3 << endl;
  else if(s=="FRI") cout << 2 << endl;
  else cout << 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */



signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int N;
  cin >> N;
  vector<int> W(N);
  int sum = 0;
  REP(i,N) cin >> W[i], sum += W[i];
  vector<int> cum(N+1);
  REP(i,N) {
    cum[i+1] = cum[i] + W[i];
  }
  int ans = INF;
  REP(i,N+1) {
    CHMIN(ans,abs(cum[i]-(sum-cum[i])));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
typedef long long ll;
using namespace std;
typedef pair<int, int> ii;
#define MOD 998244353LL
#define MAXN 300300

ll fakt[MAXN];

ll pow(ll a, ll b)
{
  if (b == 0) return 1LL;

  if (b == 1) return a;

  if (b % 2 == 1) return a * pow(a, b - 1) % MOD;

  ll ret = pow(a, b / 2LL);

  return ret * ret % MOD;
}

int main()
{
  fakt[0] = 1;
  for (int i = 1; i < MAXN; i++)
    fakt[i] = fakt[i - 1] * ll(i) % MOD;
  ll n, a, b, k;
  scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
  ll reza = 0LL;
  for (ll x = 0LL; x <= n; x++) {
    ll by = k - a * x;
    if (by % b == 0 && by / b >= 0 && by / b <= n) {
      ll y = by / b;
      reza += fakt[n] * pow(fakt[n - x], MOD - 2) % MOD * pow(fakt[x], MOD - 2) % MOD * fakt[n] % MOD * pow(fakt[n - y], MOD - 2) % MOD * pow(fakt[y], MOD - 2) % MOD;
      reza %= MOD;
    }
  }
  cout << reza;
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct edge{
	int u,v;
}e[100005];
ll fa[100005],ans[100005],sz[100005];
int find(int x) {
	if(x==fa[x]) return x;
	return fa[x]=find(fa[x]);
}
int main(){
	ll n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>e[i].u;
		cin>>e[i].v;
	}
	for(int i=1;i<=n;i++){
		fa[i]=i;
		sz[i]=1;
	}
	ans[m]=(ll)n*(n-1)/2;
	for(int i=m;i>=1;i--){
		int u,v;
		u=find(e[i].u);
		v=find(e[i].v);
		if(u==v){
			ans[i-1]=ans[i];
		}
		else{
			ans[i-1]=ans[i]-sz[v]*sz[u];
			sz[v]+=sz[u];
			fa[u]=v;
		}
	}
	for(int i=1;i<=m;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 4480
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    while (cin >> n) {
        vi mi(256, INT_MAX);
        rep(ii, n) {
            string s;
            cin >> s;
            vi cnt(256);
            each(c, s)cnt[c]++;
            for (int i = 'a'; i <= 'z'; ++i)smin(mi[i], cnt[i]);
        }
        for (char c = 'a'; c <= 'z'; ++c) {
            cout << string(mi[c], c);
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    double a,b;
    double total=0,ntotal=0,i=0;
    while(scanf("%lf,%lf",&a,&b)!=EOF){
        i++;
        total+=a*b;
        ntotal+=b;
    }
    cout<<total<<endl;
    cout<<(int)((ntotal/i)+0.5)<<endl;
    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;

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

  double n = L/3.0;
  double ans = n*n*n;
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
main()
{
	int x1,x2,x3,x4,x5,i;
	cin>>x1>>x2>>x3>>x4>>x5;
		if(x1==0)
		{
			cout<<"1";
		}
			if(x2==0)
		{
			cout<<"2";
		}
			if(x3==0)
		{
			cout<<"3";
		}
			if(x4==0)
		{
			cout<<"4";
		}
			if(x5==0)
		{
			cout<<"5";
		}
}

Measured memory_bytes: 3568
import numpy as np

H,W = map(int,input().split())
A = []
for i in range(H):
    A.append([0 if i == "#" else H+W for i in list(input())])
A = np.array(A)

for i in range(H-1):
  A[i+1, :] = np.minimum(A[i, :] + 1, A[i+1, :])
for i in range(H-1,0,-1):
  A[i-1,:] = np.minimum(A[i,:]+1,A[i-1,:])
for i in range(W-1):
  A[:,i+1] = np.minimum(A[:,i]+1,A[:,i+1])
for i in range(W-1,0,-1):
  A[:,i-1] = np.minimum(A[:,i]+1,A[:,i-1])
print(np.max(A))


Measured memory_bytes: 60408
#include <iostream>
using namespace std;
 
#define WHITE 0 
#define GRAY 1
#define BLACK 2
#define INFTY 10000000
int n,color[100],M[100][100],d[100],p[100];
int i,j,u,k,v,c;
 
//ダイクストラ法
void dijkstra(){

  //初期化
  for( i = 0; i < n; i++ ){
    color[i] = WHITE;
    d[i] = INFTY;
  }
  d[0] = 0;
  p[0] = -1;

  while(1){
    int u = -1;
    int mincost = INFTY;
    for( i = 0; i < n; i++ ){
      if( color[i] != BLACK && d[i] < mincost ){
	mincost = d[i];
	u = i;
      }
    }
    
    if( u == -1 ) break;

    color[u] = BLACK;
 
    //更新
    for( v = 0; v < n; v++ ){
      if( color[v] != BLACK && M[u][v] != INFTY ){
	if( d[u] + M[u][v] < d[v] ){
	  d[v] = d[u] + M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }
  
  //出力
  for( i = 0; i < n; i++ ){
    cout << i << " ";
    if( d[i] == INFTY ) cout << -1;
    else cout << d[i];
    cout << endl;
  }
}
 
int main(){

  //入力
  cin >> n;
  for( i = 0; i < n; i++ ){
    for( j = 0; j < n; j++ ){
      M[i][j] = INFTY;
    }
  }
 
  for( i = 0; i < n; i++ ){
    cin >> u >> k;
    for( j = 0; j < k; j++ ){
      cin >> v >> c;
      M[u][v] = c;
    }
  }
   
  dijkstra();
 
  return 0;
}

Measured memory_bytes: 1200
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<set>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<stack>
#include<tuple>
#include<utility>
typedef long long ll;
#define rep0(i,n) for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n) for(ll i=1; i<=n; i++)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using namespace std;

int main(){
  int n,m;  cin >> n >> m;
  vi s(n);
  rep0(i,m){ //スイッチの番号
    int k;  cin >> k;
    rep0(j,k){ //スイッチの個数
      int a;  cin >> a;  a--;
      s[a] |= 1 << i;
    }
  }
  int x,p = 0;
  rep0(i,m){ //答えの点灯の仕方
    cin >> x;
    p |= x << i;
  }

  int ans = 0;
  for(int S = 0; S < (1 << n); S++){ //全ての01のパターン
    int t = 0;
    rep0(i,n){
      if(S >> i & 1){ //何ビット目が立っているか
        t ^= s[i]; //XOR演算子
      }
    }
    if(p == t){
      ans++;
    }
  }
  // cout << p << " " << ans;
  cout << ans;
}


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

int main(){
	string sub,x;
	int n,c=0;
	
	cin>>sub>>n;
	
	for(int i=0;i<n;i++){
		cin>>x;
		
		int z=sub.size()-1;
		string sa=x.substr(0,z);
		string y=x+sa;
		
		size_t zb;
		zb=y.find(sub);
		if(zb!=string::npos){c++;}
		}
		cout<<c<<endl;
		return 0;
	}

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

int main(){
    ll t,n,k,l,r;
    ll res =0 ,pre = 0;
    cin>>n;
    for(ll i=0;i<n;i++){
        ll x; cin>>x;
        res +=max(0ll,pre-x);
        pre = max(pre,x);
    }
    cout<<res;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
using namespace std;

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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

int gcd_of_vector(int A[100000], int begin, int end){
  int result = A[begin];
  for(int i=begin;i<end;i++){
    result = gcd(A[i],result);
  }
  return result;
}

int gcd_of_vector_with_skip(int A[100000], int skip, int size){
  int result = A[0];
  if(skip==0)result=A[1];
  for(int i=1;i<size;i++){
    if(i==skip)continue;
    result = gcd(A[i],result);
  }
  return result;
}

int main() {
  int N=getint();
  int A[100000];
  for(int i=0;i<N;i++)A[i]=getint();

  if(N>=100){
    cout<<max(gcd_of_vector(A,0,N/2),gcd_of_vector(A,N/2,N))<<"\n";
  }else{
    int ans=0;
    for(int i=0;i<N;i++){
      ans=max(ans,gcd_of_vector_with_skip(A,i,N));
    }
    cout<<ans<<"\n";
  }
  return 0;
}


Measured memory_bytes: 768