akhauriyash/Code-Regression huggingface dataset:
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n\r\t', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    length(S, L),
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
    \+ P(X) : not P(X)

    sum_list(Xs, Sum)

    orは!忘れに注意(末尾再帰なら直前)
*/

repX(0, _, []) :- !.
repX(N, X, [Y|Ys]) :- N2 is N - 1, Y is X, repX(N2, X, Ys).

main :-
    get_chars(S),
    length(S, L),
    repX(L, "x", Ys),
    string_chars(S2, Ys),
    writeln(S2).

    % statistics(inferences, IC), writeln(IC).


Measured memory_bytes: 8036
#include<iostream>
using namespace std;
char tile[21][21];

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

int sum=0;

void check(int x,int y)
{
  if(tile[x][y]=='#')
    return;
  sum++;
  tile[x][y]='#';
  for(int i=0;i<4;i++)
    {
      if(x+dx[i]>=0 &&x+dx[i]<21 &&y+dy[i]>=0 &&y+dy[i]<21)
	{
	  check(x+dx[i],y+dy[i]);
	}
    }
}

int main()
{
  int w,h;
  for(;cin>>w>>h,w||h;)
    {
      for(int i=0;i<21;i++)
	  for(int j=0;j<21;j++)
	      tile[i][j]='#';
      
      int x,y;
      for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)
	  {
	    cin>>tile[j][i];
	    if(tile[j][i]=='@')
	      {
		x=j,y=i;
	      }
	  }
      sum=0;
      check(x,y);
      cout<<sum<<endl;
      /*
      for(int i=0;i<h;i++,cout<<endl)
	for(int j=0;j<w;j++)
	  {
	    cout<<tile[j][i];
	  }
      */
    }
}

Measured memory_bytes: 1164
using System;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;

namespace program
{
    class Program
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            long[] array = new long[n];

            for (int i = 0; i < n; i++)
            {
                array[i] = int.Parse(str[i]);
            }
            Console.WriteLine(array.Min() + " " + array.Max() + " " + array.Sum());
            

        }
    }
}


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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 200500;

string s;
int n, ans, l[N], r[N];

inline void erase(int pos) {
	int nxt = r[pos];
	int prv = l[pos];
	r[prv] = nxt;
	l[nxt] = prv;
}

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

	//srand(time(NULL));

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

	//cout << setprecision(10) << fixed;
	
	cin >> s;

	n = ans = sz(s);

	s = "!" + s;

	r[0] = 1;
	l[n + 1] = n;

	for (int i = 1; i <= n; i++) {
		r[i] = i + 1;
		l[i] = i - 1;
	}

	for (int i = 1; i <= n; i = r[i]) {
		if (s[i] == 'S' && s[r[i]] == 'T') {
			ans -= 2;
			int nw = l[l[i]];
			int pos1 = i;
			int pos2 = r[i];
			erase(pos1);
			erase(pos2);
			i = l[l[i]];
		}
	}

	cout << ans;

	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 2128
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
int main()
{
  //flash;
    string ka;
    cin>>ka;
    if(ka[2]==ka[3] && ka[4]==ka[5])cout<<"Yes";
    else cout<<"No";
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 1e9+7
#define ll long long
#define clr(c) memset(c,0,sizeof(c))
const int M=2e5+10;
const int N=1e5+10;
using namespace std;
inline ll read()
{
	ll sum=0,b=1; char c=getchar();
	while(!isdigit(c)){if(c=='-') b=-1; c=getchar();}
	while(isdigit(c)){sum=sum*10+c-48; c=getchar();}
	return b*sum;
}
ll n,m,b,a;
char s[1000],t[1000],u[1000];
int main()	
{	
	ll i,j;
	scanf("%s",s);
	ll len=strlen(s);
	for(i=0;i<len;i++)
	printf("x");
	return 0;
} 

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

using namespace std;
using ll = int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using tpi = tuple<int, int, int>;

using vqi = vector<queue<int>>;
using vpi = vector<pii>;
using bs = bitset<60>;
using vbi = vector<bs>;

ll gcd(ll a, ll b) {
    if (a < b) {
        swap(a, b);
    }

    /* ユークリッドの互除法 */
    ll r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

constexpr int64_t __pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    if (p == 0) {
        return 1;
    }
    if (p % 2 == 0) {
        int64_t t = __pow_mod(n, p / 2, mod);
        return (t * t) % mod;
    }
    return (n * (__pow_mod(n, p - 1, mod) % mod)) % mod;
}

constexpr int64_t pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    int64_t res = __pow_mod(n, p, mod);
    return res % mod;
}

constexpr int64_t nCr_mod(int64_t n, int64_t r, int64_t mod) noexcept {
    int64_t count = 1;
    auto a = r;
    for (auto i = n; i > n - r; i--) {
        count *= i;
        if (count % mod != 0) {
            count %= mod;
        }
        int64_t inv = pow_mod(a, mod - 2, mod);
        count *= inv;
        if (count % mod != 0) {
            count %= mod;
        }
        a--;
    }
    return count;
}

constexpr long long MOD = 998244353;

int dfs(int i, const vii& tree) noexcept {
    if (tree[i].empty()) {
        return 2;
    } else {
        ll ans = 1;
        for (auto item : tree[i]) {
            ans *= dfs(item, tree);
            ans %= MOD;
        }
        return ans + 1;
    }
}

void solve(long long N, std::vector<long long> X, std::vector<long long> D) {
    using pll=pair<ll, ll>;
    using vpl=vector<pll>;
    vpl V(N);
    for (int i = 0; i < N; i++) {
        V[i] = make_pair(X[i], D[i]);
    }

    sort(V.begin(), V.end());
    sort(X.begin(), X.end());

    vii tree(N);
    set<pll> s;
    for (ll i = N - 1; i >= 0; i--) {
        int x = V[i].first, d = V[i].second;
        while (!s.empty() && s.begin()->first < x + d) {
            tree[i].push_back(s.begin()->second);
            s.erase(s.begin());
        }
        s.emplace(x, i);
    }

    ll ans = 1;
    for (auto&& root : s) {
        ans *= dfs(root.second, tree);
        ans %= MOD;
    }
    cout << ans << endl;
}

int main() {
    long long N;
    std::cin >> N;
    std::vector<long long> X(N);
    std::vector<long long> D(N);
    for (int i = 0; i < N; i++) {
        std::cin >> X[i];
        std::cin >> D[i];
    }
    solve(N, std::move(X), std::move(D));
    return 0;
}


Measured memory_bytes: 26752
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
 
list<int> ls;
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n,x;
    cin>>n;
    string s;
    rep(i,n){
        cin>>s;
        if(s=="insert"){
            cin>>x;ls.push_front(x);
        }
        else if(s=="deleteFirst") ls.pop_front();
        else if(s=="deleteLast") ls.pop_back();
        else{
            cin>>x;
            for(list<int>::iterator it=ls.begin();it!=ls.end();++it){
                if(*it==x){
                    ls.erase(it);
                    break;
                }
            }
        }
    }
    int cnt=0;
    int sz=ls.size();
    for(list<int>::iterator it=ls.begin();it!=ls.end();++it){
        cout<<*it<<(cnt+1==sz?"":" ");
        ++cnt;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 34440
#include <cstdio>
bool d[33554432];
char k[128];

int c(char str[12]){
	int ans = str[0], i = 1;
	for(i;str[i] != '\0';i++){ans <<= 2;ans += k[str[i]];}
	return ans;
}

int main(){
	k['A'] = 0;k['C'] = 1;k['G'] = 2;k['T'] = 3;
	int n;scanf("%d", &n);
	char s[7], str[12];
	while(n--){
		scanf("%s %s", s, str);
		if(s[0] == 'i')d[c(str)] = true;
		else puts(d[c(str)] ? "yes" : "no");
	}
	return 0;
}

Measured memory_bytes: 4028
#include<iostream> 
#include<queue>
using namespace std;
const int INF=2e9+3;
char c[805][805];
int n,m,k;
int a[805][805];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int sx,sy;
bool ok(int x,int y)
{
	return x>=0&&y>=0&&x<n&&y<m;
}
int main()
{
	cin>>n>>m>>k;
	for(int i=0;i<n;i++)
	    for(int j=0;j<m;j++)
	    {
	    	cin>>c[i][j];
	    	if(c[i][j]=='S')
	    	    sx=i,sy=j;
		}
	for(int i=0;i<n;i++)
	    for(int j=0;j<m;j++)
	        a[i][j]=INF;
	a[sx][sy]=0;
	queue <pair<int,int> > q;
	q.push(make_pair(sx,sy));
	while(q.size())
	{
		int x=q.front().first;
		int y=q.front().second;
		q.pop();
		for(int i=0;i<4;i++)
		{
			int nx=x+dx[i];
			int ny=y+dy[i];
			if(ok(nx,ny)&&a[nx][ny]>a[x][y]+1&&c[nx][ny]!='#')
			{
				a[nx][ny]=a[x][y]+1;
				q.push(make_pair(nx,ny));
			}
		}
	}
	int ans=INF;
	for(int i=0;i<n;i++)
	    for(int j=0;j<m;j++)
	        if(a[i][j]<=k)
	        {
	        	int mn=min(min(i,j),min(n-i-1,m-j-1));
	        	int tmp=(k+mn-1)/k;
	        	ans=min(ans,tmp+1);
			}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3456
H,W,K=map(int,input().split())
l=[]
n=0
ANS=0
answer=0
for i in range(H):
    l.append(input())
    ANS+=l[i].count("#")
#print(ANS)
for i in range(2**H):
    anss=0
    X=format(i,"b")
    n=X.zfill(H)
    for p in range(H):
        if n[p:p+1]=="0":
            anss+=l[p].count("#")
    for k in range(2**W):
        ans=anss
        Y=format(k,"b")
        m=Y.zfill(W)
        for a in range(W):
            if m[a:a+1]=="0":
                for b in range(H):
                    if n[b:b+1]=="1" and l[b][a:a+1]=="#":
                        ans+=1   
        if ANS-ans==K:
            answer+=1
print(answer)

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

int main(){
  ll n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  if (n % 2 == 1) {
    cout << b[(n - 1) / 2] - a[(n - 1) / 2] + 1 << endl;
  } else {
    cout << b[n / 2] + b[n / 2 - 1] - a[n / 2] - a[n / 2 - 1] + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 4844
package main

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

func sum(a []int) int {
	ret := 0
	for _, v := range a {
		ret += v
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()
	ac := make([]bool, n)
	// AC, WA
	cnt := make([][]int, 2)
	for i := range cnt {
		cnt[i] = make([]int, n)
	}
	for i := 0; i < m; i++ {
		p, s := nextInt()-1, next()
		if s == "AC" && !ac[p] {
			ac[p] = true
			cnt[0][p]++
		} else if s == "WA" && !ac[p] {
			cnt[1][p]++
		}
	}
	for i := 0; i < n; i++ {
		if !ac[i] {
			cnt[1][i] = 0
		}
	}
	puts(sum(cnt[0]), sum(cnt[1]))
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}
int dfs(int v, ll N, bool visited[nmax])
{
    bool all_visited = true;

    for (int i = 0; i < N; i++)
    {
        if (!visited[i])
        {
            all_visited = false;
        }
    }

    if (all_visited)
    {
        return 1;
    }
    int ret = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (!graph[v][i])
        {
            continue;
        }
        if (visited[i])
        {
            continue;
        }

        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }

    return ret;
}


void solve(long long A, std::string op, long long B){
    if(op == "+"){
        cout << A+B << endl;
    }else{
        cout << A-B << endl;
    }
}

int main(){
    long long A;
    scanf("%lld",&A);
    std::string op;
    std::cin >> op;
    long long B;
    scanf("%lld",&B);
    solve(A, op, B);
    return 0;
}


Measured memory_bytes: 256
from math import cos, radians

# input
A, B, H, M = map(int, input().split())

# check
h = 30 * H + 0.5 * M
m = 6 * M
if abs(m - h) >= 180:
    hm = radians(360 - abs(m - h))
else:
    hm = radians(abs(m - h))

C = (A ** 2 + B ** 2 - 2 * A * B * cos(hm)) ** 0.5

print(C)

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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i=0; i<n; i++) {
        cin >> d.at(i);
    }
    sort(d.begin(), d.end());
    reverse(d.begin(), d.end());
    int count=1;
    for (int i=0; i<n-1; i++) {
        if (d.at(i) > d.at(i+1)) {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int T;
int A,B,C,D;
int K;
bool check(int x)
{
    int cb=(x-1)/K;
    int p=A-x,q=B-cb;
    if(1ll*K*(p+1)<q)return 0;
    else return 1;
}
int l,ca;
int sb,tb;
char calc(int pos)
{
    if(pos<sb)return pos%(K+1)?'A':'B';
    else if(pos<=tb)return 'B';
    else return (pos-tb-1)%(K+1)?'B':'A';
}
int main()
{
    scanf("%d",&T);
    int mid;
while(T--)
{
    scanf("%d%d%d%d",&A,&B,&C,&D);
    K=(max(A,B)-1)/(min(A,B)+1)+1;
    l=0,ca=A;
    while(l<=ca)
    {
        mid=(l+ca)/2;
        if(check(mid))l=mid+1;
        else ca=mid-1;
    }
    int cb=(ca-1)/K;
    int p=A-ca,q=B-cb;
    sb=ca+cb+1;tb=sb+q-p*K-1;
    for(int i=C;i<=D;++i)putchar(calc(i));
    puts("");
}
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main (){
	int input[100];
	for (int a=0;a<3;a++){
		scanf ("%d",&input[a]);
	}
	for (int k=0;k<3-1;k++){
		for (int l=0;l<3-1-k;l++){
			if (input[l]>input[l+1]){
				int temp=input[l];
				input[l]=input[l+1];
				input[l+1]=temp;
			}
		}
	}
	int total=input[0]+input[1];
	printf ("%d\n",total);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long,long>> vpll;
typedef vector<pair<int,int>> vpii;
int main() {
	oneforall
	ini(n);	
	map<int,int> map1;
	int b = 0;
	FOR(i, 0, n) { ini(x);map1[x]++;if (map1[x] == 2) { b = 1;break; } }
	if (b == 1) { 
		out("NO");
	}
	else {
		out("YES");
	}
	return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>	
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#define INF 2000000000
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int,int>
using namespace std;
int dx[5]={1,0,-1,0,0},dy[5]={0,1,0,-1,0};
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}
int lcm(int a,int b){if(a==0){return b;} return a/gcd(a,b)*b;}

int a[3000],b[3000];
int dp[3001][3001];

signed main(){
	int n,t,s; cin>>n>>t>>s;
	for(int i=0; i<n; i++){
		cin>>a[i]>>b[i];
	}
	for(int i=0; i<3001; i++) for(int j=0; j<3001; j++) dp[i][j]=-INF;
	dp[0][0]=0;
	for(int i=0; i<t; i++){
		for(int j=0; j<n; j++){
			dp[i][j+1]=max(dp[i][j], dp[i][j+1]);
			dp[i+1][j]=max(dp[i][j], dp[i+1][j]);
			if(i+b[j]<=t&&!(i<s&&s<i+b[j])) dp[i+b[j]][j+1]=max(dp[i+b[j]][j+1], dp[i][j]+a[j]);
		}
	}
	int ret=0;
	for(int i=0; i<=t; i++) for(int j=0; j<=n; j++) ret=max(ret,dp[i][j]);
	cout<<ret<<en;
}
	


Measured memory_bytes: 73456
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 3456;
const LL INF = (LL)1e15;
int a[MAXN];
bool visit[MAXN][MAXN][2];
LL dp[MAXN][MAXN][2];

LL dfs(int x, int y, int flg) {
   if (visit[x][y][flg]) return dp[x][y][flg];
   visit[x][y][flg] = 1;
   if (y < x) return 0;
   LL ans;
   if (flg == 0) {
      ans = max(dfs(x + 1, y, 1) + a[x], dfs(x, y - 1, 1) + a[y]);
   } else {
      ans = min(dfs(x + 1, y, 0) - a[x], dfs(x, y - 1, 0) - a[y]);
   }
   return dp[x][y][flg] = ans;
}

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) scanf("%d", &a[i]);
    printf("%lld\n", dfs(0, N - 1, 0));
    return 0;
}


Measured memory_bytes: 186624
#include<stdio.h>
#include<iostream>
#include<cstring>
using namespace std;
int c1,c2,c3,n;
main()
{
	int i,j,k,x;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(x%4==0)c3++;
		else if(!(x&1))c2++;
		else c1++;
	}
	if(!(n&1))
	{
	if(c3*2+c2>=n)puts("Yes");
	else puts("No");
    }
    else {
    	if(c3*2+c2>=n-1)puts("Yes");
	else puts("No");
	}
}

Measured memory_bytes: 256
#include<iostream>

#include <math.h>
using namespace std;
 
int main(){
  	
  	float a[5];
  	float b[5];
  	float c[5];
  	float d;
  	int memo;
  	float  max;
  	for(int i = 0;i<5 ; i++){
      	cin >> d;
      	a[i] = d/10;
      	b[i] = ceil(d/10);

      	c[i] = b[i]-a[i];
      	if(c[i]>max){
        	max=c[i];
          	memo = i;
        }
    }
	
  	int sum;
  	for(int i = 0;i<5;i++){
    	if(i==memo) sum +=a[i]*10;
      	else sum += b[i]*10;
    
    }
	
  	cout << sum << endl;

 
}

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

#define MOD 998244353

int n;
int k;
int l[10], r[10];
long long memo[200005];

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < k; i++) {
		scanf("%d%d", &l[i], &r[i]);
	}
	memo[1] = 1;
	for (int i = 2; i <= n; i++) {
		memo[i] = memo[i - 1];
		for (int j = 0; j < k; j++) {
			memo[i] += memo[max(0, i - l[j])] - memo[max(0, i - r[j] - 1)];
			memo[i] = (memo[i] + MOD) % MOD;
		}
	}
	printf("%lld\n", (memo[n] - memo[n - 1] + MOD) % MOD);
	return 0;
}


Measured memory_bytes: 5384
#include <stdio.h>
#include <stdbool.h>
#include <limits.h>
int main() {
    int N, min, minPos, cnt;
    bool loop = true;
    scanf("%d%*c", &N);
    long int A[N];
    for (int i = 0; i < N; i++) scanf("%ld%*c", &A[i]);
    
    while (loop) {
        loop = false;
        min = INT_MAX;
        cnt = 0;
        for (int i = 0; i < N; i++) if (A[i] != 0 && A[i] < min) {
            min = A[i];
            minPos = i;
        }
        for (int i = 0; i < N; i++) {
            if (i == minPos) continue;
            A[i] = A[i] % min;
        }
        for (int i = 0; i < N; i++) {
            if (A[i] != 0) cnt++;
        }
        if (cnt != 1) loop = true;
    }
    for (int i = 0; i < N; i++) if (A[i] != 0) printf("%ld\n", A[i]);
    return 0;
}

Measured memory_bytes: 896
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000

void solve(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,t;
  cin>>s>>t;
  map<ll,ll> mp,mpp;
  vector<ll> ss,tt;
  
  rep(i,s.size()) mp[s[i]]++;
  rep(i,t.size()) mpp[t[i]]++;
  rep(i,s.size()) ss.push_back(mp[s[i]]);
  rep(i,t.size()) tt.push_back(mpp[t[i]]);

  sort(all(ss));
  sort(all(tt));
  bool flg = true;
  rep(i,s.size()) if(ss[i]!=tt[i]) flg = false;
  if(flg) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

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

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

    for(int i = 0 ; i < s.size() ; i++){
        if(s[i] != t[i]){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3916
import std.stdio, std.conv, std.string, std.algorithm, std.math, std.array, std.container;

string s;
int q;

void main() {
  s = readln.chomp;
  readf("%d\n", &q);
  bool reversed = false;
  string l = "";
  string r = "";
  for(int i=0; i<q; i++) {
    string query = readln.chomp;
    if(query[0] == '1') reversed = !reversed;
    else {
      bool add_head = query[2]=='1';
      if(reversed) {
        if(add_head) r = r ~ query[4];
        else l = query[4] ~ l;
      }
      else {
        if(add_head) l = query[4] ~ l;
        else r = r ~ query[4];
      }
    }
  }
  if(reversed) {
    char[] s2 = s.dup;
    char[] l2 = l.dup;
    char[] r2 = r.dup;
    std.algorithm.reverse(s2);
    std.algorithm.reverse(l2);
    std.algorithm.reverse(r2);
    writeln(r2 ~ s2 ~ l2);
  }
  else {
    writeln(l ~ s ~ r);
  }
}



Measured memory_bytes: 5784
n=int(input())
lists=list(map(int,input().split()))

if n%2==0:
    evenlists=[]
    for i in range(1,n,2):
        evenlists.append(i)
        evenlists.append(i)
    special=sorted(evenlists)
    
    if special==sorted(lists):
        ans=1
        for i in range(int(n/2)):
            ans=ans*2
            ans=ans%(10**9+7)
        print(ans)
    else:
        print(0)
else:
    oddlists=[]
    for j in range(2,n,2):
        oddlists.append(j)
        oddlists.append(j)
    oddlists.append(0)
    special=sorted(oddlists)
    
    if special==sorted(lists):
        ans=1
        for j in range(int((n-1)/2)):
            ans=ans*2
            ans=ans%(10**9+7)
        print(ans)  
    else:
        print(0)

Measured memory_bytes: 14008
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define ll long long
#define sz(x) (int)(x.size())
#define pb push_back
#define endl "\n"
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int long long

const int N = (int)(1e6) + 322;
const int inf = (long long)(1e18) + 123;
const int mod = 998244353;
const double eps = 1e-9;


int binpow(int a, int n) {
    int res = 1;
    while (n) {
        if (n & 1) {
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
        n >>= 1;
    }
    return res;
}

int cnt[N], a[N];

void solve() {
    int n; cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    if (a[1] != 0) {
        cout << 0;
        return;
    }
    if (cnt[0] > 1) {
        cout << 0;
        return;
    }
    sort(a + 1, a + n + 1);
    int mx = *max_element(a + 1, a + n + 1);
    int res = 1;
    for(int i = 1; i <= mx; ++i) {
        if (cnt[i] == 0) {
            cout << 0;
            return;
        }
        res = (res * binpow(cnt[i], cnt[i + 1])) % mod;
    }
    cout << res;
}

signed main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    int test; test = 1;

    while(test--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 5120
from string import ascii_lowercase


def solve(string):
    n = int(string)
    ans = ""
    while n:
        n, c = divmod(n - 1, len(ascii_lowercase))
        ans = ascii_lowercase[c] + ans
    return ans


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 9924
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=55,COIN=3000;

int n,s;
int tm[MAXN][MAXN],cs[MAXN][MAXN];
vector<pii> G[MAXN*COIN];
void addEdge(int u,int v,int c){G[u].pb(mp(v,c));}
ll dis[MAXN*COIN];
priority_queue<pli,vector<pli>,greater<pli> > pq;
int ei(int x,int y){return x*COIN+y;}
void dijkstra(int src)
{
	memset(dis,0x3f,sizeof(dis));
	dis[src]=0;
	pq.push(mp(0ll,src));
	while(!pq.empty())
	{
		pli p=pq.top();pq.pop();
		int u=p.y;
		if(p.x>dis[u])continue;
		for(auto t:G[u])
		{
			int v=t.x,c=t.y;
			if(dis[v]>dis[u]+c)
				dis[v]=dis[u]+c,
				pq.push(mp(dis[v],v));
		}
	}
}

int main()
{
	int E,u,v,x,y;
	readint(n),readint(E),readint(s);
	chkmin(s,COIN-1);
	while(E--)
	{
		cin>>u>>v>>x>>y;
		for(int i=x;i<COIN;++i)
			addEdge(ei(u,i),ei(v,i-x),y),
			addEdge(ei(v,i),ei(u,i-x),y);
	}
	for(int i=1;i<=n;++i)
	{
		cin>>x>>y;
		for(int j=0;j<COIN-x;++j)
			addEdge(ei(i,j),ei(i,j+x),y); 
	}
	dijkstra(ei(1,s));
	for(int i=2;i<=n;++i)
	{
		ll res=1ll<<60;
		for(int j=0;j<COIN;++j)
			chkmin(res,dis[ei(i,j)]);
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 20488
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n,m;
	cin>>n>>m;
	if(n==1){
		cout<<m<<endl;
		return;
	}
	if(n&1) rep(i,n){
		if(i) cout<<" ";
		if(i<n/2){
			cout<<0;
		}
		else{
			cout<<m;
		}
	}
	else rep(i,n){
		if(i) cout<<" ";
		if(i<=n/2) cout<<0;
		else cout<<m;
	}
	cout<<endl;
}


signed main() {
	ios_base::sync_with_stdio(false);
    cin.tie(0);
  	cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 1192
#include <iostream>
    #include <string>
    #include <set>  
    #include <algorithm>
    #include <vector>
    #include <cmath>
    #include <queue>
    #include <deque>
    #include <cstring>
    #include <cstdio>
    #include <map>
    #include <numeric>
	#include <cassert>
    #include <iomanip>
    #include <sstream>
using namespace std;
int n,m;
int cnt[303][303],a[303][303];
int Min=1e9+7,Max,Maxm;
bool ban[303];
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
		{
			cin>>a[i][j];
			a[i][j]--;
		}
	for(int i=m-1;i>=0;i--)
	{
		for(int j=0;j<n;j++)
			for(int k=0;k<m;k++)
				if(!ban[a[j][k]])
				{
		//			cout<<a[j][k]<<endl;
					cnt[i][a[j][k]]++;
					break;
				}
		Max=-1,Maxm=-1;
		for(int j=0;j<m;j++)
		{	
			//cout<<cnt[i][j]<<" ";
			if(cnt[i][j]>Max)
				Max=cnt[i][j],Maxm=j;
		}
		//cout<<endl;
		Min=min(Min,Max);
		//cout<<Min<<" "<<Max<<" "<<Maxm<<endl;
		ban[Maxm]=1;
	}
	cout<<Min<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define pob pop_back
#define mp make_pair
#define ff first
#define ss second
#define pi 3.14159265
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <ll, ll> pll;
const ll M=1e9+7;
ll inf=1e18;
int main()
{
    int x;
    cin>>x;
    int y=__gcd(360,x);
    cout<<360/y;
}


Measured memory_bytes: 3652
require 'prime'
n = gets.to_i
mod = 1000000007
map = Hash.new(0)
(2..n).each do |i|
  primes = i.prime_division
  primes.each do |j|
    map[j[0]] += j[1]
  end
end
sum = 1
map.each do |_, v|
  sum *= v + 1
  sum %= mod
end
puts sum

Measured memory_bytes: 2300
package main

import (
	"fmt"
)

func main() {
	var sa, sb, sc string
	fmt.Scan(&sa, &sb, &sc)

	t := sa[0]
	for {
		switch t {
		case 'a':
			if len(sa) == 0 {
				fmt.Println("A")
				return
			}
			t = sa[0]
			sa = sa[1:]
		case 'b':
			if len(sb) == 0 {
				fmt.Println("B")
				return
			}
			t = sb[0]
			sb = sb[1:]
		case 'c':
			if len(sc) == 0 {
				fmt.Println("C")
				return
			}
			t = sc[0]
			sc = sc[1:]
		}
	}
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    vector<int> data(5);
    for (int i = 0; i < 5; i++) {
        cin >> data[i];
    }
    sort(all(data));

    cout << n / data[0] + !!(n % data[0]) + 4 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    cout << pow(N, 3) << endl;
    return 0;
}


Measured memory_bytes: 512
// ABC 075 D Axis-Parallel Rectangle

using System;
using System.Linq;

class Program
{
    static int N;
    static int K;
    static int[] x;
    static int[] y;

    static void Main()
    {
        /* 入力の受け取り */
        int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        N = input[0];
        K = input[1];
        x = new int[N];
        y = new int[N];
        for (int i = 0; i < N; i++)
        {
            input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            x[i] = input[0];
            y[i] = input[1];
        }

        /* a,c in xかつb,d in y の場合を全探索 */
        long ans = long.MaxValue;
        foreach (var a in x)
        {
            foreach (var c in x)
            {
                foreach (var b in y)
                {
                    foreach (var d in y)
                    {
                        if (Judge(a, b, c, d))
                            ans = Math.Min(ans, (long)(c - a) * (b - d));
                    }
                }
            }
        }
        Console.WriteLine(ans);
    }

    /* 左上の座標が(a,b), 右下の座標が(c,d)の長方形が、K個以上の点を含むか */
    static bool Judge(int a, int b, int c, int d)
    {
        if (a >= c || d >= b) return false;
        int count = 0;
        for (int i = 0; i < N; i++)
        {
            int xi = x[i];
            int yi = y[i];
            if (a <= xi && xi <= c && d <= yi && yi <= b)
                count++;
        }
        if (count >= K) return true;
        return false;
    }
}

Measured memory_bytes: 13396
// ARC090
// E - Avoiding Collision

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 100000;
const int MAX_M = 200000;
const int MAX_V = MAX_N;
const ll INF = 1e18;
const int MOD = 1e9 + 7;

class Graph {
public:
    ll dist[MAX_V];
    vector<pli> g[MAX_V];  // cost, to
    void add_edge(int from, int to, ll cost);
    void dijkstra(int s);
};

void Graph::add_edge(int from, int to, ll cost) {
    g[from].push_back(pli(cost, to));
    return;
}

void Graph::dijkstra(int s) {
    priority_queue<pli, vector<pli>, greater<pli>> q;
    pli p, e;

    fill(dist, dist + MAX_V, INF);
    dist[s] = 0;
    q.push(pli(dist[s], s));
    while (!q.empty()) {
        p = q.top();
        q.pop();
        if (dist[p.second] < p.first) {
            continue;
        }
        for (int i = 0; i < (int)g[p.second].size(); i++) {
            e = g[p.second][i];
            if (dist[e.second] > dist[p.second] + e.first) {
                dist[e.second] = dist[p.second] + e.first;
                q.push(pli(dist[e.second], e.second));
            }
        }
    }
    return;
}

int N, M;
int S, T;
Graph g;
vector<int> dps, dpt;

void calc_dp(int s, bool rev, vector<int>& dp) {
    vector<int> idx(N);
    ll k = (rev ? -1 : 1);

    iota(idx.begin(), idx.end(), 0);
    sort(idx.begin(), idx.end(),
         [&](int a, int b) { return k * g.dist[a] < k * g.dist[b]; });

    dp.resize(N);
    dp[s] = 1;
    for (int u : idx) {
        for (auto e : g.g[u]) {
            ll cost = e.first;
            int v = e.second;
            if (g.dist[u] + k * cost == g.dist[v]) {
                (dp[v] += dp[u]) %= MOD;
            }
        }
    }
}

ll mul_v(int u, int v) {
    ll tmp = 1;
    (tmp *= 1LL * dps[u] * dps[u] % MOD) %= MOD;
    (tmp *= 1LL * dpt[v] * dpt[v] % MOD) %= MOD;
    return tmp;
}

int main() {
    cin >> N >> M;
    cin >> S >> T;
    S--;
    T--;
    for (int i = 0; i < M; i++) {
        int u, v, d;
        cin >> u >> v >> d;
        g.add_edge(u - 1, v - 1, d);
        g.add_edge(v - 1, u - 1, d);
    }
    g.dijkstra(S);

    calc_dp(S, false, dps);
    calc_dp(T, true, dpt);

    for (int i = 0; i < N; i++) {
        cerr << dps[i] << ", ";
    }
    cerr << endl;
    for (int i = 0; i < N; i++) {
        cerr << dpt[i] << ", ";
    }
    cerr << endl;

    ll ans_e = 0;
    for (int u = 0; u < N; u++) {
        for (auto e : g.g[u]) {
            ll cost = e.first;
            int v = e.second;
            if ((g.dist[u] + cost == g.dist[v]) && 2 * g.dist[u] < g.dist[T] &&
                2 * g.dist[v] > g.dist[T]) {
                (ans_e += mul_v(u, v)) %= MOD;
            }
        }
    }

    ll ans_v = 0;
    for (int v = 0; v < N; v++) {
        if (2 * g.dist[v] == g.dist[T]) {
            (ans_v += mul_v(v, v)) %= MOD;
        }
    }

    ll ans = (1LL * dps[T] * dps[T] - ans_e + MOD - ans_v + MOD) % MOD;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 15856
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: u64,
    };

    let mut ans = 0;
    for a in 1..=n {
        for b in 1..=n {
            if a*b < n {
                ans += 1;
            } else {
                break;
            }
        }
    }

//    for i in 1..n {
//        if i*i < n {
//            ans += n - i*i;
//        } else {
//            break;
//        }
//    }

    println!("{}", ans);
}


Measured memory_bytes: 2200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 100010;
vector<int> G[N];

int par[N];
void dfs(int x){
    for(int e:G[x])if(e!=par[x]){
        par[e] = x;
        dfs(e);
    }
}

bool b[N]={};
int vis[N]={};

bool solve(){
    int n,u,v;
    scanf(" %d %d %d", &n, &u, &v);
    --u;
    --v;
    rep(i,n-1){
        int x,y;
        scanf(" %d %d", &x, &y);
        --x;
        --y;
        G[x].pb(y);
        G[y].pb(x);
    }

    // if(n%2==1) return false;

    par[u] = -1;
    dfs(u);

    int tt = v;
    while(tt!=u){
        b[tt] = true;
        tt = par[tt];
    }

    int R=1, B=1;
    vis[u] = 1;
    vis[v] = 2;

    int now = u;
    while(R<n/2){
        int ch=0;
        for(int e:G[now])if(par[now]!=e && !vis[e]) ++ch;

        if(ch==0) break;
        else if(ch==1){
            for(int e:G[now])if(par[now]!=e && !vis[e]){
                ++R;
                vis[e] = 1;
                now = e;
            }
        }
        else if(ch==2){
            for(int e:G[now])if(par[now]!=e && !vis[e]){
                if(!b[e]){
                    ++R;
                    vis[e] = 1;
                    now = e;
                    break;
                }
            }
        }
        else return false;
    }

    while(B<n/2){
        int ct = 0;
        for(int e:G[v])if(vis[e]==0) ++ct;
        if(ct==0) break;
        if(ct>=2) return false;

        for(int e:G[v])if(vis[e]==0){
            ++B;
            vis[e] = 2;
            v = e;
        }
    }

    rep(i,n)if(vis[i]==0) return false;
    return R==B;
}

int main(){
    cout << (solve()?"Yes":"No") << endl;
    return 0;
}



Measured memory_bytes: 14236
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int n;
int h[20],w[20];
const int H=4,W=4;
int ans=16;

set<string> used;

int dfs(string s){
    vector<int> dist(1<<16,inf);
    dist[0]=0;
    queue<int> que;
    que.push(0);
    while(que.size()){
        int cur=que.front();que.pop();
        rep(i,n){
            REP(j,-h[i]+1,H)REP(k,-w[i]+1,W){;
                int nxt=cur;
                int mask=0;
                rep(l,h[i])rep(m,w[i]){
                    if(0<=j+l&&j+l<H&&0<=k+m&&k+m<W&&!(cur&(1<<((j+l)*H+k+m)))){
                        nxt+=(1<<((j+l)*H+k+m));
                        mask|=(s[(j+l)*H+k+m]=='R')*4;
                        mask|=(s[(j+l)*H+k+m]=='G')*2;
                        mask|=(s[(j+l)*H+k+m]=='B')*1;
                    }
                }
                if(mask!=1&&mask!=2&&mask!=4)continue;
                if(dist[nxt]==inf){
                    dist[nxt]=dist[cur]+1;
                    que.push(nxt);
                }
            }
        }
    }
    return dist[65535];
}


int main(){
    cin>>n;
    rep(i,n){
        cin>>h[i]>>w[i];
    }
    string s;
    rep(i,4){
        string t;
        cin>>t;
        s+=t;
    }
    cout<<dfs(s)<<endl;
    return 0;
}


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

long long fn(long long val,long long a,long long b,long long n)
 {
     long long l(0),r(n),mid;
     while(l<=r)
     {
         mid=l+(r-l)/2;
         if(mid*a+(n-mid)*b>=val)
            r=mid-1;
         else
            l=mid+1;
     }
    //cout<<l<<" "<<n<<"\n";
    if(l==n+1) 1e9+7;
    return l;

 }
int main()
{
    long long n,a,b;
    cin>>n>>a>>b;

    vector< long long > arr(n);
    for(int i=0;i<n;i++)cin>>arr[i];

    long long l(1),r(1e9+7);

    while(l<=r)
    {
        long long mid=l+(r-l)/2;
        long long cnt(0);
        for(int i=0;i<n;i++)
            cnt+=fn(arr[i],a,b,mid);
      //  cout<<l<<" "<<r<<" "<<cnt<<" "<<mid<<"\n";
        if(cnt<=mid)
        r=mid-1;
        else
        l=mid+1;
    }
    cout<<l;
    return 0;
}


Measured memory_bytes: 1024