akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main()
{
	int N,K;
	while(1)
	{
		cin >> N;
		cin >> K;
		int temp;
		if(N == 0 && K==0)break;
		int *A = new int[K];
		int *B = new int[K];
		bool flag = true;
		for(int i=0;i<K;i++)
		{
			B[i] = 0;
		}
		for(int i=0;i<K;i++)
		{
			cin >> A[i];
		}
		for(int i=0;i<N;i++)
		{
			for(int i=0;i<K;i++)
			{
				cin >> temp;
				B[i] += temp;
			}
		}
		for(int i=0;i<K;i++)
		{
			if(B[i]>A[i])
			{
				flag = false;
				break;
			}
		}
		if(flag == false)
		{
			cout << "No" << endl;
		}
		else
		{
			cout << "Yes" << endl;
		}
	}
	return 0;
}

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

const int MOD = 1e9+7;

typedef long long ll;

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

  for(int i=1; i<=n; i++){
    ans *= i;
    ans %= MOD;
  }

  cout << ans%MOD << endl;

  return 0;
}


Measured memory_bytes: 256
local n=io.read("n")
local t={}
for i=1,n do
    t[i]={io.read("n","n")}
end
table.sort(t,function(a,b)
    return a[1]+a[2]>b[1]+b[2]
end)

local total=0
for i=1,n do
    total=total-t[i][2]
end
for i=1,n,2 do
    total=total+t[i][1]+t[i][2]
end
print(total)

Measured memory_bytes: 15352
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
int main()
{
    ft
    ll n,l;
    long double m;
    cin>>n>>m;
    l=n*round(m*100)/100;
    cout<<l<<"\n";
    return 0;
}

Measured memory_bytes: 3752
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		int N = scan.nextInt();

		//WK変数
		long sum = 0L;
		//演算
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				for (int k = 1; k <= N; k++) {

					int x1, y1;
					if (i > j) {
						x1 = i;
						y1 = j;
					} else {
						x1 = j;
						y1 = i;
					}
					while (x1 % y1 != 0) {
						int tmp = x1;
						x1 = y1;
						y1 = (tmp % y1);
					}

					int x2, y2;
					if (y1 > k) {
						x2 = y1;
						y2 = k;
					} else {
						x2 = k;
						y2 = y1;
					}
					while (x2 % y2 != 0) {
						int tmp = x2;
						x2 = y2;
						y2 = tmp % y2;
					}

					sum += y2;
				}
			}
		}
		//結果出力
		System.out.println(sum);
	}
}

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


def main():
    import sys
    input = sys.stdin.readline

    h, w, m = map(int, input().split())
    h_count = [0 for _ in range(h)]
    w_count = [0 for _ in range(w)]
    pairs = set()

    for i in range(m):
        hi, wi = map(int, input().split())
        hi -= 1
        wi -= 1

        h_count[hi] += 1
        w_count[wi] += 1

        pairs.add((hi, wi))

    h_max = max(h_count)
    w_max = max(w_count)
    hk = list()
    wk = list()

    for index, hj in enumerate(h_count):
        if hj == h_max:
            hk.append(index)

    for index, wj in enumerate(w_count):
        if wj == w_max:
            wk.append(index)

    ans = h_max + w_max

    for _h in hk:
        for _w in wk:
            hw = (_h, _w)

            if hw in pairs:
                continue

            print(ans)
            exit()

    print(ans - 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 83572
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

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

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  // 0からNまでに5の約数がどれくらい入っているか、Nが奇数の時は０
  ll N;
  cin >> N;
  if (N&1) {
    cout << 0 << '\n';
    return 0;
  }
  ll ans = 0;
  ll cur = 10;
  while (N/cur) {
    ans += N/cur;
    cur *= 5;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#include <vector>
using namespace std;
int main(){
    long long n;
    cin>>n;
    long long i=0,j=0;
    vector<pair<long long, long long>> a(n);
    for(i=0;i<n;i++){
        int t;
        cin>>t;
        a[i].first=t;
        a[i].second=i;
    }
    sort(a.begin(),a.end());
    j=a[n-1].second;
    for(i=0;i<n;i++){
        if(i!=j) cout<<a[n-1].first;
        else cout<<a[n-2].first;
        cout<<endl;
    }
    return 0;
    
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111


ll mo=998244353;
ll modpow(ll a, ll n) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}


	void solve(){

		ini(n);
		vi morty(n);
		FOR(i,0,n){
			in(morty[i]);
			if(i!=0 and morty[i] == 0)return out(0);
		}
		if(morty[0] !=0)return out(0);
		map<int,int>map1;
		FOR(i,0,n){
			map1[morty[i]]++;
		}
		int rick = 1;
		FORR(x,map1){
			if(x.first == 0)continue;
			rick*=modpow(map1[x.first-1],x.second);
			rick%=mo;
		}
		rick%=mo;
		out(rick);












	}









































int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N, K;
    cin >> N >> K;
    if(N % 2 == 1)
        N++;
    if(K <= N / 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

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

#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define vpii vector<pair<ll,ll>>
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll MOD=1000000000+7;
ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
ll factor(ll n){
    vll ans;
	if(n==2)ans.pb(2);
	else
    {for(ll i=2;i*i<=n;i++){if(n%i==0 && n%i!=i){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}ans.pb(n);}
    return ans.sz+1;
}
ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i; 
    return res; } 
  
ll nCr(ll n, ll r){ return fact(n) / (fact(r) * fact(n - r)); } 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 

ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

bool sortcol(const vector<int>& v1, 
               const vector<int>& v2){ 
 return v1[0] < v2[0]; } 

 ll sumdegit(ll n)
 {
 	ll sum=0;
 	while(n>0)
 	{
 		sum+=(n%10);
 		n/=10; 	}
 		return sum;
 }

void solve()
{
	/*ll h,w,k;
	vector<string> s;
	for(ll i=0;i<n;i++)
		cin>>s;*/
	ll n;
	cin>>n;
	vll a(n);
	for(ll i=0;i<n;i++)
		cin>>a[i];
	sort(all(a));
	ll ans=0;
	ans+=a[n-1];
	
	ll k=n-2;
	
	ll c=n-2;
	while(1)
	{
		if(c==0)
			break;
		if(c>1)
		{
			// cout<<a[k]<<" ";
			ans+=(2*a[k]);
			k--;
			c-=2;
			if(c==0)
				break;
		}
		else if(c==1)
		{
			// cout<<a[k]<<" ";
			ans+=a[k];
			k--;
			break;
		}
		
	}
	cout<<ans;
	return;
}  
int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 4788
n = int(input())
a = [int(x) for x in input().split(" ")]

s = [0 for _ in range(n)]
s[0] = abs(a[0])
for i in range(1,len(a)):
    s[i] = s[i-1] + abs(a[i]-a[i-1])
s.append(s[-1]+abs(a[-1]))

for i in range(n):
    if i==0:
        ret = abs(s[-1]-s[i+1]) + abs(a[i+1])
    elif i==len(a)-1:
        ret = s[i-1] + abs(a[i-1])
    else:
        ret = s[i-1] + abs(s[-1]-s[i+1]) + abs(a[i+1]-a[i-1])

    print(ret)


Measured memory_bytes: 14048
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;

#define DEBUG(x) cerr << #x << " = " << x << endl

int to_int(const string &s) {
  if(s == "") return 0;
  stringstream ss(s);
  int res;
  ss >> res;
  return res;
}

int main() {
  string S;
  cin >> S;
  int ans = 0;
  for(int i = 0; i <= (int)S.size(); ++i) {
    string L;
    if(i == 0) L = "";
    else L = S.substr(0, i);
    string R;
    if(i == (int)S.size()) R = "";
    else R = S.substr(i);
    if(L.size() > 0 && L[0] == '0') continue;
    if(R.size() > 0 && R[0] == '0') continue;
    int LN = to_int(L);
    int RN = to_int(R);
    if((LN + RN) % 2 == 1) continue;
    int A = (LN + RN) / 2;
    int B = A - LN;
    if(A >= 0 && B >= 0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1228
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100'010
#define MOD 1'000'000'007;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define repr(i, n) for(int i=(n-1); 0<=i; i--)
#define repr2(i, from, to) for(int i=(from-1); (int)(to)<=i; i--)
#define ALL(obj) (obj).begin(), (obj).end()
typedef long long ll;

using namespace std;


int main(void){
	int k, x; cin >> k >> x;
	for(int i = x-k+1; i<x+k; i++){
		cout << i << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(b / a, c) << endl;
  return 0;
}

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

int main()
{

	int num;
	while(true){
		cin >> num;
		if(num==0)
			break;

		int n,ni,nj,nk;

		for(int i=0 ;i<num ;i++){
			int x1,y1,z1,w1,x2,y2,z2,w2;

			cin >> x1 >> y1 >> z1 >> w1;
			cin >> x2 >> y2 >> z2 >> w2;

		n = x1*x2 - y1*y2 - z1*z2 -w1*w2;
		ni = x1*y2 + y1*x2 +z1*w2 -w1*z2;
		nj = x1*z2 -y1*w2 + z1*x2 + w1*y2;
		nk = x1*w2 + y1*z2 - z1*y2 + w1*x2;
		cout << n << ' '<< ni << ' '<< nj << ' ' << nk << endl;
		}
	}

	return 0;
}

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

using namespace std;

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

    vector<int> a(N);
    for(int i = 1; i <= N; ++i) cin >> a[i];
    
    vector<vector<int> > dp(N + 1, vector<int>(K + 1, 0));
    dp[0][0] = 1;
    int mod = 1e9 + 7, sum = 0;
    for(int i = 1; i <= N; ++i) {
        sum += a[i];
        for(int j = 0; j <= min(sum, K); ++j) {
            dp[i][j] = dp[i - 1][j];
            if(j > 0) {
                dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
            }
            if(j - 1 - a[i] >= 0) {
                dp[i][j] = (dp[i][j] - dp[i - 1][j - 1 - a[i]] + mod) % mod;
            }
        }
    }
    cout << dp[N][K] << endl;
    return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static string Rl()
        {
            return Console.ReadLine().Trim();
        }

        static IEnumerable<string> Spr(string s)
        {
            return s.Split(' ');
        }

        static Int64 C2I(string c)
        {
            return Int64.Parse(c);
        }


        static void Main(string[] args)
        {
            var rl = Spr(Rl()).Select(x => C2I(x)).ToList();
            var a = rl[0];
            var b = rl[1];
            var c = rl[2];
            var k = rl[3];
            long ret = 0;
            if (k <= a)
            {
                ret = k;
            }
            else if (k <= (a + b))
            {
                ret = a;
            }
            else
            {
                ret = 2 * a + b - k;
            }

            Console.WriteLine(ret);
            return;
        }
    }
}

Measured memory_bytes: 18896
h={}
f=->l,r{h[[l,r]]||=l>r ? 0:l<2?1+f[2,r]:f[l/2,~-r/2]+f[l=-~l/2,r/2]+f[l,~-r/2]}
eval"p f[%d,%d].%%10**9+7"%gets.split

Measured memory_bytes: 2044
#include<bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
    int H,W,A,B;
    cin >> H >> W >> A >> B;
    vector<vector<int>> mat(H,vector<int>(W));
    REP(i,H){
        REP(j,W){
            if(i < B && j < A){
                mat[i][j] = 0;
            }else if(i >= B && j >= A){
                mat[i][j] = 0;
            }else{
                mat[i][j] = 1;
            }
        }
    }

    REP(i,H){
        REP(j,W){
            cout << mat[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

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

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

int main() {
	
	vector<int> dp(100001,1000000);
	dp[0] = 0;dp[1] = 1;
	
	for( int i = 0 ; i < 100001 ; ++i ){
		for( int j = 0 ; pow(6,j) < 100001 ; ++j ){
			if(i + pow(6,j) < 100001)
			dp[i + pow(6,j)] = min(dp[i + pow(6,j)], dp[i] + 1);
		}
		for( int j = 0 ; pow(9,j) < 100001 ; ++j ){
			if(i + pow(9,j) < 100001)
			dp[i + pow(9,j)] = min(dp[i + pow(9,j)], dp[i] + 1);
		}
	}
	
	int N; cin >> N; 
    cout << dp[N] << endl;
}

Measured memory_bytes: 640
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))

total = 0
for a in A_list:
    total += B_list[a-1]

for i in range(N-1):
    if A_list[i] + 1 == A_list[i + 1]:
        total += C_list[A_list[i]-1]

print(total)

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

int main() {
int n,s,ans;
while(cin>>n>>s){
	ans=0;
	if(n==0){
		break;
	}
	if(n==1){
		if(0<=s && s<=9){
			ans=1;
		}
		else{
			ans=0;
		}
	}
	if(n==2){
		for (int k=0;k<=8;k++){
			for (int l=k+1;l<=9;l++){
				if(k+l==s){
					ans=ans+1;
				}
			}
		}
	}
	if(n==3){
		for (int k=0;k<=7;k++){
			for (int l=k+1;l<=8;l++){
				for (int m=l+1;m<=9;m++){
				if((k+l)+m==s){
					ans=ans+1;
				}
				}
			}
		}
	}
	if(n==4){
		for (int k=0;k<=6;k++){
			for (int l=k+1;l<=7;l++){
				for (int m=l+1;m<=8;m++){
					for(int o=m+1;o<=9;o++){
				if((k+l)+(m+o)==s){
					ans=ans+1;
				}
					}
				}
			}
		}
	}
	if(n==5){
		for (int k=0;k<=5;k++){
			for (int l=k+1;l<=6;l++){
				for (int m=l+1;m<=7;m++){
					for(int o=m+1;o<=8;o++){
						for(int p=o+1;p<=9;p++){
				if((k+l)+((m+o)+p)==s){
					ans=ans+1;
				}}
					}
				}
			}
		}
	}
	if(n==6){
		for (int k=0;k<=6;k++){
			for (int l=k+1;l<=7;l++){
				for (int m=l+1;m<=8;m++){
					for(int o=m+1;o<=9;o++){
				if((k+l)+(m+o)==45-s){
					ans=ans+1;
				}
					}
				}
			}
		}
	}
	if(n==7){
		for (int k=0;k<=7;k++){
			for (int l=k+1;l<=8;l++){
				for (int m=l+1;m<=9;m++){
				if((k+l)+m==45-s){
					ans=ans+1;
				}
				}
			}
		}
	}
	if(n==8){
		for (int k=0;k<=8;k++){
			for (int l=k+1;l<=9;l++){
				if(k+l==45-s){
					ans=ans+1;
				}
			}
		}
	}
	if(n==9){
		if(36<=s && s<=45){
			ans=1;
		}
		else{
			ans=0;
		}
	}
	cout<<ans<<endl;
}
	return 0;

}

Measured memory_bytes: 1160
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 1e18
#define MOD 1000000007
#define PI 4*atan(1.0)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=1005;
//int arr[SIZE]={};
//ここまでテンプレ
typedef double Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
 
void shortestPath(const Graph &g, int s,
    vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}
vector<int> buildPath(const vector<int> &prev, int t) {
  vector<int> path;
  for (int u = t; u >= 0; u = prev[u])
    path.push_back(u);
  reverse(path.begin(), path.end());
  return path;
}
int main(){
	cout<<setprecision(20);
	int sx,sy,gx,gy;
	cin>>sx>>sy>>gx>>gy;
	int N;
	cin>>N;
	int x[SIZE]={},y[SIZE]={},r[SIZE]={};
	for(int i=0;i<N;i++){
		scanf("%d%d%d",&x[i],&y[i],&r[i]);
	}
	x[N]=sx,y[N]=sy,r[N]=0;
	x[N+1]=gx,y[N+1]=gy,r[N+1]=0;
	Graph G;
	for(int i=0;i<N+2;i++){
		Edges E;
		G.push_back(E);
	}
	for(int i=0;i<N+2;i++)for(int j=0;j<N+2;j++){
		double xx=x[i]-x[j],yy=y[i]-y[j];
		double cost=max(0.0,sqrt(xx*xx+yy*yy)-(double)(r[i]+r[j]));
		G[i].push_back(Edge(i,j,cost));
	}
	vector<Weight> dis;
	vector<int> prev;
 
	shortestPath(G,N,dis,prev);
	cout<<dis[N+1]<<endl;
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  vector<int> vec(n);
  for(int i=0;i<n-1;i++){
    cin>>vec.at(i);
  }
  if(n==2){
    cout<<2*vec.at(0)<<endl;
  }
  else{
  int ans=vec.at(0)+vec.at(n-2);
  for(int i=1;i<n-2;i++){
    if(vec.at(i)>=vec.at(i+1)){
        ans+=vec.at(i+1);
    }
    else{
      ans+=vec.at(i);
    }
  }
  if(vec.at(0)<=vec.at(1)){
    ans+=vec.at(0);
  }
  else{
    ans+=vec.at(1);
  }
  cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int x,h,m,s;
    
    scanf("%d",&x);
    h=x/3600;
    m=(x%3600)/60;
    s=((x%3600)%60);
    
    printf("%d:%d:%d\n",h,m,s);
    return(0);
    
}

Measured memory_bytes: 592
import heapq
n,m=map(int,input().split())
a=[-int(i) for i in input().split()]
heapq.heapify(a)
for i in range(m):
    b=-heapq.heappop(a)
    heapq.heappush(a,-b/2)
print(int( sum(-i//1 for i in a)) )

Measured memory_bytes: 94232
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String s=sc.next();
s=s.replaceAll("eraser", "-");
s=s.replaceAll("erase", "-");
s=s.replaceAll("dreamer", "-");
s=s.replaceAll("dream", "-");
s=s.replaceAll("-","");
if(s.equals("")){System.out.println("YES");}else{System.out.println("NO");}
}}

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

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

	if (a.back() == b.front() && b.back() == c.front()) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int  ans = 0;
  for (int i=1;i<=n;i++){
    if (to_string(i).size() % 2 == 1) ans ++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3584
//拓扑排序+dp 
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100025;
int dp[maxn],in[maxn];
vector<int> G[maxn];
int main()
{
    queue<int> q;
    int n,m,a,b,ans = 0;
	cin>>n>>m;
    for(int i = 1;i<=m;++i){
    	cin>>a>>b;
		in[b]++;
		G[a].push_back(b);
	}
	
    for(int i = 1;i<=n;++i) 
	    if(!in[i]) q.push(i);
	    
    while(!q.empty()){
        int now = q.front();
        q.pop();
        int sz = G[now].size();
        for(int i = 0;i<sz;++i){
            dp[G[now][i]] = max(dp[G[now][i]],dp[now]+1);
            in[G[now][i]]--;
            if(in[G[now][i]]==0) q.push(G[now][i]);
        }
    }
    for(int i = 1;i<=n;++i) ans = max(ans,dp[i]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9848
#include <iostream>

using namespace std;

int main(){
  int n,m;
  int a[100][100] = {};
  int b[100] = {};
  int c[100] = {};

  cin >> n >> m;
  for( int i = 0; i < n; ++i){
    for( int j = 0; j < m; ++j){
      cin >> a[i][j];
    }
  }

  for( int i = 0; i < m; ++i){
    cin >> b[i];
  }

  for( int i = 0; i < n; ++i){
    for( int j = 0; j < m; ++j){
      c[i] +=  a[i][j]*b[j];
    }
    cout << c[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <cstdint>
using namespace std;
using i64 = int64_t;

void solve() {
	i64 x;
	cin >> x;
	i64 c500, c5;
	c500 = x / 500;
	x %= 500;
	c5 = x / 5;
	x %= 5;
	i64 score = c500 * 1000 + c5 * 5;
	cout << score << endl;
}

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



Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1<<28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int idx;
string s;
map<string, int> m;

int number() {
	int n = 0;
	while(isdigit(s[idx])) {
		if(n) n *= 10;
		n += s[idx++] - '0';
	}
	return n;
}

int atom() {
	string s2;
	s2 += s[idx++];
	if(islower(s[idx]))
		s2 += s[idx++];
	return m.count(s2) ? m[s2] : -1;
}

int molecute() {
	int sum = 0;
	while(idx < s.size() && s[idx] != ')') {
		if(s[idx] == '(') {
			idx++;
			int sum2 = molecute();
			if(sum2 == -1)
				return -1;
			idx++;
			sum += sum2 * number();
		}
		else {
			int sum2 = atom();
			if(sum2 == -1)
				return -1;
			if(isdigit(s[idx]))
				sum += sum2 * number();
			else
				sum += sum2;
		}
	}
	return sum;
}

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

	while(cin >> s, s != "END_OF_FIRST_PART") {
		int num; cin >> num;
		m[s] = num;
	}
	while(cin >> s, s != "0") {
		idx = 0;
		int ans = molecute();
		if(ans == -1)
			cout << "UNKNOWN" << endl;
		else
			cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
import java.util.*;
import static java.lang.Math.*;

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

		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		// 計算
		int result = 0;
		result = (100*(n-m)+1900*m)*(int)pow(2,m);
		
		// 出力
		System.out.println(result);
	}
}




Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
ll Abs(ll x,ll y){
    if(x>=y)return x-y;
    else return y-x;
}



int main(void){
    ll a,b,c;
    cin>>a>>b>>c;
    ll x = c-a-b;
    if(x<=0)cout<<"No"<<endl;
    else{
        if(x*x>4*a*b)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

    return 0;
}



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

using namespace std;

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int inf = 2e18;
const ld eps = 1e-9;
const int NN = 1e5 + 2;


bool  solve() {
      int i = 0, j = 0, k = 0, n = 0, m = 0; 
      cin >> k;
      if(k%10 == 7)
      return 1;
      k /= 10;
      if(k%10 == 7)
      return 1;
      k /= 10;
      if(k%10 == 7)
      return 1;

      return 0;
}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0); 
      int T = 1; 
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            cout << (solve() ? "Yes" : "No") << el;
       }

      return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
#include<algorithm>
using namespace std;

int main(){
  int hills[10];
  for(int i = 0;i < 10;i++){
    scanf("%d",hills + i);
  }
  sort(hills,hills + 10);
  printf("%d\n%d\n%d\n",hills[9],hills[8],hills[7]);
  return 0;
}

Measured memory_bytes: 1044
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int A[10];
	for (int i = 0; i < 10; i++)
		cin >> A[i];
	sort(A, A + 10, greater<int>());
	for (int i = 0; i < 3; i++)
		cout << A[i] << endl;
}


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define all(v) v.begin(),v.end_()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define strep(it,v) for(it=v.begin();it!=v.end_();++it)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a);  a = (a * a);  b/=2;  }  return res; }
#define rs resize
long long readLI(){  register char c;  for(c = getchar(); !(c>='0' && c<='9'); c = getchar());  register long long a=c-'0';
    for(c = getchar(); c>='0' && c<='9'; c = getchar())
        a = (a<<3)+(a<<1)+c-'0';
    return a;
}
const ll N = 100011;
ll a,b;
int main()
{
   std::ios_base::sync_with_stdio(false); cin.tie(NULL);
   cin>>a>>b;
   cout<<max(0LL,a - b);
   return 0;
}


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

int main(void){
  int N, Q;
  vector<int> date;

  while(cin >> N >> Q, N | Q){
    date.clear();
    for(int i=0; i < N; i++){
      int M;
      cin >> M;
      for(int j=0; j < M; j++){
	int tmp; cin >> tmp;
	date.push_back(tmp);
      }
    }

    vector<int> possible_date(101, 0);
    for(int i=0; i < date.size(); i++){
      possible_date[date[i]] += 1;
    }
    
    vector<int>::iterator max_ind = max_element(possible_date.begin(), possible_date.end());
    if(*max_ind >= Q){
      cout << max_ind - possible_date.begin() << endl;
    }else{
      cout << 0 << endl;
    }
  }
    
    
  return 0;
}

Measured memory_bytes: 1236
#include <algorithm>
#include <cstdio>

const int N=500005;
int a[N],b[N],d[N];

int main(){
	int n,q;
	scanf("%d%d\n",&n,&a[0]);
	for (int i=1;i<=n;i++){
		scanf("%d",&d[i]);
		a[i]=std::min(a[i-1],abs(a[i-1]-d[i]));
	}
	for (int i=n;i>=1;i--)
		b[i]=(b[i+1]>=d[i]/2)*d[i]+b[i+1];
	scanf("%d\n",&q);
	for (int i=1;i<=q;i++){
		int x;
		scanf("%d",&x);
		if (b[x+1]>=a[x-1]) printf("NO\n");
			else printf("YES\n");
	}
}

Measured memory_bytes: 7680
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


#A
def A():
    n = I()
    a = LI()
    s = sum([i%2 for i in a])
    if s in (0,n):
        print(0)
    else:
        print(n-2+(s%2))
    return

#B
def B():
    n,Q,L,R = LI()
    a = LI()
    a.sort()
    query = LIR(Q)
    l = -1
    r = n
    while r-l > 1:
        m = (l+r)>>1
        am = a[m]
        for q,x,s,t in query:
            if q == 1:
                if am < x:
                    continue
                am += s
                am *= t
            else:
                if am > x:
                    continue
                am -= s
                if am < 0:
                    am = -((-am)//t)
                else:
                    am //= t
        if am < L:
            l = m
        else:
            r = m
    left = r
    l = 0
    r = n
    while r-l > 1:
        m = (l+r)>>1
        am = a[m]
        for q,x,s,t in query:
            if q == 1:
                if am < x:
                    continue
                am += s
                am *= t
            else:
                if am > x:
                    continue
                am -= s
                if am < 0:
                    am = -((-am)//t)
                else:
                    am //= t
        if am <= R:
            l = m
        else:
            r = m
    print(r-left)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#G
def G():
    n = I()

    return

#H
def H():
    n = I()

    return

#I
def I_():
    n = I()

    return

#J
def J():
    n = I()

    return

#Solve
if __name__ == "__main__":
    B()



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



int main() {
    ios_base::sync_with_stdio(false);

    long long int a,b,c,d,i,j,k,n,m;
    cin>>n>>k;
    long long int ar[n+1],dp[n+1];
    for(i=0;i<n;i++)
        cin>>ar[i];
     dp[0]=0;
     for(i=1;i<n;i++)
        dp[i]=INT_MAX;
    //dp[1]=abs(ar[1]-ar[0]);
    for(i=0;i<n;i++)
    {
        //a=INT_MAX;
        for(j=1;j<=k && i+j<n;j++)
        {
           c=i+j;
           dp[c]=min(dp[c],(dp[i]+abs(ar[i]-ar[c])));
           //cout<<i<<" "<<c<<" "<<dp[0]<<" "<<dp[c]<<"\n";
        }


    }
    cout<<dp[n-1]<<"\n";
    return 0;
}


Measured memory_bytes: 1792
def iin() gets.chomp.split.map(&:to_i) end

(h, w) = iin
path = Array.new(h) { iin }.map.with_index{|a, i| i.odd? ? a.reverse : a }.flatten
ans = []
def pos(w, i)
    return (i / w), (i / w).odd? ? (w - 1) - (i % w) : (i % w)
end
(h * w - 1).times {|i|
    if path[i].odd?
        path[i+1] += 1
        y, x = pos(w, i)
        ny, nx = pos(w, i + 1)
        ans << "#{y+1} #{x+1} #{ny+1} #{nx+1}"
    end
}
p ans.size
ans.each {|a| puts a}

Measured memory_bytes: 20836
#include <stdio.h>

int main()
{
	int N;
	char a[1000001];
	scanf("%d", &N);
	scanf("%s", a);
	
	int i, j, k, count[3] = {}, two[1000000];
	for (i = 0; i < N - 1; i++) {
		a[i] = abs(a[i] - a[i+1]);
		count[a[i]]++;
	}
	for (i = 2; i < N; i++) {
		for (j = 0, k = i; k % 2 == 0; j++, k /= 2);
		two[i] = two[i-1] + j;
	}
	
	int parity = 0;
	if (count[1] == 0 || count[2] == 0) {
		for (i = 0; i < N - 1; i++) if (two[N-2] - two[N-i-2] - two[i] == 0) parity ^= a[i];
	} else {
		for (i = 0; i < N - 1; i++) if (two[N-2] - two[N-i-2] - two[i] == 0 && a[i] == 1) parity ^= 1;
	}
	
	printf("%d\n", parity);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 4992
//実験によるクソ再帰
#include <iostream>
#include <unordered_map>
#define int long long
using namespace std;

int power[60];
unordered_map<int, int> memo;

int dfs(int n) {	
	if (n <= 1) { return 0; }
	if (memo.find(n) != memo.end()) { return memo[n]; }
	
	int i;
	for (i = 0; (1LL << i) <= n; i++); i--;
	int diff = n - (1LL << i) - (1LL << (i-1));
	int ret = power[i - 1] + dfs(n - (1LL << i)) + dfs(n - (1LL << (i-1))) - dfs(diff) * 2;
	
	return memo[n] = ret % 1000000007;
}

signed main() {
	power[0] = 1;
	for (int i = 1; i < 60; i++) {
		power[i] = power[i - 1] * 3;
		power[i] %= 1000000007;
	}
	
	int n;
	cin >> n;
	cout << dfs(n + 2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

string S;
int K;
int dp[310][310][310];

int dfs(int l, int r, int k) {
    if (l == r)
        return dp[l][r][k] = 1;
    if (l > r)
        return dp[l][r][k] = 0;
    if (dp[l][r][k]) return dp[l][r][k];
    int res = -1;
    if (S[l] == S[r]) {
        CHMAX(res, dfs(l + 1, r - 1, k) + 2);
    } else {
        if (k > 0)
            CHMAX(res, dfs(l + 1, r - 1, k - 1) + 2);
        CHMAX(res, dfs(l + 1, r, k));
        CHMAX(res, dfs(l, r - 1, k));
    }
    return dp[l][r][k] = res;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> S >> K;
    cout << dfs(0, S.size() - 1, K) << endl;

    return 0;
}

Measured memory_bytes: 223360
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s;cin >> s;
    int res = 0;
    while(!res)
    {
        int len = s.size();
        --len;
        s = s.substr(0,len);
        if(len & 1)	continue;
        if(len == 0)	break;
        
        if(s.substr(0,len / 2) == s.substr(len / 2,len / 2))
            res = len;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    bool st = false;
    FOR(i, 1, n) {
        if (s[0] != s[i]) {
            if (!st) st = true;
            s[i] = s[0];
        } else {
            if (st) {
                st = false;
                k--;
                if (k <= 0) break;
            }
        }
    }
    int ans = 0;
    REP(i, n) {
        if (i != 0 and s[i] == 'L' and s[i - 1] == 'L') ans++;
        else if (i != n - 1 and s[i] == 'R' and s[i + 1] == 'R') ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n,W;
    cin >> n >> W;
    
    int w[n],v[n];
    int sum = 0;
    
    for(int i=0;i<n;i++){
        cin >> w[i] >> v[i];
      	sum += v[i];
    }
    
    long long int dp[2][1100000];
    for(int i=1;i<1100000;i++) dp[0][i] = INT_MAX;
  	
    for(int i=1;i<=n;i++){
        int t = i%2;
      	for(int j=0;j<1100000;j++) dp[t][j]=INT_MAX;
      	for(int j=0;j<1100000;j++){
        	dp[t][j] = min(dp[t][j],dp[!t][j]);
          	if(j-v[i-1]>=0){
            	dp[t][j] = min(dp[t][j],dp[!t][j-v[i-1]]+w[i-1]);
            }
        }
    }
    
    int ans = 0;
  	for(int i=0;i<1100000;i++){
    	if(dp[n%2][i]<=W) ans = i;
    }
 	cout << ans << endl;
    return 0;
}


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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll N;
	cin>>N;
    ll n,ans=0;
    rep(i,N){
        n = i+1;
        if(n%3!=0){
            if(n%5!=0){
                ans += n;
            }
        }
    }
    cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>

int main()
{
    //????????????
    int n,i,R[200000],j;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", &R[i]);

    

    int maxv = R[1]-R[0];
    int minv = R[0];
        for (j = 1; j < n ; j++) {
        maxv = (maxv >= R[j] - minv) ? maxv : (R[j] - minv);
        minv = (minv >= R[j]) ? R[j] : minv;
        }

    printf("%d\n", maxv);


    return 0;
}

Measured memory_bytes: 2572
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readString = map BS.unpack . BS.words

getInt = readInt <$> BS.getLine
getString = readString <$> BS.getLine

simulate (s:ss) k | k == 1 = [s]
                  | s == '1' = simulate ss (k-1)
                  | otherwise = [s]

main = do
  [ss] <- getString
  k <- getInt
  putStrLn $ simulate ss k


Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
#define int long long
map<string,int> ms;
int e[222][222];
int g[222][222];
int used[222];
int v;
void dfs(int u,int d){
  //cout<<u<<" "<<d<<endl;
  if(~used[u]) assert(used[u]==d);
  if(~used[u]) return;
  //cout<<u<<" "<<d<<endl;
  used[u]=d;
  for(int i=0;i<v;i++){
    if(e[u][i]) dfs(i,!d);
    if(g[u][i]) dfs(i,d);
  }
} 
signed main(){
  int n,m;
  while(cin>>n,n){
    ms.clear();
    string s[n];
    for(int i=0;i<n;i++) cin>>s[i];
    cin>>m;
    string t[m];
    for(int i=0;i<m;i++) cin>>t[i];
    memset(e,0,sizeof(e));
    memset(g,0,sizeof(g));
    v=0;
    for(int i=0;i<n;i++){
      int k=s[i].find('-');
      string x=s[i].substr(0,k);
      string y=s[i].substr(k+1,s[i].size()-(k+1));
      if(!ms.count(x)) ms[x]=v++;
      if(!ms.count(y)) ms[y]=v++;
      e[ms[x]][ms[y]]=1;
    }
    assert(v<=200);
    for(int i=0;i<v;i++){
      for(int j=i+1;j<v;j++){
	bool f1=0,f2=0;
	for(int k=0;k<v;k++){
	  if(i==k||j==k) continue;
	  f1|=(e[i][k]||e[k][i])&&(e[j][k]||e[k][j]);
	  f2|=(e[k][i]&&e[j][k]);
	  f2|=(e[i][k]&&e[k][j]);
	}
	if(f1&&!f2) g[i][j]=g[j][i]=1;
	//if(f1&&!f2) cout<<i<<" "<<j<<endl;
      }
    }
    cout<<v<<endl;
    for(int i=0;i<m;i++){
      int k=t[i].find('-');
      string x=t[i].substr(0,k);
      string y=t[i].substr(k+1,t[i].size()-(k+1));
      if(!ms.count(x)||!ms.count(y)){
	cout<<"NO"<<endl;
	continue;
      }
      //cout<<x<<" "<<y<<" "<<ms[x]<<" "<<ms[y]<<endl;
      memset(used,-1,sizeof(used));
      dfs(ms[x],0);
      //cout<<used[ms[y]]<<endl;
      cout<<(used[ms[y]]==1?"YES":"NO")<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4024
#include<cstdio>
#include <algorithm>
#include <iostream>
#include <functional>
#include<cmath>
#include<string.h>
#include<vector>

int main(){
	int m[3][3],n,b[10];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			scanf("%d",&m[i][j]);
		}
	}
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&b[i]);
	
	bool bl=false,mp[3][3];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			mp[i][j]=false;
		}
	}
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<n;k++){
				if(m[i][j]==b[k])mp[i][j]=true;
			}
		}
	}
	for(int i=0;i<3;i++){
		if(mp[i][0]&&mp[i][1]&&mp[i][2]) bl = true;
		if(mp[0][i]&&mp[1][i]&&mp[2][i]) bl = true;
	}
	if(mp[0][0]&&mp[1][1]&&mp[2][2]) bl = true;
	if(mp[0][2]&&mp[1][1]&&mp[2][0]) bl = true;
			
	
	if(bl) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

const long long N = 1e3 + 17;
ll a[N], b[N], cnt, ans, lnt, n, m, r1, r0, l1, l0, sum, mx, h, c[N], t[N], mn = N, x, y, k;
pair<ll,ll>pr[N];
vector<ll>v,v2;
map<ll,ll>mp;
bool used[N];
char ch[1005][1005];
ll prime[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> x >> y >> k;
    cout << (x - y) % k;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	long long n, a, ans=1, p, x=1000000000000000000, flag=0;
	cin>>n;
	while(n--){
		cin>>a;
		if(ans==0)
			break;
		p=x/ans;
		if(a>p){
			ans=1;
			flag=1;
		}
		else
			ans*=a;
	}
	if(ans!=0){
		if(flag)
		cout<<-1;
		else
		cout<<ans;
	}
	else
		cout<<0;
} 

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> p(n);
  rep(i,n){
    cin >> p[i].first;
    p[i].second = i+1;
  }
  sort(p.begin(),p.end());
  rep(i,n) cout << p[i].second << " ";
}


Measured memory_bytes: 4056