akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n;
    cin >> n;

    vector<int64_t> a(n);
    for (auto&& aa : a) {
        cin >> aa;
    }

    vector<int64_t> l(n + 1), r(n + 1);
    for (auto i : irange(0L, n)) {
        l[i + 1] = max(l[i], a[i]);
        r[n - i - 1] = max(r[n - i], a[n - i - 1]);
    }

    for (auto i : irange(0L, n)) {
        cout << max(l[i], r[i + 1]) << "\n";
    }
}

Measured memory_bytes: 6272
#!/usr/bin/env python3
import sys
import numpy as np


def solve(S: str, T: str):
    print(T+S)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12452
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
const lli inf=1e18;
const int mod=1e9+7;
int main(){
IOS;
string s,t;
cin>>s>>t;
int count=0;
for(int i=0;i<3;i++){
    if(s[i]==t[i])
        count++;
}
cout<<count<<endl;
}


Measured memory_bytes: 256
from enum import Enum
import sys
import math

class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'

    def setNumber(self, n0, n1, n2, n3, n4, n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5

    def roll(self, loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3], self.work[1], self.work[0],
                           self.work[5], self.work[4], self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1], self.work[5], self.work[2],
                           self.work[3], self.work[0], self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4], self.work[0], self.work[2],
                           self.work[3], self.work[5], self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2], self.work[1], self.work[5],
                           self.work[0], self.work[4], self.work[3])

    def query(self, top_num, front_num):

        self.save_data = [i for i in range(6)]
        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]

        ret = -1

        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break
            
        for i in range(len(self.number)):
            self.number[i] = self.save_data[i]

        return ret


dice = Dice()
table = list(map(int, input().split()))
dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

num_query = int(input())
for loop in range(num_query):
    top_num, front_num = map(int, input().split())
    print("%d" % (dice.query(top_num, front_num)))



Measured memory_bytes: 6396
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
int n;
char a[2010],b[2010];
int l[2010],r[2010];
int ans=1e9;
int main()
{
	scanf("%s%s",a,b);
	n=strlen(a);
	int s1=0,s2=0;
	for(int i=0;i<n;i++)s1+=a[i]-'0',s2+=b[i]-'0';
	if(!s2)
	{
		if(s1)printf("-1");
		else printf("0");
		return 0;
	}
	for(int i=0;i<n;i++)
	{
		int p=i;
		while(b[p]!='1')
		{
			l[i]++;
			p=(p+n-1)%n; 
		}
		p=i;
		while(b[p]!='1')
		{
			r[i]++;
			p=(p+1)%n;
		}
	}
	for(int i=-n+1;i<n;i++)
	{
		vector<pair<int,int> >tot;
		int res=0;
		for(int j=0;j<n;j++)
		{
			if(a[j]!=b[(i+j+n)%n])
			{
				res++;
				if((i<=0 && l[j]<=-i) || (i>=0 && r[j]<=i))continue;
				tot.push_back(make_pair(l[j],r[j]));
			}
		}
		sort(tot.begin(),tot.end());
		int mx=max(0,i);
		int k=(int)tot.size()-1;
		for(int j=n-1;j>=-i && j>=0;j--)
		{
			while(k>=0 && tot[k].first>j)
			{
				mx=max(mx,tot[k].second);
				k--;
			}
			if(i<=0)ans=min(ans,res+mx+mx+j+j+i);
			else ans=min(ans,res+j+j+mx+mx-i);
		}
	}
	printf("%d",ans);
	return 0;
}

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

int main() {
  int N, S;
  cin >> N;
  vector<int> V(N), C(N);

  for (int i = 0; i < N; i++) {
    cin >> V.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> C.at(i);
  }
  
  
  for (int i = 0; i < N; i++) {
    if (V.at(i) >= C.at(i)){
      S = S + V.at(i) - C.at(i);
    }
  }
  
  cout << S << endl;

}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Scan()
	input := sc.Text()
	fmt.Println(check(input))
}

func check(s string) (num int) {
	var l int
	l = len(s)
	for i := 0; i < l/2; i++ {
		if s[i] != s[l-i-1] {
			num++
		}
	}
	return num
}

Measured memory_bytes: 640
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int H, N;
	cin >> H >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	sort(A.begin(), A.end(), greater<int>());
	int cnt = 0;
	for (int i = 0; i < N; ++i) {
		if (H > 0) {
			H -= A[i];
			++cnt;
		}
	}
	cout << (H <= 0 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int n, q, a, b, c, tmp;
	int num[100001] = {0};
	int i;
	long long int s = 0;
	long long int ans[100001];

	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a);
		num[a]++;
		s += a;
	}
	scanf("%d", &q);

	for (i = 0; i < q; i++)
	{
		scanf("%d%d", &b, &c);
		tmp = c - b;
		s += tmp * num[b];
		num[c] += num[b];
		num[b] = 0;
		ans[i] = s;
	}

	for (i = 0; i < q; i++)
	{
		printf("%lld\n", ans[i]);
	}

	return 0;
}


Measured memory_bytes: 2876
package main

import "fmt"

func main(){
	var N int;
	var S string;

	fmt.Scan(&N, &S);


	if len(S) % 2 == 0{
		T:=S[:len(S)/2];
		if T == S[len(S)/2:]{
			fmt.Println("Yes");
		}else{
			fmt.Println("No");
		}
	}else{
		fmt.Println("No");
	}
}

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

public class P
{
    public List<int> a1 { get; set; }
    public List<int> a2 { get; set; }
}

public class hello
{
    public static void Main()
    {

        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            var p1 = new P { a1 = new List<int>(), a2 = new List<int>() };
            var p2 = new P { a1 = new List<int>(), a2 = new List<int>() };
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = Array.ConvertAll(line, int.Parse);
            getP2(a, p2);
            getP1(a, p1);
            Console.WriteLine(getAns(p1, p2) ? "yes" : "no");
        }
    }
    static bool getAns(P p1, P p2)
    {
        if (p1.a1.Count() > 0 && p1.a1.Min() == 1 && p1.a2.Count() > 0 && p1.a2.Max() == 13) return false;
        if (p2.a1.Count() > 0 && p2.a1.Min() == 1 && p2.a2.Count() > 0 && p2.a2.Max() == 13) return true;
        var c = new bool[14];
        c[7] = true;
        int f1;
        if (p1.a1.Count() > 0 && p1.a1.Min() == 1) f1 = 1;
        else f1 = 2;
        var f2 = f1 == 1 ? 2 : 1;
        while (true)
        {
            goSim(p1, c, f1);
            if (p1.a1.Count() == 0 && p1.a2.Count() == 0) return true;
            goSim(p2, c, f2);
            if (p2.a1.Count() == 0 && p2.a2.Count() == 0) return false;
        }
    }
    static void goSim(P p, bool[] c, int t)
    {
        if (t == 1)
        {
            var a1c = p.a1.Count();
            if (a1c > 0 && c[p.a1[a1c - 1] + 1]) { c[p.a1[a1c - 1]] = true; p.a1.RemoveAt(a1c - 1); return; }
            else
            {
                if (p.a2.Count() > 0 && c[p.a2[0] - 1]) { c[p.a2[0]] = true; p.a2.RemoveAt(0); return; }
                else return;
            }
        }
        else
        {
            if (p.a2.Count() > 0 && c[p.a2[0] - 1]) { c[p.a2[0]] = true; p.a2.RemoveAt(0); return; }
            else
            {
                var a1c = p.a1.Count();
                if (a1c > 0 && c[p.a1[a1c - 1] + 1]) { c[p.a1[a1c - 1]] = true; p.a1.RemoveAt(a1c - 1); return; }
                else return; ;
            }
        }
    }
    static void getP1(int[] a, P p1)
    {
        Array.Sort(a);
        for (int i = 0; i < 6; i++)
            if (a[i] <= 6) p1.a1.Add(a[i]);
            else p1.a2.Add(a[i]);
    }
    static void getP2(int[] a, P p2)
    {
        for (int i = 1; i <= 6; i++)
            if (!a.Contains(i)) p2.a1.Add(i);
        for (int i = 8; i <= 13; i++)
            if (!a.Contains(i)) p2.a2.Add(i);
    }
}



Measured memory_bytes: 18232
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
  long K, A, B;
  scanf("%ld %ld %ld", &K, &A, &B);

  if (A >= B - 2) {
    printf("%ld\n", K + 1);
  } else {
    if (K <= A - 1) {
      printf("%ld\n", K + 1);
    } else {
      const long Kd = K - (A - 1);
      printf("%ld\n", A + Kd / 2 * (B - A) + Kd % 2);
    }
  }
  
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

int main() {
    int n,l;
    cin >> n >> l;
    int sum = 0;
    int min = 1000;
    for(int i = 1; i <= n; i++){
        int temp = l + i - 1;
        sum += temp;
        if(abs(temp) < abs(min)) min = temp;
    }
    cout << sum - min << endl;
}

Measured memory_bytes: 256
//file_name:ABC87_C.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int n;
    scanf("%d",&n);

    int a[n];
    int b[n];
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        cin >> b[i];
    }

    int ans = 0;
    rep(i,n){
        int an = 0;
        rep(j,i+1){
            an += a[j];
        }
        srep(j,i,n){
            an += b[j];
        }
        maxs(ans,an);
    }



    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
from sys import stdin
input = stdin.readline

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

dp = [[0] * (N + 1) for _ in range(N + 1)]

for i in range(N):
    dp[i][i + 1] = a[i] if N & 1 == 1 else -a[i]

for j in range(2, N + 1):
    for i in range(0, N + 1 - j):
        # j is the length of the interval + 1
        if (N - j) & 1 == 0:
            dp[i][i + j] = max(a[i] + dp[i + 1][i + j],
                               a[i + j - 1] + dp[i][i + j - 1])
        else:
            dp[i][i + j] = min(dp[i + 1][i + j] - a[i],
                               dp[i][i + j - 1] - a[i + j - 1])

print(dp[0][N])


Measured memory_bytes: 115804
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll GetDigit(ll num){
   ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main() {
 ll N;
  ll K;
  cin >>N>>K;
  
  vl D(K);
  rep(i,K) {
    cin >>D.at(i);
  }
  vl a(7);
  a.at(0)=INF;
  
  repl(i,N,10*N+1) {
     a.at(6)=i/100000;
     a.at(5)=i/10000-a.at(6)*10;
     a.at(4)=i/1000-a.at(6)*100-a.at(5)*10;
     a.at(3)=i/100-a.at(6)*1000-a.at(5)*100-a.at(4)*10;
     a.at(2)=i/10-a.at(6)*10000-a.at(5)*1000-a.at(4)*100-a.at(3)*10;
     a.at(1)=i-a.at(6)*100000-a.at(5)*10000-a.at(4)*1000-a.at(3)*100-a.at(2)*10;
   
    bool antwort=true;
    rep(j,K) {
      //repbeginnen
      ll ps=GetDigit(i);
     
      repl(k,1,ps+1) {
        if(a.at(k) ==D.at(j)) {
          antwort=false;
          break;
        }
      }
      
      
      
      
      
      
      
      
      //rependen
    }
    
    
    if(antwort) {
      cout<<i<<endl;
      break;
      return 0;
    }
    else {
      continue;
    }
  }
  
  
}
   
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<char>> A(N, vector<char>(N, 0));
    vector<vector<char>> B(M, vector<char>(M, 0));
    rep(i, N) rep(j, N) cin >> A[i][j];
    rep(i, M) rep(j, M) cin >> B[i][j];

    bool inc = 0;
    rep(i, N - M + 1) {
        rep(j, N - M + 1) {
            if(inc) break;
            bool tmp = 0;
            rep(k, M) {
                rep(l, M) {
                    if(A[i + k][j + l] != B[k][l]) {
                        tmp = 1;
                        break;
                    }
                }
            }
            if(!tmp) inc = 1;
        }
    }
    cout << (inc ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <map>
#include <string>
typedef long long ll;
using namespace std;
ll S[200005];
int main() {
  ios::sync_with_stdio(false);
  ll N, P;
  string T;
  cin >> N >> P;
  cin >> T;
  if (P == 2 || P == 5) {
    ll ret = 0;
    for (int i=0; i<N; i++) {
      ll d = T[N-1-i] - '0';
      if (d % P == 0) ret += N - i;
    }
    cout << ret << endl;
    return 0;
  }
  ll base = 1;
  for (int i=0; i<N; i++) {
    ll d = T[N-1-i] - '0';
    S[i+1] = (S[i] + d * base) % P;
    base = (base * 10) % P;
  }
  map<int, ll> m;
  for (int i=1; i<=N; i++) {
    m[S[i]]++;
  }
  m[0]++;
  ll ret = 0;
  for (int i=0; i<P; i++) {
    if (m[i] <= 1) continue;
    ret += m[i] * (m[i] - 1) / 2;
  }
  cout << ret << endl;
}

Measured memory_bytes: 2580
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    ll a,b,c,n;
    string s, t;
    ll ans;
    double dans;
    string sans;

    cin  >> n;

    dans = (double)((n+1)/2) / n;


    std::cout << dans << endl; 
    // std::cout << sans << endl; 
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

Measured memory_bytes: 256
//-----------------------
// author : xyqkoala
// time : 2020-07-06
//-----------------------

#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve();


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


void solve(){
	int n;
	cin>>n;
	vector<string> table= {"AC","WA","TLE","RE"};
	unordered_map<string,int> t;
	for(int i=0;i<n;i++){
		string str;
		cin>>str;
		t[str]++;
	}
	for(auto item:table){
		cout<<item<<" x "<<t[item]<<endl;
	}

}


Measured memory_bytes: 3656
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

#define MAXN 524288
#define MAXC 1048576
#define NO_VALUE -1

#define LEFT(x) ( 2*(x) )
#define RIGHT(x) ( 2*(x)+1 )

int A, B, C, M;

int r() {
    A = 36969 * (A & M) + (A >> 16);
    B = 18000 * (B & M) + (B >> 16);
    return (C & ((A << 16) + B)) % 1000000;
}

int x[MAXN], y[MAXN], z[MAXN], ox[MAXN], val[MAXN], N, BEST;

bool cmp_x(const int &a, const int &b) { return x[a] < x[b]; }

map<int, int> best[MAXN];

int query(int cury, int curz) {
    int s = 0, e = N, mid;
    while (e-s > 1) {
        mid = (s+e)/2;
        map<int, int>::iterator it = best[mid].lower_bound(cury);
        if (it != best[mid].begin() && (--it)->second < curz) s = mid;
        else e = mid;
    }
    return s+1;
}

void update(int cury, int curz, int v) {
    map<int, int>::iterator it1, it2;

    BEST = max(BEST, v);

    it1 = it2 = best[v].lower_bound(cury);
    while (it2 != best[v].end() && it2->second >= curz) it2++;
    best[v].erase(it1, it2);

    it1 = best[v].upper_bound(cury);
    if (it1 == best[v].begin() || (--it1)->second > curz) best[v][cury] = curz;
}

int main() {
    int m, n, i, j;

    while (scanf("%d %d %d %d", &m, &n, &A, &B) && (m || n || A || B)) {
        C = ~(1<<31); M = (1<<16)-1;
        for (i=0; i<m; i++) scanf("%d %d %d", &x[i], &y[i], &z[i]);
        for (i=m; i<m+n; i++) { x[i] = r(); y[i] = r(); z[i] = r(); }
        N = m+n;

        for (i=0; i<N; i++) ox[i] = i;
        sort(ox, ox+N, cmp_x);

        for (i=1; i<=N; i++) best[i].clear();

        i = BEST = 0;
        do {
            for (j=i; j<N && x[ox[j]]==x[ox[i]]; j++) val[j] = query(y[ox[j]], z[ox[j]]);
            for (; i<j; i++) update(y[ox[i]], z[ox[i]], val[i]);
        } while (i < N);
        printf("%d\n", BEST);
    }

    return 0;
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	int X, A;
	cin >> X >> A;

	if (X < A){
	cout << 0 << endl;		
	} else {		
	cout << 10 << endl;		
	}



	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int main(){
  IOS();
  ll n,k;
  cin>>n>>k;
  ll ans=0;
  REP1(i,n){
    if( (2*i)%k!=0 ) continue;
    ll l=i/k,r=(n+i)/k;
    ans+=(r-l)*(r-l);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
def solve(n, y):
    for i in range(0, n + 1):
        for j in range(i, n + 1):
            a, b, c = i, j - i, n - j
            if 10000 * a + 5000 * b + 1000 * c == y:
                return (a, b, c)
    return (-1, -1, -1)

_n, _y = map(int, input().split())
print(*solve(_n, _y))

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

using namespace std;

int main()
{
  int64_t n;
  cin >> n;
  int64_t prev, now;
  prev = 0;
  bool ans = true;
  for(int64_t i = 0;
      i < n;
      ++i)
    {
      cin >> now;
      if(ans)
        {
          if(prev > now)
            {
              ++now;
              if(prev > now)
                {
                  ans = false;
                }
            }
        }
      prev = now;
    }

  if(ans)
    {
      cout << "Yes" << endl;
    }
  else
    {
      cout << "No" << endl;
    }
  return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define repo(i,o,n) for(int i=o;i<(int)(n);i++)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int a,b,c;

main() {
    cin >> a >> b >> c;
    cout << min(b/a,c) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1061109567
#define int long long
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
typedef pair<int,int> ii;
const int N=1e5+5;
int h,w,n,a[N],b[N],ans[15];
map<ii,int> mp;
void add(int x,int y) {
	int lx=max(1LL,x-2),ly=max(1LL,y-2),rx=min(x,h-2LL),ry=min(y,w-2LL);
	fw (i,lx,rx+1) {
		fw (j,ly,ry+1) {
			ans[mp[ii(i,j)]]--;
			mp[ii(i,j)]++;
			ans[mp[ii(i,j)]]++;
		}
	}
}
signed main() {
	//in("aome.inp");
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>h>>w>>n;
	ans[0]=(h-2)*(w-2);
	fw (i,0,n) {
		cin>>a[i]>>b[i];
		add(a[i],b[i]);
	}
	/*
	For each newly added a[i], b[i] black spot, check all rectangles it affected.
	Starting: There are (H - 2) * (W - 2) 0 - spot rectangles
	cnt[i, j] stores all up - left corners of affected rectangles up to this point.
	If an affected rectangle haven't appeared yet, it's set to 1. Else, it's added up
	*/
	fw (i,0,10) cout<<ans[i]<<"\n";
	return 0;
}

Measured memory_bytes: 59904
#include<stdio.h>
int main(void)
{
	int n,m[100]={0},i,j,temp,k,a,b,x,y,z,p[100]={0};
	scanf("%d",&n);
	scanf("%d %d",&a,&b);
	scanf("%d",&k);
	for(i=0;i<n;i++){
		scanf("%d",&m[i]);
	}
	for(i=0;i<n;i++){
		for(j=n;j>i;j--){
			if(m[i]<m[j]){
				temp=m[i];
				m[i]=m[j];
				m[j]=temp;
			}
		}
	}
	x=k;
	y=k/a;
	z=a;
	for(i=0;i<n;i++){
		x=x+m[i];
		z=z+b;
		p[i]=x/z;
	}
		for(i=0;i<n;i++){
		for(j=n;j>i;j--){
			if(p[i]<p[j]){
				temp=p[i];
				p[i]=p[j];
				p[j]=temp;
			}
		}
	}
		printf("%d\n",p[0]);
return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
typedef bool boolean;

const int N = 3005, M = 1e9 + 7;

int n, m;
int f[N][N][2];

inline void init() {
	scanf("%d%d", &n, &m);
}

void add(int& a, int b) {
	a += b;
	if (a > M)
		a -= M;
}

inline void solve() {
	memset(f, 0, sizeof(f));
	for (int i = 0; i <= n; i++)
		f[0][i][(i == 0)] = 1;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j <= n; j++) {
			for (int c = 0; c < 2; c++) {
				if (!f[i][j][c])	continue;
				if (j) {
					add(f[i + 1][j][c | (j == 1)], f[i][j][c]);	// nj = j - 1 + 1
					add(f[i + 1][j - 1][c | (j == 1)], f[i][j][c]);
				}
				if (n - j) {
					add(f[i + 1][j][c], f[i][j][c]);
					add(f[i + 1][j + 1][c], f[i][j][c]);
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i <= n; i++)
		add(ans, f[m][i][1]);
	printf("%d\n", ans);
}

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


Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

    int n; ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    ll l = -ll(1e18) + 1, r = ll(1e18) + 1;
  
    while (l + 1 < r) {
        ll x = (l + r) / 2;
        bool ok = [&] {
            ll tot = 0;
            rep(i, n) {
                if (a[i] < 0) {
                    int l = -1, r = n;
                    while (l + 1 < r) {
                        int c = (l + r) / 2;
                        if (a[c] * a[i] < x) r = c; else l = c;
                    }
                    tot += n - r;
                }
                else {
                    int l = -1, r = n;
                    while (l + 1 < r) {
                        int c = (l + r) / 2;
                        if (a[c] * a[i] < x) l = c; else r = c;
                    }
                    tot += r;
                }
                if (a[i] * a[i] < x) tot--;
            }
            tot /= 2;
            return tot < k;
        }();
        if (ok) l = x; else r = x;
    }
    cout << l << endl;

	return 0;
}

Measured memory_bytes: 1792
N,A,B = map(int,input().split())
count = 0
for i in range(1,N+1):
    if i <=9:
        if i >= A and i <= B:
            count += i
    elif i <= 99:
        k = str(i)
        m = int(k[0]) + int(k[1])
        if m >= A and m <= B:
            count += i
    elif i <=999:
        k = str(i)
        m = int(k[0]) + int(k[1]) + int(k[2])
        if m >= A and m <= B:
            count += i
    elif i <= 9999:
        k = str(i)
        m = int(k[0]) + int(k[1]) + int(k[2]) + int(k[3])
        if m >= A and m <= B:
            count += i        
    else:
        m = 1
        if m >= A and m <= B:
            count += i
print(count)

Measured memory_bytes: 40176
#include<bits/stdc++.h>
using namespace std;
int main()
{
   unsigned long long n,a,b,x;
   cin>>n>>a>>b;
   if(a==0)
     cout<<"0";
   else if(b==0)
     cout<<n;
   else
   {
      x=n/(a+b);
      x=a*(x);
      x=x+min(a,n%(a+b));
      cout<<x;
   }
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll n, m; cin >> n >> m;
  map<ll, ll> ans;
  for(ll i = 0;i < n;i++)
  {
    ll k;
    cin >> k;
    for(ll j = 0;j < k;j++)
    {
      ll a; cin >> a;
      if(ans.count(a)) ans[a]++;
      else ans[a] = 1;
    }
  }
  ll flag = 0;
  for(ll i = 0;i < m;i++)
  {
    if(ans[i+1] == n) flag++;
  }
  fin(flag)
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 256
/***********Template Starts Here***********/
//copied from https://www.hackerrank.com/contests/5-days-of-game-theory/challenges/deforestation/editorial

#include <bits/stdc++.h>

#define pb push_back
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define SZ(x) ((vlong)(x).size())

using namespace std;

typedef long long vlong;

const vlong inf = 2147383647;

/***********Template Ends Here***********/
#define NODE 100005
vector<int> adj[NODE+10];

int hackenbush ( int s, int p ) {

    int res = 0;
    FOR(i,0,SZ(adj[s])-1) {
        int t = adj[s][i];

        if ( t == p ) continue;

        res ^= hackenbush ( t, s ) + 1;
    };

    return res;
}

void solution() {
    int kase;
    //scanf ( "%d", &kase );

    //assert ( kase >= 1 && kase <= 100 );
    kase = 1;
    while ( kase-- ) {
        int n;
        scanf ( "%d", &n );

      //  assert ( n >= 1 && n <= 500 );

        FOR(i,1,n) adj[i].clear();

        FOR(i,1,n-1) {
            int u, v;
            scanf ( "%d %d", &u, &v );
            adj[u].pb ( v );
            adj[v].pb ( u );			
        };

        int res = hackenbush ( 1, 0 );

        if ( res ) printf ( "Alice\n" );
        else printf ( "Bob\n" );
    }
}

int main () {

    solution();

    return 0;
}

Measured memory_bytes: 10368
n, m = map(int, input().split())
PN = 0
AC_list = [0 for i in range(n)] 
WA_list = [0 for i in range(n)] 

for i in range(m):
    p, s = input().split()
    p = int(p)

    if s == "AC" and AC_list[p-1] == 0:
        PN += WA_list[p-1]
        AC_list[p-1] = 1
    
    else:
        WA_list[p-1] += 1


print(AC_list.count(1), PN)

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

#define int long long

signed main() {
    int a, b, x; cin >> a >> b >> x;
    int l = b / x + 1;
    int r;
    if(a == 0) {
        r = 0;
    } else {
        r = (a - 1) / x + 1;
    }
    cout << l - r << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int n;cin>>n;
  int x[n],y[n],h[n];
  int b;
  for(int i = 0; n > i; i++){
    cin>>x[i]>>y[i]>>h[i];
    if(h[i]!=0)b=i;
  }
  int ansx = 0,ansy = 0, ans = 0;
  for(int i = 0; 101 > i; i++){
    for(int j = 0; 101 > j; j++){
      int tmp = -1;
      for(int z = b; b+1 > z; z++){
        int nw = abs(x[z]-i)+abs(y[z]-j)+h[z];
        tmp = nw;
      }
      
      for(int z = 0; n > z; z++){
        
        int nw = abs(x[z]-i)+abs(y[z]-j)+h[z];
        if(tmp == -1)tmp = nw;
        else if(h[z]==0&&nw >= tmp)continue;
        else if(h[z]==0){
          tmp = -1;
          break;
        }else if(tmp!=nw){
          tmp = -1;
          break;
        }
      }
      if(tmp != -1){
        if(ans < tmp){
          ansx = i;
          ansy = j;
          ans = tmp;
        }
      }
    }
  }
  cout << ansx << " " << ansy << " " << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
	int n,h1,h2,m1,m2,s1,s2;
	int time[60*60*24];
	int start, end, max=0;

	while(true){
		scanf("%d\n",&n);
		if(n==0){return 0;}
		max=0;
		for(int i=0; i<60*60*24; i++){ time[i]=0;}
		for(int i=0; i<n; i++){
			scanf("%d:%d:%d %d:%d:%d", &h1, &m1, &s1, &h2, &m2, &s2);
			start=3600*h1+60*m1+s1; end=3600*h2+60*m2+s2;
			for(int j=start; j<end; j++){ time[j]++;}
		}
		for(int i=0; i<60*60*24; i++){
			if(max<time[i]){ max=time[i];}
		}
		cout << max << endl;
	}
}

Measured memory_bytes: 1548
K=int(input())
def gcd(a,b,c):
    if a <b:
        a,b=b,a
    while a%b != 0:
        a,b= b,a%b
    if b < c:
        b,c=c,b
    while b % c != 0:
        b,c = c,b%c
    return c
x=0
for i in range(1,K+1):
    for j in range(1,K+1):

            for l in range(1,K+1):
                
                    if (i==1) or (j==1) or (l==1):
                        x+=1
                    else:
                        x += gcd(i,j,l)
print(x)


Measured memory_bytes: 69396
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int a[2020];
int b[2020];
int dp[2020][2020];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0,m=0;
    cin>>n>>m;
    for(int i=1;i<=n;++i)
        cin>>a[i];
    for(int i=1;i<=m;++i)
        cin>>b[i];
    for(int i=0;i<=n;++i)
        dp[i][0]=1;
    for(int i=0;i<=m;++i)
        dp[0][i]=1;
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
        {
            dp[i][j]=dp[i-1][j]+dp[i][j-1];
            if(a[i]!=b[j])
                dp[i][j]-=dp[i-1][j-1];
            dp[i][j]%=MOD;
            if(dp[i][j]<0)
                dp[i][j]+=MOD;
        }
    cout<<dp[n][m]<<endl;
}


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

int main(){
    int n;
    cin >> n;
    ll a[n],b[n],c[n],dpa[n],dpb[n],dpc[n];
    for(int i = 0;i < n;i ++){
        cin >> a[i] >> b[i] >> c[i];
    }
    dpa[0]=a[0];dpb[0]=b[0];dpc[0]=c[0];
    for(int i = 1;i < n;i ++){
        dpa[i] = a[i]+max(dpb[i-1],dpc[i-1]);
        dpb[i] = b[i]+max(dpa[i-1],dpc[i-1]);
        dpc[i] = c[i]+max(dpa[i-1],dpb[i-1]);
    }
    cout << max(dpa[n-1],max(dpb[n-1],dpc[n-1])) << endl;

    return 0;
}

Measured memory_bytes: 4992
#AGC020-B Ice Rink Game
"""
逆操作を考える。
何人組を作るということは、modにおける最大値と最小値を求め続けるということ。
そのような組が作れないような場合(全員が脱落するような場合)は、-1を出力。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

k = int(readline())
lst1 = list(map(int,readline().split()))
lst1.reverse()
if lst1[0] != 2:
    print(-1)
    exit()


def min_lot(value,unit):
    if value%unit == 0:
        return value//unit
    else:
        return value//unit + 1
mn = 2
mx = 3
for i in range(1,k):
    res = min_lot(mn,lst1[i])

    if not mn <= res*lst1[i] <= mx:
        print(-1)
        exit()

    mn = res*lst1[i]

    lim = (mx//lst1[i] + 1)*lst1[i] - 1
    mx = lim



print(mn,mx)

Measured memory_bytes: 84492
INF = 10**10

N, M = map(int, input().split())
costs = []
keys = []
for _ in range(M):
    A, B = map(int, input().split())
    cs = list(map(int, input().split()))
    costs.append(A)
    # 鍵を2進数化する
    key = 0
    for c in cs:
        key |= 1<<(c-1)
    keys.append(key)

# [1]の個数で分類する
maskss = [[] for _ in range(N+1)]
num1s = [0] * (2**N)
for S in range(2**N):
    num = bin(S).count('1')
    maskss[num].append(S)
    num1s[S] = num

dpAll = [INF] * (2**N)
for S in range(2**N):
    for cost, key in zip(costs, keys):
        if S & key == S:
            if cost < dpAll[S]:
                dpAll[S] = cost

dp = [INF] * (2**N)
for S in range(2**N):
    cost = dpAll[S]
    num1 = num1s[S]
    for k in range(1, (num1+1)//2+1):
        for mask in maskss[k]:
            if mask & S == mask:
                m2 = S^mask
                c2 = dp[mask] + dp[m2]
                if c2 < cost:
                    cost = c2
    dp[S] = cost

if dp[2**N-1] == INF:
    print(-1)
else:
    print(dp[2**N-1])


Measured memory_bytes: 3440
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
  int D,G;
  cin >> D >> G;
  int p[D],c[D];
  for (int n = 0; n < D; n++) {
   cin >> p[n] >> c[n];
  }
  int ans = 1e9;
  // D番目のbitまでを使う
  for(int mask = 0; mask < (1 << D);++mask){
    int s =0, num = 0,rest_max = 0;
    for(int i = 0; i < D; ++i){
      //i番目のbitが立っているか確認する
      //立っているとき問題を完全に解く
      if(mask >> i & 1){
        s += 100*(i+1)*p[i] + c[i];
        num += p[i];
      }
      //立っていないときの問題数を数える（中途半端に解く
      else
        rest_max = i;
    }
    if(s < G){
      int s1 = 100 * (rest_max + 1);
      int need = (G - s + s1 - 1)/s1;
      if(need >= p[rest_max]){
        continue;
      }
      num += need;
    }
    ans = min(num, ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AAccepted solver = new AAccepted();
        solver.solve(1, in, out);
        out.close();
    }

    static class AAccepted {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            int n = 0;
            for (char c : s.toCharArray()) {
                if (c == '1') n++;
            }
            out.println(n);
        }

    }
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int MOD = 1e9 + 7;

int n, ans = 1;
string s;
map<char, int> m;

int32_t main()
{
	IOS;
	cin>>n>>s;
	for(auto &it:s)
		m[it]++;
	for(auto &it:m)
	{
		ans = (ans * (it.second + 1));
		ans %= MOD;
	}
	ans -= 1;
	ans += MOD;
	ans %= MOD;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main{
   public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int train = scan.nextInt();
        int taxi = scan.nextInt();
        int restrain = N * train;
        int retaxi = taxi;
        
        if (restrain < retaxi) {
          System.out.println(restrain);
        } else {
          System.out.println(retaxi);
        }
        scan.close();
   }
}

Measured memory_bytes: 21588
program banned_k
  implicit none
  integer :: n, a(200000) = 0, i
  integer(8) :: b(200000) = 0, x = 0
  read(*,*) n
  read(*,*) a(1:n)
  do i = 1, n
    b(a(i)) = b(a(i))+1
  end do
  do i = 1, n
    x = x+(b(i)*(b(i)-1))/2
  end do
  do i = 1, n
    write(*,'(i0)') x-(b(a(i))-1)
  end do
end program banned_k

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

 string s;
 cin>>s;
 int n = s.length();
 int count = 0;
 REP(i,n){
  if(s[i]=='x')count++;
 }
 if(15-count>=8){
  cout<<"YES"<<endl;
 }else{
  cout<<"NO"<<endl;
 }

 

  return 0;
}

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

int a,b,c,cnt;

int main()
{
	scanf("%d%d%d",&a,&b,&c);
	if(a>b)
		printf("0");
	else
	{
		while(b>=a)
		{
			b-=a;
			cnt++;
		}
		if(cnt>=c)
			printf("%d",c);
		else
			printf("%d",cnt);
	}
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long unsigned;
typedef pair<int,int> P;
typedef vector<int> Vi;
int const MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { return a = b; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { return a = b; } return false; }



int main(){
  cin.tie(0); ios::sync_with_stdio(false);
    
  Int n; cin>>n;
  cout<<n*(n-1)/2<<'\n';
}

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

int main(){
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  int A=0,B=0;
  for(int i=0;i<N;i++){
    if(i%2==0){
      A+=vec.at(i);
    }else{
      B+=vec.at(i);
    }
  }
  
  cout<<A-B<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
int32_t main()
{	
	int n;
	cin >> n;
	if(n%10==3)
	cout << "bon";
	else if(n%10==0 || n%10==1 || n%10==6 || n%10==8)
	cout << "pon";
	else
	cout << "hon";
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<stdlib.h>

  int main(){
  int A[100];
  int i,x,y,N;
  int z=0;
  scanf("%d",&N);
for(i=0;i<N;i++){
  scanf("%d",&A[i]);
}
for(i=0;i<N;i++){ 
for(x=N-1;x>i;x--){
  if(A[x] < A[x-1]){
  y = A[x];
  A[x] = A[x-1];
  A[x-1] = y;
  z++;
  }
}
printf("%d",A[i]);
if(i!=N-1){
    printf(" ");
}
}
  printf("\n");
  printf("%d",z);
  printf("\n");
return 0;

}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }
int main(){
    ll a,b; cin>>a>>b;
    string s; cin>>s;
    if(s.size()!=a+b+1){
        cout<<"No"<<endl;
        return 0;
    }
    rep(i,a){
        if(s[i]<'0' || s[i]>'9'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    if(s[a]!='-'){
        cout<<"No"<<endl;
        return 0;
    }
    rep(i,b){
        if(s[a+1+i]<'0' || s[a+1+i]>'9'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256