akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

ll a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

ll dp[100010][3];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    ll res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;
}

Measured memory_bytes: 4992
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
 
struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n;
LL dp[55][1 << 20];
int a[55], b[55];
vector<int> Tree[55];
int m;
int u[22], v[22];

bool ispass[55][55][55];
int d[55];

int main(){
    cin >> n;
    REP(i, n - 1){
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        Tree[a[i]].emplace_back(b[i]);
        Tree[b[i]].emplace_back(a[i]);
    }
    cin >> m;
    REP(i, m){
        cin >> u[i] >> v[i];
        u[i]--, v[i]--;
        REP(i, n)d[i] = HINF<int>();
        d[u[i]] = 0;
        queue<int> q;
        q.push(u[i]);
        while(!q.empty()){
            int p = q.front();
            q.pop();
            for(auto to : Tree[p]){
                if(d[to] == HINF<int>()){
                    d[to] = d[p] + 1;
                    q.push(to);
                }
            }
        }
        int p = v[i];
        while(p != u[i]){
            bool flg = false;
            for(auto to : Tree[p]){
                if(flg == false && d[to] == d[p] - 1){
                    flg = true;
                    ispass[i][p][to] = true;
                    ispass[i][to][p] = true;
                    p = to;
                }
            }
        }
    }
    dp[0][0] = 1;
    REP(i, n){
        REP(bit, (1 << m)){
            dp[i + 1][bit] += dp[i][bit];
            int mask = 0;
            REP(j, m){
                if(!ispass[j][a[i]][b[i]])continue;
                mask += (1 << j);
            }
            dp[i + 1][bit | mask] += dp[i][bit];
        }
    }
    cout << dp[n - 1][(1 << m) - 1] << endl;
}

Measured memory_bytes: 412032
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define SZ(x) ((int)((x).size()))

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

template <typename T>
bool MinPlace(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool MaxPlace(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        out << v[i];
        if (i != (int)v.size()-1) out << ", ";
    }
    out << "]";
    return out;
}

template<class TH>
void _dbg(const char* name, TH val){
    clog << name << ": " << val << endl;
}
template<class TH, class... TA>
void _dbg(const char* names, TH curr_val, TA... vals) {
    while(*names != ',') clog << *names++;
    clog << ": " << curr_val << ", ";
    _dbg(names+1, vals...);
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
    #define dbg_arr(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg(...)
    #define dbg_arr(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

const int MAXN = 210000;
int last[MAXN];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!
    int N;
    cin >> N;
    vector<int> C(N);
    for (int i = 0; i < N; i++) cin >> C[i];
    const LL mod = 1e9 + 7;
    vector<LL> din(N);
    din[N-1] = 1;
    last[C[N-1]] = N-1;
    for (int i = N-2; i >= 0; i--) {
        din[i] = din[i+1];
        if (last[C[i]] > i+1) {
            din[i] = (din[i] + din[last[C[i]]]) % mod;
        }
        last[C[i]] = i;
    }
    cout << din[0] << "\n";
}


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

typedef long long ll;

int main () {
	int N;
	vector <ll> v;
	cin >> N;
	for (int i=0; i<N; i++) {
		ll tmp;
		cin >> tmp;
		v.push_back (tmp);
	}
	sort (v.begin(), v.end());
	int sum=0;
	vector <int> vb;
	ll max = v[v.size()-1];
	for (ll i=0; i<=max; i++)
		vb.push_back (0);
	
	for (int j=0; j<N; j++) {
		ll a = v[j];
		ll b = a;
		while (b<=max) {
			vb[b] += 1;
			b += a;
		}
	}

	/*
	for (ll j=0; j<=max; j++)
		cout << vb[j] << " ";
	cout << endl;
	*/

	for (int i=0; i<N; i++)
		if (vb[v[i]]==1)
			sum ++;
	
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 9028
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int N, K;
  std::cin >> N >> K;
  vt<long double> q(N);
  long double ans = 0, tmp = 0;
  rep(i,N){
    long double p;
    std::cin >> p;
    q[i] = (p+1.0)/2.0;
    if(i < K){
      tmp += q[i];
      ans += q[i];
    }
    else{
      tmp = tmp + q[i] - q[i-K];
      if(ans < tmp)
        ans = tmp;
    }
  }

  std::cout << std::fixed << std::setprecision(10) << ans << '\n';
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); ++i)
#define repf(i, from, to) for (int i = (from); i < (to); ++i)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

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

  int num = a * 1e2 + b * 1e1 + c;

  if(num % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3544
def resolve():
	n = int(input())
	d = dict()
	for _ in range(n):
		v = input()
		if d.get(v):
			d[v] += 1
		else:
			d[v] = 1
	m = int(input())
	for _ in range(m):
		v = input()
		if d.get(v):
			d[v] -= 1
		else:
			d[v] = -1
	ans = float('-inf')
	for k in d.keys():
		ans = max(ans, d[k])
	print(max(ans, 0))
resolve()

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	k, _ := strconv.Atoi(stringLineScan())
	if k%2 == 0 {
		z := 0
		h := 0
		m := k / 2
		for i := 1; i <= n; i++ {
			if i%k == 0 {
				z++
			} else if i%k == m {
				h++
			}
		}
		fmt.Println(z + z*(z-1)*3 + z*(z-1)*(z-2) + h + h*(h-1)*3 + h*(h-1)*(h-2))
	} else {
		z := 0
		for i := 1; i <= n; i++ {
			if i%k == 0 {
				z++
			}
		}
		fmt.Println(z + z*(z-1)*3 + z*(z-1)*(z-2))
	}
}


Measured memory_bytes: 640
#include <algorithm>
#include <complex>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::cerr;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::stack;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

typedef long long int ll;
const int MOD = 1e9 + 7;

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

    bool ans = (a + b == c) || (b + c == a) || (c + a == b);
    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 888
/*
      author : nishi5451
      created: 11.08.2020 22:45:58
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    int n,r;
    cin >> n >> r;
    int ans;
    if(n>=10) ans = r;
    else ans = r+100*(10-n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <limits>


template<class T>
T cc(T t)
{
	return t * (t - 1) / 2;
}

const char* YesNo(bool b)
{
	if (b)
	{
		return "Yes";
	}
	else
	{
		return "No";
	}
}

bool is_kaibun(const std::string& S, int left, int right)
{
	for (int i = 0; i < (right - left)/2; i++)
	{
		if (S[left+i] != S[right-i-1])
		{
			return false;
		}
	}
	return true;
}

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

	double a = L / 3.0;
	double ans = a * a * a;

	printf("%.10f", ans);
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long ll;
#define MAX_N 20001
#define MAX_X 256
#define INF 2000000000

int dp[MAX_N][MAX_X];

void init(){
	rep(i,MAX_N){
		rep(j,MAX_X) dp[i][j] = INF;
	}
}


int main()
{
	int N,M;
	cin>>N>>M;
	while( !(N == 0 && M == 0)){
		init();
		int *codeBook = new int[M];
		int *x = new int[N];
		rep(i,M) cin>>codeBook[i];
		rep(i,N) cin>>x[i];
		dp[0][128] = 0;
		for(int i = 0; i < N; i++){
			for(int j = 0; j <= 255; j++){
				if( dp[i][j] == INF) continue;
				for(int k = 0; k < M; k++){
					int next = j + codeBook[k];
					if(next <= 0){
						next = 0;
					}else if(next >= 255){
						next = 255;
					}
					dp[i+1][next] = min(dp[i+1][next], dp[i][j] + (next-x[i])*(next-x[i]));
				}
			}
		}
		int ans = INF;
		rep(i,256){
			ans = min(ans,dp[N][i]);
		}
		cout<<ans<<endl;
		cin>>N>>M;
	}
	return 0;
}




Measured memory_bytes: 23420
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

#include<queue>

using namespace std;

int main(void)
{
    int N;

    cin >> N;

    if( N <= 999 )
    {
        cout << "ABC";
    }
    else
    {
        cout << "ABD";
    }

    return 0;
}


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

long long const MOD = 1000000007LL;

int gcd(int a, int b) {
    int rest = max(a, b) % min(a, b);
    if (rest == 0) return min(a, b);
    else return gcd(min(a, b), rest);
}

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

    // c で割り切れるものの個数
    long long numC = b / c - a / c + (a % c == 0 ? 1 : 0);
    // d で割り切れるものの個数
    long long numD = b / d - a / d + (a % d == 0 ? 1 : 0);

    // 最小公倍数を考える
    long long x = c * d / gcd(c, d);
    long long numX = b / x - a / x + (a % x == 0 ? 1 : 0);

    long long res = (b - a + 1) - (numC + numD) + numX;

    cout << res << endl;
}


Measured memory_bytes: 256
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();

        final List<Integer> list = IntStream.range(0, n)
                .mapToObj(i -> scanner.nextInt())
                .sorted()
                .collect(Collectors.toList());

        int min = Integer.MAX_VALUE;
        for (int i = 0; i < 101; i++) {
            final int tmp = i;
            final int sum = list.stream()
                    .map(v -> (v - tmp) * (v - tmp))
                    .mapToInt(Integer::intValue)
                    .sum();
            min = Math.min(sum, min);
        }

        System.out.println(min);
    }
}


Measured memory_bytes: 28372
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
  
using namespace std;

int StoI(string s)
{
    int ans = 0;
    for(int i = 0; i < s.length(); i++){
        ans += (s[i] - '0') * (int)pow(10, s.length() - 1 - i);
    }
    return ans;
}

long long int solve(string s)
{
    // cout << s << endl;
    bool flag = false;
    string a = "";
    int leftnum = 0;
    vector<int> result;
    for(int i = 1; i < s.length() - 1; i++){
        a += s[i];
        if(s[i] == '[') leftnum++;
        else if(s[i] == ']') leftnum--;
        if(leftnum > 1) flag = true;
        if(leftnum == 0){
            if(flag){
                result.push_back(solve(a));
            } else {
                a = a.substr(1, a.length() - 2);
                // cout << a << endl;
                result.push_back(StoI(a) / 2 + 1);
            }
            a = "";
            flag = false;
        }
    }
    sort(result.begin(), result.end());
    long long int ans = 0;
    for(int i = 0; i < result.size() / 2 + 1; i++){
        // cout << result[i] << endl;
        ans += result[i];
    }
    return ans;
}

int main()
{
    int n;
    cin >> n;
    string s;
    for(int i = 0; i < n; i++){
        cin >> s;
        cout << solve(s) << endl;
    }
    return 0;
}

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

int main(){
  int w,a,b;
  cin>>w>>a>>b;
  int ans;
  if((a+w)>=b&&a<=(b+w)) ans=0;
  else{
    if(b>(a+w)) ans=b-(a+w);
    else ans=a-(b+w);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	string s, t;
	cin >> s >> t;
	s.insert(s.end(), s.begin(), s.end());
	vector< set< int > > ilist(26);
	M = s.size();
	N = M / 2;
	rep(i, M) ilist[s[i] - 'a'].insert(i);
	int ans = 0, i = -1;
	rep(j, t.size()) {
		char c = t[j];
		auto it = ilist[c - 'a'].upper_bound(i);
		if (it == ilist[c - 'a'].end()) {
			cout << -1 << endl;
			return 0;
		}
		//cout << *it << endl;
		ans += *it - i;
		i = *it;
		if (i >= N)
			i -= N;
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
#define REP(i, n, m) for(int i = n; i < m; i++)
#define REPR(i, n, m) for(int i = n; i >= m; i--)
#define LREP(i, n, m) for(ll i = n; i < m; i++)
#define LREPR(i, n, m) for(ll i = n; i >= m; i--)

#define P pair<int, int >


const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;



//---functions---//
int gcd(int a, int b){
    if(a < b) swap(a, b);
    return b?gcd(b, a%b):a;
}

int s2i(string num){stringstream ss; ss << num << flush; int n; ss >> n; return n;}
string i2s(int n){stringstream ss; ss << n << flush; return ss.str();}

bool firstCompare(const P& firstElof, const P& secondElof){
    return firstElof.first < secondElof.first;
}
bool secondCompare(const P& firstElof, const P& secondElof){
    return firstElof.second < secondElof.second;
}
//---------------//

ll N;
int main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    ll A[N+1], B[N];
    LREP(i, 0, N + 1) cin >> A[i];
    LREP(i, 0, N) cin >> B[i];
    ll ans = 0;
    LREP(i, 0, N){
        if(A[i] >= B[i]){
            ans += B[i];
        }else{ 
            ans += A[i];
            if(A[i+1] < B[i] - A[i]){
                ans += A[i+1];
                A[i+1] = 0;
            }else{
                ans += (B[i] - A[i]);
                A[i+1] -= (B[i] - A[i]);
            }
        }
    }
    cout << ans << '\n';

}


Measured memory_bytes: 1792
import sys
input = sys.stdin.readline

N = int(input())
L = [int(input()) for v in range(N)]
p = sum(L)

if p % 10 != 0:
    print(p)
else:
    nt = [v for v in L if v % 10 != 0]
    if len(nt) == 0:
        print(0)
    else:
        nt.sort()
        print(p - nt[0])

Measured memory_bytes: 3060
#include <stdio.h>
int main()
{
int i=0,n=0,x=0,m=1000000,M=-1000000;
long s=0;
scanf("%d",&n);
for (i=0;i<n;i++) {
scanf("%d",&x);
if (m > x) m = x;
if (M < x) M = x;
s+= x;
}
printf("%d %d %ld\n", m, M, s);
return 0;
}

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

using namespace std;

struct item
{
	int weight;
	int64_t value;
};

int main()
{
	ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);

	int n, w; cin >> n >> w;
	vector<item> items(n);
	for (int i = 0; i < n; ++i) {
		cin >> items[i].weight >> items[i].value;
	}
	int64_t dp[n][w + 1];
	for (int i = 0; i <= w; ++i) {
		if (i >= items[0].weight) {
			dp[0][i] = items[0].value;
		} else {
			dp[0][i] = 0;
		}
	}
	for (int i = 1; i < n; ++i) {
		for (int j = 0; j <= w; ++j) {
			if (j >= items[i].weight) {
				dp[i][j] = max(items[i].value + dp[i - 1][j - items[i].weight], dp[i - 1][j]);
			} else {
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	int64_t max_value = 0;
	for (int i = 0; i <= w; ++i) {
		max_value = max(max_value, dp[n - 1][i]);
	}
	cout << max_value << endl;
}

Measured memory_bytes: 78336
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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

//がんばってputintつくるかぁ
const int MAX = 10000;
const int dm = 1 << 17;
char dn[dm], * di = dn, * owad = dn + dm - 20;
class shuturyoku_unko {
public:
	char C[MAX * 4];
	shuturyoku_unko() : C() {
		rep(i, MAX) {
			int X = i;
			rep(j, 4) {
				C[i * 4 + 3 - j] = '0' + X % 10;
				X /= 10;
			}
		}
	}
	void putint(ll A) {
		if (owad < di) {
			fwrite(dn, 1, di - dn, stdout);
			di = dn;
		}
		int dig = 1;
		if (A >= 100000000) {
			if (A >= 10000000000) dig = 3;
			else if (A >= 1000000000) dig = 2;
			memcpy(di + 4 + dig, C + A % 10000 * 4, 4);
			A /= 10000;
			memcpy(di + dig, C + A % 10000 * 4, 4);
			A /= 10000;
			memcpy(di, C + A * 4 + 4 - dig, dig);
			di += 8 + dig;
		}
		else if (A >= 10000) {
			if (A >= 10000000) dig = 4;
			else if (A >= 1000000) dig = 3;
			else if (A >= 100000) dig = 2;
			memcpy(di + dig, C + A % 10000 * 4, 4);
			A /= 10000;
			memcpy(di, C + A * 4 + 4 - dig, dig);
			di += 4 + dig;
		}
		else {
			if (A >= 1000) dig = 4;
			else if (A >= 100) dig = 3;
			else if (A >= 10) dig = 2;
			memcpy(di, C + A * 4 + 4 - dig, dig);
			di += dig;
		}
		*di++ = '\n';
	}
} f;



int A[100001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint();
	ll kotae = 0;
	rep(i, N) {
		int kari = getint();
		A[kari]++;
		kotae += kari;
	}

	int Q = getint();
	rep(i, Q) {
		int b = getint();
		int c = getint();

		A[c] += A[b];
		kotae += A[b] * ll(c - b);
		A[b] = 0;

		f.putint(kotae);
	}


	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 2200
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Math;

class Program
{
    const long mod = 998244353;
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var D = ReadLine().Split().Select(int.Parse).ToArray();
        if (D[0] != 0)
        {
            WriteLine(0);
            return;
        }
        var zero = false;
        for (int i = 1; i < N; i++)
        {
            if (D[i] == 0) zero = true;
        }
        if (zero)
        {
            WriteLine(0);
            return;
        }
        Array.Sort(D);
        var ren = true;
        for (int i = 1; i < N; i++)
        {
            if (D[i] - D[i - 1] > 1) ren = false;
        }
        if (!ren)
        {
            WriteLine(0);
            return;
        }

        var d = new int[N];
        for (int i = 0; i < N; i++)
        {
            d[D[i]]++;
        }

        var m = D.Max();
        var ans = 1L;
        for (int i = 0; i < m; i++)
        {
            ans *= ModPow(d[i] , d[i + 1] , mod);
            ans %= mod;
        }
        WriteLine(ans);
    }

    public static long ModPow(long x, long n, long m)
    {
        var res = 1L;
        while (n != 0)
        {
            if ((n & 1) == 1) res = res * x % m;
            x = x * x % m;
            n >>= 1;
        }
        return res;
    }
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    ll A;
    string b;
    cin >> A >> b;
    int bl = b.length();
    string bs;
    REP(i,bl){
        if (b[i] != '.'){
            bs.push_back(b[i]);
        }
    }

    ll B = stoi(bs);

    cout << (A * B) / 100 << endl;
}

Measured memory_bytes: 3616
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define int __int128
#define min(a,b) a<b?a:b 
template<class T>inline void read(T& x) {
	T f=1;x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=(x<<1)+(x<<3)+(s&15);s=getchar();}
	x*=f;
}
inline void print(int x,char s) {
    if(x>=10) { print(x/10,'S'); }
    putchar(x%10+'0');
    if(s!='S') putchar(s);
}
inline void print(int x) {
    if(x>=10) { print(x/10); }
    putchar(x%10+'0');
}
template<class T>inline T po(T a) { return a*a; }
inline int gcd(int a,int b) { return a%b==0?b:gcd(b,a%b); }
int n,a,b,rans;
inline int ksm(int a,int b) {
	int ans=1,asd=a;
	while(b) {
		if(b&1) ans*=asd;
		asd=asd*asd; asd%=mod;
		b>>=1;
		ans%=mod;
	}
	return ans;
}
inline int C(int A,int B) {
	int ans=1,k=1;
	rep(i,A-B+1,A) ans*=i,ans%=mod;
	rep(i,1,B) k*=i,k%=mod;
	return ((ans*ksm(k,mod-2))%mod);
}
inline int f(int r,int c) {
	return C(r+c,r);
}
inline int g(int r,int c) {
	return f(r+1,c+1)-1;
}
int c1,c2,r1,r2;
signed main() {
	read(r1); read(c1); read(r2); read(c2);
	print((((g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1))%mod)+mod)%mod);
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <functional>
#include <utility>

using namespace std;

//  E[i]: vertexes which can be reased from i
//  W[i]: their weight
template<class T>
vector<T> dijkstra(vector<vector<int>> E, vector<vector<T>> W, int s, T inf)
{
    int n = (int)E.size();

    vector<T> D(n, inf);
    typedef pair<T,int> P;
    priority_queue<P,vector<P>,greater<P>> Q;

    D[s] = T();
    Q.push(make_pair(D[s], s));

    while (!Q.empty())
    {
        int d = Q.top().first;
        int p = Q.top().second;
        Q.pop();
        if (d > D[p])
            continue;
        for (int i=0; i<(int)E[p].size(); i++)
        {
            int t = E[p][i];
            if (d+W[p][i] < D[t])
                D[t] = d+W[p][i],
                Q.push(make_pair(D[t], t));
        }
    }
    return D;
}

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int N, M;
    cin>>N>>M;
    vector<int> u(M), v(M);
    for (int i=0; i<M; i++)
    {
        cin>>u[i]>>v[i];
        u[i]--;
        v[i]--;
    }
    int S, T;
    cin>>S>>T;
    S--;
    T--;

    vector<vector<int>> E(N*3);
    vector<vector<int>> W(N*3);
    for (int i=0; i<M; i++)
        for (int j=0; j<3; j++)
        {
            E[u[i]*3+j].push_back(v[i]*3+(j+1)%3);
            W[u[i]*3+j].push_back(1);
        }

    int oo = 99999999;
    vector<int> D = dijkstra(E, W, S*3, oo);
    if (D[T*3] < oo)
        cout<<D[T*3]/3<<endl;
    else
        cout<<-1<<endl;
}


Measured memory_bytes: 68472
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
int main() {
    int N, M;
    cin >> N >> M;
    int ans = -1;
    vector<int> S(M, 0);
    vector<char> C(M, 0);
    for (int i = 0; i < M; ++i) {
        cin >> S[i] >> C[i];
    }
    int maxi = 0, mini = 0;
    if (N == 1) maxi = 9, mini = 0;
    else if (N == 2) maxi = 99, mini = 10;
    else if (N == 3) maxi = 999, mini = 100;
    for (int i = mini; i <= maxi; ++i) {
        string str = to_string(i);
        bool T = true;
        for (int j = 0; j < M; ++j) {
            if (T == true && str[S[j] - 1] == C[j]) T = true;
            else {
                T = false;
                break;
            }
        }
        if (T) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, M, ans;

int main()
{
    cin >> N >> M;
    vector<int> k(M);
    vector<int> p(M);
    vector<vector<int>> s(M);
    for (int i = 0; i < M; i++)
    {
        cin >> k[i];
        for (int j = 0; j < k[i]; j++)
        {
            int a;
            cin >> a;
            a--;
            s[i].push_back(a);
        }
    }

    for (int i = 0; i < M; i++)
    {
        cin >> p[i];
    }

    for (int i = 0; i < (1 << N); i++)
    {
        int on = 0;
        for (int j = 0; j < M; j++)
        {
            int cnt = 0;
            for (int r = 0; r < k[j]; r++)
            {
                if ((1 << s[j][r]) & i)
                    cnt++;
            }
            if (cnt % 2 == p[j])
                on++;
        }
        if (on == M)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
using namespace std;

int main() {
    int N;
    cin >> N;
    int ct[100]{}, mx = 0;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        ++ct[a];
        mx = max(mx, a);
    }
    for (int i = 0; i < (mx + 2) / 2; ++i) {
        if (mx % 2 == 0 && i == mx / 2) {
            if (ct[mx / 2]) {
                ct[mx / 2] -= 1;
            } else {
                cout << "Impossible" << endl;
                return 0;
            }
        } else {
            if (ct[mx - i] >= 2) {
                ct[mx - i] -= 2;
            } else {
                cout << "Impossible" << endl;
                return 0;
            }
        }
    }
    for (int i = 1; i < (mx + 2) / 2; ++i)
        ct[mx - i + 1] = 0;
    for (int i = 0; i < 100; ++i) {
        if (ct[i]) {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    cout << "Possible" << endl;
    return 0;
}


Measured memory_bytes: 384
n = int(input())
s = input()

pins = [str(i).zfill(3) for i in range(1000)]

ans = 0
for pin in pins:
    index = -1;
    for c in pin:
      index = s.find(c, index+1);
      if (index < 0):
        break;
    else:
      ans += 1;
      
print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		int n = sc.nextInt();
		if (d == 0) {
			if(n == 100) {
				System.out.println(101);
			}else {
				System.out.println(n);
			}
		}else if (d == 1) {
			if (n == 100) {
				System.out.println(10100);
			}else {
				System.out.println(n * 100);
			}
		}else {
			if (n == 100) {
				System.out.println(1010000);
			}else {
				System.out.println(n * 10000);
			}
		}
	}

}


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

namespace _20_0358
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] train = Console.ReadLine().Split(' ');
            int N = int.Parse(train[0]);
            int I = int.Parse(train[1]);

            Console.WriteLine(N - I + 1);
            Console.Read();
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N,K;
  int S = 0;
  cin >> N >> K;
int i = 0; // カウンタ変数
while (N > 0) {
  N /= K;
  i++;
}
  cout << i << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int mod=1e9+7;
int main() {
int n;
cin>>n;
bool flag=false;
for(int i=0;i<=n/4;i++){
   if((n-i*4)%7==0){
      flag=true;
      break;
   }
}
if(flag){
   cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;

}


Measured memory_bytes: 256
let () =
  let n = Scanf.scanf "%d\n" (fun x -> x) in
  let d = Array.make_matrix 4 3 (Array.make 10 0) in
  for i = 0 to 3 do
    for j = 0 to 2 do
      d.(i).(j) <- Array.make 10 0
    done
  done;
  for i = 1 to n do
    let b, f, r, v = Scanf.scanf "%d %d %d %d\n" (fun x y z w -> x-1, y-1, z-1, w) in
    d.(b).(f).(r) <- d.(b).(f).(r) + v
  done;

  let sF rs = Array.map string_of_int rs |> Array.to_list |> String.concat " " |> (^) " " in
  let sB fs = Array.map sF fs |> Array.to_list |> String.concat "\n" in
  let sD bs = Array.map sB bs |> Array.to_list |> String.concat "\n####################\n" in

  sD d |> Printf.printf "%s\n"

Measured memory_bytes: 2392
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] arrx = new long[N];
        long[] arry = new long[N];
        long[] arrh = new long[N];
        int si = -1;
        for(int i = 0; i < N; i++) {
            arrx[i] = sc.nextLong();
            arry[i] = sc.nextLong();
            arrh[i] = sc.nextLong();
            if(arrh[i] > 0) si = i;
        }

        long resx = -1, resy = -1, resh = -1;
        for(long x = 0; x <= 100; x++) {
            for(long y = 0; y <= 100; y++) {
                long h = arrh[si] + Math.abs(x-arrx[si]) + Math.abs(y-arry[si]);
                boolean ok = true;
                for(int i = 0; i < N; i++) {
                    if(arrh[i] > 0 && h - arrh[i] != Math.abs(x-arrx[i]) + Math.abs(y-arry[i]))
                        ok = false;
                    if (arrh[i] == 0 && h > Math.abs(x - arrx[i]) + Math.abs(y - arry[i]))
                        ok = false;
                }
                if(ok) {
                    resx = x;
                    resy = y;
                    resh = h;
                }
            }
        }
        System.out.println(resx + " " + resy + " " + resh);
    }
}


Measured memory_bytes: 40452
#include<bits/stdc++.h>
using namespace std;
long long n,m;
long long a[100010];
int main(){
	cin>>n>>m;
	a[0]=1;
	for(long long i=0;i<m;i++){
		int x;
		cin>>x;
		a[x]=-1;
	}
	for(long long i=1;i<=n;i++){
		if(a[i]!=-1){
			if(a[i-1]!=-1)
				a[i]+=a[i-1]%1000000007;
			if(a[i-2]!=-1)
				a[i]+=a[i-2]%1000000007;
		}
	}
	if(a[n]==-1)
		cout<<0;
	else
		cout<<a[n]%1000000007;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<ll, string> PLS;

ll a, b, c, d, e;
ll na, nb, nc;

int main(){
	while (cin >> a >> b >> c >> d >> e&&a + b + c + d + e){
		cin >> na >> nb >> nc;
		ll ans = a*na + b*nb + c*nc;
		if (na + nb + nc < d){
			ans = min(ans, d*e);
		}
		else{
			if (nc >= d){
				ans = e*nc + b*nb + a*na;
			}
			else if (nc + nb >= d){
				ans = min(ans, d*e + (nc + nb - d)*b + a*na);
			}
			else if (nc + nb + na >= d){
				ans = min(ans, d*e + (nc + nb + na - d)*a);
			}
		}
		cout << ans << endl;
	}
}

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

using namespace std;

int a[300010],b[300010];

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

    string s;
    cin >> s;

    for(int i=0;i<n;i++)
    {
        a[i+1] = s[i] == 'W' ? 1 : 0;
        b[i+1] = s[i] == 'E' ? 1 : 0;
    }

    a[0] = b[0] = a[n+1] = b[n+1] = 0;

    for(int i=1;i<=n;i++)
        a[i] += a[i-1];

    for(int i=n;i>0;i--)
        b[i-1] += b[i];

    int ans = 1e9;

    for(int i=1;i<=n;i++)
    {
        int temp = a[i-1] + b[i+1];

        if(ans > temp)
            ans = temp;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3076
"""
prd_xxx 様のコードを参考にさせていただきました。感謝です...！
https://beta.atcoder.jp/contests/abc076/submissions/1724160
"""

N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split()))

maxv = [0]
# グラフを整える準備
for v, t in zip(V, T):
    # 転換地点では低い方に合わせる
    maxv[-1] = min(maxv[-1], v)
    for ti in range(t * 2):
        maxv.append(v)

T = len(maxv)
# 前からグラフを整える
for i in range(T - 1):
    maxv[i + 1] = min(maxv[i+1], maxv[i] + 0.5)

maxv[-1] = 0
# 後ろからグラフを整える
for i in reversed(range(T-1)):
    maxv[i] = min(maxv[i], maxv[i + 1] + 0.5)

ans = 0
# 台形計算
for i in range(T-1):
    ans += (maxv[i] + maxv[i+1]) * 0.25
print(ans)


Measured memory_bytes: 3500
#include<iostream>
#include<string>
using namespace std;
int main() {
    int count[31] = { 0 }, n, i;
    for (i = 1; i <= 28; i++)
    {
        cin >> n;
        count[n] = 1;
    }
    for (i = 1; i <= 30; i++)
    {
        if (count[i] == 0)
        {
            cout << i << endl;
        }
    }
    return 0;
}

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

int main() {
    long long n,m;
    cin >> n >> m;

    long long ans;
    if (n == 1 && m == 1) ans = 1;
    else if (n == 1) ans = m - 2;
    else if (m == 1) ans = n - 2;
    else ans = (n - 2) * (m - 2);

    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace answer
{
    class Program
    {
        static void Main(string[] args)
        {
			var first = Console.ReadLine().Split(' ');
			List<string> kotae = new List<string>();
			foreach (var a in first[0])
			{
				kotae.Add(a.ToString());
			}

            string ans = "";
            if(kotae[2] == kotae[3] && kotae[4] == kotae[5])
            {
                ans = "Yes";
            }
            else
            {
                ans = "No";
            }
            Console.WriteLine(ans);
		}
    }
}

Measured memory_bytes: 13140
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//?????±????????????????´?
		ArrayList<String> list = new ArrayList<String>();
		while(true) {
			list.add(sc.nextLine());
			if(list.get(list.size() - 1).equals("0 0")) {
				break;
			}
		}
		
		//?????±???int???????????????2?¬?????????????????´???????
		int [][] data = new int[list.size() - 1][2];
		for(int i = 0; i < list.size() - 1; i++) {
			String s = list.get(i);
			String[] ary = s.split(" ");
			data[i][0] = Integer.parseInt(ary[0]);
			data[i][1] = Integer.parseInt(ary[1]);
		}
		
		//
		int answer = 0;
		for(int cntData = 0; cntData < data.length; cntData++) {
			for(int count1 = 1; count1 < data[cntData][0] - 1; count1++) {
				for(int count2 = count1 + 1; count2 < data[cntData][0] ; count2++) {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				}
			}
			System.out.println(answer);
			answer = 0;
		}
	}

}

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

int main()
{
	double a, b;
	double y;
	int x;
	cin >> a >> b;
	y = (a + b) / 2;
	x = (a + b) / 2;
	if (x == y)
	{
		cout << x << endl;
	}
	else
	{
		cout << x + 1 << endl;
	}
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

int n, k;
ll a[111111];

int main()
{
  while(cin >> n >> k, n){
    rep(i, n) cin >> a[i];

    rep(i, n - 1) a[i + 1] += a[i];

    ll res = a[k - 1];
    rrep(i, k, n) maxup(res, a[i] - a[i - k]);
    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 1948
import sys

def main():
    bingo = []
    for i in range(3):
        line = sys.stdin.readline().rstrip('\n').split()
        bingo.append(line[0])
        bingo.append(line[1])
        bingo.append(line[2])

    line = sys.stdin.readline().rstrip('\n')
    N = int(line)

    inputs = []
    for i in range(N):
        line = sys.stdin.readline().rstrip('\n')
        inputs.append(line)

    for i in [0, 3, 6]:
        if (bingo[i] in inputs) and (bingo[i+1] in inputs) and (bingo[i+2] in inputs):
            print('Yes')
            return

    for i in [0, 1, 2]:
        if (bingo[i] in inputs) and (bingo[i+3] in inputs) and (bingo[i+6] in inputs):
            print('Yes')
            return

    if (bingo[0] in inputs) and (bingo[4] in inputs) and (bingo[8] in inputs):
        print('Yes')
        return

    if (bingo[2] in inputs) and (bingo[4] in inputs) and (bingo[6] in inputs):
        print('Yes')
        return

    print('No')

main()


Measured memory_bytes: 2696
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int c[][] = new int[3][3];
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                c[i][j] = sc.nextInt();
            }
        }
        int sum1 = c[0][0] + c[1][1] + c[2][2];
        int sum2 = c[2][0] + c[0][1] + c[1][2];
        int sum3 = c[1][0] + c[2][1] + c[0][2];
        if(sum1 == sum2 && sum2 == sum3){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = (to) - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define all(v) v.begin(), v.end()
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int n;
  cin >> n;
  V<int> a(n);

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

  sort(a.rbegin(), a.rend());

  int a_score, b_score;
  a_score = b_score = 0;

  rep(i, n) {
    if(i % 2 == 0) {
      a_score += a[i];
    } else {
      b_score += a[i];
    }
  }

  cout << a_score - b_score << endl;
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		if(a%2 == 0 || b%2 == 0) {
			System.out.println("Even");
		}else {
			System.out.println("Odd");
		}
	}

}

Measured memory_bytes: 21204
S = input()
N = len(S)
zeroStart = 0
oneStart = 0
for i in range(N):
    if i%2 == 0:
        if S[i] == "1":
            zeroStart += 1
        else:
            oneStart += 1
    else:
        if S[i] == "1":
            oneStart += 1
        else:
            zeroStart += 1

print(min(zeroStart,oneStart))

Measured memory_bytes: 3188
import numpy as np
N,M = map(int,input().split())
LR = [list(map(int,input().split())) for i in range(M)]
LR = np.array(LR)

mini = max(LR[:,0])
maxi = min(LR[:,1])

if maxi-mini < 0:
    print(0)
else:
    print(maxi-mini+1)

Measured memory_bytes: 37900
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] T = new int[N];
		for (int i = 0; i < N; i++) {
			T[i] = sc.nextInt();
		}
		int M = sc.nextInt();

		int[] P = new int[M];
		int[] X = new int[M];
		int a =0;

		for (int i = 0; i < M; i++) {
			P[i] = sc.nextInt();
			X[i] = sc.nextInt();
		}

		for (int i = 0; i < M; i++) {

			for (int j = 0; j < N; j++) {
				
				if (P[i] == (j + 1)) {
					a = T[j];
					T[j] = X[i];
					int sum = 0;
					
					for (int k = 0; k < N; k++) {
						sum += T[k];
					}
					
					System.out.println(sum);
					T[j]=a;

				}
				
				else {
					// 何もしない
				}
			}

		}
	}
}


Measured memory_bytes: 10572