akhauriyash/Code-Regression huggingface dataset:
/**
  * @brief atcoder
  * @author yao
  */
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#define ft first
#define sd second
#ifdef DBG
#   define dbg_pri(x...) fprintf(stderr,x)
#else
#   define dbg_pri(x...) 0
#   define NDEBUG
#endif //DBG
#include <cassert>

typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long int ulli;

#define N 262144

char s[N], t[N];

int main()
{
    int n;
    scanf("%s%s", s, t), n = strlen(s);
    int ans = 0;
    for(int i=0;i<n;++i) ans += s[i] != t[i];
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 2084
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd



def solve(N: int, X: int):
    a, p = [1], [1]
    for i in range(N):
        a.append(a[i] * 2 + 3)
        p.append(p[i] * 2 + 1)

    def _f(N, X):
        if N == 0:
            return 0 if X <= 0 else 1
        elif X <= 1 + a[N-1]:
            return _f(N-1, X-1)
        elif X == (2 + a[N-1]):
            return 1 + p[N-1]
        elif X < a[N]:
            return p[N-1] + 1 + _f(N-1, X - 2 - a[N-1])
        else:
            return p[N]

    return _f(N, X)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    result = solve(N, X)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5252
#include <iostream>
#include <complex>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;

#define EPS 1e-7
typedef complex<double> P;

struct L : public vector<P>
{
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

struct C
{
	P p; double r;
	C(const P &p, double r) 
	:p(p),r(r) 
	{}
};

double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}

double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

double dist(const P& a, const P& b)
{
	return sqrt((a.real()-b.real())*(a.real()-b.real())+(a.imag()-b.imag())*(a.imag()-b.imag()));
}

bool intersectSC(const L& l, const C& c)
{	
	double vc=dot(l[1]-l[0], c.p-l[0]);
	if(vc<0)
	{
		double dif=c.r-dist(l[0], c.p);
		return dif+EPS > 0;
	}
	
	double vv=dot(l[1]-l[0], l[1]-l[0]);
	
	if(vc > vv)
	{
		double d=dist(l[1], c.p);
		double dif=c.r*c.r-d*d;
		
		return dif+EPS > 0;
	}
	
	double cc=dot(c.p-l[0], c.p-l[0]);
	double dif=c.r*c.r-(cc-(vc/vv)*vc);
	
	return dif+EPS > 0;
}

int T;

class UFO
{
public:
	double v,d,dx,dy,x,y,r;
	UFO(double v, double d, double dx, double dy, double x, double y, double r)
	:v(v),d(d),dx(dx),dy(dy),x(x),y(y),r(r)
	{}
	
	bool operator<(const UFO& u) const
	{
		return d-v*T>u.d-u.v*T;
	}
};

int main()
{
	int R,N;
	while(cin >> R >> N,(R||N))
	{
		T=1;
		priority_queue<UFO> q;
		while(N--)
		{
			double x,y,r,v;
			cin >> x >> y >> r >> v;
			double d=sqrt(x*x+y*y), dx=v*x/d, dy=v*y/d;
			q.push(UFO(v,d,dx,dy,x,y,r));
		}
		
		int cnt=0;
		while(!q.empty())
		{
			UFO u=q.top(); q.pop();
			if(u.d-u.v*T < R+EPS)
			{
				cnt++;
				continue;
			}
			
			priority_queue<UFO> tq;
			double nx=u.x-u.dx*T, ny=u.y-u.dy*T, r=sqrt(nx*nx+ny*ny);
			L s(P(R*nx/r,R*ny/r),P(nx*3000, ny*3000));
			while(!q.empty())
			{
				UFO uf=q.top(); q.pop();
				if(intersectSC(s,C(P(uf.x-uf.dx*T, uf.y-uf.dy*T), uf.r))) continue;
				
				tq.push(uf);
			}
			
			T++;
			while(!tq.empty())
			{
				q.push(tq.top()); tq.pop();
			}
		}
		
		cout << cnt << endl;
	}
}

Measured memory_bytes: 0
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)

ans = 0
a.group_by(&:itself).map do |k, v|
  if k.to_i < v.count
    ans += v.count - k.to_i
  elsif k.to_i > v.count
    ans += v.count
  end
end
puts ans


Measured memory_bytes: 24196
<?php
fscanf(STDIN,"%d",$n);
$p_li = explode(" ",trim(fgets(STDIN)));
$count = 0;
$flag =false;
for($i=0;$i<$n;$i++){

  if($p_li[$i] == $i+1&&!$flag){
    $count++;
    if($p_li[$i+1] == $i+2){
      $flag = true;
    }
  }else{
    $flag = false;
  }
}

echo $count;


Measured memory_bytes: 22528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265358979323846264338327950L
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1)
    {
        cerr << name << " = " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args)
    {
        const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
        __f(comma+1, args...);
    }
#else
#define debug(...)
#endif
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	ll n;
 	cin >> n;
 	ll ans = 0;
 	for (ll i = 1; i <= n; i++) {
 		ll temp = (n - 1) / i;
 		ans += temp;
 	}   
 	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3664
#include<stdio.h>
#define N 100

#define WHITE  0
#define GRAY  1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N];
int tt;

void dfs_visit(int);
void dfs();


int main(){

  int u, k, v; 
  int i, j;

  scanf("%d", &n);

  for ( i = 0; i <n; i++ ){
    for ( j = 0; j <n; j++ ) {
      M[i][j] = 0;
    }
  }
  
  for ( i = 0; i < n; i++ ){
    
    scanf("%d %d", &u, &k);
    u--;

    for ( j = 0; j < k; j++ ){
      scanf("%d", &v);
      v--;
      M[u][v] = 1;

    }
  }
  
  dfs();

  return 0;
}



void dfs_visit(int u){

  int v;

  color[u] = GRAY;
  tt++;
  d[u] = tt;

  for ( v = 0; v < n; v++ ){
    if ( M[u][v] == 0 ) continue;
    if ( color[v] == WHITE ){
      dfs_visit(v);
    }
  }

  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs(){

  int i, u;

  for ( i = 0; i < n; i++ ){
    color[i] = WHITE;
  }
  
  tt = 0;

  for ( u = 0; u < n; u++ ){
    if ( color[u] == WHITE ){
      dfs_visit(u);
    }
  }
  for ( i = 0; i < n; i++ ){
    printf("%d %d %d\n", i+1, d[i], f[i]);
  }
}

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

int main() {
	cin.tie(0)->sync_with_stdio(false);

	ll n;
	cin >> n;

	ll ans = 0;
	for (ll i = 1; i <= n; i++)
		ans += (n / i) * (n / i + 1) * i / 2;

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


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

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

    vector<int> A(3);
    REP(i, 3) cin >> A[i];

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

    cout << A[0] + A[1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	char a[15][15];
	int n,m,i,j;
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{cin>>a[i][j];}
		
	} 
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
			if(i==j)cout<<a[i][i];
	}
    cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#define		_CRT_SECURE_NO_WARNINGS
#include <cstdio>

int main()
{
	int		n, m;
	scanf("%d", &n);
	scanf("%d", &m);

	int		A[100][100];
	int		B[100];

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			scanf("%d", &(A[i][j]));
		}
	}

	for (int i = 0; i < m; i++)
	{
		scanf("%d", &(B[i]));
	}

	for (int i = 0; i < n; i++)
	{
		int		sum = 0;
		for (int j = 0; j < m; j++)
		{
			sum += A[i][j] * B[j];
		}
		printf("%d\n", sum);
	}

	return 0;
}

Measured memory_bytes: 2772
import sys
def print_list(A):
    for k in range(len(A)):
        sys.stdout.write(str(A[k]))
        if not k == len(A) -1: sys.stdout.write(" ")
    print()
def insert_sort(A,N):
    print_list(A)
    for i in range(1,N):
        v = A[i]
        j = i-1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j = j-1
        A[j+1]=v
        print_list(A)


N = int(input())
A = list(map(int,input().split()))
insert_sort(A,N)

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

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < 30; i++) {
		for (int j = 0; j < 20; j++) {
			if (((4 * i) + (7 * j)) == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int r, D, x2000;
    int ans;
    cin >> r >> D >> x2000;
    ans = x2000;
    for(int i = 1; i <= 10; i++){
        ans = r * ans - D;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int a,b,c;
//=============================
void input()
{
    cin>>a>>b>>c;
}

void solve()
{
    int m = max({a,b,c});
    cout<<m*10 +a+b+c-m<<endl;


}

//=============================
signed main()
{
    input();
    solve();
    return 0;
}

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

using namespace std;
#define ff first
#define ss second
#define pb push_back
#define quicker ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
 
int main()
{
    quicker
    int n, k, c, s;
    cin >> n >> k;
    unordered_map<int, int> m;
    for (int i = 0; i < k; i++){
      cin >> s >> c;
      if (m.find(s) != m.end()){
        if (m[s] == c) continue;
        else {
          cout << -1;
          return 0;
        }
      } else {
        m[s] = c;
      }
    }
    if (n == 1){
      if (m.find(1) == m.end()) cout << 0;
      else cout << m[1];
      return 0;
    }
    string ans;
    for (int i = 1; i <= n; i++){
      if (i == 1 && m.find(1) != m.end() && m[1] == 0) {
        cout << -1;
        return 0;
      }
      if (m.find(i) == m.end()){
        if (i != 1) ans += ('0' + 0);
        else ans += '0' + 1;
      }
      else ans += '0' + m[i];
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
S = gets.chomp.chars
n = S.length

MOD = 2019


h = Hash.new(0)

mul = 1
prev = 0

# 0も倍数に含む
# 2019なら答えは2つ

ans = 0

n.times do |i|
  num = S[n-i-1].to_i


  key = (num * mul + prev) % MOD
  prev = key

  ans += 1 if key == 0

  if h[key] != 0
    ans += h[key]
  end

  h[key % MOD] += 1

  mul *= 10
  mul %= 2019
end

puts ans


Measured memory_bytes: 25024
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int solve(const string &S){
    int res = 0;
    int lb = 0;
    int ub = S.size()-1;
    while(ub-lb>0){
        // int size = ub-lb+1;
        if(S[lb]==S[ub]){
            lb++;
            ub--;
        } else if(S[lb]=='x'){
            lb++;
            res++;
        } else if(S[ub]=='x'){
            ub--;
            res++;
        } else{
            return -1;
        }
    }
    return res;
}

int main(){
    string S;
    cin >> S;
    cout << solve(S) << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <stdexcept>
#include <cassert>
#include <cmath>
#include <vector>
#include <stack>
using namespace std;


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

  vector<long long> A(N+1, 0), B(M+1, 0);
  for (int i = 1; i <= N; i++) {cin >> A[i];A[i] += A[i-1];}
  for (int i = 1; i <= M; i++) {cin >> B[i];B[i] += B[i-1];}

  int ans = 0;
  long long life;
  int l, r = M + 1, m;
  for (int i = 0; i <= N; i++) {
    life = K;
    life -= A[i];
    if (life < 0) break;
    l = 0;
    // l is ok, r is ng
    while (r > l+1) {
      m = l + (r-l)/2;
      if (life - B[m] >= 0) l = m;
      else r = m;
    }
    assert(life - B[l] >= 0);
    ans = max(ans, i + l);
  }
  cout << ans << endl;

  return 0;
}


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

int main()
{
  int N;
  
  cin >> N;
  
  if(N%1000%111 == 0)
    cout << "Yes" << endl;
  else if (N/10%111 == 0)
    cout << "Yes" << endl;
  else 
    cout << "No" << endl;
}


Measured memory_bytes: 256
n = int(input())
h = [int(x) for x in input().split()]
h.reverse()
flag = True

for i in range(1,len(h)):
    if (h[i-1] < h[i]):
        if (h[i] - h[i-1] <= 1):
            h[i] -= 1
        else:
            flag = False
            break

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14396
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
vector<string> Split(const string &s)
{
	vector<string> v;
	int i=0, j;
	while((j=s.find_first_of(' ',i)) !=string::npos)
	{
		v.push_back(s.substr(i,j-i));
		i=j+1;
	}
	if(i!=s.size()-1)
		v.push_back(s.substr(i));
	return v;
}
int main()
{
	int n;
	string s;
	vector<string>v;
	map<string,int>m;
	cin.tie(0);
	ios::sync_with_stdio(false);
	while(cin>>n,n)
	{
		getline(cin,s);
		m.clear();
		while(n--)
		{
			getline(cin,s);
			v=Split(s);
			for(int i=0;i<v.size();++i)
				++m[v[i]];
		}
		getline(cin,s);
		vector<pair<int,string> >vp;
		for(map<string,int>::iterator ite=m.begin();ite!=m.end();++ite)
		{
			if(ite->first[0]!=s[0])continue;
			vp.push_back(make_pair(-ite->second,ite->first));
		}
		if(vp.empty())cout<<"NA"<<endl;
		else
		{
			sort(vp.begin(),vp.end());
			int end=min(5,(int)vp.size());
			for(int i=0; i<end; ++i)
				cout<<vp[i].second<<(i+1==end?"\n":" ");
		}
	}
	return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define REP(i,b,n) for(i=b;i<n;i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))

using namespace std;

int n;
char seg[11][8] = { "1111110", "0110000", "1101101", "1111001", "0110011", 
					"1011011", "1011111", "1110010", "1111111", "1111011", "0000000"};
					
string solve(int a, int b)
{	
	string res = "";
	
	FOR(i, 0, 7)
	{
		if( seg[a][i] == seg[b][i] )
			res += '0';
		else
			res += '1';
	}
	
	return string(res.rbegin(), res.rend());
}

int main()
{
	while(cin >> n, n != -1)
	{
		int a = 10;
		
		FOR(i, 0, n)
		{
			int b;
			cin >> b;
			cout << solve(a, b) << endl;
			a = b;
		}
		
	}
	
	return 0;
}

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

using namespace std;

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int inf = 2e18;
const ld eps = 1e-9;

const int NN = 51;
const int MAX_COINS = 2500;

struct edge {
      int to;
      int cost, time;
      edge(int _to, int _cost, int _time) : to(_to), cost(_cost), time(_time)
      {}
};

vector<vector<edge>> g(NN);

vvi minTimeWithCost(NN);

void solve() {
	int i = 0, n = 0, m = 0, S;
	cin >> n >> m >> S;
      S = min(S, MAX_COINS);
      fr(i, 0, m) {
            int u, v, a, b;
            cin >> u >> v >> a >> b;
            g[u].eb(v, a, b);
            g[v].eb(u, a, b);
      }
      vi C(NN), D(NN);
      fr(i, 0, n) {
            cin >> C[i + 1] >> D[i + 1];
      }

      fr(i, 1, n + 1) {
            minTimeWithCost[i].assign(MAX_COINS + 10, inf);
      }
      vpi emptyy;
      vector<vpi> state(NN, emptyy);
      state[1].eb(S, 0);
      for(int iter = 0; iter < MAX_COINS+100; iter++) {
            vector<vpi> newState(n + 1, emptyy);
            for(int node = 1; node <= n; node++) {
                  for(auto& ns : state[node]) {
                        for(auto& next : g[node]) {
                              int coinsLeft = ns.fi - next.cost;
                              if(coinsLeft < 0) 
                                    continue;
                              if(minTimeWithCost[next.to][coinsLeft] > ns.se + next.time){
                                    minTimeWithCost[next.to][coinsLeft] = ns.se + next.time;
                                    newState[next.to].eb(coinsLeft, ns.se + next.time);
                              }
                        }

                        // exchange one gold coin and update self state
                        if(ns.fi + C[node] <= MAX_COINS and 
                        minTimeWithCost[node][ns.fi+C[node]] > ns.se + D[node]) {
                              minTimeWithCost[node][ns.fi + C[node]] = ns.se + D[node];
                              newState[node].eb(ns.fi + C[node], ns.se + D[node]);
                        } 
                  }
            }

            state = newState;
      }

      for(int t = 2; t <= n; t++) {
            int ans = inf;
            for(i = 0; i < MAX_COINS; i++) {
                  remin(ans, minTimeWithCost[t][i]);
            }
            cout << ans << el;
      }
}

int32_t main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int T = 1;
	for(int tc = 1; tc <= T; tc++) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 8296
#include <iostream>
#include <cstdio>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define el '\n'
#define oo 1000000

const int N = 1e5;
int n, t;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    //freopen("test.inp", "r", stdin);
    //freopen("test.out", "w", stdout);
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if (s == u) cout << a-1 << ' ' << b;
    else cout << a << ' ' << b-1;
}


Measured memory_bytes: 256
import itertools

N,K=map(int,input().split())
d=[]
A=[]
for i in range(K):
    d.append(int(input()))
    A.append(list(map(int,input().split())))
A=list(itertools.chain.from_iterable(A))

count=0
for i in range(1,N+1):
    if not i in A:count+=1
print(count)

Measured memory_bytes: 9180
{-# LANGUAGE FlexibleContexts #-}

import Control.Applicative
import qualified Data.Map.Strict as Map
import Data.List (maximumBy)
import Data.Ord (compare)
import Data.Function (on)

main = do
  [_,capa] <- map (read :: String -> Int) . words <$> getLine
  goods <- map (map (read :: String -> Int) . words) . lines <$> getContents
  print $ snd $ maximumBy (compare `on` snd) $ Map.toList (resolve capa (Map.fromList (zip [0..capa] [0,0..])) goods)

resolve capa capaMap ([v,w]:xs)
  | xs == [] = koushin'
  | otherwise = resolve capa koushin' xs
  where
    koushin' =  koushin capaMap [v,w] (capa-w)
    koushin capaMap [v,w] n
      | n == 0 && capaMap Map.! w <= v          = Map.insert w v capaMap
      | n == 0                                           = capaMap
      | oldValue == 0                               = next
      | capaMap Map.! (n+w) >= v + oldValue   = next
      | otherwise = koushin (Map.insert (n+w) (v + oldValue) capaMap) [v,w] (n-1)
      where
        oldValue = capaMap Map.! n
        next        = koushin capaMap [v,w] (n-1)

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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    VI x(m);
    REP(i, m) cin >> x[i];
    if(n >= m) {
        cout << 0 << ln;
        return 0;
    }
    sort(ALL(x));
    VI x_diff(m - 1);
    REP(i, m - 1) x_diff[i] =  x[i + 1] - x[i];
    sort(ALL(x_diff));

    int ans = 0;
    REP(i, m - n) ans += x_diff[i];
    cout << ans << ln;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<ll,ll> pint;

int dp[2002][2002][2];
int main(){
    int n,m;
    cin>>n>>m;
    string s,t;
    cin>>s>>t;
    s+='X',t+='X';
    rep(i,n+1)rep(j,m+1)rep(k,2){
        int mx=0;
        if(k==0){
            if(s[i]=='I') dp[i+1][j][1]=max(dp[i+1][j][1],dp[i][j][k]+1);
            if(t[j]=='I') dp[i][j+1][1]=max(dp[i][j+1][1],dp[i][j][k]+1);
        }
        else{
            if(s[i]=='O'&&dp[i][j][1]!=0) dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]+1);
            if(t[j]=='O'&&dp[i][j][1]!=0) dp[i][j+1][0]=max(dp[i][j+1][0],dp[i][j][k]+1);
        }
    }
    int mx=0;
    rep(i,n+1)rep(j,m+1) mx=max(mx,dp[i][j][1]);
    cout<<mx<<endl;
    return 0;
}


Measured memory_bytes: 34496
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#include<string.h>
int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);                    
    cout.tie(NULL);
   	ll a;
   	cin>>a;
   	cout<<a+a*a+(a*a*a);
   	return 0;
}

Measured memory_bytes: 3644
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;

int main() {
  int n;
  map<string, bool> flag;

  cin >> n;
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (flag[s]) continue;
    ans++;
    flag[s] = true;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 19224
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

#define N 8
bool row[N], col[N], dpos[2 * N - 1], dneg[2 * N - 1];
bool X[N][N];

void print_board() {
	rep(i, 0, N) {
		rep(j, 0, N) {
			if (X[i][j])cout << 'Q';
			else cout << '.';
		}
		cout << endl;
	}
}

void dfs(int i) {
	if (i == N) {
		print_board();
		return;
	}
	rep(j, 0, N) {
		if (X[i][j]) {
			dfs(i + 1);
			return;
		}
	}

	rep(j, 0, N) {
		if (row[i] || col[j] || dpos[i + j] || dneg[i - j + N - 1])continue;
		X[i][j] = true;
		row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = true;
		dfs(i + 1);
		X[i][j] = false;
		row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = false;
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	rep(i, 0, n) {
		int y, x; cin >> y >> x;
		X[y][x] = true;
		row[y] = col[x] = dpos[y + x] = dneg[y - x + N - 1] = true;
	}
	dfs(0);
	return 0;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

// vi sieve(int n) {
// vi primes(n + 1, 1);
// iota(primes.begin(), primes.end(), 0);
// for (int i = 2; i * i <= n; ++i) {
//     if (primes[i] == i) {
//         for (int j = 2 * i; j <= n; j += i) { primes[j] = min(primes[j], i); }
//     }
// }
// return primes;
// }

vector<bool> is_prime(int n) {
    vector<bool> is_prime(n + 1, true);
    for (int i = 2; i * i <= n; ++i) {
        if (is_prime[i] == true) {
            for (int j = 2 * i; j <= n; j += i) { is_prime[j] = false; }
        }
    }
    return is_prime;
}

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

    int n;
    cin >> n;

    int maxv = 0;
    vi a(n);
    rep(i, 0, n) {
        cin >> a[i];
        maxv = max(maxv, a[i]);
    }

    vector<bool> p = is_prime(maxv);

    int ans = 0;
    rep(i, 0, n) {
        if (p[a[i]]) { ++ans; }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 14788
#include <iostream>
#include <string>
using namespace std;
#define MAX 2500

int main(){
  int n,m;
  string str[MAX+1];

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

  int dp[50][50];
  fill(dp[0],dp[50],0);

  for(int i = 1 ; i < n ; i++){
    dp[i][0] = dp[i-1][0]+(str[i][0]-'0');
  }

  for(int j = 1 ; j < m ; j++){
    dp[0][j] = dp[0][j-1] + (str[0][j]-'0');
  }

  for(int i = 1 ; i < n ; i++){
    for(int j = 1 ; j < m ; j++){
      dp[i][j] = min(dp[i-1][j],dp[i][j-1])+(str[i][j]-'0');
    }
  }

  cout << dp[n-1][m-1] << endl;

  return 0;
}

Measured memory_bytes: 1236
#include "bits/stdc++.h"
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

constexpr auto inf = 1e9;

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 ll = long long;

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

	cout << 3 * pow(r, 2) << endl;

	return 0;
}


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

using namespace std;

using ll = long long;
using l = long;
using vi = vector<int>;
using vl = vector<l>;
using vll = vector<ll>;
using vvl = vector<vector<l>>;
using vvll = vector<vector<ll>>;
using pll = pair<ll, ll>;

int main()
{
  string s;
  int n, k; cin >> n >> k; n--; k--;
  cin >> s;
  s[k] = s[k] + 32;
  cout << s;
  return 0;
}


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

int main(){
    long long A,B,N;
    cin >> A >> B >> N;
    
    if(N>=B)
        cout << (B-1)*A/B << endl;
    else{
        /*
        double step=B/(A+0.0);
        //cout << step << endl;
        
        long long K;
        K = (long long)N/step;
        cout << K << endl;
        */
        cout << N*A/B << endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
#define INF 1000000000000000000
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 long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
class Union_Find {
private:
	vector<int> par;
	vector<int> rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y)) rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k; vector<int>a(n); rep(i, n)cin >> a[i];
	int ans = INF;
	for (int i = 0; i < n - k + 1; i++) {
		int sum = min(abs(a[i]) + abs(a[i + k-1] - a[i]), abs(a[i + k-1]) + abs(a[i + k-1] - a[i]));
		ans = min(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }



int main() {
    int N; 
    long long a[9];
    int b[9];

    for(int i= 0; i< 9; i++){cin >> a[i]; b[i] = 0;}

    cin >> N;
    int n;
    for(int i=0; i<N; i++){
        cin >> n;
        for(int j = 0;j<9;j++){
            if(a[j] == n){
                b[j] = 1;
            }
        }
    }

    //条件せってい
    int flag=0;
    for(int i=0;i<3;i++){
        //横
        if((b[3*i]==1) && (b[3*i + 1] ==1)){
            if((b[3*i+2]==1 )&& (b[3*i + 1] ==1)){
                flag = 1;
            }
        }
        //たて
        if((b[i + 3]==1 )&& (b[i] ==1)){
            if((b[i + 6]==1 )&& (b[i + 3] ==1)){
                flag = 1;
            }
        }
    }

    if((b[0] == 1) && (b[4] == 1)){
        if((b[4] == 1) && (b[8] == 1)){
            flag = 1;
        }
    }

    if((b[2] == 1) && (b[4] == 1)){
        if((b[4] == 1) && (b[6] == 1)){
            flag = 1;
        }   
    }
    
    if(flag == 1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    


}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef unsigned  uint;
typedef unsigned long long int ull;
typedef pair<ll,ll> P;
typedef pair<P,long double> Pi;
typedef pair <long double,int> Pd;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//const uint mod=998244353;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
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 (a>b) { a=b; return 1; } return 0; }
const ll MAX = 200010;//設定して
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;//＊１
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
COMinit();
int n;
cin>>n;
n++;
vector<int> used(100005,-1);
int l,r;
for(int i=0;i<n;i++){
    int a;cin>>a;
    if(used[a]!=-1){
        l=used[a];r=n-i-1;
    }
    used[a]=i;
}
for(int k=1;k<=n;k++){
    cout<<(COM(n,k)-COM(l+r,k-1)+mod)%mod<<endl;
}
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define lout cout
#else
stringstream devnull;
#define lout devnull
#endif
template <class C>
inline void vcin(C &a);
template <class C>
inline void vcout(const C a, const string separate = "\n");

int main()
{
  int n;
  cin >> n;
  array<int, 100> bucket;
  bucket.fill(0);
  vector<int> d(n);
  vcin(d);
  for (auto e : d)
  {
    bucket[e - 1]++;
  }

  int cnt = 0;
  for (int b : bucket)
  {
    cnt += (b > 0);
  }

  cout << cnt << endl;

  return 0;
}

template <class C>
inline void vcin(C &c)
{
  for (auto &a : c)
  {
    cin >> a;
  }
}
template <class C>
inline void vcout(const C c, const string separate)
{
  for (auto it = c.begin(); it != c.end(); it++)
  {
    if (it != c.begin())
      cout << separate;
    cout << *it;
  }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_b() {
	ll a, b, c, d;
	string ans;

	cin >> a >> b >> c >> d;

	ll n, m;
	n = ceil((double)c / b);
	m = ceil((double)a / d);

	if (n <= m) {
		ans = "Yes";
	}
	else {
		ans = "No";
	}

	cout << ans << "\n";
}

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

	solve_abc_b();

	return 0;
}

Measured memory_bytes: 3740
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	final static int MOD = (int)1e9 + 7;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt() , m = scan.nextInt();
		char[][] arr = new char[n][m];
		int[][] dp = new int[n][m];
	
		for(int i = 0 ; i < n ; ++i) {
			arr[i] = scan.next().toCharArray();
		}
		for(int i = 0 ; i < n ; i++) {
			if(arr[i][0] == '#')break;
			else dp[i][0] = 1;
		}
		
		for(int j = 0 ; j < m ; j++) {
			if(arr[0][j] == '#')break;
			else dp[0][j] = 1;
		}
		for(int i = 1 ; i < n ; ++i) {
			for(int j = 1; j < m ; ++j) {
				if(arr[i][j] == '#')
					continue;
				if(arr[i-1][j] == '#' && arr[i][j-1] == '#')
					continue;
				else if(arr[i-1][j] == '#')
					dp[i][j] = dp[i][j-1];
				else if(arr[i][j-1] == '#')
					dp[i][j] = dp[i-1][j];
				else dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
			}
		}
		
		System.out.println(dp[n-1][m-1]);
	}
}


Measured memory_bytes: 37472
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>
#include <unordered_map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <sstream>

#include <boost/range/irange.hpp>
using boost::irange;

#include <boost/utility/string_ref.hpp>
using boost::string_ref;

using namespace std;

template<class T, size_t N, class F>
struct compare_n
{
    F f;
    bool operator() (const T& t1, const T& t2)
    {
        return f(get<N>(t1), get<N>(t2));
    }
};

template<class T>
using less_1st = compare_n<T, 0, less<typename tuple_element<0, T>::type>>;

template<class T>
using less_2nd = compare_n<T, 1, less<typename tuple_element<1, T>::type>>;

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

    int64_t n;
    cin >> n;
    vector<int64_t> as(n);
    for(auto& a : as) cin >> a;

    unordered_map<int64_t, int64_t> count;
    
    for(auto a : as){
        count[a]++;
        count[a+1]++;
        count[a-1]++;
    }
    
    cout << max_element(begin(count), end(count), less_2nd<pair<int64_t,int64_t>>())->second << '\n';
    
    return 0;
}



Measured memory_bytes: 5028
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll> > mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;
const int dx[9] = {-1, 0, 0, 1, -1, -1, 1, 1, 0};
const int dy[9] = {0, -1, 1, 0, -1, 1, -1, 1, 0};

int N, K;
int A[101010];

signed main() {
  cin >> N >> K;
  int d = 0;
  REP(i,N) {
    cin >> A[i];
    d = __gcd(d, A[i]);
  }

  if (K % d == 0 && K <= *max_element(A, A + N)) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
using namespace std;
typedef long long int ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a;
	cin >> a;
	a = 48 - a;
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 896
def main():
    N = int(input())
    S = {'AC':0,'WA':0,'TLE':0,'RE':0}
    for n in range(N):
        S[str(input())] += 1
        
    tmp = ['AC','WA','TLE','RE']
    for t in tmp:
        print(t+' x '+str(S[t]))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9200
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int x = in.nextInt();
        int ans = 0;

        for(int i=0; i<=a; i++){
            for(int j=0; j<=b; j++){
                for(int k=0; k<=c ;k++){
                    if(500*i+100*j+50*k == x){
                        ans++;
                    }
                }
            }
        }
        System.out.println(ans);

    }
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MAX = 999999;
const static int MOD = 1000000007;
const static int IINF = INT_MAX;
const static llong LINF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}
template<typename T> T my_lcm(T a, T b){
    return a * b / my_gcd(a, b);    
}


int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    string S;
    cin >> n >> S;

    int ans = 0;
    ostringstream ss;
    for (int i = 0; i < 1000; ++i) {
        ss << setw(3) << setfill('0') << i;
        string V(ss.str());
        int pos = 0, j = 0;
        while (pos < n) {
            if (S[pos] == V[j]) ++j;
            ++pos;
        }
        if (j == 3) ++ans;

        ss.str("");
    }

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

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a!=b && a!=c && b!=c){
    cout<<"3"<<endl;
  }
  else if(a==b && b==c){
    cout<<"1"<<endl;
  }
  else{
    cout<<"2"<<endl;
  }
}
    


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CBugged solver = new CBugged();
        solver.solve(1, in, out);
        out.close();
    }

    static class CBugged {
        private static int ans = 0;
        private static final boolean[][] dp = new boolean[10001][101];
        private static int[] s;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            s = IntStream.range(0, in.nextInt()).map(i -> in.nextInt()).toArray();
            calc(0, 0);
            out.println(ans);
        }

        private static void calc(int sum, int index) {
            if (dp[sum][index]) {
                return;
            }
            dp[sum][index] = true;
            if (index == s.length) {
                if (sum % 10 > 0) {
                    ans = Math.max(ans, sum);
                }
                return;
            }
            calc(sum, index + 1);
            calc(sum + s[index], index + 1);
        }

    }
}



Measured memory_bytes: 28628
def main():
  h, w, k = map(int, input().split())
  C = [list(input()) for _ in range(h)]

  result = 0
  for i in range(1 << h):
    for j in range(1 << w):
      cnt = 0
      for n in range(h):
        if i >> n & 1:
          continue

        for m in range(w):
          if j >> m & 1:
            continue

          if C[n][m] == '#':
            cnt += 1

      if cnt == k:
        result += 1

  print(result)


if __name__ == "__main__":
  main()


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

void sieve(vector<int>& primes)
{
  int n = primes.size();
  primes[0] = primes[1] = 0;
  for (int i = 2; i * i < n; ++i) {
    if (not primes[i]) { continue; }
    for (int j = i * i; j < n; j += i) {
      primes[j] = 0;
    }
  }
}

void check(vector<int>& sims, vector<int>& primes, int left, int right)
{
  for (int i = left; i <= right; ++i) {
    if (primes[i] and primes[(i + 1) / 2]) {
      sims[i] = 1;
    }
  }
}

int main()
{
  int Q;
  scanf("%d", &Q);
  vector<int> L(Q, 0), R(Q, 0);
  int least = INF, most = 0;
  for (int i = 0; i < Q; ++i) {
    scanf("%d %d", &L[i], &R[i]);
    least = min(least, L[i]);
    most = max(most, R[i]);
  }
  vector<int> primes(most + 5, 1);
  sieve(primes);

  vector<int> sims(most + 5, 0);
  check(sims, primes, least, most);
  for (int i = 1; i <= most; ++i) {
    sims[i] += sims[i - 1];
  }
  for (int i = 0; i < Q; ++i) {
    printf("%d\n", sims[R[i]] - sims[L[i] - 1]);
  }
  return 0;
}


Measured memory_bytes: 2176
n, m = map(int,input().split())
from1 = [False]*(n+1)
toN = [False]*(n+1)
for _ in range(m):
    a, b = map(int,input().split())
    if a > b:
        a, b = b, a
    if a == 1:
        from1[b] = True
    if b == n:
        toN[a] = True
for i in range(n):
    if from1[i] and toN[i]:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")


Measured memory_bytes: 6132
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K, C = mapint()
S = list(input())
from heapq import heappop, heappush
from itertools import accumulate

Q = []
left = [0]*K
nx = -1
cnt = 0
for i, s in enumerate(S):
    if i<=nx: continue
    if s=='o':
        left[cnt] = i
        nx = i+C
        cnt += 1
        if cnt==K:
            break
right = [0]*K
nx = -1
cnt = 0
for i, s in enumerate(S[::-1]):
    if i<=nx: continue
    if s=='o':
        right[cnt] = N-i-1
        nx = i+C
        cnt += 1
        if cnt==K:
            break

for l, r in zip(left, right[::-1]):
    if l==r:
        print(l+1)

Measured memory_bytes: 88552
import math
import random
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
input = sys.stdin.readline
S = input().strip()
num = len(S)
if num%2 == 0:
    left = S[:num//2]
    right = S[num//2:]
else:
    left = S[:num//2]
    right = S[num//2+1:]
right = right[::-1]
ans = 0
for i in range(len(left)):
    if left[i] != right[i]:
        ans += 1
print(ans)

Measured memory_bytes: 66924
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int N,L;cin>>N>>L;
    vector<string> S(N,"");
    REP(i,N)cin>>S[i];
    sort(S.begin(),S.end());
    REP(i,N)printf("%s",S[i].c_str());
    cout<<endl;
}

Measured memory_bytes: 256
N = int(input())
A = [list(map(int, input().split())) for n in range(N)]
P = [0] * N


def get_num(i):
    return A[i][P[i]] - 1


def update(mem, K):
    for i in mem:
        P[i] += 1
        if P[i] == N - 1:
            K.remove(i)


def f():
    K = {i for i in range(N)}
    L = {i for i in range(N)}
    mem = set()
    for t in range(N * (N - 1) // 2 + 1):
        if len(K) == 0:
            return t

        for i in L:
            if i in mem:
                continue

            j = get_num(i)
            if j in mem:
                continue

            if i == get_num(j):
                mem.add(i)
                mem.add(j)

        if len(mem) == 0:
            return -1
        update(mem, K)
        L = K & mem
        mem.clear()

    return -2

print(f())


Measured memory_bytes: 35188
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	if(a==0)
		cout<<"1"<<endl;
	else if(b==0)
		cout<<"2"<<endl;
	else if(c==0)
		cout<<"3";
	else if(d==0)
		cout<<"4";
	else if(e==0)
		cout<<"5";
}

Measured memory_bytes: 3596
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector <int> a(n);
	long long sum = 0;
	unordered_map <int, int> m;
	for (int &i : a)  { cin >> i; sum += i; ++m[i];}
	int q;
	cin >> q;
	int b, c;
	while (q--) {
		cin >> b >> c;
		sum += (m[b] * (c - b));
		m[c] += m[b];
		m[b] = 0;
		cout << sum << '\n';
	}
}


Measured memory_bytes: 7512
n = int(input())
v_list = list(map(int, input().split()))

import collections

v_odd = v_list[::2]
v_even = v_list[1::2]

count_odd = collections.Counter(v_odd).most_common(2)
count_even = collections.Counter(v_even).most_common(2)

if count_odd[0][0] != count_even[0][0]:
    ans = len(v_list) - (count_odd[0][1] + count_even[0][1])
elif len(count_odd) == 1 and len(count_even) == 1:
    ans = int(len(v_list) / 2)
elif len(count_odd) == 1 or count_odd[0][1] + count_even[1][1] > count_odd[1][1] + count_even[0][1]:
    ans = len(v_list) - (count_odd[0][1] + count_even[1][1])
else:
    ans = len(v_list) - (count_odd[1][1] + count_even[0][1])

print(ans)

Measured memory_bytes: 15972
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()
x,y = li()

command = s.split("T")

ud = set()
lr = set()

lr.add(len(command[0]))
ud.add(0)

for i, cm in enumerate(command[1:]):
    if i%2 == 1:
        new_lr = set()
        for element in lr:
            new_lr.add(element + len(cm))
            new_lr.add(element - len(cm))
            
        lr = new_lr
        
    else:
        new_ud = set()
        for element in ud:
            new_ud.add(element + len(cm))
            new_ud.add(element - len(cm))
            
        ud = new_ud

if (x in lr) and (y in ud):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3816