akhauriyash/Code-Regression huggingface dataset:
/*
Aldew
PROB: Save Konoha
CLASSIFICATION: Priority Queue
DIFFICULTY:
*/

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <cmath>
#include <string>
#include <map>
#include <math.h>
#include <cstdio>
#include <stack>
#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


typedef long long ll;
typedef unsigned long long ull;

using namespace std;

//void io()
//{
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif
//}

vector <int> factors(int x) {
    vector <int> result;
    int i = 1;
    while(i*i <= x) {
        if(x % i == 0) {
            result.push_back(i);
            if(x/i != i) {
                result.push_back(x/i);
            }
        }
        i++;
    }
    return result;
}

int main()
{
    io;
    int n, k;
    cin >> n >> k;

    vector<int> p(n);
    for(auto& it : p) cin >> it;

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

    int ans = 0;
    for (int i = 0; i < k; i++){
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

const int N = 55;
int n, m;
string a[N], b[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i++){
        cin >> b[i];
    }

    int maxle = n - m;

    for(int i = 0; i <= maxle; i++){
        for(int j = 0; j <= maxle; j++){
            bool can = true;
            for(int k = i; k <= i + m - 1; k++){
                if(a[k].substr(j, m) != b[k - i]){
                    can = false;
                }
            }
            if(can){
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

int main() {
    int r; cin >> r;
    cout << r * r << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define bye return 0
#define Yes cout << "Yes" << "\n"
#define No  cout << "No" << "\n"
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
#define endl cout << "\n"
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    vector<int> v;
    int a, b, c, r;
    cin >> a >> b;
    if(a<=b) cout << "unsafe" << "\n";
    else cout << "safe" << "\n";
   bye;

}



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

int main() {
	string s;
	cin >> s;
	int count = 0;
	for (int i = 0; i < s.size() - 1; i++)
		if (s[i] != s[i + 1])
			count++;
	cout << count << endl;
	return 0;
}

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

int main() {
	bool cards[4][14];
	int n, rank;
	char suit;

	for (int s = 0; s < 4; s++) {
		for (int r = 0; r <= 13; r++) {
			cards[s][r] = 0;
		}
	}
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> suit >> rank;
		if (suit == 'S') cards[0][rank] = 1;
		if (suit == 'H') cards[1][rank] = 1;
		if (suit == 'C') cards[2][rank] = 1;
		if (suit == 'D') cards[3][rank] = 1;
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 1; j < 14; j++) {
			if (cards[i][j] ) continue;
			if (i == 0) suit = 'S';
			if (i == 1) suit = 'H';
			if (i == 2) suit = 'C';
			if (i == 3) suit = 'D';
			cout << suit << ' ' << j << endl;
			
		}
	}

	return 0;
}



Measured memory_bytes: 3048
#include<iostream>

using namespace std;

int main() {
	long long n, pow = 1;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		pow *= i;
		pow = pow % 1000000007;
	}
	if(pow > 1000000007)pow = pow % 1000000007;
	cout << pow << endl;
	return 0;
} 

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int n,m;cin>>n>>m;

    cout<<n*(n-1)/2+m*(m-1)/2<<"\n";

    return 0;

}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []

for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

S = sum(A)
memory = [0] * 100001
for num in A:
    memory[num] += 1

for i in range(Q):
    S_next = S + (C[i] - B[i]) * memory[B[i]]
    print(S_next)
    S = S_next
    memory[C[i]] += memory[B[i]]
    memory[B[i]] = 0


Measured memory_bytes: 92124
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int main()
{

	int n, k, q;
	cin >> n >> k >> q;
	int a[2004];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int b[2004];
	int answer = 1000000009;
	typedef pair<int, int> p;
	for (int x = 0; x < n; x++) {
		int mini = a[x];
		vector<p> vec;
		vector<int> ans;
		int start = 0;
		for (int i = 0; i < n; i++) {
			b[i] = a[i];
			if (b[i] < mini) { vec.push_back(p(start, i-1)); start = i + 1; }
		}
		vec.push_back(p(start, n - 1));
		for (int z = 0; z < vec.size(); z++) {
			p now = vec[z];
			if (now.second - now.first - k + 2 <= 0)continue;
			sort(b + now.first, b + now.second + 1);
			for (int i = 0; i < now.second - now.first - k + 2;i++) {
				ans.push_back(b[now.first+i]);
			}
		}
		if (ans.size() < q)continue;
		sort(ans.begin(), ans.end());
		if (ans[q - 1] - mini<answer)answer = ans[q - 1] - mini;
	}
	cout << answer;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sortu(x) sort((x).begin(),(x).end())
#define sortd(x) sort((x).begin(),(x).end(), greater<int>())
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1e9+7;
#define dame0 { puts("0"); return 0;}
#define dame1 { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define yn2 {puts("YES");}else{puts("NO");}
#define yn3 {puts("yes");}else{puts("no");}
#define on {puts("ok");}else{puts("ng");}
#define on2 {puts("OK");}else{puts("NG");}
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define outa {cout << ans << endl;}
#define out(x) {cout << x << endl;}
using Graph = vector<vector<int>>;
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
//mins(ans,now);  ansに最小値が入る
//if(max(ans,now)) ansが小さければ更新して実行
//ll sum = suma(a);
//int a[33][4];

int main(){
  int a,b; cin>>a>>b;
  if(a-b-b >= 0) cout << a-b-b << endl;
  else cout << 0 << endl;
}

 /*
g++ a.cpp
./a.out

oj d
oj t

debug:ctrl+shift+B problemin

*/


Measured memory_bytes: 3600
///in the name of ALLAH
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
   int l,r,d,c=0;
   cin>>l>>r>>d;
   for(int i=l;i<=r;i++)
   {
       if(i%d==0)
        c++;
   }
   cout<<c<<endl;
}


Measured memory_bytes: 3548
#include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
#include<algorithm>
#include<cstring>
using namespace std;
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int n,sum=0,t=0;
    int b[110],a[110];
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]%10) b[++t]=a[i];
        sum=sum+a[i];
    }
    if(sum%10) cout<<sum<<endl;
    else
    {
        if(t==0) cout<<0<<endl;
        else
        {
            sort(b+1,b+1+t,cmp);
            cout<<sum-b[t]<<endl;
        }
    }
    return 0;
}


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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	int n, m;
	cin >> n >> m;

	set<int> s;


	for (int i = 0; i < m; i++) {
		int tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		if (tmp1==1) {
			if (s.count(tmp2)>0) {
				cout << "POSSIBLE" << "\n";
				return 0;
			}
			s.insert(tmp2);
		}
		if (tmp2==n) {
			if (s.count(tmp1)>0) {
				cout << "POSSIBLE" << "\n";
				return 0;
			}
			s.insert(tmp1);
		}
	}
	cout << "IMPOSSIBLE" << endl;
}


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

const ll MAXN = 200000;
const ll INF = 1001001001001;

ll A, B, Q, ans=0, tmp=0;
vector<ll> As, Bs;

signed main(){
    cin >> A >> B >> Q;
    for(int i=0;i<A;i++) {
        ll a;
        cin >> a;
        As.push_back(a);
    }
    sort(As.begin(), As.end());
    for(int i=0;i<B;i++) {
        ll a;
        cin >> a;
        Bs.push_back(a);
    }
    sort(Bs.begin(), Bs.end());
    for(int i=0;i<Q;i++) {
        ll a;
        cin >> a;
        tmp = INF;
        ans = INF;
        vector<ll>::iterator itr1, itr2;
        itr1 = lower_bound(As.begin(), As.end(), a);
        itr2 = lower_bound(Bs.begin(), Bs.end(), a);
        if(itr1!=As.end()&&itr2!=Bs.end()) {
            tmp = max(*itr1-a, *itr2-a);
            ans = min(ans, tmp);
        }
        if(itr1!=As.begin()&&itr2!=Bs.end()) {
            itr1--;
            tmp = 2*min(*itr2-a, a-*itr1)+max(*itr2-a, a-*itr1);
            ans = min(tmp, ans);
        }
        itr1 = lower_bound(As.begin(), As.end(), a);
        itr2 = lower_bound(Bs.begin(), Bs.end(), a);
        if(itr1!=As.end()&&itr2!=Bs.begin()) {
            itr2--;
            tmp = 2*min(*itr1-a, a-*itr2)+max(*itr1-a, a-*itr2);
            ans = min(tmp, ans);
        }
        itr1 = lower_bound(As.begin(), As.end(), a);
        itr2 = lower_bound(Bs.begin(), Bs.end(), a);
        if(itr1!=As.begin()&&itr2!=Bs.begin()) {
            itr1--;
            itr2--;
            tmp = max(a-*itr1, a-*itr2);
            ans = min(ans, tmp);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3060
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int w,h,n,b;(h=s.nextInt())>0;System.out.println(b<1?n%w+" "+n/w:"LOOP")){String x="";for(w=s.nextInt();h-->0;)x+=s.next();Set<Long>set=new HashSet<Long>();for(n=b=0;x.charAt(n)>46&&b<1;b=set.add((long)n)?0:1)for(int[]c:new int[][]{{62,1},{60,-1},{118,w},{94,-w}})if(x.charAt(n)==c[0])n+=c[1];}}}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    string s;
    cin>>n;
    cin>>s;
    ll ans=0;

    REP(i,2,n){
        if(s[i-2]=='A'&&s[i-1]=='B'&&s[i]=='C'){
            ans++;
        }
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);

ll w[100],v[100],ar[100][100000],sum;

int main()
{
	ll n,wt,mx=0,max_value=0;
	cin>>n>>wt;
	ll i,j;
	for(i=0;i<n;i++){
		cin>>w[i]>>v[i];
		max_value+=v[i];
	}
	vector<ll> dp(max_value+1 , mod);
	dp[0]=0;
	for(i=0;i<n;i++)
	{
		for(j=max_value-v[i];j>=0;j--)
			dp[j+v[i]]=min(dp[j+v[i]] , dp[j]+w[i]);
	}
	for(i=0;i<=max_value;i++)
		if(dp[i]<=wt)
			mx=max(mx,i);
	cout<<mx;
} 

Measured memory_bytes: 1024
import sys

nN = int(input())

A = [0 for i in range(nN)]
B = [0 for i in range(nN)]

nData = []
nData  = input().rstrip().split(' ')
aT = 0
bT = 0


for i in range(nN):
    A[i] = int(nData[i])
    aT += A[i]

nData  = input().rstrip().split(' ')

for i in range(nN):
    B[i] = int(nData[i])
    bT += B[i]

N = bT - aT

nFlag = 0

if N < 0:
    print('No')
    sys.exit()

elif N == 0:
    for i in range(nN):
        if A[i] != B[i]:
            print('No')
            nFlag = 1
            break

    if nFlag == 0:
        print('Yes')

    sys.exit()

else:
    nCnt = 0
    nCntA = 0
    nCntB = 0
    nDiff = 0
    
    for i in range(nN):
        if A[i] > B[i]:
            nDiff = A[i] - B[i]
            nCntB += nDiff
            
        elif B[i] > A[i]:
            nDiff = B[i] - A[i]
            nTmp = nDiff % 2
            if nTmp == 0:
                nCntA += nDiff/2
            else:
                nCntA += nDiff//2 +1
                nCntB += 1
    
    if (N < nCntA) or (N < nCntB):
        print('No')
    
    elif nCntA == nCntB:
        print('Yes')
    
    else :
        nA = (N - nCntA) * 2
        nB = N - nCntB
        if nA == nB:
            print('Yes')
        else:
            print('No')



Measured memory_bytes: 5236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
const int INF = 2e9;

int main(){
    int n, ans=INF, left=0, right=0;
    vector<int> w(100);
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> w[i];
        right += w[i];
    }
    for(int i=0; i<n-1; i++){
        left += w[i];
        right -= w[i];
        ans = min(ans,abs(right-left));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math
while 1:
    n = int(input())
    if n == 0:
        break
    s = list(map(int,input().split()))
    mean = sum(s)/len(s)
    sum_2 = 0
    for t in s:
        sum_2 += (t-mean)**2
    print(math.sqrt(sum_2/len(s)))


Measured memory_bytes: 5696
from math import factorial
mod=10**9+7
def comb(n,r):
    return ((factorial(n)//factorial(r))//factorial(n-r))%mod
n=int(input())
ans=0
for k in range(1,min((n)//3+1,(n-1)//2+1)):
    ans+=comb(n-2*k-1,k-1)
    ans%=mod
print(ans%mod)

Measured memory_bytes: 72372
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <set>

#define v_exists(elem, v) find(v.begin(),v.end(),elem)!=v.end()
#define s_exists(elem, s) s.find(elem)!=s.end()

using namespace std;
const int MOD = 1000000007;

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

long lcm( long m, long n ){
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;

	return ((m / gcd(m, n)) * n);
}


long kake(long x, long y){
	return x * y % MOD;
}

long fact_mod(long x){
	long ans = x;
	x-=1;
	while(x>1){
		ans = ans * x % MOD;
		x-=1;
	}
	return ans;
}


int main(){


	long N;
	scanf("%ld",&N);

	long long snuke_sum = 0;
	long long rakoon_sum = 0;

	std::vector<long> A;

	for(int i=0; i<N; i++){
		long a;
		scanf("%ld",&a);
		rakoon_sum += a;
		A.push_back(a);
	}

	snuke_sum = A[0];
	rakoon_sum = rakoon_sum - A[0];
	long long min_diff = abs(rakoon_sum - snuke_sum);

	for(int i=1; i<N-1; i++){
		snuke_sum += A[i];
		rakoon_sum -= A[i];

		if( min_diff > abs(rakoon_sum - snuke_sum)){
			min_diff = abs(rakoon_sum - snuke_sum);
		}
	}

	cout << min_diff << endl;



}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int main(){
    int dish[5];
    int mi = INT_MAX, index = 0;
    for(int i = 0; i < 5; i++){
        cin >>  dish[i];
        if(mi > dish[i]%10 && dish[i]%10 != 0){
            mi = dish[i]%10; index = i;
        }
    }
    int sum = 0;
    for(int i = 0; i < 5; i++){
        if(i != index){
            sum += dish[i];
            if(dish[i]%10!=0) sum += 10-dish[i]%10;
        }
    }
    sum += dish[index];
    cout << sum  << endl;

}

Measured memory_bytes: 256
N = int(input())
A = input()
B = input()
C = input()
ans = 0
for a, b, c in zip(A, B, C):
    if a == b and b == c:
        continue
    if a == b or b == c or c == a:
        ans += 1
    else:
        ans += 2
print(ans)


Measured memory_bytes: 2940
//
//  main.cpp
//  BC20161109
//
//  Created by TA on 2016/11/09.
//  Copyright © 2016年 TA. All rights reserved.
//

#include <iostream>
#include <list>
using namespace std;
int main(int argc, const char * argv[]) {
    int counter = 0;
    string str;
    cin >> str;
    unsigned long length = str.length();
    if (length == 1) {
    cout << counter << endl;
    }
    else{
    for (int i = 0; i<length-1; i++) {
        if (str[i] != str[i+1]) {
            counter++;
        }
    }cout << counter << endl;
    }
    return 0;
}


Measured memory_bytes: 512
import math
Q = int(input())
ans = []

for i in range(Q):
    a,b = map(int,input().split())
    if a>b:
        a,b = b,a
    if a == b:
        ans.append((a-1)*2)
        continue
    c = math.ceil((a*b)**0.5-1)
    
    ans.append(c*2-2)
    if c*(c+1) < a*b:
        ans[-1] +=1
for i in ans:
    print(i)


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    int X,A;
    scanf("%d %d",&X,&A);

    if (X < A) {
        puts("0");
    }  else{
        puts("10");
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
 
int main(){
  int h,w,k;
  cin >> h >> w >> k;
  vector<string> c(h);
  for(int i=0;i<h;++i){
    cin >> c[i];
  }
 
  int ans=0;
  for(int hb=0;hb<(1<<h);hb++){ // 塗る行を指定 2^h-1通り
    for(int wb=0;wb<(1<<w);wb++){ // 塗る列を指定 2^w-1通り
      int cnt=0;
      for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
          if(hb>>i&1) continue; //その列が塗ってあったら何もしない(bit列が立っていたら)
          if(wb>>j&1) continue; //その行が塗ってあったら何もしない
          if(c[i][j]=='#') cnt++;
        }
      }
      if(cnt==k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define per(i,a,b) for(ll i=(a)-1; i>=(b); i--)
string s;
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>s;
    cout<<(s[2]==s[3]&&s[4]==s[5]?"Yes":"No")<<"\n";
}


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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int main() {
   int n;
   cin >> n;
   vector<ll> v(3*n);
   for (ll& x: v) {
      cin >> x;
   }
   sort(v.begin(), v.end());
   ll sum = 0;
   int pos = v.size() - 2;
   for (int i = 0; i < n; i++) {
      sum += v[pos];
      pos -= 2;
   }

   cout << sum <<endl;

   return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

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

  if(a-b >= c){
    cout << 0 << endl;
  }else{
    cout << c-(a-b) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
String s=sc.next();
String  t=sc.next();
int n=s.length();
int m=t.length();
int count=0;
int ans=Integer.MAX_VALUE;
	for(int i=0;i<n-m+1;i++) {
		String ss=s.substring(i,i+m);
		for(int j=0;j<ss.length();j++) {
			if(ss.charAt(j)!=t.charAt(j)) {
				count++;
			}
		}

		ans=Math.min(ans,count);
		count=0;
	}
	System.out.println(ans);

	}
}

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

int main() {
    int N, K;

    cin >> N >> K;
    double res = 0;
    for (int i = 1; i <= N; i++) {
        double temp = 1.0 / N;
        int point = i;
        while (point < K) {
            temp *= 0.5;
            point *= 2;
        }
        res += temp;
    }
    cout << setprecision(12) << res << endl;
}

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

#define Int long long int
#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()

int main(){
    int co[]={500,100,50};
    int a,b,c;
    cin >> a >> b >> c;
    int x;
    cin >> x;
    int res=0;
    REP(i,a+1){
        REP(j,b+1){
            REP(k,c+1){
                if(co[0]*i+co[1]*j+co[2]*k == x){
//                    cout << i << " "<<j<<" "<<k<<":";
                    res++;
                    break;
                }
            }
        }
    }

    cout << res << endl;
}


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

int c[300300];
int main() {
	int n;
	string s;
	cin >> n >> s;
	c[0] = s[0] == 'W';
	for (int i = 1; i < n; i++) {
		c[i] = c[i - 1];
		if (s[i] == 'W') {
			c[i]++;
		}
	}
	int tot = c[n - 1];
	int ans = n - tot - (1 - c[0]);
	for (int i = 1; i < n; i++) {
		int tmp = c[i - 1] + (n - i - 1 - (tot - c[i]));
		ans = min(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;
int n,m,q,v[12], ans = 0;
int a[55], b[55], c[55], d[55];
int ctr = 0;

void solve (int i) {
  if (i == n) {
    int score = 0;
    for (int j = 0; j < q; j++) {
      if (v[b[j]] - v[a[j]] == c[j])
        score += d[j];
    }
    ans = max(ans, score);
  } else {
    int start = i ? v[i-1] : 1;
    for (int val = start; val <= m; val++) {
      v[i] = val;
      solve(i+1);
    }
  }
}

int main (void) {
  ios::sync_with_stdio(false);cin.tie(0);
  cout << fixed << setprecision(15);
  cin >> n >> m >> q;
  for (int i = 0; i < q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--, b[i]--;
  }
  solve(0);
  cout << ans << '\n';
  return 0;
}



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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

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

    int N;
    std::cin >> N;

    string S = to_string(N);
    int f = 0;
    for(char c : S){f += c - '0';}

    const string YESNO[2] = {"No", "Yes"};
    std::cout << YESNO[N % f == 0] << std::endl;
}


Measured memory_bytes: 256
/*
	Atcoder Beginner 168 B
	Author : Hardik Bagada
*/
#include<bits/stdc++.h>
using namespace std;

int main()
{
		string S;
		int K;
		cin >> K;
		cin >> S;
		int t = S.size();
		if(K >= t){
			cout << S;
			return 0;
		}
		else if(K < t)
		{
			for(int i=0;i<K;i++)
			{
					cout << S[i] ;
			}
			cout << "...";
			return 0;
		}
		
		return 0;
}



Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, k, a[200001] = {}, cur = 1, visited[200001] = {}, seq[200001] = {};

int main() {
	cin >> n >> k;
	rep(i, n)cin >> a[i + 1];
	for (int i = 1;; i++) {
		if (visited[cur]) {
			cout << seq[(k - visited[cur] + 1) % (i - visited[cur]) + visited[cur]] << endl;
			return 0;
		}
		visited[cur] = i;
		seq[i] = cur;
		cur = a[cur];
		if (i == k) {
			cout << cur << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 7904
n = gets.chomp.to_i
w = []
(0..(n - 1)).each do |i|
  w << gets.chomp
end

flg = true
(1..(n - 1)).each do |i|
  prev = w[i - 1]
  curr = w[i]
  if w[0..(i - 1)].include?(curr) || prev[prev.length - 1] != curr[0]
    flg = false
    break
  end
end

flg ? puts('Yes') : puts('No')

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
const long long MOD = 1e18 ;
const long long INF = 1e18;
const int INT_INF   = 1e9 + 8;
int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD, long long tot = 1) {
    for(;exp > 0; exp >>= 1, base = base * base % mod) if((exp & 1) == 1) tot = tot * base % mod;
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD, long long tot = 0) {
    for(;exp > 0; exp >>= 1, base = base * 2 % mod) if((exp & 1) == 1) tot = (tot + base) % mod;
    return tot;
}
struct chash {
    static uint64_t splitmix64(uint64_t x) {x += 0x8e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf54876d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    size_t operator()(pair<uint64_t,uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);}
};

long long arr[200005], psa[200005];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, m; cin >> n >> m;
    string s; cin >> s;

    int p = n, upper = n;
    vector<int> mov;

    while(p != 0){
        bool found = false;
        for(int i = max(0, p - m); i < upper; ++i){
            if(s[i] == '1') continue;
            mov.push_back(p - i);
            upper = p - m; p = i; found = true; break;
        }
        if(!found){
            cout << -1;
            return 0;
        }
    }

    while(!mov.empty()){
        cout << mov.back() << " ";
        mov.pop_back();
    }
    return 0;

}


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

int main(){
  int a,b,c;
  cin >> a;
  cin >> b;
  cin >> c;
  if((a == b && b == c) || (a != b && b != c && a != c)){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

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

int main(int, char**) {
  int a, b;
  cin >> a >> b;
    
  int ans = 0;
  if (a > b) { ans += a--; }
  else { ans += b--; }
  if (a > b) { ans += a--; }
  else { ans += b--; }
  cout << ans << endl;
}

Measured memory_bytes: 256
//### In The Name Of GOD ###

//%% Remember; (((He))) is The (((Accepter))) %%

// GOD IS GREATER ...

#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;

#define int ll
#define pb push_back
#define bp pop_back
#define X first
#define Y second
#define sz(a) (int)(a.size())

const int MAXN = 1e5 + 10; // ios_base :: sync_with_stdio(false);

signed main() {
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	int cnt[MAXN] = {};
	for(int i = 0; i < m; i++) {
		int a, b;	
		cin >> a >> b;
		cnt[--a]++;
		cnt[--b]++;
	}
	for(int i = 0; i < n; i++)
		if(cnt[i] % 2) {
			cout << "NO";
			return 0;
		}
	cout << "YES";
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;

const int N=1e5+5;
ll h[N];
bool vis[N];

int main()
{
   IOS;
   int n,m;
   cin >> n >> m;
   MEM(vis,1);
   rep(i,1,n){
       cin >> h[i];
   }
   rep(i,1,m){
       int a,b;
       cin >> a >> b;
       if(h[b]>=h[a]){
           vis[a]=0;
       }
       if(h[b]<=h[a]){
           vis[b]=0;
       }
   }
   int ans=0;
   rep(i,1,n){
       if(vis[i]==1)
       ++ans;
   }
   cout<< ans;
}


Measured memory_bytes: 4572
N = int(input())
words = []
ans = 'Yes'
for i in range(N):
  W = input()
  if(words != []):
    if(W in words):
      ans = 'No'
    words.append(W)
    if(W[0] != words[i-1][-1]):
      ans = 'No'
  else:
    words.append(W)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

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

    ll a,b,k;cin>>a>>b>>k;

    ll tmp=min(a,k);
    a-=tmp;k-=tmp;
    b-=k;
    cout<<a<<' '<<max(0ll,b)<<endl;
    return 0;
}


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

int cnt[5];
int main()
{
	for (int i = 0; i < 3; ++i) {
		int a, b;
		std::cin >> a >> b;
		++cnt[a - 1], ++cnt[b - 1];
	}

	int ans = 0;
	for (int i = 0; i < 4; ++i)
		if (cnt[i] % 2 == 1)
			++ans;
	if (ans < 3)
		std::cout << "YES" << std::endl;
	else
		std::cout << "NO" << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((int)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define root sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : ' ');
  }
  // os << '}';
  return os;
}

int main()
{
  int r;
  cin >> r;
  double ans = 3.141592648777698869248;
  printf("%.10lf\n", r * 2 * ans);
}

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

int main(){
    int n,d;
    cin >> n >> d;
    int x[n][d];
    rep(i,n){
        rep(j,d){
            cin >> x[i][j];
        }
    }
    int ans = 0;
    rep(i,n)rep(j,i) {
        int sq = 0;
        rep(k,d) {
            int s = x[i][k]-x[j][k];
            sq += s*s;
        }
        int s = sqrt(sq)+0.5;
        if (s*s == sq) ans++;
    }
    cout << ans << endl;
} 

Measured memory_bytes: 256
n = int(input())
A = []
X = []

for _ in range(n):
    a = int(input())
    A.append(a)
    Y = []
    for _ in range(a):
        x, y = map(int, input().split())
        Y.append(x)
        Y.append(y)
    X.append(Y)

# print("X",X)
ans = 0

for i in range(2**n):
    flg = True
    honest = [0]*n
    count = 0
    for j in range(n):
        if ((i >> j) & 1):
            honest[j] = 1
    # print("honest",honest)
    for k in range(n):
        for l in range(0,len(X[k]),2):
            # print(honest[X[k][l]-1], X[k][l+1])
            if honest[X[k][l]-1] != X[k][l+1] and honest[k] == 1:
                # print('hi')
                flg = False

    if flg:
        count = sum(honest)
        # print("count", count)
        ans = max(ans, count)



print(ans)

Measured memory_bytes: 74108
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var A = ReadLongs();

            if (N == 2)
            {
                return A.Max();
            }

            var L_Gcd = new long[N];
            L_Gcd[0] = A[0];
            var R_Gcd = new long[N];
            R_Gcd[N - 1] = A[(int)N - 1];
            for (int i = 1; i < N; i++)
            {
                L_Gcd[i] = Gcd(L_Gcd[i - 1], A[i]);
                R_Gcd[N - 1 - i] = Gcd(R_Gcd[N - 1 - i + 1], A[(int)N - 1 - i]);
            }

            var M = new long[N];
            M[0] = R_Gcd[1];
            M[N - 1] = L_Gcd[N - 2];
            for (int i = 1; i < N - 1; i++)
            {
                M[i] = Gcd(L_Gcd[i - 1], R_Gcd[i + 1]);
            }

            return M.Max();
        }
        public static long Gcd(long a, long b)
        {
            // 引数を入替えて自分を呼び出す
            if (a < b) return Gcd(b, a);

            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }
        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 40404
#!/usr/bin/env python3
#ABC145 E

import sys
import math
import copy
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,t = LI()
ab = [LI() for _ in range(n)]
dp1 = [0]*t
dp2 = [0]*t
for i in range(n):
    a,b = ab[i]
    for j in range(t)[::-1]:
        if j - a < 0:
            dp2[j] = max(dp2[j],dp1[j]+b)
            continue
        tmp1,tmp2 = dp1[j],dp2[j]
        dp1[j] = max(tmp1,dp1[j-a]+b)
        dp2[j] = max(tmp2,tmp1+b,dp2[j-a]+b)
print(dp2[-1])

Measured memory_bytes: 46172
# D

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

cash = 1000
stock = 0

for i in range(N - 1):
    if (A[i] < A[i + 1]):
        num = cash // A[i]
        stock += num
        cash -= num * A[i]
    elif (A[i] > A[i + 1]):
        cash += stock * A[i]
        stock = 0
            
print(cash + A[-1] * stock)

Measured memory_bytes: 62000
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e9+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}

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


int main(){
	ll h,w,k;
	cin >> h >> w >> k;

	pal s,g;
	cin >> s.F >> s.S >> g.F>>g.S;

	ll d[h+2][w+2];
	bool obs[h+2][w+2];
	fill(d[0],d[0]+(h+2)*(w+2),-INF);
    fill(obs[0],obs[0]+(h+2)*(w+2),false);
    
    for(ll i=1;i<=h;i++){
		for(ll j=1;j<=w;j++){
			char tmp;
			cin >> tmp;
			if(tmp=='@'){
				obs[i][j]=true;
			}
		}
    }
    for(ll i=0;i<h+2;i++){
        obs[i][0]=true;
        obs[i][w+1]=true;
    }
	for(ll i=0;i<w+2;i++){
        obs[0][i]=true;
        obs[h+1][i]=true;
    }

	priority_queue<pair<pal, pal>> que; //(掻いた回数,向いてる方向),座標
    
	d[s.F][s.S]=0;
	
	que.push(MP(MP(0,-1),s));
	
    while(que.size()){
        pair<pal,pal> t=que.top(); que.pop();
        if(t.S.F==g.F && t.S.S==g.S) break;//終了条件
        
        for(ll i=0;i<4;i++){ //4方向
			if(i==t.F.S || (i+2)%4 == t.F.S) continue;
            for(ll j=0;j<k;j++){ //kマス先まで
				if(obs[t.S.F+(j+1)*dx[i]][t.S.S+(j+1)*dy[i]]) break;
				if(d[t.S.F+(j+1)*dx[i]][t.S.S+(j+1)*dy[i]]==-INF){ //未訪問&蓮ナシ
					d[t.S.F+(j+1)*dx[i]][t.S.S+(j+1)*dy[i]]= t.F.F-1;
					if(j==k-1){
						que.push(MP(MP(t.F.F-1,-1),MP(t.S.F+(j+1)*dx[i],t.S.S+(j+1)*dy[i])));
					}else{
						que.push(MP(MP(t.F.F-1,i),MP(t.S.F+(j+1)*dx[i],t.S.S+(j+1)*dy[i])));
					}
					
				}
			}
        }
    }
    if(d[g.F][g.S]!=-INF){
		cout << -d[g.F][g.S] << endl;
	}else{
		cout << -1 << endl;
	}
}

Measured memory_bytes: 29964
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#include<cmath>

using namespace std;

int mod_num_counter[2030];

int main()
{
  //fill(mod_num_counter,mod_num_counter+2030,0);
  
  int n,m;
  cin >> n >> m;
  
  int h[n];
  for(int i=0;i<n;i++) cin >> h[i];
  
  bool is[n];
  for(int i=0;i<n;i++) is[i] = true;
  
  for(int i=0;i<m;i++)
  {
    int a, b;
    cin >> a >> b;
    a--;b--;
    if(h[a]<=h[b]) is[a] = false;
    if(h[b]<=h[a]) is[b] = false;
  }
  

  
  int ans=0;
  for(int i=0;i<n;i++)
  {
    if(is[i]) ans++;
  }
  
        cout << ans << endl;
    
  return 0;
}

Measured memory_bytes: 4084
from collections import deque


h, w = map(int, input().split())
graph = '#' * (w+2)
for _ in range(h):
    line = '#' + input() + '#'
    graph = graph + line

graph = graph + '#' * (w+2)


def bfs(x):
    if graph[x] == '#':
        return 0
    seen = [-1] * ((h+2)*(w+2))
    seen[x] = 0
    pattern = [-(w+2), -1, 1, w+2]
    todo = deque([])
    for delta in pattern:
        if graph[x+delta] == '.':
            todo.append([x+delta, 1])

    while todo:
        node, dist = todo.popleft()
        if seen[node] != -1:
            continue
        seen[node] = dist
        for delta in pattern:
            if graph[node+delta] == '.' and seen[node+delta] == -1:
                todo.append([node+delta, dist+1])

    return max(seen)


ans = []
for i in range((h+1)*(w+1)):
    ans.append(bfs(i))

print(max(ans))

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

int main(){
    int N, left=0, right=0, ans=2e9;
    cin >> N ;
    string s;
    cin >> s;

    for(int i=0; i<N; i++){
	if(s[i]=='E')
	    right++;
    }
    
    for(int i=0; i<N; i++){
	ans = min(ans, left+right);
	if(s[i]=='E'){
	    right--;
	}
	else{
	    left++;
	}
    }
    ans = min(ans, left+right);
    cout << ans << endl;
}



Measured memory_bytes: 900
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue

n,k = map(int, input().split())
p = (1.00 + np.array(list(int(i) for i in input().split()))) / 2
temp = np.sum(p[:k])
ans = temp

for i in range(k, n):
	temp += (p[i] - p[i - k])
	ans = max(ans, temp)

print('{:.10f}'.format(ans))


Measured memory_bytes: 34844
N = int(input())
pool = [('a',0)]
ord_a = ord('a')
while pool:
    li, m = pool.pop()
    if len(li) == N:
        print(li)
    else:
        pool.append((li+chr(ord_a+m+1),m+1))
        for i in range(m,-1,-1):
            pool.append((li+chr(ord_a+i),m))


Measured memory_bytes: 44888
#include <bits/stdc++.h>
using namespace std;
int main(){
  long n;
  cin >> n;
  for(int i = (int)sqrt(n); i > 0; i--){
    if(n % i == 0){
      cout << i + n / i - 2 << endl;
      return 0;
    }
  }
}

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

#define llong long long
#define rep(i,l,n) for(llong (i)=(l);(i)<(n);(i++))
#define _min(a,b) ((a)<(b)?(a):(b))
#define _max(a,b) ((a)>(b)?(a):(b))
#define _abs(a) ((a)>0?(a):(-(a)))

using namespace std;

int main(){
	int D,T,S;
	cin >> D >> T >> S;
	if( D <= T*S ) cout << "Yes";
	else cout << "No";
	return 0;
}


Measured memory_bytes: 3632
/**
 * ATCODER 160 B
 * Kartikeya (doomsday861)
**/
#include<bits/stdc++.h>
#include<time.h>
#define ll long long
#define testcase ll t;cin>>t;while(t--)
#define timeb  auto start = high_resolution_clock::now(); 
#define timee auto stop = high_resolution_clock::now();auto duration = duration_cast<seconds>(stop - start);cout << "Time taken by function: "<<duration.count() << "seconds" << endl; 
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
using namespace std::chrono;
//timeb
	ll x;
	cin >>x;
	ll h=0;
	ll n =x/500;
	h += n*1000;
	x %=500;
	//cout<<x<<endl;
	while(x>5)
	{
		ll d = x/5;
		h += d*5;
		x %=5;
	}
	cout << h <<endl;
//timee
    return 0; 
} 

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

int main() {
  int n, k, ans; cin >> n >> k;
  ans = 0;

  rep(i, n) {
    int x; cin >> x;
    ans += (min(abs(x-k), x)*2);
  }
  
  p(ans);
}

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

using namespace std;
long long int gcd(long long  int m,long long int n )
{
  if ( ( 0 == m ) || ( 0 == n ) )
    return 0;  
  while( m != n )
    {
      if ( m > n ) m = m - n;
      else         n = n - m;
    }
  return m;
}
long long int lcm(long long  int m,long long int n )
{
  if ( ( 0 == m ) || ( 0 == n ) )
    return 0;
  
  return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}


int main()
{
  int a1,m1,a2,m2,a3,m3;
  for(;cin>>a1>>m1>>a2>>m2>>a3>>m3,a1;)
    {
      long long int a=0,b=0,c=0,ans;
      long long int x=1;
      do{
	x=(a1*x)%m1;
	a++;
      }while(x!=1);
      do{
	x=(a2*x)%m2;
	b++;
      }while(x!=1);
      do{
	x=(a3*x)%m3;
	c++;
      }while(x!=1);
      //      cout<<a<<" "<<b<<" "<<c<<endl; 
      cout<<lcm(lcm(a,b),c)<<endl;
    }
}

Measured memory_bytes: 1156