akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(A - B*2 > 0) {
			System.out.println(A-B*2);
		}else {
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
int dp[100005]={};
int main()
{
  int n,k,h[100005];
  int min;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  dp[0]=0;
  for(int j=1;j<=k;j++){
    dp[j]=abs(h[j]-h[0]);
  }
  for(int i=k+1;i<n;i++){
    min=dp[i-k]+abs(h[i]-h[i-k]);
    for(int j=i-k;j<i;j++){
      if(min>dp[j]+abs(h[i]-h[j])){
	min=dp[j]+abs(h[i]-h[j]);
      }
    }
    dp[i]=min;
  }
  cout<<dp[n-1]<<"\n";
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;

int main(){
  int N; cin >> N;
  if(N%2==0)cout << N << endl;
  else cout << N * 2 << endl;
  return 0;
}


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

int main() {
  
   string n;
   
 
   cin >> n;
  
   if (n[0]==n[2]){
      cout << "Yes" << endl;
     
   }else{
     cout << "No" << endl;
   }
  
 
  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();

        boolean isYes = true;
        for (int i = 0; i < n; i++) {
            if ((i % 2 == 0 && s.charAt(i) == 'L') || (i % 2 == 1 && s.charAt(i) == 'R')) {
                isYes = false;
                break;
            }
        }
        System.out.println(isYes ? "Yes": "No");
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


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

using ll = long long;
static const ll MOD = 1e9 + 7;

// 組合せを素数で割った値を求める
const ll MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k || n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 階乗を利用した順列
ll nPr(int n, int r) {
  if (n < r || n < 0 || r < 0) return 0;
  return (fac[n] * finv[n - r]) % MOD;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, m;
  cin >> n >> m;
  
  COMinit();
  
  ll ans = 0;
  for (ll i = 0; i <= n; i++) { // i: A, B で一致する数
    ans += MOD * MOD;
    ans += COM(n, i) * (ll) pow(-1, i) * (nPr(m, i) * (nPr(m - i, n - i) * nPr(m - i, n - i) % MOD) % MOD) % MOD;
    ans %= MOD;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 15852
n = int(input())
a = [int(i) for i in input().split()]

b = [0] * n
center = n // 2

before = center
if n % 2 != 0:
    for i in range(len(a)):
        if i % 2 != 0:
            before = before + i
        else:
            before = before - i
        b[before] = a[i]
else:
    for i in range(len(a)):
        if i % 2 != 0:
            before = before - i
        else:
            before = before + i
        b[before] = a[i]

b = " ".join(list(map(str, b)))
print(b)


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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    FOREACH(x, v) { cout << x << " "; }                                        \
    cout << "\n";

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N, M;

int main() {
    cin >> N >> M;
    priority_queue<ll> pq;
    map<ll, ll> num;
    REP(i, N) {
        LCIN(a);
        num[a]++;
        pq.emplace(a);
    }
    REP(i, M) {
        LCIN(B, C);
        if(num[C] == 0) pq.emplace(C);
        num[C] += B;
    }
    ll ans = 0, cnt = 0;
    while(cnt < N) {
        ll t = pq.top();
        pq.pop();
        ll sel = min(num[t], N - cnt);
        cnt += sel;
        ans += sel * t;
        num[t] -= sel;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 14320
#include <bits/stdc++.h>
#define endl "\n"
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define ll long long
#define llu unsigned long long
#define MAX(a, b)  (((a) > (b)) ? (a) : (b))
#define MIN(a, b)  (((a) < (b)) ? (a) : (b))
#define ABS(X) ((X)< 0 ? -(X): (X))
#define LCM(X, Y)  ( ( (X) / (GCD( (X)  , (Y) ))) * (Y) )
#define MEM( A,  B) memset((A), (B), sizeof(A))
#define MEM_VEC(V, FILL ) fill( V.begin(), V.end(), FILL)
#define FOR_EACH(IT, V) for (auto IT = V.begin(); IT != V.end(); IT++)
#define DEBUG_ARRAY_PRINT(A,I) cout<<"at pos "<< I <<"  value is: "<< A[I]
#define TURBO ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0)
const double EPS =1e-9 ;
const double PI = 3.1415926535897932384626433832795 ;
using namespace std ;
inline ll GCD(ll A, ll B){
      if ( B == 0 ) return A;
      return GCD( (B) ,  (A % B) );
}
inline ll POW(ll BASE, ll EXP) {
   ll RES = 1;
   for(ll I= 0; I < EXP; I++) RES *= BASE ;
   return RES;
}

inline ll BIGMOD  ( ll a, ll p, ll m ) {
   ll res = 1 % m;
   ll x = a % m;
   while ( p > 0 ) {
       if ( (p & 1) > 0 ) res = ( res * x ) % m;
       x = ( x * x ) % m; p >>= 1;
   }
   return res;
}
inline void FILE_HANDLE( ){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

}

int main()
{
            TURBO;
            //FILE_HANDLE() ;
            int n ;
            cin >> n ;
            vector <int> v ;
            for(int i = 0 ; i < n ; i++)
            {
                  int temp ;
                  cin >> temp ;
                  v.PB(temp) ;
            }
            ll stool = 0 ;
            ll crnt_high = INT_MIN ;
            for(int i = 0; i < v.size() ; i++)
            {
                  if(crnt_high < v[i]) crnt_high = v[i] ;

                  stool += ( crnt_high - v[i] ) ;
            }
            cout << stool << endl ;



}



Measured memory_bytes: 4276
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

#define ll long long

using namespace std;

int main(){
    string a, b;
    cin >> a >> b;
    if(b.size() != (a.size() + 1)){
        cout << "No" << endl;
        return 0;
    }
    bool f = false;
    for(int i = 0; i < a.size(); i++){
        if(a[i] != b[i]){
            f = true;
        }
    }
    if(f){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

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

int main() {
	int n, k,sum=0;
	cin >> n >> k;
	vector<int> p(n);
	for (int i = 0; i < n; i++) cin >> p[i];
	sort(p.begin(),p.end());
	for (int i = 0; i < k; i++) {
		sum += p[i];
	}
	cout << sum;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
string s,t;

void solve(){
    t.pop_back();
    if(s==t){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}
  

int main(){
  
    
    cin>>s>>t;
    
    solve();
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

int main()
{
    int n;

    cin >> n;

    vi v(n);
    vi l(n);
    vi r(n);

    for(auto &z : v)cin >> z;

    l[0] = v[0];
    r[n - 1] = v[n - 1];

    for(int i = 1; i < n; i++)
    {
        l[i] = __gcd(l[i - 1], v[i]);
    }

    for(int i = n - 2; i >= 0; i--)
    {
        r[i] = __gcd(r[i + 1], v[i]);
    }

    int najveci = INT_MIN;

    for(int i = 1; i < n - 1; i++)
    {
        int trenutni = __gcd(l[i - 1], r[i + 1]);
        if(trenutni > najveci)najveci = trenutni;
    }

    if(l[n - 2] > najveci)najveci = l[n - 2];
    if(r[1] > najveci)najveci = r[1];

    cout << najveci << '\n';

    return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;



//DONT WASTE YOUR TIME......i said don't waste -_- 
//prove yourself remember....fuck ps&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it

// fortunately or unfortunately tu sabse badaah chodu h ....ek number ka chutiyaa -_-

const ll N= 1e6+55,mod = 1e9+7;

int main() {
 	//freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	ll i,j,k,a,b,c,x,y,z;
	//cout<<"snuke\n";	
	sc(a);sc(b);sc(c);sc(y);
	x=min(a,b);
	z=min(c,y);
	i=x+z;
	pr(i);
}

Measured memory_bytes: 764
N = int(input())
A = list(map(int, input().split()))
flag = None
ans = 0
for i in range(N-1):
    if flag is None:
        if A[i] < A[i+1]:
            flag = True
        elif A[i+1] < A[i]:
            flag = False
        continue
    if flag:
        if A[i+1] < A[i]:
            ans += 1
            flag = None
    elif not flag:
        if A[i] < A[i+1]:
            ans += 1
            flag = None
ans += 1
print(ans)


Measured memory_bytes: 15020
#include <stdio.h>
#define ARRAY_BUFFER_SIZE 100

int main()
{
	int N = 0;

	scanf("%d", &N);

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

	for (int i = 0; i < N; i++) {
		int value = A[i];
		int j = i;

		while( j >= 1 &&  A[j] < A[j-1] ){
			int tmp = A[j];
			A[j] = A[j-1];
			A[j-1] = tmp;

			--j;
		}
		for (int k = 0; k < N; k++) {
			if (k != N - 1) {
				printf("%d ", A[k]);
			}
			else {
				printf("%d\n", A[k]);
			}
		}

	}

	return 0;
}


Measured memory_bytes: 2740
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let s = Array(readLine()!).sorted(by: >)
    if s[0] == s[1] && s[1] != s[2] && s[2] == s[3] {
        print("Yes")
    } else {
        print("No")
    }
}

main()


Measured memory_bytes: 7916
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define sf scanf
#define pf printf
#define pb push_back
#define F first
#define S second
ll mx=1000000000000000000;
int main()
{
    BOOST

    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        ll n;
        cin>>n;
        ll x[n+5];
        bool flag=false;
        for(ll i=0; i<n; i++)
        {
            cin>>x[i];
            if(x[i]==0)
            {
                flag=true;
            }
        }
        if(flag==true)
        {
            cout<<"0"<<endl;
            return 0;
        }
        sort(x,x+n);
        ll ans=1;
        for(ll i=0; i<n; i++)
        {
            ll tmp=ans;
            if(tmp>ans*x[i] || ans*x[i]>1000000000000000000)
            {
              cout<<"-1"<<endl;
              return 0;
            }
            ans*=x[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}


/*

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define sf scanf
#define pf printf
#define pb push_back
#define F first
#define S second

int main()
{
    BOOST

    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        ll n;
        cin>>n;
        ll x[n+5];
        ll ans=1;
        for(lli i=0; i<n; i++)
        {
            cin>>x[i];
        }
        sort(x,x+n);
        for(lli i=0; i<n; i++)
        {
            //cout<<ans*x[i]<<endl;
            if((ans*x[i]>1000000000000000000LL) || (i<n-1 && ans*x[i]>1000000000000000000LL))
            {
                cout<<"-1"<<endl;
                return 0;
            }
            ans*=x[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}


*/


Measured memory_bytes: 4440
def e(x,y):
 A[y][x]='0'
 for d in range(-3,4):
  0<=x+d<8and'1'==A[y][x+d]and e(x+d,y)
  0<=y+d<8and'1'==A[y+d][x]and e(x,y+d)
for i in range(int(input())):
 print(f'Data {i+1}:');input()
 A=[list(input())for _ in[0]*8]
 e(int(input())-1,int(input())-1)
 for r in A:print(*r,sep='')


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<pair<int,int>> vp;

#define pb push_back
#define mp make_pair

const int INF = INT_MAX;

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

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	string s, t;
	cin >> s >> t;

	int ans = 0;
	for(int i = 0; i < s.length(); i++){
		if(s[i] != t[i])
			ans++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int hmt() {int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';if(n) x=-x;return x;}
#define in hmt()
#define ins ({string x;char c=getchar();for(;c==' '||c=='\n';c=getchar());for(;c!=' '&&c!='\n';c=getchar()) x+=c;x;})
#define forinc(i,a,b) for(int i=a,_b=b;i<=_b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define forv(a,b) for(auto &a:b)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define reset(f,x) memset(f,x,sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define onbit(x,i) (x|(1<<(i-1)))
#define offbit(x,i) (x&~(1<<(i-1)))
const int N=400010;
int n,q,t[N],dd[N][27],p[N],id=1,ans[N],cnt;
pii nx[N];
string a;
string st[N];
void add(int s,int i)
{
    if(i==a.size())
    {
        ans[s]=cnt;
        t[s]++;
        nx[s]={s,1};
        return;
    }
    int x=a[i]-'a';
    if(!dd[s][x])
    {
        dd[s][x]=++id;
        add(id,i+1);
        t[s]+=t[id];
        if(t[s]==t[id]) nx[s]={nx[id].fi,nx[id].se+1};
        else nx[s]={s,1};
    }
    else
    {
        int it=dd[s][x];
        int p=t[it];
        add(it,i+1);
        t[s]+=(t[it]-p);
        if(t[s]==t[it]) nx[s]={nx[it].fi,nx[it].se+1};
        else nx[s]={s,1};
    }
}
int get(int s,int i,int k)
{
    if(ans[s]==k) return 1;
    int c=(ans[s])?1:0;
    forinc(j,0,25)
    {
        int it=dd[s][p[j]];
        if(st[k][i]-'a'==p[j]) return c+get(nx[it].fi,i+nx[it].se,k);
        c+=t[it];
    }
}
int main()
{
    //freopen("atE.inp","r",stdin);
    n=in;
    forinc(i,1,n)
    {
        cnt=i;
        a=ins;
        st[i]=a;
        add(1,0);
    }
    q=in;
    while(q--)
    {
        int k=in;
        a=ins;
        forinc(i,0,25) p[i]=a[i]-'a';
        cout<<get(1,0,k)<<"\n";
    }
}


Measured memory_bytes: 72964
import java.util.*;

public class Main {

    static boolean[] bits;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] sum = new int[2][n+1];
        for (int i = 0; i < 2; i++) {
            for (int j = 1; j < n+1; j++) {
                sum[i][j] = sum[i][j - 1] + sc.nextInt();
            }
        }
        int ans=0;
        for(int i=0;i<n;i++){
            ans=Math.max(ans,sum[0][i+1]+sum[1][n]-sum[1][i]);
        }
        System.out.println(ans);
    }

}


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

int n, m;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  string sr = s;
  reverse(sr.begin(), sr.end());
  if (sr != s) {
    puts("No");
    return 0;
  }
  string tp = s.substr(0, (n - 1) / 2);
  string t = tp;
  reverse(t.begin(), t.end());
  if (tp != t) {
    puts("No");
    return 0;
  }
  reverse(s.begin(), s.end());
  tp = s.substr(0, (n - 1) / 2);
  t = tp; reverse(t.begin(), t.end());
  if (tp != t) return puts("No"), 0;
  puts("Yes");
  return 0;
}


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

using namespace std;

using ll = long long;

#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  rep(i, n) cin >> v[i];
  int p = -1;
  ll ma = -1;
  rep(i, n) {
    if (ma < abs(v[i])) {
      ma = abs(v[i]);
      p = i;
    }
  }
  cout << 2*n - 1 << endl;
  rep(i, n) {
    cout << p+1 << ' ' << i+1 << endl;
  }
  rep(i, (n-1)) {
    int a, b;
    if (v[p] >= 0) {
      a = i+1;
      b = i+2;
    } else {
      a = n-i;
      b = a-1;
    }
    cout << a << ' ' << b << endl;
  }
}


Measured memory_bytes: 256
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N-i+1):
        k = N - i - j
        t = (i, j, k)
        if Y == i*10000 + j*5000 + k*1000:
           print(*t)
           exit()
print('-1 -1 -1')

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

using namespace std;

long long T, ans = 0;
int len;
void BS(int val, int len);
bool isX(long long a);

bool isX(long long a)
{
    int flag3 = 0;
    int flag5 = 0;
    int flag7 = 0;
    while(a != 0)
    {
        if(a % 10 == 3)
            flag3 = 1;
        else if(a % 10 == 5)
            flag5 = 1;
        else if(a % 10 == 7)
            flag7 = 1;
        else
            return false;
        a /= 10;
    }
    if(flag3 == 1 && flag5 == 1 && flag7 ==1)
        return true;
    else
        return false;
}
void BS(int val, int step)
{
    if(step == len)
    {
        if(val <= T && isX(val))
        {
            ans++;
        }
        return;
    }
    else if(step < len)
    {
        if(val <= T && isX(val))
            ans++;
    }
    for(int i = 3; i <= 7; i = i + 2)
    {
        BS(val * 10 + i, step + 1);
    }
}
int main()
{
    scanf("%lld", &T);
    char s[15];
    sprintf(s, "%d", T);
    len = strlen(s);
    //printf("%d", len);
    //if(isX(T))
       // printf("!!!");
    ans = 0;
    BS(0, 0);
    printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int W, H;
    int x, y, r;
 
    scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
    W -= r, H -= r;
    if (r <= x && x <= W && r <= y && y <= H) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<char>());
	cout << ((s < t) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
package main
import "fmt"
func main() {
  var s,t string
  fmt.Scan(&s,&t)
  fmt.Println(lcs(s,t))
}
func max(n,m int) int {
  if n > m { return n }
  return m
}
func lcs(s,t string) string {
  dp := len_lcs(s,t)
  return backtrack(dp,s,t,len(s),len(t))
}
func len_lcs(s,t string) [][]int {
  n,m := len(s),len(t)
  dp := make([][]int,n+1)
  for i:=0;i<n+1;i++ { dp[i] = make([]int,m+1) }
  for i:=1;i<n+1;i++ {
    for j:=1;j<m+1;j++ {
      if s[i-1:i] == t[j-1:j] {
        dp[i][j] = dp[i-1][j-1]+1
      } else {
        dp[i][j] = max(dp[i][j-1],dp[i-1][j])
      }
    }
  }
  return dp
}
func backtrack(dp [][]int,s,t string,i,j int) string {
  if i == 0 || j == 0 { return "" }
  if s[i-1:i] == t[j-1:j] { return backtrack(dp,s,t,i-1,j-1)+s[i-1:i] }
  if dp[i][j-1] > dp[i-1][j] { return backtrack(dp,s,t,i,j-1) }
  return backtrack(dp,s,t,i-1,j)
}

Measured memory_bytes: 81024
#include <stdio.h>
#include <algorithm>

using namespace std;

int main() {
	int l = 1, r, n, m, a, b;
	scanf("%d %d", &n, &m);
	r = n;
	while (m--) {
		scanf("%d %d", &a, &b);
		l = max(l, a);
		r = min(r, b);
	}
	n = max(0, r - l + 1);
	printf("%d\n", n);
	return 0;
}

Measured memory_bytes: 128
def test(d, str):
    d[str] = d.get(str, 0) + 1

S = input()

dic = {}

# dic["s"] = 2
# dic["a"] = 2
s1 = S[0:1]
s2 = S[1:2]
s3 = S[2:3]
s4 = S[3:4]


test(dic, s1)
test(dic, s2)
test(dic, s3)
test(dic, s4)

expect =[2,2]
if  list(dic.values()) == expect:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3064
N,M=gets.chomp.split.map(&:to_i)
c=M.times.map { gets.split.map(&:to_i) }
a=c[0][0]
b=c[0][-1]
(M-1).times do |i|
  i+=1
  a=c[i][0] if a<c[i][0]
  b=c[i][-1] if b>c[i][-1]
end
puts (a..b).size

Measured memory_bytes: 9596
///RAIYAN_MAHIN
        #include "bits/stdc++.h"
        using namespace std;
        using ll = long long;
        int main()
        {
            ll n, m; cin >> n >> m;
            n = n * 500;
            if(n >= m) cout << "Yes" << '\n';
            else cout << "No" << '\n';
    
            
        }

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
     int n, temp,r, rev = 0;
     
     cin >> n;
     temp=n;
     while (temp > 0){
	 
     r=temp%10;
         rev=(rev*10)+r;
         
         temp= temp / 10;
      
 }
 if ((n>=100)&&(n<=999))
 
     if (n == rev){
	 
	 
         cout<<"Yes";}
       else {
	   
         cout << " No";}
    return 0;
}

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

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

Measured memory_bytes: 3620
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n,i,cnt = 1;
		n = sc.nextInt();
		
		System.out.println(sum(n,0,100000));
		
	}
	public static int sum(int n,int cnt,int min){
		int six = 6,nine = 9;
		int tmp;
		if(cnt > min){
			return 100000;
		}
		if(n < 6){
			return cnt + n;
		}
		
		while(six <= n){
			six *= 6;
		}
		six /= 6;
		
		tmp = sum(n - six,cnt + 1,min);
		if(tmp < min){
			min = tmp;
		}

		while(nine <= n){
			nine *= 9;
		}
		nine /= 9;
		
		tmp = sum(n - nine,cnt + 1,min);
		if(tmp < min){
			min = tmp;
		}

		return min;
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}

int main(){
	int n;
	cin>>n;
	vector<ll> v(n+1,0);
	range(i,1,n+1)cin>>v[i];
	partial_sum(all(v),v.begin());
	sort(all(v));
	v.push_back(-2e9);
	ll ans=0,p=1;
	range(i,1,n+2){
		if(v[i]==v[i-1]){
			p++;
		}else{
			if(p>1) ans+=p*(p-1)/2;
			p=1;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4608
import java.util.*;
 
public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		
		Map<String, Integer> rest = new TreeMap<String, Integer>();
		
		for(int i=1; i< N+1; i++){
			String s  = keyboard.next();
			int k  = keyboard.nextInt();
			rest.put(s+(200-k), i);
		}
		
        for(String key : rest.keySet()){
				System.out.println(rest.get(key));
			}
		keyboard.close();	
	}
}

Measured memory_bytes: 21844
#pragma GCC optimize("Ofast", "unroll-loops")

#define PRINT_INFO

#include <bits/stdc++.h>

using namespace std;

#define K (26) // コンテストの種類

int D;
vector<int> c(K);
vector<vector<int>> s;

void input(void){
	cin >> D;
	for (auto& ci : c)
		cin >> ci;
	s.resize(D, vector<int>(K));
	for (int i = 0; i < D; ++i)
		for (auto& sij : s[i])
			cin >> sij;
}

int calc_score(vector<int> t){
	vector<int> lst_held(K, -1);
	int score = 0;
	for (int i = 0; i < D; ++i){
		score += s[i][t[i]];
		lst_held[t[i]] = i;
		for (int c_id = 0; c_id < K; ++c_id){
			score -= c[c_id] * (i - lst_held[c_id]);
		}
#ifdef PRINT_INFO
		cout << score << endl;
#endif
	}
	return score;
}
 
int main(void){
	input();
	vector<int> t(D);
	for (auto& ti : t) 
		cin >> ti;
	for (auto& ti : t)
		--ti;
	calc_score(t);
	return 0;
}

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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int left;
    left = A + B;
    int right;
    right = C + D;
    if (left > right) {
        cout << "Left" << endl;
    }

    else if (left < right) {
        cout << "Right" << endl;
    }
    
    else if (left == right) {
        cout << "Balanced" << endl;

    }
    
}

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

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
    if (a < b) swap(a, b);
    ll g = gcd( a, b);
	return a / g * b;
}

int main() {
	ll N;
	cin >> N;

	ll T[N];
	for (int i = 0; i < N; i++) cin >> T[i];

	ll ans=T[0];
	for (ll i = 1; i < N; i++) {
		ans = lcm(ans, T[i]);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
    ll n,W; cin>>n>>W;
    ll p[n+1],w[n+1];
    for(int i=1;i<=n;i++) cin>>w[i]>>p[i];
    ll dp[W+1][n+1];
    for(ll i=0;i<=W;i++) dp[i][0]=0;
    for(ll i=0;i<=n;i++) dp[0][i]=0;
    //filling column-wise: per item, fill all the weights- you need prev column in recurrence relation
    for(ll j=1;j<=n;j++) {
        for(ll i=1;i<=W;i++) {
            dp[i][j]=dp[i][j-1];
            if(i-w[j]>=0) dp[i][j]=max(p[j]+dp[i-w[j]][j-1], dp[i][j]);
        }
        cout<<endl;
    }
    cout<<dp[W][n];
}

Measured memory_bytes: 79104
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    input!{
        a: usize, b: usize,
    }
    if (a * b) % 2 != 0 {
        println!("Yes");
    } else {
        println!("No");
    }
    
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std; 
int main()
{
    int a,b,c,d,ans;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    ans = min(a,b) + min(c,d);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var t=sc.S;
		var p=sc.S;
		int a=1009;
		int m=p.Length;
		if(t.Length<m){return;}
		var sb=new StringBuilder();
		t.Rh(p,a,mod,(i)=>{
			sb.Append(i+"\n");
		});
		Console.Write(sb);
	}
}
static class Ex2{
	public static void Rh(this string a,string s,int b,int mod,Action<int> f){
		int n=a.Length;
		int m=s.Length;
		long r=Hs(a,b,mod,m);
		long h=Hs(s,b,mod);
		long c=Fp(b,m,mod);
		if(r==h){f(0);}
		for(int i=m;i<n;i++){
			r=(r*b+(a[i]-47))%mod;
			r=(mod+r-(((a[i-m]-47)*c)%mod))%mod;
			if(r==h){f(i-m+1);}
		}
	}
	public static long Hs(string s,int a,int mod){
		int n=s.Length;
		long p=0;
		for(int i = 0;i<n;i++) {p=(p+(s[i]-47)*Fp(a,n-1-i,mod))%mod;}
		return p;
	}
	public static long Hs(string s,int a,int mod,int n){
		long p=0;
		for(int i = 0;i<n;i++) {p=(p+(s[i]-47)*Fp(a,n-1-i,mod))%mod;}
		return p;
	}
	private static long Fp(long x,long e,int mod){
		long r=1;
		while(e>0){
			if((e&1)>0){r*=x;r%=mod;}
			x=(x*x)%mod;
			e>>=1;
		}
		return r;
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


Measured memory_bytes: 48524
#include<iostream>
#include<cmath>
using namespace std;
 
int main(){
	int N, T, A;
	cin >> N >> T >> A;
	int H[N];
	for(int i=0; i<N; i++) cin >> H[i];
	
	double dif=100000;
	int ans=0;
	for(int i=0; i<N; i++){
		double tmp=T-H[i]*0.006;
		if(abs(A-tmp)<dif){
          dif=abs(A-tmp);
          ans=i+1;
        }
      
     // cout << dif << " " << tmp << endl;
	}
	cout << ans << endl;
}


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

using namespace std;

int main(void){
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i = 0; i < n; i++) cin >> d[i];
    long long sum = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
    return 0;
}

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

#define min(a,b) ((a)<(b)?(a):(b))

long long inf=0;

struct edge{
		long long from;
		long long to;
		long long cost;
};

int n,m;
long long d[1000];
struct edge e[2000];
long long from0[1000];
int check[1000]={0};

int find_negative(){
		int i,j;
		for(i=0;i<n;i++){
				for(j=0;j<m;j++){
						if(d[e[j].to]>d[e[j].from]+e[j].cost){
								d[e[j].to]=d[e[j].from]+e[j].cost;
								if(i==n-1)return 0;
						}
				}
		}
		return -1;
}

int fi_ne(){
		int i,j;
		for(j=0;j<n;j++){
				for(i=0;i<m;i++){
						if(d[e[i].from]==inf)continue;
						
						if(d[e[i].to]>d[e[i].from]+e[i].cost){
								d[e[i].to]>d[e[i].from]+e[i].cost;
								check[e[i].to]=1;
						}
						if(check[e[i].from]==1)check[e[i].to]=1;
				}
		}
}

void shortest(int s){
		int i,f,j;
		for(i=0;i<n;i++)d[i]=inf;
		d[s]=0;
		for(j=0;j<n-1;j++){
				f=0;
				for(i=0;i<m;i++){
						if(d[e[i].from]!=inf&&d[e[i].to]>d[e[i].from]+e[i].cost){
								d[e[i].to]=d[e[i].from]+e[i].cost;
								f=1;
						}
				}
				if(f==0)break;
		}
		for(i=0;i<n;i++)from0[i]=d[i];
}

int main(){
		int i,j;
		scanf("%d%d",&n,&m);
		for(i=0;i<m;i++){
				scanf("%lld%lld%lld",&e[i].from,&e[i].to,&e[i].cost);
				e[i].from--;
				e[i].to--;
				e[i].cost= -e[i].cost;
				inf+=abs(e[i].cost);
		}
		shortest(0);
		fi_ne();
		if(check[n-1]==1)puts("inf");
		else printf("%lld\n",-from0[n-1]);
		return 0;
}


Measured memory_bytes: 256
def solve(N):
    if N == 0:
        return "0"
    n = -N
    result = []
    while n != 0:
        q, r = divmod(n, -2)
        #print("%3d %3d %3d" % (n, q, r))
        n = q
        result.append(-r)
    return "".join(str(x) for x in reversed(result))

print(solve(int(input())))
#print(solve(-9)) # 1011
#print(solve(123456789)) # 1011
#print("11000101011001101110100010101")
#print(solve(0)) # 1011


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
typedef pair<int,int> P;
const int INF = 1<<29;

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

int w,h;
int xs,ys,xg,yg;

bool dfs(int y,int x){
    if(field[y][x]==0) return false;
    if(y==yg && x==xg) return true;
    int c = field[y][x];
    field[y][x] = 0;
    for(int i=0;i<4;i++){
        int nextx = x+dx[i], nexty = y+dy[i];
        if(0<=nextx&&nextx<w&&0<=nexty&&nexty<h && c==field[nexty][nextx]){
            if(dfs(nexty,nextx)) return true;
        }
    }
    return false;
}

int main(){
    while(1){
        scanf("%d%d",&w,&h);
        if(w==0)break;

        scanf("%d%d%d%d",&xs,&ys,&xg,&yg);
        xs--;ys--;xg--;yg--;

        int n;
        scanf("%d",&n);
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                field[i][j] = 0;
            }
        }
        for(int k=0;k<n;k++){
            int c,d,x,y;
            scanf("%d%d%d%d",&c,&d,&x,&y);
            x--;y--;
            int tate=2,yoko=4;
            if(d) swap(tate,yoko);
            for(int i=y;i<y+tate;i++){
                for(int j=x;j<x+yoko;j++){
                    field[i][j] = c;
                }
            }
        }
        /*
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                printf("%2d",field[i][j]);
            }
            printf("\n");
        }
        */


        if(dfs(ys,xs))cout << "OK" << endl;
        else cout << "NG" << endl;
    }

    return 0;
}

Measured memory_bytes: 1240
#include<stdio.h>

int main(){
  int w,h,x,y,r;
  scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);

  if(x+r>w || x-r<0 || y+r>h || y-r<0){
    printf("No\n");
  }
  else{
    printf("Yes\n");
  }

  return 0;
}


Measured memory_bytes: 2104
from operator import itemgetter
N = int(input())
SP = []
for i in range(N):
    name,cost = [x for x in input().split()]
    SP.append([name,int(cost),i])
SP.sort(key=itemgetter(1),reverse=True)
SP.sort(key=itemgetter(0))
for i in SP:
    print(i[2]+1)

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    double p = double((n + 1) / 2) / n;
    printf("%.10f\n", p);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int M = sc.nextInt();

    int sum = 0;
    if (N >= 2) {
      for (int i = N-1; i > 0; i--) {
        sum += i;
      }
    }

    if (M >= 2) {
      for (int i = M-1; i > 0; i--) {
        sum += i;
      }
    }

    System.out.println(sum);

  }

}

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

int n, a[1000], b[1000], c[1000], d[1000], ans = 0;

int main(){
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    partial_sum(a, a + n + 1, c);
    partial_sum(b, b + n + 1, d);
    for (int i = 1; i <= n; i++) ans = max(ans, c[i] + d[n] - d[i-1]);
    cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
vector<ll> cost,wt;
ll dp[101][100001];

ll solve(int i, int remain)
{
    if(i==cost.size())
        return 0;
    if(~dp[i][remain])
        return dp[i][remain];
    ll x=0,y;
    if(wt[i]<=remain)
        x=cost[i]+solve(i+1,remain-wt[i]);
    y=solve(i+1,remain);
    return dp[i][remain]=max(x,y);
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int n,w;
    ll x,y;
    cin>>n>>w;
    while(n--)
    {
        cin>>x>>y;
        wt.push_back(x);
        cost.push_back(y);
    }
    memset(dp, -1, sizeof dp);
    cout<<solve(0, w)<<endl;
} 


Measured memory_bytes: 79360
# -*- coding: utf-8 -*-

import sys
import os

n = int(input())
for i in range(n):
    base = [0, 0, 0]
    score = 0
    out_count = 0
    while True:
        s = input().strip()
        if s == 'HIT':
            if base[2] == 1:
                score += 1
            base[2] = base[1]
            base[1] = base[0]
            base[0] = 1

        elif s == 'HOMERUN':
            score += sum(base) + 1
            base = [0, 0, 0]

        elif s == 'OUT':
            out_count += 1
            if out_count > 2:
                break
    print(score)

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

using namespace std;

#define ll long long
#define ini(arr, val) memset(arr, (val), sizeof(arr))
#define loop(i,n)  for(ll i=0; i<n; i++)
#define loop1(i,n)  for(ll i=1; i<=n; i++)

#define all(a)      (a).begin(),(a).end()
#define exist(s,e)  (s.find(e)!=s.end())
#define dbg(x)  cout << #x << " = " << x << endl
#define pt(x) cout<<x<<"\n"
#define pts(x) cout<<x<<" "

#define mp make_pair
#define pb push_back
#define F first
#define S second


#define inf (int)1e9
#define infll 1e18
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007


#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test   int t; cin>>t; while(t--)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef set<int> si;

typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pll> vpll;
typedef vector<vl> vvl;
typedef map<ll,ll> mll;
typedef set<ll> sl;


int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };



//===========================DEBUG======================//
#define XOX 1
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

//================================================================//



//////////////////////////////////////////////////////////////////////////////////////////
//                      main starts
//////////////////////////////////////////////////////////////////////////////////////////
int const lmt=2e5+5;
char a[10][10];
ll R,C,K; 

ll cnt(int r, int c){
	int ans=0;
	loop(i,R)loop(j,C){
		if( ((r>>i)&1) || ((c>>j)&1) ) continue;
		if(a[i][j]=='#')ans++;
	}
	return ans;
}
int main(){
    #ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
    fast

    cin>>R>>C>>K;

    ll ans=0;
    loop(i,R)loop(j,C)cin>>a[i][j];
    loop(r,(1<<R)) loop(c,(1<<C)){
    	if(cnt(r,c)==K) ans++;
    }

    pt(ans);
}


/*


*/





Measured memory_bytes: 3608
A = [int(input()) for _ in range(5)]
A.sort(key=lambda x: (x-1) % 10)
time = 0
for i, a in enumerate(reversed(A)):
    if a % 10 == 0 or i == 4:
        time += a
    else:
        time += a + 10 - (a % 10)
print(time)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
//#include "rubo.h"

#define dbl double
#define pb push_back
#define mp make_pair
#define SQ(x) (x)*(x)
#define ll long long
#define ull unsigned long long
#define vc vector
//#define F first
//#define S second
//#define in ll
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define loop(xxx, yyy) for(int xxx = 0; xxx < yyy; xxx++)
//#define printf(fmt...) (0)
//#define puts(fmt...) (0)

using namespace std;

const int MAXN = 2222222;

ll q, h, s, d, n;

int main() {
    cin >> q >> h >> s >> d >> n;
    ll ans = 4 * n * q;
    ans = min(ans, 2 * n * h);
    ans = min(ans, n * s);

    ll x;
    if (n % 2 == 0) {
        x = (n / 2) * d;
    } else {
        x = (n / 2) * d;
        ll mek = 4*q;
        mek = min(mek,2*h);
        mek = min(mek,s);
        x += mek;
    }

    ans = min(ans,x);
    cout << ans;
    return 0;
}
/*50 4 5 123456*/


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

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

#define pb push_back

#define rep(i, l, n) for (int i = (l); i < n; i++)
#define rep_cs(i, l, n) for (int i = (l); i <= n; i++)

#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

const int MOD = 1000000007;

const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

using Graph = vector<vector<int>>;

Graph G;

vector<bool> seen;
void dfs(const Graph &G, int v)
{
    seen[v] = true;

    for (auto next_v : G[v])
    {
        if (seen[next_v])
            continue;
        dfs(G, next_v);
    }
}

int main()
{
    ll n;
    cin >> n;
    vll h(n);
    rep(i, 0, n) cin >> h[i];

    ll dp[100010];
    rep(i, 0, 100010)
    {
        dp[i] = INF;
    }

    dp[0] = 0;

    rep(i, 0, n)
    {
        chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }

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

Measured memory_bytes: 1792
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int a, p;
    cin >> a >> p;

    cout << (a * 3 + p) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int ll;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll ans = 0;
	if (a + b >= k) {
		if (k <= a)
			cout << min(k, a);
		else
			cout << a << "\n";
		return 0;
	}
	k -= (a + b);
	cout << a - k << " \n";
}



Measured memory_bytes: 3648
n,m=map(int,input().split())
cnt=[1]*n
res=[0]*n
res[0]=1
for i in range(m):
    x,y=map(int,input().split())
    if res[x-1]==1:
        res[y-1]=1
        if cnt[x-1]==1:
            res[x-1]=0
    cnt[x-1]-=1
    cnt[y-1]+=1
print(sum(res))

Measured memory_bytes: 4596