akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

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

    long long int k, n;
    n = 2;
    long long int a[50];
    cin >> k;
    int ama = k % 50;
    int count = 0;
    if(k < 50){
        for(int i = 0; i < 50; i++){
            a[i] = 0;
        }
        a[0] = k*50;
    }
    else{
        if(ama == 0){
            for(int i = 0; i < 50; i++){
                a[i] = k/50+49;
            }
        }else{
            for(int i = 0; i < 50; i++){
                if(i < ama){
                    a[i] = (k-ama)/50+49 - ama + 50 + 1 - count;
                    count++;
                }else{
                    a[i] = (k-ama)/50+49 - ama;
                }
            }   
        }
    }
    cout << "50\n";
    for(int i = 0; i < 50; i++){
        cout << a[i] << ' ';
    }
    cout << '\n';

    return 0;
}

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


int main()
{
	int a, b, d, r;
	double fa, fb, f;

	cin >> a >> b;
	fa = a;
	fb = b;

	d = a / b;
	r = a % b;
	f = fa / fb;

	cout << d << " " << r << " " ;
	cout << fixed << setprecision(5) << f << endl;
	
	return 0;
}


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

int main() {
    char s;
    cin >> s;
    if(s >= 'A' && s <= 'Z') {cout << 'A' << endl; return 0;}
    if(s >= 'a' && s <= 'z') { cout << 'a' << endl; return 0;}
    return 0;
}

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

#define fto(i, x, y) for(int i = (x); i <= (y); ++i)
#define fdto(i, x, y) for(int i = (x); i >= (y); --i)
#define ftoa(i, x, y, a) for(int i = (x); i <= (y); i += a)
#define ftoit(it, var) for (__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)

#define ii pair<int, int>
#define mp make_pair
#define FF first
#define SS second

#define vi vector<int>
#define vii vector<ii>
#define ll long long
#define vll vector<ll>

#define eb emplace_back
#define ef emplace_front
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()

#define oo 1000000007
#define OO 1000000000000000007LL

using namespace std;

#define Pro "sevens"
#define maxN 100007

int num_used[5], card[5][10];
bool state[15], check[15];

bool dp(int step, bool player) {
    if (num_used[player] == 6) return player;
    bool couldWin = 0;

    bool couldGo = 0;
    fto (i, 1, 6) {
        int cur_card = card[player][i];
        if (!state[cur_card] && (state[cur_card-1] || state[cur_card+1])) {
            couldGo = 1;
            state[cur_card] = 1;
            ++num_used[player];

            if (dp(step+1, !player) == player) couldWin = 1;
            --num_used[player];
            state[cur_card] = 0;
        }
    }

    if (!couldGo) {
        if (dp(step+1, !player) == player) couldWin = 1;
    }
    return couldWin ? player : !player;
}

int main() {
//    #ifndef ONLINE_JUDGE
//        freopen(Pro".inp", "r", stdin);
//        freopen(Pro".out", "w", stdout);
//    #endif // ONLINE_JUDGE

    int n;
    scanf("%d",&n);

    fto (i_test, 1, n) {
        num_used[0] = num_used[1] = 0;
        fto (i, 1, 13) state[i] = check[i] = 0;

        check[7] = state[7] = 1;
        fto (i, 1, 6) {
            scanf("%d", &card[0][i]);
            check[card[0][i]] = 1;
        }

        int idx = 1;
        fto (i, 1, 13) {
            if (!check[i]) card[1][idx++] = i;
        }

//        fto (i, 1, 6) cout << card[0][i] << " ";
//        puts("");
//
//        fto (i, 1, 6) cout << card[1][i] << " ";
//        puts("");
//
//        puts("");

        if (!dp(1, 0)) puts("yes");
        else puts("no");
    }
    return 0;
}



Measured memory_bytes: 3140
import collections
N = int(input())
cnt = collections.defaultdict(int)
for lower in range(1, N):
    for upper in range(lower, N):
        if lower * upper > N:
            break
        cnt[lower * upper] += 1 if lower == upper else 2
ans = 0
for C in range(1, N):
    ans += cnt[N - C]
print(ans)


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

#define FOR(i, a, b) for(int i = a; i<b; ++i)
#define FR(a, b) for(int i = a; i>=b;--i)
#define _upgrade cin.tie(0); ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define INF 1e9

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int, int> iPair;

const int MAX = 2e5+2;
const int M = 1e9+7;

double dp[301][301][301];
int main()
{
    _upgrade;
    int n, c1 = 0, c2 = 0, c3 = 0;
    cin>>n;
    FOR(i, 0, n)
    {
        int x;
        cin>>x;
        if(x == 1)
            c1++;
        else if(x == 2)
            c2++;
        else
            c3++;
    }
    FOR(i, 0, 301)
        FOR(j, 0, 301)
            FOR(k, 0, 301)
            {
                if(i+j+k > n || i+j+k == 0)
                    continue;
                db a, b, c;
                a = 1.0*k/(i+j+k);
                b = 1.0*j/(i+j+k);
                c = 1.0*i/(i+j+k);
                if(k)
                    dp[k][j][i] += dp[k-1][j][i]*a;
                if(j)
                    dp[k][j][i] += dp[k+1][j-1][i]*b;
                if(i)
                    dp[k][j][i] += dp[k][j+1][i-1]*c;

                dp[k][j][i] += 1.0*n/(i+j+k);
            }
    cout<<setprecision(9)<<fixed<<dp[c1][c2][c3];
}



Measured memory_bytes: 213248
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;




int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================

	int X;
	cin >> X;

	for (int i = 0; i < INF; i++) {
		if ((i + 1) * i >= X * 2) {
			cout << i;
			return 0;
		}
	}


}	




Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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

	int N, K;
	cin >> N >> K;
	
	//priority_queue<int> kind[N];

	vector<priority_queue<int> > kind(N);
	REP(i, N) {
		int t,d;
		cin >> t >> d;
		kind[t - 1].push(d);
	}

	priority_queue<int> best, rem;

	REP(i, N) {

		if (!kind[i].empty()) {
			best.push(kind[i].top());
			kind[i].pop();

			while (!kind[i].empty()) {
				rem.push(kind[i].top());
					kind[i].pop();
			}
		}
	}

	VI sum = { 0 };

	while (!best.empty()) {
		sum.push_back(sum.back() + best.top());
		best.pop();
	}

	VI rsum = { 0 };

	while (!rem.empty()) {
		rsum.push_back(rsum.back() + rem.top());
		rem.pop();
	}
	int ans = 0;
	eFOR(x, 1, K) {
		if (x >= sum.size())break;
		if (K - x >= rsum.size())continue;

		ans = max(ans, sum[x] + rsum[K - x] + x * x);
	}

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



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

int main(){
    int a,b;
    cin >> a >> b;

    string ans, as = to_string(a), bs = to_string(b);

    if(a == b){
        ans = as;
        rep(i, a-1)ans += as;
    }

    else if(a > b){
        ans = bs;
        rep(i, a-1)ans += bs;
    }

    else if(a < b){
        ans = as;
        rep(i, b-1)ans += as;
    }

    cout << ans << endl;
}

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

int main() {
  unsigned N, Z, W;
  std::cin >> N >> Z >> W;
  std::vector<long> a(N + 1);
  for (unsigned i = 1; i <= N; ++i) { std::cin >> a[i]; }
  std::vector<std::pair<long, long>> score(N + 1);
  long maxx = std::abs(a[N] - W);
  long maxy = 0;
  for (unsigned i = N - 1; i > 0; --i) {
    if (i == N - 1) {
      score[i].first = std::abs(a[N] - a[N - 1]);
      score[i].second = -std::abs(a[N] - a[N - 1]);
      maxx = std::max(score[i].first, maxx);
      maxy = score[i].second;
    } else {
      score[i].first = std::min(-maxy, std::abs(a[i] - a[N]));
      score[i].second = std::min(-maxx, -std::abs(a[i] - a[N]));
      maxx = std::max(maxx, score[i].first);
      maxy = std::max(maxy, score[i].second);
    }
  }
  std::cout << maxx << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long ll;
typedef unsigned long long llu;

int main () {
	FIO
	int a,b,c;
	cin>>a>>b>>c;
	if(c-a-b <= 0){
		cout<<"No";
		return 0;
	} 
	ll rhs = 1LL*(c-a-b)*(c-a-b);
	ll lhs = 1LL*4*a*b;
	bool res = (lhs < rhs);
	cout<<(res?"Yes":"No");	
	return 0;
}

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

int main(void){
    int n, l;
    cin >> n >> l;

    int t[n], ans = 0;
    int min = 100;

    rep(i, n){
        t[i] = l + i;
        ans += t[i];
        if(abs(min) > abs(t[i]))
            min = t[i];
    }

    ans -= min;

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


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect, heapq
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m=map(int,input().split())
G=[[] for i in range(3*n)]
for i in range(m):
    u,v=map(int,input().split())
    u-=1; v-=1
    G[3*u].append(3*v+1)
    G[3*u+1].append(3*v+2)
    G[3*u+2].append(3*v)
s,t=map(int,input().split())
s-=1; t-=1

# dp=[[inf]*3 for i in range(n)]
# dp[s][0] = 0

def disktra(g,s):
    c=1
    n=len(g)
    dist = [inf]*n
    dist[s] = 0
    hq=[]
    heapq.heappush(hq,(dist[s],s))
    while hq:
        cost,u =heapq.heappop(hq)
        if dist[u] < cost:
            continue
        for v in g[u]:
            if dist[v] <= dist[u] +c:
                continue
            dist[v] = dist[u] + c
            heapq.heappush(hq,(dist[v],v))
    return dist

dp=disktra(G,3*s)
print(-1 if dp[3*t]==inf else dp[3*t]//3)
# print(*dp,sep="\n")

Measured memory_bytes: 98416
def put(ret, val):
    if val == 0:
        ret.append('A')
    elif val == 1:
        ret.append('B')
    else:
        ret.append('C')


n, a, b, c = map(int, input().split())

s = []

for i in range(n):
    tmp = input()
    if tmp == 'AB':
        val = 0
    elif tmp == 'BC':
        val = 1
    else:
        val = 2
    s.append(val)

ret = []
if a + b + c == 0:
    print('No')
    exit()
elif a + b + c == 1:
    t = []
    t.append(a)
    t.append(b)
    t.append(c)
    for i, item in enumerate(s):
        if t[item] == 1:
            t[item] = 0
            t[(item+1) % 3] = 1
            put(ret, (item+1) % 3)
        elif t[(item+1) % 3] == 1:
            t[item] = 1
            t[(item+1) % 3] = 0
            put(ret, item)
        else:
            print('No')
            exit()
elif a + b + c == 2:
    t = []
    t.append(a)
    t.append(b)
    t.append(c)
    for i, item in enumerate(s):
        if t[item] == 0 and t[(item+1) % 3] == 0:
            print('No')
            exit()
        if t[item] > t[(item+1) % 3]:
            t[item] -= 1
            t[(item+1) % 3] += 1
            put(ret, (item+1) % 3)
        elif t[item] < t[(item+1) % 3]:
            t[item] += 1
            t[(item+1) % 3] -= 1
            put(ret, item)
        elif t[item] == 0:
            print('No')
            exit()
        elif t[item] == 2:
            t[item] -= 1
            t[(item+1) % 3] += 1
            put(ret, (item+1) % 3)
        else:
            if len(s) > i + 1:
                if s[i+1] == (item + 1) % 3:
                    t[item] -= 1
                    t[(item+1) % 3] += 1
                    put(ret, (item+1) % 3)
                else:
                    t[item] += 1
                    t[(item+1) % 3] -= 1
                    put(ret, item)
            else:
                put(ret, item)

else:
    t = []
    t.append(a)
    t.append(b)
    t.append(c)
    for i, item in enumerate(s):
        if t[item] == 0 and t[(item+1) % 3] == 0:
            print('No')
            exit()
        if t[item] > t[(item+1) % 3]:
            t[item] -= 1
            t[(item+1) % 3] += 1
            put(ret, (item+1) % 3)
        else:
            t[item] += 1
            t[(item+1) % 3] -= 1
            put(ret, item)

print('Yes')
for item in ret:
    print(item)


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

int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  
  if (h1 == h2)
    cout << (m2 - m1) - k << endl;
  else {
    int x = (60 - m1) + (h2 - (h1 + 1)) * 60 + m2;
    cout << x - k << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>

int main()
{
  std::string s, t;
  std::cin >> s >> t;
  std::string ans = "UNRESTORABLE";
  int index = -1;
  for (int i = 0; i < s.size() - t.size() + 1; ++i)
  {
    bool includeT = true;
    for (int j = i; j < t.size() + i; ++j)
    {
      if (s[j] == '?' || s[j] == t[j - i]) continue;
      includeT = false;
      break;
    }
    if (includeT)
    {
      index = i;
    }
  }
  if (index == -1)
  {
    std::cout << ans << std::endl;
  }
  else
  {
    ans = s;
    for (int i = index; i < index + t.size(); ++i)
    {
      ans[i] = t[i - index];
    }
    for (int i = 0; i < ans.size(); ++i)
    {
      if (ans[i] == '?')
      {
        ans[i] = 'a';
      }
    }
    std::cout << ans << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int A[3][3];
	for (auto i = 0; i < 3; ++i)
	{
		for (auto j = 0; j < 3; ++j)
		{
			cin >> A[i][j];
		}
	}

	int N;
	cin >> N;
	for (auto k = 0; k < N; ++k)
	{
		int b;
		cin >> b;
		for (auto i = 0; i < 3; ++i)
		{
			for (auto j = 0; j < 3; ++j)
			{
				if (A[i][j] == b)
				{
					A[i][j] = 0;
				}
			}
		}
	}

	auto ans = "No";
	for (auto i = 0; i < 3; ++i)
	{
		if (A[i][0] == 0
			&& A[i][1] == 0
			&& A[i][2] == 0)
		{
			ans = "Yes";
		}
		if (A[0][i] == 0
			&& A[1][i] == 0
			&& A[2][i] == 0)
		{
			ans = "Yes";
		}
	}
	if (A[0][0] == 0
		&& A[1][1] == 0
		&& A[2][2] == 0)
	{
		ans = "Yes";
	}
	if (A[0][2] == 0
		&& A[1][1] == 0
		&& A[2][0] == 0)
	{
		ans = "Yes";
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll GCD(ll a, ll b) { return (b == 0)? a: GCD(b, a % b); }

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

  ll N; cin >> N;
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    for (ll j = 1; j <= N; j++) {
      for (ll k = 1; k <= N; k++) {
        ll g = GCD(i, j);
        g = GCD(g, k);
        ans += g;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3648
user_input = list(map(int, input().split()))
five = 0
seven = 0
for i in range(3):
    if user_input[i] == 5:
        five += 1
    elif user_input[i] == 7:
        seven += 1

if five == 2 and seven == 1:
    print('YES')
else:
    print('NO')

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

int main(void) {
  int n;
  vector<long long> a, b, c;
  long long ans=0;
  long long x;
  cin>>n;
  for(int i=0; i<n; i++) {
    cin>>x;
    a.push_back(x);
  }

  for(int i=0; i<n; i++) {
    cin>>x;
    b.push_back(x);
  }
  for(int i=0; i<n; i++) {
    cin>>x;
    c.push_back(x);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  for(auto i=b.begin(); i!=b.end(); i++) {
    auto u=lower_bound(a.begin(), a.end(), *i);
    auto l=upper_bound(c.begin(), c.end(), *i);
    ans+=(u-a.begin())*(c.end()-l);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};
char c[50][50];

void dfs(int y, int x, int h, int w){
    c[y][x] = '0';
    for(int i = 0; i < 8; i++){
        int ny = y + dy[i], nx = x + dx[i];
        if(ny < 0 or h <= ny or nx < 0 or w <= nx or c[ny][nx] == '0') continue;
        dfs(ny, nx, h, w);
    }
}

int main(void){
    while(true){
        int w, h;
        cin >> w >> h;
        if(w == 0 and h == 0) break;

        for(int y = 0; y < h; y++){
            for(int x = 0; x < w; x++){
                cin >> c[y][x];
            }
        }

        int res = 0;
        for(int y = 0; y < h; y++){
            for(int x = 0; x < w; x++){
                if(c[y][x] == '0') continue;

                dfs(y, x, h, w);
                res++;
            }
        }

        cout << res << '\n';
    }

    return 0;
}


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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

struct dice {
	int back, bottom, front, left, right, top;
};

class Dice {
	dice a;

public:
	Dice(dice& newA) : a(newA) {}

	dice get() {
		return a;
	}

	bool isSame(Dice& b) {
		vector<Dice> tmp;
		for (int i = 0; i < 4; ++i) {
			tmp.push_back(b);
			b.rotate();
		}
		b.move("E");
		for (int i = 0; i < 4; ++i) {
			tmp.push_back(b);
			b.move("N");
		}
		b.move("WN");
		for (int i = 0; i < 4; ++i) {
			tmp.push_back(b);
			b.move("E");
		}
		b.move("SS");
		for (int i = 0; i < 4; ++i) {
			tmp.push_back(b);
			b.move("E");
		}
		b.move("NW");
		for (int i = 0; i < 4; ++i) {
			tmp.push_back(b);
			b.move("N");
		}
		b.move("W");
		for (int i = 0; i < 4; ++i) {
			tmp.push_back(b);
			b.rotate();
		}
		int i;
		for (i = 0; i < 24; ++i) {
			if (a.back == tmp[i].get().back && a.bottom == tmp[i].get().bottom && a.front == tmp[i].get().front && a.left == tmp[i].get().left && a.right == tmp[i].get().right && a.top == tmp[i].get().top) break;
		}
		return i != 24;
	}

	void move(string b) {
		for (char& i : b) {
			dice tmp;
			if (i == 'E') {
				tmp.back = a.back;
				tmp.bottom = a.right;
				tmp.front = a.front;
				tmp.left = a.bottom;
				tmp.right = a.top;
				tmp.top = a.left;
			}
			else if (i == 'N') {
				tmp.back = a.top;
				tmp.bottom = a.back;
				tmp.front = a.bottom;
				tmp.left = a.left;
				tmp.right = a.right;
				tmp.top = a.front;
			}
			else if (i == 'S') {
				tmp.back = a.bottom;
				tmp.bottom = a.front;
				tmp.front = a.top;
				tmp.left = a.left;
				tmp.right = a.right;
				tmp.top = a.back;
			}
			else {
				tmp.back = a.back;
				tmp.bottom = a.left;
				tmp.front = a.front;
				tmp.left = a.top;
				tmp.right = a.bottom;
				tmp.top = a.right;
			}
			a = tmp;
		}
	}

	void rotate() {
		dice tmp;
		tmp.back = a.right;
		tmp.bottom = a.bottom;
		tmp.front = a.left;
		tmp.left = a.back;
		tmp.right = a.front;
		tmp.top = a.top;
		a = tmp;
	}
};

int main() {
	int n, i, j;
	cin >> n;
	vector<Dice> a;
	for (int i = 0; i < n; ++i) {
		dice b;
		cin >> b.top >> b.front >> b.right >> b.left >> b.back >> b.bottom;
		Dice tmp(b);
		a.push_back(tmp);
	}
	for (i = 0; i < n - 1; ++i) {
		for (j = i + 1; j < n; ++j) {
			if (a[i].isSame(a[j])) break;
		}
		if (j != n) break;
	}
	if (i == n - 1) cout << "Yes";
	else cout << "No";
	cout << endl;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){ 
  int n; cin >> n;
  vector<int>A(n);
  rep(i,n) cin >>A[i];
  vector<int>ans(n);
  rep(i,n)ans[A[i]-1]=i+1;
  rep(i,n)cout << ans[i] << endl;
  return 0;
}



Measured memory_bytes: 1664
n=int(input())
t,a=map(int,input().split())
h=[t-int(x)*0.006 for x in input().split()]
ans=0
mn=10**18
for i,hi in enumerate(h):
  t=abs(hi-a)
  if t<mn:
    mn=t
    ans=i+1
print(ans)

Measured memory_bytes: 9264
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define all(x) (x).begin(), (x).end() 

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

long long INF=numeric_limits<long long>::max();

int w[111];
int dp[111];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int n,t = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> w[i];
		t+=w[i];
		if(i)dp[i]+=dp[i-1]+w[i];
		else dp[i] = w[i];
	}
	int d = t;
	for(int i = 0; i < n; i++){
		int cur = t - dp[i];
		d = min(d,abs(dp[i]-cur));
	}
	cout << d << endl;
}	


Measured memory_bytes: 256
#include <stdio.h>
/*ソーシャルゲーム (Social Game)
問題文

JOI 君は明日から新たにソーシャルゲームを始めることにした．

このソーシャルゲームでは，1 日につき 1 回までログインすることができ，ログインするたびに A 枚のコインが得られる．

また，月曜日から日曜日まで 7 日連続でログインすると，そのたびに，追加で B 枚のコインが得られる．

これ以外にコインがもらえることはない．

明日は月曜日である．JOI 君が少なくとも C 枚のコインを得るためにログインしなければならない回数の最小値を求めよ．
制約

    1≦A≦1000
    0≦B≦1000
    1≦C≦1000000(=106)

入力・出力

入力
入力は以下の形式で標準入力から与えられる．
A B C

出力
JOI 君が少なくとも C 枚のコインを得るためにログインしなければならない回数の最小値を出力せよ．
入出力例
入力例 1

3 0 10

出力例 1

4

    1 回のログインあたり 3 枚のコインが得られ，10 枚のコインを集めたい．
    JOI 君は，月曜日から連続 4 日間ログインすることで 12 枚のコインが得られる．
    3 回以下のログインで 10 枚以上のコインを得ることはできないので，JOI 君がログインしなければならない回数の最小値は 4 である．従って，4 を出力する．

入力例 2

1 2 10

出力例 2

8

    1 回のログインあたり 1 枚のコインが得られる．それとは別に，1 週間連続でログインすることで 2 枚のコインが得られる．10 枚のコインを集めたい．
    月曜日から日曜日まで連続でログインすると，日々のコイン 7 枚に加えて，2 枚のコインが得られるため，合計 9 枚のコインが得られる．従って，更にもう 1 回ログインすることにより，10 枚のコインが得られる．
    7 回以下のログインで 10 枚以上のコインを得ることはできないので，JOI 君がログインしなければならない回数の最小値は 8 である．従って，8 を出力する．
 */


void clear_std_io() {
    while (getchar() != '\n');
    {

    }
}
int main()
{
    //ログイン時にもらえるコイン数
    int log_in_bonus = 0;

    //一週間連続ログインするともらえるコイン数
    int weekly_bonus = 0;

    //目標コイン数
    int target = 0;

//    printf(">");
    scanf("%d", &log_in_bonus);
    
    
    scanf("%d", &weekly_bonus);
    
    scanf("%d", &target);
    clear_std_io();
    int current_coin_count = 0 ;
    for (int date_count = 1; /*なし*/;date_count++) {
        current_coin_count += log_in_bonus;
        if (date_count % 7 == 0) {
            current_coin_count += weekly_bonus;
        }

        if (current_coin_count >= target) {
            printf("%d\n", date_count);
            break;
        }
    }
    return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します



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

int main(void) {
  int A, B;
  string S;
  bool flag = true;
  cin >> A >> B >> S;
  for (int i = 0; i < A; i++) {
    if (0 > S[i] - '0' || S[i] - '0' > 9) {
      flag = false;
      break;
    }
  }
  if (S[A] != '-') flag = false;
  for (int i = 0; i < B; i++) {
    if (0 > S[A + 1 + i] - '0' || S[A + 1 + i] - '0' > 9) {
      flag = false;
      break;
    }
  }
  cout << (flag ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
int cnt[N],ans[N],a[N];
int n,q,bl;
int res;
struct node
{
    int l,r,p;

}e[N];
bool cmp(const node &a,const node &b)
{
    return (a.l/bl)==(b.l/bl) ? a.r<b.r :a.l<b.l;
}
void remove(int x)
{
    if((--cnt[a[x]])==0) res--;
}
void add(int x)
{
    if((++cnt[a[x]])==1) res++;
}
int main()
{
    scanf("%d %d",&n,&q);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
     bl=sqrt(n);
    for(int i=1,l,r;i<=q;i++)
    {
        scanf("%d %d",&l,&r);
        e[i]={l,r,i};
    }
  //  cout<<"--------------"<<endl;

    sort(e+1,e+1+q,cmp);
   // cout<<"*****"<<endl;
    res=0;
    int curL=1,curR=0;
    for(int i=1;i<=q;i++)
    {
        //cout<<i<<endl;
        int L=e[i].l,R=e[i].r;
        while(curL<L) remove(curL++);
        while(curL>L) add(--curL);
        while(curR<R) add(++curR);
        while(curR>R) remove(curR--);
        ans[e[i].p]=res;
    }
    for(int i=1;i<=q;i++) printf("%d\n",ans[i]);

}


Measured memory_bytes: 15484
#include <bits/stdc++.h>
using namespace std;
static const int N=100,INFTY=(1<<21);
int n,M[N][N],d[N];
void bfs(int s){
    std::queue<int> q;
    q.push(s);
    for(int i=0;i<n;i++) d[i]=INFTY;
    d[s]=0;
    int u;
    while(!q.empty()){
        u=q.front(); q.pop();
        for(int v=0;v<n;v++){
            if(M[u][v]==0) continue;
            if(d[v]!=INFTY) continue;
            d[v]=d[u]+1;
            q.push(v);
        }
    }
    for(int i=0;i<n;i++){
        cout << i+1 << " " << ((d[i]==INFTY)?(-1):d[i]) << endl;
    }
}

int main(void){
    int u,k,v;
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++) M[i][j]=0;
    }
    for(int i=0;i<n;i++){
        cin >> u >> k;
        u--;
        for(int j=0;j<k;j++){
            cin >> v;
            v--;
            M[u][v]=1;
        }
    }
    bfs(0);
}


Measured memory_bytes: 3108
from bisect import bisect_right

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

def calc(m): #m以下の組が何通りあるかを数える
    count = 0 #組数を数える
    for a in A:
        b = m - a #b以上のは含める
        count += N - bisect_right(A, b - 0.5)
    return count

l = 0 
r = 3 * 10 ** 5

while r - l > 1:
    mid = (l + r) // 2
    if calc(mid) >= M: #合計mid以上の組と手を繋ぐとしたとき、とM回以上握手できる
        l = mid
    else:
        r = mid

B = [0] * (N + 1)
for i in range(N):
    B[i + 1] = B[i] + A[i]

# print(B)
flag = False
for i in range(mid + 3, -1, -1):
    if calc(i) < M:
        flag = False
    else: #初めて手をにぎる回数がM回を下回ったとき
        break

i += 1 #合計この値までは全て使う、残り回数を調整
ans = 0
for a in A:
    b = i - a
    tmp = bisect_right(A, b - 0.5)
    M -= (N - tmp) #使った数
    ans += a * (N - tmp) + (B[-1] - B[tmp])

ans += M * (i - 1)
print (ans)

Measured memory_bytes: 56088
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define int long long
int n,m,k,a[20002],dp[22222];
signed main(){
  cin>>n>>m>>k;
  r(i,n)cin>>a[i];
  r(i,20002)dp[i]=1e16;
  dp[0]=0;
  for(int i=0;i<n;i++){
    int MAX=0,MIN=1e16;
    for(int j=0;j<m;j++){
      if(i+j+1>n)continue;
      MAX=max(MAX,a[i+j]);
      MIN=min(MIN,a[i+j]);
      dp[i+j+1]=min(dp[i+j+1],dp[i]+k+(j+1)*(MAX-MIN));
    }
  }
  cout<<dp[n]<<endl;
}


Measured memory_bytes: 3404
#include <iostream>
//#include <string>
using namespace std;

int main() {
    string number;
    int num, sum;

    while(1) {
        sum = 0;
        cin >> number;

        for (int i=0; i<number.size(); i++)
        {
            num = number[i] - '0';
            sum += num;
        }
        if (sum == 0) break;
        cout << sum << endl;
    }
}

Measured memory_bytes: 3108
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = inpl()

ruiseki = [0]
for i in range(n):
    ruiseki.append(ruiseki[i] + A[i])

C = Counter(ruiseki)
ans = 0
for c in C.values():
    if c == 1:
        continue
    ans += c*(c-1) // 2

print(ans)

Measured memory_bytes: 65276
N, M = map(int, raw_input().split())
a = []
for i in range(N):
    a.append(map(int, raw_input().split()))

mincost = 10001
minnum = 10000
for i in range(N):
    if a[i][1]>M:
        continue
    else:
        if mincost > a[i][0]:
            mincost = a[i][0]
            minnum = i
if mincost == 10001:
  print ("TLE")
else:
  print(a[minnum][0])

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

#define endl "\n"

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

int three_gcd(int a, int b, int c)
{
    return gcd(a, gcd(b, c));
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    long long int sum = 0;
    cin>>n;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            for(int k=1;k<=n;k++)
            {
                sum += three_gcd(i, j, k);
            }

    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>

int main(void)
{
  int a, b, c, min;
  
  scanf("%d%d%d", &a, &b, &c);

  min = a+b;
  if (a+c<min) min = a+c;
  if (b+c<min) min = b+c;
  
  printf("%d\n", min);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
	using namespace std;
const int N=300010;
int n;
long long ans=0;
int a[N];
int main(){
	cin>>n;
	int t=n;
	n*=3;
	for (int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	int p=0,c=0;
	for (int i=n;i>=0;i--) {
		p^=1;
		if (!p) {
			c++;
			ans+=a[i];
		}
		if (c==t) break;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 5010;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; 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(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll dp[101010];

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}

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

char c[2010][2010];
vector<ll>a, p;

ll f(ll n, ll x) {
	if (n == 0) {
		if (x <= 0)return 0;
		else return 1;
	}
	else if (x <= a[n - 1] + 1) {
		return f(n - 1, x - 1);
	}
	else {
		return p[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1]);
	}
}

//long longしか使わない
//素数は1より大きい
int main() {
	ll n, x;
	cin >> n >> x;
	a.resize(n);
	p.resize(n);
	a[0] = 1;
	p[0] = 1;
	for (ll i = 1;i < n;++i) {
		a[i] = a[i - 1] * 2 + 3;
		p[i] = p[i - 1] * 2 + 1;
	}
	cout << f(n, x) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

const int mod = 1000000007;
int N; long long S[404],D[404][404];

int main()
{
	scanf ("%d",&N);
	for (int i=1;i<=N;i++) scanf ("%lld",&S[i]), S[i] += S[i-1];
	for (int l=2;l<=N;l++){
		for (int i=1,j=l;j<=N;i++,j++){
			D[i][j] = D[i][i] + D[i+1][j];
			for (int k=i;k<j;k++){
				if (D[i][j] > D[i][k] + D[k+1][j])
					D[i][j] = D[i][k] + D[k+1][j];
			}
			D[i][j] += S[j] - S[i-1];
		}
	}
	printf ("%lld\n",D[1][N]);
	return 0;
}


Measured memory_bytes: 1408
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


class UnionFind:
    def __init__(self, n):
        self.d = [-1] * n

    def find(self, x):
        if(self.d[x] < 0):
            return x
        self.d[x] = self.find(self.d[x])
        return self.d[x]

    def unite(self, x, y):
        xd = self.find(x)
        yd = self.find(y)
        if(xd == yd):
            return False
        if self.d[xd] > self.d[yd]:
            self.d[yd] += self.d[xd]
            self.d[xd] = yd
        else:
            self.d[xd] += self.d[yd]
            self.d[yd] = xd
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -1 * self.d[self.find(x)]


def main():
    n, m, k = map(int, input().split())
    uf = UnionFind(n)
    fr = [0] * n
    bl = [[] for _ in range(n)]
    for i in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        fr[a] += 1
        fr[b] += 1
        uf.unite(a, b)
    for i in range(k):
        c, d = map(int, input().split())
        c -= 1
        d -= 1
        bl[c].append(d)
        bl[d].append(c)

    ans = [0]*n
    for i in range(n):
        t = uf.size(i)-1-fr[i]
        for j in range(len(bl[i])):
            if(uf.same(i, bl[i][j])):
                t -= 1
        ans[i] = t
    print(*ans)


main()


Measured memory_bytes: 94624
#![allow(non_snake_case,unused_imports,dead_code)]
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::{HashMap,HashSet,VecDeque,BinaryHeap};
use std::cmp::Ordering;

use proconio::input;
use proconio::marker::{Chars,Usize1,Isize1};

fn comp_f64(a: &f64, b: &f64) -> Ordering {
    if a < b {
        return Ordering::Less;
    } else if a > b {
        return Ordering::Greater;
    }
    Ordering::Equal
}

fn main() {
    input!{
        N:usize,
        mut P:[usize;N]
    }
    let mut ans = 0;
    for i in 0..N-1{
        if P[i] == i+1{
            ans += 1;
            P[i+1] = P[i];
        }
    }
    if P[N-1] == N{ans += 1;}
    println!("{}",ans);
}

Measured memory_bytes: 3248
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#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> ans(N,-1);
    int M;
    cin >> M;
    rep(i, M){
        int a,b;
        cin >> a >> b; a--;
        if((a == 0 && b == 0 && N != 1) || (ans[a] != b && ans[a] != -1)){
            cout << -1 << endl;
            return 0;
        }
        ans[a] = b;
    }
    if(ans[0] == -1 && N != 1) ans[0] = 1;
    ll sum = 0;
    rep(i,N){
        if(ans[i] == -1) continue;
        sum += ans[i] * pow(10, N-1-i);
    }
    cout << sum << endl;
    return 0;
}

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

typedef long long ll;
const ll INF = 1e+12;

int main() {
	int N, W, sval = 0, ans = 0;
	static ll dp[110][100010];
	cin >> N >> W;
	vector<int> w(N), v(N);
	for (int i = 0; i < N; ++i) {
		cin >> w[i] >> v[i];
		sval += v[i];
	}
	for (int i = 0; i <= N; ++i)
		for (int j = 1; j <= sval; ++j)
			dp[i][j] = INF;
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= sval; ++j) {
			if (j >= v[i - 1]) {
				dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
			}
			else dp[i][j] = min(dp[i - 1][j], dp[i][j]);
		}
	}
	for (int i = 1; i <= sval; ++i)
		if (dp[N][i] <= W) ans = i;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 80128
cnt=0
A=int(input())
B=int(input())
C=int(input())
X=int(input())

for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if 500*i+100*j+50*k==X:
        cnt+=1
print(cnt)
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define INF 1e12
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m; cin>>n>>m;
	int a,b,t; cin>>a>>b;
	For(i,1,n)
	{
		cin>>t;
		a=max(a,t);
	}
	For(i,1,m)
	{
		cin>>t;
		b=min(b,t);
	}
	cout<<(a<b?"No War\n":"War\n");
	return 0;
}

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

int main() {
    string cards[3];
    rep(i, 3) cin >> cards[i];
    int cnt[3];
    rep(i, 3) cnt[i] = -1;
    int turn = 0;
    char ans;
    
    while (true) {
        cnt[turn]++;
        
        if (cnt[turn] >= cards[turn].length()) {
            ans = turn + 'A';
            break;
        }
        
        turn = cards[turn][cnt[turn]] - 'a';
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define MOD 1000000007
#define mkp make_pair
#define maxN 100005
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
const int infi=1e9+7;

void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
cout<<endl;
}
 set<pair<int,int>> primeset;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primeset.insert(mkp(p,1));
}
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}
int wt[maxN],val[maxN];
// int recur_knap(int capacity,int n){
//     if(capacity==0 || n==0 )return 0;
//     if(weight[n-1]>capacity) return recur_knap(capacity,n-1);
//     return max(val[n-1]+recur_knap(capacity-weight[n-1],n-1),recur_knap(capacity,n-1));
//
// }
int knapSack(int W,  int n)
{
   int i, w;
   int K[n+1][W+1];
   for (i = 0; i <= n; i++)
   {
       for (w = 0; w <= W; w++)
       {
           if (i==0 || w==0)
               K[i][w] = 0;
           else if (wt[i-1] <= w)
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]);
           else
                 K[i][w] = K[i-1][w];
       }
   }

   return K[n][W];
}
int32_t main()
{
fastio;
int n;in n;int k;in k;
rep(i,n){
    in wt[i];in val[i];
}
//cout<<recur_knap(k,n)<<endl;
printf("%lld\n",knapSack(k,n));
    return 0;
}


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

int main(){
    int k,x;
    cin>>k>>x;
    for(int i=x-k+1; i<x; i++)
        cout<<i<<' ';
    for(int i=x; i<x+k; i++){
        if(i!=x+k-1)
            cout<<i<<' ';
        else
        {
            cout<<i<<"\n";
        }
        
    }
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        N: usize,
        d: [u64; N],
    }
    let mut d = d;
    d.sort();
    if d[N/2-1] == d[N/2] {
        println!("0");
        return;
    } else {
        println!("{}", d[N/2] - d[N/2-1]);
    }
}



Measured memory_bytes: 4352
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define CAT(a,b)a b
#define VASIZE(a,b,N,...)N
template<class T>auto size(T&&a)->decltype(a.size(), int()) { return a.size(); }
template<class T>typename make_signed<decltype(T() % 0)>::type size(T a) { return a; }
#define REP(t,a,N)for(decltype(size(N))t=size(a),_l##t=size(N);t<_l##t;t++)
#define RREP(t,a,N)for(decltype(size(N))t=size(N)-1,_l##t=size(a);t>=_l##t;t--)
#define rep(t,...)CAT(REP,VASIZE(__VA_ARGS__,(t,__VA_ARGS__),(t,0,__VA_ARGS__)))
#define rrep(t,...)CAT(RREP,VASIZE(__VA_ARGS__,(t,__VA_ARGS__),(t,0,__VA_ARGS__)))
#define all(a)begin(a),end(a)

void Calc();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/

void Calc() {
  string w = in;
  map<char, int> m;
  for (auto& i : w) {
    m[i]++;
  }
  bool ok = true;
  for (auto& i : m) {
    ok &= (i.second % 2 == 0);
    err(i.first, i.second, ok);
  }
  cout << (ok ? "Yes" : "No") << endl;
}


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

int main(){
  int a, b;
  cin >> a >> b;
  if(a%2==0){
    cout << "Even" << endl;
  }else{
    if(b%2==0){
      cout << "Even" << endl;
    }else{
      cout << "Odd" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define moca(a, s, b) a=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
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;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


//for(i=0; i<N; i++) cin >> a[i];


int main(void) {
  ll i, j, k, l;
  
  ll N;
  cin >> N;
  ll a[MAX*2];
  ll cnt[22][22]={};
  
  map<double, ll> mp;
  for(i=0; i<N; i++) {
    double tt;
    cin >> tt;
    a[i]=llround(tt*1e9);
    
    ll t=a[i];
    ll c2=0, c5=0;
    while(t%2==0) {c2++; t/=2;}
    while(t%5==0) {c5++; t/=5;}
    cnt[min(18LL, c2)][min(18LL, c5)]++;
    
  }
  
  
  ll ans=0;
  for(i=0; i<22; i++) {
    for(j=0; j<22; j++) {
      for(k=0; k<22; k++) {
        for(l=0; l<22; l++) {
          if(i==k && j==l) continue;
          
          if(i+k>=18 && j+l>=18) {
            ans+=cnt[i][j]*cnt[k][l];
          }
        }
      }
    }
  }
  ans/=2;
  
  for(i=9; i<22; i++) {
    for(j=9; j<22; j++) {
      ans+=cnt[i][j]*(cnt[i][j]-1)/2;
    }
  }
  pt(ans);
  
}


Measured memory_bytes: 3776