akhauriyash/Code-Regression huggingface dataset:
package main
import(
  "fmt"
)

func main(){
  var s string
  fmt.Scanf("%s",&s)
  switch s {
	case "SUN":
    	fmt.Print("7");
	case "MON":
    	fmt.Print("6")
    case "TUE":
    	fmt.Print("5")
    case "WED":
    	fmt.Print("4")
    case "THU":
    	fmt.Print("3")
    case "FRI":
    	fmt.Print("2")
    case "SAT":
    	fmt.Print("1")
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<int>> a(n, vector<int>(m+1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= m; j++) {
      cin >> a[i][j];
    }
  }

  int min = 10000000;
  for (int is = 0; is < 1<<n; is++) {
    vector<int> b(m+1);
    for (int i = 0; i < n; i++) {
      if (is>>i&1) {
        for (int j = 0; j <= m; j++) b[j] += a[i][j];
      }
    }
    bool t = true;
    for (int k = 1; k <= m; k++) {
      if (b[k] < x) t = false;
    }
    if (t && b[0] < min) min = b[0];
  }

  if (min == 10000000) cout << -1 << endl;
  else cout << min << endl;

  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define make_pair mp
#define pii pair<int,int>
using namespace std;
typedef long long ll;
const int maxn=100007;
const int inf=(1LL<<29);
char s[maxn];
ll num[27];
const int mod=1e9+7;
int main(){
    int len;cin>>len;
    scanf("%s",s+1);
    for(int i=1;i<=len;i++){
        num[s[i]-'a']++;
    }
    ll ans=1;
    for(int i=0;i<26;i++){
        ans*=(1+num[i]);ans%=mod;
    }
    cout<<ans-1;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

int n, w;
ll weight[102], value[102];
ll dp[102][100002];

// dp[i][j] = max value we can get if we take at most weight j and last item
// visited was i
// dp[0][0] = 0

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> w;
    FOR(i, 1, n + 1) { cin >> weight[i] >> value[i]; }
    dp[0][0] = 0;
    FOR(i, 1, n + 1) {
        FOR(j, 0, w + 1) {
            if (j - weight[i] >= 0) {
                dp[i][j] =
                    max(dp[i - 1][j], dp[i - 1][j - weight[i]] + value[i]);
            } else {
                dp[i][j] = dp[i - 1][j];
            }
            // cout << i << ' ' << j << ' ' << dp[i][j] << '\n';
        }
    }
    cout << dp[n][w] << '\n';
    return 0;
}

Measured memory_bytes: 78464
#include <iostream>
#include <cstdio>
using namespace std;
#define OVER_SIX_DIGITS 1000000

int prime[OVER_SIX_DIGITS];

void make_prime(void) {
    for(int r = 0; r < OVER_SIX_DIGITS; r++) prime[r] = 1;
    prime[0] = prime[1] = 0;
    
    for(int r = 2; r < OVER_SIX_DIGITS; r++) {
        if(prime[r]) {
            for(int c = 2 * r; c < OVER_SIX_DIGITS; c += r) prime[c] = 0;
        }
    }
    //累積和配列を作成
    for(int r = 1; r < OVER_SIX_DIGITS; r++) prime[r] += prime[r - 1];
}

int main(void) {
    int n;
    make_prime();
    while(cin >> n) {
        cout << prime[n] << endl;
    }
    return(0);
}

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    for(ll i=k;i<=n+1;i++){
        ll l=i*(i-1)/2;
        ll r=n*(n+1)/2-(n-i)*(n-i+1)/2;
        (ans+=(r-l+1)%MOD)%=MOD;
    }
    cout<<ans<<en;
}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 3644
N=gets.to_i
ans=0
c1,c2,c3,c4=0,0,0,0
N.times do
  s=gets.chomp
  ans += s.scan(/AB/).size
  if s.match(/^B.*A$/)
    c1+=1
  elsif s.match(/A$/)
    c2+=1
  elsif s.match(/^B/)
    c3+=1
  else
    c4+=1
  end
end

if c2>0 || c3>0
  ans += [c2,c3].min + c1
elsif c1>0
  ans+=c1-1
end
puts ans


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    if (s.size() > 3 && s.substr(0, 4) == "YAKI") cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        String btw = str.substring(1, str.length() - 1);
        System.out.println(str.substring(0, 1) + btw.length() + str.substring(str.length() - 1, str.length()));
    }

}


Measured memory_bytes: 22612
A, B = map(int, input().split())

h, w = 100, 100
board = [["."] * 100 for i in range(100)]
#print(board)
for i in range(50):
  for j in range(100):
    board[i][j] = "#"
#print(board)

l, r = 0, 0
while A > 1:
  A -= 1
  board[l][r] = "."
  r += 2
  if r == 100:
    l += 2
    r = 0

l, r = 99, 99 
while B > 1:
  B -= 1
  board[l][r] = "#"
  r -= 2
  if r == 1:
    l -= 2
    r = 99
print(h,w)
for i in range(100):
  for j in range(100):
    print(board[i][j], end = "")
  print("")
  


Measured memory_bytes: 9432
//  Created by Vignesh Manoharan

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <cstring>
#include <cassert>

using namespace std;

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

const int INF = 1000000000;
const ll LINF = 1e17;
const double PI =3.141592653589793238;
#pragma unused(INF,PI,LINF)
#define F(i,a,n) for(int i=(a);i<(n);i++)

template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){
    for(int i=0;i<(t).size();i++)s<<t[i]<<((i<(t).size()-1)?" ":"");return s; }
template<typename T> ostream& operator<<(ostream &s,set<T> t){for(T x:t) s<<x<<" ";return s; }
template<typename T> istream& operator>>(istream &s,vector<T> &t){
    for(int _i=0;_i<t.size();_i++) s>>t[_i];return s; }

#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()

const int MAXN=10010;
int parent[MAXN];
int root(int v){return parent[v] < 0 ? v : (parent[v] = root(parent[v]));}
void merge(int x,int y){	//	x and y are some vertices
    if((x = root(x)) == (y = root(y)))
       return ;
    if(parent[y] < parent[x])	// balancing the height of the tree
       swap(x, y);
    parent[x] += parent[y];
    parent[y] = x;
}

int main(int argc, const char * argv[]) {
#ifdef local_test
    //    input
    //    freopen("input","w",stdout);
    //    cout<<"1 \n 100 10 \n";
     freopen("input","r",stdin);
     freopen("output","w",stdout);
#endif
    int n,q;
    cin>>n>>q;
    F(i,0,n) parent[i]=-1;
    F(i,0,q){
        int com,x,y;
        cin>>com>>x>>y;
        if(com==0){
            merge(x,y);
        } else {
            cout<<(root(x)==root(y))<<"\n";
        }
    }
}

Measured memory_bytes: 3112
///Happy copying <3

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <set>
#define ll long long
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int l,r,d,cnt=0,a=0;
    cin>>l>>r>>d;
    for(int i=1;; i++)
    {
        a=i*d;
        if(a>=l && a<=r)
            cnt++;
        else if(a>r)
            break;
    }
    cout<<cnt<<endl;


    return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acosl(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define MXN 200005

int main(){
    int hh,ww,h,w;
    scanf("%d %d %d %d",&hh,&ww,&h,&w);
    if(hh%h==0&&ww%w==0){
        printf("No\n");
    }
    else{
        printf("Yes\n");
        for(int i = 0;i<hh;i++){
            for(int j=0;j<ww;j++){
                if(i%h==0&&j%w==0){
                    printf("999999999 ");
                }
                else if(i%h==h-1&&j%w==w-1){
                    printf("-1000000000 ");
                }
                else{
                    printf("0 ");
                }
            }
            printf("\n");
        }
    }
}
/*

23847657 
23458792534

102334155
111111111 
111111111
*/

Measured memory_bytes: 2944
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;

#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using Int = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

void solve()
{
  ll n;
  cin >> n;
  ll sum1 = n * (n + 1) * (n + 2) / 6;
  ll sum2 = 0;
  rep(i, n - 1)
  {
    ll a, b;
    cin >> a >> b;
    if (a > b)
      swap(a, b);
    sum2 += a * (n - b + 1);
  }
  cout << sum1 - sum2 << "\n";
}

int main()
{
  init_main();
  solve();
}


Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int main(){
	int a,b,ans;
	cin>>a>>b;
	if((a+b)%2==0){
		ans=(a+b)/2;
	}
	if((a+b)%2!=0){
		ans=(a+b+1)/2;
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<stdio.h>
using namespace std;

int main(){

	string x;
	int a;
	int ans = 999;
	int num;

	cin >> x;

	a = x.length();

	for (int i = 0; i <= a - 2; i++) {

		num = stoi( x.substr(i, 3));

		ans = min(ans, abs(753 - num));

	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        String s1 = "";
        String s2 = "";
        s.nextLine();
        for(int i = 0; i < n; i++){
            s1 = s.nextLine();
            s2 = s.nextLine();
            System.out.println(findLongest(s1,s2));
        }
    }
    
    public static int findLongest(String x, String y){
    	//[row][col]
        int[][] arr = new int[x.length()+1][y.length()+1];
        //fill first row and first column with zeros
        for(int i = 0; i <= x.length(); i++) {
        	arr[i][0] = 0;
        }
        for(int i = 0; i <= y.length(); i++) {
        	arr[0][i] = 0;
        }
        //the number of rows is the length of y + 1
        int row = x.length()+1;
        int col = y.length()+1;
        //fill the rest of the array, from [1][1] to [x.length()][y.length()]
        for(int i = 1; i < row; i++) {
        	for(int j = 1; j < col; j++) {
        		if(x.charAt(i-1)==y.charAt(j-1)) {
        			arr[i][j] = 1 + arr[i-1][j-1];
        		}
        		else {
        			arr[i][j] = Math.max(arr[i-1][j],arr[i][j-1]);
        		}
        	}
        }
        return arr[x.length()][y.length()];
    } 
}


Measured memory_bytes: 64864
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    len_S = len(S)
    cnt = 0
    for i in range(len_S):
        for j in range(i+3,len_S):
            if j == i+3:
                mod = int(S[len_S-j-1:len_S-i])%3
            else:
                mod = (mod+int(S[len_S-j-1]))%3
            if mod == 0:
                _ = int(S[len_S-j-1:len_S-i])
                if _%673==0:
                    cnt += 1
                    break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


if __name__ == "__main__":
    #main()

    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 0
    mod_arr = [0] * 2019
    mod_arr[0] += 1

    num, dec = 0, 1
    for s in S[::-1]:
        num += int(s)*dec
        num %= 2019
        dec *= 10
        dec %= 2019
        mod_arr[num] += 1

    for i in range(2019):
        if mod_arr[i] > 0:
            cnt += mod_arr[i]*(mod_arr[i]-1)//2
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

const int M = 100000;

int n, m, p[M], y[M], r[M];
vector<pair<int, int>> v[M];

int main() {
	cin >> n >> m;
	inc(i, m) { cin >> p[i] >> y[i]; p[i]--; }
	
	inc(i, m) { v[p[i]].EB(y[i], i); }
	inc(i, n) { sort(ALL(v[i])); }
	inc(i, n) {
	inc(j, v[i].size()) {
		r[v[i][j].SE] = j;
	}
	}
	
	inc(i, m) {
		printf("%06d%06d\n", p[i] + 1, r[i] + 1);
	}
	
	return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <queue> 
using namespace std;
int V[100][100];
int d[100];
int t[100];
int n;
queue<int> qu;
void bfs()
{
	t[0] = 1;
	d[0] = 0;
	qu.push(0);
	while (!qu.empty())
	{
		int u = qu.front(); qu.pop();
		for (int i = 0; i < n; i++)
		{
			if (V[u][i] == 1 && t[i] == 0)
			{
				t[i] = 1;
				d[i] = d[u] + 1;
				qu.push(i);
			}
		}
		t[u] = 2;
	}
	return;
}

int main()
{
	int k, u, v;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			V[i][j] = 0;
		}
	}

	for (int i = 0; i < n; i++)
	{
		cin >> u >> k;
		for (int j = 0; j < k; j++)
		{
			cin >> v;
			V[u - 1][v - 1] = 1;
		}
	}

	for (int i = 0; i < n; i++)
	{
		d[i] = -1;
		t[i] = 0;
	}
	bfs();
	for (int i = 0; i < n; i++)
	{
		cout << i + 1 << " " << d[i] << endl;
	}
	return 0;
}

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

void Main()
{
  int n; string s;
  cin >> n; cin >> s;
  vector<int> appear(1000);
  rep(i,1000) {
    std::ostringstream ss;
	ss << std::setw(3) << std::setfill('0') << i << "\n";
	std::string snum(ss.str());
    int idx = 0;
    rep(j,n) {
      if (snum[idx] == s[j]) idx++;
    }
    if (idx == 3) appear[i] = 1;
  }
  int ans = 0;
  rep(i,1000) {
    if (appear[i] == 1) ans++;
  }
  cout << ans << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


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

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (n, m) = [int(e) for e in lines[0].split(' ')]
    a = [int(e) for e in lines[1].split(' ')]

    return (n, m, a)


def solve(n, m, a):

   
    result = n - sum(a)
    if result < 0:
        result = -1

    
    return result
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;
typedef unsigned long long ull;

#define F first
#define S second
#define en end()
#define bg begin()
#define rev reverse
#define mp make_pair
#define pb push_back
#define y1 y1234567890
#define um unordered_map                         
#define all(x) x.bg, x.en
#define sqr(x) ((x) * (x))
#define sz(x) (int)x.size()

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const double pi = acos(-1.0);
const double eps = (double)1e-9;

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

const int N = 105;

char c[N];
int n, ans, f[N][26];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//cin.tie(NULL);
	//cout.tie(NULL);
	//ios_base::sync_with_stdio(false);

	scanf("%s", c + 1);

	n = strlen(c + 1);

	ans = N;

	for (int j = 0; j < 26; j++) {
		int mx = 0;
		for (int i = 1; i <= n; i++) {
			if (c[i] - 'a' == j)
				f[i][j] = 0;
			else
				f[i][j] = f[i - 1][j] + 1;
			mx = max(mx, f[i][j]);
		}
		ans = min(ans, mx);
	}

	printf("%d", ans);

	return 0;
}


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

using namespace std;

int main() {

    int N;
    long int res = 0;

    cin >> N;
    for(int i = 1; i<=N; i++) {

        if((i%5 != 0) && (i%3 != 0)) {
            res += i;
        }

    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

struct shop {
  long long int v;
  long long int num;

  bool operator<(const shop &another) const {
        //メンバ変数であるnum1で比較した結果を
        //この構造体の比較とする
        return v < another.v;
    }
};

int main(void){
  long long int N, M;
  cin >> N >> M;

  vector<shop> l(N);

  for(int i = 0; i < N; i++)cin >> l[i].v >> l[i].num ;

  sort(l.begin(),l.end());
  int c = M;
  long long int ans = 0;

  for(int i = 0; i < N; i++){
    if(c > l[i].num){
      c -= l[i].num;
      ans += l[i].num * l[i].v;
    }
    else{
      ans += c * l[i].v;
      break;
    }
  }
  cout << ans << endl;

}



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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void compress(vector<int> &v,map<double,int>& zip){
    vector<double> x;
    rep(i,0,v.size()){
        x.emplace_back(v[i]-0.5);
        x.emplace_back(v[i]);
        x.emplace_back(v[i]+0.5);
    }
    sort(x.begin(),x.end());
    x.erase(unique(x.begin(),x.end()),x.end());
    rep(i,0,x.size()) zip[x[i]]=i;
}

void solve(){
    while(true){
        int n;
        cin >> n;
        if(n==0) break;
        vector<int> l(n),t(n),r(n),b(n);
        rep(i,0,n) cin >> l[i] >> t[i] >> r[i] >> b[i];

        map<double,int> zipx,zipy;
        vector<int> tmpx=l,tmpy=t;
        tmpx.insert(tmpx.end(),r.begin(),r.end());
        tmpy.insert(tmpy.end(),b.begin(),b.end());
        compress(tmpx,zipx);
        compress(tmpy,zipy);

        const int w=zipx.size(),h=zipy.size();
        vector<vector<bool>> field(w,vector<bool>(h,false));
        rep(i,0,n){
            rep(x,zipx[l[i]],zipx[r[i]]+1) field[x][zipy[t[i]]]=field[x][zipy[b[i]]]=true;
            rep(y,zipy[b[i]],zipy[t[i]]+1) field[zipx[l[i]]][y]=field[zipx[r[i]]][y]=true;
        }

        int ans=0;
        rep(x,0,w) rep(y,0,h){
            if(field[x][y]) continue;
            ++ans;
            queue<pii> que;
            que.push(make_pair(x,y));
            field[x][y]=true;
            while(!que.empty()){
                pii p=que.front(); que.pop();
                rep(i,0,4){
                    const int nx=p.first+dx[i],ny=p.second+dy[i];
                    if(nx<0 or w<=nx or ny<0 or h<=ny or field[nx][ny]) continue;
                    que.push(make_pair(nx,ny));
                    field[nx][ny]=true;
                }
            }
        }
        cout << ans << endl;
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(8);
    solve();
    return 0;
}

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

int main() {
	int A,B;
	cin>>A>>B;
	if(A==1)A=14;
	if(B==1)B=14;
	string ans = "Bob";
	if(A>B)ans = "Alice";
	else if(A==B)ans ="Draw";
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(ll i=0;i<N;++i)
const ll INF = 1LL<<60;

int main(){
    ll N; cin >> N;
    vector<ll> A(N+1),B(N+1,0);
    for(int i=1;i<N+1;++i){
        cin >> A[i];
    }
    ll m=0;
    for(int i=N;i>0;--i){
        int x = i, sum = 0;
        for(int j=0;j<N+1;j+=x){
            sum += B[j];
        }
        if(sum % 2 != A[i]){
            B[i]++;
            m++;
        }
    }
    cout << m << endl;
    for(int i=1;i<N+1;++i){
        if(B[i]) cout << i << " ";
    }
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    char a, b; cin >> a >> b;
    if (a == b) {
        cout << "H" << endl;
    } else {
        cout << "D" << endl;
    }
    return 0;
}

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

int dp[100010];
int main(){
  dp[10000]=0;
  for(int i=10001;i<100000;i++){
    if(i/10000==i%10 && (i%10000)/1000==(i%100)/10){
      dp[i]=dp[i-1]+1;
    }else{
      dp[i]=dp[i-1];
    }
  }
  
  int a,b;
  cin>>a>>b;
  int ans;
  ans = dp[b]-dp[a-1];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
int main () 
{
	int a[10];
	cin>>a[0]>>a[1]>>a[2];
	int i;
	int x=0,y=0;
	for(i=0;i<3;i++)
	{
		if(a[i]==5)
		x++;
		if(a[i]==7)
		y++;
	}
	if(x==2&&y==1)
	{
		cout<<"YES"<<endl;
//		cout<<"Using three phrases of length"<<a[0];
//		cout<<", "<<a[1];
//		cout<<" and "<<a[2];
//		cout<<", it is possible to construct a Haiku."<<endl;
	}else
	cout<<"NO"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
if n==0:
  if a[0]==1:print(1)
  else:print(-1)
  exit()
if a[0]:
  exit(print(-1))
b=[1]
for i in range(1,n+1):
  b.append(b[-1]*2-a[i])
b[-1]=a[-1]
for i in range(n,0,-1):
  b[i-1]=min(b[i-1],b[i])
  if not(b[i-1]<=b[i]<=2*b[i-1]):exit(print(-1))
  b[i-1]+=a[i-1]
print(sum(b))

Measured memory_bytes: 668720
import java.io.PrintWriter

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val n = readInteger()
    val aList = readLongList()

    var ans = ModInt(0)
    var e = ModInt(1)
    for (i in 0 until 60) {
        val countOne = aList.count { ((it shr i) and 1) == 1L }
        val countZero = aList.size - countOne
        ans += ModInt(countOne.toLong()) * ModInt(countZero.toLong()) * e
        e *= ModInt(2)
    }
    println(ans)
}

/** always positive number (Use for minus)
 * MODは素数（フェルマーの小定理を利用するため）
 */
class ModInt(x: Long, val MOD: Long = 1000000007L) {
    val x = ((x % MOD) + MOD) % MOD

    operator fun unaryMinus() = ModInt(-x, MOD)

    operator fun plus(other: ModInt): ModInt {
        var value = x + other.x
        if (value >= MOD) { value -= MOD }
        return ModInt(value, MOD)
    }

    operator fun minus(other: ModInt): ModInt {
        var value = x + MOD - other.x
        if (value >= MOD) { value -= MOD }
        return ModInt(value, MOD)
    }

    operator fun times(other: ModInt): ModInt {
        val value = (x * other.x) % MOD
        return ModInt(value, MOD)
    }

    operator fun div(other: ModInt) = this * other.inverse()

    override fun toString() = x.toString()


    /** O(log(n)) */
    private fun pow(n: Long): ModInt {
        var ret = ModInt(1L, MOD)
        var x = this
        var k = n
        while (k > 0) {
            if ((k and 1L) == 1L) { ret *= x }
            x *= x
            k = k shr 1
        }
        return ret
    }

    /**  O(log(MOD)) */
    private fun inverse() = pow(MOD - 2)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 82568
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
typedef complex<double> Point;
typedef vector<Point> VP;
#define X real()
#define Y imag()

// ???a??¨???b?????????????????????r????????????????????????
VP circlesPointsRadius(Point a, Point b, double r) {
  VP cs;
  Point abH = (b-a)*0.5;
  double d = abs(abH);
  if (d == 0 || d > r) return cs;
  double dN = sqrt(r*r - d*d);
  Point n = abH * Point(0,1) * (dN / d);
  cs.push_back(a + abH + n);
  if (dN > 0) cs.push_back(a + abH - n);
  return cs;
}

int main(void){
    int N;
    while(cin>>N,N){
        VP p(N);
        int res=1;
        rep(i,N){
            double x,y;
            cin>>x>>y;
            p[i] = {x,y};
        }
        rep(i,N)rep(j,i){
            VP cs = circlesPointsRadius(p[i],p[j],1.0);
            for(Point c:cs){
                int cnt=0;
                rep(k,N) if(abs(c-p[k]) <= 1.0001)cnt++;
                res=max(res,cnt);
            }
        }
        cout<<res<<endl;
    }

    return 0;
}

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



int main() 
{
    int n,k;
    cin >> n>>k;
    int ans = 0;
    rep(i,n)
    {
        int h;
        cin >> h;
        if(h>=k)
        {
            ans +=1;
        }
    }
    cout << ans << endl;


    return 0;
}



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

using namespace std;



int main(){
int n;
cin >> n;
string s;
cin >> s;
vector<int> d(n+1,0);
d[0] = 0;
for(int i = 0;i<n;i++){
    if(s[i]=='#') d[i+1] = d[i] + 1;
    else d[i+1] = d[i];
}
//for(auto x : d) cout << x << ' '; cout << endl;
int ans = 1e9;
for(int i = 0;i<=n;i++){
      //  cout << i << ' ' << (n-i)-(d[n]-d[i]) + d[i] << endl;
    ans = min(ans, (n-i)-(d[n]-d[i]) + d[i]);
}
cout << ans;

}


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

#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}

ll mod(ll a, ll b) {return (a % b + b) % b;}

ll powerm(ll base,ll exp,ll mod) 
{ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}

using namespace std;

int main() 
{	
	fast;
	string s; string t; ll flag = 0;
	cin>>s>>t;
	for(ll i = 0; i < s.size(); i++)
	{
		if(s[i] != t[i])
		{
			flag = 1;
			break;
		}
	}
	if(flag == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
 	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int N = 300000 + 100;
const int oo = 1e9;

int n , a[N],cnt = 0;

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

Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX = 300000;

bool T[MAX+1];
int L[MAX+1];

main(){

  int N, Q, q, x, L[MAX+1];

  cin >> N >> Q;

  for ( int i = 0; i < N; i++ ) {
    cin >> x;
    T[x] = true;
  }

  int m = 0;
  for ( int i = 1; i <= MAX; i++ ){
    L[i] = m;
    if ( T[i] ) m = i;
  }

  for ( int i = 0; i < Q; i++ ){
    cin >> q;
    int maxv = 0;
    int cur = m;
    while(cur){
      int p = cur%q;
      maxv = max(maxv, p);
      if ( cur - p < 0 ) break;
      cur = L[cur - p];
    }
    cout << maxv <<endl;
  }
}




Measured memory_bytes: 4548
#include<stdio.h>
#define INF 999999

int dp[41][160801];

int min(int x,int y){
	if(x<y)return x;
	return y;
}

int max(int x,int y){
	if(x>y)return x;
	return y;
}

int main(){
	int N,A,B,i,m=INF;
	scanf("%d%d%d",&N,&A,&B);
	int a[N],b[N],c[N],s[N];
	for(i=0;i<N;i++){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
		s[i]=a[i]*401+b[i];
	}
	
	for(i=0;i<41;i++)for(int j=0;j<160801;j++)dp[i][j]=INF;
	dp[0][0]=0;
	for(i=0;i<N;i++){
		for(int j=0;j<160801;j++){
			dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
			if(j>=s[i])dp[i+1][j]=min(dp[i+1][j],dp[i][j-s[i]]+c[i]);
		}
	}
	for(i=1;i<=400/max(A,B);i++){
		if(dp[N][A*i*401+B*i]<m){
			m=dp[N][A*i*401+B*i];
		}
	}
	if(m<INF)printf("%d\n",m);
	else printf("-1\n");
	return 0;
}

Measured memory_bytes: 25856
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;

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

	int A, B; cin >> A >> B;
	if ((A + B) < 24)
		cout << A + B << endl;
	else if ((A + B )>= 24)
		cout << A + B - 24 <<  endl;
	
	
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>  // ver1.8
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  int n;
  cin >> n;
  int sum1,sum2;
  Vi a(n+1);
  Vi b(n+1);
  rep(i,1,n+1) cin >> a[i];
  Vi ans(0);
  
  repr(i,n,0){
    
    if(i>n/2){
      if(a[i]==1) {
        ans.pb(i);
        b[i] = 1;
      }
      continue;
    }
    
    int nowsum = 0,nowi = i;
    while(nowi<=n){
      nowsum += b[nowi];
      nowi += i;
    }
    if(nowsum%2!=a[i]) {
      b[i] = 1;
      ans.pb(i);
    }
  }
  
  sort(ALL(ans));
  cout << ans.size() << endl;
  rep(i,0,ans.size()) {
    if(i==ans.size()-1) cout << ans[i] << endl;
    else cout << ans[i] << ' ';
  }
  
  return 0;
}


Measured memory_bytes: 4980
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    lint N,A,B;
    cin >> N >> A >> B;
    lint dis=B-A;
    if(dis<0) cout << 0 << endl;
    else if(N==1 && A!=B){
        cout << 0 << endl;
    }
    else{
        lint mini=A*(N-1)+B;
        lint maxi=B*(N-1)+A;
        cout << maxi-mini+1 << endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
 string s;
  cin >> s;
 ll q;
  cin >> q;
 
  vector<char> front,rear;
  
  bool flag=true;
  while(q--){
   ll t;
    cin >> t;
    if(t==1){
    flag^=true;
    }
    else {
     ll f;
     char c;
      cin >> f >> c;
      if((f==1&&flag)||(f==2&&!flag)) front.emplace_back(c);
      else rear.emplace_back(c);
    }
    
  }
    if(flag) {
      reverse(front.begin(),front.end());
      rep(i,0,front.size()) cout << front[i];
      cout << s;
      rep(i,0,rear.size()) cout << rear[i];
      cout << endl;
    }
      else {
        reverse(s.begin(),s.end());
        reverse(rear.begin(),rear.end());
        rep(i,0,rear.size()) cout << rear[i]; 
        cout << s;
        rep(i,0,front.size()) cout << front[i];
        cout << endl;
      }
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
#define L long long
#define LL long long
#define SS string
#define PB push_back
#define pp pair<L,L>
#define f(x, n , i) for (i = x ; i <= n ; i++)
#define setE(a, x , size) memset(a,x,size);
#define N 100005
using namespace std;
    L a[101][N];
    L n,w;
    L g[101][2];
L recursivedpKnapsackmaximum(L w , L i)
{
    if (a[i][w] != -1)
    return a[i][w];

if (w < g[i][0])
    a[i][w] = max(a[i][w],recursivedpKnapsackmaximum(w,i-1));
    else
    {
        a[i][w] = max(a[i][w],max(recursivedpKnapsackmaximum(w,i-1)
        ,recursivedpKnapsackmaximum(w-g[i][0],i-1)+g[i][1]));
    }
    return a[i][w];
}
int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> w;
    L i;
    L j;
    setE(a,-1,sizeof(L)*101*N);
    // f(0,n,i)
    // {
    //     f(0,N-1,j)
    //     a[i][j] = -1;
    // }
    f(0, w, i)
    {   
        a[0][i] = 0;
    }
    f (0 , n, i)
    {
        a[i][0] = 0;
    }
    f(1 , n , i)
    {
        cin >> g[i][0] >> g[i][1];
    }
    cout << recursivedpKnapsackmaximum(w,n);
    return 0; 
}

Measured memory_bytes: 79232
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
int N,M,H,K;
LL a[1001];
LL b[1001];
LL c[10001];
LL h[10001];
LL r[10001];
int S,T;
int PPP;
LL l[1<<8];
LL d[1<<8];
LL k[1<<8];

LL dp[501][31];
bool used2[10];
LL now[1<<8];

typedef pair<int,int>P;
typedef pair<LL,P>PP;
struct edge{LL to, cost, h,r;};
vector<edge> G[1001];
//int d[1001];

void dijkstra(int s){
   //greater<PP>????????????????????¨??§first????°???????????????????????????????????????????
   priority_queue<PP, vector<PP>, greater<PP> > que;
   REP(i,501){
       REP(j,31){
           dp[i][j]=1e16;
       }
   }
   dp[s][0]=0;
   que.push(PP(0,P(s,0)));
   while(!que.empty()){
      PP p=que.top();que.pop();
      int v=p.second.first;
      int nh=p.second.second;
      if(dp[v][nh]< p.first)continue;
      REP(i,G[v].size()){
          edge e =G[v][i];
          int c_cost=e.cost;
          if(used2[e.r])c_cost=0;
          if(nh+e.h<=H){
             if(dp[e.to][nh+e.h] > dp[v][nh]+ c_cost){
                dp[e.to][nh+e.h] = dp[v][nh] + c_cost;
                que.push(PP(dp[e.to][nh+e.h],P(e.to,nh+e.h)));
             }
          }
      }
   }
}

LL dp2[1<<8];

int main(){
    while(cin>>N>>M>>H>>K,N){
       REP(i,1000){
           G[i].clear();
       }
       REP(i,M){
           cin>>a[i]>>b[i]>>c[i]>>h[i]>>r[i];
           a[i]--;b[i]--;r[i]--;
           G[a[i]].push_back(edge{b[i],c[i],h[i],r[i]});
           G[b[i]].push_back(edge{a[i],c[i],h[i],r[i]});
       }
       cin>>S>>T;
       S--;T--;
       cin>>PPP;
       REP(i,PPP){
           cin>>l[i]>>d[i];
           k[i]=0;
           REP(j,l[i]){
              int aa=0;
              cin>>aa;
              aa--;
              k[i]=(k[i]+(1<<aa));
           }
       }
       LL ans=1e18;
       REP(i,1<<K){
           now[i]=1e16;
           REP(j,K){
               used2[j]=false;
           }
           REP(j,K){
               if((i>>j)&1)used2[j]=true;
           }
           dijkstra(S);
           REP(o,H+1){
               now[i]=min(now[i],dp[T][o]);
           }
           //cout<<i<<" now "<<now[i]<<endl;
       }
       REP(i,1<<K){
           dp2[i]=1e16;
       }
       dp2[0]=0;
       REP(i,PPP){
           REP(j,1<<K){
               dp2[j|k[i]]=min(dp2[j|k[i]],dp2[j]+d[i]);
           }
       }
       
       REP(i,1<<K){
           ans=min(ans,dp2[i]+now[i]);
       }
       if(ans==1e16){
          cout<<-1<<endl;
       }else{
          cout<<ans<<endl;
       }
    }
    return 0;
}

Measured memory_bytes: 3516
import bisect

S=[]

def insert(S,count,x):
    y=bisect.bisect_left(S,x)
    if y>=count or S[y]!=x:
        S.insert(y,x)
        count+=1
    print(count)
    return S,count

def find(S,x):
    y=bisect.bisect_left(S,x)
    if y<count and S[y]==x:
        judge=1
    else:
        judge=0
    return judge,y

q=int(input())
count=0
for i in range(q):
    query=list(map(int,input().split()))
    
    if query[0]==0:
        S,count=insert(S,count,query[1])
    elif query[0]==1:
        print(find(S,query[1])[0])
    else:
        if find(S,query[1])[0]==1:
            S.pop(find(S,query[1])[1])
            count-=1



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

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

  vector<int> idx(26, -1);
  rep(i, s.size()) idx[(int)(s[i] - 'a')] = i;

  if (s.size() != 26) {
    rep(i, 26) if (idx[i] == -1) {
      s += (char)('a' + i);
      cout << s << endl;
      return 0;
    }
  } else {
    for (int i = 25; i >= 0; i--) {
      REP(k, 1, 26) {
        int ii = (int)(s[i] - 'a' + k);
        if (ii >= 26) break;
        if (i < idx[ii]) {
          cout << s.substr(0, i) + (char)('a' + ii) << endl;
          return 0;
        }
      }
    }
  }

  cout << "-1" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll,int> pr;
const int maxn = 200100;
struct T {
    int to, nxt, v;
} way[maxn << 4];
int h[maxn], head[maxn], num = 1;
inline void adde(int x,int y,int v) {
    way[++num] = {y, h[x], v}, h[x] = num;
    way[++num] = {x, h[y], 0}, h[y] = num;
}
int dis[maxn];
inline bool bfs(int s,int t) {
    std::queue<int> q;
    for(int i = s;i <= t;++i) dis[i] = - 1, head[i] = h[i];
    for(q.push(s), dis[s] = 0;!q.empty();) {
        int t = q.front(); q.pop();
        for(int i = h[t];i;i = way[i].nxt) if(way[i].v && dis[way[i].to] < 0) 
            dis[way[i].to] = dis[t] + 1, q.push(way[i].to);
    }
    return dis[t] >= 0;
}
inline int dfs(int s,int t,int lim) {
    if(s == t || !lim) return lim;
    int ans = 0, mn;
    for(int & i = head[s];i;i = way[i].nxt)
        if(dis[way[i].to] == dis[s] + 1 && (mn = dfs(way[i].to, t, std::min(lim, way[i].v)))) {
            way[i].v -= mn;
            way[i ^ 1].v += mn;
            ans += mn; lim -= mn;
            if(!lim) break;
        }
    return ans;
}
inline int dinic(int s,int t) {
    int ans = 0;
    for(;bfs(s,t);) ans += dfs(s,t,1e9);
    return ans;
}
int a[(int) 1e7 + 100];
std::vector<int> v;
inline bool chk(int x) {
	if(x == 1) return 0;
	for(int i = 2;i * i <= x;++i) {
		if(x % i == 0) return 0;
	}
	return 1;
}
int main(){
    std::ios::sync_with_stdio(false),std::cin.tie(0);
    int n;
    std::cin >> n;
    for(int i = 0, x;i < n;++i) {
    	std::cin >> x, a[x] ^= 1;
	}
	for(int i = 1;i <= 1e7 + 1;++i) {
		if(a[i] ^ a[i - 1]) {
			v.push_back(i);
		}
	}
	for(int i = 0;i < v.size();++i) if(v[i] & 1) for(int j = 0;j < v.size();++j) if(v[j] % 2 == 0 && chk(std::abs(v[i] - v[j]))) {
		adde(i + 1, j + 1, 1);
	}
	int odd = 0, even = 0;
	for(int i = 0;i < v.size();++i) if(v[i] & 1) adde(0, i + 1, 1), ++ odd;
	else adde(i + 1, v.size() + 1, 1), ++ even;
	int fl = dinic(0, v.size() + 1), ans = 0;
	ans += fl, odd -= fl, even -= fl;
	ans += odd / 2 * 2;
	ans += even / 2 * 2;
	ans += odd % 2 * 3;
	std::cout << ans << '\n';
}


Measured memory_bytes: 41344
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// to container
template <class C>
void input(C &c)
{
    for_each(c.begin(), c.end(), [](auto &i) { cin >> i; });
}

// to number, string
template <class T>
T input()
{
    T data;
    cin >> data;
    return data;
}

int main()
{
    string S = input<string>();

    string res;
    if (S == "Sunny")
    {
        res = "Cloudy";
    }
    else if (S == "Cloudy")
    {
        res = "Rainy";
    }
    else
    {
        res = "Sunny";
    }
    cout << res << endl;
    return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;



int main(){
  ll r, d, x;
  cin >> r >> d >> x;


  rep(i, 10){
    x = r*x - d;
    cout << x << endl;
  }
  
  return 0;
}


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

using ll = long long;
using namespace std;

int main(){
	ll a,b,k;

	cin >> a >> b >> k;

	if(k >= a){
		k-=a;
		a=0;
	}
	else{
		a-=k;
		k=0;
	}

	if(k >= b){
		k-=b;
		b=0;
	}
	else b-=k;

	cout << a << " " << b << '\n';

	return 0;
}


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

ans = 0
for i,n in enumerate(L[:-2]):
    for j,m in enumerate(L[i+1:]):
        for k,o in enumerate(L[i+j+2:]):
            if n + m <= o or n >= m + o or m >= n + o:
                continue
            if n == m or m == o or o == n:
                continue

            ans += 1

print(ans)

Measured memory_bytes: 9196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);
const ll MD = 1000000007LL;

ll A, B;

// repeat square - (x ** n) % M
ll power(ll x, ll n, ll M){
	ll tmp = 1;

	if (n > 0){
		tmp = power(x, n/2, M);
		if ( n%2 == 0 ) tmp = (tmp*tmp)%M;
		else tmp = (((tmp*tmp)%M)*x)%M;
	}
	return tmp;
}

int main() {
	cin >> A >> B;
	cout << power(A, B, MD) << endl;
}

Measured memory_bytes: 3080