akhauriyash/Code-Regression huggingface dataset:
s = int(input())

def f(x):
    if x % 2 == 0:
        ans = x/2
    else:
        ans = 3 * x + 1
    return ans

check = 0
check_list = []
i = 0

while check == 0:
    if i == 0:
        check_list.append(s)
    else:
        if f(check_list[i-1]) not in check_list:
            check_list.append(f(check_list[i-1]))
        else:
            print(i+1)
            check = 1
            break
    i += 1


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;

const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}



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


  // n % m == n/m

  // 大きい数から順番に出していく　多分意外と少ない


  for(ll i=1;i<sqrt(n);i++){  //nは10^12までだからO(1)で間に合う
    ll tmp = n - i;

    if (tmp%i == 0 && n % (tmp/i)!=0 ){
      ans += tmp/i;
      // cerr << i<<endl;
    }
    if (tmp/i <= i)break;
  }







  cout << ans << endl;

}







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

S = 0
for i in range(N):
  S += A[i]
X = S
for i in range(N):
  if i%2:
    X -= 2*A[i]
print(X, end=" ")
for i in range(1,N):
    X = 2*A[i-1]-X
    print(X, end=" ")
print()


Measured memory_bytes: 14024
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(x) x.begin(),x.end()
#define VI vector<int> 
using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/
VI v(100005);
/*.....................DEFINE FUNCTIONS ......................*/
/*.........................kemkemG0...........................*/
int main() {int N;cin >> N;VI a(N);REP(i, N){int a; cin>>a;v[a]++;v[a+1]++;if(a!=0)v[a-1]++;}sort(ALL(v),greater<int>());cout<<v[0]<<endl;return 0;}


Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
long MOD=1e9+7,n,k,ans=1,l,r,flg=1,a[1<<18],x,y;
int main(){
  cin>>n>>k;
  r=n-1;
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  if(k%2)ans=a[r],r--,k--,flg=(ans<0?-1:1);
  while(k){
    x=a[l]*a[l+1],y=a[r]*a[r-1];
    if(x*flg>y*flg)ans*=x%MOD,ans%=MOD,l+=2;
    else ans*=y%MOD,ans%=MOD,r-=2;
    k-=2;
  }
  cout<<(ans%MOD+MOD)%MOD<<endl;
}


Measured memory_bytes: 5188
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(b-a)>1000000000000000000LL) cout<<"Unfair"<<endl;
    else if(d%2) cout<<b-a<<endl;
    else cout<<a-b<<endl;
    return 0;
}


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

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;
 
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;

int main() {

  int w,a,b;
  cin >> w >> a >> b;
  
  if ( ( b > a && a + w >= b ) || ( a > b && b + w >= a ) || ( a == b )){
    cout << 0 << endl;
  }else if ( b > a && b >= a + w ){
    cout << b - ( a + w ) << endl;
  }else if ( a > b && a >= b + w ){
    cout << a - ( b + w ) << endl;
  }

}

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

int main()
{
  int N, K, d, A;
  cin >> N >> K;

  vector<bool> vec(N);

  for (int i = 0; i < K; i++)
  {
    cin >> d;

    for (int i = 0; i < d; i++)
    {
      cin >> A;
      vec.at(A - 1) = true;
    }
  }

  int ans = 0;

  for (int i = 0; i < N; i++)
  {
    if (!vec.at(i))
      ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7;
inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}
int main() {
  int n;
  cin >> n;
  vector<int> c(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  c[n] = -1;
  vector<int> dp(n + 1), ep(2e5 + 1, 0);
  dp[n] = 1;
  for(int i = n - 1; i >= 0; i--) {
    if (c[i] != c[i + 1]) add(ep[c[i]], dp[i + 1]);
    dp[i] = ep[c[i]];
  }
  cout << dp[0] << '\n';
  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<utility>
#define ttn 1000000000LL
using namespace std;


int main() {
	long long n, k, a[200000];
	cin >> n >> k;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	long long l = -ttn * ttn, u = ttn * ttn + 1;
	while(l + 1 != u) {
		long long b = (l + u) / 2;
		long long s = 0;
		for(int i = 0; i < n - 1; i++) {
			long long ai = a[i];
			if (ai < 0) {
				int jl = n-1;
				if (ai * a[jl] > b) {
					continue;
				}
				int ju = i+1;
				if (ai * a[ju] <= b) {
					s += n - i - 1;
					continue;
				}
				while(ju + 1 != jl) {
					int j = (ju + jl) / 2;
					if (ai * a[j] <= b) {
						jl = j;
					} else {
						ju = j;
					}
				}
				s += n-jl;
			} else {
				int jl = i + 1;
				if (ai * a[jl] > b) {
					continue;
				}
				int ju = n - 1;
				if (ai * a[ju] <= b) {
					s += n - i - 1;
					continue;
				}
				while(jl + 1 != ju) {
					int j = (jl + ju) / 2;
					if (ai * a[j] <= b) {
						jl = j;
					} else {
						ju = j;
					}
				}
				s += jl - i;
			}
		}
		if (s < k) {
			l = b;
		} else {
			u = b;
		}
	}
	cout << u << endl;
}


Measured memory_bytes: 1792
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    double H = sc.nextDouble();
    double W = sc.nextDouble();
    if (H != 1 && W != 1)
			System.out.println((long) Math.ceil(H * W / 2));
		else
			System.out.println(1);
  }
}
    


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

int main(){
    
    int check[110] = {0};
    check[4] = 1;
    check[7] = 1;
    for (int i = 8; i <= 100; i++) 
    {
        if (check[i-4] == 1 or check[i-7] == 1)
        {
            check[i] = 1;
            //std::cout << "Now: " << i << " yes" << std::endl;
        }
    }
    
    int N;
    std::cin >> N;
    
    if (check[N] == 1)
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }
    
    return 0;
}

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

int main(){
	string x;
	while(1){
	int num,k=0;
	cin >> x;
	if(x=="0"){
		break;
	}
	for(int i=0;x[i];i++){
		num=x[i]-'0';
		k+=num;
	}
		cout << k << endl;
	}
return 0;
}

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

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int maxn=0,p=0;
		List<String[]> list=new ArrayList<>();
		
		int h=0;
		while(in.hasNext()) {
			String str=in.next();
			String datas[]=str.split(",");
			list.add(datas);
			if(datas.length>maxn) {
				maxn=datas.length;
				p=h;
			}
			h++;
		}
		
		int data[][]=new int[maxn][maxn],dp[][]=new int[maxn][maxn];
		h=0;
		for(int i=0;i<list.size();i++) {
			if(i>p)h=i-p;
			String[] nums=list.get(i);
			for(int j=0;j<nums.length;j++) {
				if(i<=p)data[nums.length-j-1][j]=Integer.parseInt(nums[j]);
				else data[maxn-j-1][h+j]=Integer.parseInt(nums[j]);
			}
		}
		
		
		dp[0][0]=data[0][0];
		for(int i=0;i<maxn;i++) {
			for(int j=0;j<maxn;j++) {
				if(i+1<=maxn-1)dp[i+1][j]=Math.max(dp[i+1][j], dp[i][j]+data[i+1][j]);
				if(j+1<=maxn-1)dp[i][j+1]=Math.max(dp[i][j+1], dp[i][j]+data[i][j+1]);
			}
		}

		System.out.println(dp[maxn-1][maxn-1]);
	}

}




Measured memory_bytes: 28472
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;

typedef long long ll;
const int MAXN=1000;

ll n,co[MAXN][8],u[4],ans;
map<ll,ll> vis;

ll get(ll a,ll b,ll c,ll d){
    return (a<<30)|(b<<20)|(c<<10)|d;
}

void add(ll x,ll v){
    for(int i=0;i<4;i++){
        vis[x]+=v;
        x=(x>>10)|(x&1023)<<30;
    }
}

int main(){
    scanf("%lld",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<4;j++){
            scanf("%lld",&co[i][j]);
            co[i][j+4]=co[i][j];
        }
        add(get(co[i][0],co[i][1],co[i][2],co[i][3]),1);
    }
    for(int i=0;i<n;i++){
        add(get(co[i][0],co[i][1],co[i][2],co[i][3]),-1);
        for(int j=i+1;j<n;j++){
            add(get(co[j][0],co[j][1],co[j][2],co[j][3]),-1);
            for(int k=0;k<4;k++){
                ll r=1;
                u[0]=get(co[j][k+1],co[j][k+0],co[i][1],co[i][0]);
                u[1]=get(co[j][k+0],co[j][k+3],co[i][2],co[i][1]);
                u[2]=get(co[j][k+3],co[j][k+2],co[i][3],co[i][2]);
                u[3]=get(co[j][k+2],co[j][k+1],co[i][4],co[i][3]);
                if(vis[u[0]]&&vis[u[1]]&&vis[u[2]]&&vis[u[3]]){
                    r*=vis[u[0]]; add(u[0],-1);
                    r*=vis[u[1]]; add(u[1],-1);
                    r*=vis[u[2]]; add(u[2],-1);
                    r*=vis[u[3]];
                    add(u[2],1); add(u[1],1); add(u[0],1);
                    ans+=r;
                }
            }
            add(get(co[j][0],co[j][1],co[j][2],co[j][3]),1);
        }
    }
    printf("%lld",ans);
}


Measured memory_bytes: 20404
S = input()
ans = 0
if len(S)%2 ==0:
    s1 = list(S[:len(S)//2])
    s2 = list(S[len(S)//2:])
    s2.reverse()

else:
    s1 = list(S[:len(S)//2 + 1])
    s2 = list(S[len(S)//2 : ])
    s2.reverse()

for a1, a2 in zip(s1, s2):
    if a1 != a2:
        ans += 1
print(ans)

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

Int n, t[1001], a[1001];

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> t[i] >> a[i];
	}
	t[0] = 1; a[0] = 1;
	
	for(int i = 1; i <= n; i++){
		Int k = max(t[i-1] / t[i] + (t[i-1] % t[i] != 0), a[i-1] / a[i] + (a[i-1] % a[i] != 0));
		t[i] *= k; a[i] *= k;
	}
	cout << t[n] + a[n] << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

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

        void run() {
            Scanner sc = new Scanner(System.in);
            long K = sc.nextLong();
            long ans = 0;
            long add = 1;
            PrintWriter pw = new PrintWriter(System.out);
            
            int cnt = 0;
            while (cnt++ < K) {
                if ((ans + add) * S(ans + add * 10) > (ans + add * 10) * S(ans + add))
                    add = add * 10;
                ans += add;
                pw.println(ans);
            }
            pw.close();
        }

        long S(long a) {
            long ret = 0;
            while (a > 0) {
                ret += a % 10;
                a /= 10;
            }
            return ret;
        }

        static void tr(Object... objects) {
            System.out.println(Arrays.deepToString(objects));
        }


}


Measured memory_bytes: 19540
A, B, C, X, Y = map(int, input().split())

if A + B < 2 * C:
    print(A*X + B*Y)

else:
    C_num = min(X, Y)
    print(min(2*C*max(X, Y), C_num*2*C + A*(X-C_num) + B*(Y-C_num)))

Measured memory_bytes: 3064
import sys

n = int(input())
a = list(map(int, input().split()))

a.sort()

ai = a.pop()

half_ai = ai / 2

min_diff = sys.maxsize
for i in a:
    diff = abs(half_ai - i)
    if diff < min_diff:
        aj = i
        min_diff = diff

print("{} {}".format(ai,aj))

Measured memory_bytes: 14060
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
const int maxn = 200010;

int n;
int total;
bool notequal;

int32_t main() {
	cin >> n;
	int ans = INT_MAX/2;
	for (int i =0;i<n;i++) {
		int a,b; cin >> a >> b;
		total += a;
		if (a > b) ans = min(ans,b);
		if (a != b) notequal = true;
	}
	if (!notequal) cout << 0;
	else cout << total - ans;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>

namespace {
using namespace std;
using ll = long long;
using ull = unsigned long long;
}

int X, Y, Z, K;
vector<ll> A, B, C;

void input() {
    cin >> X >> Y >> Z >> K;
    A.resize(X);
    for (auto& a : A)
        cin >> a;
    B.resize(Y);
    for (auto& b : B)
        cin >> b;
    C.resize(Z);
    for (auto& c : C)
        cin >> c;
}

bool cut_search(ll p, vector<ll>* sums = nullptr) {
    int cnt = 0;
    for (auto a : A) {
        for (auto b : B) {
            for (auto c : C) {
                ll sum = 0ll+a+b+c;
                if (sum < p)
                    break;
                cnt++;
                if (sums)
                    sums->push_back(sum);
                if (cnt >= K)
                    return true;
            }
        }
    }
    return cnt >= K;
}

void solve() {
    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());
    sort(C.rbegin(), C.rend());
    ll l = 0, r = 0ll+A[0]+B[0]+C[0];
    ll p = 0;
    while (l <= r) {
        ll c = (l+r)/2;
        if (cut_search(c)) {
            p = c;
            l = c + 1;
        } else {
            r = c - 1;
        }
    }
    vector<ll> sums;
    cut_search(p+1, &sums);
    sort(sums.rbegin(), sums.rend());
    for (auto sum : sums)
        cout << sum << endl;
    for (ll i = K - sums.size(); i > 0; i--)
        cout << p << endl;
}

int main() {
    input();
    solve();
    
    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long  A, B, C, D, E, F;
long long mass , sugar;
int main()
{
	scanf("%lld%lld%lld%lld%lld%lld", &A, &B, &C, &D, &E, &F);
	mass = A*100;
	for (int i = 0; i <= 30; i++) {
		for (int j = 0; j <= 30; j++) {
			if (i + j == 0)continue;
			for (int k = 0; C*k <= (A*i + B*j)*E; k++) {
				long long g = min(((A*i + B*j)*E - C*k) / D,( F - (100 * (i*A + j*B) + C*k)) / D);
				if ((100 * (i*A + j*B) + C*k + g*D <= F) && (sugar * (100 * (i*A + j*B) + C*k + g*D) < mass*(C*k + g*D))) {
					mass = 100 * (i*A + j*B) + C*k + g*D;
					sugar = C*k + g*D;
				}
			}
		}
	}
	printf("%lld %lld\n", mass, sugar);
}

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

void init(vector<vector<long long>> &mat, int n)
{
    mat[0][0] = 1;
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < n; ++j)
        {
            mat[i+1][j] += mat[i][j];
            mat[i+1][j+1] += mat[i][j];
        }
    }
}

long long sloveOdd(vector<vector<long long>> &mat, int n, int odd)
{
    long long res = 0;
    int todd = odd;
    if(odd%2==0)
    {
        --todd;
    }
    for(int i = todd; i > 0; i -= 2)
    {
        for(int j = 0; j <= n-odd; ++j)
        {
            res += mat[odd][i] * mat[n-odd][j];
        }
    }
    return res;
}

long long sloveEven(vector<vector<long long>> &mat, int n, int odd)
{
    long long res = 0;
    for(int i = 0; i <= n; ++i)
    {
        res += mat[n][i];
    }
    return res - sloveOdd(mat,n,odd);
}

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

    int odd = 0;
    for(int i = 0; i < n; ++i)
    {
        int t;
        cin >> t;
        if(t%2!=0)
        {
            odd += 1;
        }
    }

    long long int ans = 0;
    vector<vector<long long>> mt(n+1,vector<long long>(n+1));
    init(mt, n);
    if(p%2 == 0)
    {
        ans = sloveEven(mt,n,odd);
    }
    else
    {
        ans = sloveOdd(mt,n,odd);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int main()
{
	int n, a, b,ans1,ans2;
	cin >> n >> a >> b;
	ans1 = min(a, b);
	ans2 = max(a + b - n,0);
	cout << ans1 << " " << ans2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
#define MOD (ll)(1e9+7)
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

struct edge{
    ll to,k;
    edge(ll to,ll k):to(to),k(k){};
};

signed main(){
    ll n;
    cin >> n;
    vector<vector<edge> > G(n);
    queue<ll> que;
    bool is_visited[n] = {false};
    ll ans[n-1] = {};
    rep(i,0,n-1) ans[i] = -1;

    rep(i,0,n-1){
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[b].push_back(edge(a,i));
        G[a].push_back(edge(b,i));
        if(i == 0){
            que.push(a);
            is_visited[a] = true;
        }
    }

    ll cnt = 0;
    while(!que.empty()){
        ll v = que.front();
        que.pop();

        map<ll,ll> m;
        rep(i,0,G[v].size()){
            if(ans[G[v][i].k] == -1) continue;
            if(m.count(ans[G[v][i].k]) == 0){
                m[ans[G[v][i].k]] = 1;
            }
        }

        ll temp = 1;
        rep(i,0,G[v].size()){
            
            while(m.count(temp) == 1){
                temp++;
            }
            if(ans[G[v][i].k] == -1) ans[G[v][i].k] = temp++;
            if(!is_visited[G[v][i].to]){
                is_visited[G[v][i].to] = true;
                que.push(G[v][i].to);
            }
        }
    }

    rep(i,0,n-1) cnt = max(cnt,ans[i]);
    cout << cnt << endl;
    rep(i,0,n-1){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 8960
// Selection Sort
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_B&lang=jp
#include <iostream>
using namespace std;
const int ARRAY = 100;
int selectionSort(int a[], int n) {
    int minj;
    int sw = 0;
    int t;
    for(int i = 0; i < n -1; i++){
        minj = i;
        for(int j = i;j < n; j++){
            if(a[j] < a[minj]) minj = j;
        }
        t = a[i]; a[i] = a[minj]; a[minj] = t;
        if(i != minj) sw++;
    }
    return sw;
}
int main() {
    int n;
    int a[ARRAY];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int sw = selectionSort(a, n);
    for(int i = 0; i < n; i++){
        cout << a[i];
        if(i != n -1) cout << " ";
    }
    cout << endl;
    cout << sw << endl;
    return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
int n;
int x;
int t;
double sd;
int main()
{
	scanf("%d %d %d",&n,&x,&t);
	if(n%x==0)
	{
		printf("%d",n/x*t);
	}
	else
	{
		printf("%d",(n/x+1)*t);
	}
}

Measured memory_bytes: 3732
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;

int main()
{
	ll n,a,b;
	scanf("%lld%lld%lld",&n,&a,&b);
	if (a > b)
	{
		puts("0");
		return 0;
	}
	if (n==1 && b!=a)
	{
		puts("0");
		return 0;
	}
	ll low = a*(n-1) + b;
	ll up = b*(n-1) + a;
	printf("%lld\n",up-low+1);
	return 0;
}


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

int main()
{
    string str;
    int start, end;
    cin >> str;
    for (int i = 0; i < str.size();i++){
        if(str.at(i)=='A'){
            start = i;
            break;
        }
    }
    for (int i = str.size()-1; i >= start;i--){
        if (str.at(i) == 'Z')
        {
            end = i+1;
            break;
        }
    }

    cout << end-start << endl;
    //cout << end << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int a, b, c, x, y;

int solve() {
    int res = a * x + b * y;
    res = min(res, max(x, y) * c * 2);
    if (x > y) {
        res = min(res, y * c * 2 + a * (x - y));
    } else {
        res = min(res, x * c * 2 + b * (y - x));
    }
    return res;
}

void input() {
    cin >> a >> b >> c >> x >> y;
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll x,a,b;
int main(){
	cin >> x >> a >> b;
	if(a >= b) {
		cout << "delicious" << endl;
	}else if(b - a <= x) {
		cout << "safe" << endl;
	}else {
		cout << "dangerous" << endl;
	} 
	return 0;
}


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

using namespace std;

int main() {
    vector<vector<int>> c(3, vector<int>(3));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }

    cout << (c[0][0] - c[0][1] == c[1][0] - c[1][1]
            && c[0][0] - c[0][1] == c[2][0] - c[2][1]
            && c[0][0] - c[0][2] == c[1][0] - c[1][2]
            && c[0][0] - c[0][2] == c[2][0] - c[2][2] ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

//配列の並びを反転し、表示する。

public class Main {
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		
		//要素数の入力を受け取る
		int num = sc.nextInt();
		
		//配列の要素の入力を受け取る
		int[] array = new int[num];//配列を作る
		
		for (int i=0;i<array.length;i++){
			array[i]=sc.nextInt();
		}
		
		//配列の要素の並びを反転する
		reverse(array);
        
			for(int i=0;i<array.length;i++){
				System.out.print(array[i]);
                if(i<array.length-1){
                    System.out.print(" ");
                }
			}
			System.out.println();
        
		sc.close();
	}		
	
	//要素の並びを反転する
		static void reverse(int[] a){
			for(int i = 0; i < a.length /2; i++){
				swap(a,i,a.length - i - 1);
			}
		}
		
	//配列の要素を交換する
		static void swap(int[] a,int x, int y){
			int tmp = a[x];
			a[x]=a[y];
			a[y]=tmp;
		}

}


Measured memory_bytes: 26232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i,N){
        cin >> A[i];
    }
    vector<vector<ll>> dp(51,vector<ll>(2,-1));
    dp[0][0]=0;
    rep(i,50){
        ll mask=1LL<<(49-i);
        ll count=0;
        rep(j,N){
            if (A[j]&mask){
                count++;
            }
        }
        ll cost0=mask*count;
        ll cost1=mask*(N-count);
        if (dp[i][1]!=-1){
            dp[i+1][1]=max(dp[i+1][1],dp[i][1]+max(cost0,cost1));
        }
        if (dp[i][0]!=-1){
            if (K&mask){
                dp[i+1][0]=max(dp[i+1][0],dp[i][0]+cost1);
                dp[i+1][1]=max(dp[i+1][1],dp[i][0]+cost0);
            }
            else {
                dp[i+1][0]=max(dp[i+1][0],dp[i][0]+cost0);
            }
        }
    }
    cout << max(dp[50][0],dp[50][1]) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  string s;
  int al[26]={};
  cin>>s;
  for(int i=0;i<3;i++){
    if(s[i]=='a'){
      al[1]++;
    }
    else if(s[i]=='b'){
      al[2]++;
    }
     else if(s[i]=='c'){
      al[3]++;
    }
  }
  if((al[1]==1 && al[2]==1) && al[3]==1){
    cout<<"Yes"<<"\n";
  }
  else{
    cout<<"No"<<"\n";
  }
  return 0;
}

Measured memory_bytes: 3620
n = int(input())

a, b, ab = [], [], []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
    ab.append(ai + bi)
ab.sort(reverse=True)

ans = -sum(b)
for i in range(0, n, 2):
    ans += ab[i]
print(ans)


Measured memory_bytes: 21340
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>
#include<atcoder/all>
 
using namespace std;
 
/* template */
 
using ll = long long;
 
void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
 
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};
 
struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};
 
 
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;
 
template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}
 
template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
 
template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}
 
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
 
constexpr ll LNF = 1LL<<50;
 
constexpr int INF = 1e9+7;
 
const long double PI=3.14159265358979323846;
 
 
vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};
 
/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q; cin >> n >> q;
    atcoder::fenwick_tree<ll> fw(n);
    rep(i,0,n){
        ll a; cin >> a;
        fw.add(i,a);
    }
    rep(i,0,q){
        int t; cin >> t;
        if(t==0){
            int p;ll x; cin >> p >> x;
            fw.add(p,x);
        }
        else{
            int l,r; cin >> l >> r;
            cout << fw.sum(l,r) << endl;
        }
    }
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            var dict = new Dictionary<char, int>();
            for (var i = 0; i < S.Length; i++)
            {
                if (dict.ContainsKey(S[i]))
                    dict[S[i]]++;
                else
                    dict[S[i]] = 1;
            }

            if (dict.Count == 2 && !dict.Any(z => z.Value != 2))
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13276
n =  int(input())
for i in range(n):
    tri_list = list(map(int,input().split(" ")))
    tri_list.sort()
    a = int(tri_list[2]) ** 2
    b = int(tri_list[0]) ** 2 + int(tri_list[1]) ** 2
    if a == b:
        print("YES")
    else:
        print("NO")


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

using namespace std;

const int MAX_N = 1E5 + 10;

vector<int> gr[MAX_N];
vector<int> comp(MAX_N, -1);
vector<int> sz(MAX_N, 0);
vector<int> res(MAX_N);

void DFS(int i, int c)
{
    comp[i] = c;

    for (auto to : gr[i])
        if (comp[to] == -1)
            DFS(to, c);
}

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

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

    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;

        u--, v--;

        gr[u].push_back(v);
        gr[v].push_back(u);
    }

    int cur = 0;

    for (int i = 0; i < n; i++)
        if (comp[i] == -1)
        {
            DFS(i, cur);
            cur++;
        }

    for (int i = 0; i < n; i++)
        sz[comp[i]]++;

    for (int i = 0; i < n; i++)
        res[i] = sz[comp[i]] - gr[i].size() - 1;

    for (int i = 0; i < k; i++)
    {
        int u, v;
        cin >> u >> v;

        u--, v--;

        if (comp[u] == comp[v])
        {
            res[u]--;
            res[v]--;
        }
    }

    for (int i = 0; i < n; i++)
        cout << res[i] << " ";

    cout << "\n";

    return 0;
}


Measured memory_bytes: 7936
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)

#define Yes_RTN s_cout("Yes");return 0
#define No_RTN  s_cout("No");return 0
#define YES_RTN s_cout("YES");return 0
#define NO_RTN  s_cout("NO");return 0


int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);

int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}

#pragma endregion



int main(void) {
	int N,i,n;

	i_cin(N);
	
	for (i = N;i>0;i--) {
		n = sqrt(i);
		if (!(n * n - i)) break;
	}
	
	i_cout(i);
	return 0;
}







Measured memory_bytes: 128
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.trim().split("\n");
	const [N, K] = input[0].split(' ').map(n => parseInt(n))
	var data = input.slice(1)
	var arr = []
	for (var i = 0; i < data.length; i++ ) {
		if (i % 2 == 0) continue
		arr.push(... data[i].split(' ').map(n => parseInt(n)))
	}
	var snk = uniq(arr)

	function uniq(array) {
		return array.filter((elem, index, self) => self.indexOf(elem) === index);
	}

	var ans = N - snk.length 
	//出力
	console.log(ans)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require('fs').readFileSync('./input.txt', 'utf-8'));

Measured memory_bytes: 30436
#include <cstdio>

typedef long long ll;

const ll mod=1000000007ll;

void ad(ll &a,ll b){a+=b;a%=mod;}

int main()
{
  int n,m;
  scanf("%d%d",&n,&m);
  static ll dp[310][310][310]={0};
  dp[1][1][0]=1;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      for(int k=0;j+k<=n;k++){
	//printf("%d %d %d %lld\n",i,j,k,dp[i][j][k]);
	ad(dp[i+1][j][k],dp[i][j][k]*k%mod);
	ad(dp[i+1][j+k][0],dp[i][j][k]*j%mod);
	if(j+k+1<=n){
	  ad(dp[i+1][j][k+1],dp[i][j][k]*(n-j-k)%mod);
	}
      }
    }
  }
  printf("%lld\n",dp[m+1][n][0]);
  return 0;
}


Measured memory_bytes: 218624
package main

import (
	"fmt"
	"sort"
	"strings"
)

func main() {
	var (
		n, l int
		s    []string
		tx   string
	)
	fmt.Scan(&n, &l)
	for i := 0; i < n; i++ {
		fmt.Scan(&tx)
		s = append(s, tx)
	}
	sort.Strings(s)
	fmt.Print(strings.Join(s, ""))
}


Measured memory_bytes: 1900
if __name__ == '__main__':
    from sys import stdin
    # from collections import defaultdict
    # from collections import deque
    # from collections import Counter
    # import numpy as np
    # import math
    # import random
    input = stdin.readline

    a, v = map(int, input().split())
    b, w = map(int, input().split())
    t = int(input())
    if v <= w:
        print('NO')
        exit()
    if (v-w)*t >= abs(a-b):
        print('YES')
    else:
        print('NO')


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

const int mod = 998244353;
const int maxn = 1e7;
long long int pw[maxn+1],fac[maxn+1],inv[maxn+1];

long long int C(int n,int k){
	return fac[n]*inv[k]%mod*inv[n-k]%mod;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	pw[0]=fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=maxn;i++){
		fac[i]=fac[i-1]*i%mod;
		inv[i]=mod-mod/i*inv[mod%i]%mod;
	}
	for(int i=2;i<=maxn;i++)
		inv[i]=inv[i]*inv[i-1]%mod;
	int n;
	cin>>n;
	long long int ans = 1;
	for(int i=1;i<=n;i++)
		ans=ans*3%mod,pw[i]=pw[i-1]*2%mod;
	long long int tot = 0;
	for(int i=0;i<n/2;i++)
		tot += pw[i] * C(n,i)%mod;
	tot*=2;
	ans -= tot;
	cout<<(ans%mod+mod)%mod<<endl;
}


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

using namespace std;
#define ll long long

int main (void) {
    string s;
    cin >> s;

    string ret;
    ret = "Yes";
    for(int i=0;i<s.size();i+=2){
        if(s[i] != 'h' || s[i+1] != 'i'){
            ret = "No";
            break;
        }
    }

    cout << ret << endl;

    return 0;
}

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

int main(){
  int n, i;
  long double x1, x2, x3, x4, y1, y2, y3, y4, slopeofAB, slopeofCD;

  cin >> n;

  for(i = 0; i < n; i++){
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;

    slopeofAB = (y2 - y1) / (x2 - x1);
    slopeofCD = (y4 - y3) / (x4 - x3);

    if(slopeofAB == slopeofCD){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }

  return 0;
}

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

int main()
{
  string s;
  bool a=true;
  cin >> s;
  for(int i=0;i<3;i++){
    if(s[i]==s[i+1])	a=false;
  }
if(a==true)	cout << "Good";
else	cout << "Bad";
  return 0;
}

Measured memory_bytes: 256
import numpy as np
# N, M, X = map(int, input().split())
#
# A = []
# C = []
#
# for i in range(N):
#     L = list(map(int, input().split()))
#     C.append(L[0])
#     A.append(L[1:])
#
# CC = np.array(C)
# AA = np.array(A)
#
# if np.min(np.sum(AA, axis=0)) < X:
#     print('-1')
# else:
#   ans=np.sum(CC)
#
#   import itertools
#   origin_list = list(range(N))
#   for i, _ in enumerate(origin_list, 1):
#       for j in itertools.permutations(origin_list, r=i):
#           SA = np.zeros(M)
#           COST = 0
#           for id in j:
#               SA += AA[id]
#               COST += CC[id]
#           if np.min(SA)>=X and ans > COST:
#               ans = COST
#   print(ans)

n, m, x = map(int, input().split())
c = []
a = []

for i in range(n):
    L = list(map(int, input().split()))
    c.append(L[0])
    a.append(L[1:])

INF = 1001001001
ans = INF

# n = ビット数とみなしてfor文を回す
for s in range(0,1<<n): # 2のn乗.
    cost = 0
    d = [0]*m
    for i in range(n): #
        if s>>i&1: # sのiビット目が1かどうか判定する
            cost += c[i]
            for j in range(m):
                d[j] += a[i][j]
    ok = True
    for j in range(m):
        if d[j] < x:
            ok = False
    if ok:
        ans = min(ans, cost)

if ans == INF:
    print('-1')
else:
    print(ans)


Measured memory_bytes: 27016
#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
#define ff first
#define ss second
/*----------------------------------------------------------------------*/

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int a,b;
    cin>>a>>b;
    cout<<(3*a + b)/2;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  if(s[2]==s[3] && s[4]==s[5])
  cout << "Yes";
  else
  cout << "No";
}


Measured memory_bytes: 256
// Ivan Carvalho
// Problem D - Educational Dynamic Programming Contest - AtCoder
// Link : https://atcoder.jp/contests/dp
#include <bits/stdc++.h>
using namespace std;

const int MAXW = 1e5 + 10;

long long knapsack[MAXW];
int N,W;

int main(){

	cin >> N >> W;

	for(int item = 1;item<=N;item++){
		int w,v;
		cin >> w >> v;
		for(int i = W;i>=w;i--) knapsack[i] = max(knapsack[i-w] + v,knapsack[i]);
	}

	long long best = 0;
	for(int i = 0;i<=W;i++) best = max(best,knapsack[i]);
	cout << best << endl;

	return 0;

}

Measured memory_bytes: 4400
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#include <iostream>

using namespace std;

int main() {


    int N;
    std::cin >> N;

    map<long long, long long> m;

    vector<long long> as;
    vector<long long> bs;

    for (int i = 0; i < N; i++) {
        long long a, b;
        std::cin >> a >> b;
        m[b] += a;
    }

    long long current = 0;

    bool ok = true;

    for (auto kv : m) {

        if (current + kv.second <= kv.first) {
            current += kv.second;
        } else {
            ok = false;
            break;
        }
    }

    if (ok) {
        std::cout << "Yes" << "\n";
    } else {
        std::cout << "No" << "\n";
    }

    return 0;
}

Measured memory_bytes: 13184
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string T;
    cin >> T;
    int N;
    cin >> N;
    vector<string> S(N);
    for(int i=0; i<N; i++){
        cin >> S[i];
        S[i] += S[i];
    }
    int cnt = 0;
    for(int i=0; i<N; i++){
        bool ok = false;
        for(int j=0; j<S[i].size(); j++){
            if(S[i].substr(j,T.size()) == T) ok = true;
        }
        if(ok) cnt++;
    }
    cout << cnt << enld;
    return 0;
}



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

using namespace std;

#define MAX_LEN 1000
const int MOD = 1e9 + 7;

long long int ans = 1;

void updateAns(int val)
{
    ans *= val;
    ans %= MOD;
}

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    vector<int> a(n + 1);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    a[n] = 0;
    sort(a.begin(), a.end(), greater<int>());

    vector<int> b(m + 1);
    for (int i = 0; i < m; i++)
    {
        scanf("%d", &b[i]);
    }
    b[m] = 0;
    sort(b.begin(), b.end(), greater<int>());

    int ai = 0, bi = 0;
    for (int i = n * m; i >= 1; i--)
    {
        if (a[ai] > i || b[bi] > i)
        {
            ans = 0;
            break;
        }
        else if (a[ai] == i && b[bi] == i)
        {
            updateAns(1);
            ai++;
            bi++;
        }
        else if (a[ai] == i)
        {
            updateAns(bi);
            ai++;
        }
        else if (b[bi] == i)
        {
            updateAns(ai);
            bi++;
        }
        else
        {
            updateAns(ai * bi - (n * m - i));
        }
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
flg = 0
max = 0
if n > 1 :
  for i in range(n):
    if h[i] > max:
      max = h[i]
    elif h[i] < max-1 :
      flg = 1
      break

if flg == 1 :
  print('No')
else:
  print('Yes')

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

using namespace std;

int main(){
    int n, d;
    cin >> n >> d;
    int ans = 0;
    for (int i = 0; i < n; i++){
        int64_t x, y;
        cin >> x >> y;
        if (sqrt(x * x + y * y) <= d)
            ans++;
    }

    cout << ans << endl;
}

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

int N, C, K;
const int MAX_N = 1.0e5 + 100;
int T[MAX_N];

int main() {
    cin >> N >> C >> K;
    for (int i = 0; i < N; i++) cin >> T[i];

    sort(T, T+N);

    int ans = 0;
    int cnt = 1;
    int t = T[0];
    for (int i = 1; i < N; i++) {
        if (t+K >= T[i] && cnt < C) {
            cnt++;
        }
        else if (cnt >= C) {
            ans += ceil((double)cnt/C);
            cnt = 1;
            t = T[i];
        }
        else {
            ans += ceil((double)cnt/C);
            cnt = 1;
            t = T[i];
        }
    }
    ans += ceil((double)cnt/C);
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

m = 0
money = 0

stores = sorted(AB, key=lambda x:x[0])

for store in stores:
    money += min(store[1], M - m) * store[0]
    m += min(store[1], M - m)
    
print(money)


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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

int main() {
    int M; cin >> M;
    ll ans = 0;
    ll sum = 0;
    while (M--) {
        int d;
        ll c;
        cin >> d >> c;
        sum += c * d;
        ans += c;
    }
    ans += (sum - 1) / 9;
    cout << ans - 1 << endl;
}


Measured memory_bytes: 384
// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define ordered_set                            \
    tree<ll, null_type, less<ll>, rb_tree_tag, \
         tree_order_statistics_node_update>

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

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

    ll dp[s.size() + 1][t.size() + 1];

    for (int i = 0; i <= s.size(); i++) {
        dp[i][0] = 0;
    }

    for (int i = 0; i <= t.size(); i++) {
        dp[0][i] = 0;
    }

    for (int i = 1; i <= s.size(); i++) {
        for (int j = 1; j <= t.size(); j++) {
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] =
                    max({dp[i - 1][j - 1] + 1, dp[i - 1][j], dp[i][j - 1]});
            } else {
                dp[i][j] = max({dp[i][j - 1], dp[i - 1][j]});
            }
        }
    }

    string ans;
    ll n = s.size(), m = t.size();
    while (n > 0 && m > 0) {
        if (dp[n][m] == dp[n - 1][m]) {
            n--;
        } else if (dp[n][m] == dp[n][m - 1]) {
            m--;
        } else {
            ans.pb(s[n - 1]);
            n--, m--;
        }
    }

    reverse(all(ans));
    cout << ans << "\n";
}


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

int main(void)
{

	string instr;
	int N;

	cin >> N;

	cin.get();	//改行無視るための一文字読み込み関数（今回は()の中は何も書かない）
	for(int i = 0; i < N; i++){
		getline(cin, instr);
		for(int i = 0; i < instr.length(); i++){
			if(instr.substr(i, 7) == "Hoshino"){
				instr[i+6] = 'a';
				i += 5;
			}
		}
		cout << instr << endl;
	}

	return 0;
}

Measured memory_bytes: 1220
#!python3

iim = lambda: map(int, input().rstrip().split())

def factor(n):
    ans = []
    i = 0
    while n & 1 == 0:
        n >>= 1
        i += 1

    if i > 0:
        ans.append((2, i))

    for i in range(3, int(n**.5) +1, 2):
        x, y = divmod(n, i)

        if y == 0:
            j = 1
            x1 = x
            while True:
                x1, y = divmod(x, i)
                if y == 0:
                    x = x1
                    j += 1
                else:
                    ans.append((i, j))
                    break
            n = x

    if n > 1:
        ans.append((n, 1))
    return ans

def resolve():
    N = int(input())
    A = list(iim())
    mod = 10**9 + 7

    c = 1
    c2 = dict()
    for a in A:
        for n, m in factor(a):
            if n in c2:
                c2[n] = max(c2[n], m)
            else:
                c2[n] = m

    c3 = 1
    for n, m in c2.items():
        c3 *= n**m%mod % mod

    s = 0
    for a in A:
        s += c3*pow(a, mod-2, mod)%mod
        s %= mod

    print(s)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 4596