akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	i, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return float64(i)
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

const Mod = 1000000007

func ModComb(n, k int) int {
	if k == 0 {
		return 1
	}
	x, y := n, k
	for i := 1; i < k; i++ {
		x = x * (n - i) % Mod
		y = y * (k - i) % Mod
	}
	inv := ModInv(y)
	return x * inv % Mod
}

func ModFact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % Mod
	}
	return fact
}

func ModInv(x int) int {
	return ModPow(x, Mod-2)
}

func ModPow(a, n int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % Mod
		}
		a = a * a % Mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}

func intSliceReverse(slice []int) []int {
	for i, j := 0, len(slice)-1; i < j; i, j = i+1, j-1 {
		slice[i], slice[j] = slice[j], slice[i]
	}
	return slice
}

func stringReverse(str string) string {
	runes := []rune(str)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func main() {
	sc.Split(bufio.ScanWords)

	a, b := readInt64(), readfloat64()

	ans := (a * int64(b*100+0.5)) / 100
	fmt.Printf("%d\n", ans)
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ankit
 */
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);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int x[] = {1, 3, 5, 7, 8, 10, 12};
            int y[] = {4, 6, 9, 11};
            int z = 2;
            int a = in.nextInt();
            int b = in.nextInt();
            if (a == z || b == z) {
                System.out.print("No");
                return;
            }
            boolean ok1 = false, ok2 = false, ok3 = false, ok4 = false;
            for (int i = 0; i < 7; i++) {
                if (a == x[i]) {
                    ok1 = true;
                }
                if (b == x[i]) {
                    ok2 = true;
                }
                if (ok1 && ok2) {
                    System.out.println("Yes");
                    return;
                }
            }
            for (int i = 0; i < 4; i++) {
                if (a == y[i]) {
                    ok3 = true;
                }
                if (b == y[i]) {
                    ok4 = true;
                }
                if (ok3 && ok4) {
                    System.out.println("Yes");
                    return;
                }
            }
            System.out.println("No");
        }

    }
}



Measured memory_bytes: 23636
#include<iostream>
#include<cmath>
#include <iomanip>

// std::cout.setf(std::ios::right, std::ios::adjustfield);
using namespace std;

int main(){
  long long H;
  cin >> H;
  long long counter=0;
  while(H>0) {
    counter++;
    H = H/2;
  }
  // printf("%12ld\n", pow(2, counter)-1);
  // cout << fixed << setprecision(15) << pow(2, counter)-1 << endl;
  std::cout.setf(std::ios::left, std::ios::adjustfield);
  cout << setw(25) << setprecision(15) << pow(2, counter)-1 << endl;
  return 0;
}

Measured memory_bytes: 256
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
x,y=n1()

def comb(n,k):
    nCk = 1
    MOD = 10**9+7

    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk

if (x+y)%3!=0:
    print(0)
else:
    n=(x+y)//3
    if x-n>=0 and y-n>=0:
        ans=comb(n,x-n)
        print(ans)
    else:
        print(0)

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

int main() {
	int n; cin >> n;
	long long ans = 0;
	vector<int> m(n + 1);
	for (int i = 0; i < n + 1; i++) {
		cin >> m[i];
	}
	for (int i = 0; i < n; i++) {
		int b; cin >> b;
		ans += min(b, m[i] + m[i+1]);
		m[i+1] -= min(b, m[i]+m[i+1])-min(b,m[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
a=input().split()
N=int(a[0])
M=int(a[1])
X=int(a[2])
list1=[]
for i in range(N) :
  k=input().split()
  k=[int(j) for j in k]
  list1.append(k)

flag1=True
def count(item,i) :
  count1=0
  for a in item :
    count1+=a[i]
  return count1

def algo(item,i) :

  for j in range(1,i+1) :
    if count(item,j)<X :
      return False
  return True


import itertools
value_list=[]
for i in range(1,N+1) :
  c=list(itertools.combinations(list1,i))


  for item in c :
    item1=list(item)


    if algo(item1,M) :
      value_list.append(count(item1,0))

if value_list!=[] :
  print(min(value_list))
else :
  print('-1')


Measured memory_bytes: 69188
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll N;
string A, B, C;

int main() {
	cin >> N;
	cin >> A >> B >> C;
	ll ans = 0;
	for (ll n = 0; n < N; n++) {
		if (A[n] == B[n] && B[n] == C[n])continue;
		else if (A[n] == B[n] || B[n] == C[n] || C[n] == A[n])ans++;
		else ans += 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,a,b,res[1<<17];
int p[25][25];
int calc(int s)
{
	int ans=0;
	while(s)
	{
		if(s&1)ans++;
		s>>=1;
	}
	return ans;
}
void solve(int*res,int n,int a,int b)
{
	if(n==1)
	{
		res[0]=a;
		res[1]=b;
		return;
	}
	b^=a;
	int p=n-1;
	while(((1<<p)&b)==0)p--;
	b^=(1<<p);
	b^=(1<<(n-1));
	int mid=1;
	while((mid|(1<<(n-1)))==b)mid<<=1;
	solve(res,n-1,0,mid);
	solve(res+(1<<(n-1)),n-1,res[(1<<(n-1))-1],b^(1<<(n-1)));
	for(int i=0;i<(1<<(n-1));i++)
	  res[i|(1<<(n-1))]+=(1<<(n-1));
//	printf("n=%d,a=%d,b=%d:",n,a,b);
//	for(int i=0;i<(1<<n);i++)
//	  printf("%d ",res[i]);
//	printf("\n");
	for(int i=0;i<(1<<n);i++)
	{
		int x=(res[i]&(1<<p));
		int y=(res[i]&(1<<(n-1)));
		res[i]^=x,res[i]^=y;
		swap(x,y);
		x>>=(n-1-p),y<<=(n-1-p);
		res[i]^=x,res[i]^=y;
		res[i]^=a;
	}
}
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	if(calc(a^b)%2==0)
	{
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	solve(res,n,a,b);
	for(int i=0;i<(1<<n);i++)
	  printf("%d ",res[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int a,b,c,d,k;
  cin>>a>>b>>c>>k;
  d=max({a,b,c});
  a=a+b+c-d;
  cout<<a+d*pow(2,k)<<endl;
}

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

int main() {
	int n; cin >> n;
	vector<int>a(n + 2, 0);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	int sum = 0; for (int i = 1; i < a.size(); i++) { sum += abs(a[i] - a[i - 1]); }

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = sum + abs(a[i - 1] - a[i + 1]) - (abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1]));
		cout << ans << endl;
	}

	return 0;
}

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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_6_A

int main() {
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++) cin >> arr[i];
	cout << arr[n - 1];
	for (int i = n - 2; i >= 0; i--)
		cout << " " << arr[i];
	
	cout << endl;
	return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int N, M; cin >> N >> M;
  double sp = pow(0.5, M);
  int cnt = 1;
  int ans = (1900 * M + 100*(N-M)) * pow(2, M);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int N  = 100010, M = 200010;

int a[N], h[N], ne[M], e[M], idx;

bool sta[N];

void add(int x, int y){
	e[idx] = y, ne[idx] = h[x], h[x] = idx++;
}

bool dfs(int u){
	for (int i = h[u]; i != -1; i = ne[i]){
		int j = e[i];
		if (a[j] >= a[u]) return false;
	}
	return true;
}

int main(){
	int n, m;
	scanf("%d%d",&n,&m);
	for (int i = 1 ;i <= n; i++){
		scanf("%d",&a[i]);
	}

	memset(h,-1,sizeof h);

	for (int i = 0; i < m; i++){
		int x, y;
		scanf("%d%d",&x,&y);
		sta[x] = true;
		sta[y] = true;
		add(x,y),add(y,x);
	}

	int res  = 0;
	for (int i = 1; i <= n; i++){
		if (!sta[i]) res ++;
		else{
			if (dfs(i)) res ++;
		}
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 6264
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
int main() {
	int a;
	std::cin >> a;
	if (a == 3 || a == 5 || a == 7) {
		std::cout << "YES" << std::endl;
	}
	else {
		std::cout << "NO" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int main() {
	int x, y; read(x), read(y);
	puts(abs(x-y) <= 1 ? "Brown" : "Alice");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;


int main() {
	ll x;
	cin >> x;
	ll ans = (x / 11) * 2;
	x %= 11;
	if (x && x <= 6)
		++ans;
	else if (x > 6)
		ans += 2;
	cout << ans << "\n";
	return 0;
}




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

bool judge(string str){
    int n = str.length();
    bool jud = true;
    for(int i=0;i<(n-1/2);i++){
        if(str[i] != str[n-1-i]){
            jud = false;
            break;
        }
    }
    return jud;
}

int main(){   
    string s;
    cin >> s;
    int n = s.length();
    bool strong = true;

    if(!judge(s)) strong = false;
    if(!judge(s.substr(0,(n-1)/2))) strong = false;
    if(!judge(s.substr((n+3)/2 - 1,(n-3)/2 + 1))) strong = false;

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


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

struct SegmentTree {
    vector< V<int> > data;
    int n;

    SegmentTree(vector< V<int> > vec) {
        int sz = vec.size();
        n=1;
        while(n<sz) n*=2;
        data.resize(2*n-1, V<int>(26, 0));

        for (int i=0; i<sz; i++) data[i+n-1] = vec[i];
        for (int i=n-2; i>=0; i--) {
            for (int j = 0; j < 26; j++) {
                data[i][j] = data[2 * i + 1][j] | data[2 * i + 2][j];
            }
        }
    }

    void update(int x, V<int> val) {
        x += (n-1);
        data[x] = val;
        while(x > 0) {
            x = (x-1) / 2;
            for (int i = 0; i < 26; i++) {
                data[x][i] = data[2 * x + 1][i] | data[2 * x + 2][i];
            }
        }
    }

    V<int> query(int l, int r) {
        V<int> ret(26, 0);
        l += (n-1), r += (n-1);
        while (l < r) {
            if ((l & 1LL) == 0LL) {
                for (int i = 0; i < 26; i++) {
                    ret[i] |= data[l][i];
                }
                // ret = min(ret, data[l]);
            }
            if ((r & 1LL) == 0LL) {
                for (int i = 0; i < 26; i++) {
                    ret[i] |= data[r - 1][i];
                }
                // ret = min(ret, data[r-1]);
            }
            l /= 2;
            r = (r-1) / 2;
        }
        return ret;
    }    
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    V< V< int > > cc(n, V<int>(26, 0));
    for (int i = 0; i < n; i++) {
        cc[i][s[i] - 'a']++;
    }

    SegmentTree segt(cc);

    int q; cin >> q;
    for (int i = 0; i  < q; i++) {
        int t; cin >> t;
        if (t == 1) {
            int i; char c;
            cin >> i >> c;
            V<int> ch(26, 0);
            ch[c - 'a'] = 1;
            segt.update(i - 1, ch);
        } else {
            int l, r; cin >> l >> r;
            l--;
            V<int> ret = segt.query(l, r);
            cout << accumulate(ALL(ret), 0) << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 272796
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,i,j,k;
    cin>>n;
    ll ar[n],br[n];
    for(i=0;i<n;i++)
        cin>>ar[i];
    br[n-1]=ar[n-1];
    for(i=n-2;i>=0;i--){
        br[i]=ar[i]+br[i+1];
    }
    ll ans=0;
    ll m=1000000007;
    for(i=n-2;i>=0;i--){
        ans=((ans%m)+((ar[i]%m)*(br[i+1]%m))%m)%m;
    }
    cout<<ans<<endl;
}


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

double a, b, x;
const double PI = acos(-1);
double volTot;

double volumen(double x) {
  if (tan(x) <= b / a) return a * (a * a * tan(x) / 2.0);
  return volTot - a * (b * b * tan(PI / 2 - x) / 2.0);;
}

bool check(double med, double y) {
  return y <= volumen(med);
}

double bs(double lo, double hi, double y) {
  for (int i = 0; i < 100; ++i) {
    double med = (lo + hi) / 2;
    if (check(med, y)) hi = med;
    else lo = med;
  }
  return hi;
}

int main() { // claudio van
  cout.precision(10); cout << fixed;
  cin >> a >> b >> x;
  volTot = a * a * b;
  cout << bs(0, PI / 2, volTot - x) * 180.0 / PI << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
double n ,m ,d;

void solve(){
  double pairNum = 0;
  for(int i = 1; i + d <= n; i++){
    pairNum++;
  }
  //cout << pairNum << endl;
  double ans;
  if(d != 0) ans = (double)pairNum * 2  * (m-1) / (double)(n*n);
  else ans = (double)pairNum * (m-1)  / (n*n);

  printf("%lf\n",ans);

  return;
}

int main(){

  cin >> n >> m >> d;
  solve();

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
@author: Saurav Sihag
"""

rr = lambda: input().strip()
rri = lambda: int(rr())
# rri = lambda: int(stdin.readline())
rrm = lambda: [int(x) for x in rr().split()]
# stdout.write(str()+'\n')

from sys import stdin, stdout, setrecursionlimit

def sol():
    x, k, d=rrm()
    x=abs(x)
    a=x//d
    if a>k:
        print(abs(x-k*d))
        return
    rk=k-a
    xa=x-a*d
    # print(x, k, d, a, rk, xa)
    if rk%2==1:
        xa-=d
    print(abs(xa))
    return

    
# sol()
def main():
    # T = rri()
    # for t in range(1, T + 1):
        ans=sol()
        # print("Case #{}: {}".format(t, ans))

main()

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	string s;
	cin>>s;
	int n=s.size();
	ll ans=0;
	vl a(n+1,0),c(n+1,0),q(n+1,0),p(100001,1);
	rep(i,n){
	    a[i+1]=a[i]; if(s[i]=='A') a[i+1]++;
	    c[i+1]=c[i]; if(s[i]=='C') c[i+1]++;
	    q[i+1]=q[i]; if(s[i]=='?') q[i+1]++;
	}

    range(i,1,100001) p[i]=p[i-1]*3%MOD;
	rep(i,n){
	    if(s[i]=='A' or s[i]=='C') continue;
	    ll A= a[i]*p[q[i]]%MOD + q[i]*p[q[i]-1]%MOD;
	    ll C= (c[n]-c[i+1])*p[q[n]-q[i+1]]%MOD + (q[n]-q[i+1])*p[q[n]-q[i+1]-1]%MOD;
	    ans=(ans+A%MOD*C%MOD)%MOD;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3664
#include<iostream>
#include<cmath>

int main()
{
    int num, result;
    std::cin >> num;

    while(1)
    {
        if(std::cin.fail())
        {
            std::cout << "Error!\a" << std::endl;
            std::cin.clear();
            std::cin.ignore();

            std::cout << "integer x = " << std::flush;
            std::cin >> num;
        }
        else
        {
            break;
        }
    }

    result = std::pow(num, 3);

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


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  ll k;cin>>k;
  vector<int> a(n), f(n);
  rep(i, n)cin>>a[i];
  rep(i, n)cin>>f[i];

  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());

  vector<pi> ts;
  rep(i, n) ts.push_back( {a[i], f[i]} );

  ll min=-1,max=pow(10LL, 18)+1, mid;
  while(max-min>1){
    mid = (max+min)/2;
//cout<<"-------------"<<endl<<min<<' '<<max<<endl;

    ll ck=k;
    // tsの中に入っているスコアがすべてmid以下にできるか検証
    for(auto p: ts){
      ll score = (ll)p.first*(ll)p.second;
      if(score<=mid)continue;

      ll new_a = mid/p.second;
      ck -= (p.first-new_a);
    }

//cout<<ck<<endl;
    // 実現可能なら減らす
    if(ck>=0)max=mid;
    else min=mid;
  }

//cout<<min<<' '<<max<<endl;

  cout<<max<<endl;

  return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, M, V, P;
	cin >> N >> M >> V >> P;
	VI A(N);
	VI sum(N,0);
	VI f(N, 0);

	REP(i, N)cin >> A[i];
	rSORT(A);
	FOR(i, P - 1, N) {
		//sum[i] = sum[i - 1] + A[i];
		if (i != 0)sum[i] = sum[i - 1] + A[i];
		else sum[i] = A[i];
	}

	int L = 0, R = N - 1,X;

	while (L <= R) {
		X = (L + R) / 2;

		bool F = false;
		//true-採用される

		int m = M * V;
		m -= (P - 1)*M;
		m -= (N - X)*M;
		//左右で吸収

		if (X != 0 && ((A[X] + M)*(X - P + 1) - sum[X - 1]) >= 0) {
			m -= (A[X] + M)*(X - P + 1) - sum[X - 1];
		}

		//真ん中で吸収したい数

		if (X <= P-1) {
			F = true;
		}
		else if (A[X] + M < A[P - 1]) {
			
		}
		else {
			if (m <= 0)F = true;
		}



		if (!F) {
			R = X - 1;
			//chmin(ans, M);
		}
		else {
			f[X] = true;
			L = X + 1;
			//chman(ans, M);
		}

		//cout << X << endl;
	}
	int ans=-1;
	REP(i, N) {
		//cout << f[i];
		if (f[i])chmax(ans, i + 1);
	}
	
	cout << ans << endl;


	return 0;
}



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

using namespace std;

const int N = 2e5;
int n, a[N], b[N], t, l, r;

inline void solve() {
	for (register int i = 0; i < n; i++)
		if (a[i] == b[i]) {
			l = i;
			t = a[i];
			break;
		}
	for (register int i = n-1; i >= 0; i--)
		if (a[i] == t && b[i] == t) {
			r = i;
			break;
		}
	for (register int i = 0; i < n; i++)
		if (a[i] != t && b[i] != t && l <= r)
			swap(b[i], b[l++]);
	if (l <= r) {
		puts("No");
		return;
	}
	puts("Yes");
	for (register int i = 0; i < n; i++)
		printf("%d ", b[i]);
	puts("");
}

int main() {
	scanf("%d", &n);
	for (register int i = 0; i < n; i++)
		scanf("%d", a+i);
	for (register int i = n-1; i >= 0; i--)
		scanf("%d", b+i);
	solve();
	return 0;
}


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

//template
#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 ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end



int main(){
    int n; scanf("%d",&n);
    vector<vector<int>> a(n);
    rep(i,0,n){
        a[i].resize(n-1);
        rep(j,0,n-1){
            scanf("%d",&a[i][j]);
            a[i][j]--;
        }
    }
    vector<vector<int>> g(n*n);
    int cnt[n*n]={},u,v; bool fl[n*n]={};
    rep(i,0,n)rep(j,0,n-2){
        u=min(i,a[i][j])*n+max(i,a[i][j]);
        v=min(i,a[i][j+1])*n+max(i,a[i][j+1]);
        fl[u]=1; fl[v]=1;
        g[u].push_back(v); cnt[v]++;
    }
    queue<P> q;
    rep(i,0,n*n)if(fl[i]&&cnt[i]==0)q.push({i,0});
    vector<int> b; int now=-1,ans=0;
    while(q.size()){
        P p=q.front();q.pop();
        b.push_back(p.first);
        if(now!=p.second){
            ans++; now=p.second;
        }
        for(int nxt:g[p.first]){
            cnt[nxt]--;
            if(cnt[nxt]==0)q.push({nxt,p.second+1});
        }
    }
    if(b.size()!=n*(n-1)/2){
        printf("-1"); return 0;
    }
    printf("%d",ans);
    return 0;
}

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

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

  long long N, M, K;
  cin >> N >> M >> K;

  vector<long long> A(N), a(N + 1, 0), B(M), b(M + 1, 0);
  for(int i = 0; i < N; ++i) {
    cin >> A[i];
    a[i + 1] = a[i] + A[i];
  }
  for(int i = 0; i < M; ++i) {
    cin >> B[i];
    b[i + 1] = b[i] + B[i];
  }

  long long ans = 0, j = M;
  for(int i = 0; i < N + 1; ++i) {
    if(a[i] > K) {
      break;
    }
    while (b[j] > K - a[i]) {
      j--;
    }
    ans = max(ans, i + j);
  }

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


Measured memory_bytes: 9548
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,n;
  cin >> k >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  int maxv=k-a.back()+a[0];
  for(int i=0;i<n-1;i++) maxv=max(maxv,a[i+1]-a[i]);
  cout << k-maxv << endl;
}

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

using namespace std;
int r,g,b,t;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    cin>>r>>g>>b>>t;
    while(t--){
        if(g >= b) b *= 2;
        else if(r >= g) g *= 2;
    }
    if(r < g && g < b) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 3660
//https://atcoder.jp/contests/abc145/tasks/abc145_a
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main() {
    ll r; cin>>r;
    cout<<r*r<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
static const int N = 101;
int main()
{
    int n;
    int p[N],m[N][N];
    cin>>n;
    for (int i = 1; i <= n; i++)
    {
        cin>>p[i-1]>>p[i];
        m[i][i] = 0;
    } 
    for (int l = 2; l <= n; l++)
    {
        for (int i = 1; i <= n-l+1; i++)
        {
            int j = i+l-1;
            m[i][j] = (1<<21);
            for (int k = i; k <= j-1; k++)
            {
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j]); 
            } 
        }  
    } 
    cout<<m[1][n]<<endl;
    return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <climits>
#include <math.h>
using namespace std;

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end()

int main() {
	int n; cin >> n;
	vi a(n), b(n);
	rep(i, n) {
		cin >> a.at(i);
	}
	rep(i, n) {
		int index = n - 1 - 2 * i;
		if (index < 0)index = -1 - index;
		b.at(i) = a.at(index);
	}
	rep(i, n) {
		cout << b.at(i) << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3712
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy
from pprint import pprint

# If you use recursive call, uncomment this code
sys.setrecursionlimit(10**6)

def main():
    global result,aa,N
    N = int(input())
    aa = []
    for _ in range(N):
        aaa = []
        na = int(input())
        for _ in range(na):
            x,y = map(int,input().split())
            aaa.append((x-1,y))
        aa.append(aaa)

    ans = 0
    for bm in range(1<<N):
        inconsisted = False
        #print("---")
        #print("{:08b}".format(bm))
        for i in range(N):
            #print("\t",i)
            if not bm & 1<<i:
                continue
            for x,y in aa[i]:
                if (bm & 1<<x) ^ y<<x:
                    inconsisted = True
                    break
            if inconsisted:
                break
        if inconsisted:
            continue
        tmp = 0
        for i in range(N):
            tmp += bm>>i & 0b1
        ans = max(ans,tmp)
    print(ans)
    

if __name__ == '__main__':
    main()


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

#define ll long long

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin >> s;
	for(int i=0;i<s.length();i++)
		cout << "x";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cctype>
using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int h,w;
    cin>>h>>w;
    char data[100][100];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>data[i][j];
        }
    }
    for(int i=-1;i<h+1;i++){
        for(int j=-1;j<w+1;j++){
            if(i==-1||i==h||j==-1||j==w){
                cout<<'#';
            }else{
                cout<<data[i][j];
            }
            if(j==w){
                cout<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 2000003;
const int MOD = 1000000007;

//
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

        signed main() {
    cout<<fixed<<setprecision(10);
        int n,m;
        cin>>n>>m;
        if(n==1||m==1){
                if(n!=1)swap(n,m);
                if(m==1){
                        cout<<1;
        
                        return 0;
                }else{
                        cout<<m-2;
                        return 0;
                }
        }else{
                cout<<(n-2)*(m-2);
        }
       

        }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector <int> pa(A);
  vector <int> pb(B);
  vector <int> pc(C);
  vector <int> data(X+Y+C);
  
  long long ans = 0;
  
  for(int i = 0; i < A; i++){
    cin >> pa.at(i);
  }
  sort(pa.begin(),pa.end());
  reverse(pa.begin(),pa.end());
  
  for(int i = 0; i < B; i++){
    cin >> pb.at(i);
  }
  sort(pb.begin(),pb.end());
  reverse(pb.begin(),pb.end());

  for(int i = 0; i < X; i++){
    data.at(i) = pa.at(i);
  }
  
  for(int i = X; i < X+Y; i++){
    data.at(i) = pb.at(i-X);
  }
  
  
  for(int i = X+Y; i < X+Y+C; i++){
    cin >> data.at(i);
  }
  sort(data.begin(),data.end());
  reverse(data.begin(),data.end());
  
  for(int i = 0; i < X+Y; i++){
    ans += data.at(i);
  }  
  
  cout << ans << endl;
}

Measured memory_bytes: 2560
# すぬけくんは 3 匹のヤギにクッキーを渡したいです。
# すぬけくんは A 枚のクッキーが入った缶と、B 枚のクッキーが入った缶を持っています。 
# すぬけくんは A,B,A+B のいずれかの枚数のクッキーをヤギたちに渡すことができます。
# 3 匹のヤギが同じ枚数ずつ食べられるようにクッキーを渡すことが可能かどうか判定してください。

input = gets.chomp.split
a = input[0].to_i
b = input[1].to_i

if a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0
    puts "Possible"
else
    puts "Impossible"
end

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


int main(){
    int t;
    scanf("%d",&t);
    int a,b;
    scanf("%d%d",&a,&b);
    int temp=a/t*t;
    bool flag=false;
    for(int i=temp;i<=b;i+=t){
        if(i>=a&&i<=b){
            flag=true;
            break;
        }
    }
    printf("%s",flag?"OK":"NG");
    return 0;
}


Measured memory_bytes: 3720
N, W = map(int, input().split())
items = []
for _ in range(N):
    items.append(tuple(map(int, input().split())))
dp = [0 for i in range(W+1)]
for w, v in items:
    for i in reversed(range(W+1)):
        if i - w >= 0: dp[i] = max(dp[i-w] + v, dp[i])
print(max(dp))

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

int main(){
	int N;
	cin >> N;
	vector<int> a;
	for (int i = 0; i < N; i++){
		int temp;
		cin >> temp;
		a.push_back(temp);
	}
	sort(a.begin(), a.end(), [](const int& x, const int& y){return x>y; });	//ソートして取りやすくする
	
	int Alice = 0;	//アリスの得点
	int Bob = 0;	//ボブの得点

	for (int i = 0; i < N; i++){
		//順番がずれて気持ち悪いけど
		if (i % 2 == 0)	Alice += a[i];
		else
		{
			Bob += a[i];
		}
	}

	cout << Alice - Bob << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    L = pow(2, N)
    Inf = pow(10, 20)
    Dist = [Inf] * L
    
    Dist[0] = 0
    for _ in range(M):
        a, b = map(int, input().split())
        bit = 0
        C = [int(c) for c in input().split()]
        for c in C: bit += pow(2, c-1)
        for k, d in enumerate(Dist):
            if d < Inf: Dist[k | bit] = min(Dist[k | bit], d + a)
            
    print(Dist[L - 1] if Dist[L-1] < Inf else -1)

    return 0

if __name__ == "__main__":
    solve()

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

int main(void){
   
   string s;
   cin >> s;
   
   if(s[0] == s[1] && s[1] == s[2]){
       cout <<"No"<<endl;
   }
   else{
       cout <<"Yes"<<endl;
   }
}

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

using namespace std;

#define ll long long
#define pii pair<int,int>
#define mod 1000000007
int main()
{
    ll n;
    cin>>n;
    if(n == 1)
    {
        cout<<0<<endl;
    }
    else
    {
        ll ans1 = 1;
        ll ans2 = 1;
        ll ans3 = 1;
        for(int i=0;i<n;i++)
        {
            ans1 = (ans1*10)%mod;
            ans2 = (ans2*9)%mod;
            ans3 = (ans3*8)%mod;
        }
        ll res = (ans1 + ans3)%mod;
        res = (res - (2*(ans2))%mod + mod)%mod;
        cout<<res<<endl;
    }
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<n;i++)
using namespace std;
 
int main() {
  int a, b;
  int s[110000];
  int sum=0;
  cin>>a>>b;
  rep(i,b) cin>>s[i];
  rep(i,b) sum += s[i];
  if (a>sum) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}

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

using namespace std;
using ll = long long;

#define debug(x) cerr << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

const int maxn = 1e6 + 10;

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

int a[maxn];

int main()
{
	ios::sync_with_stdio(false);
	int test = 1;
	while(test--)
	{
		int n;
		cin >> n;
		int g = 0;
		for(int i = 1; i <= n; i++)
		{
			int b;
			cin >> b;
			a[b]++;
			g = __gcd(g, b);
		}

		bool isSet = false;

		for(int i = 2; i < maxn; i++)
		{
			int cnt = 0;
			for(int j = i; j < maxn; j += i)
			{
				cnt += a[j];
			}
			if(cnt > 1)
			{
				isSet = true;
				break;
			}
		}
		if(g == 1 && isSet)
			cout << "setwise ";
		else if(g == 1)
			cout << "pairwise ";
		else
			cout << "not ";
		cout << "coprime" << endl;
	}
	
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int SUM = 0;  
  for (int i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++){
      SUM++;      
    }    
  }
    
  cout << SUM << endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
const int inf=0x3f3f3f3f;
int n,k;
int a[maxn];
bool check(int x)
{
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		sum+=a[i]/x;
		if(a[i]%x==0)
			sum--;
	}
	if(sum>k)
		return 0;
	else
		return 1;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n>>k;
	int maxv=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		maxv=max(maxv,a[i]);
	}
	int l=1,r=maxv+1,ans;
	while(l<r)
	{
		int mid=(l+r)/2;
		if(check(mid))
			r=mid;
		else
			l=mid+1;
	}
	cout<<l<<endl;
	return 0;
}




Measured memory_bytes: 4384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define vec(x) vector<x>
#define IINF INT_MAX
#define LLINF LLONG_MAX
ll gcd(ll a,ll b){while(b){ll tmp = a % b;a = b;b = tmp;}return a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define out(x) for(auto i : x) cout << i << " "; cout << endl;
#define outln(x) for(auto i : x) cout << i << endl;
#define vec_cpy(to,from) copy(all(to),back_inserter(from))
#define ary_cpy(to,from) memcpy(to, from, sizeof from)
#define MOD 1000000007
#define DEBUG true

int main(){
  int h,r;cin >> h >> r;
  int sum = h + r;
  if(sum == 0) cout << 0;
  else{
   if(sum > 0) cout << 1;
   else if(sum < 0) cout << -1;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3092
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] t = new int[N + 1];
            int[] x = new int[N + 1];
            int[] y = new int[N + 1];

            for (int i = 1; i <= N; i++) {
                t[i] = in.nextInt();
                x[i] = in.nextInt();
                y[i] = in.nextInt();
            }

            for (int i = 1; i <= N; i++) {
                if (Math.abs(x[i] - x[i - 1]) + Math.abs(y[i] - y[i - 1]) > t[i] - t[i - 1]) {
                    System.out.println("No");
                    return;
                }
                int t2 = (t[i] - t[i - 1]) - Math.abs(x[i] - x[i - 1]) - Math.abs(y[i] - y[i - 1]);
                if (t2 % 2 == 1) {
                    System.out.println("No");
                    return;
                }
            }

            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 90992
import math
n = int(input())

v = [0]*(100000)

for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1, 101):
      v[x*x+y*y+z*z+x*y+y*z+z*x] += 1

print('\n'.join(map(str,v[1:n+1])))



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

vector<int> edges[100001];
int n,m;
bool *visited = new bool[100001]();

void dfs(int ind){
	
	visited[ind] = true;
	for(int i=0;i<edges[ind].size();i++){
		if(!visited[edges[ind][i]]){
			dfs(edges[ind][i]);
		}
			
	}
	
}

int main() {
	// your code goes here

	cin>>n>>m;
	
	for(int i=0;i<m;i++){
		int f,s;
		cin>>f>>s;
		edges[f].push_back(s);
		edges[s].push_back(f);
	}
	int cnt = 0;
	for(int i=1;i<=n;i++){
		if(!visited[i]){
			cnt++;
			dfs(i);
		}	
	}
	cout<<cnt-1;
	return 0;
}

Measured memory_bytes: 9692
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 1000000007;

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

    int m = 1;
    while(m * m <= n)
        ++ m;
    -- m;
    m *= 2;

    vector<int> cnt(m, 1);
    for(int i=1; i<=m/2; ++i)
        cnt[m-i] = (n / i) - max(m/2, (n / (i + 1)));

    vector<long long> dp(cnt.begin(), cnt.end());
    while(--k > 0){
        vector<long long> nextDp(m, 0);
        long long sum = 0;
        for(int i=0; i<m; ++i){
            sum += dp[i];
            sum %= MOD;
            nextDp[m-1-i] += sum * cnt[m-1-i];
            nextDp[m-1-i] %= MOD;
        }
        dp = move(nextDp);
    }
    long long ans = accumulate(dp.begin(), dp.end(), 0LL) % MOD;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1536
import math
n,m = map(int,input().split())
ans = 0
if n >= 2:
    a = math.factorial(n)//(math.factorial(n-2)*math.factorial(2))
    ans += a
if m >= 2:
    b = math.factorial(m)//(math.factorial(m-2)*math.factorial(2))
    ans += b
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>

void view(const std::vector<T> &v)
{
#ifndef ONLINE_JUDGE
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
#endif
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

const int INF = 1e9;
int main()
{
    int n, m;
    cin >> n >> m;
    vvint g(n, vint());
    rep(i, m)
    {
        int f, t;
        cin >> f >> t;
        f--;
        t--;
        g[f].emplace_back(t);
    }
    int s, t;
    cin >> s >> t;
    s--;
    t--;

    queue<P> q;
    vvint cst(n, vint(3, INF));
    q.push(P(s, 0));
    cst[s][0] = 0;
    while (q.size())
    {
        P p = q.front();
        q.pop();
        int v = p.first, cmod = p.second;
        if (v == t && cmod == 0)
        {
            break;
        }
        int c = cst[v][cmod];
        int nc = (c + 1) % 3;
        for (int nv : g[v])
        {
            if (cst[nv][nc] > c + 1)
            {
                cst[nv][nc] = c + 1;
                q.push(P(nv, nc));
            }
        }
    }

    int ans = cst[t][0];
    if (ans == INF)
    {
        ans = -3;
    }
    cout << (ans / 3) << endl;

    return 0;
}

Measured memory_bytes: 14000
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
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; }
const string MINUSINF = "-";
void chmax(string &a, string b) {
    if (a == MINUSINF) a = b;
    else if (a.size() < b.size()) a = b;
    else if (a.size() == b.size()) {
        if (a < b) a = b;
    }
}
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1001001001001001LL;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
const int match[10] = {2,5,5,4,5,6,3,7,6 };
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> a(M);
    for (int i = 0; i < M; ++i) {
        cin >> a[i];
    }
    SORT(a);

    vector<string> dp(10010, MINUSINF);
    dp[0] = "";
    for (int i = 0; i <= N; ++i) {
        if (dp[i] == MINUSINF) continue;
        for (auto j : a) chmax(dp[i + match[j - 1]],dp[i]+(char)('0' + j));
    }
    cout << dp[N]<< endl;
    return 0;
}

Measured memory_bytes: 43776