akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

var m map[int]int
var a, b, c, d int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	t := intScanner()
	for i := 0; i < t; i++ {
		n := intScanner()
		a, b, c, d = intScanner(), intScanner(), intScanner(), intScanner()
		m = make(map[int]int)
		m[0], m[1] = 0, d
		solve(n)
		fmt.Println(m[n])
	}
}
func solve(x int) {
	p := make([]int, 7)
	p[0] = q(x/2) + a + x%2*d
	p[1] = q((x+1)/2) + a + ((x+1)/2*2-x)*d
	p[2] = q(x/3) + b + x%3*d
	p[3] = q((x+2)/3) + b + ((x+2)/3*3-x)*d
	p[4] = q(x/5) + c + x%5*d
	p[5] = q((x+4)/5) + c + ((x+4)/5*5-x)*d
	p[6] = overflow(x * d)
	m[x] = min(p)
}
func q(x int) int {
	if _, ok := m[x]; !ok {
		solve(x)
	}
	return m[x]
}
func overflow(x int) int {
	if x*d/d == x {
		return x
	} else {
		return mod * mod
	}
}


Measured memory_bytes: 6376
n = int(input())
s = list(input())
minChange = n
sumE = s.count('E')

w = [0 for i in range(n)]
e = [0 for i in range(n)]

for i in range(n):
    if s[i] == 'W':
        if i == 0:
            w[i] = 1
            e[i] = 0
        else:
            w[i] = w[i - 1] + 1
            e[i] = e[i - 1]
    else:
        if i == 0:
            e[i] = 1
            w[i] = 0
        else:
            e[i] = e[i - 1] + 1
            w[i] = w[i - 1]

for i in range(n):
    if s[i] == 'W':
        acW = w[i] - 1
    else:
        acW = w[i]
    racE = sumE - e[i]
    minChange = min(minChange, acW + racE)

print(minChange)

Measured memory_bytes: 20196
# AGC039B - Graph Partition
from collections import deque


def is_bipartite() -> bool:
    stack = [(1, 1)]
    color = [-1] * (N + 1)
    color[1] = 1
    while stack:
        v, cur_color = stack.pop()
        next_color = cur_color ^ 1
        for u in E[v]:
            if color[u] == cur_color:
                return False
            if color[u] == -1:
                color[u] = next_color
                stack.append((u, next_color))
    return True


def bfs(start) -> int:
    que = deque([start])
    dist = [-1] * (N + 1)  # dist[i] := distance from V_start to V_i
    dist[start] = 0
    while que:
        v = que.popleft()
        cur = dist[v]
        for u in E[v]:
            if dist[u] == -1:
                dist[u] = cur + 1
                que.append(u)
    return max(dist)


def main():
    # if bipartite graph -> diameter of the graph + 1
    global N, E
    N, *S = open(0).read().split()
    N = int(N)
    E = [0] + [[i for i, flg in enumerate(s, 1) if flg == "1"] for s in S]
    if is_bipartite():
        ans = max(bfs(i) for i in range(1, N + 1)) + 1
        print(ans)
    else:
        print(-1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3700
def main(A, V, B, W, T):
    dist = abs(A - B)
    velo = V - W
    if dist <= velo * T:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    A, V = list(map(int, input().split()))
    B, W = list(map(int, input().split()))
    T = int(input())
    main(A, V, B, W, T)

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}




/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll X;
  cin >> X;
  ll M = 200;
  set<ll> fifth;
  for(ll A = -M;A<=M;A++){
    for(ll B=-M;B<=M;B++){  
    	if(A*A*A*A*A-B*B*B*B*B==X){cout << A << " " << B;
      return 0;}
    }
  }
  return 0;
}


Measured memory_bytes: 3568
n = int(input())
h = list(map(int, input().split()))

dp = [0] * n
dp[1] = abs(h[1] - h[0])

for i in range(2, n):
  dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i]- h[i-1]))

print(dp[-1])

Measured memory_bytes: 13980
#include <iostream>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;

#define ll long long
#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define mkp make_pair
#define eb emplace_back

const int N = 2e5 + 69;
const int NN = 2e3 + 69;
const int INF = 2e9 + 69;
const ll INF_LONG = 1e18;
const int mod = 1e9 + 7;
const int BLOCK = 174;

#define int ll

int h[N];

int a, b, n;

bool check(int x) {
	int cnt = 0;
	for (int i = 1; i <= n; ++ i) {
		int cur = h[i] - b * x;
		if (cur > 0) {
			if (cur % (a - b))
				cnt += cur / (a - b) + 1;
			else
				cnt += cur / (a - b);
		}
	}
	return (cnt <= x);
}

void solve() {
	cin >> n >> a >> b;
	for (int i = 1; i <= n; ++ i) {
		cin >> h[i];
	}
	int l = 0;
	int r = INF;
	while(r - l > 1) {
		int mid = (l + r) / 2;
		if (check(mid))
			r = mid;
		else
			l = mid;
	}
	cout << r << '\n';/*
	while(l < r) {
		int mid = (l + r) >> 1;
		if (check(mid))
			r = mid;
		else
			l = mid + 1;
	}
	cout << l;*/
}

main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout <<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;

	VAR(int, n, k);
	VEC(int, a, n);
	sort(ALL(a));
	reverse(ALL(a));
	int ans = n, sm = 0;

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

	OUT(ans)BR;
  return 0;
}


Measured memory_bytes: 256
from math import factorial
N, A, B = map(int, input().split())
v = [int(vi) for vi in input().split()]

def combination(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

v = sorted(v, reverse=True)
basket = v[:A]
max_basket = basket[0]
min_basket = basket[-1]
print(sum(basket) / len(basket))

n_selected = 0
n_candidate = 0
for vi in v:
    if vi > min_basket:
        n_selected += 1
    elif vi == min_basket:
        n_candidate += 1

if min_basket != max_basket:
    print(combination(n_candidate, A - n_selected))
else:
    count = 0
    for i in range(A, min(B, n_candidate) + 1):
        count += combination(n_candidate, i)
    print(count)

Measured memory_bytes: 3064
#include <stdio.h>


int main(){

 int n,i,l,j,k,ans;
  int p[100];
 int m[100][100];

 scanf("%d",&n);

 for(i = 1; i <= n; i++)
  scanf("%d %d",&p[i-1],&p[i]);
  
 for(i = 1; i <= n; i++)
   m[i][i] = 0;
 
 for(l = 2; l <=n; l++){
  for(i = 1; i <= n-l+1; i++){
   j = i + l - 1;
   m[i][j] = 100000000000000;
    for(k = i; k < j;k++){
     if(m[i][j] > m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j])
      m[i][j] = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
    }
   }
  }

 ans = m[1][n];
      
 printf("%d\n",ans);
 
 return 0;
}

Measured memory_bytes: 636
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}

/////////////////////////////////////////////////////////////////////////////////

struct UnionFind {
    vector<int> node;
    int N;

    UnionFind(){}
    UnionFind(int N) : N(N), node(N,-1) {}

    void init(int x) {
        node.assign(x,-1);
        N = x;
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (node[x] > node[y]) swap(x,y);
        node[x] += node[y];
        node[y] = x;
        N--;
        return true; 
    }

    bool same(int x, int y) {return root(x) == root(y);}

    int root(int x) {
        if (node[x] < 0) return x;
        return node[x] = root(node[x]);
    }

    int size(int x) {return -node[root(x)];}

    int count() const {return N;}
};

//////////////////////////////////////////////////////////////////////////////////

void yosupo() {
    int N,Q; cin >> N >> Q;
    UnionFind uf(N);
    while (Q--) {
        int t,u,v; cin >> t >> u >> v;
        if (t) cout << uf.same(u,v) << ln;
        else uf.merge(u,v);
    }
}

void DSL_1_A() {
    int N,Q; cin >> N >> Q;
    UnionFind uf(N);
    while (Q--) {
        int com,x,y; cin >> com >> x >> y;
        if (com) cout << uf.same(x,y) << endl;
        else uf.merge(x,y);
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //yosupo();
    DSL_1_A();
}

/*
  verified on 2020/05/26
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A&lang=ja
*/


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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H.at(i);
  int cnt = 0;
  int ans = 0;
  for (int i = 0; i < N-1; i++) {
    if (H.at(i) >= H.at(i+1)) cnt++;
    else {
      ans = max(ans, cnt);
      cnt = 0;
    }
  }
  ans = max(ans, cnt);
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

char buf1[1000];
char buf2[1000];
int main(void) {
  scanf("%s%s", buf1, buf2);
  int n = strlen(buf1);
  REP(offset, n) {
    bool ok = true;
    REP(i, n) {
      if(buf1[i] != buf2[(i+offset)%n]) {
        ok = false;
      }
    }
    if(ok) {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <map>
using namespace std;
map<string,int>q;
int main() {
    int n;
    cin>>n;
    string s,ss;
    bool f=true;
    for (int i = 0; i <n ; ++i) {
        cin>>s;
        if(ss!=""&&ss[ss.size()-1]!=s[0])
            f= false;
        q[s]++;
        if(q[s]>1)
            f= false;
        ss=s;
    }
    if(f)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N;
    cin >> N;
    vector<long long> A(N);
    long long ans =0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        ans ^= A[i];
    }
    for(int i = 0; i < N; i++){
        cout << (long long)(ans ^ A[i]) << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 4780
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-01-12 20:04:06
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

class Combination {
 public:
  constexpr Combination() { Build(); }
  static constexpr int mod_ = 1000000007;
  static constexpr int n_ = 101010;
  struct LookupTable {
    int64 factorial_[n_];
    int64 inverse_[n_];
    int64 finverse_[n_];
  };
  LookupTable lt{};

  // return nCk
  constexpr int64 Get(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0) return 0;
    return lt.factorial_[n] * (lt.finverse_[k] * lt.finverse_[n - k] % mod_) %
           mod_;
  }

 private:
  constexpr void Build() noexcept {
    lt.factorial_[0] = 1;
    lt.factorial_[1] = 1;
    lt.finverse_[0] = 1;
    lt.finverse_[1] = 1;
    lt.inverse_[1] = 1;
    for (int i = 2; i < n_; ++i) {
      lt.factorial_[i] = lt.factorial_[i - 1] * i % mod_;
      lt.inverse_[i] = mod_ - lt.inverse_[mod_ % i] * (mod_ / i) % mod_;
      lt.finverse_[i] = lt.finverse_[i - 1] * lt.inverse_[i] % mod_;
    }
  }
} kyomu;

constexpr int64 MOD = 1e9 + 7;

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

  int n, k; cin >> n >> k;
  vector<int64> a(n); cin >> a;

  sort(a.begin(), a.end());

  int64 ans = 0LL;

  for (int i = 0; i < n; ++i) {
    ans += a[n - 1 - i] * kyomu.Get(n - 1 - i, k - 1) % MOD;
    ans %= MOD;
  }

  for (int i = 0; i < n; ++i) {
    ans -= (a[i] * kyomu.Get(n - 1 - i, k - 1) + MOD) % MOD;
    (ans += MOD) %= MOD;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0503

def main():
    from collections import deque
    while True:
        N, M = map(int, input().split())
        if N == 0 and M == 0:
            return
        cop = [list(map(int, input().split())) for _ in range(3)]
        cop = [cop[0][1:]] + [cop[1][1:]] + [cop[2][1:]] + [0] + [-1]
        q = deque([cop])
        cnt = 0
        while q:
            lst = q.popleft()
            # a->b, b->a, b->c, c->bの4手が可能
            a = lst[0][-1] if lst[0] else 0
            b = lst[1][-1] if lst[1] else 0
            c = lst[2][-1] if lst[2] else 0
            a_cops = lst[0]
            b_cops = lst[1]
            c_cops = lst[2]
            cnt = lst[3]
            last = lst[4]
            if (lst[1] + lst[2] == []) or (lst[0] + lst[1] == []):
                print(cnt)
                break
            if cnt > M:
                print(-1)
                break
            if a > b and last != 1:
                nq = [a_cops[:-1]] + [b_cops + [a]] + [c_cops] + [cnt + 1] + [0]
                q.append(nq)
            if b > a and last != 0:
                nq = [a_cops + [b]] + [b_cops[:-1]] + [c_cops] + [cnt + 1] + [1]
                q.append(nq)
            if b > c and last != 3:
                nq = [a_cops] + [b_cops[:-1]] + [c_cops + [b]] + [cnt + 1] + [2]
                q.append(nq)
            if c > b and last != 2:
                nq = [a_cops] + [b_cops + [c]] + [c_cops[:-1]] + [cnt + 1] + [3]
                q.append(nq)


main()



Measured memory_bytes: 6012
import java.util.*;
//素因数分解
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        TreeMap<Long,Long> mapA = primeFactorize(a);
        TreeMap<Long,Long> mapB = primeFactorize(b);
        mapA.put(1L, 1L);
        mapB.put(1L, 1L);

        long cnt =0;
        for(Long key:mapA.keySet()){
 
			if(mapB.containsKey(key)){
				cnt++;
			}
		}
		long ans = cnt;
		System.out.println(ans);
    }

    public static TreeMap<Long, Long> primeFactorize(long N) {
	TreeMap<Long, Long> map = new TreeMap<>();
	for (long i = 2; i * i <= N; i++) {
		long k = 0;
		while (N % i == 0) {
			k++;
			N /= i;
		}
		if(k!=0)
			map.put(i, k);
	}
	map.put(N, 1L);
	return map;
}

    public static long gcd(long a, long b){
        if(b == 0){return a;}
        return gcd(b, a%b);
    }
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	ll a[n+1], m=0;
	int m_idx;
	for(int i=1; i<=n; i++){
		cin >> a[i];
		if(abs(a[i])>=abs(m)){
			m=a[i];
			m_idx=i;
		}
	}

	cout << 2*n-1 << endl;
	for(int i=1; i<=n; i++){
		cout << m_idx << " " << i << endl;
	}
	if(m>=0){
		for(int i=1; i<n; i++){
			cout << i << " " << i+1 << endl;
		}
	}else{
		for(int i=n; i>1; i--){
			cout << i << " " << i-1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e18;



int main(){
    string s;
    cin >> s;
    ll l = s.size();
    if(s[l-1]=='s')s+="es";
    else s+='s';
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include<queue>
#include<vector>
#include<algorithm>
#define  point pair<int,int>
using namespace std;
char map[1000][1000];
int dist[1000][1000];
int dy[4] = { 0,1,0,-1 };
int dx[4] = { 1,0,-1,0 };
int H, W;
int ans;
vector<pair<int, point>> s;
int sx, sy, ex, ey;
void BFS()
{
	
	for (int i = 0; i < H; ++i)
		for (int j = 0; j < W; ++j)
			dist[i][j] = 1000000;
	queue<point> node;
	node.push({ sx, sy });
	dist[sx][sy] = 0;
	while (1)
	{
		point p = node.front();
		node.pop();
		for (int i = 0; i <= 3; ++i)
		{
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];
			if (0 <= nx&&nx < H&&ny < W&&ny >= 0 && dist[nx][ny] == 1000000 && map[nx][ny] != 'X')
			{
				dist[nx][ny] = dist[p.first][p.second] + 1;
				if (nx == ex&&ny == ey)
				{
					ans += dist[nx][ny];
					return;
				}
				node.push({ nx,ny });
			}
		}
	}
}
int main()
{
	int index = 0;
	int N;
	cin >> H >> W >> N;
	for (int i = 0; i < H; ++i)
		for (int j = 0; j < W; ++j)
		{
			cin >> map[i][j];
			if (map[i][j] == 'S')
				s.push_back({ 0,{i,j} });
			if ('1' <= map[i][j] && map[i][j] <= '9')
				s.push_back({ map[i][j] - '0',{i,j} });
		} 
	sort(s.begin(), s.end());
	for (int i = 0; i < s.size()-1 ; ++i)
	{
		for (int i = 0; i < H; i++)
			for (int j = 0; j < W; ++j)
				dist[i][j] = 1000000;
		sx = s[i].second.first;
		sy = s[i].second.second;
		ex = s[i + 1].second.first;
		ey = s[i + 1].second.second;
		BFS();
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define int long long
#define all(V) (V).begin(),(V).end()
#define umap unordered_map
#define uset unordered_set
#define br cout<<"\n";

const int MAXN = 1e5 + 10, MOD = 1e9 + 7;
int n, m;
vector<int> grf[MAXN], et, st;
int tin[MAXN], tout[MAXN], timer = 0;

void dfs(int node, int p = -1) {
    et.push_back(node);
    tin[node] = timer++;
    for (auto nbr: grf[node]) {
        if (nbr != p) {
            dfs(nbr, node);
        }
    }
    tout[node] = timer++;
    et.push_back(node);
}


void update(int start, int end, int point, int val, int index = 1) {
    if (start == end and start == point) {
        st[index] += val;
        return;
    }
    int mid = start + end >> 1;
    if (point <= mid) {
        update(start, mid, point, val, index << 1);
    } else {
        update(mid + 1, end, point, val, index << 1 | 1);
    }
    st[index] = st[index << 1] + st[index << 1 | 1];
}

int query(int start, int end, int l, int r, int index = 1) {
    if (r < start or l > end) return 0;
    if (l <= start and end <= r) {
        return st[index];
    }
    int mid = start + end >> 1;
    return query(start, mid, l, r, index << 1) + query(mid + 1, end, l, r, index << 1 | 1);
}

void doit() {
    st.resize(5 * et.size());
}

signed main() {
//	#ifndef ONLINE_JUDGE
//		freopen("./input.txt","r",stdin);
//		freopen("./output.txt","w",stdout);
//	#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int i = 0, tmp; i < n; i++) {
        cin >> m;
        while (m--) {
            cin >> tmp;
            grf[i].push_back(tmp);
            grf[tmp].push_back(i);
        }
    }
    dfs(0);
    doit();
    int q;
    cin >> q;
    while (q--) {
        int qt;
        cin >> qt;
        if (qt == 0) {
            int v, w;
            cin >> v >> w;
            update(0, et.size() - 1, tin[v], w);
            update(0, et.size() - 1, tout[v], -w);
        } else {
            int u;
            cin >> u;
            cout << query(0, et.size() - 1, 0, tin[u]);
            br;
        }
    }
//    br;
//    for (int i = 0; i < n; i++) {
//        cout << tin[i] << " ";
//    }
//    br;
//    for (int i = 0; i < n; i++) {
//        cout << tout[i] << " ";
//    }
}


Measured memory_bytes: 23860
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0

for i in range(N):
  s = input()
  if s == "AC":
    ac+=1
  elif s == "WA":
    wa+=1
  elif s == "TLE":
    tle+=1
  elif s == "RE":
    re+=1
  
  
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

Measured memory_bytes: 9200
import Control.Monad
import Data.List

data Dice = Dice {top :: Int,
                  south :: Int,
                  east :: Int,
                  west :: Int,
                  north :: Int,
                  bottom :: Int} deriving Eq
fromList :: [Int] -> Dice
fromList [t,s,e,w,n,b] = Dice t s e w n b
allState :: Dice -> [Dice]
allState d = nub $ [rotateAll d' direction |
                    d' <- map (rotateAll d) ["","N","S","W","E","NN"],
                    direction <- inits "ccc" ]

rotate :: Dice -> Char -> Dice
rotate d 'N' = d {bottom = north d,
                  north = top d,
                  top = south d,
                  south = bottom d}
rotate d 'S' = d {bottom = south d,
                  south = top d,
                  top = north d,
                  north = bottom d}
rotate d 'E' = d {bottom = east d,
                  east = top d,
                  top = west d,
                  west = bottom d}
rotate d 'W' = d {bottom = west d,
                  west = top d,
                  top = east d,
                  east = bottom d}
rotate d 'c' = d {north = west d,
                  west = south d,
                  south = east d,
                  east = north d}
rotate d 'C' = rotateAll d "ccc"

rotateAll :: Dice -> [Char] -> Dice
rotateAll d [] = d
rotateAll d (op:ops) = rotateAll (rotate d op) ops

main :: IO ()
main = do
  n <- readLn
  ds <- replicateM n $ fmap (fromList . map read . words) getLine
  let dSs = map allState ds
  putStrLn $ if ds == (nub ds) &&
                and [null $ intersect ds1 ds2 |
                     ds1 <- dSs, ds2 <- dSs, ds1 /= ds2]
             then "Yes" else "No"

Measured memory_bytes: 4284
package main

import "fmt"

const inf = int(1e10)

var n, a, b, c, ans int
var l []int

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func calc(s, t int) int {
	return abs(s - t)
}

func dfs(step, sum, na, nb, nc int) {
	cost := sum
	if na > 0 && nb > 0 && nc > 0 {
		// 全て魔法が使用可能なのでコストを計算する
		cost += calc(na, a) + calc(nb, b) + calc(nc, c)
		if ans > cost {
			ans = cost
		}
	}
	if step == n { // 全ての竹を使った
		return
	}
	dfs(step+1, sum, na, nb, nc)
	if na > 0 {
		dfs(step+1, sum+10, na+l[step], nb, nc)
	} else {
		dfs(step+1, sum, l[step], nb, nc)
	}
	if nb > 0 {
		dfs(step+1, sum+10, na, nb+l[step], nc)
	} else {
		dfs(step+1, sum, na, l[step], nc)
	}
	if nc > 0 {
		dfs(step+1, sum+10, na, nb, nc+l[step])
	} else {
		dfs(step+1, sum, na, nb, l[step])
	}
}

func main() {
	fmt.Scan(&n, &a, &b, &c)
	// N(max 8)本の竹の使い道は、以下の4パターンしかない
	// (1) Aの材料にする
	// (2) Bの材料にする
	// (3) Cの材料にする
	// (4) 使わない
	// そうすると、4^8で最大65536通りで十分列挙可能
	ans = inf
	l = make([]int, n)
	for i := range l {
		fmt.Scan(&l[i])
	}
	dfs(0, 0, 0, 0, 0)
	fmt.Println(ans)
}


Measured memory_bytes: 512
//#include"cpp_kyopro.h"
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <stdlib.h>
#include <math.h>
using namespace std;
int main() {
	int n, l; cin >> n >> l;
	int sum = 0;
	if (l < 0) {
		if (n + l - 1 >= 0) {
			for (int i = 0; i < n; ++i) {
				sum += l + i;
			}
		}
		else {
			for (int i = 0; i < n - 1; ++i) {
				sum += l + i;
			}
		}
	}
	else {
		for (int i = 1; i < n; ++i) {
			sum += l + i;
		}
		
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
input=[]
for i in range(3):
    input.append(stdin.readline().rstrip())

input[0]=int(input[0])
input[2]=int(input[2])
flag=input[1][input[2]-1]
output=""
for i in range(input[0]):
    if input[1][i]!=flag:
        #input[1][i]="*"
        output+="*"
    else:
        output+=flag
print(output)

Measured memory_bytes: 3060
N = input()

# N の 1 の位が 2 , 4 , 5 , 7 , 9 のとき hon 
# N の 1 の位が 0 , 1 , 6 , 8 のとき pon 
# N の 1 の位が 3 のとき bon
if N[-1] in ["2" , "4" , "5" , "7" , "9"]:
    print("hon")

elif N[-1] in ["0" , "1" , "6" , "8"]:
    print("pon")

elif N[-1] in ["3"]:
    print("bon")


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

#define int long long 

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int n,a,b;

signed main() {
    read(n),read(a),read(b);
    if((b-a)&1) write(min(a+(b-a-1)/2,n-b+1+(n-(a+n-b+1))/2));
    else write((b-a)/2);
    return 0;
}


Measured memory_bytes: 256
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { N: number, X: number, L: number[] } => {
  const [N, X] = lines[0].split(' ').map(line => +line)
  const L = lines[1].split(' ').map(line => +line)
  const obj = { N, X, L }
  debug(obj)
  return obj
}
// solver
export const solve = (lines: string[]): string => {
  const { N, X, L } = parseLines(lines)

  const bounds = [0]
  for (let i = 1; i < N + 1; i++) {
    const d = bounds[i-1] + L[i-1]
    bounds.push(d)
  }
  const count = bounds.filter(b => b <= X).length
  return `${count}`
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


Measured memory_bytes: 7628
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
char a[55][55];
int vis[55][55];
int n,m;
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
void solve()
{
    int i,j,k,s,x,y;
    queue<int> q;
    if(a[0][0]=='#'||a[n-1][m-1]=='#')
    {
        printf("-1\n");
        return;
    }
    q.push(0);
    q.push(0);
    q.push(1);
    memset(vis,0,sizeof(vis));
    vis[0][0]=1;
    while(!q.empty())
    {
        i=q.front();
        q.pop();
        j=q.front();
        q.pop();
        k=q.front();
        q.pop();
        if(i==n-1&&j==m-1)
        {
            s=n*m-k;
            for(x=0;x<n;x++)
            for(y=0;y<m;y++)
            if(a[x][y]=='#')
            s--;
            printf("%d\n",s);
            return;
        }
        for(int t=0;t<4;t++)
        {
            x=i+dir[t][0];
            y=j+dir[t][1];
            if(x<0||x>=n)
                continue;
            if(y<0||y>=m)
                continue;
            if(a[x][y]=='#')
                continue;
            if(vis[x][y]==0)
            {
                vis[x][y]=1;
                q.push(x);
                q.push(y);
                q.push(k+1);
            }
        }
    }
    printf("-1\n");
    return;
}
int main()
{
    int i,j;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
        scanf("%s",a[i]);
    solve();
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b, c, x int

	fmt.Scan(&a, &b, &c, &x)

	var res = abc087B(a, b, c, x)
	fmt.Println(res)
}

func abc087B(a, b, c, x int) int {
	var res int

	for hund5 := 0; hund5 <= a; hund5++ {
		for hund1 := 0; hund1 <= b; hund1++ {
			for five := 0; five <= c; five++ {
				if hund5*500+hund1*100+five*50 == x {
					res++
				}
			}
		}
	}

	return res
}


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

int main() {
    int n;
    cin >> n;
    vector<double> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }
    for (int i = 0; i < n; i++) {
        double l0, r0, l1, r1;
        l0 = l1 = -M_PI, r0 = r1 = M_PI;
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            double angle = atan2(y[j] - y[i], x[j] - x[i]);
            if (x[j] > x[i]) {
                r0 = min(r0, angle - M_PI / 2);
                l1 = max(l1, angle + M_PI / 2);
            } else if (y[j] < y[i]) {
                l0 = max(l0, angle + M_PI / 2);
                l1 = max(l1, angle + M_PI / 2);
                r0 = min(r0, angle + 3 * M_PI / 2);
                r1 = min(r1, angle + 3 * M_PI / 2);
            } else {
                l0 = max(l0, angle - 3 * M_PI / 2);
                l1 = max(l1, angle - 3 * M_PI / 2);
                r0 = min(r0, angle - M_PI / 2);
                r1 = min(r1, angle - M_PI / 2);
            }
        }
        double ans = (max(0.0, r0 - l0) + max(0.0, r1 - l1)) / (2 * M_PI);
        if (l0 == l1 && r0 == r1) ans /= 2;
        cout << setprecision(10) << ans << endl;
    }
    return 0;
}

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

int main(){
  int a[100000],count=1,i,kyokai,temaedai=0,n;
  char x[100000];
  cin>>x[0];
  for(i=0;i<100000;i++){
    a[i]=0;
  }
  for(i=1;;i++){
    cin>>x[i];
    if(x[i-1]=='R'&&x[i]=='R'){
      count++;
    }else if(x[i-1]=='L'&&x[i]=='L'){
      count++;
    }else if(x[i-1]=='R'&&x[i]=='L'){
      kyokai=i;
      count++;
      if(count%2==0){
        temaedai=1;
      }
    }else if(x[i-1]=='L'&&x[i]=='R'){
      if(count%2==0){
        a[kyokai-1]=count/2;
        a[kyokai]=count/2;
      }else{
        a[kyokai-temaedai]=count/2+1;
        a[kyokai-1+temaedai]=count/2;
      }
      count=1;
      temaedai=0;
    }else{
      break;
    }
  }
  if(count%2==0){
      a[kyokai-1]=count/2;
      a[kyokai]=count/2;
    }else{
      a[kyokai-temaedai]=count/2+1;
      a[kyokai-1+temaedai]=count/2;
    count=1;
    temaedai=0;
  }
  n=i-1;
  for(i=0;i<=n;i++){
    cout<<a[i]<<" ";
  }
}
      

Measured memory_bytes: 896
#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() {
    int a[3][3];
    rep(i, 3) {
        rep(j, 3) {
            cin >> a[i][j];
        } 
    } 
    int n;
    cin >> n;
    vector<int> b(n);
    rep(i, n) cin >> b[i];
    bool bingo = false;
    int c[3][3] = {};
    rep(h, n) {
        rep(i, 3) {
            rep(j, 3) {
                if(a[i][j]==b[h]) c[i][j] = 1;
            } 
        } 
    } 
    rep(i, 3) {
        if (c[i][0]*c[i][1]*c[i][2]==1||c[0][i]*c[1][i]*c[2][i]==1) {
            bingo = true;
            break;
        }
    } 
    if (c[0][0]*c[1][1]*c[2][2]==1||c[0][2]*c[1][1]*c[2][0]==1) {
        bingo = true;
    }

    if(bingo) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 256
//ABC070 D.Transit Tree Path
//2頂点u,vを繋ぐ最短経路のうち頂点kを経由するものの長さを求める問題
//方針：頂点kを根に決めてDFSをし各頂点について根からの距離を求める
//      頂点xの根からの距離をd[x]とすればd[u]+d[v]が求める値となる
//2020/03/01 1st AC

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

struct edge {
    int to,cost;
};
vector<edge> G[100010];
ll dist[100010];

void dfs(int v,int p,int d) {
    dist[v] = dist[p] + d;
    for(auto e: G[v]) {
        if(e.to == p) continue;
        dfs(e.to, v, e.cost);
    }
}

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

int N;
cin >> N;
rep(i,N-1) {
    int a,b,c;
    cin >> a >> b >> c;
    --a;--b;
    G[a].push_back({b,c});
    G[b].push_back({a,c});
}
int Q,K;
cin >> Q >> K;
--K;

//適当に使わないところを利用する
dist[100005] = 0;
dfs(K,100005,0);

ll ans[100010];
rep(i,Q) {
    int x,y;
    cin >> x >> y;
    --x;--y;
    ans[i] = dist[x] + dist[y];
}

rep(i,Q) cout << ans[i] << endl;

return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second

using namespace std;
const int N = 5e2 + 5;



int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a , b , c , d; cin >> a >> b >> c >> d;
    cout << a * b - (c * b + d * a - c * d);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int N = sc.nextInt();
        int Sr = sc.nextInt();
        int Sc = sc.nextInt();
        String S = sc.next();
        String T = sc.next();


        //Row
        int left=0;
        int right=W -1;

        for (int i = N-1; i >=0; i--) {
            char s = S.charAt(i);
            char t = T.charAt(i);
            if(t=='R') left = Math.max(left-1,0);
            if(t=='L') right = Math.min(right+1,W-1);
            if(s=='L') left++;
            if(s=='R') right--;

            if(left>right){
                System.out.println("NO");
                return;
            }
        }

        int top=0;
        int bottom=H -1;
        for (int i = N-1; i >= 0 ; i--) {
            char s = S.charAt(i);
            char t = T.charAt(i);
            if(t=='D') top = Math.max(top-1,0);
            if(t=='U') bottom = Math.min(bottom+1,H-1);
            if(s=='U') top++;
            if(s=='D') bottom--;

            if(top>bottom){
                System.out.println("NO");
                return;
            }

        }

        if( left<=Sc-1 && Sc-1 <= right && top<= Sr-1 && Sr-1 <= bottom){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 29556
R,G,B,N = list(map(int,input().split()))
r_max = N//R+1
ans = 0
for r in range(r_max):
	g_max = (N-r*R)//G+1
	for g in range(g_max):
		if (N-r*R-g*G)%B == 0:
			ans += 1
print(ans)


Measured memory_bytes: 2940
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

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

  if(N%10==N/100) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

#define INF (1<<29) //53687091
#define INFLL (1ll<<58)

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())
#define DBG(x) cerr << #x << ": " << x << "\n";

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }


int
main(void){  
  ll d, g;
  cin >> d >> g;

  ll p[d], c[d];
  REP(i, d) cin >> p[i] >> c[i];

  /*
  ll sum = g;
  ll ans = 0LL;
  ROF(i, d-1, 0){
    //cout << "Currenc sum: " << sum << endl;
    if(sum > p[i] * (i+1) * 100 + c[i]){
      sum -= p[i] * (i+1) * 100 + c[i];
      ans += p[i];
    }
    else{
      ll count = p[i];
      for(;;){
	if(count < 0) break;	
	sum -= (i+1) *100;
	if(sum < 0) break;
	++ans;
	--count;
	//cout << "While sum: " << sum << " count: " << count << endl;	
      }      
    }
  }
  */

  int ans = INF, max_rest = 0;
  for(int mask=0; mask<(1<<d); mask++){
    int num=0, score=0;
    REP(i, d){
      if((mask>>i) & 1){
	num += p[i];
	score += p[i]*(i+1)*100 + c[i];
      }
      else{
	max_rest = i;
      }
    }
    if(score < g){
      int itmp = (max_rest+1)*100;
      int need = (g - score + itmp - 1) / itmp;
      if(p[max_rest] <= need) continue;
      num += need;
    }
    ans = min(ans, num);
  }

  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
// 全然わからないので、解説を読んで実装
// 兎と亀の例はそこから

#include <iostream>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
  int a,b;
  cin >> a >> b;
  
  if ((a+b)%2==1) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << (a+b)/2 << endl;
  }
  
  return 0;
}


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

int k,n,x[200],ans;

int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>x[i];
        ans+=min(x[i]*2,abs(k-x[i])*2);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定 setprecision()
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror



#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = acos(-1); //円周率

//常設関数↓

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

//degree → radian
long double chg_DegRad(long double deg) {
	return deg * PI / 180.0;
}

//radian → degree
long double chg_RadDeg(long double rad) {
	return rad * 180.0 / PI;
}
 
//桁数
ll CountDigit(ll n) {
	ll digit = 1;
	while ((n /= 10) != 0) digit++;
	return digit;
}

//距離
double dis(double xa, double ya, double xb, double yb) {
	return pow(pow(xa - xb, 2.0) + pow(ya - yb, 2.0), 0.5);
}

//abs()平均
//pow(,)累乗


//提出コード↓

ll n, k, ans;
ll h[1000000];


int main() {
	cin >> n >> k;
	rep(i, n) cin >> h[i];
	sort(h, h + n);
	rep(i, n - k) {
		ans += h[i];
	}
	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<cmath>
#include<bitset>
#include<cassert>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<iomanip>
#include<fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
int main()
{
    fast_io;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int n, r;
    cin >> n >> r;

    if (n >= 10)
        cout << r << endl;
    else
    {
        r = r - (100 * (10 - n));
        int ir = r + (100 * (10 - n));
        int res = ir + (100 * (10 - n));

        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 3108
S = input()
T = input()
t_len = len(T)
count = len(S) - len(T) + 1
max_correct = []
for i in range(count):
  s_tmp = S[i:t_len]
  correct = 0
  for n, s in enumerate(s_tmp):
    if s == T[n]:
      correct += 1
  max_correct.append(correct)
  
  i = i + 1
  t_len = t_len + 1

max_correct = len(T) - max(max_correct)
print(max_correct)

Measured memory_bytes: 9128
#include <iostream>

using namespace std;

int main(){
	
	ios::sync_with_stdio(false); cin.tie(0);
	int A, B;
	cin >> A >> B;
	if(1 != A && 1 != B)
		cout << "1\n";
	else if(2 != A && 2 != B)
		cout << "2\n";
	else
		cout << "3\n";

	return 0;
}

Measured memory_bytes: 256
n, D = map(int, input().split())
points = [list(map(int, input().split())) for i in range(n)]
ans = 0

for i in range(n-1):
    for j in range(i+1, n):
        pre_distance = 0
        for d in range(D):
            pre_distance += (points[i][d] - points[j][d])**2

        distance = pre_distance ** 0.5
        if distance.is_integer():
            ans += 1

print(ans)


Measured memory_bytes: 3188
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define ll  long long 
const ll INF=1LL<<60;
const ll MOD=1000000007;
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
int main(){
    ll a,b,c,d=0;
    cin>>a;
    rep(i,a){
        cin>>b>>c;
        if(b==c)d++;
        else d=0;
        if(d==3){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<utility>
#include <cmath>
using namespace std;

int main(){
 
    int a,b;
    cin >> a >> b;
    if(a%2==0 || b%2==0){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    int l,r,d;
    int cnt=0;
    cin >> l >> r >> d;
    for(int i = l; i<=r; i++){
        if(i%d == 0) cnt++;
    }
    cout << cnt << endl;
}

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

#define INF 1000000000000000LL

int main() {
    ll ans = - INF;
    ll N, K; cin >> N >> K;
    vector<ll> P(N+1);
    for (int i = 1; i <= N; ++i) cin >> P[i];
    vector<ll> C(N+1);
    for (int i = 1; i <= N; ++i) cin >> C[i];

    for (int s = 1; s <= N; ++s) {
        ll score = 0;
        ll i;
        int next = s;
        for (i = 1; i <= K; ++i) {
            next = P[next];
            score += C[P[next]];
            ans = max(score, ans);
            if (next == s) break;
        }
        ll loop = (K / i) - 1;
        if (loop == -1) continue;
        score = score * loop;
        ll count = i * loop;
        next = s;
        for (count = i * loop; count < K; ++count) {
            next = P[next];
            score += C[P[next]];
            ans = max(score, ans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
#define BOOST ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(0)
#define fo(i,a,n) for(int i=a;i<n;i++)
#define fc(i,a,n,c) for(int i=a;i<n;i+=c)
#define fi(i,n,a) for(int i=n-1;i>=a;i--)
#define in cin>>
#define out cout<<
#define ll long long
#define el <<"\n"
#define es <<" "

int main(){
  BOOST;
  int a,c;  in a;
  int b[a],e[101];
  fo(i,0,a) in b[i];
  fo(i,0,100){
    int f=0;
    fo(j,0,a){
      f+=pow((b[j]-i),2);
      e[i]=f;
    }
  }
  sort(e,e+100);
  out e[0];
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	char x;
	int goukei = 0;
	while(1){
		scanf("%c",&x);
		if(x == '0'&&goukei == 0)break;
		if(x == '\n'){
			printf("%d\n",goukei);
			goukei = 0;
		}else{
			goukei += atoi(&x);
		}
	}
	return 0;
}

Measured memory_bytes: 548