akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(decltype(t) i##0_to = (t), i = (f); i <= i##0_to; i++)
#define uptil(f, t, i)   for(decltype(t) i##0_to = (t), i = (f); i <  i##0_to; i++)
#define downto(f, t, i)  for(decltype(f) i##0_to = (t), i = (f); i >= i##0_to; i--)
#define downtil(f, t, i) for(decltype(f) i##0_to = (t), i = (f); i >  i##0_to; i--)
// types
    typedef long double LD;
    #define long long long
    #define int long
    using VI = vector<int>;
    using WI = vector<VI>;
    using PI = pair<int, int>;
    using VPI = vector<PI>;
    using WPI = vector<VPI>;

bool debug;
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 2
#define _LIBCPP_DEBUG2 2
#define ln << '\n'
#define tb << '\t'
#define sp << ' '
#define db(x) if(debug) cerr << #x << " = " << (x) << ", "
#define dbg(x) if(debug) cerr << #x << " = " << (x) ln

constexpr long INF = 1LL << 60;

void solve();

signed main(signed argc, char *argv[]) {
    #ifdef EBUG
        debug = true;
    #elif defined(ONLINE_JUDGE)
        debug = false;
    #else
        debug = argc >= 2;
    #endif
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(20);

    solve();

    return 0;
}

/******************************* basic library ********************************/
// IO
    template<class T>
    istream& operator>>(istream& s, vector<T>& v) {
        for(auto&& p : v) s >> p; return s;
    }
    template<class T>
    ostream& operator<<(ostream& s, vector<T> v) {
        int i = 0;
        for(const auto& p : v) s << (i++?" ":"") << p;
        return s;
    }
    template<class T>
    ostream& operator<<(ostream& s, vector<vector<T>> w) {
        for(const auto& v : w) {
            int i = 0;
            for(const auto& p : v) s << (i++?" ":"") << p;
            s ln;
        }
        return s;
    }
    template<class T, class... A>
    T RD(A... a) { T t(a...); cin >> t; return t; }
// other
    #define all(x) (x).begin(), (x).end()
    #define b_max(x, y) x = max(x, y)
    #define b_min(x, y) x = min(x, y)
    inline LD AC(LD d) { return d ? d : 0; }

/****************************** optional library ******************************/
//-mod constexpr long MOD = 1000000009; // 1000000007; // 998244353;

/************************************ main ************************************/

void solve() {
    int N; scanf("%lld", &N);
    int t1 = 0, x1 = 0, y1 = 0;
    times(N, i) {
        int T, X, Y; scanf("%lld%lld%lld", &T, &X, &Y);
        if((t1 + x1 + y1 + T + X + Y) % 2
        or abs(X - x1) + abs(Y - y1) > T - t1) {
            cout << "No" ln;
            return;
        }
    }
    cout << "Yes" ln;
}


Measured memory_bytes: 256
S = input()[::-1]
L = len(S)
MOD = 10**9+7
N = 13
# 0~13
dp = [ [0]*13 for i in range(L+1)]
dp[0][0] = 1
mul = 1

for i in range(L):
  if S[i] == "?":
    for prev in range(N):
      for j in range(10):
        dp[i+1][(j*mul+prev)%N] += dp[i][prev]
        dp[i+1][(j*mul+prev)%N] %= MOD
  else:
    j = int(S[i])
    for prev in range(N):
      dp[i+1][(j*mul+prev)%N] += dp[i][prev]
      dp[i+1][(j*mul+prev)%N] %= MOD
  
  mul *= 10
  mul %= N

print(dp[-1][5])

Measured memory_bytes: 61916
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        double total = 0.0;
        int t = 1900 * m + 100 * (n - m);
        double nth = t;
        int i = 0;
        double d = Math.pow(0.5, m);
        while (nth > 0.00000001) {
            i++;
            nth = ((double)t * i) * d;
            total += nth;
            d *= (1 - Math.pow(0.5, m));

        }
        System.out.println(Math.round(total));
    }
}

Measured memory_bytes: 35708
#include<bits/stdc++.h>
//***** Jai Gurudev *****//
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define all(x) x.begin(),x.end()
#define vii vector<pair<int,int> >
#define vll vector<pair<ll,ll> >
#define pb push_back
#define fi first
#define se second
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI 3.1415926535897932384626433832795
#define inf64 LLONG_MAX
#define inf32 INT_MAX
#define mod 1000000007
using namespace std;
vl seive(){ll n=2;vl pr(200000,-1);for(int i=n;i<200000;i++){if(pr[i]==-1)pr[i]=1;else continue;for(int j=2*i;j<200000;j+=i)pr[j]=0;}return pr;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
bool isprime(ll n) {bool flag=true;for(ll i=2; i<=sqrt(n);i++){if(n%i==0){flag=false;break;}}return flag;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main()
{
	fast
//	int t;
//	cin>>t;
//	while(t--)
//	{
		int n;
		cin>>n;
		vi a(n);
		for(int i=0;i<n;i++)
		cin>>a[i];
		sort(all(a));
		int ct=0;
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				for(int k=j+1;k<n;k++)
				{
					if(a[i]!=a[j]&&a[j]!=a[k])
					if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i])
					ct++;
				}
			}
		}
		cout<<ct<<"\n";
//	}
	return 0;
}


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

using namespace std;

using ll = long long;
vector<ll> g[57];
bool bio[57];
vector<ll> tin(57), low(57);
ll timer;
ll ans = 0;

void dfs(ll u, ll p = -1){
    bio[u] = true;
    tin[u] = low[u] = timer++;
    for (auto to : g[u]){
        if (to == p)continue;
        if (bio[to]) {
            low[u] = min(low[u], tin[to]);
        }else {
            dfs(to, u);
            low[u] = min(low[u], low[to]);
            if (low[to] > tin[u])
                ans++;
        }
    }
}

int main(){
    ll n, m;
    cin >> n >> m;
    for(ll i = 1; i <= m; ++i){
        ll u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1);
    cout << ans;
    return 0;
}


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

using namespace std;

typedef long long ll;

ll e_gcd(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1, y = 0;
		return a;
	}
	ll val = e_gcd(b, a % b, x, y);
	ll nx = x, ny = y;
	x = ny;
	y = nx - (a / b) * ny;
	return val;
}

int main() {
	ll a, b;
	cin >> a >> b;
	ll x, y;
	auto tmp = e_gcd(a, b, x, y);
	cout << x << " " << y << endl;
	return 0;
}



Measured memory_bytes: 3100
n = int(input())
rests = []
for i in range(n):
    rest_name, point = input().split() 
    rests.append([rest_name, int(point)])

sorted_rests = sorted(rests, key=lambda x: (x[0], -x[1]))

for i in range(len(sorted_rests)):
    for j in range(len(rests)):
        if sorted_rests[i] == rests[j]:
            print(j + 1)
            break
            


Measured memory_bytes: 3060
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
string str;
long long sum,cnt;
int main(){
	cin>>str;
	for (int i=0;i<(1<<(str.length()-1));i++){
		for (int j=0;j<str.length();j++){
			cnt=cnt*10+int(str[j]-'0');
			if ((i>>j)&1){
				sum+=cnt;
				cnt=0;
			}
		}
		sum+=cnt;
		cnt=0;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
from math import sqrt

xs, ys, xt, yt = map(int, input().split())
N = int(input())
xyr = [[int(i) for i in input().split()] for _ in range(N)]

cost = [0] * N
h = []

def dist(x, y) :
    return sqrt(x ** 2 + y ** 2)

for i, (x, y, r) in enumerate(xyr) :
    d = max(0, dist(xs-x, ys-y) - r)
    heappush(h, (d, i))
    cost[i] = d
 
while h :
    dc, i = heappop(h)
    if cost[i] < dc :
        continue
        
    xc, yc, rc = xyr[i]
    
    for i, (x, y, r) in enumerate(xyr) :
        d = dc + max(0, dist(xc-x, yc-y) - rc - r)
        if d < cost[i] :
            heappush(h, (d, i))
            cost[i] = d
            
ret = sqrt((xs-xt) ** 2 + (ys-yt)**2)
for i, (x, y, r) in enumerate(xyr) :
    ret = min(ret, cost[i] + max(0, dist(xt-x, yt-y) - r))
    
print(ret)

Measured memory_bytes: 93660
#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct TNode
{
	int Id;
	TNode* Parent;
	TNode* NextSibling;
	TNode* FirstChild;
};

enum TNodeType {Root, InternalNode, Leaf};

void Create(int Id, vector<TNode*>& Nodes)
{
	TNode* Node = new TNode;
	*Node = {Id, NULL, NULL, NULL};
	Nodes[Id] = Node;
}

void CreateRelation(TNode* ParentNode, TNode* LastChild, TNode* ChildNode)
{
	if(LastChild == NULL){
		ParentNode->FirstChild = ChildNode;
		ChildNode->Parent = ParentNode;
	}else{
		LastChild->NextSibling = ChildNode;
		ChildNode->Parent = LastChild->Parent;
	}
}

vector<TNode*> Input()
{
	int n;
	cin >> n;
	vector<TNode*> Nodes(n, NULL);
	for(int i = 0; i < n; i++){
		int Id;
		cin >> Id;
		if(Nodes[Id] == NULL){
			Create(Id, Nodes);
		}
		int ChildCount;
		cin >> ChildCount;
		TNode* LastChild = NULL;
		for(int j = 0; j < ChildCount; j++){
			int ChildId;
			cin >> ChildId;
			if(Nodes[ChildId] == NULL){
				Create(ChildId, Nodes);
			}
			CreateRelation(Nodes[Id], LastChild, Nodes[ChildId]);
			LastChild = Nodes[ChildId];
		}
	}
	return Nodes;
}

int GetDepth(const TNode* Node)
{
    int depth = 0;
    while(Node->Parent){
        depth++;
        Node = Node->Parent;
    }
    return depth;
}

TNodeType GetType(const TNode* Node)
{
    if(Node->Parent == NULL){
        return Root;
    }else if(Node->FirstChild == NULL){
        return Leaf;
    }else{
        return InternalNode;
    }
}

void OutputChildren(const TNode* Node)
{
    if(Node->FirstChild == NULL){
        return;
    }
    Node = Node->FirstChild;
    cout << Node->Id; 
    while(Node->NextSibling){
        Node = Node->NextSibling;
        cout << ", " << Node->Id;
    }
}

void Output(const vector<TNode*>& Nodes)
{
	for(unsigned int i = 0; i < Nodes.size(); i++){
		cout << "node " << Nodes[i]->Id << ": ";
		if(Nodes[i]->Parent){
		    cout << "parent = " << Nodes[i]->Parent->Id << ", ";
		}else{
		    cout << "parent = -1, ";
		}
		cout << "depth = " << GetDepth(Nodes[i]) << ", ";
		if(GetType(Nodes[i]) == Root){
		    cout << "root, "; 
		}else if(GetType(Nodes[i]) == InternalNode){
		    cout << "internal node, ";    
		}else{
		    cout << "leaf, ";
		}
		cout << "[";
		OutputChildren(Nodes[i]);
		cout << "]" << endl;
	}
}

int main()
{
	vector<TNode*> Nodes = Input();
	Output(Nodes);
    return 0;
}

Measured memory_bytes: 8292
import sys
input = sys.stdin.readline
a,b=map(int,input().split())
s=input().strip()
flg=True
for i in range(a):
    if s[i]=="-":
        flg=False
if s[a]!="-":
    flg=False
for i in range(b):
    if s[a+i+1]=="-":
        flg=False
print("Yes" if flg else "No")


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

using namespace std;

int main(){
    int n, k, q;
    cin>>n>>k>>q;
    vector <int> s(n);
    for(int i=0;i<n;i++){
        s[i]=0;
    }
    for(int i=0;i<q;i++){
        int a;
        cin>>a;
        s[a-1]++;
    }
    for(int i=0;i<n;i++){
        if(q-s[i]<k){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}
//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
bool isPrime(int x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

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

    rep(i,s.size()){
        if(s[i]!=t[i]){
            puts("No");
            return 0;
        }
    }

    puts("Yes");

    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 15
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
  scanf("%d",&head);
  RI(tail...);
}
using namespace std;
typedef long long LL;
using P = pair<int,int>;
vector<P> p;
vector<int> lisan;
long double calc(int n) {
	long double res = 0;
	for(int i = 0; i < n-1; i++) {
		res += sqrt((long double)pow(p[lisan[i]].first - p[lisan[i+1]].first, 2) + 
														 pow(p[lisan[i]].second - p[lisan[i+1]].second, 2) );
	}
	return res;
}
int main()
{  
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		p.push_back(make_pair(x, y));
		lisan.push_back(i);
	}
	long double sum = 0;
	int cnt = 0;
	do {
		sum += calc(n);
		cnt++;
	} while(next_permutation(lisan.begin(), lisan.end()));
	cout << fixed << setprecision(6) << sum / cnt << endl;
  return 0;
}


Measured memory_bytes: 256
icase=0
if icase==0:
    n,m,x,y=map(int,input().split())
    xi=list(map(int,input().split()))        
    xi.append(x)
    yi=list(map(int,input().split()))        
    yi.append(y)
    if max(xi)<min(yi):
        print("No War")
    else:
        print("War")

Measured memory_bytes: 3060
import java.util.*

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }

    val graph = Graph1(n)
    repeat(m) {
        val (x, y) = readLine()!!.split(' ').map { it.toInt() }
        graph.add(x - 1, y - 1)
    }

    println(graph.solve())
}

class Graph1 constructor(private val n: Int) {
    private val graph = Array(n) { mutableListOf<Int>() }
    private val dp = IntArray(100000) { -1 }

    fun add(x: Int, y: Int) {
        graph[x].add(y)
    }

    private fun rec(v: Int): Int {
        if (dp[v] != -1) return dp[v]

        var res = 0
        graph[v].forEach {
            res = Math.max(res, rec(it) + 1)
        }
        dp[v] = res
        return res
    }

    fun solve(): Int {
        var res = 0
        (0 until n).forEach {
            res = Math.max(res, rec(it))
        }
        return res
    }

}

class Graph2 constructor(private val n: Int) {
    private val graph = Array(n) { mutableListOf<Int>() }
    private val deg = IntArray(n) { 0 }
    private val dp = IntArray(100000) { 0 }

    fun add(x: Int, y: Int) {
        graph[x].add(y)
        deg[y]++
    }

    fun solve(): Int {

        val queue: Queue<Int> = ArrayDeque<Int>()
        deg.forEachIndexed { index, i ->
            if (i == 0) {
                queue.add(index)
            }
        }

        while (queue.isNotEmpty()) {
            val v = queue.remove()
            graph[v].forEach {
                deg[it]--
                if (deg[it] == 0) {
                    queue.add(it)
                    dp[it] = Math.max(dp[it], dp[v] + 1)
                }
            }
        }

        var res = 0
        (0 until n).forEach {
            res = Math.max(res, dp[it])
        }
        return res
    }

}

Measured memory_bytes: 71444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s, t;
	cin >> s >> t;
	int n = s.size();
	int m = t.size();
	int dp[n + 1][m + 1];
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			dp[i][j] = 0;
		}
	}
	for (int i = 0; i <= n; i++)dp[i][0] = 0;
	for (int i = 0; i <= m; i++)dp[0][i] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i - 1] == t[j - 1])
				dp[i][j] = max(dp[i][j], 1 + dp[i - 1][j - 1]);
			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}
	string res = "";
	int i = n, j = m;
	while (i >= 0 && j > 0) {
		if (s[i - 1] == t[j - 1]) {
			res += s[i - 1];
			i--;
			j--;
		}
		else if (dp[i - 1][j] > dp[i][j - 1])
			i--;
		else
			j--;
	}
	reverse(res.begin(), res.end());
	cout << res << endl;
}

Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(a),ed=(b);i<=ed;++i)
typedef long long ll;
inline int read(){
    register int x=0,f=1;register char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
    while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}
    return f?x:-x; 
}

const int N=5e3+10;
int n,m,c[N],f[N];
inline void pls(int &x,int y){x=x+y>=m?x+y-m:x+y;}

int main(){
    //freopen("in.in","r",stdin);
    n=read(),m=read();
    int k=(n+1)>>1;
    REP(i,2,k)c[i]=i-2;
    if(n&1)REP(i,1,k-1)c[k+k-i]=i;
    else{c[k+1]=k-1;REP(i,1,k-1)c[k+k+1-i]=i;}
    REP(i,2,n)++c[i];
    f[0]=1;
    REP(i,2,n)REP(j,c[i],n-1)pls(f[j],f[j-c[i]]);
    int ans=0;
    REP(i,0,n-1)pls(ans,1ll*f[i]*(n-i)%m);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,r=0,f=0;
  cin>>n;
  vector<int> a(n);
  for(auto& i:a)cin>>i;
  sort(a.begin(),a.end());
  for(int i=0;i<n;++i){
    if(!i)f++;
    else if(a[i]==a[i-1])f++;
    else r+=f%2,f=1;
  }
  cout<<r+f%2;
}

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

int main() {
    int l,r,d;

    cin >> l >> r >> d;

    int ans = 0;
    for (int i = l; i <= r; i++) {
        if (i % d == 0) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
require 'prime'

n, m = gets.strip.split.map(&:to_i)
MOD = 10**9+7

def power(n, k)
  return 1 if k==0
  return power(n, k/2)**2 % MOD if k.even?
  n*power(n, k-1) % MOD
end

fmax = Math.sqrt(m).ceil+n
@factor = [1,1]
(2..fmax).each do |i|
  @factor[i] = i*@factor[i-1] % MOD
end

@ifactor = [1,1]
@ifactor[fmax-2] = power(@factor[fmax-2], MOD-2) % MOD
(fmax-3).downto(2).each do |i|
  @ifactor[i] = @ifactor[i+1]*(i+1) % MOD
end

def comb(n, k)
  @factor[n]*(@ifactor[n-k]*@ifactor[k]%MOD)%MOD
end

divisions = m.prime_division

ans=1
divisions.each do |pr, div|
  ans = ans * comb(div+n-1, n-1) % MOD
end

#p @factor
#p @ifactor

p ans

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

int main() {
  int n,k;
  cin >> n >> k;
  double sum = 0;
  rep(i,1,n+1){
    int v = i;
    double nn = n;
    double a = 1/nn;
    while(v < k){
      v *= 2;
      a /= 2;
    }
    sum += a;
  }
  cout << fixed;
  cout << setprecision(12) << sum << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        t: usize,
        cases: [(u64, u64, u64, u64, u64);t],
    }

    for (n, a, b, c, d) in cases {
        let mut memo: HashMap<u64, u64> = HashMap::new();
        let ans = solve(n, a, b, c, d, &mut memo);
        println!("{}", ans);
    }
}

fn solve(n: u64, a: u64, b: u64, c: u64, d: u64, memo: &mut HashMap<u64, u64>) -> u64 {
    if n == 0 {
        return 0;
    }
    if n == 1 {
        return d;
    }
    if let Some(&n) = memo.get(&n) {
        return n;
    }

    let mut res = d.saturating_mul(n);

    //A
    let a_plus = 2 - (n % 2);
    res = min(res, solve((n + 1) / 2, a, b, c, d, memo) + a + d * a_plus);

    let a_minus = n % 2;
    res = min(res, solve(n / 2, a, b, c, d, memo) + a + d * a_minus);

    //B
    let b_plus = 3 - (n % 3);
    res = min(res, solve(n / 3 + 1, a, b, c, d, memo) + b + d * b_plus);

    let b_minus = n % 3;
    res = min(res, solve(n / 3, a, b, c, d, memo) + b + d * b_minus);

    //C
    let c_plus = 5 - (n % 5);
    res = min(res, solve(n / 5 + 1, a, b, c, d, memo) + c + d * c_plus);

    let c_minus = n % 5;
    res = min(res, solve(n / 5, a, b, c, d, memo) + c + d * c_minus);

    memo.insert(n, res);
    res
}


Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 N;
  cin >> N;
  vector<vector<i64>> a(N + 1, vector<i64>(4));
  for(int i = 0;i < N;i++) cin >> a[i][1] >> a[i][2] >> a[i][3];

  vector<vector<i64>> dp(N + 1, vector<i64>(4, -1e9));
  dp[0][0] = 0;
  for(int i = 0;i < N;i++) {
    for(int j = 0;j <= 3;j++) {
      for(int k = 1;k <= 3;k++) {
        if(j == k) continue;
        dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k]);
      }
    }
  }

  cout << *max_element(all(dp[N])) << endl;
}


Measured memory_bytes: 14336
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x), b(y), c(z);
    rep(i, x) {
        cin >> a[i];
    }
    rep(i, y) {
        cin >> b[i];
    }
    rep(i, z) {
        cin >> c[i];
    }

    vector<ll> ab;
    rep(i, x) {
        rep(j, y) {
            ab.push_back(a[i] + b[j]);
        }
    }

    sort(ab.begin(), ab.end());
    reverse(ab.begin(), ab.end());

    vector<ll> abc;
    rep(i, min(k, (int)ab.size())) {
        rep(j, z) {
            abc.push_back(ab[i] + c[j]);
        }
    }

    sort(abc.begin(), abc.end());
    reverse(abc.begin(), abc.end());

    rep(i, k) {
        cout << abc[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 43368
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll inf = 1e18;
ll mod=1e9+7;
//LLONG_MIN

ll ans=0;
string s;
stack<ll> st;

int main(void){
	cin>>s;
	rep(i,s.size()){
		ll q = s[i]-'0';
		if(st.empty()){
			st.push(q);
			continue;
		}
		ll p = st.top();
		if(p!=q){
			st.pop();
			ans+=2;
		}else{
			st.push(q);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int x, y;

  while (true) {
    cin >> x >> y;

    if (x == 0 && y == 0) {
      break;
    }

    if (x <= y) {
      cout << x << " " << y << endl;
    } else {
      cout << y << " " << x << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
from collections import Counter

N = int(input())
A1 = list(map(int, input().split()))
A2 = [-1 * A1[i] for i in range(N)]

for i in range(N):
    A1[i] -= i
    A2[i] -= i

C1 = Counter(A1)
C2 = Counter(A2)
res = 0
for c1 in C1.keys():
    res += C1[c1] * C2[c1]
print(res)


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

int main(void){
	int n;
	int list[100005];

	scanf("%d", &n);
	int in;
	long sum = 0;
	for(int i = 0; i < 100001; list[i++] = 0);
	for(int i = 0; i < n; i++){
		scanf("%d", &in);
		list[in]++;
		sum += in;
	}
	int q;
	scanf("%d", &q);
	int to;
	int from;
	for(int i = 0; i < q; i++){
		scanf("%d %d", &from, &to);
		sum += (to - from) * list[from];
		list[to] += list[from];
		list[from] = 0;
		printf("%ld\n", sum);
	}
	return 0;
}


Measured memory_bytes: 2500
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
int n,m,k,a[15][15],c[15],ans=100000000;
int main()
{
	cin>>n>>m>>k;
	rep(i,n)
	{
		cin>>c[i];
		rep(j,m)
		cin>>a[i][j];
	}
	rep(i,1<<n)
	{
		int cnt=0,s[15]={0};
		bool ok=1;
		rep(j,n)
		{
			if((i>>j&1)==1)
			{
				cnt+=c[j];
				rep(l,m)
				s[l]+=a[j][l];
			}
		}
		rep(j,m)
		if(s[j]<k)
		{
			ok=0;
			break;
		}
		if(ok) ans=min(ans,cnt);
	}
	if(ans==100000000) re(-1)
	re(ans)
	return 0;}

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

//https://atcoder.jp/contests/agc004/tasks/agc004_b

const int nm = 2e3;
int n;
ll x, a[nm][nm], temp, ans = 2e12;

int main() {
	cin >> n >> x;
	for (int i = 0; i < n; ++i)
		cin >> a[0][i];
	for (int i = 1; i < n; ++i)
		for (int j = 0; j < n; ++j)
			a[i][j] = min(a[i - 1][(j + n - 1) % n], a[0][j]);
	for (int i = 0; i < n; ++i) {
		temp = x * i;
		for (int j = 0; j < n; ++j)
			temp += a[i][j];
		ans = min(ans, temp);
	}
	cout << ans << endl;
}


Measured memory_bytes: 34888
#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>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
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 vector<LL> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

template<class T>
void in(T& x) {
	cin >> x;
}

template<class T1,class T2>
void in(pair<T1, T2>& p) {
	in(p.first);
	in(p.second);
}

template<class T>
void in(vector<T>& v,LL st=-1,LL en=-1) {
	if (st == -1) {
		st = 0;
		en = v.size() - 1;
	}
	for (LL n = st; n <= en; n++) {
		in(v[n]);
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	string S;
	cin >> S;
	for (LL n = 0; n < S.size(); n++)cout << "x";
	cout << "\n";
	return 0;
}

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

using namespace std;


//二項係数ライブラリ
const int MAX = 1000000;
const int MOD = 1000000007;

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

long long 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;
}
//前処理COMinit()忘れずに


void solve() {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    COMinit();

    sort(A.begin(), A.end());

    long long ans = 0;

    for (int i = 0; i < N; i++) {
        long long plus, minus;

        if (i < K-1) plus = 0;
        else plus = COM(i, K-1);
        if (i >= N - K + 1) minus = 0;
        else minus = COM(N-1-i, K-1);

        ans += A[i] * (plus - minus);
        if (ans < 0) ans += MOD;
        ans %= MOD;
    }

    cout << ans << endl;
}


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

Measured memory_bytes: 27076
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define nyan "(=^･ω･^=)"
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    ll way[30005];
    ll n, r, g, b;

    cin >> r >> g >> b >> n;

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

    for(int i = g; i <= n; i++) {way[i] += way[i-g];}
    

    for(int i = b; i <= n; i++) {way[i] += way[i-b];}

    cout << way[n] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>

int main()
{
  int cnt;
  int N, K;
  int i;
  int result = 0;

  cnt = scanf("%d %d", &N, &K);

  for (i=1; i<=N; i++) {
    if ((i+(K-1)) <= N) {
      result++;
    }
  }
  printf("%d", result);

  return 0;
} 

Measured memory_bytes: 128
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let m: usize = input();
    let p: i32 = input();
    let abc: Vec<(usize, usize, i32)> = (0..m)
        .map(|_| {
            let a: usize = input();
            let b: usize = input();
            let c: i32 = input();
            (a - 1, b - 1, -c + p)
        })
        .collect();

    let mut e1 = vec![vec![]; n];
    let mut e2 = vec![vec![]; n];
    for &(a, b, _) in &abc {
        e1[a].push(b);
        e2[b].push(a);
    }

    let mut ok1 = vec![false; n];
    dfs(0, &e1, &mut ok1);
    let mut ok2 = vec![false; n];
    dfs(n - 1, &e2, &mut ok2);

    let mut e = vec![];
    for &(a, b, c) in &abc {
        if ok1[a] && ok2[a] && ok1[b] && ok2[b] {
            e.push((a, b, c));
        }
    }

    let mut dist = vec![1001001001; n];
    let cycle = bellman_ford(n, &e, 0, &mut dist);
    if cycle {
        println!("-1");
    } else {
        println!("{}", std::cmp::max(0, -dist[n - 1]));
    }
}

fn dfs(cur: usize, e: &Vec<Vec<usize>>, ok: &mut Vec<bool>) {
    ok[cur] = true;
    for &nxt in &e[cur] {
        if !ok[nxt] {
            dfs(nxt, e, ok);
        }
    }
}

fn bellman_ford(
    n: usize,
    edge: &Vec<(usize, usize, i32)>,
    start: usize,
    dist: &mut Vec<i32>,
) -> bool {
    dist[start] = 0;
    let mut cycle = true;
    for _ in 0..n + 1 {
        let mut updated = false;
        for &(u, v, w) in edge {
            if dist[u] + w < dist[v] {
                dist[v] = dist[u] + w;
                updated = true;
            }
        }
        if !updated {
            cycle = false;
            break;
        }
    }
    cycle
}


Measured memory_bytes: 4476
import numpy as np
 
N, M = map(int, input().split())
array = np.zeros([M, N])
for i in range(M):
    l = list(map(int, input().split()))
    for j in l[1:]:
        array[i, j-1] = 1
p = np.array(list(map(int, input().split())))
count = 0
for i in range(1<<N):
    array_i = array.copy()
    for j in range(N):
        if i&(1<<j):
            array_i[:, j-1] = 0
    if sum(array_i.sum(1)%2 == p)==M:
        count += 1
print(count)

Measured memory_bytes: 27228
#include <stdio.h>

int main()
{
	int max,a[100000],sum,k,n;

	
	while(scanf("%d %d",&n,&k) && n || k ){
	
		for(int i = 0; i < n; i++){
			scanf("%d",&a[i]);
		}
	
		sum = 0;
		for(int i = 0; i < k; i++){
			sum += a[i];
		}
	
		max = sum;
		for(int i = k; i < n; i++){
			sum += a[i]-a[i-k];
			if(sum > max){
				max = sum;
			}
		}

		printf("%d\n",max);
	}

	return 0;
}

Measured memory_bytes: 1416
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-13)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

double dot(P a, P b) {
    return (a.X * b.X + a.Y * b.Y);
}

// 2???????????????????????????????±???????
double cross(P a, P b) {
    return (a.X * b.Y - a.Y * b.X);
}

P projection(P a1, P a2, P p) {
    return a1 + dot(a2-a1, p-a1) / norm(a2-a1) * (a2-a1);
}

// ??´??? a1, a2 ??¨??? C ??¨?????????
vector<P> crossp_lc(P a1, P a2, C c) {
    vector<P> ps;
    double r = c.second;
    P ft = projection(a1, a2, c.first);
    if(!GEQ(r*r, norm(ft-c.first))) return ps;

    P dir = sqrt(max(r*r - norm(ft-c.first), 0.0)) / abs(a2-a1) * (a2-a1);
    ps.push_back(ft + dir);
    if(!EQ(r*r, norm(ft-c.first))) ps.push_back(ft - dir);
    return ps;
}

int main() {
    C a;
    cin >> a.fr.X >> a.fr.Y >> a.sc;
    int n; cin >> n;
    rep(i,0,n) {
        P x, y;
        cin >> x.X >> x.Y >> y.X >> y.Y;
        vector<P> ans = crossp_lc(x, y, a);
        if(ans.size() == 1) {
            printf("%.10f %.10f %.10f %.10f\n", ans[0].X, ans[0].Y, ans[0].X, ans[0].Y);
        }
        else {
            sort(ans.begin(), ans.end());
            printf("%.10f %.10f %.10f %.10f\n", ans[0].X, ans[0].Y, ans[1].X, ans[1].Y);
        }
    }
    return 0;
}

Measured memory_bytes: 1272
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define int long long
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 1e7 + 10 ;
const ll INF = 1e18 + 10 ;
bool go(string s){
    string t = s ;
    reverse(t.begin(), t.end()) ;
    return t == s ;
}
signed main(){
    fastio
    int n ;
    cin >> n ; 
    double a = n / 3.0 ; 
    double ans = a * a * a ;
    cout << fixed << setprecision(12) << ans << endl;
    return 0; 
}

Measured memory_bytes: 256
using System;

namespace AtCoder.Abc
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = int.Parse(Console.ReadLine());
            var res = 1000 - (n % 1000);
            if (res == 1000) res = 0;
            Console.WriteLine(res);

            Console.Out.Flush();
        }
    }
}


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

using namespace std;

const int INF = 1e9+10;

int main(){
	int k,n,ans = 0;
	cin >> k >> n;
	vector<int> v(n),dist(n,INF);
	for(auto &x:v) cin >> x;
	sort(v.begin(),v.end());

	for(int i=0;i<n-1;++i)
		dist[i] = abs(v[i]-v[(i+1)%n]);

	dist[n-1] = (k-v[n-1])+v[0];

	sort(dist.begin(),dist.end());

	for(int i=0;i<n-1;++i){
		ans+=dist[i];
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int dp[100005][4];
int a[100005][4];
int n;
int func(int day,int flag)
{
    if(day==n)
    return 0;
    if(dp[day][flag]!=-1)
    return dp[day][flag];
    int maxi=0;
    if(flag==0)
    {
        maxi=max(maxi,a[day][1]+func(day+1,1));
        maxi=max(maxi,a[day][2]+func(day+1,2));
        maxi=max(maxi,a[day][3]+func(day+1,3));
    }
    else if(flag==1)
    {
        maxi=max(maxi,a[day][2]+func(day+1,2));
        maxi=max(maxi,a[day][3]+func(day+1,3));
    }
    else if(flag==2)
    {
        maxi=max(maxi,a[day][1]+func(day+1,1));
        maxi=max(maxi,a[day][3]+func(day+1,3));
    }
    else
    {
        maxi=max(maxi,a[day][1]+func(day+1,1));
        maxi=max(maxi,a[day][2]+func(day+1,2));
    }
    return dp[day][flag]=maxi;
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        for(int j=1;j<=3;j++)
        cin>>a[i][j];
    }
    memset(dp,-1,sizeof(dp));
    cout<<func(0,0);
}


Measured memory_bytes: 14532
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int a = scanner.nextInt();
        final int b = scanner.nextInt();
        final int c = scanner.nextInt();

        System.out.println(Math.max(c - a + b, 0));
    }
}


Measured memory_bytes: 23124
def is_divisible(x):
    if x % 2 == 0:
        return True
    return False

num = int(input())
count = 0
lis = [int(n) for n in input().split()]

while all([is_divisible(n) for n in lis]):
    count += 1
    lis = [n//2 for n in lis]

print(count)

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

static int Par[100000], Rank[100000];

void init(int n) {
	for (int i = 0; i < n; i++) {
		Par[i] = i;
		Rank[i] = 0;
	}
}

int root(int x) {
	if (Par[x] == x) return x;
	return Par[x] = root(Par[x]);
}

bool same(int x, int y) {
	return root(x) == root(y);
}

void unite(int x, int y) {
	x = root(x);
	y = root(y);
	if (x == y) return;
	if (Rank[x] < Rank[y]) {
		Par[x] = y;
	}
	else {
		Par[y] = x;
		if (Rank[x] == Rank[y]) Rank[x]++;
	}
}

int main() {
	int N, M, P[100000], ans = 0;
	cin >> N >> M;
	init(N);
	for (int i = 0; i < N; i++) {
		int p;
		cin >> p;
		P[i] = p - 1;
	}
	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		unite(x, y);
	}
	for (int i = 0; i < N; i++) {
		if (same(i, P[i])) ans++;
	}
	cout << ans;
}

Measured memory_bytes: 1408
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int k[2001];
int r[2001];

int fir(int a, int x){
	if(x==1) return a;
	int b = fir(a, x/2);
	b = ((long)b)*b%P;
	if((x&1)==0){
		return b;
	}else{
		return ((long)b)*a%P;
	}
}

long comb(int a, int b){
	if(a<b) return 0;
	return ((long)k[a])*r[b]%P*r[a-b]%P;
}

int main(void){
	int n, m;
	scanf("%d%d", &n, &m);
	k[0]=1;
	for(int i=1; i<=n; i++){
		k[i]=k[i-1]*((long)i)%P;
	}	
	r[n]=fir(k[n], P-2);
	for(int i=n-1; i>=0; i--){
		r[i]=((long)r[i+1])*(i+1)%P;
	}
	for(int i=1; i<=m; i++){
		printf("%ld\n", comb(n-m+1, i)*comb(m-1, i-1)%P);
	}
}


Measured memory_bytes: 128
#include <algorithm>
#include <functional>
#include <iostream>
#include <set>
#include<iomanip>
#include<queue>
#include <cstdint>


using namespace std;

int main() {
	int way[4];
	for(int i=0;i<4;i++){
		way[i]=0;
	}
	int a,b;
	for(int i=0;i<3;i++){
		cin>>a>>b;
		++way[a-1];
		++way[b-1];
	}
	int odd_num = 0;
	for(int i=0;i<4;i++){
		if(way[i]%2==1){
			odd_num++;
		}
	}
	if(odd_num==2){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;

}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long  

int32_t main(){

        IOS;
        int l,r,d;
        cin >> l >> r >> d;
        int ans = 0;
        for(int i=l;i<=r;i++){
            if(i%d == 0)
                ans++;
        }
        cout << ans << endl;
        
    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rt return
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll n,a,b;
int main()
{
    cin>>n>>a>>b;
    ll ans1=min(a,b);
    ll ans2=max(0ll,a+b-n);
    cout<<ans1<<" "<<ans2;
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;

  int a = 0;
  for (int i = 0; i < 4; i++) {
    if (s[i] == '+') {
      a++;
    } else {
      a--;
    }
  }

  cout << a << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
//import java.util.Map.Entry;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        long MOD = (long) (Math.pow(10, 9) + 7);
        int n = sc.nextInt();
        long array[] = new long[n];
        long arr[] = new long[2];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        Arrays.sort(array);
        int count = 0;
        for (int i = n - 1; i >= 1; i--) {
            if (array[i] == array[i - 1]) {
                arr[count] = array[i];
                count++;
                i--;
            }
            if (count == 2) {
                break;
            }
        }
        System.out.println(arr[0] * arr[1]);
        bw.flush();
    }
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//

    static class Pair implements Comparable<Pair> {

        int a, b;

        public Pair(int x, int y) {
            a = x;
            b = y;
        }

        @Override
        public int compareTo(Pair p) {
            return a - p.a;
        }
    }

    static void forl_0(int n, int[] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
    }

    static void forl_1(int n, int[] array, Scanner sc) {
        for (int i = 1; i <= n; i++) {
            array[i] = sc.nextInt();
        }
    }

    static void two_d(int n, int m, int[][] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                array[i][j] = sc.nextInt();
            }
        }
    }

    static boolean isPrime(long n) {
        if (n < 2) {
            return false;
        } else if (n == 2 || n == 3) {
            return true;
        } else if (n % 2 == 0 || n % 3 == 0) {
            return false;
        }
        long sqrtN = (long) Math.sqrt(n) + 1;
        for (long i = 6L; i <= sqrtN; i += 6) {
            if (n % (i - 1) == 0 || n % (i + 1) == 0) {
                return false;
            }
        }
        return true;
    }

    public static long gcd(long a, long b) {
        return (b == 0) ? a : gcd(b, a % b);
    }

    public static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
    }
}


Measured memory_bytes: 59348
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define sortall(obj) sort(ALL(obj))
#define revall(obj) reverse(ALL(obj))
#define SortRevAll(obj) revall(sortall(obj))
typedef string str;
typedef long long ll;
const int mod=1e9+7;
const int INF=1e9;
const ll LINF=1e18;
#define VI vector<int>
#define P pair
#define M map
#define F first()
#define S second()
#define PB(a) push_back(a)
#define IN(a) insert(a)
#define ins(a) int a;cin >> a
#define lls(a) ll a;cin >> a
#define in(a) cin >> a
#define sts(a) string (a);cin >> a
#define For(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) For(i,0,n)
#define Forr(i,m,n) for(int i=n-1;i>=m;i--)
#define repr(i,n) Forr(i,0,n)
#define print(a) cout << a << endl
#define Endl cout << endl
#define YES(n) cout << ((n)? "YES" : "NO") << endl
#define Yes(n) cout << ((n)? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define br(c,y,n) cout << ((c)? y : n) << endl

int main(){
    ins(a);ins(b);ins(c);ins(d);
    if(a*b>c*d){
        print(a*b);
    }else{
        print(c*d);
    }
    return 0;
}

Measured memory_bytes: 256
/* Dynamic Programming implementation of LCS problem */
#include <bits/stdc++.h> 
using namespace std; 

// Maximum string length 
#define N 3000+1 

int dp[N][N]; 

string printLCS(string X, int m, int n){
	string s ="";
	
	while(0<m and 0<n){
		if(dp[m][n] == dp[m][n-1]) n--; // daaner tar soman hole
		else if(dp[m][n] == dp[m-1][n]) m--; // uporer tar soman hole
		else {
			s += X[m-1]; // or i can add s[n-1], mane eikhane char 2 ta milche. eikhane diagonal er sathe 1 add hoiche. ar ekhn e else ken? karon ei table e value kokhonoi kome na. same thake or bare.
			m--, n--;
		}
	}
	
	reverse(s.begin(), s.end()); // hisab ta kora hoy last theke, tai reverse kora
	
	return s;
}

// Returns length of LCS for X[0..m-1], Y[0..n-1]; building the table, also LCS size can be found from this table
void LCStable(string X, string Y, int m, int n) 
{ 
	// Build L[m+1][n+1] in bottom up fashion 
	for (int i = 0; i <= m; i++) 
	{ 
		for (int j = 0; j <= n; j++) 
		{ 
			if (i == 0 || j == 0) // i/j 0 hole 0-1 index bole to kichu nai. tai 0 hobe.
				dp[i][j] = 0; 
			else if (X[i - 1] == Y[j - 1]) // char mile gele diagonal er sathe 1 + hobe
				dp[i][j] = dp[i - 1][j - 1] + 1; 
			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); // na mille daner ba uporer tar moddhe max ta
		} 
	} 
	//return dp[m][n]; // number of the last row and last column ekdom nicer daner value ta. the max value in the table!
} 

/* Driver program to test above function */
int main() 
{ 
    string X, Y;
	cin>>X>>Y;
	int m = X.length(); 
	int n = Y.length(); 
	
	LCStable(X, Y, m, n);
	cout<<printLCS(X, m, n)<<endl;
	
	return 0; 
}


Measured memory_bytes: 35456
import sys

input = sys.stdin.readline

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


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

for len in range(1, N + 1):
	for i in range(N+1-len):
		j = i + len
		if ((N-len) % 2 == 0):
			dp[i][j] = max(dp[i+1][j] + lst_a[i], dp[i][j-1] + lst_a[j-1])
		else :
			dp[i][j] = min(-lst_a[i] + dp[i + 1][j], -lst_a[j - 1]+dp[i][j - 1])


print(dp[0][N])

Measured memory_bytes: 120348