akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair<int,int> pii;
int dp[2][366][366];
int n;
vector<pair<pii,int> > scd;

int main(){

  while(cin>>n&&n){
    scd.clear();
    for(int i=0;i<n;i++){
      int a,b,c;
      cin>>a>>b>>c;
      scd.push_back(make_pair(pii(a,b),c));
    }
    sort(scd.begin(),scd.end());
    for(int i=n;i>=0;i--){
      int cur=i%2;
      int nxt=(i+1)%2;
      for(int j=0;j<366;j++){
	for(int k=0;k<366;k++){
	  int res=0;
	  if(i==n)res=0;
	  else{
	    if(scd[i].first.first>j)
	      res=max(res,dp[nxt][scd[i].first.second][k]
		      +scd[i].second);
	    if(scd[i].first.first>k)
	      res=max(res,dp[nxt][j][scd[i].first.second]
		      +scd[i].second);
	    res=max(res,dp[nxt][j][k]);
	  }
	  dp[cur][j][k]=res;
	}
      }
    }
    cout<<dp[0][0][0]<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1980
#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>

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

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;

int main() {
  ll MOD = 998244353;

  int N, K;
  cin >> N >> K;
  vector<int> l(K), r(K);
  for (int i = 0; i < K; i++) {
    cin >> l[i] >> r[i];
  }

  vector<ll> dp(N + 1, 0);
  vector<ll> dpsum(N + 1, 0);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= N; i++) {
    for (int j = 0; j < K; j++) {
      int l_idx = i - r[j];
      int r_idx = i - l[j];
      if (r_idx < 0) {
        continue;
      }
      l_idx = max(l_idx, 1);
      dp[i] += dpsum[r_idx] - dpsum[l_idx - 1];
      if (dp[i] < 0) {
        dp[i] = (dp[i] + MOD) % MOD;
      }

      dp[i] %= MOD;
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
    dpsum[i] %= MOD;
  }

  cout << dp[N] << endl;

  return 0;
}

Measured memory_bytes: 6436
// #pragma GCC optimize("O3")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, vector<vector<T>> &v)
{
	for (vector<T> &x : v)
		out << x << '\n';
	return out;
}

template <class T>
ostream& operator << (ostream& out, vector<T> &v)
{
	for (T &x : v)
		out << x << ' ';
	return out;
}

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define per(i,b,a) for (int i = b; i > a; i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	// 2rarb z c-a-b
	ll a,b,c;
	cin >> a >> b >> c;
	cout << (c - a - b >= 0 and 4 * a * b < (c-a-b) * (c-a-b) ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N;
    cin >> N;
    map<int, int> mp;
    vi A(N);
    rep(i, N) {
        cin >> A[i];
        mp[A[i]]++;
    }
    int sums = 0;
    for(auto &p : mp) {
        sums += p.se*(p.se-1)/2;
    }

    rep(i, N) {
        int t = sums;
        t -= mp[A[i]]*(mp[A[i]]-1)/2;
        t += (mp[A[i]]-1)*(mp[A[i]]-2)/2;
        cout << t << endl;
    }
    return 0;
}

Measured memory_bytes: 11008
'use strict'
const inArray = (needle, haystack) => haystack.some(item => item === needle)
const main = (input) => {
    input = input.split('\n')
    let temp = input[0].split(' ').map(i => parseInt(i))
    const N = temp[0]
    const M = temp[1]
    const X = temp[2]
    const As = input[1].split(' ').map(i => parseInt(i))
    let arr = Array(N+1).fill(false).map((v, i) => inArray(i, As))
    let cost1 = 0
    let cost2 = 0

    for(let i = X; i >= 0; i--){
        if(arr[i]){
            cost1++
        }
    }

    for(let i = X; i <= N; i++){
        if(arr[i]){
            cost2++
        }
    }

    console.log(Math.min(cost1, cost2))
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7500
import Data.Bool

main = do
  [h,w,n] <- map read.words<$>getLine
  [sr,sc] <- map read.words<$>getLine
  s <- getLine
  t <- getLine
  putStrLn $ bool "NO" "YES" $ solve h w n sr sc s t

solve h w n sr sc s t = eval $ go s t where
  eval Nothing = False
  eval (Just (l,r,u,d))
    = l<=sc && sc<=r && u<=sr && sr<=d
  go [] [] = Just (1,w,1,h)
  go (s:ss) (t:tt) = go ss tt >>= g t >>= f s
  f 'L' (l,r,u,d)
    | l < r = Just (l+1,r,u,d)
    | l == r = Nothing
  f 'R' (l,r,u,d)
    | l < r = Just (l,r-1,u,d)
    | l == r = Nothing
  f 'U' (l,r,u,d)
    | u < d = Just (l,r,u+1,d)
    | u == d = Nothing
  f 'D' (l,r,u,d)
    | u < d = Just (l,r,u,d-1)
    | u == d = Nothing
  g 'L' (l,r,u,d) = Just (l,min w (r+1),u,d)
  g 'R' (l,r,u,d) = Just (max 1 (l-1),r,u,d)
  g 'U' (l,r,u,d) = Just (l,r,u,min h (d+1))
  g 'D' (l,r,u,d) = Just (l,r,max 1 (u-1),d)

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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout)
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve()
{
    ll n;
    cin >> n;
    cout << n*n*n << "\n";
}

int main()
{
    FAST_IO;
    // #ifndef ONLINE_JUDGE 
   	// 	OC;
    // #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

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

int main() {
	int a, b, k, n=0;
	cin >> a >> b >> k;
	for (int i = a; i != 0; i--) {
		if (a%i == 0 && b%i == 0) {
			n++;
		}
		if (n == k) {
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
def main():
    from collections import Counter
    n = int(input())
    l = list(map(int,input().split()))
    c = Counter(l)

    
    count = 0
    for j,k in c.items():
        count += k*(k-1)//2
        
    for i in l:
        x = c[i]
        y = (x*(x-1)-(x-1)*(x-2))//2
        print(count-y)
if __name__ == "__main__":
    main()

Measured memory_bytes: 26780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (int) (1e9+7)
#define INF (int) 2e9

int main(){
    int n, m;
    cin >> n >> m;
    int c[m];
    rep(i, m){
        cin >> c[i];
    }

    int dp[50005];

    rep(j, 50005){
        dp[j] = j;
    }

    for (int i = 0; i < m; i++){
        for (int j = c[i]; j < n+1; j++) {
            dp[j] = min(dp[j], dp[j-c[i]]+1);
        }
    }

    cout << dp[n] << endl;
    // printf("%d\n", N);
    return 0;
}


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

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define N 405
using namespace std;
inline int read(){
	int ans=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
int n,col[N][4];
ll ans=0,mp[N][4];
map<ll,int>cnt;
inline ll idx(int a,int b,int c,int d){return 1ll*a+1ll*b*1000+1ll*c*1000000+1ll*d*1000000000;}
int main(){
	n=read();
	for(int i=1;i<=n;++i)for(int j=0;j<=3;++j)col[i][j]=read();
	for(int i=1;i<=n;++i){
		mp[i][0]=idx(col[i][0],col[i][1],col[i][2],col[i][3]);
		mp[i][1]=idx(col[i][1],col[i][2],col[i][3],col[i][0]);
		mp[i][2]=idx(col[i][2],col[i][3],col[i][0],col[i][1]);
		mp[i][3]=idx(col[i][3],col[i][0],col[i][1],col[i][2]);
		for(int j=0;j<4;++j)++cnt[mp[i][j]];
	}
	for(int i=1;i<=n;++i){
		for(int j=0;j<4;++j)--cnt[mp[i][j]];
		for(int j=i+1;j<=n;++j){
			if(i==j)continue;
			for(int k=0;k<4;++k)--cnt[mp[j][k]];
			for(int k=0;k<4;++k){
				ll tmp[16],ttmp=1;
				tmp[0]=idx(col[i][0],col[i][3],col[j][k],col[j][(k+3)%4]);
				tmp[4]=idx(col[j][(k+3)%4],col[i][0],col[i][3],col[j][k]);
				tmp[8]=idx(col[j][k],col[j][(k+3)%4],col[i][0],col[i][3]);
				tmp[12]=idx(col[i][3],col[j][k],col[j][(k+3)%4],col[i][0]);
				tmp[1]=idx(col[i][1],col[i][0],col[j][(k+3)%4],col[j][(k+2)%4]);
				tmp[5]=idx(col[j][(k+2)%4],col[i][1],col[i][0],col[j][(k+3)%4]);
				tmp[9]=idx(col[j][(k+3)%4],col[j][(k+2)%4],col[i][1],col[i][0]);
				tmp[13]=idx(col[i][0],col[j][(k+3)%4],col[j][(k+2)%4],col[i][1]);
				tmp[2]=idx(col[i][2],col[i][1],col[j][(k+2)%4],col[j][(k+1)%4]);
				tmp[6]=idx(col[j][(k+1)%4],col[i][2],col[i][1],col[j][(k+2)%4]);
				tmp[10]=idx(col[j][(k+2)%4],col[j][(k+1)%4],col[i][2],col[i][1]);
				tmp[14]=idx(col[i][1],col[j][(k+2)%4],col[j][(k+1)%4],col[i][2]);
				tmp[3]=idx(col[i][3],col[i][2],col[j][(k+1)%4],col[j][k]);
				tmp[7]=idx(col[j][k],col[i][3],col[i][2],col[j][(k+1)%4]);
				tmp[11]=idx(col[j][(k+1)%4],col[j][k],col[i][3],col[i][2]);
				tmp[15]=idx(col[i][2],col[j][(k+1)%4],col[j][k],col[i][3]);
				if(cnt[tmp[0]]==0||cnt[tmp[1]]==0||cnt[tmp[2]]==0||cnt[tmp[3]]==0)continue;
				for(int l=0;l<4;++l){
					ttmp*=cnt[tmp[l]];
					for(int m=l;m<16;m+=4)--cnt[tmp[m]];
				}
				for(int l=0;l<16;++l)++cnt[tmp[l]];
				ans+=ttmp;
			}
			for(int k=0;k<4;++k)++cnt[mp[j][k]];
		}
		for(int j=0;j<4;++j)++cnt[mp[i][j]];
	}
	cout<<ans/3;
	return 0;
}

Measured memory_bytes: 20352
#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
ll power(ll a, ll b){ll res=1;a=a%mod; while(b){if(b&1)res=(res*a)%mod; a=(a*a)%mod;b/=2;}return res;}
ll invmod(ll a){return power(a,mod-2);}
int main(void)
{
	FIO	
	int n,x;
	cin>>n;
	vector<int> arr[n+1];
	for(int i=2;i<=n;i++)
	{
		cin>>x;
		arr[x].pb(i);
	}
	for(int i=1;i<=n;i++) cout<<arr[i].size()<<"\n";
	return 0;
}

Measured memory_bytes: 14560
import java.io.*
import java.util.*
import java.lang.Math.*


fun main() {
    val N = rd.readLong()

    var ans = 0L

    for (i in 1 .. N) {
        val sum = (i + (N/i)*i)*(N/i)/2
        ans += sum
    }

    println(ans)
}


//val rd = debug.Reader("abc", "171", "d", "sample-1")
val rd = Reader()
fun main(args: Array<String>) {
    Thread(null, MainThread(), "mainThread", 128 * 1024 * 1024).start()
}


const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
class MainThread : Runnable {
    override fun run() { main() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 34736
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>

using namespace std;
const int N = 200005;
const int M = 1000005;
int a[N];
int num[M];
int main()
{
	int n;
	scanf("%d", &n);
	int mx = 0;
	for (int i = 1; i <= n; ++i)
	{
		scanf("%d", &a[i]);
		++num[a[i]];
		mx = max(mx, a[i]);
	}

	sort(a + 1, a + n + 1);

	int res = 0;
	for (int i = 1; i <= n; ++i)
	{
		int q = a[i];
		if (num[a[i]] == 0) continue;
		for (int j = 2 * q; j <= mx; j += q)
		{
			num[j] = 0;
		}
		if (num[q] == 1) ++res;
	}

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

	return 0;
}

Measured memory_bytes: 8436
s=input()
if s[0]==">":s="<"+s
if s[-1]=="<":s=s+">"
tmps="<"
tmp1,tmp2=0,0
ans=0
for i in s:
    if tmps=="<":
        if i=="<":
            tmp1+=1
        else:
            tmps=i
            tmp2+=1
    else:
        if i==">":
            tmp2+=1
        else:
            ans+=tmp1*(tmp1+1)//2+tmp2*(tmp2+1)//2-min(tmp1,tmp2)
            tmp1,tmp2=1,0
            tmps=i
ans+=tmp1*(tmp1+1)//2+tmp2*(tmp2+1)//2-min(tmp1,tmp2)
print(ans)

Measured memory_bytes: 46320
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef vector<int> vec;
int main(){
  long a,ans=0; cin>>a;
  ans=a/500*1000;
  a=a%500;
  ans+=a/5*5;
  cout<<ans;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = 998244353;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int n, m, mini = IINF;
vector<vector<int> > g;
vector<int> ans;

void bfs(int s){
    vector<int> d(n, IINF/2), rev(n, -1);
    queue<int> que;
    for(auto v : g[s]){
        que.push(v);
        d[v] = 1;
    }
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for(auto u : g[v]){
            if(d[u] > d[v]+1){
                d[u] = d[v]+1;
                rev[u] = v;
                que.push(u);
            }
        }
    }
    if(d[s] == IINF/2) return;
    if(d[s] < mini){
        mini = d[s];
        ans.clear();
        for(int v = s; v != -1; v = rev[v]){
            ans.push_back(v);
        }
    }
}

int main(){
    cin >> n >> m;
    g.resize(n);
    for(int i=0;i<m;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
    }
    for(int i=0;i<n;i++){
        bfs(i);
    }
    if(!ans.empty()){
        cout << ans.size() << endl;
        for(auto v : ans){
            cout << v+1 << endl;
        }
    }
    else{
        cout << -1 << endl;
    }
    return 0;
}


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

using namespace std;
int main()
{

    int n;
    cin>>n;
    vector<int> c(n);
    int k;
    for(int i=0; i<n; i++)
    {
        cin>>k;
        c[i] = k;
    }
    vector<int> dp(n);
    dp[0]=0;
    dp[1] = abs(c[1]-c[0]);

    for(int i=2; i<n; i++)
        dp[i] = min(abs(c[i]-c[i-1])+dp[i-1], abs(c[i]-c[i-2])+dp[i-2]);
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <set>
#include<vector>
using namespace std;
int main(void){
    
    set<int> st;
    int a,b,k;
    cin>>a>>b>>k;
    for(long int i=a;i<=min(a+k-1,b);i++)st.insert(i);
    for(long int i=b;i>=max(b-k+1,a);i--)st.insert(i);
    for(auto x : st)cout<<x<<endl;
    
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin>>a>>b;
   if(a<b){
           cout<<"a < b"<<endl;
          }
    else if(a>b){
           cout<<"a > b"<<endl;
          }
    else  {
           cout<<"a == b"<<endl;
    }      
}



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

int s, n, t, m, p;

bool minutes[7 * 24 * 60];

int wbits, tbits;

double ck(int start){
  int cnt = 0;
  for(int i = 0; i < m; i++, start += t){
    bool flag = true;
    for(int j = 0; j <= s; j++){
      if(!minutes[(start + j) % (7 * 24 * 60)]){
        flag = false;
        break;
      }
    }
    cnt += flag;
  }
  return( 1.0 - pow( 1.0 - 1.0/p, (double)cnt * n));
}


inline int todays(int i){
  return(i / (24 * 60));
}
inline bool totime(int i){
  int tm = i % (24 * 60) / 24;
  return(tm >= 18 || tm < 6);
}

int main(){
  string weekday, time ;
  while( cin >> s >> n >> t >> weekday >> time >> p >> m, m){
    if(weekday == "All") wbits = (1 << 7) - 1;
    else wbits = 1 ;
    if(time == "Night") tbits = 1;
    else if(time == "Day") tbits = 2;
    else tbits = 3; 

    double ans = 0.0;
    for(int i = 7 * 24 * 60 - 1; i >= 0; i--){
      minutes[i] = 
        wbits >> todays(i) & 1 && (tbits & (1 << ((i/360+1)%4/2)));
    }

    for(int i = 24 * 60 - 1; i >= 0; i--){
      ans = max( ans, ck(i));
    }
    cout << fixed << setprecision(16) << ans << endl;
  }
}

Measured memory_bytes: 1340
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	n <- readInt
	as <- replicateM n readInt
	let
		left = scanl max 0 as
		right = tail $ scanr max 0 as
	mapM_ print $ zipWith max left right

Measured memory_bytes: 94972
<?php
list($q, $h, $s, $d) = ints();
list($n) = ints();
$min2l = min($q * 8, $h * 4, $s * 2, $d);
$min1l = min($q * 4, $h * 2, $s);
echo intdiv($n, 2) * $min2l + ($n % 2) * $min1l;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16276
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
	char s=getchar();
	int tot=0;
	while(s>='0'&&s<='9'){
		tot+=s-'0';
		s=getchar();
	}
	if(tot%9==0) printf("Yes");
	else printf("No");
	return 0;
} 

Measured memory_bytes: 1600
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
char s[N];
int main()
{
    scanf("%s",s+1);
    int ans=1,pre=1,n=strlen(s+1);
    for(int i=2;i<=n;i++)
    {
        if(s[i]==s[i-1]&&pre==1)
        {
            if(i==n) break;
            ans++;i++;pre=2;
        }
        else ans++,pre=1;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
#include<stack>
using namespace std;
stack<char> s[4];
stack<char> ans;
string z;
int main(){
	while(cin>>z&&z!="-"){
		for(int i=0;i<3;i++){
			for(int j=z.size()-1;j>=0;j--)s[i].push(z[j]);
			if(i!=2)cin>>z;
		}
		while(!s[1].empty()){
			if(s[2].empty())goto loop;
			if(s[1].top()==s[2].top()){
				s[1].pop(),s[2].pop(),s[1].push(s[0].top()),s[0].pop();
			}
			else{
				loop:
				s[3].push(s[1].top()),s[1].pop();
			}
		}
		while(!s[3].empty()){
			ans.push(s[3].top());
			s[3].pop();
		}
		while(!ans.empty()){
			cout<<ans.top();
			ans.pop();
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3136
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())

    red = [list(map(int, readline().split())) for _ in range(n)]
    blue = [list(map(int, readline().split())) for _ in range(n)]

    from operator import itemgetter

    red.sort()
    blue.sort()

    ans = 0

    for bx, by in blue:
        ry_max = -1
        r_idx = -1

        for ri, ele in enumerate(red):
            rx = ele[0]
            ry = ele[1]
            if rx < bx and ry < by:
                if ry > ry_max:
                    ry_max = ry
                    r_idx = ri

        if r_idx != -1:
            del red[r_idx]
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
int N;
  cin >> N;
  int a, b, c;
  c = N%10;
  b = (N-c)/10%10;
  a = (N-10*b-c)/100;
  if(a == 7){
  cout << "Yes" << endl;
  }
  else if(b == 7){
  cout << "Yes" << endl;
  }
  else if(c == 7){
  cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
  }
return 0;
}

Measured memory_bytes: 3596
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,x = readInts()
L = readInts() + [0]
cnt = 0
now = 0
for i in range(n+1):
    if now <= x:
        cnt += 1
        now += L[i]
    else:
        break
print(cnt)


Measured memory_bytes: 10440
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int n; 
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int alice=0;
  int bob=0;
  sort(a,a+n,greater<int>());
  for(int i=0;i<n;i++){
    if(i%2==0) alice+=a[i];
    else bob+=a[i];
  }
  cout<<alice-bob<<endl;
  return 0;
}

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

static const int MOD = 1000000007;

int n;
string s;
int dp[100005][13];

int main() {
    cin >> s;
    n = s.size();
    for (int i = 0; i < 13; i++) dp[0][i] = 0;
    if (s[0] == '?') {
        for (int i = 0; i < 10; i++) {
            dp[0][i] = 1;
        }
    }
    else {
        int c = s[0] - '0';
        dp[0][c] = 1;
    }
    for (int i = 1; i < n; i++) {
        if (s[i] == '?') {
            for (int j = 0; j < 10; j++) {
                for (int k = 0; k < 13; k++) {
                    int d = (j + k * 10) % 13;
                    dp[i][d] += dp[i-1][k];
                    dp[i][d] %= MOD;
                }
            }
        }
        else {
            int c = s[i] - '0';
            for (int k = 0; k < 13; k++) {
                int d = (c + k * 10) % 13;
                dp[i][d] += dp[i-1][k];
                dp[i][d] %= MOD;
            }
        }
    }
    cout << dp[n-1][5] << endl;
    return 0;
}

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

typedef long long int ll;

int main(){
   ll N,A,B;
   cin >> N >> A >> B;
   if(A > B || (N == 1 && A != B)){
      cout << 0 << endl;
      return 0;
   }
   if(N == 2){
      cout <<  1 << endl;
   }else{
      cout << (B-A) * (N-2) + 1<< endl;
   }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,string>;
using Map = map<string,ll>;



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

    vector<ll> A(N+1,0);
    vector<ll> ans(N+1,0);
    for(int i=1;i<N+1;i++){
        cin>>A[i]
    ;}
    ll counter=0;
    for(int i=N;i>0;i--){
        ll sum=0;
        for(int j=i*(N/i);j>i;j-=i){
            sum+=ans[j]
        ;}
        ans[i]=(sum+A[i])%2;
        if(ans[i]==1)counter++;
    ;}
    cout<<counter<<endl;
    for(int i=1;i<N+1;i++){
        if(ans[i]==1){cout<<i<<" ";}
    ;}
    cout<<endl;


return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b,ans;
int main(){
	cin>>n>>a>>b;
	if(a>b)swap(a,b);
	if(a%2==b%2){
		ans=(b-a)/2;
	}else{
		ans=min((a+b)/2,(n-a+1+n-b+1)/2);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
using namespace std;
int main(){
  int a,b,ans=0;
  cin>>a>>b;
  rep(i,0,2){
    if(a>=b){
      ans+=a;
      --a;
      continue;
    }
    if(a<b){
      ans+=b;
      --b;
      continue;
    }
  }
  ou(ans);
}

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

signed main(void)
{
	string s;
	long long ans;
	int cnt;
	cin >> s;
	ans = cnt = 0;
	rep(i, s.size())
	{
		if (s[i] == 'W')
			ans += cnt;
		else
			cnt++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>

using namespace std;

int main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    int min1,min2;
    if(A<B){
        min1=A;
    }else{
        min1=B;
    }
    if(C<D){
        min2=C;
    }else{
        min2=D;
    }
    cout<<min1+min2<<endl;
    return 0;
}

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

int linearSearch( int s[], int nums, int t ){
	
	int i=0;
	while( s[i] != t )  //??????(s[s.size] ???t ?????\??£??????????????§????????????????????????for????????????????????????
		i++;
	return i != nums;
}

int main()
{
	int *s, *t;
	int nums, numt;
	cin>>nums;
	s=new int[nums+1];
	for( int i=0; i<nums; i++ ){
		cin>>s[i];
	}

	cin>>numt;
	t=new int[numt];
	for( int i=0; i<numt; i++ ){
		cin>>t[i];
	}


	int ans=0;

	for( int i=0; i<numt; i++ ){
		s[nums]=t[i];
		ans +=linearSearch(s, nums, t[i]);

	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1760
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
  int n;
  cin >> n;
  
  vector<int> xs(n);
  
  int result = 0;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    xs[a-1] = i;
  }
  
  for (int i = 0; i < n; i++) {
    cout << xs[i] << (i<(n-1) ? " " : "");
  }
  cout << endl;
}


Measured memory_bytes: 1152
#2019/10/03
# a, b, c, d, e, k = list(map(int, open(0).read().split()))
# print("Yay!" if (b-a<=k and c-a<=k and d-a<=k and d-a<=k and e-a<=k and c-b<=k and d-b<=k and e-b<=k and d-c<=k and e-c<=k and e-d<=k) else ":(") )

antn = list(map(int, open(0).read().split()))
flg = 0
for i in range(0,4):
#    print(i,j)
    j=0
    for j in range(i+1, 5):
        if (antn[j] - antn[i] > antn[5]):
            flg = 1
print("Yay!" if flg == 0 else ":(")

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<deque>
using namespace std;
using ll = long long int;

int n, k;
deque<ll> x;

ll sum(int left, int right) {
	ll xl = x[left], xr = x[right];
	ll ret = xr - xl;
	return min(ret + abs(xl), ret + abs(xr));
}

int main(void) {
	cin >> n >> k;
	ll ksum = 0;
	for (int i = 0; i < n; i++) {
		ll xi;
		cin >> xi;
		x.push_back(xi);
		if (i >= k) {
			if (x.front() < 0 && xi <= 0)
				x.pop_front();
			if (x[i - k] >= 0 && xi > 0) {
				x.pop_back();
				break;
			}
		}
	}

	ksum = sum(0, x.size() - 1);
	for (int i = 0; i < x.size() - k + 1; i++) {
		ll tmp = sum(i, i + k - 1);
		if (tmp < ksum)
			ksum = tmp;
	}
	cout << ksum << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>

using namespace std;
using pii=pair<int,int>;
using ll=long long;

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

    int n;
    cin>>n;
    vector<int> v(n);
    int max1=0,max2=0;
    for(int i=0; i<n; i++){
        cin>>v[i];
        if(max1<v[i]){
            max2=max1;
            max1=v[i];
        }
        else if(max2<v[i]) max2=v[i];
    }
    for(int i=0; i<n; i++){
        if(max1==v[i]) cout<<max2<<"\n";
        else cout<<max1<<"\n";
    }

    return 0;
}


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

using namespace std;

using Int = long long;
using P = pair<int, int>;

const long long MOD = 1e9 + 7;
const int INF = 1e9;
const double EPS = 1e-9;

int main() {
  int N;
  cin >> N;
  cout << N * N * N << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <set>
#include <sstream>
#include <algorithm>
#include <fstream>
#include <deque>
using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()

const int inf = (int)1e9;
const int mod = inf+7;
	
int n, a, b;
string s;

int main(){

	cin >> n >> s;
	string t = "";

	for(int i=0;i<n;i++){
		char c = s[i];
		if(c == '('){
			a++;
			t+='(';
		}else{
			if(a>0){
				t+=')';
				a--;
			}else{
				t = '(' + t + ')';
			}
		}
	}
	cout << t;
	for(int i=0;i<a;i++){
		cout << ')';
	}


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a<b){
        if(b<c){
            printf("%d %d %d\n",a,b,c);
        }
        else if(c<a){
            printf("%d %d %d\n",c,a,b);
        }
        else{
            printf("%d %d %d\n",a,c,b);
        }
    }
    else if(b<a){
        if(a<c){
            printf("%d %d %d\n",b,a,c);
        }
         else if(c<b){
             printf("%d %d %d\n",c,b,a);
         }
         else{
             printf("%d %d %d\n",b,c,a);
         }
    }
    
    return 0;

    
}



Measured memory_bytes: 2044
#include <stdio.h>
long abs(long);
int main(){
  int n,h[100000],dp[100000],f1,f2;
  scanf("%d",&n);
  for (int i=0;i<n;i++) scanf("%d",&h[i]);
  dp[0]=0;
  dp[1]=abs(h[0]-h[1]);
  for (int i=2;i<n;i++){
    f1=dp[i-1]+abs(h[i]-h[i-1]);
    f2=dp[i-2]+abs(h[i]-h[i-2]);
    if (f1>f2) dp[i]=f2;
    else dp[i]=f1;
  }
  printf("%ld\n",(long)dp[n-1]);
  return 0;
}
long abs(long num){
  if (num<0) num=-num;
  return num;
}

Measured memory_bytes: 896
import numpy as np
n = input()
n = int(n)
ls = input()
ls = ls.split()
for i in range(n):
  ls[i] = int(ls[i])


M = np.argmax(ls)
if (ls[M] < (sum(ls)-ls[M])):
    print("Yes")        
else:
    print("No")


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

int main() {
  string s;
  int count = 0;
  cin >> s;
  
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'x') {
    count++;
    }
  }
  
  if (count<8) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18 
 
using namespace std;
 
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int x,y,a,b,c,i;
    cin>>x>>y>>a>>b>>c;
    vi A(a),B(b),C(c);
    for(i=0;i<a;i++) cin>>A[i];
    for(i=0;i<b;i++) cin>>B[i];
    for(i=0;i<c;i++) cin>>C[i];
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    for(i=a-1;i>=a-x;i--) C.pb(A[i]);
    for(i=b-1;i>=b-y;i--) C.pb(B[i]);
    sort(C.begin(),C.end());
    int n=C.size();
    int ans=0;
    for(i=n-1;i>=n-(x+y);i--) ans+=C[i];
        cout<<ans;
}

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

int main() {
  int d[] = {105, 135, 165, 189, 195};
  int n;
  std::cin >> n;
  int count = 0;
  for (const auto i : d) {
    if (i <= n) {
      count++;
    }
  }

  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
int m[101][101];


void min(int n,int *p){

  int i,j,k,l;
  for(i=1;i<=n;i++) m[i][i]=0;

  for(l=2;l<=n;l++) {
    
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=100000000;
      
      for(k=i;k<=j-1;k++){
    if(m[i][j]>m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]){
      m[i][j]=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
    }
      }
    }
  }
}

    
int main(){

  int i,p[N+1],n;

  scanf("%d",&n);
  for(i=1;i<=n;i++) scanf("%d%d",&p[i-1],&p[i]);

  min(n,p);

  printf("%d\n",m[1][n]);

  return 0;

}

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

using namespace std;

/*---------------------------------------------------*/
/* 0 : pushBack                                      */
/* 1 : dump                                          */
/* 2 : clear                                         */
/*---------------------------------------------------*/

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

  std::vector< std::vector<int> > vv(n);

  int order;
  int num;
  int t;

  for(int i=0; i<q; ++i){
    cin >> order;

    if(order == 0){
      cin >> t >> num;
      vv[t].push_back(num);      // Vector[t]の末尾にnumを追加
    }

    else if(order == 1){
      cin >> t;
      for(int j=0; j<vv[t].size(); ++j){
        if(!vv[t].empty()){
          cout << vv[t][j];  // Vector[t]全ての要素を出力
          if(j!=vv[t].size()-1)cout << " ";
        }else cout << endl;
      }cout << endl;
    }

    else{
      cin >> t;
      vv[t].clear();             // 全要素削除
    }
  }
  return 0;
}



Measured memory_bytes: 5776
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	
	using namespace std;
	int main()
	{
      double ans;
double n,k;
cin >> n>>k;
double t;
ans =0;
double j=1;

for(int i=1;i<n+1;i++){
  j=1;
 for(;i*j<k;){
  j=j*2;
}
t=1/(j*n);
 ans=ans+t;
}

cout << std::setprecision(10) <<ans;
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct Random_Number_Generator{
    mt19937_64 mt;

    Random_Number_Generator() : mt(chrono::steady_clock::now().time_since_epoch().count()) {}

    int64_t operator () (int64_t l, int64_t r){
        uniform_int_distribution<int64_t> dist(l, r-1);
        return dist(mt);
    }

    int64_t operator () (int64_t r){ 
        return (*this)(0, r);
    }
};

ll c[26], a[365][26];
ll res = 0, sum = 0;
vector<int> ans(365), now(365);
set<int> s[26];

ll insert(int d, int q){
    ll ret = a[d][q];
    s[q].insert(d);
    set<int>::iterator it1 = s[q].find(d), it2 = it1;
    int l = *--it1, r = *++it2;
    ret += c[q]*(r-l)*(r-l-1)/2;
    ret -= c[q]*((d-l)*(d-l-1)/2 + (r-d)*(r-d-1)/2);
    s[q].erase(d);
    return ret;
}

ll remove(int d, int q){
    ll ret = -a[d][q];
    set<int>::iterator it1 = s[q].find(d), it2 = it1;
    int l = *--it1, r = *++it2;
    ret += c[q]*((d-l)*(d-l-1)/2 + (r-d)*(r-d-1)/2);
    ret -= c[q]*(r-l)*(r-l-1)/2;
    return ret;
}

ll eval(int d, int q){
    return insert(d, q) + remove(d, now[d]);
}

void change(int d, int q){
    s[q].insert(d), s[now[d]].erase(d);
    now[d] = q;
}

int main(){
    int D;
    cin >> D;
    rep(i, 26){
        cin >> c[i];
        s[i].insert(0), s[i].insert(D+1);
    }
    rep(i, D){
        rep(j, 26) cin >> a[i][j];
    }
    Random_Number_Generator rnd;

    rep(i, D) now[i] = rnd(26);
    copy(all(now), ans.begin());

    int T = 100000;
    double start_temp = 3000, end_temp = 0;
    rep(t, T){
        ll M = -INF;
        int d = rnd(D), q = 0;
        rep(i, 26){
            if(i == now[d]) continue;
            if(chmax(M, eval(d, i))) q = i;
        }
        double temp = start_temp+(end_temp-start_temp)*t/T;
        double p = exp(M/temp);
        if(p > (rnd(INF)%INF)/double(INF)){
            change(d, q);
            sum += M;
            if(chmax(res, sum)) copy(all(now), ans.begin());
        }
    }

    rep(i, D) cout << ans[i]+1 << endl;
}

Measured memory_bytes: 4332
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String r =s.next();
		String g =s.next();
		String b =s.next();

		String an = r+g+b;
		int ans = Integer.parseInt(an);

		if(ans%4==0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}





	}

}

Measured memory_bytes: 21204
n, q = map(int, input().split())
s = input()
a = []
for i in range(q):
    a.append(list(map(int, input().split())))
lis = [[0, 0]]
count = 0
for i in range(n):
    if s[i] == 'A':
        if i+1 <= n-1 and s[i+1] == 'C':
            count += 1
    lis.append([i+1, count])
for i in range(q):
    l = a[i][0] - 1
    r = a[i][1] - 1
    print(lis[r][1] - lis[l][1])




Measured memory_bytes: 40384
extern crate core;

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    let mut iter = input.split("\n");
    let n = iter.next().unwrap().parse::<usize>().unwrap();
    let list = iter
        .take(n)
        .map(|x| {
            let mut iter = x.split_whitespace().map(|x| x.parse::<i64>().unwrap());
            (iter.next().unwrap(), iter.next().unwrap())
        })
        .collect::<Vec<_>>();
    list.into_iter()
        .max_by_key(|&(a, _)| a)
        .map(|(a, b)| a + b)
        .unwrap()
        .to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "3\n4 7\n2 9\n6 2" => "8",
    test2: "5\n1 10\n3 6\n5 2\n4 4\n2 8" => "7",
    test3: "2\n1 1000000000\n1000000000 1" => "1000000001",
}


Measured memory_bytes: 12540
package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var m, k int
	fmt.Scan(&m, &k)
	n := int(math.Pow(2.0, float64(m)))
	if n == 2 && k == 1 {
		fmt.Println(-1)
		return
	}
	if n <= k {
		fmt.Println(-1)
		return
	}

	ans := make([]int, 0)
	for i := 0; i < n; i++ {
		if i == k && k != 0 {
			continue
		}
		ans = append(ans, i)
	}
	if k != 0 {
		ans = append(ans, k)
	}

	for i := n - 1; i >= 0; i-- {
		if i == k && k != 0 {
			continue
		}
		ans = append(ans, i)
	}
	if k != 0 {
		ans = append(ans, k)
	}

	str := fmt.Sprintf("%v", ans)
	str = strings.Trim(str, "[]")
	fmt.Println(str)
}


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

stack<int> st;
int n, a, cnt = 0;

int main() {
  int i;
  cin >> n;
  st.push(0);
  for(i = 0; i < n; ++i) {
    cin >> a;
    while(st.top() > a) st.pop();
    if(st.top() < a) {
      ++cnt;
      st.push(a);
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3468
#include <stdio.h>
int main(){
  long long int k,i,n=0;
  scanf("%lld",&k);
  
  for(i=1; i<=100000000;i++){
    n=10*n+7;
    n=n%k;
    if(n==0){
      printf("%lld",i);
      return 0;
    }
  }
  printf("-1");
  return 0;
}


Measured memory_bytes: 1708
n=gets.to_i
ba,bs,sa,result=0,0,0,0
n.times do 
  s=gets.chomp
(s.size-1).times do |i|
  if s[i]=="A" && s[i+1]=="B"
    result+=1
  end
end
ba+=1 if s[0]=="B" && s[-1]=="A"
bs+=1 if s[0]=="B" && s[-1]!="A"
sa+=1 if s[0]!="B" && s[-1]=="A"
end
if ba==0
  if bs>sa
    result+=sa
  else
    result+=bs
  end
else
    if bs==0&&sa==0
		result+=(ba-1)
	elsif bs>sa
  		result+=ba+sa
	else
  		result+=ba+bs
	end
end
puts result

Measured memory_bytes: 1788
def is_prime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    x = 3
    while x * x <= n:
        if n % x == 0:
            return False
        x += 2
    return True


X = int(input())
while not is_prime(X):
    X += 1
print(X)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int a[32] = {1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
int main(){
int k;
cin >> k;
cout << a[k - 1] << endl;
}


Measured memory_bytes: 256
n,l = gets.split.map(&:to_i)
array=[]
array_abs=[]
(1..n).each do |i|
  array.push(l+i-1)
end

array.each do |a|
  array_abs.push(a.abs)
end

ary = [array_abs, array].transpose

ary = ary.sort {|a,b| a[0] <=> b[0]}

ary.delete_at(0)

sum=0
ary.each do |a|
  sum+=a[1]
end

p sum



Measured memory_bytes: 1788
#include <algorithm>
#include<iostream>
#include<vector>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using namespace std;

struct position{
  long ee;
  long ew;
  long we;
  long ww;
};

enum Direction{
  West,
  East
};
  
long getChangeNum(int pos,vector<Direction> vec){
  int ii;
  int changeNum = 0;;
  for(ii=0;ii < pos - 1;ii++){
	if(vec[ii] == West){
	  changeNum ++;
	}
  }

  for(ii=pos+1; ii<vec.size();ii++){
	if(vec[ii] == East){
	  changeNum++;
	}
  }
  return changeNum;
}
				  
int main(){
  long n;
  string str;
  //char c;
  long ii;
  vector<Direction> pos;
  vector<struct position> pos2;
  long min = LONG_MAX,ret;
  cin >> n >> str;

  pos.resize(n);
  pos2.resize(n);
  
  for(char c : str){
	//cout << c << endl;
	if(c == 'W'){
	  pos[ii] = West;
	}
	else{
	  pos[ii] = East;
	}
	ii++;
  }

  //for(ii=0;ii<n;ii++){
  //	ret = getChangeNum(ii,pos);
  //	if(ret < min){
  //	  min = ret;
  //	}
  //}
  struct position pos3;
  struct position cur;
  pos3.ee = 0;
  pos3.ew = 0;
  pos3.we = 0;
  pos3.ww = 0;
  for(ii=0;ii<n;ii++){
	if(pos[ii] == East){
	  pos3.ee++;
	}
	else{
	  pos3.ew++;
	}
  }

  //0番目
//  if(pos[0] == West){
//	cur.w
//  }
//  else{
//
//  }
//  cout << "ee:" << pos3.ee << "ew:" << pos3.ew << endl;
  long changeNum;
  //long min;
  for(ii=0;ii<n;ii++){
	//自分の位置を除く
	if(pos[ii] == East){
	  cur.ee = pos3.ee -1;
	  cur.ew = pos3.ew;
	  cur.we = pos3.we;
	  cur.ww = pos3.ww;
	}
	else{
	  cur.ee = pos3.ee;
	  cur.ew = pos3.ew - 1;
	  cur.we = pos3.we;
	  cur.ww = pos3.ww;
	}

	pos2[ii] = cur;
	changeNum = cur.ww + cur.ee;
	//cout << "ww:" << cur.ww << "ee:" << cur.ee << "" << endl;
	if(changeNum < min){
	  min = changeNum;
	}
	//次の位置の計算
	
	if(pos[ii] == East){
	  pos3.ee = pos3.ee -1;
	  pos3.we = pos3.we + 1;

	  pos3.we = pos3.we;
	  pos3.ww = pos3.ww;

	}
	else{

	  pos3.ew = pos3.ew - 1;
	  pos3.ww = pos3.ww + 1;

	  pos3.ee = pos3.ee;
	  pos3.we = pos3.we;
	}

  }

  
  cout << min << endl;
  return 0;
}


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

using namespace std;


bool cmp(const int &p1, const int &p2) {
	return p1 > p2;
}

int main() {
	int n, m, sum;
	int price[1000];

	while (cin >> n >> m, n) {
		memset(price, 0, sizeof(price));
		for (int i = 0; i < n; ++i) {
			cin >> price[i];
		}
		sort(price, price + n,cmp);
		
		sum = 0;
		for (int i = 0; i < n; ++i) {
			//cout << price[i] << " ";
			if ((i + 1) % m == 0) {
				price[i] = 0;
			}
			sum += price[i];
		}
		cout << sum << endl;
	}

	return 0;
}


Measured memory_bytes: 3080
import java.util.Scanner;

public class Main{
        public static void main(final String[] args){
            final Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            if(a < b){
                if(c < a){
                    System.out.println(c + " " + a + " " + b);
                }else if(b < c){
                    System.out.println(a + " " + b + " " + c);
                }else {
                    System.out.println(a + " " + c + " " + b);
                }
            }else{
                if(c < b){
                    System.out.println(c + " " + b + " " + a);
                }else if(a < c){
                    System.out.println(b + " " + a + " " + c);
                }else {
                    System.out.println(b + " " + c + " " + a);
                }
            }
            sc.close();
        }


}




Measured memory_bytes: 26124
import java.util.Scanner;




public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);

    	int H=sc.nextInt();
    	int W=sc.nextInt();


    	for(int i=0;i<H;i++) {
    		String buf=sc.next();

    		System.out.println(buf);
    		System.out.println(buf);
    	}
    }
}



Measured memory_bytes: 22868
# 夏休みN日
# 宿題M
# i番目の宿題をやるにはAi日間かかります。

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

S = 0

for i in range(M):
  S += A[i]
  
R = N - S

if R < 0:
  print(-1)
else:
  print(R)



Measured memory_bytes: 9932