akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
int const N = 1234;
 
long long f[N];
int c[N][4];
long long dp[42];
int can[42];
long long cr[N][4];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) {
      scanf("%d", c[i] + j);
    }
    for (int rot = 0; rot < 4; rot++) {
      long long z = 0;
      for (int e = 0; e < 4; e++) {
        z = z * 1000 + c[i][(e + rot) & 3];
      }
      cr[i][rot] = z;
    }
  }
  long long ans = 0;
  for (int first = 0; first < n; first++) {
    for (int back = first + 1; back < n; back++) {
      for (int rb = 0; rb < 4; rb++) {
        for (int i = 0; i < 4; i++) {
          f[i] = c[first][(i + 1) & 3];
          f[i] = f[i] * 1000 + c[first][i];
          f[i] = f[i] * 1000 + c[back][(-i + rb + 1) & 3];
          f[i] = f[i] * 1000 + c[back][(-i + rb) & 3];
        }
        for (int i = 0; i < 1 << 4; i++) dp[i] = 0;
        dp[0] = 1;
        for (int i = first + 1; i < n; i++) {
          if (i == back) continue;
          for (int j = 0; j < 4; j++) {
            can[j] = 0;
            for (int rot = 0; rot < 4; rot++) {
              if (f[j] == cr[i][rot]) {
                ++can[j];
              }
            }
          }
          
          dp[15] += dp[14] * can[0];
          dp[15] += dp[13] * can[1];
          dp[15] += dp[11] * can[2];
          dp[15] += dp[7] * can[3];
          dp[14] += dp[12] * can[1];
          dp[14] += dp[10] * can[2];
          dp[14] += dp[6] * can[3];
          dp[13] += dp[12] * can[0];
          dp[13] += dp[9] * can[2];
          dp[13] += dp[5] * can[3];
          dp[12] += dp[8] * can[2];
          dp[12] += dp[4] * can[3];
          dp[11] += dp[10] * can[0];
          dp[11] += dp[9] * can[1];
          dp[11] += dp[3] * can[3];
          dp[10] += dp[8] * can[1];
          dp[10] += dp[2] * can[3];
          dp[9] += dp[8] * can[0];
          dp[9] += dp[1] * can[3];
          dp[8] += dp[0] * can[3];
          dp[7] += dp[6] * can[0];
          dp[7] += dp[5] * can[1];
          dp[7] += dp[3] * can[2];
          dp[6] += dp[4] * can[1];
          dp[6] += dp[2] * can[2];
          dp[5] += dp[4] * can[0];
          dp[5] += dp[1] * can[2];
          dp[4] += dp[0] * can[2];
          dp[3] += dp[2] * can[0];
          dp[3] += dp[1] * can[1];
          dp[2] += dp[0] * can[1];
          dp[1] += dp[0] * can[0];
        }
        ans += dp[15];
      }
    }
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<vector<pair<int, int>>> g(n);
	for (int i = 0; i < m; i++) {
		int l, r, d;
		cin >> l >> r >> d;
		l--; r--;
		g[l].emplace_back(r, d);
		g[r].emplace_back(l, -d);
	}
	vector<long long> dist(n, LLONG_MAX);
	bool ok = true;
	for (int i = 0; i < n; i++) {
		if (dist[i] != LLONG_MAX) continue;
		queue<int> que;
		que.push(i);
		dist[i] = 0;
		while ((int) que.size()) {
			int cur = que.front();
			que.pop();
			for (auto &nbr : g[cur]) {
				if (dist[nbr.first] != LLONG_MAX) {
					if (dist[nbr.first] != dist[cur] + nbr.second) ok = false;
				} else {
					dist[nbr.first] = dist[cur] + nbr.second;
					que.push(nbr.first);
				}
			}
		}
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 9728
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
t = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        if math.gcd(i,j) ==1:
            t += 1*len(list(range(1,k+1)))
        else:
            for l in range(1,k+1):
                    t += gcd(i,j,l)
print(t)

Measured memory_bytes: 9632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P =pair<int,int>;
int main(){
	int X;
	cin>>X;
	int yasa=0;
	yasa+=(X/500);
	X=X-yasa*500;
	yasa*=1000;
	yasa+=(X/5)*5;
	cout<<yasa<<endl;
return 0;}

/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

d = {"Gray": 0, "Brown": 0, "Green": 0, "Sky": 0, "Blue": 0, "Yellow": 0, "Orange": 0, "Red": 0}
f = 0

for i in range(N):
    s = A[i]
    if s <= 399:
        d["Gray"] += 1
    elif s >= 400 and s <= 799:
        d["Brown"] += 1
    elif s >= 800 and s <= 1199:
        d["Green"] += 1
    elif s >= 1200 and s <= 1599:
        d["Sky"] += 1
    elif s >= 1600 and s <= 1999:
        d["Blue"] += 1
    elif s >= 2000 and s <= 2399:
        d["Yellow"] += 1
    elif s >= 2400 and s <= 2799:
        d["Orange"] += 1
    elif s >= 2800 and s <= 3199:
        d["Red"] += 1
    elif s >= 3200:
        f += 1

MIN = 0
for v in d.values():
    if v > 0:
        MIN += 1

MAX = MIN + f

if MIN == 0 :
    MIN = 1

print(MIN, MAX)

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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; ++i)
    	cin >> h[i];
    sort(h.begin(), h.end());
    lint total = 0;
    for (int i = 0; i < n-k; ++i) 
    	total += 1ll*h[i];
    cout << total << '\n';
}

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

int main() {
	int t; cin >> t;
	int doublet = 0, maxd = 0;
	for (int i = 0; i < t; i++) {
		int x, y; cin >> x >> y;
		if (x == y) { doublet++; }
		else { maxd = max(maxd, doublet); doublet = 0; }
	}
	maxd = max(maxd, doublet);
	if (maxd >= 3) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;

struct LCA {
private:
  vector<vector<int>> G;
  size_t n, m;
  vector<vector<int>> A;
  void dfs(int v, int p){
    for(auto v_ : G[v]){
      if(v_ == p) continue;
      A[v_][0] = v;
      D[v_] = D[v]+1;
      dfs(v_,v);
    }
  }
  void build(int r){
    dfs(r,-1);
    A[r][0] = r;
    for(size_t i = 1; i < m; ++i){
      for(size_t j = 0; j < n; ++j){
        A[j][i] = A[A[j][i-1]][i-1];
      }
    }
  }
public:
  vector<int> D;
  LCA(const vector<vector<int>>& Tree, int r) : G(Tree), n(Tree.size()), m(1), D(n,0) {
    size_t t = 1;
    while(t < n) ++m, t *= 2;
    A = vector<vector<int>>(n,vector<int>(m,-1));
    build(r);
  }
  size_t query(int u, int v){
    if(D[u] < D[v]) swap(u,v);

    for(size_t i = m-1; i < m; --i){
      size_t u_ = A[u][i];
      if(D[u_] < D[v]) continue;
      u = u_;
    }

    if(u == v) return u;
    assert(D[u] == D[v]);
    for(size_t i = m-1; i < m; --i){
      if(A[u][i] != A[v][i])
        u = A[u][i], v = A[v][i];
    }
    return A[u][0];
  }
};

int main(){
  int N, u, v;
  cin >> N >> u >> v;
  --u,--v;
  vector<vector<int>> T(N);
  for(int i = 0; i < N-1; ++i){
    int a, b;
    cin >> a >> b;
    --a,--b;
    T[a].push_back(b);
    T[b].push_back(a);
  }
  LCA lca(T,v);
  int ans = 0;
  for(int i = 0; i < N; ++i){
    int a = lca.query(u,i);
    int d_a = lca.D[a], d_u = lca.D[u];
    if(d_u-d_a > d_a) continue;
    ans = max(ans,lca.D[i]-1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 24448
sc = iter(open(0).read().split())
ni = lambda: int(next(sc))
ns = lambda: next(sc)

T = ni()
for _ in range(T):
    N = ni()
    A = [ni() for _ in range(N)]
    S = ns()

    B = []
    ans = 0
    for a, s in zip(reversed(A), reversed(S)):
        for b in B:
            a = min(a, a ^ b)

        if a:
            if s == "1":
                ans = 1
                break
            else:
                B.append(a)

    print(ans)

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

int main(){
    int N; cin >> N;
    vector <int> A(N);
    rep(i,N) cin >> A[i];
    int maxA=1;
    int cnt=1;
    rep(i,N){
        A.push_back(A[i]+1);
        A.push_back(A[i]-1);
    }
    sort(A.begin(),A.end());
    rep(i,N*3-1){
        if (A[i]==A[i+1]) cnt++;
        else{
            maxA=max(maxA,cnt);
            cnt=1;
        }
    }
    cout << maxA;
}

Measured memory_bytes: 1784
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(LAST(v));
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI(N);
  vector<unordered_set<int>> G(N);
  FOR(i, N - 1) {
    GI2(a, b);
    G[a - 1].insert(b - 1);
    G[b - 1].insert(a - 1);
  }
  vector<bool> visited(N);
  queue<int> q;
  if (N % 2) {
    print("First");
    return 0;
  }
  FOR(i, N) if (G[i].size() == 1) q.push(i);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    if (visited[v])
      continue;
    if (G[v].size() == 0) {
      print("First");
      return 0;
    }
    int next = *(G[v].begin());
    visited[v] = 1;
    visited[next] = 1;
    G[next].erase(v);
    for (int i : G[next]) {
      G[i].erase(next);
      if (G[i].size() == 1) {
        q.push(i);
      }
    }
  }
  print("Second");
  return 0;
}

Measured memory_bytes: 16512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int k;
	cin >> k;
	int cnt=1;
	int now=7;
	while(true)
	{
		now%=k;
		if(now==0)
			break;

		cnt++;
		now*=10;
		now+=7;

		if(cnt>=100000000)
		{
			cout << -1 << endl;
			return 0;
		}
	}
	cout << cnt << endl;




}

Measured memory_bytes: 3632
import math
N = int(input())
ans = 0
li = []
for i in range(1,math.floor(math.sqrt(N-1))+1):
    if (N-1)%i==0:
        ans += 1
        if not (N-1)//i == i:
            ans += 1
for i in range(1,math.floor(math.sqrt(N))+1):
    if N%i==0:
        li.append(i)
        if not N//i == i:
            li.append(N//i)
for x in li:
    if x != 1:
        e = 1
        while N%(x**e) == 0:
            e += 1
        m = N//(x**(e-1))
        if m%x == 1:
            ans += 1
print(ans-1)

Measured memory_bytes: 40540
local mod = 1000000007
local function badd(x, y) return (x + y) % mod end
local function bsub(x, y) return y <= x and x - y or x + mod - y end
local n, k = io.read("*n", "*n")
local dp1, dp2 = {1}, {0}
for i = 2, k + 1 do
  dp1[i] = 0
end
for i = 1, n do
  local src = i % 2 == 1 and dp1 or dp2
  local dst = i % 2 == 1 and dp2 or dp1
  local a = io.read("*n") + 1
  local sum = 0
  for j = 1, k + 1 do
    sum = badd(sum, src[j])
    if a < j then
      sum = bsub(sum, src[j - a])
    end
    dst[j] = sum
  end
end
local ret = n % 2 == 1 and dp2 or dp1
print(ret[k + 1])


Measured memory_bytes: 2304
from collections import Counter

n = int(input())

s = sorted(input())
ans = Counter(s)
for i in range(n-1):
    s = sorted(input())
    c = Counter(s)
    tmp_dic = {}
    for k,v in ans.items():
        if k in c:
            tmp_dic[k] = min(c[k],v)
    ans = tmp_dic

a = ""
ans_list = sorted(ans.items()) 
for i in ans_list:
    a += i[0]*i[1]
print(a)






Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LL long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int N;
int X[200000];
int Y[200000];
int main(){
  cin>>N;
  FOR(i,0,N){
    cin>>X[i];
    Y[i]=X[i];
  }
  sort(Y,Y+N);
  int M=Y[N/2-1],MM=Y[N/2];
  FOR(i,0,N){
    if(X[i]<=M){
      cout<<MM<<endl;
    }else{
      cout<<M<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3712
#include <iostream>

using namespace std;
 
int main() {
  int n,a,b;
  cin>>n;
  a=n/10;
  b=n/100;
  string str;
  str="No";
  if(a%10==7 || b%10==7 || n%10==7){
    str="Yes";
  }
  cout<<str;
}

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

const int INF = 1e9;
int main() {
    int n;
    while (cin >> n, n) {
        vector<int> sch[55];
        for (int i = 0; i < n; i++) {
            int l;
            cin >> l;
            for (int j = 0; j < l; j++) {
                int d;
                cin >> d;
                sch[d].push_back(i);
            }
        }
        set<int> v[55];
        int ans = -1;
        for (int i = 0; i < n; i++) v[i].insert(i);
        for (int day = 1; day < 31; day++) {
            set<int> t;
            for (int i = 0; i < sch[day].size(); i++) {
                for (auto e : v[sch[day][i]]) t.insert(e);
            }
            if (t.size() == n) {
                ans = day;
                break;
            }
            for (int i = 0; i < sch[day].size(); i++) {
                v[sch[day][i]] = t;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3288
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main(void){

    int S,W;
    cin >> S >> W;

    if(W>=S){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
    
    return 0;
}


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

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

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void){
    int M1, D1, M2, D2;
    scanf("%d %d", &M1, &D1);
    scanf("%d %d", &M2, &D2);

    if(D2==1){
        printf("1");
    }else{
        printf("0");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const long long INF = (1LL << 60);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  ll x;
  cin >> x;

  ll ans = 0;
  ll cnt = 0;
  for(ll i = 0;; i++){
    cnt += i+1;
    ans++;
    if(cnt >= x) break;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 200005
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fd(i,l,r) for(int i=(l);i>=(r);i--)
using namespace std;
#define Set set<int>
#define P pair<int,int>
int n,m,a[maxn],b[maxn];
int main()
{
    IOS;
    cin>>n;
    string k;
    cin>>k;
    int sum=0;
    for (int i = 0; i < n; ++i) {
        if(k[i]=='#')sum++;
        b[i]=sum;
//        cout<<b[i]<<" ";
    }
    int M=min(b[n-1],n-b[n-1]);
    for (int j = 0; j < n; ++j) {
        int i=j+1;
        int t=b[j]+n-i-(b[n-1]-b[j]);
//        cout<<"i:"<<i<<" t:"<<t<<endl;
        M=min(M,t);
    }
    cout<<M;
    return 0;
}


Measured memory_bytes: 1300
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    l = ri()
    print((l*l*l)/27)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main()
{
    ll n;
    cin >> n;
    if(n%2==0){
        cout << n*(n-2)/2 << endl;
        REP(i,n){
            ll k=i+1;
            FOR(j,i+1,n){
                if(k+j+1==n+1){
                    continue;
                }
                cout << k << " " << j+1 << endl;
            }
        }
    }
    else{
        cout << n-1+(n-3)*(n-1)/2 << endl;
        REP(i,n-1){
            ll k=i+1;
            FOR(j,i+1,n){
                if(k+j+1==n){
                    continue;
                }
                cout << k << " " << j+1 << endl;
            }
        }
    }
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <string.h>

int main()
{
    int a,b;
    scanf("%d%d", &a, &b);
    if(a<b)
      printf("a < b\n");
    else if(a>b)
      printf("a > b\n");
    else
      printf("a == b\n");

    return 0;
}



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

long long n,num,f,t,fh,th;

int main()
{
	scanf("%lld",&n);
	scanf("%lld",&num);
	f = num;
	t = -num;
	for ( long long i = 1 ; i < n ; i++ )
	{
		scanf("%lld",&num);
		fh = max(f+num,t-num);
		th = max(f-num,t+num);
		f = fh;
		t = th;
	}
	printf("%lld",f);
	printf("\n");
	return 0;
}

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

using namespace std;

bool is_blackjack(vector<int> &cards)
{
    return (cards[0] == 1 && cards[1] >= 10);
}

int to_num(char ch)
{
    if (ch == 'A') {
        return 1;
    } else if (ch == 'T') {
        return 10;
    } else if (ch == 'J') {
        return 11;
    } else if (ch == 'Q') {
        return 12;
    } else if (ch == 'K') {
        return 13;
    }
    return (ch - '0');
}

int get_point(int c)
{
    return (c >= 10 ? 10 : c);
}

pair<int, int> get_point(vector<int> &cards)
{
    int point = 0, ace_cnt = 0;
    vector<int> ace;
    for (int i = 0; i < (int)cards.size(); i++) {
        if (cards[i] == 1) {
            ace_cnt++;
            point += 11;
        } else {
            point += get_point(cards[i]);
        }
    }
    int jk = 0;
    for (int i = 0; i < ace_cnt; i++) {
        if (point > 21) {
            point -= 10;
            jk++;
        }
    }
    return make_pair(point, ace_cnt - jk);
}

int main()
{
    int N;
    cin >> N;
    while (N--) {
        char ch;
        vector<int> cards;
        int pile[8];
        for (int i = 0; i < 2; i++) {
            cin >> ch;
            cards.push_back(to_num(ch));
        }
        sort(cards.begin(), cards.end());
        for (int i = 0; i < 8; i++) {
            cin >> ch;
            pile[i] = to_num(ch);
        }
        if (is_blackjack(cards)) {
            cout << "blackjack" << endl;
            continue;
        }
        pair<int, int> p;
        int point = 0;
        for (int i = 0; i < 8; i++) {
            p = get_point(cards);
            point = p.first;
            if (point <= 16) {
                cards.push_back(pile[i]);
            } else if (point == 17 && p.second > 0) {
                cards.push_back(pile[i]);
            } else {
                break;
            }
        }
        point = get_point(cards).first;        
        if (point > 21) {
            cout << "bust" << endl;
        } else {
            cout << point << endl;
        }
    }
    return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll dp[5000][5000][4];
int val[5000][5000];

int main(){
	int h,w,K;cin>>h>>w>>K;
	rep(i,K){
		int r,c,v;scanf("%d%d%d",&r,&c,&v);r--;c--;
		val[r][c]=v;
	}
	rep(i,h)rep(j,w)rep(k,4){
		//pick
		if(k<=2){
			if(i+1<h)dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]+val[i][j]);
			if(j+1<w)dp[i][j+1][k+1]=max(dp[i][j+1][k],dp[i][j][k]+val[i][j]);
		}
		if(i+1<h)dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
		if(j+1<w)dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
	}
	ll Max=0;
	rep(k,4){
		if(k<=2)Max=max(Max,dp[h-1][w-1][k]+val[h-1][w-1]);
		else Max=max(Max,dp[h-1][w-1][k]);
	}
	cout<<Max<<endl;
}

Measured memory_bytes: 342880
#include<string>
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    string s;
    cin>>a>>b ;
    cin >> s;
    int flag=0;
    for(int i=0;i<s.length();i++)
    {
        if(i!=a&&!(s[i]>='0' && s[i]<='9'))
            flag=1;
    }
    if(!flag && s[a]=='-')
        printf("Yes");
    else
        printf("No");
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {

	var H,W int

	fmt.Scan(&H,&W)

	S := make([]string,H)

	for i:=0;i<H;i++{

		fmt.Scan(&S[i])
	}

	for i:=0;i<H;i++{

		var result  string
		str := S[i]

		//１つの行を１文字づつ
		for j:=0;j<W;j++{

			cnt := 0

			if str[j] == '.'{

				//左上
				if i != 0 && j!=0 {
					temp:=S[i-1]
				
					if temp[j-1] == '#'{
						cnt++
					}
				}
				
				//真上
				if  i!=0{
				 temp := S[i-1]
				
					if temp[j]  == '#'{
						cnt++
					}
									
				}
				
				//右上
				if  i!=0 && j!= W-1{ 
					temp := S[i-1]
				
					if temp[j+1] == '#' {
						cnt++
					}
				}
				
				//左
				if j!=0{		
				
					if str[j-1] == '#'{
						cnt++
					}
				}
				
				//右
				if  j != W-1{
				
					if str[j+1] == '#'{
						cnt++
					}
				}
				
				//左下
	 			if j!=0 && i != H-1{
				
					temp := S[i+1]
				
					if temp[j-1] == '#'{
						cnt++
					}

				}
				
				//真下
				if i!=H-1{
				
					temp := S[i+1]
					if temp[j] == '#'{
						cnt++
					
					}
				}
				
				//右下
				if i != H-1 && j!=W-1{
					temp :=S[i+1]				
								
					if temp[j+1] == '#'{
						cnt++
					}
				}

				result = result + strconv.Itoa(cnt)

			} else{

				result += "#"
			}

		}

		fmt.Println(result)
	}


}

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

#define int long long
#define all(v) (v).begin(), (v).end()
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int INF = 1e18;

int A, B, Q;
vector<int> s, t;

int bin(vector<int> &v, int key) {
   auto check = [&](int mid) -> bool {
      return v[mid] <= key;
   };

    // [l, r)
   int l = 0;
   int r = v.size();

   while (r - l > 1) {
      int mid = (l + r) / 2;
      if (check(mid)) {
         l = mid;
      } else {
         r = mid;
      }
   }

   return l;
}

int solve(int x) {
  // Right, Leftはxより右にあるか左にあるか
  // abs取るのは、値が見つからなかったときの処理をINFで統一させたいから(-INFあるとめんどい）
  int sRight = abs(*lower_bound(all(s), x));
  // int sLeft = abs(*(upper_bound(all(s), x) - 1));
  int sLeft = s[bin(s, x)];
  int tRight = abs(*lower_bound(all(t), x));
  // int tLeft = abs(*(upper_bound(all(t), x) - 1));
  int tLeft = t[bin(t, x)];

  int ret = INF;

  // (s, t) -> x -> (t, s)
  if (sLeft != INF and tLeft != INF) {
    chmin(ret, abs(x - min(sLeft, tLeft)));
    // dbg2(sLeft, tLeft)
  } 

  // s -> x -> t {
  if (sLeft != INF and tRight != INF) {
    chmin(ret, min(abs(x - sLeft), abs(x - tRight)) + abs(sLeft - tRight));
    // dbg2(sLeft, tRight)
  }

  // t -> x -> s {
  if (tLeft != INF and sRight != INF) {
    chmin(ret, min(abs(x - tLeft), abs(x - sRight)) + abs(tLeft - sRight));
    // dbg2(tLeft, sRight)
  }

  // x -> (s, t) -> (t, s)
  if (sRight != INF and tRight != INF) {
    chmin(ret, abs(max(sRight, tRight) - x));
    // dbg2(sRight, tRight)
  }

  return ret;
}

signed main() {
  cin >> A >> B >> Q;
  s.resize(A);
  t.resize(B);
  for (int i = 0; i < A; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < B; i++) {
    cin >> t[i];
  }

  // 番兵を設置すると値が見つからなかったときの処理が楽になる
  s.push_back(INF);
  s.push_back(-INF);
  t.push_back(INF);
  t.push_back(-INF);
  sort(all(t));
  sort(all(s));

  while (Q--) {
    int x;
    cin >> x;
    int ans = solve(x);
    cout << ans << endl;
    // line()
  }

  return 0;
}

Measured memory_bytes: 2912
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] wd = {
				"SAT",
				"FRI",
				"THU",
				"WED",
				"TUE",
				"MON",
				"SUN",
		};
		String s = sc.next();
		int ans = 99;
		for (int i = 0; i < wd.length; i++) {
			if (s.equals(wd[i])) {
				ans = i + 1;
				break;
			}
		}
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i,a,n) for (i = a; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;



void solve(){
    int n, k;
    cin>>n>>k;
    int a[n+4];
    double b[n+4];
    f(i,n)cin>>a[i];
    f(i,n){
        b[i] = (a[i]*(a[i] + 1))/2;
        b[i] /= a[i];
    }
    for(int i = 1; i < n; i++)b[i] += b[i-1];
    double ans = b[k-1];
    for(int i = k; i < n; i++)ans = max(ans,(b[i] - b[i - k]));
    cout<<fixed<<setprecision(12)<<ans;
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3456
from collections import Counter
N = int(input())
A = list(input())
B = list(input())
C = list(input())
count = 0
for i in range(N):
    tmpA = A[i]
    tmpB = B[i]
    tmpC = C[i]
    a = Counter([tmpA,tmpB,tmpC])
    count+= 3 - a.most_common()[0][1]
print(count)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define ll long long
#define vl vector<ll int>
#define vs vector<string>
#define v vector<int>
#define mi map<int,int>
#define mc map<char,int>

//ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int k;
	cin>>k;
	string s,s1="";
	cin>>s;
	int i,n=s.length();
	if(n>k){
	for(i=0;i<k;i++){
		s1.push_back(s[i]);
		}
		for(i=0;i<3;i++)s1.push_back('.');
	}
	else{s1=s;}
		cout<<s1 <<"\n";
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector <int> s(M, 0);
	vector <int> c(M, 0);
	for (int ii = 0; ii < M; ++ii){
		cin >> s[ii] >> c[ii];
	}

	if (N == 1){
		int ans = -1;
		for (int ii = 0; ii < 10; ++ii){
			bool OK = true;
			//条件をチェック
			for (int jj = 0; jj < M; ++jj){
				if (c[jj] != ii){
					OK = false;
					break;
				}
			}
			if (OK){
				ans = ii;
				break;
			}
		}
		cout << ans << endl;
		return 0;
	}

	if (N == 2){
		int ans = -1;
		for (int ii = 10; ii < 100; ++ii){
			bool OK = true;

			int bottom = ii % 10;
			int top = (ii - bottom) / 10;
			//条件をチェック
			for (int jj = 0; jj < M; ++jj){
				//topのチェック
				if (s[jj] == 1){
					if (c[jj] != top){
						OK = false;
						break;
					}
				}

				//bottomのチェック
				if (s[jj] == 2){
					if (c[jj] != bottom){
						OK = false;
						break;
					}
				}
			}
			if (OK){
				ans = ii;
				break;
			}
		}
		cout << ans << endl;
		return 0;
	}

	if (N == 3){
		int ans = -1;
		for (int ii = 100; ii < 1000; ++ii){
			bool OK = true;

			int tmp = ii % 100;
			int top = (ii - tmp) / 100;
			int bottom = tmp % 10;
			int middle = (tmp - bottom) / 10;
			//条件をチェック
			for (int jj = 0; jj < M; ++jj){
				//topのチェック
				if (s[jj] == 1){
					if (c[jj] != top){
						OK = false;
						break;
					}
				}

				//middleのチェック
				if (s[jj] == 2){
					if (c[jj] != middle){
						OK = false;
						break;
					}
				}

				//bottomのチェック
				if (s[jj] == 3){
					if (c[jj] != bottom){
						OK = false;
						break;
					}
				}
			}
			if (OK){
				ans = ii;
				break;
			}
		}
		cout << ans << endl;
		return 0;
	}


	return 0;
}


Measured memory_bytes: 384
N = input()

lst_A = input().split()

A_sum = 0
B_sum = 0

for i in range(len(lst_A)):
    lst_A[i] = int(lst_A[i])

lst_A.append(-1)

lst_A.sort(reverse=True)

while 1:
    if lst_A[0] == -1:
        break
    A_sum += lst_A[0]
    del lst_A[0]
    if lst_A[0] == -1:
        break
    B_sum += lst_A[0]
    del lst_A[0]

ans = A_sum - B_sum
print(ans)

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


#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }



int N;
vector<int> P, invP;

bool solve() {
    vector<int> maxLeftP(N+1, 0), minRightP(N+1, N-1); // 左累積max、右累積min
    for (int i = 0; i < N; ++i) maxLeftP[i+1] = max(maxLeftP[i], P[i]);
    for (int i = N; i >= 1; --i) minRightP[i-1] = min(minRightP[i], P[i-1]);
    
    // 区間ごとに区切った時に、区間の外へと数字が逃げていかない条件
    // maxLeftP[i+1] = i は (1, 2, ..., i) の部分が最終的にその並び替えになっていることを意味する
    for (int i = 0; i < N-1; ++i) {
        // 連続して固定値のときはそこで途切れているはず
        if (P[i] == i && P[i+1] == i+1) { if (maxLeftP[i+1] != i) return false; }
        
        // 連続して固定値でないときは、i: 左へ行っているはず、i+1: 右へ行っているはず (つまり区切れる)
        if (P[i] != i && P[i+1] != i+1) { if (maxLeftP[i+1] != i) return false; }
    }
    
    for (int i = 1; i+1 < N; ++i) {
        // 増加している i は最後には右隣を pivot としているはずで、その場合はより大きい値が左には来れない
        if (P[i] > i) { if (maxLeftP[i] > P[i]) return false; }
        
        // 減少している i は最後には左隣を pivot としているはずで、その場合はより小さい値が右には来れない
        else if (P[i] < i) { if (minRightP[i] < P[i]) return false; }
    }

    return true;
}

int main() {
    cin >> N;
    P.resize(N); invP.resize(N);
    for (int i = 0; i < N; ++i) cin >> P[i], --P[i], invP[P[i]] = i;
    if (solve()) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define    ll     long long int

vector<int> v;
ll cnt[100005];

int main( )
{
    ll n, a, b, i, j, k;
    cin >> n >> k;
    while (n--) {
        cin >> a >> b;
        if (cnt[a] == 0) {
            v.push_back(a);
        }
        cnt[a] += b;
    }
    sort(v.begin(), v.end());
    j = 0;
    for (i = 0; i < (int) v.size(); i++) {
        if (j + cnt[v[i]] < k) {
            j += cnt[v[i]];
            continue;
        }
        cout << v[i] << '\n';
        return 0;
    }
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN=1e5+5;
int a[MAXN];
LL b[MAXN];

int main()
{
    int n,k;
    while(scanf("%d%d",&n,&k)!=EOF)
    {
        for(int i=1;i<=n;i++)
            scanf("%d%lld",&a[i],&b[i]);
        LL ans=0,sum=0;
        int tmp=k;
        tmp^=((1<<30)-1);
        for(int i=1;i<=n;i++)
        {
            if((tmp&a[i])==0) sum+=b[i];
        }
        ans=max(ans,sum);
        for(int bit=0;bit<=30;bit++)
        {
            sum=0; tmp=k;
            if(tmp&(1<<bit))
            {
                tmp^=(1<<bit);
                tmp|=((1<<bit)-1);
                tmp^=((1<<30)-1);
                for(int i=1;i<=n;i++)
                {
                    if((tmp&a[i])==0) sum+=b[i];
                }
                ans=max(ans,sum);
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstring>

using namespace std;

int main(void){
    int i;
    int sum=0;
    int sum_t=0,len;
    char str[81];
    
    while(cin>>str){
        len=strlen(str)+1;
        for(i=0;i<len;i++){
            if('0'<=str[i]&&str[i]<='9'){
                sum_t*=10;
                sum_t+=str[i]-'0';
            }else{
                sum+=sum_t;
                sum_t=0;
            }
        }
    }
    cout<<sum<<endl;
    return(0);
}

Measured memory_bytes: 1140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <utility>
using namespace std;
#define fol(i,n) for (int i=0;i<n;i++)

int main(){
    int a,b,c;
    cin >>a>>b>>c;
    if (a+b==c)cout << "Yes"<<endl;
    else if (b+c==a) cout << "Yes"<<endl;
    else if (a+c==b) cout << "Yes"<<endl;
    else cout << "No"<<endl;
}


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

using namespace std;

int main() {
	int n,m,x,y;
	cin >> n >> m >> x >> y;
	vector<int> xr(n),yr(m);
	for(int i = 0; i < n; i++) cin >> xr[i];
	for(int i = 0; i < m; i++) cin >> yr[i];
	sort(xr.begin(),xr.end());
	sort(yr.begin(),yr.end());
	bool flag = true;
	flag &= yr[0]-xr[xr.size()-1]>0;
	flag &= x<y;
	flag &= x<yr[0];
	flag &= xr[xr.size()-1]<y;
	cout << ((flag)?"No War":"War") << endl;
	return 0;
}


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

int main()
{
    int array[101];
    int n, count = 0;
    
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> array[i];
    
    for(int i = 0; i < n; ++i){
        for(int j = n - 1; j >= i + 1; --j){
            if(array[j] < array[j - 1]){
                swap(array[j], array[j - 1]);
                ++count;
            }
        }
    }
    
    for(int i = 0; i < n; ++i){
        if(i != 0) cout << ' ';
        cout << array[i];
    }
    cout << endl;
    cout << count << endl;
}

Measured memory_bytes: 1160
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

#print(listA[0],listA[1])
N=listA[0]
i=1
order=[]
listA[1]
import numpy as np
np_=np.array(listA[1])
x=np.argsort(np_)
x1=list(map(lambda y:y+1,x))
print(*x1)

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

int main() {
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	for (int i = s.length() - 2; i >= 0; i--) {
		if (i % 2 == 0) continue;
		if (s.substr(0, i / 2 + 1) == s.substr(i / 2 + 1, i / 2 + 1)) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
from sys import stdin

n = stdin.readline()
n_i = int(n)

a = stdin.readline().rstrip().split()
a_list = list(a)

n_count = 0

if len(a_list) == 2 and a_list[0] == a_list[1] :
    print(n_count + 1)
else :
    for i in range(n_i):
        if i == n_i - 1 :
            break
        if a_list[i] == a_list[i + 1]:
            n_count = n_count + 1
            a_list[i + 1] = "X"

    print(n_count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}
int main()
{
    ios;
    int x,y,flag=0;
    cin>>x>>y;
    for(int i=0;i<=x;i++)
    {
        if((i*2+(x-i)*4==y)||((x-i)*2+i*4==y))
        {
            flag=1;
            break;
        }
    }
    if(flag)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}




























Measured memory_bytes: 3652
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>

using namespace std;
#define REP(i,n) for(unsigned int i=0;i<n;++i)

unsigned int a[200000],n,b;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    REP(i,n)cin>>a[i];
    REP(i,n)b^=a[i];
    REP(i,n)cout<<(a[i]^b)<<"\n";
    return 0;
}

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

typedef long long ll;


int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c,k,ans=0;
    cin>>a>>b>>c>>k;
    if(k==(a+b+c))
        cout<<a-c;
    else if(k<(a+b+c)&&k>=(a+b))
        cout<<a-(k-b-a);
    else if(k<(a+b)&&k>=a)
        cout<<a;
    else
        cout<<k;
    return 0;
}

Measured memory_bytes: 3608
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/
#include <bits/stdc++.h>
#define newline ("\n")
#define deb(x) cerr << (#x) << " = " << (x) << '\n'
#define FOR(x, n) for (int x = 0; x < n; x++)
#define PI (3.141592653589)

#define MOD 1000000007
using namespace std;

int length[100001];
vector<int> adj[100001];
void dfs(int node)
{
    if(length[node] != -1)
    {
        return;
    }
    for(auto child:adj[node])
    {
        dfs(child);
    }
    length[node] = 0;
    for(auto child:adj[node])
    {
        length[node] = max(length[node], length[child] + 1);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // Pikachu, I choose you
    int n, m;
    cin >> n >> m;
    for(int i = 0;i<m;i++)
    {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
    }
    for(int i = 0;i<=n;i++)
    {
        length[i] = -1;
    }
    for(int i = 1;i <=n;i++)
    {
        if(length[i] == -1)
        {
            dfs(i);
        }
    }
    int sol = 0;
    for(int i = 1;i<=n;i++)
    {
        sol = max(sol, length[i]);
    }
    cout << sol;
    return 0;
}

Measured memory_bytes: 8192
N,W = map(int, input().split())
items = []
for i in range(N):
    v, w = map(int, input().split())
    items.append([v, w])
dp = [[0 for j in range(W+1)] for i in range(N+1)]
for i in range(1, N+1):
    iv = items[i-1][0]
    iw = items[i-1][1]
    for j in range(1, W+1):
        if iw <= j: dp[i][j] = max(dp[i-1][j-iw] + iv, dp[i-1][j])
        else: dp[i][j] = dp[i-1][j]
print(dp[N][W])


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

int main(){
    int N;
    cin>>N;
    vector<double> v(N);
    for(int i=0;i<N;i++){
        cin>>v.at(i);
    }

    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());

    double ans;
    double two=1;

    for(int i=0;i<N-1;i++){
        two*=2;
        ans+=v.at(i)/two;
        
    }
    ans+=v.at(N-1)/two;
    cout<<std::fixed<<std::setprecision(7)<<ans<<endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int x,a,b;
    scanf("%d %d %d",&x,&a,&b);
    int n,m;
    if(x>=a)  m = x-a;
    else  m = a-x;
    if(x>=b)  n = x-b;
    else  n = b-x;
    if(n>=m) printf("A\n");
    else printf("B\n");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    int N; scanf("%d", &N);
    map<string ,int> mp;
    rep(i,N){
        string S; cin>>S;
        mp[S]++;
    }
    int ans = 0;
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
        ans++;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 19316
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int max = 1e5 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	//ifstream cin (".in");
	//ofstream cout (".out");
    int n;
    cin >> n;
    for(int i=1; i<66666; i++){
    	if(floor(i*1.08) == n){
    		cout << i << endl;
    		return 0;
    	}
    }
    cout << ":(" << endl;
    return 0;
}




Measured memory_bytes: 3640
from collections import Counter
def main():
    N = int( input())
    t = 10**18
    A = list( map( int, input().split()))
    ans = 1
    if Counter(A)[0] > 0:
        print(0)
        return
    for a in A:
        ans *= a
        if ans > t:
            print(-1)
            return
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 24328
#include <algorithm>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>


using namespace std;


class Solution {
 public:
  void solve(std::istream& in, std::ostream& out) {
    int n;
    in >> n;
    if (n == 3 || n == 5 || n == 7)
      out << "YES\n";
    else out << "NO\n";
  }
};

void solve(std::istream& in, std::ostream& out)
{
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}
// Powered by caide (code generator, tester, and library code inliner)


#include <fstream>
#include <iostream>


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


  istream& in = cin;


  ostream& out = cout;

  solve(in, out);
  return 0;
}



Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a,b,c,x,y,w,h,m,n;
  cin>>m;
  for(i=0;i<m;i++){
    cin>>x>>y>>w>>h>>n;
    c=0;
    for(j=0;j<n;j++){
      cin>>a>>b;
      if(x<=a&&a<=x+w&&y<=b&&b<=y+h)
	c++;
    }
    cout<<c<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
n = int(input())
lis = list(map(int, input().split()))

ans = 0        
while True:
    for i in range(n):
        if lis[i] % 2 == 0:
            lis[i] = lis[i] // 2
        else:
            print(ans)
            exit()
    ans += 1


Measured memory_bytes: 9160
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        String[] s = sc.next().split("");

        int min = 753;
        for (int i = 0; i < s.length - 2; i++) {
            int num = Integer.parseInt(s[i] + s[i + 1] + s[i + 2]);
            min = Math.min(min, Math.abs(753 - num));
        }

        System.out.println(min);
    }
}

Measured memory_bytes: 21460
n=int(input())
arr=[]
for i in range(n):
    a,b=input().split()
    arr.append((a,b))

title=input()
flag=0
out=0
for i in arr:
    if flag==1:
        out+=int(i[1])
    if i[0]==title:
        flag=1 

print(out)


Measured memory_bytes: 3316
n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
le = [[p[0]-p[1], p[0]+p[1]] for p in xl]
le.sort(key = lambda x : x[1])

ans = 0
right = -(10 ** 9) - 1
for i in range(n):
    if right <= le[i][0]:
        ans += 1
        right = le[i][1]

print(ans)

Measured memory_bytes: 42792
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

#define EKI 100
#define KAISHA 20
#define DMAX 200
#define INF (1<<29)

int n,m,c,s,g;
int d[EKI][EKI][KAISHA];
int p[KAISHA];
int q[KAISHA][50+1];
int r[KAISHA][50];

int cost[EKI][EKI];

int calc(int c,int dist){
	int n=0,res=0,t;
	while(dist){
		t = min(dist,q[c][n+1]-q[c][n]);
		res += t*r[c][n];
		dist -= t;
		n++;
	}
	return res;
}
int main(){
	int t1,t2,t3,t4;
	while(cin>>n>>m>>c>>s>>g,n|m|c|s|g){
		int ans=INF;
		fill_n((int*)cost,sizeof(cost)/sizeof(int),INF);
		fill_n((int*)d,EKI*EKI*KAISHA,INF);
		s--;g--;
		while(m--){
			cin>>t1>>t2>>t3>>t4;
			t1--;t2--;t4--;
			if(t3 < d[t1][t2][t4])
				d[t1][t2][t4] = d[t2][t1][t4] = t3;
		}
		for(int i=0;i<c;i++)cin>>p[i];
		for(int i=0;i<c;i++){
			q[i][0] = 0;
			for(int j=1;j<p[i];j++)cin>>q[i][j];
			q[i][p[i]] = INF;
			for(int j=0;j<p[i];j++)cin>>r[i][j];
		}
		rep(l,c){//ワーシャルフロイド
			rep(k,n)rep(i,n)rep(j,n)d[i][j][l] = min(d[i][j][l],d[i][k][l]+d[k][j][l]);
		}
		rep(i,n)rep(j,n){
			int m=INF;
			rep(k,c)if(d[i][j][k]!=INF)m = min(m, calc(k,d[i][j][k]));
			cost[i][j] = m;
		}
		rep(k,n)rep(i,n)rep(j,n)
			cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
		ans = cost[s][g];
		cout<<(ans!=INF?ans:-1)<<endl;
	}
}

Measured memory_bytes: 1696