akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N; cin >> N;
    int d[N];
    int sum = 0;
    for(int i = 0; i < N; i++){
        cin >> d[i];
    }
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
bxs = list(map(int, input().split()))
xs = bxs[:]
dd = defaultdict(set)
for i, x in enumerate(xs):
    dd[x].add(i+1)
xs = list(set(xs))
xs.sort()

#for x, i in xs:
G = [set() for _ in range(N+1)]
G2 = [set() for _ in range(N+1)]
es = []
for i in range(M):
    u, v = map(int, input().split())
    if bxs[u-1] == bxs[v-1]:
        G[v].add(u)
        G[u].add(v)
    elif bxs[u-1] > bxs[v-1]:
        G[u].add(v)
    else:
        G[v].add(u)
    e = (min(u,v), max(u,v))
    es.append(e)

r = True
d = dict()
cc = [-1 for _ in range(N+1)]
for i in range(N):
    if len(G[i+1]) == 0:
        print(-1)
        sys.exit()
for x in xs:
    for u in dd[x]:
        if cc[u] != -1:
            continue
        for c in G[u]:
            if cc[c] == -1:
                cc[u] = 1
                break
            else:
                cc[u] = 1-cc[c]
        stack = [u]
        while stack:
            q = stack.pop()
            for c in G[q]:
                e = (min(q,c), max(q,c))
                if e in d:
                    continue
                d[e] = x
                if cc[c] != -1:
                    continue
                stack.append(c)
                cc[c] = 1 - cc[q]
for i in range(1, N+1):
    if cc[i] == -1:
        print(-1)
        sys.exit()
for i in range(1, N+1):
    print("B"if cc[i] else "W", end="")
print()
for i in range(M):
    print(d[es[i]])



Measured memory_bytes: 134264
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static void Main() {
        for (string line; (line = Console.ReadLine()) != "0";) {
            var dic = new Dictionary<string, int>();
            var n = int.Parse(line);

            for (var i = 0; i < n; i++) {
                var words = Console.ReadLine().Split(' ');
                foreach (var word in words) {
                    if (dic.ContainsKey(word)) {
                        dic[word]++;
                    }
                    else {
                        dic.Add(word, 1);
                    }
                }
            }

            var k = Console.ReadLine();
            var results = dic.Where(kv => kv.Key.StartsWith(k))
                             .OrderByDescending(kv => kv.Value).ThenBy(kv => kv.Key)
                             .Take(5).Select(kv => kv.Key);
            Console.WriteLine(results.Any() ? string.Join(" ", results.ToArray()) : "NA");
        }
    }
}

Measured memory_bytes: 10936
#include<stdio.h>
int main(){
    int a;
    scanf("%d",&a);
    a=a%10;
    if(a==3)printf("bon\n");
    else if(a==0||a==1||a==6||a==8)printf("pon\n");
    else printf("hon\n");
    return 0;
}

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

int main()
{
    ll n, a, b, count, tmp1, tmp2;
    string line;
    cin >> n >> a >> b;
    count=0;
    tmp1=0;
    tmp2=0;
    // printf("%ld %ld %ld\n", n, a, b);

    if(a==0) {
        cout << 0 << endl;
        return 0;
    }

    tmp1=n/(a+b);
    tmp2=n%(a+b);

    if(tmp2>a && tmp2<(a+b)) {
        count=tmp1*a + a;
    } else {
        count=tmp1*a + tmp2;
    }
    cout << count << endl;



    return 0;
}


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

int main(){
  int n,q;
  cin>>n>>q;
  string s;
  cin>>s;
  int a[n];
  a[0]=0;
  rep(i,0,n-1){
    if(s[i]=='A' && s[i+1]=='C'){
      a[i+1]=a[i]+1;
    }
    else{
      a[i+1]=a[i];
    }
  }
  rep(i,0,q){
    int l,r;
    cin>>l>>r;
    cout<<a[r-1]-a[l-1]<<endl;
  }
}

Measured memory_bytes: 1408
N=int(input())
A=list(map(int,input().split()))
total=0
for i in range(N):
  total+=A[i]
average1=int(total/N)
average2=average1+1
ans1=0
ans2=0
for i in range(N):
  ans1+=(A[i]-average1)**2
  ans2+=(A[i]-average2)**2
print(min(ans1,ans2))

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

change = 0
for i in range(N):
    for j in range(N-i-1):
        if A[j] > A[j+1]:
            A[j],A[j+1] = A[j+1],A[j]
            change += 1
print(" ".join(map(str,A)))
print(change)


Measured memory_bytes: 5600
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#include <stdio.h>
#define ll long long
#include<cstring>
#define rep(i,n) for(int i=0;i<n;i++)
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>QUE;//きゅー

int length(char* str) {
	int len = strlen(str);
	return len;
}

int main(void)
{
	char S[100];
	cin >> S;
	int ans = 7;
	if (S[0] == 'S') {
		if (S[1] == 'U') {
			cout << ans;
			return 0;
		}
		cout << ans - 6;
		return 0;
	}
	else if (S[0] == 'M') {
		cout << ans - 1;
		return 0;
	}
	else if (S[0] == 'T') {
		if (S[1] == 'U') {
			cout << ans - 2;
			return 0;
		}
		cout << ans - 4;
		return 0;
	}
	else if (S[0] == 'W') {
		cout << ans - 3;
		return 0;
	}
	else if (S[0] == 'F') {
		cout << ans - 5;
		return 0;
	}
	
	
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cctype>
#define il inline
#define vd void
#define rg register
#define mn 2500005
#define p 998244353
#define rep(i,x,y) for(rg int i=x;i<=y;++i)
#define drp(i,x,y) for(rg int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il int rd(); il vd pc(char c); il vd rt(int x); il vd flush();
template<class T> il T Max(T a,T b){return a>b?a:b;}
template<class T> il T Min(T a,T b){return a<b?a:b;}
int n,m,mm,r,ans,fac[mn],inv[mn];
il int Pow(int a,int b){int ans=1; for(a%=p;b;b&1?ans=1ll*ans*a%p:0,a=1ll*a*a%p,b>>=1); return ans;}
il int C(int n,int m){
	if(n<m) return 0;
	return 1ll*fac[n]*inv[m]%p*inv[n-m]%p;
}
il vd Inc(int &a,int b){if((a+=b)>=p) a-=p;}
il int Ic(int a,int b){return a+b>=p?a+b-p:a+b;}
il int Dc(int a,int b){return a-b<0?a-b+p:a-b;}
int main(){
	n=rd(),m=rd(),fac[0]=1,mm=3*m,r=mm+n;
	rep(i,1,r) fac[i]=1ll*fac[i-1]*i%p;
	inv[r]=Pow(fac[r],p-2);
	drp(i,r-1,0) inv[i]=1ll*inv[i+1]*(i+1)%p;
	drp(i,Min(n,m),0) if(!((mm-i)&1)){
		int t=(mm-i)>>1;
		Inc(ans,1ll*C(n,i)*Dc(C(t+n-1,n-1),Ic(1ll*(n-i)*C(t-(i+(m-i)/2*2+1)+n-1,n-1)%p,1ll*i*C(t-(i+(m-i)/2*2)+n-1,n-1)%p))%p);
	}
	rt(ans);
	return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il int rd(){char c;
	while(!isdigit(c=gc())&&c!='-');
	int f=c=='-'?c=gc(),1:0,x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(int x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end(), greater<int>() );

    ll height=0, width=0;
    bool heightflag = true, widthflag = true;
    rep(i, N-1){
        if(!heightflag && !widthflag) break;

        if(A[i] == A[i+1] && heightflag){
            height = A[i];
            heightflag = false;
            i++;
            continue;
        }

        if(A[i] == A[i+1] && widthflag){
            width = A[i];
            widthflag = false;
            i++;
            continue;
        }
    }

    cout << height*width << endl;

    return 0;
}

Measured memory_bytes: 640
//submitted by HimJ
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;
const int mxn=1e5+1;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  ll t=1;
  //cin>>t;
    while(t--){
            ll n,i,ans=0;
    cin>>n;
    ll arr[n];
    fr(i,0,n)
    {
        cin>>arr[i];
        while(arr[i]%2==0)
        {
            ans++;
            arr[i]/=2;
        }
    }
    cout<<ans;
            

    }
  return 0;
  }



Measured memory_bytes: 384
// atcoder/abc158/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

int di[] = {0, 1, -1, 0, 1, -1, 1, -1};
int dj[] = {1, 0, 0, -1, 1, -1, -1, 1};
constexpr lli mod = 1e9 + 7;

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

  int n, p;
  str s;
  while (cin >> n >> p >> s) {
    if (p == 2 || p == 5) {
      lli sum = 0;
      for (int i = 0; i < s.size(); ++i) {
        if ((s[i] - '0') % p == 0) {
          sum += i + 1;
        }
      }
      cout << sum << endl;
      continue;
    }

    reverse(s.begin(), s.end());

    const int N = 2 * 1e5 + 5;
    static lli u[N];
    fill(u, u + N, -1);
    u[0] = (s[0] - '0') % p;

    lli w = 1;
    for (int i = 1; i < s.size(); ++i) {
      (w *= 10) %= p;
      u[i] = ((s[i] - '0') * w + u[i - 1]) % p;
    }

    lli sum = count(u, u + N, 0);
    map<lli, lli> m;
    for (int i = 0; i < s.size(); ++i) {
      sum += m[u[i]];
      ++m[u[i]];
    }
    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 2708
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
def check(node_hash_list, edge_color_hash, next_node, node, color):
    edge_color_hash[str(node) + " " + str(next_node)] = color
    edge_color_hash[str(next_node) + " " + str(node)] = color
    new_color = 1
    max_color = color
    for new_next_node in node_hash_list[next_node]:
        if new_next_node == node:
            continue
        if color == new_color:
            new_color += 1
        if max_color < new_color:
            max_color = new_color
        temp_color = check(node_hash_list, edge_color_hash, new_next_node, next_node, new_color)
        new_color += 1
        if max_color < temp_color:
            max_color = temp_color
    return max_color
n = int(input())
sys.setrecursionlimit(n * 10)
node_hash_list = {}
print_list = []
for i in range(1, n):
    input_string = input()
    print_list.append(input_string)
    a, b = map(int, input_string.split())
    if a not in node_hash_list:
        node_hash_list[a] = []
    if b not in node_hash_list:
        node_hash_list[b] = []
    node_hash_list[a].append(b)
    node_hash_list[b].append(a)
edge_color_hash = {}
node = 1
color = 0
max_color = 1
for next_node in node_hash_list[node]:
    color += 1
    if max_color < color:
        max_color = color
    temp_color = check(node_hash_list, edge_color_hash, next_node, node, color)
    if max_color < temp_color:
        max_color = temp_color

print(max_color)
for key in print_list:
    print(edge_color_hash[key])

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

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  D(x)         cout << #x << " - " << x << endl;
  #define  D2(x)        cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]" << endl;
  #define  all(x)       (x).begin(), (x).end()
  #define  D2p(x)       cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << endl;
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;


  void solve(){
    int n;
    cin >> n;
    cout << (n>=30?"Yes":"No");
  }

  int main(){
    IOS
    solve();
    cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


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

#define ll long long int

ll Merge(vector<int> &A, int n, int left, int mid, int right, vector<int> &R, vector<int> &L){
    ll cnt = 0;
    int SENTINEL = 2000000000;
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++)    L[i] = A[left + i];
    for (int i = 0; i < n2; i++)    R[i] = A[mid + i];
    L[n1] = SENTINEL;
    R[n2] = SENTINEL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++){
        if (L[i] <= R[j])   A[k] = L[i++];
        else {
            A[k] = R[j++];
            cnt += n1 - i;
        }
    }
    return cnt;
}

ll mergeSort(vector<int> &A, int n, int left, int right, vector<int> &R, vector<int> &L){
    ll v1, v2, v3;
    if (left+1 < right){
        int mid = (left + right) / 2;
        v1 = mergeSort(A, n, left, mid, L, R);
        v2 = mergeSort(A, n, mid, right, L, R);
        v3 = Merge(A, n, left, mid, right, L, R);
        return v1 + v2 + v3;
    }
    else return 0;
}

int main(void){
    int MAX = 200000;
    vector<int> A(MAX), L(MAX/2+2), R(MAX/2+2);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> A[i];
    ll ans = mergeSort(A, n, 0, n, L, R);
    cout << ans << endl;
    return 0;
}



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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int a = 0; a <= A; ++a) {
    for (int b = 0; b <= B; ++b) {
      for (int c = 0; c <= C; ++c) {
        int total = 500*a + 100*b + 50*c; 
        if (total == X) ++res;
      }
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	int T;
	cin >> T;
	int c[1005];
	int t[1005];
	for (int i = 0; i < n; i++) {
		cin >> c[i] >> t[i];
	}
	int min = 1000000;

	for (int i = 0; i < n; i++) {
		if (t[i] <= T) {
			if (c[i] < min) {
				min = c[i];
			}
		}
	}
	if (min == 1000000) {
		cout << "TLE" << endl;
		return 0;
	}
	else {
		cout << min << endl;
		return 0;
	}
	return 0;
}


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

int main() {
  
  int n,m;
  cin >> n >> m;
  
  vector<vector<int>> stu(n,vector<int>(2)),che(m,vector<int>(2));
  for ( int i = 0; i < n; i++){
    for ( int j = 0; j < 2; j++){
      cin >> stu[i][j];
    }
  }
  for ( int i = 0; i < m; i++){
    for ( int j = 0; j < 2; j++){
      cin >> che[i][j];
    }
  }
  
  long long kyori,mn;
  int pnt;
  
  for ( int i = 0; i < n; i++){
    kyori = 0;
    mn = 10000000000;
    for ( int j = 0; j < m; j++){
      kyori = abs(stu[i][0] - che[j][0]) + abs(stu[i][1] - che[j][1]);
      if ( mn > kyori ){
        mn = kyori;
        pnt = j+1;
      }
    }
    cout << pnt << endl;
  }
   
}

Measured memory_bytes: 256
puts 9394,a=?+,0,1,m=9,?<,2,9,u=3,
[a,5-u+=1,3,9]+(0..59).map{[a,u,u,u,a,u,3,6,[a,6,6,6]*(59-_1),?<,6,9,m+=1,a,u,m,u]},
[a,5-u+=1,3,9]+(0..59).map{[a,u,u,u,a,u,3,6,[a,6,6,6]*(59-_1),?<,6,9,m+=1,a,u,m,u]},
(0..59).map{|m|[a,2,2,2]+(1..m).map{[a,40+m-_1,99+_1,u,?<,3,u,u,a,u,2,2]}}

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

using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<int> a(N+1);
	a[0] = -1;
	for (int i = 0; i < N; ++i) {
		cin >> a[i+1];
	}

	int M = 0;
	vector<int> res(N);
	vector<int> ball(N+1,0);
	for (int i = 0; i < N; ++i) {
		int now = 2*(N-i);
		int count = 0;
		while (now <= N) {
			count += ball[now];
			now += N-i;
		}
		if ((a[N-i]+count)%2 == 1) {
			res[M] = N-i;
			++ball[N-i];
			++M;
		}
	}
	cout << M << endl;
	if (M > 0) {
		for (int i = 0; i < M; ++i) {
			cout << res[i] << " ";
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int n;
  cin>>n;
  vector<ll> a(n);
  ll sum=0;
  REP(i,n){
    cin>>a[i];
  }

  vector<ll> ac_front(n),ac_back(n);
  REP(i,n-1){
    if(i==0){
      ac_front[0]=a[0];
      ac_back[n-2]=a[n-1];
    }
    else{
      ac_front[i]=ac_front[i-1]+a[i];
      ac_back[n-2-i]=ac_back[n-1-i]+a[n-1-i];
    }
  }
  ll ans=INF;
  REP(i,n-1){
    ans=min(ans,abs(ac_front[i]-ac_back[i]));
  }
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <string.h>
char s[100], p[100], s_[200];

int main(){
  int i;

  /* scan s & p */
  scanf("%s", s);
  scanf("%s", p);
  
  strcpy(s_,s);
  strcat(s_,s);
  strstr(s_,p)!=NULL ? printf("Yes\n") : printf("No\n");
    
  return 0;
}

Measured memory_bytes: 540
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val Array(x, y, z) = sc.nextLine.split(" ").map(_.toInt)
    if (x % (y + z) >= z) println(x / (y + z))
    else println((x / (y + z)) - 1)

  }
}


Measured memory_bytes: 27448
#include <stdio.h>

int main(void)
{
	int i,j,tmp,ans;
	int N,K;
	scanf("%d %d",&N,&K);
	int large[N];
	
	
	for(i=0;i<N;i++){
		scanf("%d",&tmp);
		large[i] = tmp;
		
	}
	
	
	for(i=0;i<N;i++){
		for(j=i+1;j<N;j++){
			if(large[i] <= large[j]){
				
				tmp =large[i];
				large[i] = large[j];
				large[j] = tmp;
			}
		}
	}	
	
	for(i=0;i<K;i++){
		ans += large[i];
	}
	
	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 128
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
//import std.regex;
import std.container;

void main()
{
	int w, cnt = 1;

	while (w = readln.chomp.to!int, w) {
		auto n = readln.chomp.to!int;
		auto dp = new int[][](n+1, w+1);
		foreach(i; 0..n+1) {
			dp[i][] = -1;
		}
		dp[0][0] = 0;

		foreach (i; 1..n+1) {
			auto tre = readln.chomp.split(",").map!(to!int);
			foreach (j; 0..w+1) {
				if (dp[i-1][j] == -1) continue;
				if (j + tre[1] <= w) {
					dp[i][j+tre[1]] = max(dp[i][j+tre[1]], dp[i-1][j] + tre[0]);
				}
				dp[i][j] = max(dp[i-1][j], dp[i][j]);
			}
		}

		int index, res = -1;
		foreach (i; 0..w+1) {
			if (dp[n][i] > res) {
				res = dp[n][i];
				index = i;
			}
		}
		writeln("Case ", cnt++, ":");
		writeln(res);
		writeln(index);
	}
}

Measured memory_bytes: 6980
#include <bits/stdc++.h>
#define  pb push_back
#define nl "\n"
#define fastScan ios_base::sync_with_stdio(0); cin.tie(NULL);
#define int long long int
using namespace std;
int dp[450][450];
int pref[450];
int s[450];
signed main()
{
	fastScan;
	int n,tot=0;cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
			dp[i][j]=(int)(1e18);
	}
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
		dp[i][i]=0;
		tot+=s[i];
		pref[i]=tot;
	}
	for(int i=0;i<n;i++)
	{
		if(i<n-1)
			dp[i][i+1]=s[i]+s[i+1];
	}
	for(int l=3;l<=n;l++)
	{
		for(int i=0;i<n-l+1;i++)
		{
			int j=i+l-1;
			for(int k=i;k<j;k++)
			{
				int before=0,after=0;
				before=dp[i][k];
				after=dp[k+1][j];
				int sum2=pref[j],sum1=0;
				if(i!=0)
					sum1=pref[i-1];
				dp[i][j]=min(dp[i][j],after+before+sum2-sum1);
			}
		}
	}
	cout<<dp[0][n-1]<<nl;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#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() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    for(int l = 0; l <= k; ++l){
        for(int r = 0; r <= k-l; ++r){
            if(r+l > n) continue;
            int d = k-l-r;
            int now = 0;
            vector<int> s;
            rep(i,l){
                now += a[i];
                s.push_back(a[i]);
            }
            for(int i = n-r; i <= n-1; i++){
                now += a[i];
                s.push_back(a[i]);
            }
            sort(all(s));
            rep(i,d){
                if(i >= s.size()) break;
                if(s[i]>0) break;
                now -= s[i];
            }
            ans = max(ans, now);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  
  bool ans = true;
  
  if(e - a > k) 
    ans = false;
  
  if (ans)
    cout << "Yay!" << endl;
  else 
    cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ep emplace_back
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>

typedef long long ll;

using namespace std;

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


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>

using namespace std;

int RepaintTiles(string s, char start){

    int res = 0; 

    for (int i = 0; i < s.size(); i++){
        if (i % 2 == 0){
            if (s[i] != start){
                res++;
            }
        } else {
            if (s[i] == start){
                res++;
            }
        }
    }

    return res; 

}

int main(){

    string s;
    cin >> s;
    int res = min(RepaintTiles(s, '0'), RepaintTiles(s, '1'));
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Station and Bus
            var S = Console.ReadLine();

            if (S == "AAA" | S == "BBB")
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }
    }
}

Measured memory_bytes: 11092
import java.util.Scanner;

public class Main{ 
        public static void main(String[] args){
            int i;
            String a;
            char b[];
            b = new char[2000];
                Scanner n = new Scanner(System.in);
                a = n.nextLine();
                for(i=0;i<a.length();i++){
                    b[i] = a.charAt(i);
                    if(b[i] >= 'a' && b[i]<='z'){
                        b[i] -= 32;
                    }else if(b[i] >= 'A' && b[i] <= 'Z'){
                        b[i] += 32;
                    }
                }
                for(i=0;i<a.length();i++){
                    System.out.print(b[i]);
                }
                System.out.printf("\n");
        }
    }


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


#define lld long long 

lld max(lld x,lld y)
{
	if(x>y)
		return x;
	return y;
}		
lld min(lld x,lld y)
{

	if(x<y)
		return x;
	return y;
}

lld power(lld x, lld y) 
{ 
    lld temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
} 


void solve ()
{
	lld n,W;
	cin>>n>>W;
	lld v[n],w[n];
	for(lld i=0;i<n;i++)
	{
		cin>>w[i];
		cin>>v[i];
	}
	//cout<<"pp";
	lld *a[n+1]; 
    	for (lld i=0; i<=n; i++) 
	{
         	a[i] = (lld *)malloc((W+1) * sizeof(lld)); 
	}
	//lld a[n+1][W+1];
	
	for(lld i=0;i<=n;i++)
	{
		for(lld j=0;j<=W;j++)
		{
			if(i==0 || j==0)
			{
				a[i][j]=0;
			}
			else if( j-w[i-1]>=0)
			{
				a[i][j]=max(v[i-1]+a[i-1][j-w[i-1]],a[i-1][j]);
			}
			else
			{
				a[i][j]=a[i-1][j];


			}
		}
	}
	cout<<a[n][W]<<"\n";
}



int main()
{
	solve();
}

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

#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 998244353 
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii unordered_map<int,int>
#define mll unordered_map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi  first

#define se second
#define pb push_backP
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}

int main(){
	boost;

	int n,k;
    cin>>n>>k;
    if(k>=n)
        cout<<1;
    else if(n%k==0)
        cout<<n/k;
    else
    {
        cout<<n/k+1;
    }
    
}

Measured memory_bytes: 256
H, W = map(int, input().split())
h_odd = 1 if H%2 == 1 else 0
if H == 1 or W == 1:
    print("1")
else:
    if h_odd == 1:
        H += 1
    print(W * H//2 - int(W//2 + 2**-1) * h_odd)


Measured memory_bytes: 2940
void main()
{
    long n = rdElem;
    long[][] f = n.rdMat;
    long[][] p = n.rdMat;

    long result = long.min;
    foreach (i; 1 .. 1<<10)
    {
        long total;
        foreach (j; 0 .. n)
        {
            long cnt;
            foreach (k; 0 .. 10)
            {
                if ((i & 1 << k) && f[j][k] == 1) ++cnt;
            }
            total += p[j][cnt];
        }

        result = max(result, total);
    }

    result.writeln;
}

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const unsigned int M = 1000000007;
int data[105];
void sum(){
    data[0]=0,data[1]=1;
    for(int i=2;i<105;i++){
        data[i]=data[i-1]+i;
    }
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    sum();
    int n;
    while(cin>>n){
        cout<<data[n]<<endl;
    }
    return 0;
}


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



int count=0;

//二分探索。xが探すもの。Nは整列済みの配列。a,bは範囲
void v_search(int x,int *N,int a,int b){
  if(a<=b){
    int c;
    c=(a+b)/2;
    if(N[c]==x) count+=1;
    else if(N[c] <x) v_search(x,N,c+1,b);
    else v_search(x,N,a,c-1);
  }
}




int main(){
  int n,q;
  int i,j;
  int *N;
  int x;
   

  scanf("%d",&n);
  N=malloc(n*sizeof(int));
  for(i=0;i<n;i++) scanf("%d",&N[i]);
  

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&x);
    v_search(x,N,0,n-1);
  }
  
  printf("%d\n",count);
  return 0;
}
    


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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll n, m;
    cin >> n >> m;
    vector<ll> x(m);
    REP(i, m)
    cin >> x[i];
    SORT(x);
    vector<ll> l(m - 1);
    REP(i, m - 1)
    {
        l[i] = x[i + 1] - x[i];
    }
    SORT(l);
    ll res = 0;
    REP(i, m - n)
    {
        res += l[i];
    }
    cout << res << endl;
    return 0;
}


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

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

// ---
template<class T, T P=1000000007>
struct ModuloP {
    T x;
    ModuloP() : x(0) {}
    ModuloP(T y) { x = y%P; if(x < 0) x += P; }
    ModuloP operator+(const ModuloP y) { return (ModuloP(x)+=y); }
    ModuloP operator*(const ModuloP y) { return (ModuloP(x)*=y); }
    ModuloP operator-(const ModuloP y) { return (ModuloP(x)-=y); }
    ModuloP operator/(const ModuloP y) { return (ModuloP(x)/=y); }
    ModuloP operator-() { return (x == 0) ? ModuloP(P-x) : ModuloP(x); }
    ModuloP& operator+=(const ModuloP y) { x+=y.x; if(x>=P)x-=P; return *this; }
    ModuloP& operator*=(const ModuloP y) { x=((LL)x*(LL)y.x)%P; return *this; }
    ModuloP& operator-=(const ModuloP y) { x+=P-y.x; if(x>=P)x-=P; return *this; }
    ModuloP& operator/=(ModuloP y) { return ((*this)*=y.fermetinv()); }
    bool operator==(const ModuloP y) { return x == y.x; }
    bool operator!=(const ModuloP y) { return x != y.x; }
    bool operator <(const ModuloP y) { return x < y.x; }
    bool operator <=(const ModuloP y) { return x <= y.x; }
    bool operator >(const ModuloP y) { return x > y.x; }
    bool operator >=(const ModuloP y) { return x >= y.x; }

    ModuloP pow(LL n) { // O(log n)
        ModuloP ans(1), t(x);
        while(n) {
            if(n & 1) ans *= t;
            t *= t; n >>= 1;
        }
        return ans;
    }

    ModuloP fermetinv() { return pow(P-2); }

    static ModuloP combination(T n, int r){
        ModuloP m(1),fr(1); REP(i,r) m*=ModuloP(n-i), fr*=ModuloP(i+1);
        return m/fr;
    }
};
using MP = ModuloP<int>;
// ---

int main(){
    INIT;
    LL n, m, k;
    cin >> n >> m >> k;
    MP ans(0);
    FOR(d,1,n) ans += MP(n-d) * MP(m) * MP(m) * MP(d);
    FOR(d,1,m) ans += MP(m-d) * MP(n) * MP(n) * MP(d);
    ans *= MP::combination(n*m-2, k-2);
    cout << ans.x;
}

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

using namespace std;

int main(void) {
    int L;
    cin >> L;

    vector< tuple<int,int,int> > g;
    for(int i=2; i<20; i++) {
        g.emplace_back(i, i+1, 0);
        g.emplace_back(i, i+1, 1 << (19-i));
    }

    for(int j=0; j<=18; j++) {
        if(L >> j & 1) {
            L ^= (1 << j);
            g.emplace_back(1, 20-j, L);
        }
    }

    if(L >> 19 & 1) {
        g.emplace_back(1, 2, 0);
        g.emplace_back(1, 2, 1<<18);
    }

    cout << "20 " << g.size() << endl;
    for(auto e: g) {
        cout << get<0>(e) << ' ' << get<1>(e) << ' ' << get<2>(e) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
package main

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

var nextString func() string

func init() {
	nextString = newReadString(os.Stdin)
}

func main() {
	n := nextInt()
	s := []int{0}

	for i := 0; i < n; i++ {
		a := nextInt()
		s = append(s, s[len(s)-1]+a)
	}
	sort.Ints(s)
	ans := 0
	cnt := 0
	for i := 0; i < len(s)-1; i++ {
		if s[i] == s[i+1] {
			cnt++
		} else {
			cnt = 0
		}
		ans += cnt
	}
	fmt.Println(ans)
}

func nextInt() (result int) {
	result, _ = strconv.Atoi(nextString())
	return
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
		}
		return r.Text()
	}
}


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

ll ans, dp[51][51*51][51];
int x[51];
int n, a;

ll solve(int idx, int rem, int cnt) {
	if(cnt < 0)return 0;
	if(rem < 0)return 0;
	if(idx == n)return !rem && !cnt;
	ll &ret = dp[idx][rem][cnt];
	if(~ret)return ret;
	ret = solve(idx + 1, rem, cnt);
	ret += solve(idx + 1, rem - x[idx], cnt - 1);
	return ret;
}

int main() {
	memset(dp, -1, sizeof dp);
	cin >> n >> a;
	for(int i = 0; i < n; ++i)
		cin >> x[i];

	for(int i = 1; i <= n; ++i) {
		ans += solve(0, a * i, i);
	}

	cout << ans;
}


Measured memory_bytes: 53120
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<queue>
#include<algorithm>
#define ll long long
#define re register
using namespace std;
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
int n;
int gcd(int a,int b)
{
	return b?gcd(b,a%b):a;
}
int main()
{
	n=gi();
	int ans=0;
	for(int i=1;i<=n;i++){
		int x=gi();
		ans=gcd(ans,x);
	}
	printf("%d\n",ans);
	return 0;
}

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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define fi first
#define se second
#define pb push_back
//#define int long long

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 1e5 + 10;
const int oo = 1e18;

int n, m, root, cnt;
int deg[N], ans[N], dp[N], tpid[N], idtp[N];
bool check[N], visit[N];
vector<ii> child[N];
ii edge[N];
stack<int> st;

void dfs(int u) {
    visit[u] = 1;
    for(auto it: child[u])  if(!visit[it.fi])   {
        dfs(it.fi);
    }
    st.push(u);
}

void solve()    {
    dfs(root);
    while(!st.empty())  {
        tpid[st.top()] = ++cnt;
        idtp[cnt] = st.top();
        st.pop();
    }

    FOR(i, 1, n) dp[i] = -1;
    dp[1] = 0;
    FOR(i, 1, n)    {
        int u = idtp[i];
        for(auto it: child[u]) if(dp[tpid[it.fi]] < dp[i] + 1)
            dp[tpid[it.fi]] = dp[i] + 1;
    }
//    FOR(i, 1, n) cout << dp[tpid[i]] << ' '; cout << '\n';
    FOR(i, 1, n)    {
        for(auto it: child[i]) if(dp[tpid[it.fi]] - dp[tpid[i]] > 1)
            check[it.se] = 1;
    }
    FOR(i, 1, n - 1 + m)    if(!check[i])
        ans[edge[i].se] = edge[i].fi;
    FOR(i, 1, n) cout << ans[i] << '\n';
}

signed main()  {
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
//    ios_base::sync_with_stdio(false); cout.tie(0);

    scanf("%d%d", &n, &m);
    FOR(i, 1, n - 1 + m)    {
        int u, v; scanf("%d%d", &u, &v);
        edge[i] = {u, v};
        child[u].pb({v, i});
        deg[v] ++;
    }

    FOR(i, 1, n) if(deg[i] == 0) root = i;

    return solve(), 0;
}


Measured memory_bytes: 14284
// K - Stones
// O(n * k)
// dp[i] is the player can win when there are i stones remaining
#include <bits/stdc++.h>

using namespace std;

#define MEM(a,b)    memset(a, b, sizeof(a))
#define UN(a)       sort(all(a)), a.erase(unique(all(a)), a.end())
#define REV(a)      reverse(all(a))
#define MP(a, b)    make_pair(a, b)
#define PAIR(a, b)  pair<int, int>(a, b)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int inf = 0x7f7f7f7f;
const int maxn = 123456;
const double EPS = 1e-8;

int main() {
    // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    std::vector<int> a(n);
    std::vector<bool> dp(k+1, false);
    int res = inf;
    for(int i = 0; i < n; ++i)cin >> a[i], res = min(a[i], res);
    for(int i = 1; i <= k; ++i){
        for(int j = 0; j < n; ++j){
            if(i >= a[j] && !dp[i-a[j]])dp[i] = 1;
        }
    }
    puts(dp[k] ? "First" : "Second");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<cctype>
using namespace std;
const int inf=0x7fffffff;
const double eps=1e-10;
const double pi=acos(-1.0);
//char buf[1<<15],*S=buf,*T=buf;
//char getch(){return S==T&&(T=(S=buf)+fread(buf,1,1<<15,stdin),S==T)?0:*S++;}
inline int read(){
	int x=0,f=1;char ch;ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch&15);ch=getchar();}
	if(f)return x;else return -x;
}
using namespace std;
const int N=300005;
int n,L,ans=1,cnt,ok;
int x[N],t[N],l[N],r[N];
int main(){
	n=read();L=read()<<1;
	for(int i=1;i<=n;i++)x[i]=read()<<1;
	for(int i=1;i<=n;i++)t[i]=read();
	for(int i=1;i<=n;i++){
		int v=t[i]%L;
		ans+=t[i]/L+(t[i]%L!=0);
		l[i]=(0<v&&v<=x[i]);
		r[i]=(0<v&&v<=L-x[i]);
	}
	for(int i=1;i<n;i++)
		if(cnt&&r[i]){if(l[i])++ok;--ans;--cnt;}
		else if(l[i]) cnt++;
		else if(r[i]&&ok) ok--,cnt++;
	if(r[n])ans--;
	printf("%lld\n",1ll*ans*L);
	return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for(int i = 0; i < n-1; i++){
    map<char, int> cnt;
    int q = 0;
	for(int j = 0; j <= i; j++)
      cnt[s[j]]++;
    for(int j = i+1; j < n; j++)
      if(cnt[s[j]] != 0){
        q++;
        cnt[s[j]] = 0;
      }
    ans = max(q, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
bool dp[N];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,k;cin>>n>>k;
    ll a[n];for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=1;i<=k;i++){
        bool flg=1;
        for(ll j=0;j<n;j++)if(i-a[j]>=0)flg&=dp[i-a[j]];
        dp[i]=!flg;
    }
    cout<<(dp[k]?"First":"Second");
}

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

#define		BMAX		4
#define		FMAX		3
#define		RMAX		10

int main()
{
	int		n;
	scanf("%d", &n);
	int		univ[BMAX][FMAX][RMAX] = { 0 };

	int		b, f, r, v;

	for (int i = 0; i < n; i++)
	{
		scanf("%d %d %d %d", &b, &f, &r, &v);

		univ[b - 1][f - 1][r - 1] += v;
	}

	for (b = 0; b < BMAX; b++)
	{
		for (f = 0; f < FMAX; f++)
		{
			for (r = 0; r < RMAX; r++)
			{
				printf(" %d", univ[b][f][r]);
			}
			printf("\n");
		}
		if (b != BMAX - 1)
			printf("####################\n");
	}

	return 0;
}

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

int main() {
  int DIV = 998244353;
  int N; cin >> N;
  pair<int, int> R[N+1]; int x, d;
  for (int i = 0; i < N; i++) {
    cin >> x >> d;
    R[i] = make_pair(x, d);
  }
  R[N] = make_pair((int)2e+9 + 1, 1);
  sort(R, R+N, [](auto &a, auto &b) {
    return a.first < b.first;
  });
  int num[N], res[N+1];
  vector<int> childs[N+1]; childs[0].push_back(0);
  stack<pair<int, int>> st;
  st.push(make_pair(0, R[0].first + R[0].second));
  for (int i = 1; i <= N; i++) {
    pair<int, int> e;
    while (!st.empty() && (e = st.top()).second <= R[i].first) {
      st.pop();
      num[e.first] = i - e.first;
    }
    if (i < N) {
      if (st.empty()) {
        childs[0].push_back(i);
      } else {
        childs[e.first + 1].push_back(i);
      }
    }
    st.push(make_pair(i, R[i].first + R[i].second));
  }
  for (int i = N; i >= 0; i--) {
    long r = 1;
    vector<int> v = childs[i];
    for (auto it = v.begin(); it != v.end(); it++) {
      r *= res[*it + 1]; r %= DIV;
    }
    r++;
    res[i] = r;
  }
  cout << res[0] - 1 << endl;
}

Measured memory_bytes: 16000
#include<iostream>
#include<queue>
#include<vector>
#include<map>
using namespace std;

vector<int> cards(8);
typedef pair<vector<int>,int> state;
map<vector<int>,int> memo;
queue<state> q;
int mv[4]={-1,1,-4,4};//左，右，上，下

int main()
{
	for(int i=0;i<8;i++) cards[i]=i;
	q.push(state(cards,0));
	memo.insert(map<vector<int>,int>::value_type(cards,0));
	while(!q.empty())
	{
		state now=q.front(); q.pop();
		cards=now.first;
		int zero;
		for(int i=0;i<8;i++)
		{
			if(cards[i]==0) 
			{
				zero=i;
				break;
			}
		}

		for(int i=0;i<4;i++)
		{
			if((zero==3&&i==1)||(zero==4&&i==0)) continue;
			int change=zero+mv[i];
			if(0<=change&&change<=7)
			{
				vector<int> tmp;
				tmp=cards;
				tmp[zero]=cards[change];
				tmp[change]=cards[zero];
				if(memo.find(tmp)==memo.end())
				{
					q.push(state(tmp,now.second+1));
					memo.insert(map<vector<int>,int>::value_type(tmp,now.second+1));
				}
			}
		}
	}

	while(cin>>cards[0]>>cards[1]>>cards[2]>>cards[3]>>cards[4]>>cards[5]>>cards[6]>>cards[7])
	{
		cout<<memo.find(cards)->second<<endl;
	}
	return 0;
}

Measured memory_bytes: 2296
inp = [i for i in input().split()]
com = input()
for i in range(len(com)):
    if com[i] == "N":
        a = []
        a.append(inp[1])
        a.append(inp[5])
        a.append(inp[2])
        a.append(inp[3])
        a.append(inp[0])
        a.append(inp[4])
        inp = a
    elif com[i] == "S":
        a = []
        a.append(inp[4])
        a.append(inp[0])
        a.append(inp[2])
        a.append(inp[3])
        a.append(inp[5])
        a.append(inp[1])
        inp = a
    elif com[i] == "E":
        a = []
        a.append(inp[3])
        a.append(inp[1])
        a.append(inp[0])
        a.append(inp[5])
        a.append(inp[4])
        a.append(inp[2])
        inp = a
    elif com[i] == "W":
        a = []
        a.append(inp[2])
        a.append(inp[1])
        a.append(inp[5])
        a.append(inp[0])
        a.append(inp[4])
        a.append(inp[3])
        inp = a
print(inp[0])

Measured memory_bytes: 7636
N = int(input())
A = [int(i) for i in input().split()]

flag = False
for a in A:
    if a % 2 == 1:
        continue

    if a % 3 == 0 or a % 5 == 0:
        continue

    flag = True

if flag:
    print("DENIED")
else:
    print("APPROVED")

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

using namespace std;

using ll = long long;

const ll INF = 1e9 + 7;

int main() {
	
	int H, W;
	cin>>H>>W;
	ll dp[H+1][W+1];
	char g[H+1][W+1];
	
	for (int i = 0;i <= H;++i) {
		for (int j = 0;j <= W;++j) {
			g[i][j] = '.';
			dp[i][j] = 0;
		}
	}
	
	dp[0][1] = 1;

	for (int i = 1;i <= H;++i) {
		for (int j = 1;j <= W;++j) {
			cin>>g[i][j];
		}
	}
	
	for (int i = 1;i <= H;++i)  {
		for (int j = 1;j <= W;++j) {
			if (g[i][j] == '#') {
				continue;
			}
			
			dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % INF;
		}
	}
	
	cout<<dp[H][W]<<endl;
	return 0;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007

lli a,b;
void solve()
{
    for(int i=1;i<10000;i++)
    {
        lli x=0.08*i;
        lli y=0.1*i;
        if(a==x && b==y)
        {
            cout<<i<<"\n";
            return ;
        }
    }
    cout<<-1<<"\n";

}
int main()
{
    cin>>a>>b;
    solve();
    return 0;
}


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

int main() {
    ll n, k;
    ll MOD = 998244353LL;
    cin >> n >> k;
    vector<ll> left(k), right(k);
    for (int i = 0; i < k; i++) {
        cin >> left[i] >> right[i];
    }

    vector<ll> ans(n, 0LL);
    vector<ll> sum_region(k, 0LL);
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            ans[i] = 1LL;
        } else {
            for (int j = 0; j < k; j++) {
                ans[i] = (ans[i] + sum_region[j]) % MOD;
            }
        }

        // update sum
        for (int j = 0; j < k; j++) {
            if (i + 1 - left[j] >= 0) {
                sum_region[j] = (sum_region[j] + ans[i + 1 - left[j]]) % MOD;
            }
            if (i + 1 - right[j] - 1 >= 0) {
                sum_region[j] = (sum_region[j] - ans[i - right[j]]) % MOD;
                if (sum_region[j] < 0LL) {
                    sum_region[j] += MOD;
                }
            }
        }
    }
    cout << ans[n - 1] << endl;
    return 0;
}

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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

int main() {
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> a(q);
    vector<int> ten(n,0);
    REP(i,q){
        cin >> a[i];
        ten[a[i]-1]++;
    }

    REP(i,n){
        if(q - ten[i] < k)cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1408