akhauriyash/Code-Regression huggingface dataset:
A, B, C, X, Y = map(int, input().split())


Set = min(X, Y)

if A+B >= 2*C:
    ans = Set * C * 2
    X -= Set
    Y -= Set
    big = max(X, Y)
    ans += min(A*X+B*Y, big*2*C)
else:
    ans = A*X + B*Y

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, A;
    vector<int> colors;
    cin >> N;
    REP(i, N) {
        cin >> A;
        auto ub = upper_bound(ALL(colors), A - 1);
        if (ub == colors.begin()) {
            colors.insert(colors.begin(), A);
        } else {
            colors[ub - colors.begin() - 1] = A;
        }
    }
    cout << colors.size() << endl;
    return 0;
}

Measured memory_bytes: 892
input()
A = [int(i) for i in input().split()]
c = 0
def bubble_sort(A):
    global c
    flag = True
    while flag:
        flag = False
        for i in range(len(A)-1, 0, -1):
            if A[i] < A[i -1]:
                A[i], A[i -1] = A[i -1], A[i]
                c += 1
                flag = True
bubble_sort(A)
print(*A)
print(c)


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



#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
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; }

const long long INF = 1LL<<60;

int lcm(int a,int b){
    //最小公倍数
    return a/__gcd(a,b) * b;
}


double L;

int main()
{
    cin>>L;
    double a=L/3;
    cout<<fixed<<setprecision(12)<<a*a*a<<endl;
    return 0;

}




Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

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

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

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

ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);
	return s + n;
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}

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

int main() {
	ll a, b; cin >> a >> b;
	if (a == b) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3660
#include<cstdio>
bool a[100005];
long long b[100005];
long long MOD = 1e9+7;
int main(void)
{
    long long n,m,t;
    scanf("%lld %lld" ,&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%lld" ,&t);
        a[t]=true;
    }
    b[0]=1;
    if(!a[1]) b[1]=1;
    for(int i=2;i<=n;i++)
    {
        if(!a[i])
            b[i]=(b[i-1]+b[i-2])%MOD;
    }
    printf("%lld" ,b[n]);
    return 0;
}


Measured memory_bytes: 1024
main :: IO ()
main = do
  [k, s] <- map (read :: String -> Int) .words <$> getLine
  let ans = [(x,y,s-x-y) | x <- [max 0 (s - 2 * k)..k]
                     , y <- [max 0 (s - 2 * k)..min k (s-x)]
                     , s - x - y >= 0 && k >= s - x- y]
  print $ length ans


Measured memory_bytes: 636
n=int(input())
P=[0]+list(map(float,input().split()))
#dp[i][j]i枚目まででj枚表が出る。
dp=[[0]*(n+1) for i in range(n+1)]
dp[1][0]=1-P[1]
dp[1][1]=P[1]
if n==1:
    print(P[1])
else:
    for i in range(2,n+1):
        for j in range(i+1):
            if j==0:
                dp[i][j]=dp[i-1][j]*(1-P[i])
            else:
                dp[i][j]=P[i]*dp[i-1][j-1]+(1-P[i])*dp[i-1][j]
    ans=0
    for i in range((n+1)//2):
        ans+=dp[n][i]
    print(1-ans)

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

string S[101], T[101];

int main(){
  int N, M;

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

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

  
  int ans = 0;

  for(int i = 0; i < N; i++){
    int x = 0;
    for(int j=0; j < N; j++) if(S[i] == S[j]) x++;
    for(int j=0; j < M; j++) if(S[i] == T[j]) x--;
    ans = max(x, ans);
  }
  cout << ans;
}


Measured memory_bytes: 256
#include<algorithm>
#include<stdio.h>
using namespace std;
int main(){
int d,i,n,m,j,ans=0,a[1100000],b[1100010],min,max,mid;
while(1){
scanf("%d %d\n",&n,&m);
if(n==0 && m==0){
break;
}
  n++;
a[0]=0;
for(i=1;i<n;i++){
scanf("%d\n",&a[i]);
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
b[i*n+j]=a[i]+a[j]; 
}
}
sort(b,b+n*n);
for(i=0;i<n*n;i++){
  min=0,max=n*n;
d=m-b[i];
  while(abs(max-min)>1){
    mid=(max+min)/2;
    if(d<=b[mid]){
      max=mid;
    }
    else if(d>b[mid]){
      min=mid;
    }
  }
   if(b[min]+b[i]<=m && b[min]+b[i]>ans){
ans=b[min]+b[i];
   }
}
printf("%d\n",ans);
ans=0;
}
  return 0;
}


Measured memory_bytes: 6540
#ifndef ___CLASS_MODINT
#define ___CLASS_MODINT

#include <cstdint>

template<std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::uint64_t n_) : n(n_ % mod) {};
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	std::uint32_t get() const { return n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint binpow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
	modint inv() { return (*this).binpow(mod - 2); }
};

#endif // ___CLASS_MODINT

using modulo = modint<1000000007>;

#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N; string S;
	cin >> N >> S;
	vector<vector<modulo> > dp(N);
	dp[0].push_back(modulo(1));
	for (int i = 1; i < N; ++i) {
		dp[i].resize(i + 1, modulo(0));
		if (S[i - 1] == '<') {
			for (int j = 1; j <= i; ++j) {
				dp[i][j] = dp[i][j - 1] + dp[i - 1][j - 1];
			}
		}
		else {
			for (int j = i - 1; j >= 0; --j) {
				dp[i][j] = dp[i][j + 1] + dp[i - 1][j];
			}
		}
	}
	modulo ans = 0;
	for (int i = 0; i < N; ++i) {
		ans += dp[N - 1][i];
	}
	cout << ans.get() << '\n';
	return 0;
}

Measured memory_bytes: 17920
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if (a < b)
        printf("a < b\n");
    else if (a > b)
        printf("a > b\n");
    else
        printf ("a == b\n");
}

Measured memory_bytes: 1168
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef complex<double> Point;

const double INF = 1e10;
const double EPS = 1e-7;

int main()
{
	int L;
	while(scanf("%d", &L) != EOF){
		char c;
		vi rs;
		while(scanf("%c", &c), c==' '){
			int r;
			scanf("%d", &r);
			rs.push_back(r);
		}
		int n = rs.size();
		
		vector<vector<double> > dp(1<<n, vector<double>(n, INF));
		rep(i, n){
			dp[1<<i][i] = rs[i]*2.0;
		}
		rep(i, 1<<n){
			rep(j, n){
				if(!(i&(1<<j)))
					continue;
				rep(k, n){
					if(j == k || !(i&(1<<k)))
						continue;
					dp[i][j] = min(dp[i][j], dp[i^(1<<j)][k] + 2.0*sqrt(rs[j]*rs[k])+rs[j]-rs[k]);
				}
			}
		}
		
		double best = INF;
		rep(i, n)
			best = min(best, dp[(1<<n)-1][i]);
		puts(best-EPS < L ? "OK" : "NA");
	}
	
	return 0;
}

Measured memory_bytes: 1356
n = int(input())
s = input().split(" ")
S = list(map(int,s))
q = int(input())
t = input().split(" ")
T = list(map(int,t))
C = []
for i in range(n):
    flag = 0
    for k in range(len(C)):
        if S[i] == C[k]:
            flag = 1
            break
    if flag == 1:
        continue
    for j in range(q):
        if S[i] == T[j]:
            C.append(S[i])
            break
print(len(C))

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> P;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N, M;
int A[550000], B[550000];
bool G[770][770];
int state[770];
vector<P> ps;
bool dp[770][770];

void dfs(int s, int st) {
    if(state[s] == st) return;
    if(state[s] != 0) {
        cout << -1 << endl;
        exit(0);
    }
    state[s] = st;
    if(st == 1) ps[ps.size()-1].first++;
    else ps[ps.size()-1].second++;
    for (int i = 1; i <= N ; i++) {
        if(s != i && !G[s][i]) dfs(i, -st);
    }
}

signed main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        G[A[i]][B[i]] = true;
        G[B[i]][A[i]] = true;
    }
    for(int i = 1; i <= N; i++) {
        if(state[i] == 0) {
            ps.push_back(P(0, 0));
            dfs(i, 1);
        }
    }
    dp[0][0] = true;
    for(int i = 1; i <= ps.size(); i++) {
        for(int j = 0; j < 770; j++) {
            if(dp[i - 1][j]) {
                dp[i][j + ps[i - 1].first] = true;
                dp[i][j + ps[i - 1].second] = true;
            }
        }
    }
    int ans = LLONG_MAX;
    for(int i = 0; i < 770; i++)  {
        if(dp[ps.size()][i])
            ans = min(ans, (i * (i - 1) + (N - i) * (N - i - 1)) / 2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 8320
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt() {
		int n = sc.nextInt();
		long x = sc.nextLong();
		long p[] = makeNumOfPatty(n);
		long bp[] = makeLenOfBg(n);
		long sum = 0;
		for(int i = n; i >= 0; i--) {
			if(bp[i] <= x) {
				sum += p[i];
				x -= bp[i];
				//System.out.println(i+" "+x + " " + sum);
				if(x > 0) { 
					x--;
					sum++;
					//System.out.println(i+" "+x + " " + sum);
				}
				if(bp[i] <= x) {
					sum += p[i];
					x -= bp[i];
					if(x > 0) { 
						x--;
						sum++;
						//System.out.println(i+" "+x + " " + sum);
					}
				}
			}
			
			x--;
			
			if(x == 0)break;
		}
		//System.out.println(Arrays.toString(p));
		//System.out.println(Arrays.toString(bp));
		//System.out.println(x);
		System.out.println(sum);
	}
	Main(){doIt();}
	public static void main(String[] args) {
		new Main();
	}
	long[] makeNumOfPatty(int n) {
		long ans[] = new long[n + 1];
		ans[0] = 1;
		for(int i = 1; i <= n; i++) {
			ans[i] = ans[i - 1] * 2 + 1;
		}
		return ans;
	}
	long[] makeLenOfBg(int n) {
		long ans[] = new long[n + 1];
		ans[0] = 1;
		for(int i = 1; i <= n; i++) {
			ans[i] = ans[i - 1] * 2 + 3;
		}
		return ans;
	}

}


Measured memory_bytes: 22996
const Main = input => {
  const FH = 500
  const F = 5
  const property = parseInt(input)
  const count500 = Math.floor(property / FH)
  const amari = property % FH
  const count5 = Math.floor(amari / F)
  console.log(count500 * 1000 + count5 * 5)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        for (int i = 0; i <= x; i++) {
            if ((y - (2 * i)) % 4 == 0) {
                int j = (y - (2 * i)) / 4;
                if (i + j == x) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 35748
#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N, M;
  cin >> N >> M;
  vector<vector<pll>> connect(N);
  for (ll i = 0; i < M; ++i)
  {
    ll l, r, d;
    cin >> l >> r >> d;
    connect.at(l - 1).push_back({r - 1, d});
    connect.at(r - 1).push_back({l - 1, -d});
  }
  vector<ll> place(N, -INF);
  for (ll i = 0; i < N; ++i)
  {
    queue<ll> q;
    q.push(i);
    if (place.at(i) == -INF)
    {
      place.at(i) = 0;
      while (!q.empty())
      {
        ll now = q.front();
        q.pop();
        for (ll j = 0; j < connect.at(now).size(); ++j)
        {
          pll check = connect.at(now).at(j);
          if (place.at(check.first) == -INF)
          {
            place.at(check.first) = place.at(now) + check.second;
            q.push(check.first);
          }
          else
          {
            if (place.at(check.first) != place.at(now) + check.second)
            {
              cout << "No" << endl;
              return 0;
            }
          }
        }
      }
    }
  }
  // for (ll i = 0; i < N; ++i)
  // {
  //   cout << place.at(i) << ' ';
  // }
  cout << "Yes" << endl;
}


Measured memory_bytes: 14080
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        int n = kbd.nextInt();
        Restaulant[] listRestaulant = new Restaulant[n];
        String x = kbd.nextLine();
        for (int i = 0; i < n; i++) {
            Restaulant temp = new Restaulant();
            temp.name = kbd.next();
            temp.point = kbd.nextInt();
            temp.index = i + 1;
            listRestaulant[i] = temp;
        }

        Arrays.sort(listRestaulant,
                Comparator.comparing(Restaulant::getName).thenComparingInt(Restaulant::getPoint).reversed());

        Arrays.sort(listRestaulant, Comparator.comparing(Restaulant::getName));
        for (int j = 0; j < n; j++) {
            Restaulant temp = listRestaulant[j];
            System.out.println(temp.getIndex());
        }
    }
}

class Restaulant {
    String name;
    int point;
    int index;

    String getName() {
        return this.name;
    }

    int getPoint() {
        return this.point;
    }

    int getIndex() {
        return this.index;
    }
}


Measured memory_bytes: 26836
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  string ans;
  switch (N % 10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      ans = "hon";
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      ans = "pon";
      break;
    case 3:
      ans = "bon";
      break;
    default:
      ans = "nope";
  }
  cout << ans << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define MAXN 200005
#define REP(temp, init_val, end_val) for (int temp = init_val; temp <= end_val; ++temp)
#define REPR(temp, init_val, end_val) for (int temp = init_val; temp >= end_val; --temp)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> intpair;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while (c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while (c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
inline int lowbit(int x){
    return x & (-x);
}
inline int modadd(int x, int y){
    return (x + y >= MOD ? x + y - MOD: x + y);
}
inline int sgn(int x){
    return (x < 0 ? -1: (x > 0 ? 1: 0));
}
template<typename T>
T gcd(T a, T b){
    return (!b) ? a: gcd(b, a % b);
}
int poww(int a, int b){
    int res = 1;
    while (b > 0){
        if (b & 1) res = 1ll * res * a % MOD;
        a = 1ll * a * a % MOD, b >>= 1;
    }
    return res;
}
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
const int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1}, ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

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

int n, t, a[100005];
unordered_set<int> st;
void init(){
    n = read(), t = read() / 2;
    REP(i, 1, n) a[i] = read();
}
void solve(){
    int maxi = 0, mini = INF;
    REP(i, 1, n){
        maxi = max(maxi, a[i] - mini);
        mini = min(mini, a[i]);
    }
    int cnt = 0;
    if (maxi == 0) {
        printf("0\n");
        return ;
    }
    REP(i, 1, n){
        if (st.count(a[i] - maxi)) ++cnt;
        st.insert(a[i]);
    }
    printf("%d\n", cnt);
}
int main(){
    int T = 1;
    while (T--){
        init();
        solve();
    }
    return 0;
}

Measured memory_bytes: 7656
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {

            var read = Console.ReadLine();
            read = Console.ReadLine();
            var temp_string = read.Split(' ');
            string ans = "";
            int count=0;

            Array.Reverse(temp_string);

            foreach (string i in temp_string)
            {
                ans += i;
                if(count<temp_string.Length-1)
                {
                    ans += " ";
                }
                count++;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 8924
#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;
int main(int a,char**){
    int b,h,m;
    cin>>a>>b>>h>>m;
    long double t=abs(M_PI*2*(60*h-11*m))/(12*60);
 // long double sint=sin(t),u=a*sint, v=a*sqrt(1-sint*sint)-b,result=sqrt(u*u+v*v);
    long double cost=cosl(t),result=sqrtl(a*a-2*a*b*cost+b*b);
 
    cout<<fixed<<setprecision(20)<<result<<endl;
}

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

#define int long long

#define REP(i, a) for(int i = 0; i < (a); i++)

using namespace std;

signed main()
{
    cout << fixed << setprecision(10);

    int n; cin >> n;
    int i = 1;
    while(i <= n)
    {
        int x = i;
        if(x % 3 == 0)
        {
            cout << " " << i;
        }
        else
        {
            while(x > 0)
            {
                if(x % 10 == 3)
                {
                    cout << " " << i;
                    break;
                }
                else
                {
                    x /= 10;
                }
            }
        }
        i++;
    }
    cout << endl;
}


Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <algorithm> 
#include <map>
using namespace std;
const int maxn = 1e4+10;
int a[maxn];

int main()
{
	int n , m , sum = 0;
	cin >> n >>m;
	for(int i  = 0; i < m; i++){
		cin  >> a[i];
		sum += a[i];
	}
	if(sum > n){
		cout << -1 << endl;
		return 0;
	}else{
		cout << n-sum << endl;
		return 0;
	}
	return 0;
}

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

#define mainspring cout<<"mainspring\n";
#define barrel cout<<"barrel\n";
#define escapement cout<<"escapement\n";

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define INF INT_MAX
#define NINF INT_MIN
#define fs first
#define sd second
#define tik(i,a,b) for(int i = a; i < b; i++)
#define tok(i,a,b) for(int i = a; i >= b; i--)
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}
#define int ll

typedef long long ll;
typedef unsigned long long ull;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << "\n";
    err(++it, args...);
}

const int MAX_A = 100+10, MAX_D = 100000+100;

int dp[MAX_A][MAX_D], w[MAX_A], v[MAX_A];

//dp[i][j] = solving the problem for the objects i, i+1, ..., n with W = j
//dp[i][j] = max(dp[i+1][j-w[i]]+v[i],dp[i+1][j])

int32_t main() {

	int n, W;
	cin >> n >> W;

	tik(i,1,n+1) {
		cin >> w[i] >> v[i];
	}

	tik(i,1,MAX_D) {
		if(i >= w[n])
			dp[n][i] = v[n];
		else
			dp[n][i] = 0;
	}

	tok(i,n-1,1) {
		tik(j,1,MAX_D) {
				if(j < w[i])
					dp[i][j] = dp[i+1][j];
				else
					dp[i][j] = max(v[i]+((j-w[i] > 0) ? dp[i+1][j-w[i]] : 0),dp[i+1][j]);
		}
	}

	cout << dp[1][W];

}



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

int N, a[100], cnt[9];

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        if(a[i] >= 3200){
            a[i] = 3200;
        }
        cnt[a[i] / 400] ++;
    }
    int ans = 0;
    for(int i = 0; i < 8; i++){
        if(cnt[i] != 0){
            ans++;
        }
    }
    cout << max(ans, 1) << " " << ans + cnt[8] << endl;

}


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

int main()
{
  int a, b, k;
  cin >> a >> b >> k;
  int i;
  for(i = 0; i < k; i++)
  {
    if(i%2==0)
    {
      b += a/2;
      a /= 2;
    }
    else
    {
      a += b/2;
      b /= 2;
    }
  }
  cout << a << ' ' << b << endl;
}

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

using namespace std;
const int MAXN = 200010;

int n, m;
vector<int> graph[MAXN];
bool visited[MAXN];

bool dfs(int cur, int remain) {
  if (remain < 0) {
    return false;
  }
  if (cur == n - 1) {
    return true;
  }
  visited[cur] = true;
  for (int i=0;i<graph[cur].size();i++) {
    int next = graph[cur][i];
    if (!visited[next] && dfs(next, remain - 1)) {
      return true;
    }
  }
  return false;
}

void solve() {
  if (dfs(0, 2)) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

int main() {
  int a, b;
  cin >> n >> m;
  for (int i=0;i<m;i++) {
    cin >> a >> b;
    a--;b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  solve();
}


Measured memory_bytes: 12144
N, M = gets.chomp.split(" ").map(&:to_i);
P = []
(N + 1).times{|i| P << []}
M.times{|i|
  x, y, z = gets.chomp.split(" ").map(&:to_i);
  P[x] << y
  P[y] << x
}

C = Array.new(N + 1, 0)

cnt = 0
(1..N).each{|i|
  next if C[i] != 0
  q = []
  q.push(i)
  cnt += 1
  while(q.size > 0) do
    j = q.shift
    next if C[j] == 1
    C[j] = 1
    P[j].select{|k| C[k] == 0}.each{|l| q.push(l)}
  end
}

puts cnt


Measured memory_bytes: 16124
a=str(input())
alist=list(a)
count7=0
count5=0
for x in alist:
    if x=="7":
        count7+=1
    if x=="5":
        count5+=1
    else:
        pass
if count7==1 and count5==2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9004
# -*- coding: utf-8 -*-
import heapq

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

la, lb, lc = len(a), len(b), len(c)

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

fix = set()

q = [(-(a[0]+b[0]+c[0]), 0, 0, 0)]

for _ in range(k):
    abc, i, j, l = heapq.heappop(q)
    print(-abc)

    if i+1 < la and (i+1, j, l) not in fix:
        heapq.heappush(q, (-(a[i+1]+b[j]+c[l]), i+1, j, l))
        fix.add((i+1, j, l))

    if j+1 < lb and (i, j+1, l) not in fix:
        heapq.heappush(q, (-(a[i]+b[j+1]+c[l]), i, j+1, l))
        fix.add((i, j+1, l))

    if l+1 < lc and (i, j, l+1) not in fix:
        heapq.heappush(q, (-(a[i]+b[j]+c[l+1]), i, j, l+1))
        fix.add((i, j, l+1))


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

#define ll unsigned long long

int main() {

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


	int n;
	cin >> n;
	int k ;
	cin >> k;
	int *arr = new int [n];
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
	}

	int *dp = new int [n];

	dp[0] = 0;
	for (int i = 1; i < n; ++i) {

		int mi = INT_MAX;
		for (int j = 1; j <= k; ++j) {
			if (i - j < 0) {
				break;
			}
			mi = min(mi, dp[i - j] + abs(arr[i] - arr[i - j]));
		}
		dp[i] = mi;
	}

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

	return 0;
}

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

int main(){
  int n,m,sum=0,a,sums=0,sumh;
  vector<int> x,y,sa;
  while(1){
    cin>>n>>m;
    if(n==0)break;
    x.clear();  y.clear();  sa.clear();

    cin>>a;
    x.push_back(a);
    for(int i=1;i<n;i++){
      cin>>a;
      x.push_back(a+x[i-1]);
    }

    cin>>a;
    y.push_back(a);
    for(int j=1;j<m;j++){
      cin>>a;
      y.push_back(a+y[j-1]);
    }
    x.push_back(0);    y.push_back(0);
    for(int i=0;i<x.size();i++){
      for(int j=0;j<y.size();j++){
	sa.push_back(x[i]-y[j]);
      }
    }
    sort(sa.begin(),sa.end());
    //for(int i=0;i<sa.size();i++)cout<<sa[i]<<endl;///////////
    sum=0;
    sums=0;
    for(int i=1;i<sa.size();i++){
      if(sa[i]==sa[i-1])sum++;
      else if(sa[i]!=sa[i-1]&&sum!=0){
	if(sum==1)sums+=sum;
	else {
	  sum++;
	  sums+=sum*(sum-1)/2;
	}
	//cout<<sums<<"kkkkkk"<<endl;//////////
	sum=0;
      }
    }
    cout<<sums<<endl;
  }
  return 0;
}

Measured memory_bytes: 19292
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#define rep(i,n) for (int i = 0; i< (n); i++)
using namespace std;
 
int main() {
  int N;
  string s = "APPROVED";
  cin >>N;
 
  vector<int> a(N); 
  
  rep(i,N) cin >> a[i];

  rep(i,N){
    if(a[i]%2==0){
      if(a[i]%3==0||a[i]%5==0) ;
      
      else s = "DENIED";
    }
  }
  
  
 
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String str = in.readLine();
    StringBuffer sb = new StringBuffer(str);
    String s = sb.reverse().toString();
    System.out.println(s.equals(str)?"Yes":"No");
  }
}

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

#define fi first
#define se second
#define eb emplace_back
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int) b; i--)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vi a (n);
  FOR (i, 0, n) {
    cin >> a[i];
  }
  i64 tot = 0;
  FOR (i, 0, n) {
    FOR (j, i + 1, n) {
      tot += a[i] * a[j];
    }
  }
  cout << tot << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;
#define INF (1LL << 60)
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,k,n) for(int i=(k);(i)<(n);(i)++)
#define REP(i,n) for(int i = 0;(i)<(n);(i)++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define F first
#define S second

int main() {
	int x;
	cin >> x;
	string ans;
	if (x == 7 || x == 5 || x == 3) {
		ans = "YES";
	}
	else {
		ans = "NO";
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;

int main() {
    int n, m, q;
    int l, r;
    int qp, qq;
    int ans;
    cin >> n >> m >> q;

    vector<vector<int>> x(n+1, vector<int>(n+1, 0));
    vector<vector<int>> c(n+1, vector<int>(n+1, 0));

    for(auto i=0;i<m;++i) {
        cin >> l >> r;
        x[l][r] += 1;
    }

    for(auto i=0;i<n+1;++i) {
        for(auto j=0;j<n+1;++j) {
            c[i][j] = c[i][j-1] + x[i][j];
        }
    }

    for (auto i=0;i<q;++i) {
        cin >> qp >> qq;
        ans = 0;
        for (auto j=qp;j<=qq;++j) {
            ans += c[j][qq] - c[j][qp-1];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 2944
using System;
using System.Linq;

namespace SHIP_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(n[0] + n[1] == 15 ? "+" : (n[0] * n[1] == 15 ? "*" : "x"));
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vec A(n);
    rep(i,n) cin>>A[i];
    ll m=1000,k=0;
    rep(i,n){
        if((i==0||A[i-1]>=A[i])&&(i!=n-1&&A[i]<A[i+1])) k+=m/A[i],m-=m/A[i]*A[i];
        if((i!=0&&A[i-1]<=A[i])&&(i==n-1||A[i]>A[i+1])) m+=k*A[i],k=0;
    }
    cout<<m<<"\n";
}

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

#define all(v) v.begin(), v.end()
#define mp make_pair
#define EPS (int)1e-9
#define PI acos(-1)
#define endl '\n'
#define pb push_back
#define fi first
#define se second

using namespace std;
using ld = long double;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

const int mod = 1000000007;


int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, x;
	cin >> n;

	set<int> st;
	while(n--)
	{
		cin >> x;
		if(st.count(x))
			st.erase(x);
		else
			st.insert(x);
	}

	cout << st.size() << endl;
	return 0;	
}

Measured memory_bytes: 4992
/*
AizuOnline A1250
Title Leaky Cryptography
@kankichi573
*/
#include <stdio.h>
int n;
unsigned int dat[8];
unsigned int sum;
//
unsigned int solve()
{
        int i,j,c;
        unsigned int ret,ret1,carry;

        ret=0;carry=0;
        for(i=0;i<32;i++)
        {
                c=1<<i; 
                ret1=c & (sum^carry);
                for(j=0;j<8;j++)
                        ret1 ^= (dat[j] & c);
                ret+=ret1;
#ifdef DEBUG
                printf("R1=%d R=%d\n",ret1,ret);
#endif
                carry=0;
                for(j=0;j<8;j++)
                {
                        carry += ((dat[j] ^ ret) & ((c<<1)-1));
                }
                if(i<31)
                        carry &= (c<<1);
#ifdef DEBUG
                printf("CR=%d\n",carry);
#endif
        }
        return(ret);
}

main()
{
        int i,j;
        unsigned int ret;

        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
                for(j=0;j<8;j++)
                        scanf("%x",&dat[j]);
                scanf("%x",&sum);
                ret=solve();
                printf("%x\n",ret);
        }

return(0);
}

Measured memory_bytes: 604
r, c = map(int, input().split())
array = []
for a in range(r):
	row = list(map(int, input().split()))
	array.append(row)

coltotal = [0 for i in range(c + 1)]
for a in range(r):
	array[a].append(sum(array[a]))
	for x in range(c + 1):
		coltotal[x] += array[a][x]

array.append(coltotal)

for a in range(r + 1):
	print(*array[a])

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

int main() {
	int N;
	cin >> N;
	vector<int>ans(4,0);
	for(int i=0;i<N;i++){
		string S;
		cin >> S;
		if(S == "AC"){
			ans.at(0)++;
		}
		 else if(S == "WA"){
			ans.at(1)++;
		}
		 else if(S == "TLE"){
			ans.at(2)++;
		}
		 else if(S == "RE"){
			ans.at(3)++;
		}
	}
	cout << "AC" << " " << "x" << " " << ans.at(0)<< endl;
	cout << "WA" << " " << "x" << " " << ans.at(1)<< endl;
	cout << "TLE" << " " << "x" << " " << ans.at(2)<< endl;
	cout << "RE" << " " << "x" << " " << ans.at(3)<< endl;

}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Ruined Square
            var lines = ReadLines<int>(1).ToList();

            int x1 = lines[0][0];
            int y1 = lines[0][1];
            int x2 = lines[0][2];
            int y2 = lines[0][3];

            int diffX = x2 - x1;
            int diffY = y2 - y1;

            int x3 = x2 - diffY;
            int y3 = y2 + diffX;
            int x4 = x3 - diffX;
            int y4 = y3 - diffY;

            var array = new int[4] { x3, y3, x4, y4 };
            Console.WriteLine(String.Join(" ", array));
        }
                        
        static IEnumerable<List<T>> ReadLines<T>(int count = 0, char separator = ' ')
        {
            //[summary]コンソールの値を読み込んで、List<T>のコレクションを返却

            //読み込む行数が未指定のときは、1行目の値を"count"とみなす
            if (count == 0)
            {
                string line = Console.ReadLine().TrimEnd();
                count = int.Parse(line);
            }

            for (int i = 0; i < count; i++)
            {
                //コンソールを1行読み込み
                string line = Console.ReadLine().TrimEnd();

                //char型のときは1文字ずつに分割
                if (typeof(T) == typeof(char))
                {
                    var list = line.ToCharArray().ToList();
                    yield return (List<T>)(object)list;
                }
                else
                {
                    //読み込んだ値を"separator"で区切る
                    var list = line.Split(separator).ToList();

                    //int型のときは数値に変換
                    if (typeof(T) == typeof(int))
                    {
                        var numbers = list.ConvertAll(int.Parse);
                        yield return (List<T>)(object)numbers;
                    }
                    else
                    {
                        yield return (List<T>)(object)list;
                    }
                }
            }
        }
    }
}


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

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

#define fi first
#define sec second
#define PB push_back
#define MP make_pair
#define endl '\n'
#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define revp(i,a,b)     for(int i=b;i>=a;i--)
#define all(v)          v.begin(),v.end()
void fast(){ ios::sync_with_stdio(false); cin.tie(NULL);}
void file()
{ 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin); 
    freopen("output.txt","w",stdout);
    #endif
}

string a,b,c;
char temp;
int main()
{
    fast();
    

    cin>>a>>b>>c;
    temp = a[0];
    a.erase(0,1);
    while(true){
 
     if(temp == 'a'){
        if(a.size() == 0){
            cout<<"A"<<endl;
            return 0; }
          temp = a[0];
          a.erase(0,1);
     }else if(temp == 'b'){
        if(b.size() == 0){
            cout<<"B"<<endl;
            return 0;
        }
        temp = b[0];
        b.erase(0,1);
     }
     else if(temp == 'c'){
         if(c.size() == 0){
            cout<<"C"<<endl;
            return 0;
         }
         temp = c[0];
         c.erase(0,1);
       }
  }
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
int main(){int n;
cin>>n;
int sum=10000000;
for(int i=0;i<n;i++){
  int s=0;
  int a;
  cin>>a;
  while(a%2==0){
    a/=2;
    s++;}
    if(s<sum){
  sum=s;
}
  

}
 cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<pair<int,int>> v[15];
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        for(int j=0;j<a;j++){
            int x,y;
            cin>>x>>y;
            x--;
            v[i].push_back(make_pair(x,y));
        }
    }
    int res=0;
    for(int bit=0;bit<(1<<n);bit++){
        int cnt=0;
        bool ok=true;
        for(int i=0;i<n;i++){
            if(bit&(1<<i)){
                cnt++;
                for(auto it:v[i]){
                    if(it.second==1){
                        if(bit&(1<<it.first)){
                            continue;
                        }else{
                            ok=false;
                        }
                    }else{
                        if(bit&(1<<it.first)){
                            ok=false;
                        }
                    }
                }
            }
        }
        if(ok){
            res=max(res,cnt);
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
from collections import deque
import copy
def bfs():
    h,w = map(int, input().split())
    maze = [list(input()) for i in range(h)]
    S, G = [], []
    for y in range(h):
        for x in range(w):
            if maze[y][x]=='.':
                S.append([y,x])
                G.append([y,x])
                maze[y][x]=float("inf")
            else:
                maze[y][x]=-1
    l = []
    ans = 0
    for i in range(len(S)):
        maze1 = copy.deepcopy(maze)
        maze1[S[i][0]][S[i][1]]=0
        que=deque([[S[i][0],S[i][1]]])
        while que:
          y,x=que.popleft()
          for k,m in [(1,0),(0,1),(-1,0),(0,-1)]:
            nexty,nextx=y+k,x+m
            if nexty < 0 or nexty >= h or nextx < 0 or nextx >= w:
                continue
            dist=maze1[nexty][nextx]
            if dist!=-1:
              if dist>maze1[y][x]+1:
                maze1[nexty][nextx]=maze1[y][x]+1
                que.append([nexty,nextx])
            ans = max(ans, maze1[nexty][nextx])
    print(ans)
bfs()

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
typedef complex<double> Complex;

struct data {
  bool line;
  Complex p, q;
};

string S;
ll p;

ll number() {
  ll sign = 1;
  if(S[p] == '-') {
    sign = -1;
    p++;
  }
  ll d = 0;
  while(p < S.length() && '0' <= S[p] && S[p] <= '9') {
    d = d * 10 + (S[p++] - '0');
  }
  return sign * d;
}

double det(Complex a, Complex b) {
  return a.real() * b.imag() - a.imag() * b.real();
}

Complex cross_point(Complex a, Complex b, Complex c, Complex d) {
  Complex u = b - a;
  Complex v = d - c;
  double p1 = u.imag(), q1 = -u.real(), r1 = -det(u, a);
  double p2 = v.imag(), q2 = -v.real(), r2 = -det(v, c);
  double t = p1 * q2 - p2 * q1;
  double x = (r1 * q2 - r2 * q1) / t;
  double y = (r2 * p1 - r1 * p2) / t;
  return Complex(x, y);
}

Complex opposite_point(Complex a, Complex p, Complex q) {
  Complex d = Complex((p - q).imag(), -(p - q).real());
  Complex s = cross_point(a, a + d, p, q);
  return a + (s - a) * 2.0;
}

data calc(data a, data b) {
  if(!a.line && !b.line) {
    return (data) { true, a.p, b.p };
  }
  if(a.line && b.line) {
    return (data) { false, cross_point(a.p, a.q, b.p, b.q) };
  }
  if(a.line && !b.line) swap(a, b);
  return (data) { false, opposite_point(a.p, b.p, b.q) };
}

data dfs() {
  data ret;
  if(S[p] != '(') {
    ret.line = false;
    ll x = number();
    p++;
    ll y = number();
    ret.p = Complex(x, y);
  } else {
    p++;
    ret = dfs();
    p++;
    while(p < S.length() && S[p] == '@') {
      p++;
      p++;
      data s = dfs();
      p++;
      ret = calc(ret, s);
    }
  }
  return ret;
}

int main(void) {
  while(cin >> S, S != "#") {
    p = 0;
    data ans = dfs();
    printf("%.15lf %.15lf\n", ans.p.real(), ans.p.imag());
  }
}


Measured memory_bytes: 3220
for _ in[0]*int(input()):
 X,z=input(),[]
 for y in input():
  s=i=0
  for k in z:
   t=X.find(y,s)+1
   if not t:break
   if t<k:z[i]=t
   s=k;i+=1
  else:
   t=X.find(y,s)+1
   if t:z+=[t]
 print(len(z))


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

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

int main(int argc, char **argv)
{
	ll a, b;
	cin >> a >> b;
	std::cout << (a * b) / GCD(a, b) << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define endl '\n'
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, sum = 0;
    cin >> n >> m;
    int a[m];
    for (int i = 0; i < m; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    cout << ((sum <= n) ? n - sum : -1) << endl;
    return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
  long long int n,m,mi;
  cin>>n;
  mi=n+1;
  m=fabs(sqrt(n));
  for(long long int i=1;i<m+1;i++){
    if(n%i==0){
      mi=min(mi,i+n/i);
    }
  }
  mi-=2;
  cout<<mi<<endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e16;

/*
<url:>
問題文============================================================

=================================================================

解説=============================================================

================================================================
*/

int retIdx(int i,int j,int N){
    if(i <= N/2 && j <= N/2){
        return (i-1)*N/2 + j;
    }else if(i > N/2 && j <= N/2){
        return (N-i)*N/2 + j;
    }else if(i <= N/2 && j > N/2){
        return (i-1)*N/2 + (N-j+1);
    }else{
        return (N-i)*N/2 + (N-j+1);
    }
    
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    int C,N; cin >> C >> N;
    vector<int> bit(N*N/4 + 1,0);
    vector<vector<int>> p(N+1,vector<int>(N+1,0));
    for(int i = 1; i <=N;i++){
        for(int j = 1; j <=N;j++){
            char c; cin >> c;
            p[i][j] = c - '0';
            
            if(p[i][j] == 1){
                bit[retIdx(i, j, N)]++;
            }
        }
    }
    int sum = 0;
    for(int i = 1; i <= N*N/4;i++) {
        if(bit[i] == 0 || bit[i] == 4){
            sum++;
        }
    }
    int ans = 0;
    if(sum == N*N/4) ans++;
    for(int i = 0; i < C - 1;i++){
        int D; cin >> D;
        for(int j = 0; j < D;j++){
            int r,c; cin >> r >> c;
            int idx = retIdx(r,c,N);
            
            if(bit[idx] == 0 || bit[idx] == 4) sum--;
            
            if(p[r][c] == 0){
                p[r][c] = 1;
                bit[idx]++;
            }else{
                p[r][c] = 0;
                bit[idx]--;
            }
            if(bit[idx] == 0 || bit[idx] == 4) sum++;
            
        }
        if(sum == N*N/4)ans++;
    }
    cout << ans << endl;
	return 0;
}



Measured memory_bytes: 7780
#include<iostream>
#include<algorithm>
using namespace std;
long long n,m,h,a[200100],f[200100],ans;
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		h+=a[i];
	}
	for(int i=0;i<n;i++)
		cin>>f[i];	 
	if(h-m<=0)
		cout<<0<<endl;
	else
	{
		long long k=h-m; 
		sort(f,f+n);
		sort(a,a+n,greater<int>());
		long long l=0,r=1000000000000,w,h;
		while(r-l!=1)
		{
			h=0;
			w=(l+r)/2;
			for(int i=0;i<n;i++)
			{
				if(a[i]<=w/f[i])
					h+=a[i];
				else
					h+=w/f[i];
			}
			if(h<k)
				l=w;
			else
				r=w;
			//cout<<w<<" "<<h<<endl;		
		}
		h=0;
		//cout<<l<<" "<<r<<endl;
		for(int i=0;i<n;i++)
		{
			if(a[i]>=w/f[i])
				h+=a[i];
			else
				h+=l/f[i];	
		}
		if(h>k)
			cout<<r<<endl;
		else
			cout<<l<<endl;	
	}		
} 

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double PI = 3.14159265358979323846;
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0; i < (n); ++i)

int main() {
  ll n, a[100001] = {0};
  ll res = 0;
  cin >> n;
  REP(i, n) cin >> a[i];
  ll minPlus = 0, minMinus = 0;
  ll sumPlus = 0, sumMinus = 0;
  REP(i, n) {
    sumPlus += a[i];
    if (i % 2 == 0 && sumPlus <= 0) {
      minPlus += 1 - sumPlus;
      sumPlus = 1;
    } else if (i % 2 == 1 && sumPlus >= 0) {
      minPlus += sumPlus + 1;
      sumPlus = -1;
    }
  }
  REP(i, n) {
    sumMinus += a[i];
    if (i % 2 == 0 && sumMinus >= 0) {
      minMinus += sumMinus + 1;
      sumMinus = -1;
    } else if (i % 2 == 1 && sumMinus <= 0) {
      minMinus += 1 - sumMinus;
      sumMinus = 1;
    }
  }
  res = min(minPlus, minMinus);
  cout << res << endl;
  return 0;
}

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

using namespace std;

int main()
{
  int Q;
  bool prime[100001] = {};
  int sum[100001] = {};

  for(int i = 2; i * i < 100001; i++) {
    if(prime[i]) continue;
    for(int j = i + i; j < 100001; j += i) {
      prime[j] = true;
    }
  }

  for(int i = 3; i < 100001; i++) {
    if(i & 1 && !prime[i] && !prime[(i + 1) / 2]) {
      ++sum[i];
    }
    sum[i] += sum[i - 1];
  }

  cin >> Q;
  while(Q--) {
    int L, R;
    cin >> L >> R;
    cout << sum[R] - sum[L - 1] << endl;
  }

}

Measured memory_bytes: 1152
n, K = map(int, input().split())
h = [int(x) for x in input().split()]
inf = float('inf')
dp = [inf] * n  # initialize dp
dp[0] = 0
for i in range(1, n):
    for k in range(1, K+1):
        if i - k >= 0:
            kouho = dp[i-k] + abs(h[i] - h[i-k])
            dp[i] = min(kouho, dp[i])
        else:
            break
print(dp[-1])

Measured memory_bytes: 55344
def power_of_2?(n)
  (n & (n - 1)) == 0
end

def max_divisor(n)
  n & -n
end

def g(sequence)
  table = [-1] * sequence.inject(1, &:+)
  table[0] = 0

  sum = 0
  sequence.each do |x|
    (sum & -x).step(0, -x) do |a|
      b = a + x
      if table[a] >= 0 && table[b] < table[a] + 1
        table[b] = table[a] + 1
      end
    end
    sum += x
  end

  indices = []
  i = 1
  while i <= sum
    indices << i
    i <<= 1
  end
  table.values_at(*indices).max
end

def extract(sequence, k)
  subsequence = sequence.select{|x| x % k == 0 && power_of_2?(x / k)}
  min = subsequence.min
  subsequence.map{|x| x / min}
end

def f(sequence)
  numbers = sequence.map{|k| k / max_divisor(k)}.uniq
  numbers.map{|k| g(extract(sequence, k))}.max
end

loop do
  n = gets.to_i
  break if n == 0
  sequence = gets.split.map!(&:to_i)
  puts f(sequence)
end

Measured memory_bytes: 18548