akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>

#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define IN(x) int (x); cin >> x
#define INS(x) string (s); cin >> s
#define INL(x) ll (x); cin >> x
#define VINT(a,n) vector<int> a(n)
#define VIN(a,n) VINT(a,n); REP(i,n){cin >> a[i];}
#define ALL(x) (x).begin(),(x).end()

const int MAX = 510000;
const int MOD = 1000000007;



// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}


long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}



// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


//

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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


int dfs(vector<vector<int> >& tree, vector<bool>& visited, int k, int current, int num){
  if (visited[current]){
    //    cout<<"ignore";
    return 1;
  }
  visited[current]=true;
  ll temp;
  if (current==0){
    temp=k;
    //    cout<<"hoge";
  }
  else if (find(tree[0].begin(), tree[0].end(), current)!=tree[0].end()){
    temp=k-num-1;
    //    cout<<"fuga";
  }
  else{
    temp=k-num-2;
  }
  int j=-1;
  REP(i,tree[current].size()){
    if(!visited[tree[current][i]]){
      j++;
      temp=(temp*dfs(tree, visited, k, tree[current][i], j))%MOD;
    }
  }
  //  cout<<temp<<' ';
  return temp;
}

int main () {
  IN(n);
  IN(k);

  vector<vector<int> > tree(n);
  
  int a, b;
  REP(i,n-1){
    cin>>a>>b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }

  vector<bool> visited(n, false);
  cout << dfs(tree, visited, k, 0, 0);
}


Measured memory_bytes: 11520
N=int(input())
A=list(map(int, input().split()))
A=sorted(A)
if A[0] == 0:
  print(0)
  exit(0)

ans = 1
for i in range(N):
  ans*=A[i]
  if(ans>1000000000000000000):
    print(-1)
    exit(0)
print(ans)

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

int main() {
	int n;
	cin >> n;
	string a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		set<char> s;
		s.insert(a[i]);
		s.insert(b[i]);
		s.insert(c[i]);
		ans += s.size() - 1;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 256
Md,MN=1000000007,1000006
fac,ifac,a,res,inv=[1,1],[1,1],[0],0,[1,1]
for i in range(2,MN):
    inv.append(inv[Md%i]*(Md-Md//i)%Md)
    fac.append(fac[-1]*i%Md)
    ifac.append(ifac[-1]*inv[i]%Md)
n=int(input())
for i in range(1,n):
    if i*2-n>=0:
        a.append(fac[i-1]*ifac[i+i-n]*fac[i]%Md)
    else:
        a.append(0)
for i in range(n-1,0,-1):
    a[i]=(a[i]-a[i-1])%Md
    res+=a[i]*i
res=res%Md
print(res)


Measured memory_bytes: 174616
N, T = map(int, input().split())
nums = list(map(int, input().split()))
INF = 10**10
min_num = INF
max_diff = 0
cnt = 0
for num in nums:
  if num-min_num > max_diff:
    cnt = 1
    max_diff = num-min_num
  elif num-min_num == max_diff:
    cnt += 1
  if num < min_num:
    min_num = num
print(cnt)


Measured memory_bytes: 62832
package main

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

func main() {
	n := nextInt()
	m := nextInt()
	var X, Y int
	for i := 0; i < n; i++ {
		x := nextInt()
		X += i*x - (n-(i+1))*x
	}
	for i := 0; i < m; i++ {
		y := nextInt()
		Y += i*y - (m-(i+1))*y
	}

	p := int(math.Pow10(9)) + 7
	fmt.Println((X % p) * (Y % p) % p)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


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

//プロトタイプ宣言
void printFormula(const vector<int>&, const bitset<3>);
int calc(const vector<int>&, const bitset<3>);


int main() {
  int n;
  cin >> n;
  const int ans = 7;
  vector<int> nums(4);
  for (int i = nums.size()-1; i >= 0; i--) {
    nums[i] = n % 10;
    n /= 10;
  }

  bitset<3> ops;
  bool flag;
  for (int tmp = 0; tmp < (1 << 3); tmp++) {
    bitset<3> b(tmp);
    if (calc(nums, b) == ans) {
      ops = b;
      flag = true;
      break;
    }
  }

  if (flag) {
    printFormula(nums, ops);
  }
}

void printFormula(const vector<int> &nums, const bitset<3> ops) {
  cout << nums[0];
  for(int i = 3-1; i >= 0; i--) {
    if (ops.test(i)) cout << "+";
    else cout << "-";
    cout << nums[3-i];
  }
  cout << "=7" << endl;
}

int calc(const vector<int> &nums, const bitset<3> b) {
  int ret = nums[0];
  for(int i = 3-1; i >= 0; i--) {
    if (b.test(i)) { //bのi桁目が1ならtrue
      ret += nums[3-i];
    }
    else {
      ret -= nums[3-i];
    }
  }

  return ret;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  string s;
  cin >> s;
  cout << (s <= "2019/04/30" ? "Heisei" : "TBD") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 1e5 + 5, MOD = 1e9 + 7;
int x[N], y[N], a[N], b[N], s[N], t[N];
vector<int> v[N];

void add(int &a, int b) {
	a += b;
	if (a >= MOD)
		a -= MOD;
}

void compress(int c[N], int len) {
	for (int i = 0; i < len; i++) {
		s[i] = c[i];
	}

	sort(s, s + len);

	int uniq_ct = unique(s, s + len) - s;
	for (int i = 0; i < len; i++) {
		c[i] = lower_bound(s, s + uniq_ct, c[i]) - s;
	}
}

int que(int x) {
	if (x < 0)
		return 1;
	int s = 0;
	for (; x >= 0; x = (x & (x + 1)) - 1)
		add(s, t[x]);
	add(s, 1);
	return s;
}

void upd(int x, int y) {
	for (; x < N; x |= x + 1) {
		add(t[x], y);
	}
}

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

    int n, m;
    cin >> n >> m;

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

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

    int len = 0;

    for (int i = 0; i < n; i++) {
    	int j = upper_bound(y, y + m, x[i]) - y;

    	if (j < m && j > 0) {
    		b[len] = y[j] - x[i];
    		a[len++] = x[i] - y[j - 1];
    	}
    }

    compress(a, len);
    compress(b, len);

    for (int i = 0; i < len; i++) {
    	v[a[i]].push_back(b[i]);
    }

    for (int i = 0; i < N; i++) {
    	sort(all(v[i]));
    	v[i].erase(unique(all(v[i])), v[i].end());
    	reverse(all(v[i]));
    }

    for (int i = 0; i < N; i++) {
    	for (int z : v[i]) {
    		upd(z, que(z - 1));
    	}
    }

    cout << que(N - 1);

    return 0;   
}

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

int main(){
	int w, a, b;
	scanf("%d%d%d", &w, &a, &b);
	if(a + w < b) printf("%d\n", b - a - w);
	else if(b + w < a) printf("%d", a - b - w);
	else printf("%d\n", 0);
}


Measured memory_bytes: 256
n = int(input().rstrip())
R = [0 for _ in range(n)]
for i in range(n):
    R[i] = int(input().rstrip())

margin = - 10**9
min_R = R[0]
for j in range(1, n):
    margin = max(margin, R[j] - min_R)
    min_R = min(min_R, R[j])

print(margin)


Measured memory_bytes: 13600
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,f,b;
  cin>>m>>f>>b;
  if(m>=b) cout<<"0"<<endl;
  else if(m+f>=b) cout<<b-m<<endl;
  else cout<<"NA"<<endl;
  return 0;
}



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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    a--;b--;c--;d--;
    string s;
    cin >> s;
    int32 cnt = 0;
    for(int32 sunuke = a; sunuke <= c; ++sunuke){
        if(s[sunuke] == '#'){
            cnt++;
            if(cnt > 1){
                Yes(false);
                return 0;
            }
        }else{
            cnt = 0;
        }
    }
    cnt = 0;
    for(int32 hunuke = b; hunuke <= d; ++hunuke){
        if(s[hunuke] == '#'){
            cnt++;
            if(cnt > 1){
                Yes(false);
                return 0;
            }
        }else{
            cnt = 0;
        }
    }
    if(c == d){
        Yes(false);
        return 0;
    }
    if(d < c){
        bool flg = false;
        int32 cnt = 0;
        for(int32 x = b-1; x <= d+1; ++x){
            if(s[x] == '#'){
                cnt = 0;
            }else{
                cnt++;
                if(cnt >= 3){
                    flg = true;
                    break;
                }
            }
        }
        if(!flg){
            Yes(false);
            return 0;
        }
    }
    Yes(true);
    return 0;
}

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

int main() {
  int D,N; 
  cin>>D>>N;
  if(D==0){
    if(N==100)cout<<101<<endl;
    else cout<<N<<endl;
    return 0;
  }
  
  else if(D==1){
    if(N==100)cout<<10100<<endl;
    else cout<<N*100<<endl;
    return 0;
  }
  
  else {
    if(N==100)cout<<1010000<<endl;
    else cout<<N*10000<<endl;
    return 0;
  }
    
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int x = (a + d - 1) / d;  //高橋君のモンスターの体力が0以下になる回数
  int y = (c + b - 1) / b;
  if (x >= y) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3588
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    vl h(n);
    ll maxh = 0;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
        chmax(maxh, h[i]);
    }
    ll ok = maxh / b + 1;
    ll ng = 0;
    auto check = [&](ll x) {
        ll requiredA = 0;
        for (int i = 0; i < n; ++i) {
            requiredA += max(0LL, h[i] - x * b + a - b - 1) / (a - b);
        }
        return requiredA <= x;
    };
    while (ng + 1 != ok) {
        ll mid = (ng + ok) / 2;
        if (check(mid))
            ok = mid;
        else
            ng = mid;
    }
    cout << ok << "\n";

    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int A[200007];
int SORT[200007];
int main()
{
    int N;

    scanf("%d\n", &N);
    for(int i=0; i<N; i++) scanf("%d\n", &A[i]);
    for(int i=0; i<N; i++) SORT[i]=A[i];

    sort(SORT, SORT+N, greater<>());
    for(int i=0; i<N; i++)
    {
        if(A[i]==SORT[0]) printf("%d\n",SORT[1]);
        else printf("%d\n",SORT[0]);
    }

    return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
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; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

int count(string a, string b) {
  int ret = 0;
  set<char> s;
  for (char c : a) {
    s.insert(c);
  }
  for (char c : s) {
    if (b.find(c) != std::string::npos) ret++;
  }
  return ret;
}


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

  int n;
  cin >> n;
  string s;
  cin >> s;

  int ans = 0;
  for (int i = 1; i < n; i++) {
    chmax(ans, count(s.substr(0, i), s.substr(i, n-i+1)));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
(let ((lst (loop :repeat 3 :collect (loop :repeat 3 :collect (read)))))
  (defun f (a b c d)
    (- (nth a (nth b lst)) (nth c (nth d lst))))
  (if (and (= (f 0 0 0 1) (f 1 0 1 1) (f 2 0 2 1))
           (= (f 0 1 0 2) (f 1 1 1 2) (f 2 1 2 2))
           (= (f 0 0 1 0) (f 0 1 1 1) (f 0 2 1 2))
           (= (f 1 0 2 0) (f 1 1 2 1) (f 1 2 2 2)))
      (princ "Yes")
      (princ "No")))

Measured memory_bytes: 5344
import java.util.Scanner;

public class Main {

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

        final String S = sc.next();

        int ans = 700;
        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) == 'o') ans += 100;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21460
a=(1..4).map{(1..3).map{[0]*10}}
gets.to_i.times{
b,f,r,v=gets.split.map &:to_i
a[b-1][f-1][r-1]+=v
}
4.times{|i|
3.times{|j| puts" #{a[i][j]*' '}"}
if i!=3
puts"#"*20
end
}

Measured memory_bytes: 8680
#include<stdio.h>
int N=100;

int main(){
  int M[N][N],n,a,b,c,i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)M[i][j] = 0;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    a--;
    for(j=0;j<b;j++){
      scanf("%d",&c);
      c--;
      M[a][c] = 1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j)printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");

  }
  return 0;
}



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

int main() {
	string a;
	string b;
  	int n=0;
	cin>>a;
	cin>>b;
  	for (int i=0;i<3;i++){
      	if (a.at(i)==b.at(i)){
          	n++;
        }
    }
  cout<<n;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
mod = 10 ** 9 + 7
ans = 0
N1 = 1
M1 = 1
cnt = 1
while True:
    cnt += 1
    if cnt <= N:
        N1 *= cnt
    if cnt <= M:
        M1 *= cnt
    N1 %= mod
    M1 %= mod
    if (cnt > M) and (cnt > N):
        break

if N == M - 1:
    ans = N1 * M1

elif N - 1 == M:
    ans = N1 * M1

elif N == M:
    ans = N1 * M1 * 2

else:
    ans = 0
ans %= mod
print(ans)

Measured memory_bytes: 3064
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <vector>
#define ll long long
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

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

    int n,b,sum;
    cin >> n;
    int a[100003];
    REP(i,100002) a[i] = 0;

    REP(i, n){
        cin >> b;
        a[b]++;
    }

    int mx = a[0] + a[1];
    RREP(i,1,100001){
        sum = a[i] + a[i-1] + a[i+1];
        mx = max(mx,sum);
    }

    cout << mx << endl;

    return 0;
}

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

int main(){
  std::string str;
  std::cin >> str;
  string ans;
  for (int i = 1; i <= 3; ++i){
    if(str[i] == str[i-1]){
      ans = "Bad";
      break;
    }else{
      ans = "Good";
    }
  }
  
  cout << ans <<endl;
  
  
  
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
	int n, x, i, j;
	char c[9], d[5];
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> x;
		cout << "Case " << i+1 << ":" << endl;
		for (j = 0; j < 10; j++)
		{
			x *= x;
			sprintf(c, "%08d", x);
			d[0] = c[2], d[1] = c[3], d[2] = c[4], d[3] = c[5], d[4] = '\0';
			x = atoi(d);
			cout << x << endl;
		}
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int a,b;
    char c;
    scanf("%d %c %d", &a, &c, &b);
    if(c=='+')
        printf("%d",a+b);
    else if (c=='-')
        printf("%d",a-b);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define P pair<int,int>
using namespace std;int main() {int a;while (scanf("%d", &a), a) {stack<P>b;for (int c = 1; c <= a; c++) {int d;scanf("%d", &d);if (c & 1){if (b.size() && b.top().second == d)b.top().first++;else b.push(P(1, d));}else {if (b.size() && b.top().second == d) {b.top().first++;}else {P x = b.top(); b.pop();P y = P(0, 0);if (b.size()) {y = b.top();b.pop();}b.push(P(x.first + y.first + 1, d));}}}int k = 0;while (b.size()) {P s = b.top(); b.pop();if (s.second == 0)k += s.first;}cout << k << endl;}}

Measured memory_bytes: 3144
#include <stdio.h>
#define min(a, b) ((a)<(b) ? (a) : (b))

int main(){
  int n, w_max, w[101], v[101];
  scanf("%d %d", &n, &w_max);
  for(int i=0; i<n; i++) scanf("%d %d", &w[i], &v[i]);

  int v_sum_max = n * 1000;
  long int dp[100001] = {};
  for(int i=1; i<=v_sum_max; i++)  dp[i] = w_max+1;

  for(int i=0; i<n; i++){
    for(int j=v_sum_max; j>=v[i]; j--){
      dp[j] = min(dp[j], dp[j-v[i]]+w[i]);
    }
  }

  int i;
  for(i=v_sum_max; dp[i]>w_max; i--);
  
  printf("%d\n", i);    

  return 0;
}


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

using namespace std;
typedef long long ll;

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

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> ab;
    rep(i, n)
    {
        ll a, b;
        cin >> a >> b;
        ab.push_back(make_pair(a, b));
    }

    sort(all(ab));
    ll ans = 0;
    rep(i, n)
    {
        if (m <= 0)
        {
            break;
        }
        if (ab[i].second <= m)
        {
            ans += ab[i].first * ab[i].second;
        }
        else
        {
            ans += ab[i].first * m;
        }
        m = max(0LL, m - ab[i].second);
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 5276
import math
import itertools
import statistics
n = int(input())
#n, d = list(input().split())
x = list(map(int, input().split()))
x.sort()
m = max(x)
total = [0]*m


for i in range(n):
    for p in range(1, m+1):
        total[p-1]+=abs(x[i]-p)*abs(x[i]-(p))
     
            
print(min(total))

Measured memory_bytes: 5276
#include <stdio.h>

int main() {
	
	char S[3];
	int k=0;
	for(int i=0; i<4; i++){
		scanf("%c", &S[i]);
		if(S[i]=='+'){
			k=k+1;
		}
		else if(S[i]=='-'){
			k=k-1;
		}	
	}
	printf("%d\n", k);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {

 /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
  */
    ios::sync_with_stdio(0);
    cin.tie(0);

    ll n;
    cin >> n;
    ll s_of_n = 0, s, temp = n;
    while (temp != 0) {
        s = temp % 10;
        s_of_n += s;
        temp /= 10;
    }
    if (n % s_of_n == 0)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void dfs(vector<set<int> > &graph,int s,vector<int> &vis,int &temp){
	temp++;
	vis[s]=1;
	set<int> :: iterator it=graph[s].begin();
	for(it=graph[s].begin();it!=graph[s].end();it++){
		if(vis[*it]==0){
			dfs(graph,*it,vis,temp);
		}
	}
}
int main() {
	int n,m;
	cin>>n>>m;
	vector<set<int> > graph(n+1);
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		graph[a].insert(b);
		graph[b].insert(a);
	}
    vector<int> vis(n+1,0);
    int ans=0;
    for(int i=1;i<=n;i++){
    	if(vis[i]==0){
    		int temp=0;
    		dfs(graph,i,vis,temp);
    		ans=max(ans,temp);
		}
	}
	cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 44616
a = int(input())
b = int(input())
c = int(input())
x = int(input())

l = []
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            l.append([i, j, k])
count = 0
for i in range(len(l)):
    sum = l[i][0] * 500 + l[i][1] * 100 + l[i][2] * 50
    if sum == x:
        count += 1
print(count)

Measured memory_bytes: 16500
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
long long mod = 1000000007;
long long power(long long m,long long n){
    long long res = 1;
    if(n > 0){
        res = power(m,n / 2);
        if(n % 2 == 0){
            res = (res * res) % mod;
        }
        else{
            res = (((res * res) % mod) * m) % mod;
        }
    }
    return res;
}
int main(){
  int n;
  cin >> n;
  map<int,int> count;
  for(int i = 0;i < n;i++){
    int num = 0;
    cin >> num;
    count[num]++;
  }
  bool can = true;
  for(int i = n - 1;i >= 0;i -= 2){
    if(i == 0){
      if(count[i] != 1)can = false;
    }
    else{
      if(count[i] != 2)can = false;
    }
  }
  if(!can)cout << 0 << endl;
  else cout << power(2,n / 2) << endl;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    int a, b;
    cin >> a >> b;
    int ans = 1;
    while (ans<=10000 && !((ans*8)/100==a && ans/10==b)) {
        ans ++;
    }
    if (ans>=10000) {
        cout << "-1" << endl;
        return 0;
    }
    
    cout << ans << endl;
    return 0;
}


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


int main()
{
     
    int k,i;
    cin>>k;
  string s;
  cin>>s;
  
  if(s.length()<=k)
     cout<<s;
     
     
  else
   {
       for(i=0;i<k;++i)
         cout<<s[i];
         
        cout<<"..."; 
          
   }
    
    return 0;    
        
} 



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int n,k,a[105]={0},x,y,sum=0;//a是用来记录每一个人有没有零食，x是人数，y是编号 
int main()
{
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{//k种零食
		cin>>x;
		for(int j=1;j<=x;j++)
		{//x个人有零食i
			cin>>y;
			a[y]=1;//记录有零食的人
		}
	}
	for(int i=1;i<=n;i++)
	{//找出没有零食的人
		if(a[i]==0)
		{
			sum++;
		}
	}
	cout<<sum;
}


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

vector<int> g[200'000];
int cnt[200'000];
int ans[200'000];

void dfs(int v, int from, int add) {
    if(ans[v] != -1) return;
    ans[v] += add + 1;
    for(auto && i : g[v]){
        if(i == from) continue;
        dfs(i, v, add + cnt[i]);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n, q;
    cin >> n >> q;
    for(int i = 0; i < n; ++i){
        ans[i] = -1;
    }
    for(int i = 0; i < n-1; ++i){
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    while(q--){
        int p, x;
        cin >> p >> x;
        --p;
        cnt[p] += x;
    }
    dfs(0, -1, cnt[0]);
    cout << ans[0];
    for(int i = 1; i < n; ++i){
        cout << " " << ans[i];
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 24064
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String forecast = s.next();
        String actual = s.next();

        int result = 0;
        for (int i = 0; i < 3; i++) {
            if (forecast.charAt(i) == actual.charAt(i)) result += 1;
        }
        System.out.println(result);
    }


}

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

ll solve() {
    ll Q;
    cin >> Q;
    vector<ll> L(Q), R(Q);
    for ( int i = 0; i < Q; i++ ) {
        cin >> L[i] >> R[i];
    }
    ll M = 1e5+1;
    vector<int> pr(M, 1), cpr(M+1);
    pr[0] = pr[1] = 0;
    for ( int i = 2; i < M; i++ ) {
        for ( int k = 2; i*k < M; k++ ) {
            pr[i*k] = 0;
        }
    }
    for ( int i = 1; i < M+1; i++ ) {
        cpr[i] = cpr[i-1];
        if ( i % 2 == 1 && pr[i] == 1 && pr[(i+1)/2] == 1) {
            cpr[i] += 1;
        }
    }
    vector<int> ans;
    for ( int i = 0; i < Q; i++ ) {
        ans.push_back(cpr[R[i]] - cpr[L[i]-1]);
    }
    for ( int i = 0; i < Q; i++ ) {
        cout << ans[i] << "\n";
    }
    return 0;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3448
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var x = IO.RInt;
            for (int i = 1; i < 100000; i++)
            {
                if (x * i % 360 == 0)
                {
                    WriteLine(i);
                    return;
                }
            }
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

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

int main() {
 int k,n;
  cin>>k>>n;
  vector<int>house(n);
  for(int i=0;i<n;i++){
  cin>>house.at(i);
   }
  house.push_back(house.at(0)+k);
  int l=0;
  for(int i=0;i<n;i++){
  l=max(l,house.at(i+1)-house.at(i));
  }
  cout<<k-l<<endl;
}

Measured memory_bytes: 4844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> L(M),R(M);
    for(int i=0;i<M;i++){
        cin>>L[i];
        cin>>R[i];
    }
    int R_min=0,L_max=0;
    L_max=*max_element(L.begin(),L.end());
    R_min=*min_element(R.begin(),R.end());
    if(R_min>=L_max){
        cout<<R_min-L_max+1<<endl;
    }else{
        cout<<0<<endl;
    }
}

Measured memory_bytes: 1024
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	length, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	array := strings.Split(sc.Text(), " ")

	counta := 0
	fix := true
	for fix {
		fix = false
		for i := 0; i <= length-2; i++ {
			val1, _ := strconv.Atoi(array[i])
			val2, _ := strconv.Atoi(array[i+1])
			if val1 > val2 {
				array[i], array[i+1] = array[i+1], array[i]
				counta++
				fix = true

			}

		}
	}

	fmt.Println(strings.Join(array, " "))
	fmt.Println(counta)
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define All(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
template<class T> T gcd(T a,T b) {return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b) {return a/gcd(a,b)*b; }
template<class T> bool isPrime(T num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (T i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

using namespace std;

ll a,b,n;

main()
{
    cin>>a>>b;
    cout<<(6-a-b)<<endl;
}

Measured memory_bytes: 256
package main

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

//const mod = 998244353

func main() {
	sc := newScanner(os.Stdin)
	N, M, K := sc.i(), sc.i(), sc.i()
	fac, ifac := factorial()
	sum := 0
	for k := 0; k <= K; k++ {
		com := combination(N-1, k, fac, ifac) * M % mod
		com = com * Pow(M-1, N-1-k) % mod
		sum = (sum + com) % mod
	}
	fmt.Println(sum)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

//func (m *math2) Pow(x, y int) int {
//	fx := float64(x)
//	fy := float64(y)
//	z := math.Pow(fx, fy)
//	return int(z)
//}
const mod = 998244353
const facNum = 300001

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}


Measured memory_bytes: 6660
N = int(input())

Lst = [x for x in range(1, int(N ** 0.5) + 1) if N % x == 0]

Mn = len(str(N))
for x in range(len(Lst)):
  A = Lst[x]
  B = int(N/Lst[x])
  Mx = max(len(str(A)),len(str(B)))
  if Mn > Mx:
    Mn = Mx

print(Mn)

Measured memory_bytes: 40048
#include<iostream>
#include<vector>
#include<algorithm>

#define REP(n) for(int i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 1000000005

int main(){

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

    ll ans = 0;
    for(int i = 0;i < n;i++){

        if(i == n-1){
            ans+=k;
        }else{
            ans += min(k,a[i+1]-a[i]);
        }
        //cout << ans << endl;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const ll INF = 1LL<<60;

int n,m,s,t;
vector<pair<int, ll>> adjS[100005], adjT[100005];
vector<ll> distS(100005, INF), distT(100005, INF);
vector<bool> visited(100005, false);

void dijkstraS(){
    priority_queue<pair<ll, int>> q;
    for(int i=1; i<=n; i++) visited[i] = false;

    q.push({0, s});
    distS[s] = 0;

    while(!q.empty()){
        pair<ll, int> f = q.top(); q.pop();
        int u = f.second;
        visited[u] = true;
        
        if(distS[u] < f.first*(-1)) continue;
        
        for(int i=0; i<adjS[u].size(); i++){
            int v =  adjS[u][i].first;
            if(visited[v] == true) continue;

            if(distS[v] > distS[u]+adjS[u][i].second){
                distS[v] = distS[u]+adjS[u][i].second;
                q.push({distS[v]*(-1), v});
            }
            
        }
    }
}

void dijkstraT(){
    priority_queue<pair<ll, int>> q;
    for(int i=1; i<=n; i++) visited[i] = false;

    q.push({0, t});
    distT[t] = 0;

    while(!q.empty()){
        pair<ll, int> f = q.top(); q.pop();
        int u = f.second;
        visited[u] = true;

        if(distT[u] < f.first*(-1)) continue;

        for(int i=0; i<adjT[u].size(); i++){
            int v = adjT[u][i].first;

            if(visited[v] == true) continue;
            if(distT[v] > distT[u]+adjT[u][i].second){
                distT[v] = distT[u]+adjT[u][i].second;
                q.push({-distT[v], v});
            }
        }


    }
    
}

int main(){
    cin >> n >> m >> s >> t;
    for(int i=0; i<m; i++){
        int u, v;
        ll a, b;
        cin >> u >> v >> a >> b;
        adjS[u].push_back({v, a});
        adjS[v].push_back({u, a});

        adjT[u].push_back({v, b});
        adjT[v].push_back({u, b});
    }

    dijkstraS();
    dijkstraT();

    ll money = 1e15;
    ll MAX = 0;
    vector<ll> ans(n+1);
    for(int i=n; i>0; i--){
        ll tmp = money-distS[i]-distT[i];
        MAX = max(MAX, tmp);
        ans[i] = MAX;
    }

    for(int i=1; i<=n; i++) cout << ans[i] << endl;
}



Measured memory_bytes: 19140
#include <bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
	scanf("%d%d",&a,&b);
	if(a<=0&&b>=0)
	{
		puts("Zero");
		return 0;
	}
	else if(a<0&&b<0)
	{
		if((b-a+1)&1) puts("Negative");
		else puts("Positive");
		return 0;
	}
	else if(a>0&&b>0)
	{
		puts("Positive");
		return 0;
	}
}

Measured memory_bytes: 256
package main

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


var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

func main() {
    sc.Split(bufio.ScanWords)
    n := nextInt()

    a := make([]int, n)
    for i := 0; i < n; i++ {
        tmp := nextInt()
        if tmp % 2 != 0 {
            fmt.Println(0)
            return
        }
        a[i] = tmp
    }

    times := 0
    for {
        times++
        for i := 0; i < n; i++ {
            a[i] = a[i] / 2
            if a[i] % 2 != 0 {
                fmt.Println(times)
                return
            }
        }
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h[ohara],w,x[ohara],y[ohara],sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rep(i,n)cin>>x[i]>>y[i]>>h[i];
    rep(cx,101){
        rep(cy,101){
            ll H=0;
            b=0;
            c=0;
            rep(i,n){
                if(h[i]==0)continue;
                if(!b){
                    b=1;
                    H=h[i]+abs(x[i]-cx)+abs(y[i]-cy);
                }
                if(b){
                    if(H!=h[i]+abs(x[i]-cx)+abs(y[i]-cy)){
                        c=1;
                        break;
                    }
                }
            }
            if(c)continue;

            c=0;
            rep(i,n){
                if(h[i]!=0)continue;
                if(0<=H&&H<=abs(x[i]-cx)+abs(y[i]-cy))continue;
                c=1;
            }
            if(c)continue;
            cout<<cx<<" "<<cy<<" "<<H<<"\n";
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
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; }


int main(){
    
    int N;
    long long W;
    long long w[110], v[110];
    long long dp[110][100100] = {0};
    cin >> N >> W;
    
    for(int i=0;i<N;i++) cin >> w[i] >> v[i];
    for(int i=0;i<N;i++){
        for(int j=0;j<=W;j++){
            chmax(dp[i+1][j],dp[i][j]);
            if(w[i]<=j) chmax(dp[i+1][j],dp[i][j-w[i]] + v[i]);
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 86272
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil {
    public static void Swap<T>(ref T a, ref T b){
        var t = a;
        a = b;
        b = t;
    }

    public static int[] ReadIntArray(){
        return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }

    public static long[] ReadLongArray(){
        return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class UnionFind {
    private int[] d;

    public UnionFind(int n){
        d = new int[n];
        for (int i = 0; i < n; i++){ d[i] = -1; }
    }

    public int find(int x){
        if (d[x] < 0){ return x; }
        return d[x] = find(d[x]);
    }

    public void unite(int x, int y){
        x = find(x); y = find(y);
        if (x == y){ return; }
        if (d[x] > d[y]){ Swap(ref x, ref y); }
        d[x] += d[y];
        d[y] = x;
    }

    public bool same(int x, int y){ return find(x) == find(y); }
    public int size(int x){ return -d[find(x)]; }
}

class Program {
    public static void Main(){
        Solve();
    }

    private static void Solve(){
        var t = ReadIntArray();
        int n = t[0];
        int m = t[1];

        var v = new Tuple<int, int>[m];
        for (int i = 0; i < m; i++){
            int a, b;
            var tt = ReadIntArray();
            a = tt[0]; b = tt[1];
            v[i] = Tuple.Create(a-1, b-1);
        }

        var uf = new UnionFind(n);

        var ans = new long[m];
        long curr = (long) n * (n - 1) / 2;
        int j = 0;
        ans[j++] = curr;

        for (int i = m - 1; i > 0; i--){
            int a = v[i].Item1;
            int b = v[i].Item2;
            if (! uf.same(a, b)){
                curr -= (long) uf.size(a) * uf.size(b);
                uf.unite(a, b);
            }
            ans[j++] = curr;
        }

        for (int i = m - 1; i >= 0; i--){
            WriteLine(ans[i]);
        }
    }
}


Measured memory_bytes: 22580
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////

LL a[100005];
LL b[100005];
LL c[100005];
LL dp[100005][3];

///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> b[i] >> c[i];
	}
    
    //dp[i][aktywnosc];
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;
    
    for(int i = 1; i <= n; i++){
		dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = c[i] + max(dp[i-1][1], dp[i-1][0]);
	}
	
	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
	
	
	return 0;
}


Measured memory_bytes: 4992
n = gets.to_s.to_i
s = gets.to_s.chomp

a = Array.new(3){0}
s.each_char do |c|
  a[c.ord%3] += 1
end

ans = a[0] * a[1] * a[2]
n.times do |j|
  
  (1...n).each do |t|
    i = j - t
    k = j + t
    break if i < 0 || n - 1 < k
    ans -= 1 if s[i] != s[j] && s[j] != s[k] && s[k] != s[i]
  end
end

puts ans

Measured memory_bytes: 14320
-- modules to import --
import Data.ByteString.Char8
import Data.Maybe
import Prelude

-- functions for this task --

read_Integer     = Prelude.fst . Data.Maybe.fromJust . Data.ByteString.Char8.readInteger
read_ListInteger = Prelude.map read_Integer . Data.ByteString.Char8.words

get_Integer     = read_Integer     <$> Data.ByteString.Char8.getLine
get_ListInteger = read_ListInteger <$> Data.ByteString.Char8.getLine

isMultiple :: Integer -> Integer -> Bool
isMultiple target base
        | mod target base == 0 = True
        | otherwise            = False

isEven :: Integer -> Bool
isEven target = isMultiple target 2

task_A :: [Integer] -> ByteString
task_A [a, b]
        | isEven (a * b) == True = Data.ByteString.Char8.pack $ "Even"
        | otherwise              = Data.ByteString.Char8.pack $ "Odd"

-- main process is below --

main :: IO ()
main = do

        -- STEP.01
        -- read out the given string
        [a, b] <- get_ListInteger

        -- STEP.02
        -- output the answer of this task
        Data.ByteString.Char8.putStrLn $ task_A $ [a, b]

-- End of this source code --

Measured memory_bytes: 380
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
ll n,m,cnt=1,ans,tot,bi[30],x[100010];
char ss[100010];
ll cal(ll k)
{
	ll s=1;
	while(!(k&1) && k)k/=2,s*=(ll)2; 
	return s;
}
struct tri
{
	int ch[1000010][2],v[1000010];
	void insert(int j)
	{
		int i,s,a,b,k;
		k=1;
		for(i=1;i<=j;i++)
		{
			b=x[i];
			if(!ch[k][b])ch[k][b]=++cnt;
			k=ch[k][b];
		}
		v[k]=1;
	}
	void ff(int k,int de)
	{
		if(v[k])return ;
		if(ch[k][0])ff(ch[k][0],de-1);
		else ans^=cal(de);
		if(ch[k][1])ff(ch[k][1],de-1);
		else ans^=cal(de);
	}
}tr;
int main()
{
	int i,s,a,b,j,k;
	scanf("%lld%lld",&n,&m);
	for(i=1;i<=n;i++)
	{
		scanf(" %s",ss);k=strlen(ss);
		for(s=1;s<=k;s++)x[s]=(ss[s-1]=='1');
		tr.insert(k);
	}
	tr.ff(1,m);
	if(ans)printf("Alice");
	else printf("Bob");
	return 0;
}

Measured memory_bytes: 7808