akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    ans = 0
    M = N
    M = [c for c in M[::-1]]
    A = []
    M.append('0')
    carry = 0
    for i, c in enumerate(M):
        c = int(c) + carry
        carry = 0
        if c == 5 and int(M[i+1]) >= 5:
                carry += 1
                a = 0
        elif c >= 6:
            carry += 1
            a = 0
        else:
            a = c
        # A += 10**i * a
        A.append(a)
    # A += 10**(len(M)) * carry
    if carry != 0:
        A.append(carry)
    if A[-1] == 0:
        A.pop()
    A = ''.join(map(str, [c for c in A[::-1]]))

    if len(A) - len(N) > 0:
        N = ('0' * (len(A) - len(N))) + N

    carry = 0
    ans = 0
    for a, n in reversed(list(zip(A, N))):
        # print(a, n)
        a = int(a)
        ans += a
        n = int(n)
        if carry != 0:
            if a == 0:
                a = 9
                carry =1
            else:
                a -= 1
                carry = 0
        b = a - n
        if b < 0:
            b += 10
            carry = 1
        ans += b

    # print(N)
    # print(A)
    # B = int(A) - int(N)
    # for c in str(B):
    #     ans += int(c)
    # for c in str(A):
    #     ans += int(c)

    # print('   ', B)
    return ans


def main():
    N = read_str()
    print(slv(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 100400
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
int r,g,b;
cin>>r>>g>>b;

int total;
total = r*100 + g*10 + b;

if(total%4==0)
cout<<"YES"<<endl;

else
cout<<"NO"<<endl;

}

Measured memory_bytes: 256
n = int(input())
apple = []
for i in range(n):
    apple.append(str(input()))
print("AC x " + str(apple.count("AC")))
print("WA x " + str(apple.count("WA")))
print("TLE x " + str(apple.count("TLE")))
print("RE x " + str(apple.count("RE")))



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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;
	cin>>n;
	vector<int> a(n);
	for(int& x:a) cin>>x;
	int sum=accumulate(a.begin(),a.end(),0);
	int t;
	cin>>t;
	while(t--){
		int p,x;
		cin>>p>>x;
		--p;
		cout<<sum-a[p]+x<<'\n';
	}
}




Measured memory_bytes: 3640
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string S;
	std::cin >> S;
	int result = 700;
	for (auto ch : S) {
		if (ch == 'o') {
			result += 100;
		}
	}
	std::cout << result << "\n";
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <iostream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define maxn 1000010
const ll mod=1e9+7;
#define sz(a) a.size()
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef set<int> si;
#define fori(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,b,a) for(int i = (b); i >= (a); --i)
#define all(a) (a).begin(), (a).end()
#define __builtin_popcountll bitCountLL
#define __builtin_popcount bitCount
//__builtin_ctz 末尾0的个数, __builtin_clz 前导0的个数
//__builtin_ffs 最后一个1的位置
const int INF = 2e9;
const ll ML = 4e18;
ll Pow(ll x, ll p) {
    ll res = 1;
    while(p) {
        if(p & 1) res = (res * x) % mod;
        p >>= 1;
        x = (x * x ) % mod;
    }
    return res;
}
ll fac[maxn], inv[maxn];
void init() {
    fac[0] = fac[1] = 1;
    fori(i,2,maxn) fac[i] = (fac[i-1] * i) % mod;
    inv[maxn-1] = Pow(fac[maxn-1],mod-2);
    rep(i,maxn-2,0) inv[i] = (inv[i+1] * (i + 1)) % mod;
    ///inv[i]=Pow(i,mod-2);
}
ll C(int a, int b) {
    return (fac[b] * inv[a] % mod * inv[b - a] % mod) % mod;
}
ll A(int a, int b) {
    return fac[b] * inv[b-a] % mod;
}
ll cnt[maxn];
ll mul(ll a, ll b){
    return (a%mod)*(b%mod)%mod;
}
vector<int>a[maxn];
int main()
{
    init();
    int n;cin>>n;
    if(n==1)return cout<<0<<endl,0;
    ll ans=2*C(2,n)%mod;
    ll a=1,b=1,c=1;
    for(int i=1; i<=n; i++){
        a=a*10%mod;
        b=b*9%mod;
        c=c*8%mod;
    }
    a=(a-b%mod+mod)%mod;
    a=(a-b%mod+mod)%mod;
    a=(a+c%mod)%mod;
    cout<<a<<endl;
   // for(int i=1; i<=n-2; i++)ans=ans*10%mod;
   // ans=ans*A(n,n)%mod;
    //a=((a-(b*2%mod)+mod)%mod-c+mod)%mod;
    //cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 42248
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {

	// reader := bufio.NewReader(os.Stdin)
	// s, _ := reader.ReadString('\n')
	// n := eAtoi(strings.TrimSpace(s))
	// count := 0
	// prev := '@'
	// for i := 0; i < n; i++ {
	// 	r, _, _ := reader.ReadRune()
	// 	if prev != r {
	// 		count++
	// 	}
	// 	prev = r
	// }
	scanner := makeScanner(200000)
	eGetInt(scanner)
	s := eGetLine(scanner)
	count := 0
	prev := '@'
	for _, r := range s {
		if prev != r {
			count++
		}
		prev = r
	}
	fmt.Println(count)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeCharScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanRunes)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 896
n,m = map(int,input().split())
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if a[i+k][j:j+m] != b[k]:
                break
        else:
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,a,b;
  cin>>n>>a>>b;
  int x[n];
  for(int i=0;i<n;i++) cin>>x[i];
  int ans=0;
  for(int i=0;i<n-1;i++)
    ans+=min((x[i+1]-x[i])*a,b);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#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>;


const int mod = 1e9+7;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

int main(){
   int n;   
   cin >> n;
   vector<ll> c(n);
   rep(i,n) cin >> c[i];
   sort(c.begin(),c.end());
   vector<mint> two(n+1);
   two[0] = 1;
   rep(i,n) two[i+1] = two[i]*2;

   mint ans;
   rep(i,n){
      int l = i, r = n-1-i;
      mint now = two[r];
      if(r != 0) now += two[r-1]*r;
      now *= two[l];
      now *= c[i]; 
      ans += now;
   }

   ans *= two[n];

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

Measured memory_bytes: 3328
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mi = 10**6
for i in range(M):
  x, y, c = map(int, input().split())
  tmp = a[x-1] + b[y-1] - c
  if mi > tmp:
    mi = tmp
a.sort()
b.sort()
tmp = a[0] + b[0]
if mi > tmp:
  mi = tmp
print(mi)


Measured memory_bytes: 18684
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner kbScanner = new Scanner(System.in);
		
		int num1 = kbScanner.nextInt();
		int num2 = kbScanner.nextInt();
		String symbol;
		
		if(num1 > num2){
			symbol = "a > b";
		}else if(num1 < num2){
			symbol = "a < b";
		}else{
			symbol = "a == b";
		}
		
		System.out.println(symbol);
	}
}

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

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

    if(s[0] != 'A'){
        cout << "WA" << endl;
        return 0;
    }

    int count = 0;
    int rec;
    for(int i=2; i<s.length()-1; i++){
        if(s[i] == 'C'){
            count += 1;
            rec = i;
        }
    }
    if(count != 1){
        cout << "WA" << endl;
        return 0;
    }

    for(int i=1; i<s.length(); i++){
        if(i == rec) continue;
        if(islower(s[i]) == 0){
            cout << "WA" << endl;
        return 0;
        }
    }    

    cout << "AC" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int m, n1, n2;
void solve() {
    int p[202];
    rep(i, m) cin >> p[i];
    int ans = n1;
    for (int i = n1; i <= n2; i++) {
        if (p[i - 1] - p[i] >= p[ans - 1] - p[ans]) {
            ans = i;
        }
    }
    cout << ans << endl;
}
int main() {
    while (cin >> m >> n1 >> n2) {
        if (m == 0) break;
        solve();
    }
    return 0;
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
// #define SORT(v, n) stable_sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

// WA
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(5);
    int n;
    cin >> n;
    ll h[n];
    rep(i, n) { cin >> h[i]; }
    h[0]--;
    bool flg = true;
    for (int i = 1; i < n; i++) {
        if (h[i - 1] < h[i]) {
            h[i] -= 1;
        }
    }
    rep(i, n - 1) {
        if (h[i] > h[i + 1]) {
            flg = false;
            break;
        }
        flg = true;
    }

    if (flg) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
int main(void)
{
	int skin=100000;
	int skin2;
	int shu;
	int i;
	scanf("%d",&shu);
	for(i=0;shu>i;i++){
		skin=skin*1.05;
			if(skin%1000!=0){
		skin2=skin%1000;
		skin=skin-skin2+1000;
	}


	}



		printf("%d\n",skin);
	return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int32 N;
vector<int32> G[101];

PII calc(int32 v1, int32 v2){
	vector<int32> out(N+1, 0);
	vector<int32> leaf(N+1, 0);
	vector<int32> d(N+1, INF);
	d[v1] = d[v2] = 0;
	int32 maxd = 0;
	function<void(int32, int32, int32)> dfs = [&](int32 v, int32 p, int32 dd){
		d[v] = dd;
		maxd = max(maxd, dd);
		if(G[v].size() == (v != p)){
			chmax(leaf[dd], 1);
			chmax(out[dd], 0);
			return;
		}
		chmax(out[dd], G[v].size()-(v != p));
		REP(i, G[v].size()){
			if(G[v][i] == p) continue;
			dfs(G[v][i], v, dd+1);
			chmax(leaf[dd], leaf[dd+1]*out[dd]);
		}
	};
	dfs(v1, v2, 0);
	dfs(v2, v1, 0);
	int32 res = 0;
	res = leaf[0]*(v1 != v2 ? 2 : 1);
	return PII(maxd, res);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	REP(i, N-1){
		int32 a, b;
		cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	PII res(INF, INF);
	REP(i, N){
		chmin(res, calc(i, i));
		REP(j, G[i].size()){
			chmin(res, calc(i, G[i][j]));
		}
	}
	cout << res.fs+1 << " " << res.sc << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=1e6+5;
int n,k,a[N],b[N],c[N];

signed main(){
	read(n,k);
	if(n<2*k-1) return write(-1),0;
	int s=(n+1>>1)*3;
	if(n&1) s--;
	for(int i=1,x=1,y=s;i<=n;i++,x+=2,y--){
		a[i]=x;b[i]=y;
		if(x+2>=y-1) x=0,y=2*n+1;
	}
	for(int i=1;i<=n;i++) c[i]=2*n+i;
	for(int i=1;i<=n;i++) printf("%d %d %d\n",a[i]+k-1,b[i]+k-1,c[i]+k-1);
}

Measured memory_bytes: 4852
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

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

	rep(i,s.size()){
		s = s.back() + s.substr(0, s.size() - 1);
		if(t == s){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


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

using namespace std;

int N;
vector<int> HomeId;

int main() {
	int x;

	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> x;
		HomeId.push_back(x);
	}
	sort(HomeId.begin(), HomeId.end());
	cout << HomeId[N - 1] - (HomeId[0] + HomeId[N - 1]) / 2 << endl;

	return 0;
}


Measured memory_bytes: 3152
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin >> s;
    string ans = "No";
    string k="Yes";
    string g="Yes";
    for(int i=0; i < s.size(); i++){
        if(i % 2 == 0){
            if(!(s[i] == 'R' || s[i] == 'U' || s[i] == 'D')) k = "No";
        }
        else{
            if(!(s[i] == 'L' || s[i] == 'U' || s[i] == 'D')) g = "No";
        }
    }
    if(g == "Yes" && k == "Yes") ans = "Yes";
    cout << ans << endl;
}


Measured memory_bytes: 256
#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>;
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b; 
return true; } return false; }
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b; 
return true; } return false; }
const int MX = 1000005;

int main(){
    int n;
    ll w,weight[110],value[110];
    ll dp[110][100100];
    cin>>n>>w;
    rep(i,n)cin>>weight[i]>>value[i];

    rep(i,n){
        rep(j,w+1){

            if(j-weight[i]>=0){
                chmax(dp[i+1][j],dp[i][j-weight[i]]+value[i]);
            }
            chmax(dp[i+1][j],dp[i][j]);
        }
    }
    cout<<dp[n][w]<<endl;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, K;
int A[int(2e5 + 5)];
int main(){
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> A[i];

  for (int i = K; i < N; i++){
    if (A[i - K] < A[i]) Yes();
    else No();
  }

  return 0;
}


Measured memory_bytes: 4412
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n;
bool ask(vector<ll> v){
  cout<<"? ";
  for(int i=0;i<v.size();i++) cout<<v[i]<<(i==v.size()-1?"\n":" ");
  string s;
  cin>>s;
  return s=="Red";
}
vector<ll> make_seq(ll x){
  vector<ll> ret;
  for(int i=0;i<n;i++) ret.push_back(x+i);
  return ret;
}
int main(){
  cin>>n;
  if(n==1){
    cout<<"? 1"<<endl;
    string s;
    cin>>s;
    if(s=="Red"){
      cout<<"! RB"<<endl;
    }
    else cout<<"! BR"<<endl;
  }
  ll lb=1,rb=n+1;
  bool a1=ask(make_seq(1));
  bool a2=~a1;
  ll ans[205]={0};
  while(rb-lb>1){
    ll mid=(lb+rb)/2;
    bool f1=ask(make_seq(mid));
    bool f2=ask(make_seq(mid+1));
    if(f1!=f2){
      lb=mid;
      if(f1==a1){
        ans[lb]=(a1?1:2);
        ans[lb+n]=(a1?2:1);
      }
      else{
        ans[lb]=(a1?2:1);
        ans[lb+n]=(a1?1:2);
      }
      break;
    }
    else{
      if(f1==a1) lb=mid;
      else rb=mid;
    }
    if(rb-lb==1){
      bool f3=ask(make_seq(lb));
      if(f3==a1){
        ans[lb]=(a1?1:2);
        ans[lb+n]=(a1?2:1);
      }
      else{
        ans[lb]=(a1?2:1);
        ans[lb+n]=(a1?1:2);
      }
    }
  }

  vector<ll> non_decide,decide;
  for(int i=1;i<=2*n;i++){
    if(i==lb||i==lb+n) continue;
    if(i<lb||i>lb+n) non_decide.push_back(i);
    else decide.push_back(i);
  }


  ll c1=0,c2=0;
  for(int i=0;i<non_decide.size()-1;i++){
    cout<<"? "<<non_decide[i]<<" ";
    for(int j=0;j<n-1;j++) cout<<decide[j]<<(j==n-2?"\n":" ");

    string s;
    cin>>s;
    bool f=(s=="Red");

    if(f){
      ans[non_decide[i]]=1;
      c1++;
    }
    else{
      ans[non_decide[i]]=2;
      c2++;
    }
  }
  int ina=non_decide.size();
  if(c1<c2){
    ans[non_decide[ina-1]]=1;
  }
  else ans[non_decide[ina-1]]=2;

  vector<ll> r,b;
  for(int i=1;i<=2*n;i++){
    if(ans[i]==1) r.push_back(i);
    else if(ans[i]==2) b.push_back(i);
  }
  int d1=0,d2=0;
  int kn=(n-1)/2;
  for(int i=0;i<decide.size()-1;i++){
    cout<<"? "<<decide[i]<<" ";
    for(int j=0;j<kn;j++) cout<<r[j]<<" ";
    for(int j=0;j<kn-1;j++) cout<<b[j]<<" ";
    cout<<b[kn-1]<<endl;

    string s;
    cin>>s;
    if(s=="Red") {
      ans[decide[i]]=1;
      d1++;
    }
    else{
      ans[decide[i]]=2;
      d2++;
    }
  }
  cout<<"! ";
  for(int i=1;i<=2*n;i++){
    if(ans[i]==0){
      if(d1<d2) cout<<"R";
      else cout<<"B";
    }
    else cout<<(ans[i]==1?"R":"B");
  }
  cout<<endl;
}


Measured memory_bytes: 724
import java.util.*;

public class Main {
	static long MOD = 1000000007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] x = new int[N];
		for(int i=0; i<N; i++)
			x[i] = sc.nextInt();
		int[] y = new int[M];
		for(int i=0; i<M; i++)
			y[i] = sc.nextInt();
		
		System.out.println((calc(x)*calc(y))%MOD);
		
		sc.close();
	}
	
	static long calc(int[] p) {
		int N = p.length;
		long ans = 0;
		for(int i=0; i<N-1; i++) {
			long mul = ((long)(i+1)*(N-1-i))%MOD;
			ans = (ans + mul*(p[i+1]-p[i]))%MOD;
		}
		return ans;
	}
}


Measured memory_bytes: 65704
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scanner = new Scanner(System.in);
		
		String inputN = scanner.nextLine();
		String inputA = scanner.nextLine();

		scanner.close();
		
		Integer inN = Integer.parseInt(inputN);
		List<Integer> inA = Arrays.asList( inputA.split(" ") ).stream().map(x -> Integer.parseInt(x) ).collect(Collectors.toList());
		
		Integer[] ls = new Integer[inA.size()];
		Integer[] rs = new Integer[inA.size()];
		
		int acm = inA.get(0);
		ls[0] = acm;
		
		// create accumulation list
		for(int i = 1; i < inN; i++) {
			acm = calc(acm, inA.get(i));
			ls[i] = acm;
		}

		acm = inA.get(inN - 1);
		rs[0] = acm;
		int j = 1;
		for(int i = inN - 2; i >= 0; i--) {
			acm = calc(acm, inA.get(i));
			rs[j] = acm;
			j++;
		}

		
		int max = 0;
		
		for(int i = 0; i< inN; i++) {
			
			if(i == inN - 1) {
				int val = ls[inN - 2];
				if(val > max) {
					max = val;
				}
			}
			else if(i == 0) {
				int val = 	rs[inN - 2];
				
				if(val > max) {
					max = val;
				}
			} else {
				int x,y;
				if(ls[i - 1] >  rs[(inN - 1) - i - 1]) {
					x = ls[i - 1];
					y = rs[(inN - 1) - i - 1];
				} else {
					y = ls[i - 1];
					x = rs[(inN - 1) - i - 1];
				}
				int val = 	calc( x, y ) ;
				if(val > max) {
					max = val;
				}
			}
		}
		
		System.out.println(max);
	}
	
	private static int calc(int x, int y) {
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }
        
        return y;
	}
}

Measured memory_bytes: 53736
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>
 
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n,m;
  cin >> n >> m;
  vector<ll> a(m);
  vector<bool> abool(n+1,false);
  bool flag = false;
  vector<ll> w(n+1,0);
  REP(i,m) {
    cin >> a[i];
    abool[a[i]] = true;
    flag = i != 0 && a[i]-a[i-1]==1;
  }
  if (flag) {
    cout << 0 << endl;
    return 0;
  }

  for (int i = n; i >= 0; i--) {
    if (abool[i]) continue;
    if (i == n || i == n-1) 
    {
      w[i] = 1;
    }
    else {
      w[i] =  (w[i+1]+w[i+2])%(ll)(pow(10,9)+7);
    }
  }
  cout << w[0] << endl;
  return 0;
}


Measured memory_bytes: 1792
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = [1]
    a = 1
    check = [0] * len(A)
    while True:
        a = A[a - 1]
        if check[a - 1] == 1:
            x = B.index(a)
            roop = B[x:]
            print(roop[(K - x) % len(roop)])
            exit()
        B.append(a)
        check[a - 1] += 1
        if len(B) >= K + 1:
            print(B[K])
            exit()
if __name__ == '__main__':
    main()

Measured memory_bytes: 31396
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;


void array_show(int *a,int n){
	for(int i=0;i<n;i++)printf("%d%c",a[i],(i!=n-1?' ':'\n'));
}
void array_show(LL *a,int n){
	for(int i=0;i<n;i++)printf("%lld%c",a[i],(i!=n-1?' ':'\n'));
}

bool good[25][25];
int s[1<<22];

int main(){
	int n;
	int i,j,k;
	int a,b,c;
	cin>>n;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			cin>>a;
			if(a==1)good[i][j]=true;
		}
	}
	s[0]=1;
	for(i=0;i<(1<<n);i++){
		for(j=0,k=1,a=0;j<n;j++,k<<=1){
			if(i&k)a++;
		}
		for(j=0,k=1;j<n;j++,k<<=1){
			if(!good[a][j])continue;
			if(i&k)continue;
			s[i+k]+=s[i];
			if(s[i+k]>=MAX)s[i+k]%=MAX;
		}
	}
	cout<<s[(1<<n)-1]<<endl;
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, n) {
        int tmp_a;
        cin >> tmp_a;
        ++mp[tmp_a];
    }
    int cnt = 0;
    for ( auto tmp_mp : mp ) {
        if ( tmp_mp.second >= 2 ) {
            cnt += tmp_mp.second - 1;
        }
    }
    if ( cnt&1 ) {
        cout << mp.size() - 1 << endl;
    }
    else {
        cout << mp.size() << endl;
    }
    return 0;
}


Measured memory_bytes: 4992
c = [list(map(int, input().split())) for i in range(3)]
print("Yes" if c[0][0] + c[1][2] + c[2][1] == c[2][2] + c[0][1] + c[1][0] == c[0][2] + c[1][1] + c[2][0] else "No")

Measured memory_bytes: 3064
s = list(input())
v = ["N", "W", "S", "E"]
a, b = 0, 0
for i in range(4):
    if v[i] in s:
        if i % 2 == 0:
            a += 1
        else:
            b += 1
print("Yes" if a % 2 == b % 2 == 0 else "No")

Measured memory_bytes: 3060
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto S = readln.chomp;
    auto LR = M.iota.map!(_ => readln.split.map!(a => a.to!int - 1).array).array;

    auto zeros = new long[](N+1);
    foreach (i; 0..N) {
        zeros[i+1] = zeros[i] + (S[i] == '0');
    }

    auto dp = new long[][](N+1, N+1);
    dp[0][0] = 1;
    int rmax = 0;
    int q = 0;

    foreach (i; 0..N) {
        while (q < M && LR[q][0] <= i) {
            rmax = max(LR[q][1], rmax);
            q += 1;
        }
        rmax = max(rmax, i);
        long zero = zeros[rmax+1];
        long one = rmax + 1 - zero;

        foreach (j; 0..i+1) {
            long rest_zero = zero - j;
            long rest_one = one - (i - j);
            if (rest_zero < 0 || rest_one < 0) {
                continue;
            }
            if (rest_zero > 0) {
                dp[i+1][j+1] += dp[i][j];
                dp[i+1][j+1] %= MOD;
            }
            if (rest_one > 0) {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j+1] %= MOD;
            }
        }
    }

    long ans = 0;
    foreach (a; dp[N]) {
        ans += a;
        ans %= MOD;
    }

    ans.writeln;
}


Measured memory_bytes: 74876
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int K, A, B;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> K >> A >> B;

	rep(x, A, B + 1) if (x % K == 0) {
		cout << "OK" << endl;
		return;
	}
	cout << "NG" << endl;
}







Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;

ll MAX=1000005;
vector<ll> F(MAX,1);
 
void fact(){
    for(ll i=1;i<MAX;i++){
    F[i]=F[i-1]*i%MOD;
    }
return;
}


// mod. m での a の逆元 a^{-1} を計算する
//ただしmとaが互いにその時のみ
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long comb(long long a, long long b){
    return (((F[a]*modinv(F[b],MOD))%MOD)*modinv(F[a-b],MOD))%MOD;
}

//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓

int main(){
    fact();
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    vector<ll> A(N,0);
    for(ll i=0;i<N;i++){
        cin>>A[i]
    ;}
    ll ans=0;
    sort(A.begin(), A.end());
    for(ll i=K-1;i<=N-1;i++){
        ans+=A[i]*comb(i,K-1);
        ans%=MOD;
    }
    for(ll i=0;i<=N-K;i++){
        ans-=A[i]*comb(N-i-1,K-1);
        if(ans<0){
            ans=MOD-((-ans)%MOD);
        }
        else  ans%=MOD;
    ;}
    cout<<ans%MOD<<endl;


    return 0;
}


Measured memory_bytes: 8832
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(){
    int h, w, cnt = 0;
    cin >> h >> w;
    vector<vector<int>> a(h + 1, vector<int>(w + 1));
    vector<string> ans;
    string s;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 1; i <= h; i++){
        if(i % 2 == 1){
            for(int j = 1; j <= w; j++){
                if(i == h && j == w) break;
                if(a[i][j] % 2 == 1){
                    if(j < w){
                        a[i][j]--; a[i][j + 1]++;
                        s =  to_string(i) + " " + to_string(j) + " " + to_string(i) + " " + to_string(j + 1);
                        ans.push_back(s);
                        cnt++;
                    }else{
                        a[i][j]--; a[i + 1][j]++;
                        s =  to_string(i) + " " + to_string(j) + " " + to_string(i + 1) + " " + to_string(j);
                        ans.push_back(s);
                        cnt++;
                    }
                }
            }
        }else{
            for(int j = w; j >= 1; j--){
                if(i == h && j == 1) break;
                if(a[i][j] % 2 == 1){
                    if(j > 1){
                        a[i][j]--; a[i][j - 1]++;
                        s =  to_string(i) + " " + to_string(j) + " " + to_string(i) + " " + to_string(j - 1);
                        ans.push_back(s);
                        cnt++;
                    }else{
                        a[i][j]--; a[i + 1][j]++;
                        s =  to_string(i) + " " + to_string(j) + " " + to_string(i + 1) + " " + to_string(j);
                        ans.push_back(s);
                        cnt++;
                    }
                }
            }
        }
    }
    cout << cnt << endl;
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 11892
#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_set>
#include <string>
#include <sstream>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <functional>
#include <math.h>

using namespace std;

namespace
{
	int solve(std::vector<int>& h, int sum, int index, std::vector<int>& memo)
	{
		int ret;
		if (index >= h.size())
		{
			return sum;
		}
		if (memo[index] != -1)
		{
			return sum + memo[index];
		}

		if (index < h.size() - 2)
		{
			ret = min(solve(h, sum + abs(h[index] - h[index + 1]), index + 1, memo), solve(h, sum + abs(h[index] - h[index + 2]), index + 2, memo));
		}
		else if(index < h.size() - 1)
		{
			ret = (solve(h, sum + abs(h[index] - h[index + 1]), index + 1, memo));
		}
		else
		{
			return sum;
		}
		memo[index] = ret - sum;
		return ret;
	}
}
int main()
{
	int N;
	std::cin >> N;

	std::vector<int> h;
	for (int i = 0; i < N; i++)
	{
		int in;
		cin >> in;
		h.push_back(in);
	}
	std::vector<int> memo(N, -1);
	int sol = solve(h, 0, 0, memo);

	std::cout << sol;
	return 0;
}

Measured memory_bytes: 8000
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

long double eps = 1e-10;

int main() {
  while(1){
    int n,l;
    cin>>n>>l;
    if(!n)break;
    vector<int> a(86401);
    REP(i,n) {
      int s,t,u;
      cin>>s>>t>>u;
      a[s] += u;
      a[t] -= u;
    }
    vector<int> sum(86401);
    partial_sum(begin(a),end(a),begin(sum));
    long double ll = 0.0, lh = 1000000.0;
    while(lh - ll > 1e-8) {
      long double mid = (lh + ll) / 2;
      long double tank = l;
      bool ok = true;
      REP(i,86400){
        tank += mid;
        tank -= sum[i];
        if (tank < 0.0) ok = false;
        tank = min(tank, (long double)l);
      }
      long double oldt = tank;
      REP(i,86400){
        tank += mid;
        tank -= sum[i];
        if (tank < 0.0) ok = false;
        tank = min(tank, (long double)l);
      }
      if(!ok || tank + eps < oldt) ll = mid;
      else lh = mid;
    }
    cout<<setprecision(10)<<fixed<<lh<<endl;
  }
  return 0;
}

Measured memory_bytes: 1904
#include<iostream>
#include<string>
#include<algorithm>

int n = 0, a[100001], b[100000];
long long ans = 0;

int main() {

	std::cin >> n;

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

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

	for (int i = 0; i < n; i++) {

		if (a[i] >= b[i]) {
			ans += b[i];
		}
		else if (a[i + 1] + a[i] > b[i]) {
			ans += b[i];
			a[i + 1] = a[i + 1] + a[i] - b[i];
		}
		else {
			ans += a[i + 1] + a[i];
			a[i + 1] = 0;
		}
	}
	std::cout << ans << std::endl;
}

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

int main() {
    int h, w, i;
    cin >> h >> w;
    string s[h];
    for (i = 0; i < h; i++){
        cin >> s[i];
    }

    for (i = 0; i < w+2; i++){
        cout << "#";
    }
    cout << endl;

   for (i = 0; i < h; i++){
       cout << "#" << s[i] << "#" << endl;
   }

   for (i = 0; i < w + 2; i++){
       cout << "#";
   }
   cout << endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n,m; cin>>n>>m;
    vector<int> a(n);
    ll s = 0;
    rep(i,n) cin>>a[i], s+=a[i];

    int cnt = 0;
    rep(i,n) {
        if (4*m*a[i] >= s) cnt++;
    }

    if (cnt >= m) {
        cout << "Yes" << '\n';
    }
    else cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 256
//g++ main.cpp -I /usr/local/include/ac-library
#include<cmath>
#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using namespace atcoder;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    int n,m;
    cin >> n>> m;
    scc_graph ss(n);
    rep(i,m){
        int a,b;
        cin >> a>> b;
        ss.add_edge(a,b);
    }
    vector<vector<int>> ans=ss.scc();
    cout<<ans.size()<<endl;
    rep(i,ans.size()){
        cout<<ans[i].size()<<" ";
        rep(j,ans[i].size()){
            cout<<ans[i][j];
            if(j==ans[i].size()-1)cout<<endl;
            else cout<<" ";
        }
    }
    return 0;
}

Measured memory_bytes: 40068
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a)  (a).begin(),(a).end()
 
const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;
 
template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}
 
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


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


    ll ans = c - (a-b);
    if (ans<0)ans=0;

    cout << ans;

}


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

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))
#define VI(v,n) vector<int> v(n);REP(i,n){assert(0<scanf("%d",&v[i]));}

int main(){
  INT(n); INT(m); VI(as, n);
  vector<pair<int, int>> vp;
  REP(m){
    INT(b); INT(c);
    vp.EB(c, b);
  }
  sort(as.begin(), as.end());
  sort(vp.rbegin(), vp.rend());
  vector<int> cs;
  int cnt = 0;
  for(auto p: vp){
    int c = p.first, b = p.second;
    REP(b){
      cs.PB(c); cnt++;
      if (cnt == n){break;}
    }
    if (cnt == n){break;}
  }
  REP(i, n){
    if (as[i] < cs[i]){
      as[i] = cs[i];
    } else {
      break;
    }
  }
  ll ans = 0;
  for (int a: as){ans += a;}
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 2292
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

int main() {
	string s;
	cin >> s;
	int n = s.size();
	long long ans = 1;
	map < char, int > cnt;
	for (int i = n - 1; i >= 0; i--) {
		cnt[s[i]]++;
		ans += i + 1;
		ans -= cnt[s[i]];
	}
cout << ans << endl;
}

Measured memory_bytes: 888
import math


def eratos(num):
    isPrime = [True] * (num + 1)
    isPrime[0] = isPrime[1] = False
    for i in range(2, int(math.sqrt(num))):
        for j in range(2 * i, num, i):
            isPrime[j] = False
    return isPrime


def isLike(isPrime):
    n = len(isPrime)
    array = [False] * (n - 1)
    for i in range(n - 1):
        if isPrime[i] and isPrime[(i + 1) // 2]:
            array[i] = True
    return array


def cumSum(array):
    n = len(array)
    cum = [0] * (len(array))
    for i in range(1, n):
        cum[i] = cum[i - 1]
        cum[i] += 1 if array[i] else 0

    return cum


def solve(l, r, cum):
    return cum[r] - cum[l - 1]


Q = int(input())

isPrime = eratos(10 ** 5 + 1)
array = isLike(isPrime)
cum = cumSum(array)

for i in range(Q):
    l, r = map(int, input().split())
    print(solve(l, r, cum))


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

int main() {

	//initialize
	int N;
    int A[200];
    bool odd_is_included = false;
    int counter = 0;

    // input
    cin >> N;
    for (int i = 0; i < N; ++i) {
    	cin >> A[i];
    }

    while(true){

		// check
	    for (int i = 0; i < N; ++i) {
	    	if (A[i] % 2 == 1) odd_is_included = true;
	    }

	    if(odd_is_included){
	    	cout << counter << endl;
	    	break;

	    }else{
	    	for (int i = 0; i < N; ++i) {
	    		A[i] /= 2;
	    	}
    		++counter;	
	    }

	}

}

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

typedef long long int ll;

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

int main() {
  int n;
  cin >> n;
  vector<double> a(n);
  rep(i,n) cin >> a[i];
  double s = 0;
  rep(i,n) s += a[i];
  s = s / n;
  int ans = 0;
  rep(i,n) {
    if (abs(s - a[ans]) > abs(s - a[i]) + 0.0005) {
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}

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


int main(){
  int N, K;
  cin >> N >> K;
  map<int, int> A;
  rep(i, N) A[i] = 0;
  rep(i, K){
    int d;
    cin >> d;
    rep(j, d){
      int a;
      cin >> a;
      a--;
      A[a]++;
    }
  }
  int ans = 0;
  for (auto a : A){
    if (a.second == 0) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3612