akhauriyash/Code-Regression huggingface dataset:
bingo = []
for i in range(3):
    bingo.append(list(map(int, input().split())))
n = int(input())
for i in range(n):
    b = int(input())
    for j in range(3):
        for k in range(3):
            if bingo[j][k] == b:
                bingo[j][k] = None
for i in range(3):
    row = True
    column = True
    for j in range(3):
        if bingo[i][j] != None:
            column = False
        if bingo[j][i] != None:
            row = False
    if column or row:
        print("Yes")
        exit()
naname = False
if bingo[0][0] == bingo[1][1] == bingo[2][2] == None or bingo[0][2] == bingo[1][1] == bingo[2][0] == None:
    naname = True
if row or column or naname:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38256
data = input().split()
N = int(data[0])
Y = int(data[1])

flag = False

for a in range(N + 1):
    if flag:
        break
    for b in range(N + 1 - a):
        if flag:
            break
        c = N - a - b
        if c < 0:
            continue
        elif a * 10000 + b * 5000 + c * 1000 == Y:
            print(str(a) + " " + str(b) + " " + str(c))
            flag = True

if flag == False:
    print("-1 -1 -1")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define YN(y, n, b) (b? y : n)
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N;
    cin >> N;
    i32 A, B;
    cin >> A >> B;
    Vec<i32> P(N);
    for (i32 i = 0; i < N; i++) cin >> P[i];
    Vec<i32> ans(3, 0);
    for (i32 i = 0; i < N; i++) {
        if (P[i] <= A) ans[0]++;
    }
    for (i32 i = 0; i < N; i++) {
        if (P[i] <= B) ans[1]++;
    }
    for (i32 i = 0; i < N; i++) {
        if (P[i] > B) ans[2]++;
    }
    cout << min(min(ans[0], ans[1] - ans[0]), ans[2]) << endl;
}


Measured memory_bytes: 3564
mod = 10**9+7
l = input()
k = len(l)
# ans = pow(3, k-1, mod)
ans = 0
cnt = 0
for i in range(k):
    if l[i] == "1":
        left = pow(2, cnt, mod)
        right = pow(3, (k-i-1), mod)
        ans += left*right % mod
        ans %= mod
        cnt += 1
ans += pow(2, cnt, mod)
ans %= mod
print(ans)

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

int main(){
    int n;
    int ans = 0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int a, b;
        scanf("%d%d",&a, &b);
        while(true){
            if(a < b){
                ans ^= 0;
                //printf("%d\n", 0);
                break;
            }else if(a%b == 0){
                ans ^= (a/b);
                //printf("%d\n", a/b);
                break;
            }else{
                int mm = ((a/b) + 1);
                if(((a%b) % mm) == 0){
                    ans ^= (a/b);
                    //printf("%d\n", a/b);
                    break;
                }else if((a%b) < mm){
                    a -= mm;
                }else{
                    a -= ((a%b) / mm) * mm;
                }
            }
        }
    }
    if(ans == 0){
        printf("Aoki\n");
    }else{
        printf("Takahashi\n");
    }
}


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

using namespace std;

const int MAX = 10001;
bool prime[MAX];
vector<int> V;
int ans[MAX];

void make(){

  fill(prime,prime+MAX,true);
  prime[0] = prime[1] = false;

  for(int i = 2; i < MAX; i++)
    if(prime[i])
      for(int j = 2; i*j < MAX; j++)
	prime[i*j] = false;

  for(int i = 0; i < MAX; i++)
    if(prime[i]) V.push_back(i);

  
  for(int i = 0; i < V.size(); i++)
    for(int j = 1; j < V.size()-i; j++){
      int now = 0;
      for(int k = i; k < i+j; k++)
	now += V[k];
      if(now < MAX) ans[now]++;
      else break;
    }
}

int main(){
  make();
  int in;
  while(cin >> in && in) cout << ans[in] << endl;
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<62) // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n;
    cin >> n;
    ll sum = 0;

    // a*b<nとなる正の整数(a,b)の組に対して、cは一意となる。
    // cが取りうる値は1~n-1である。
    // aを固定したとき、a*b<nを満たすようなbのとり方はfloor(n/a)通りある。
    // cは最小でも1以上必要なので、floor((n-1)/a)
    // aを1～n-1まで動かして和を取る。
    for(ll i=1; i<=n-1; i++) sum += (ll)floor((double)(n-1)/i);
    cout << sum << endl;
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(),v.end()
#define mem(v,x) memset(v,x,sizeof(v))
#define N 100005

using namespace std;

vector<int> v[N];
int dp[N];
int dfs(int node){
    if(dp[node]!=-1){
        return dp[node];
    }
    int ans = 0;
    for(int i=0;i<v[node].size();i++){
        ans = max(ans, 1+dfs(v[node][i]));
    }
    return dp[node] = ans;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        v[x].pb(y);
	}
	mem(dp,-1);
	for(int i=1;i<=n;i++){
        if(dp[i]==-1){
            dfs(i);
        }
	}
	cout<<*max_element(dp,dp+n+1);
	return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,A,a;
  cin >> N >> A;
  a = N / 500;
  if (A == 0){
    if (N % 500 == 0){
      cout << "Yes";
    } else {
      cout << "No";
    }
  }else{
    if (N < A) {
      cout << "Yes" << endl;
    }else{
      if (N - a * 500 < A ) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl ;
      }
    }
  }
  
  
  return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(ll i = 0; i < n; i += k)




int main() {
	ll a, b;
	cin >> a >> b;
	cout << a * b - a - b + 1 << endl;
}

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

using namespace std;

int main(void) {
	int x, y;
	cin >> x >> y;
	rep(i, x+1) {
		if (2 * i + 4 * (x - i) == y) {
			printf("Yes");
			return 0;
		}
	}
	printf("No");
}

Measured memory_bytes: 3680
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <iterator>
using namespace std;
#define MOD int(1e9 + 7)

struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    long long N, M;
    vector<long long> P;
    vector<vector<long long>> XY;

    cin >> N >> M;
    for (long long i = 0; i < N; i++)
    {
        long long t;
        cin >> t;
        t--;
        P.push_back(t);
    }
    for (long long i = 0; i < M; i++)
    {
        long long x, y;
        cin >> x >> y;
        x--;
        y--;
        XY.push_back(vector<long long>{x, y});
    }

    UnionFind uf(N);
    for (long long i = 0; i < M; i++)
        uf.unite(XY[i][0], XY[i][1]);
    for (long long i = 0; i < N; i++)
        uf.root(i);

    vector<vector<long long>> u(N, vector<long long>{});
    for (long long i = 0; i < N; i++)
        u[uf.par[i]].push_back(i);

    long long count = 0;
    for (long long i = 0; i < N; i++)
    {
        vector<long long> t;
        for (auto x : u[i])
            t.push_back(P[x]);
        sort(t.begin(), t.end());

        vector<long long> inter;
        set_intersection(t.begin(), t.end(),
                         u[i].begin(), u[i].end(),
                         inserter(inter, inter.end()));

        count += inter.size();
    }

    cout << count << endl;
}

Measured memory_bytes: 12652
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int n, m, x;
vector<int> c;
vector<vector<int>> a;
const int INF = 1000000000;

int bit_search(int bit) {
  int sum_c = 0;
  vector<int> _x(m);
  
  for (int i = 0; i < n; ++i) {
    if (bit & (1<<i)) {
      sum_c += c[i];
      for (int j = 0; j < m; ++j) {
        _x[j] += a[i][j];
      }
    }
  }
    
  bool ok = true;
  for (int i = 0; i < m; ++i) {
    if (_x[i] < x) ok = false;
  }
  if (ok) return sum_c;
  else return -1; 
}

int main() {
  cin >> n >> m >> x;
  c.resize(n);
  a.resize(n);
  for(int i = 0; i < n; ++i) {
    a[i].resize(m);
  }
  for(int i = 0; i < n; ++i) {
    cin >> c[i];
    for(int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }

  int ans = INF;
  for (int bit = 0; bit < (1<<n); ++bit) {
    int tmp = bit_search(bit);
    if (tmp == -1) continue;
    ans = min(ans, tmp);
  }

  if (ans == INF) cout << "-1" << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	An := make([]int, N)
	// ans := big.NewInt(1)
	for i := range An {
		An[i] = nextInt()
		if An[i] == 0 {
			fmt.Println(0)
			return
		}
	}
	ans := big.NewInt(int64(An[0]))
	for i := 1; i < N; i++ {
		num := ans.Mul(ans, big.NewInt(int64(An[i])))
		if num.Cmp(big.NewInt(int64(1e18))) == 1 {
			fmt.Println(-1)
			return
		}
		ans = num
	}
	fmt.Println(ans)
}

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

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

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 6216
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n; cin>>n;
  int a[201];
  for(int i=0; i<2*n; i++) cin>>a[i];
  sort(a, a+2*n);
  int ans=0;
  for(int i=0; i<2*n; i+=2) ans+=a[i];
  cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

int height(int H, int cx, int cy, int x, int y){
    return max(H-abs(x-cx)-abs(y-cy), 0);
}

void solve(){
    int N;
    cin >> N;

    vi x(N), y(N), h(N);
    int idx=-1;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> h[i];
        if (h[i] != 0 && idx == -1) {
            idx = i;
        }
    }

    for (int cx = 0; cx <= 100; cx++) {
        for (int cy = 0; cy <= 100; cy++) {
            int H = h[idx] + abs(x[idx]-cx) + abs(y[idx]-cy);
            bool truth=true;
            for (int i = 0; i < N; i++) {
                if (h[i] != height(H, cx, cy, x[i], y[i])) {
                    truth = false;
                    break;
                }
            }
            if (truth) {
                cout << cx << " " << cy << " " << H << endl;
            }
        }
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
N , M = map(int,input().split())
edge = []
for _ in range(M):
    a ,b = map(int ,input().split())
    a , b = a - 1 , b - 1
    edge.append((a,b))

def root(a):
    if parent[a] == a:
        return a
    else:
        parent[a] = root(parent[a])
        return parent[a]

def is_same(a,b):
    return root(a) == root(b)

def unite(a , b):
    ra = root(a)
    rb = root(b)
    if ra == rb:
        return
    parent[ra] = rb

ans = 0
for i in range(M):
    parent = [k for k in range(N)]
    for j , e in enumerate(edge):
        if j == i:
            continue
        a , b = e
        unite(a , b)
    a , b = edge[i]
    if not is_same(a , b):
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int main() {
  int z, A, B;
  scanf("%d %d %d", &z, &A, &B);
  int distA = (z > A) ? z - A : A - z;
  int distB = (z > B) ? z - B : B - z;
  (distA < distB) ? puts("A") : puts("B");
  return 0;
}

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

int poww(int base, int exponent){
    long long cp = 1;
    //------
    while (exponent--) {
        cp *= base;
        cp %= 998244353;
    }
    return (int)cp;
}

int main(){
    int n,c=0;
    long long ans=1;
    cin>>n;
    int t[n],pos[n];
    fill(pos,pos+n,0);
    for (int i=0;i<n;i++){
        cin>>t[i];
    }
    if (t[0]!=0){
        cout<<'0';
        return 0;
    }
    for (int i=0;i<n;i++){
        pos[t[i]]+=1;
        c=max(c,t[i]);
    }
    for (int i=0;i<c;i++){
        ans=ans*(poww(pos[i],pos[i+1]));
        //-------
        ans %= 998244353;
    }
    if (pos[0]!=1) cout<<'0';
    else cout<<ans;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin >> n;
    vector<int> v(n);
    REP(i,n){
        scanf("%d", &v[i]);
    }

    vector<int> dp(n,inf);
    dp[0]=v[0];
    int l = 1;
    FOR(i,1,n){
        if(v[i]>dp[l-1]){
            dp[l]=v[i];
            l++;
        }else{
		    *lower_bound(dp.begin(), dp.end(), v[i]) = v[i];
        }
    }
   
    cout << l << endl;
    return 0;
}



Measured memory_bytes: 3648
N, M = map(int, input().split())
left=0
right=N

for i in range(M):
    L, R = map(int, input().split())
    if L > left:
        left = L
    if R < right:
        right = R

if left <= right:
    print(right-left+1)
else:
    print(0)

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int main() {
    string s; cin >> s;
    string ans = "";
    rep(i, s.size()) {
        ans += 'x';
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
const int N = 3e5;
int a[N], b[N];

struct data 
{
	int id;
	bool operator < (const data &other) const
	{
		return b[id] < b[other.id];
	}
};

int main()
{
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &b[i]);
	std::priority_queue<data> q;
	for (int i = 1; i <= n; ++i)
		if (b[i] > a[i])
			q.push({i});
	long long res = 0;
	while (!q.empty())
	{
		int x = q.top().id;
		q.pop();
		int prv = x > 1 ? x - 1 : n;
		int nxt = x < n ? x + 1 : 1;
		int sum = b[prv] + b[nxt];
		int cnt = (b[x] - a[x]) / sum;
		if (cnt == 0)
			break;
		res += cnt;
		b[x] -= sum * cnt;
		if (b[x] > a[x])
			q.push({x});
	}
	for (int i = 1; i <= n; ++i)
		if (a[i] != b[i])
		{
			printf("-1");
			return 0;
		}
	printf("%lld\n", res);
}

Measured memory_bytes: 2936
N = gets.to_i
towns = gets.split.map(&:to_i)
fighters = gets.split.map(&:to_i)

counter = 0
f = fighters.count
f.times do |i|
  index = f - i - 1

  if fighters[index] > towns[index + 1]
    counter += towns[index + 1]
    fighters[index] -= towns[index + 1]
    if fighters[index] <= towns[index]
      counter += fighters[index]
      towns[index] = (towns[index] - fighters[index]).abs
    else
      counter += towns[index]
      towns[index] = 0
    end
  else
    counter += fighters[index]
  end
end
puts counter

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

string tasu(string& a, string& b) {
    string s = "";
    if (a.size() < b.size()) swap(a, b);
    int prev = 0;
    for (int i = 1; i <= a.size(); i++) {
        int ac, bc, sum;
        ac = a[a.size()-i] - '0';
        if (b.size() < i) {
            bc = 0;
        } else {
            bc = b[b.size() - i] - '0';
        }
        sum = ac + bc + prev;
        prev = 0;
        if (sum >= 10) {
            prev = 1;
            sum -= 10;
        }
        s.push_back(sum + '0');
    }
    if (prev) s.push_back('1');
    reverse(s.begin(), s.end());
    if (s.size() > 80) s = "overflow";
    return s;
}

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; i++) {
        string a, b;
        cin >> a >> b;
        cout << tasu(a, b) << endl;
    }
    return 0;
}

Measured memory_bytes: 0
import java.util.*;

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        g = new ArrayList[n];

        for (int i=0; i<n; i++){
            g[i] = new ArrayList<>();
        }

        for (int i=0; i<m; i++){
            int u = sc.nextInt()-1;
            int v = sc.nextInt()-1;
            g[u].add(v);
        }

        prev = new int[n][n];
        dist = new int[n][n];
        int ucycle = -1; int dmin = n+1;

        for (int i=0; i<n; i++){
            Arrays.fill(prev[i], -1);
            Arrays.fill(dist[i], -1);
            int d = bfs(i);
            if (0 < d && d < dmin){
                ucycle = i;
                dmin = d;
//                break;
            }
        }
        if (ucycle==-1){
            System.out.println(-1);
        }
        else{
            StringBuilder sb = new StringBuilder();
            sb.append(dmin+"\n");
            ArrayList<Integer> list = new ArrayList<>();
            int i = prev[ucycle][ucycle];
            while (i!=ucycle){
                list.add(i);
                i = prev[ucycle][i];
            }
            list.add(ucycle);
//            Collections.reverse(list);
            for (int v: list){
                sb.append((v+1)+"\n");
            }
            System.out.println(sb.toString());
        }



    }

    static ArrayList<Integer>[] g;
    static int[][] prev;
    static int[][] dist;

    static int bfs(int i){
        LinkedList<Integer> list = new LinkedList<>();
        list.add(i);
        dist[i][i] = 0;
        while (!list.isEmpty()){
            int u = list.poll();
            for (int v: g[u]){
                if (v==i){
                    prev[i][i] = u;
                    return dist[i][u]+1;
                }else if (dist[i][v]<0){
                    dist[i][v] = dist[i][u]+1;
                    prev[i][v] = u;
                    list.add(v);
                }
            }
        }
        return -1;
    }
}

Measured memory_bytes: 65780
#include <iostream>
 
using namespace std;
 
int main(void) {
  int a, b, c;
  cin >> a >> b;
  c = 0;
  if (a >= 13) {
    c = b;
  } else if (a >= 6) {
    c = b / 2;
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<ll, pair<ll, ll>> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, k;

    cin >> n >> k;

    if ((ll)n * k > (ll)(1 + n) * n / 2)
    {
        cout << -1 << endl;
        return 0;
    }

    ll mx3 = (ll)k + (ll)n * 3 - 1;
    ll mx2 = (ll)k + (ll)n * 2 - 1;
    ll mx1 = (ll)k + (ll)n * 1 - 1;

    ll v2 = mx2;
    ll v1 = mx3 - v2;

    vector<P> v;

    for (int i = 0; i < n; i++)
    {
        v.push_back({v2 + v1, {v1, v2}});

        v2--;
        v1--;

        if (v1 < k)
            v1 += n;
    }

    SORT(v);

    for (int i = 0; i < n; i++)
        cout << v[v.size() - 1 - i].second.first << " " << v[v.size() - 1 - i].second.second << " " << mx3 - i << endl;

    return 0;
}

Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  int N,K;
  cin >> N >> K;
  vector<i64> h(N);
  rep(i,0,N -1 ) cin >> h[i];
  sort(begin(h),end(h));
  i64 ans = h.back() - h.front();
  for(int i = 0;i + K - 1 < N;i++){
    ans = min(ans , h[i + K - 1] - h[i]);
  }
  cout<< ans << endl;
}


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

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll x = min(N, B - 1);
  ll y = floor((A * x) / B);
  ll z = A * floor(x / B);
  ll result = y - z;
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cstring>

using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    
    int n,m,x = 0;
    cin  >> n >> m >> x;
    
    bool check[n];
    for(int i = 0; i < n+1; i++) check[i] = false;
    
    for(int i = 0; i < m; i++){
        int temp;
        cin >> temp;
        check[temp] = true;
    }
    
    int left = 0, right = 0;
    for(int i = x; i > 0; i--){
        if (check[i]) left++;
    }
    
    for(int i = x; i < n; i++){
        if (check[i]) right++;
    }
    
    cout << min(left,right) << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
vi a;

int main(){
	cin>>n>>m;
	a=vi(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		m-=a[i];
	}
	sort(a.begin(),a.end());
	cout<<n+m/a[0]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

vector<ll> enum_divisors(ll N){
    vector<ll> res;
    for (ll i = 1; i * i <= N; ++i){
        if (N % i == 0){
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }

    sort(res.begin(), res.end());
    return res;
}

int main(){
    ll N, M; cin >> N >> M;

    ll ans = 0;
    vector<ll> divisors = enum_divisors(M);
    for (ll divisor : divisors){
        if (divisor * N <= M){
            ans = divisor;
        }
    }

    cout << ans << endl;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> v {a, b, c};
  sort(v.begin(), v.end());
  if (v[0] == 5 && v[1] == 5 && v[2] == 7)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MAXN 200009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
set<int>s;
int cnt[MAXN];
int main(){
    //~ freopen("file.in", "r", stdin);
    int n,k;
    scanf("%d%d",&n,&k);
    while(n--){
		int x;
		scanf("%d",&x);
		cnt[x]++;
		s.insert(x);
	}
	if((int)s.size()<=k){
		puts("0");
		return 0;
	}
	vector<PII>v;
	tr(it,s)
		v.pb(mp(cnt[*it],*it));
	sort(all(v));
	int ans=0;
	for(int i=0;i<int(v.size())-k;i++)
		ans+=v[i].ff;
	printf("%d\n",ans);	
	return 0;
}


Measured memory_bytes: 12536
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<string>
#include<set>
#include<cstdlib>

using namespace std;
typedef long long ll;

int main() {
  int x,n;
  cin >> x >> n;
  int pi;
  vector<int> p(n);
  for(int i=0;i<n;++i){
	cin >> p[i];
  }

  if(n==0){
    cout<<x<<endl;
    return 0;
  }
  sort(p.begin(),p.end());
  int m1,m2;
  int j=0;
  m1=200;
  int ib;
  for(int i=0;i<103;++i){
    if(p[j]==i){
      j++;
      continue;
    }
    m2 = abs(x-i);
    //cout<<i<<" "<<m2<<endl;
    if(m2>=m1){
      cout<<ib<<endl;
      return 0;
    }
    m1 = m2;
    ib = i;
  }
  
}

Measured memory_bytes: 3628
mod = 10 ** 9 + 7

N, M = map(int, input().split())
S = input().split()
T = input().split()

dp = [[0] * (M + 1) for _ in range(N + 1)]
dp[0][0] = 1

for i in range(N + 1):
    for j in range(M + 1):
        if 1 <= i and 1 <= j and S[i - 1] == T[j - 1]:
            dp[i][j] += dp[i - 1][j - 1]
        if 1 <= i:
            dp[i][j] += dp[i - 1][j]
        if 1 <= j:
            dp[i][j] += dp[i][j - 1]
        if 1 <= i and 1 <= j:
            dp[i][j] -= dp[i - 1][j - 1]
        dp[i][j] %= mod

print(dp[N][M])


Measured memory_bytes: 73052
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

A,B = list(map(float,input().split()))
B = int(B*100+0.1)
A = int(A)
ans = A*B//100
print(ans)


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define MAX_N 510
int n,s;
int lft[MAX_N], rig[MAX_N];
pii rsort[MAX_N];
int g[MAX_N][MAX_N];

struct state{int pos,tme,val;};
bool operator<(state a,state b){
  if(a.tme != b.tme) return a.tme > b.tme; // swap
  if(a.val != b.val) return a.val < b.val;
  return a.pos < b.pos;
}

int dp[MAX_N];

int main(){
  cin>>n>>s;
  --s;
  REP(i,n){
    cin >> lft[i] >> rig[i];
  }
  REP(i,n)REP(j,n){
    cin>>g[i][j];
  }
  // WF
  REP(k,n)REP(i,n)REP(j,n) g[i][j] = min(g[i][j],g[i][k]+g[k][j]);

  // ending sort
  REP(i,n){
    rsort[i] = make_pair<int,int>(rig[i], i);
  }
  sort(rsort,rsort+n);
  // dp
  REP(i,n) dp[i] = -1000000000;
  REP(i,n){
    int pos = rsort[i].second;
    // from start point
    dp[pos] = max(dp[pos], rig[pos] - max(g[s][pos], lft[pos]));
    // from before point
    REP(j,i){
      int from = rsort[j].second;
      dp[pos] = max(dp[pos], dp[from] + rig[pos] - max(rig[from] + g[from][pos], lft[pos]));
    }
  }
  int result = 0;
  REP(i,n)result = max(result,dp[i]);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 2172
w,h,n = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(n)]
a = 0
b = 0
for i in range(n):
    if ls[i][2] == 1:
        if ls[i][0] > a:
            a = ls[i][0]
    elif ls[i][2] == 2:
        if ls[i][0] < w:
            w = ls[i][0]
    elif ls[i][2] == 3:
        if ls[i][1] > b:
            b = ls[i][1]
    else:
        if ls[i][1] < h:
            h = ls[i][1]
if (a < w) and (b < h):
    print((w-a)*(h-b))
else:
    print(0)

Measured memory_bytes: 3064
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
left = 0
right = sum(A)
MIN = float('inf')
for i in range(n-1):
    left += A[i]
    right -= A[i]
    #print(left, right)
    MIN = min(MIN,abs(left - right))
print(MIN)


Measured memory_bytes: 33360
import java.io.*;

public class Main{
    public static void main(String[]args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String crlf = System.getProperty("line.separator");
       
    
        
        while(true){
            String[] str = br.readLine().split(" ");
            int h = Integer.parseInt(str[0]);
            int w = Integer.parseInt(str[1]);
           
            if(h==0 && w==0){
                break;
            }else{
                for(int i=0;i<h;i++){
                    for(int j=0;j<w;j++){
                        System.out.print("#");
                    }
                    System.out.println();
                }
                
            }
            System.out.println();
        }
        
        
        
        
    }
}

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

int main() {
	int a, b;
	int mini = 100000;
	int ans = 0;
	cin >> a >> b;


	for (int i = 0; i < a; i++) {
		int c;
		cin >> c;
		b -= c; ans++;
		if (mini > c) {
			mini = c;
		}
	}
	while(b >= mini) {
		b -= mini; ans++;
	}

	cout << ans << endl;

	//getchar();
	//getchar();

	return 0;

}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;
import java.util.LinkedList;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        LinkedList<Integer> list = new LinkedList<Integer>();
        for (int i = 0; i < n; i++){
            list.add(sc.nextInt());
        }
        sc.close();
        InsertionSort(list);
    }
    
    static void InsertionSort(LinkedList<Integer> list){
        int key = 0;
        PrintList(list);
        for (int i = 1; i < list.size(); i++){
            key = list.get(i);
            int j = i - 1;
            while (j >= 0 && list.get(j) > key){
                swap(list, j+1, j);
                j--;
            }
            list.set(j+1 , key);
            PrintList(list);
        }
        
    }
    static void swap(LinkedList<Integer> list, int from, int to){
        int temp = list.get(from);
        list.set(from,list.get(to));
        list.set(to, temp);
     }
    static void PrintList(LinkedList<Integer> list){
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < list.size(); i++){
            sb.append(list.get(i)+" ");
        }
        System.out.println(sb.deleteCharAt(sb.length()-1));
        
    }
}

Measured memory_bytes: 24352
/*

*/
#include <bits/stdc++.h>

using namespace std;

#define ll           long long int
#define mp           make_pair
#define pb           push_back
#define fi           first
#define si           second
#define fastIO       ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F(a,n)       for(int i=0;i<n;i++){cin>>a[i];}
#define F1(a,n)      for(int i=1;i<=n;i++){cin>>a[i];}
#define P(a,n)       for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define P1(a,n)      for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;
#define NF(a,n,m)    for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}
#define NF1(a,n,m)   for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}
#define PNF(a,n,m)   for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define PNF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
const int nax = 1e5;
const int mod = 1e9+7;



int main(){
fastIO
	ll n, ans = 0;
	cin>>n;
	map<ll, ll> m;
	for(ll i=0; i<n; i++){
		ll temp;
		cin>>temp;
		if(m.count(temp) == 0){
			m[temp] = 1;
		}
		else{
			m[temp]++;
		}
	}
	for(auto x:m){
		ans +=  (x.si < x.fi) ? (x.si) : (x.si - x.fi);
	}
	cout<<ans;
}

Measured memory_bytes: 9592
import math
a,b,x=map(int,input().split())

bottle=(a**2)*b
#空間が三角柱か四角柱の境目の時の角度r
r=b/a

theta=2*(bottle-x)/(a**3)
theta=math.degrees(math.atan(theta))

if 2*x>(a**2)*b:
    print(theta)
else:
    theta=(a*(b**2))/(2*x)
    print(math.degrees(math.atan(theta)))

Measured memory_bytes: 9268
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

x,y = inpl()
ans = 0
if abs(x) < abs(y):
	if x < 0:
		ans += 1
	ans += abs(y)-abs(x)
	if y < 0:
		ans += 1

elif abs(x) == abs(y):
	ans = 1

else:#abs(x) > abs(y)
	if x > 0:
		ans += 1
	ans += abs(x)-abs(y)
	if y > 0:
		ans += 1

print(ans)


Measured memory_bytes: 4212
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    int h, w;
    cin >> h >> w;

    rep(i, h){
        rep(j, w){
            string s;
            cin >> s;

            if(s=="snuke"){
                char res = 'A' + j;
                cout << res << i+1 << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

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

        int N = sc.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        int[] h = new int[N];
        for (int i = 0; i < N; ++i) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            h[i] = sc.nextInt();
        }

        System.out.println(solve(x, y, h));

        sc.close();
    }

    static String solve(int[] x, int[] y, int[] h) {
        int nonZeroHeightIndex = IntStream.range(0, h.length).filter(i -> h[i] != 0).findAny().orElse(-1);

        for (int cx = 0;; ++cx) {
            for (int cy = 0; cy <= 100; ++cy) {
                int height = (nonZeroHeightIndex == -1) ? 1
                        : Math.abs(x[nonZeroHeightIndex] - cx) + Math.abs(y[nonZeroHeightIndex] - cy)
                                + h[nonZeroHeightIndex];
                if (check(x, y, h, cx, cy, height)) {
                    return String.format("%d %d %d", cx, cy, height);
                }
            }
        }
    }

    static boolean check(int[] x, int[] y, int[] h, int cx, int cy, int height) {
        return IntStream.range(0, x.length)
                .allMatch(i -> Math.max(height - Math.abs(x[i] - cx) - Math.abs(y[i] - cy), 0) == h[i]);
    }
}

Measured memory_bytes: 40244
import java.util.Scanner;

public class Main {

	private static Scanner mScanner;

	public static void main(String[] args) {

		mScanner = new Scanner(System.in);

		//料理の種類の合計をセット
		int intDishTotal = mScanner.nextInt();

		//食べた料理の順番をセット
		int[] intArrEatOrder = CreateArrayFromInput(intDishTotal);

		//各料理の満足度Bをセット
		int[] intArrSatisfactionB = CreateArrayFromInput(intDishTotal);

		//各料理の満足度Cをセット
		int[] intArrSatisfactionC = CreateArrayFromInput(intDishTotal - 1);

		//満足度合計
		int intSatisFactionSum = 0;

		//料理No.履歴（前回食べた料理No.）
		int intDishNoHistory = 0;

		for(int i = 0; i < intArrEatOrder.length; i++) {

			//料理No.を取得
			int intDishNo = intArrEatOrder[i];

			//満足度Bを追加
			intSatisFactionSum += intArrSatisfactionB[intDishNo - 1];

			if(intDishNoHistory != 0 && intDishNoHistory == (intDishNo - 1)) {

				//満足度Cを追加
				intSatisFactionSum += intArrSatisfactionC[intDishNoHistory - 1];
			}

			//料理No.履歴を更新
			intDishNoHistory = intDishNo;

		}

		//アウトプット
		System.out.println(intSatisFactionSum);

	}

	//-----------------------------------------------------------
	//	コンソールで入力した値から配列を生成する
	//-----------------------------------------------------------
	private static int[] CreateArrayFromInput(int intInCount) {

		int[] intArrRet = new int[intInCount];

		for (int i = 0; i < intInCount; i++) {
			intArrRet[i] = mScanner.nextInt();
		}

		return intArrRet;
	}

}


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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n, x;
    cin >> n >> x;
    vec l(n);
    init(l);
    int now = 0;
    int time = 1;
    rep (i, n) {
        now += l[i];
        if (now <= x) time++;
    }
    print(time);

    return 0;
}


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

int main(){
  int a, b, c[5] = {0};
  for(int i = 0; i < 3; i++){
    cin >> a >> b;
    c[a] += 1;
    c[b] += 1;
  }
  if(c[1] == 1 && c[2] == 1 && c[3] == 2){
    cout << "YES" << endl;
  }else if(c[1] == 1 && c[2] == 2 && c[3] == 2){
    cout << "YES" << endl;
  }else if(c[1] == 2 && c[2] == 2 && c[3] == 1){
    cout << "YES" << endl;
  }else if(c[1] == 2 && c[2] == 1 && c[3] == 2){
    cout << "YES" << endl;
  }else if(c[1] == 2 && c[2] == 1 && c[3] == 1){
    cout << "YES" << endl;
  }else if(c[1] == 1 && c[2] == 2 && c[3] == 1){
    cout << "YES" << endl;
  }else{
    cout <<"NO" << endl;
  }
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

struct unionFind {
    int elements = 0;
    vector<int> Par, Rank_p;
    unionFind(int n) : Par(n), Rank_p(n) {
        for (int id = 0; id < n; id++) {
            elements   = n;
            Par[id]    = id;
            Rank_p[id] = 0;
        }
    }
    int find(int x) {
        if (Par[x] == x)
            return x;
        else
            return Par[x] = find(Par[x]);
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (Rank_p[x] < Rank_p[y])
            Par[x] = y;
        else {
            Par[y] = x;
            if (Rank_p[x] == Rank_p[y]) Rank_p[x]++;
        }
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int groups() {
        set<int> se;
        for (auto x : Par) {
            se.insert(x);
        }
        return se.size();
    }
};

int main() {
    int n;
    cin >> n;
    bool all_even = true;
    rep(i, n) {
        int a;
        cin >> a;
        if (a % 2 == 1) all_even = false;
    }
    cout << (all_even ? "second" : "first") << endl;
    return 0;
}

Measured memory_bytes: 3628