akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//#define int long long
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> vec;
    vec.push_back(0);
    for(int i=1;i<n;i++){
        if((s[i]=='1' && s[i-1]=='0') || (s[i]=='0' && s[i-1]=='1')) vec.push_back(i);
    }
    int ans=0;
    rep(i,vec.size()){
        if(s[vec[i]]=='0'){
            if(i+2*k<vec.size()) ans=max(ans,vec[i+2*k]-vec[i]);
            else ans=max(ans,n-vec[i]);
        }
        else{
            if(i+2*k+1<vec.size()) ans=max(ans,vec[i+2*k+1]-vec[i]);
            else ans=max(ans,n-vec[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1020
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
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;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string & S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
void add(long long& a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}

void solv() {
	int p, q, r;
	cin >> p >> q >> r;

	cout << min(p + q, min(p + r, q + r)) << endl;

}

int main() {
//	COMinit();
	solv();

	return 0;
}


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

main(){
  int i,n,m,j;
  long long ans;
  while(1){
    vector<int> v;
    cin >> m;
    if(m == 0) break;

    for(i=0;i<m;i++){
      cin >> n;
      v.push_back(n);
    }

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

    ans = j = 0;
    for(i=v.size()-1;i>0;i--){
      ans += (long long)v[j] * i;
      j++;
    }
    
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<queue>
#include<cmath>
using namespace std;
#define ll long long
const ll len=1e3+5;
int main()
{
	ll a,b,c;
	ll sum;
	while(cin>>a>>b>>c)
	{
		sum=0;
		ll maxm=a;
		maxm=max(maxm,b);
		maxm=max(maxm,c);
		sum+=(maxm-a);
		sum+=(maxm-b);
		sum+=(maxm-c);
		cout<<(sum%2==0?sum/2:(sum)/2+2)<<endl;
	}
} 

Measured memory_bytes: 256
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {
	
	public static long create(long ao, long ai, long aj, long al){
		return ao + (ai / 2 * 2) + (aj / 2 * 2) + (al / 2 * 2);
	}
	
	public static void main(String[] args) throws IOException {
		final Scanner sc = new Scanner(System.in);
		
		final long ai = sc.nextLong();
		final long ao = sc.nextLong();
		final long at = sc.nextLong();
		final long aj = sc.nextLong();
		final long al = sc.nextLong();
		final long as = sc.nextLong();
		final long az = sc.nextLong();
		
		long answer = create(ao, ai, aj, al);
		//*
		final long min = Math.min(ai, Math.min(aj, al));
		for(long x = min; x >= Math.max(0, min - 5); x--){
			answer = Math.max(answer, create(ao, ai - x, aj - x, al - x) + 3 * x);
		}
		//*/
		System.out.println(answer);
	}
	
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 8276
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using G = vector<vector<int>>;
    
int main(){
    ll n, d;
    cin >> n >> d;
    d = d * d;
    ll x, y;
    int ans = 0;
    rep(i,n){
        ll dis;
        cin >> x >> y;
        dis = x * x + y * y;
        if(dis<=d) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int k , a, b;
    cin>>k>>a>>b;
    for(int i = a; i <= b; i++){
        if(i%k == 0){
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+6;
const int mod=1e9+7;
typedef long long ll;
ll dp[maxn];
void init(ll x)
{
	dp[1]=1;
	dp[2]=2;
	if(x>=3)
	{
		for(int i=3;i<=x;i++)
		{
			dp[i]=(dp[i-1]+dp[i-2])%mod;
		}
	}
}
int main()
{
	ll n,m;
	ll a[maxn];
	scanf("%lld%lld",&n,&m);
	memset(a,0,sizeof(a));
	init(n);
	for(int i=1;i<=m;i++)
	{
		scanf("%lld",&a[i]); 
	}
	sort(a+1,a+m+1);
	ll ans;
	ans=1;
	int flag=0;
	if(a[m]==n)
	{
		flag=1;
	}
	if(m==0)
	{
		printf("%lld\n",dp[n]);
		return 0;
	}
	for(int j=1;j<=m;j++)
	{
		if(j==1)
		{
			if(a[j]==1)
			{
				ans=1;
			}
			else
			{
				ans=ans*dp[a[j]-1]%mod;
			}
		}
		else
		{
			if(a[j]-a[j-1]==1)
			{
				ans=0;
			}
			else if(a[j]-a[j-1]==2)
			{
				ans=ans%mod;
			}
			else
			{
				ans=ans*dp[a[j]-a[j-1]-2]%mod;
			}
		}
	}
	if(flag==1)
	{
		printf("0\n");
	}
	else
	{
		if(n-a[m]==1)
		{
			printf("%lld\n",ans);
		}
		else
		{	
			printf("%lld\n",ans*dp[(n-a[m]-1)]%mod);
		} 
	}
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>

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

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define rep(i,j,k) for(int i=j; i<k; ++i)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
	fast_io 
	int a,b;cin>>a>>b;
	cout<<(6-a-b);
	return 0;
}

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

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

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

	vector<int> a(n);

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

	bool ans = 1;

	for (int i = 0; i < n; ++i) {
		if (a[i] % 2 == 0) {
			if (a[i] % 3 == 0 || a[i] % 5 == 0) {
				1;
			}
			else {
				ans = 0;
			}
		}
	}


	if (ans) {
		cout << "APPROVED" << endl;
	}
	else {
		cout << "DENIED" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=52;

vector<int>ea[maxn],eb[maxn];

int n;

inline void init()
{
	n=read();
	REP(i,1,n)ea[i].clear(),eb[i].clear();
	REP(i,1,n-1)
	{
		int u=read(),v=read();
		ea[u].push_back(v);
		ea[v].push_back(u);
	}
	REP(i,1,n-1)
	{
		int u=read(),v=read();
		eb[u].push_back(v);
		eb[v].push_back(u);
	}
}

int ans;
int fa[maxn],goal[maxn],rq[maxn];
int fake,RQ;

void dfsa(int u,int ff)
{
	for(int v:ea[u])
	{
		if(v==ff)continue;
		dfsa(v,u);
		fa[v]=u;
	}
}

void dfsb(int u,int ff)
{
	for(int v:eb[u])
	{
		if(v==ff)continue;
		goal[v]=u;
		if(goal[v]==fa[v])
		{
			if(rq[u])rq[v]=1,RQ++;
		}
		dfsb(v,u);
	}
}

inline void work(int rt)
{
	memset(fa,0,sizeof(int)*(n+1));
	memset(goal,0,sizeof(int)*(n+1));
	memset(rq,0,sizeof(int)*(n+1)); rq[rt]=1; RQ=1;
	dfsa(rt,0);
	dfsb(rt,0);
	static int rd[maxn];
	static vector<int>ed[maxn];
	
	int sum=0;
	queue<int>q;
	REP(i,1,n)rd[i]=0,ed[i].clear();
	REP(i,1,n)if(!rq[i] && !rq[fa[i]])ed[i].push_back(fa[i]),rd[fa[i]]++;
	REP(i,1,n)if(!rq[i] && !rq[goal[i]])ed[goal[i]].push_back(i),rd[i]++;
	REP(i,1,n)if(!rq[i] && !rd[i])q.push(i);
	
	while(!q.empty())
	{
		int u=q.front();q.pop();sum++;
		for(int v:ed[u])if(!(--rd[v]))q.push(v);
	}
	if(sum==n-RQ)chkmin(ans,n-RQ);
}

inline void work1(int rt,int cg)
{
	memset(fa,0,sizeof(int)*(n+1));
	memset(goal,0,sizeof(int)*(n+1));
	memset(rq,0,sizeof(int)*(n+1)); rq[rt]=1; RQ=1;
	dfsa(rt,0);
	dfsb(rt,0);
	static int rd[maxn];
	static vector<int>ed[maxn];
	int sum=0;
	queue<int>q;
	REP(i,1,n)rd[i]=0,ed[i].clear();
	REP(i,1,n)if(!rq[i] && !rq[fa[i]])ed[i].push_back(fa[i]),rd[fa[i]]++;
	REP(i,1,n)if(!rq[i] && !rq[goal[i]])ed[goal[i]].push_back(i),rd[i]++;
	REP(i,1,n)if(!rq[i] && !rd[i])q.push(i);
	while(!q.empty())
	{
		int u=q.front();q.pop();sum++;
		for(int v:ed[u])if(!(--rd[v]))q.push(v);
	}
	if(sum==n-RQ)chkmin(ans,n-RQ+1);
}

inline void doing()
{
	ans=n+1;
	REP(i,1,n)work(i);

	REP(i,1,n)if(SZ(ea[i])==1)
		REP(j,1,n)if(j!=ea[i].front())
		{
			int rem=ea[i].front();
			ea[i][0]=j;
			ea[rem].erase(find(ea[rem].begin(),ea[rem].end(),i));
			ea[j].push_back(i);
			work1(i,j);
			ea[j].pop_back();
			ea[rem].push_back(i);
			ea[i][0]=rem;
		}
	if(ans==n+1)puts("-1");
	else printf("%d\n",ans);
}

int main()
{
	int t=read();
	while(t--)
	{
		init();
		doing();
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define pi 3.14159265

int main()
{
	long long ans = 0, i = 0, j = 0, k = 0, N, K;
	cin >> N >> K;

	long a = N / K;
	long b = (N + K / 2) / K;
	ans = a*a*a;
	if (K % 2==0) ans += b*b*b;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;

const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

int main(){
    int n, l; cin >> n >> l;
    string s[n];
    REP(i, n) cin >> s[i];
    sort(s, s+n);
    REP(i, n) cout << s[i];
    cout << endl;
}

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

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
// clang-format on
/* }}} */

signed main() 
{
    int n,a,b;
    cin >> n >> a >> b;
    if(n*a<=b) cout << n*a << endl;
    else cout << b << endl;
    
    return 0;
}

Measured memory_bytes: 256
// 0bd35dc5e428754fa574049b6be8efe0

#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = (int) 1e5;

int n;

int a[MAXN + 5];

inline void input()
{
	n = read<int>();
	for(int i = 1; i <= n; ++i) a[i] = read<int>();
}

inline void solve()
{
	sort(a + 1, a + n + 1, greater<int>());

	int l = 1, r = n;
	while(l < r)
	{
		int mid = (l + r + 1) / 2;
		if(a[mid] - mid >= 0) l = mid;
		else r = mid - 1;
	}

	int fg = ((a[l] - l) & 1) | ((upper_bound(a + l, a + n + 1, l, greater<int>()) - (a + l) - 1) & 1);
	puts(fg ? "First" : "Second");
}

int main()
{
#ifndef ONLINE_JUDGE
//	freopen("E.in", "r", stdin);
//	freopen("E.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;

#define MOD 1e9+7
#define INF 1e9+7
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;

#define MAX_N 10000
#define MAX_V 100
#define MAX_E 100

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

//--------------------------

ll N, M, maxn = -(1LL << 60);
ll x[MAX_N], y[MAX_N], z[MAX_N];

int main() {

  cin >> N >> M;
  rep(i, N) cin >> x[i] >> y[i] >> z[i];

  rep(mask, 8) {
    vector<ll> vec;
    rep(i, N) {
      ll S = 0;
      S += (mask&1)? x[i] : -x[i];
      S += (mask&2)? y[i] : -y[i];
      S += (mask&4)? z[i] : -z[i];
      vec.push_back(S);
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    ll ans = 0;
    rep(j, M) ans += vec[j];
    maxn = max(maxn, ans);
  }

  cout << maxn << endl;

  return 0;
}


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
//const int mod = 998244353
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	mint ans = 1;
	vector<int>memo = { 0,0,0 };
	for (int i = 0; i < N; ++i) {
		mint count = 0;
		bool b = false;
		for (int j = 0;j<3;++j) {
			if (memo[j] == A[i]) {
				count = count +1;
				if (!b) {
					b = true;
					memo[j]++;
				}
			}
		}
		ans *= count;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;
const int64_t ZER=0LL;

int main() {
  int64_t N,K,ans=-1*INF; cin>>N>>K;
  vector<int64_t> P(N);
  rep(i,N) cin>>P.at(i);
  rep(i,N) P.at(i)--;
  vector<int64_t> C(N);
  rep(i,N) cin>>C.at(i);
  
  rep(i,N){
    vector<bool> seen(N,true);
    vector<int64_t> S,T;
    int64_t k=i,sum=0;
    while(seen.at(k)){
      seen.at(k)=false;
      S.push_back(C.at(k));
      sum+=C.at(k);
      k=P.at(k);
    }
    int64_t t=S.size(),r=K/t,q=K%t,MAX=-1*INF,NMAX,MAX2=-1*INF;
    rep(i,t){
      T.push_back(S.at(i));
      if(i>0) T.at(i)+=T.at(i-1);
      if(T.at(i)>MAX){
        MAX=T.at(i);
        NMAX=i+1;
      }
    }
      if(q<NMAX){
        rep(i,q) MAX2=max(MAX2,T.at(i));
        if(sum<0) ans=max(ans,MAX);
        else{
          auto temp=max(MAX+sum*(r-1),MAX2+sum*r);
          ans=max(ans,temp);
        }
      }
      else{
        if(sum<0) ans=max(ans,MAX);
        else ans=max(ans,MAX+sum*r);
      }
  }
  cout<<ans;
}


Measured memory_bytes: 3736
#include<stdio.h>

void binary();

int num;
int set[100000000];
int count = 0;

int main(){
  int i;
  int j;
  int Qdata;
  int Time[500000];

  scanf("%d",&num);

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

  scanf("%d",&Qdata);

  for(i = 0;i < Qdata;i++){
    scanf("%d",&Time[i]);
    binary(Time[i]);
  }

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

void binary(int data){
  int left = 0;
  int right = num;

  while(left < right){
    int mid = (left + right) / 2;

    if(data == set[mid]){
      count++;
      break;
    }

    else if(data < set[mid]){
      right = mid;
    }

    else{
      left = ++mid;
    }
  }
}



Measured memory_bytes: 2320
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

struct SegmentTree {
    int n;
    vector<int> dat;
    SegmentTree(int _n) {
        n = 1;
        while(n < _n)
            n *= 2;
        dat.resize(2 * n - 1);
        for(int i = 0; i < 2 * n - 1; i++)
            dat[i] = -1;
    }

    SegmentTree(vector<int> v) {
        int sz = v.size();
        n = 1;
        while(n < sz)
            n *= 2;
        dat.resize(2 * n - 1);
        for(int i = 0; i < sz; i++)
            dat[i + n - 1] = v[i];
        for(int i = n - 2; i >= 0; i--) {
            dat[i] = max(dat[2 * i + 1], dat[2 * i + 2]);
        }
    }

    void update(int k, int a) {
        k += n - 1;
        dat[k] = a;
        while(k > 0) {
            k = (k - 1) / 2;
            dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    int _query(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l)
            return -1; //交差しない
        if(a <= l && r <= b)
            return dat[k]; //完全に含んでいる
        else {
            int vl = _query(a, b, k * 2 + 1, l, (l + r) / 2);
            int vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);
            return max(vl, vr);
        }
    }
    int query(int i, int j) { return _query(i, j, 0, 0, n); }
};

int main() {
    int N, Q;
    string S;
    cin >> N >> S >> Q;

    vector<SegmentTree> segtree(26, SegmentTree(N));
    rep(i, N) { segtree[S[i] - 'a'].update(i, 1); }

    rep(i, Q) {
        int q;
        cin >> q;
        if(q == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            int num = c - 'a';
            int before = S[i] - 'a';
            S[i] = c;
            segtree[before].update(i, 0);
            segtree[num].update(i, 1);
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            int cnt = 0;
            rep(i, 26) {
                if(segtree[i].query(l, r) == 1)
                    cnt++;
            }
            cout << cnt << "\n";
        }
    }
    return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */

struct union_find{
    vector<int> par;
    vector<int> rank;
    vector<int> size;
    union_find(int n) : par(n), rank(n), size(n){
        for(int i = 0; i < n; i++){
            par[i] = i; rank[i] = 0; size[i] = 1;
        }
    }
    int root (int x){
        if(par[x] == x) return x;
        par[x] = root(par[x]);
        return par[x];
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (rank[rx] < rank[ry]){
            par[rx] = ry;
            size[ry] += size[rx]; 
        }
        else{
            par[ry] = rx;
            size[rx] += size[ry];
            if (rank[rx] == rank[ry]) rank[rx]++;
        }
    }
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int fl[MAX];
vector<int> bl[MAX];

int main(){
    int n; cin >> n; union_find uf(n);
    int m, k; cin >> m >> k;
    rep(i, m){
        int a, b; cin >> a >> b; a--; b--;
        uf.unite(a, b);
        fl[a]++; fl[b]++;
    }
    rep(i, k){
        int c, d; cin >> c >> d; c--; d--;
        bl[c].push_back(d);
        bl[d].push_back(c);
    }

    rep(i, n){
        int ans = uf.size[uf.root(i)] - fl[i] - 1;
        for(int j : bl[i]){
            if(uf.same(i, j)) ans--;
        }
        outs(ans);
    }
    out("");
}


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

const int MOD = 1e9 + 7;
const int N = 3000;

int a[N];

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	long long cnt1 = 0, cnt2 = 0;
	for (int i = 1; i < n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (a[i] > a[j]) cnt1++;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (a[i] > a[j]) cnt2++;
		}
	}
	cnt1 %= MOD; cnt2 %= MOD;
	printf("%lld\n", (k * cnt1 % MOD + cnt2 * (k - 1) % MOD * k % MOD * 500000004 % MOD) % MOD);
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <set>
#include <map>
#include <stdlib.h>
#include <cctype>
#include <bitset>
using namespace std;
int main()
{
    int N,i,j,A,p;
    cin >> N;
    int a[N];
    for(i = 0;i < N;i++) cin >> a[i];
    A = 40000000;
    for(i = -101;i <= 101;i++){
        p = 0;
        for(j = 0;j < N;j++){
            p += pow((a[j] - i),2);
        }
        if(p < A) A = p;
    }
    cout << A << endl;
}

Measured memory_bytes: 3620
/* 十 聖イシドールスよ、迷えるプログラマを導き給え！ 十 */
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <deque>

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

//const long long INF = 1LL << 60;
const int INF = 1e9;
using ll = long long;

struct UnionFind {
    // 配列 value = 親の番号
    std::vector<int> d;        
    // コンストラクタ サイズを初期化する
    UnionFind(int n=0): d(n,-1) {}
    // find インデックスxの要素の根っこ(=所属グループ)をみつける
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    // Unite 貰った2要素を追加してくっつけていく 
    bool unite(int x, int y) {
        x = find(x); y = find(y);       // 両方の根っこを扱う 
        if (x == y) return false;       // おんなじのはつながらない(同じ要素じゃん) 
        if (d[x] > d[y]) std::swap(x,y);// 小さい方につなげる
        d[x] += d[y];                   // 連結のサイズを合算する 
        d[y] = x;                       // yの親をxの親に更新する 
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

int main()
{
	// 経路探索の問題にする 
	// 一番人数の多い仲良しグループ人数分の新グループがあればよい 
	int N, M;
	std::cin >> N >> M;

    UnionFind uf(N);

    rep(i, M)
    {
        int a, b;
        std::cin >> a >> b;
        a--; b--;
        uf.unite(a, b); // 友達の情報なので必ずつながる  
    }

    int ans = 0;
    rep(i, N)
    {
        ans = std::max(ans, uf.size(i));
    }

    std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 4032
s=input()
t=input()
m=10000
ct=0
for i in range(len(s)-len(t)+1):
	for j in range(len(t)):
		if s[i:i+len(t)][j]!=t[j]:
			ct+=1
	m=min(ct,m)
	ct=0
print(m)


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

struct point{
  int i,j,k,l;
};

int main(){
  int h,w;
  cin >> h >> w;
  int m[h][w];
  vector<point> ret;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> m[i][j];
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w-1;j++){
      if(m[i][j]%2==1){
        m[i][j]--;
        m[i][j+1]++;
        ret.push_back({i+1,j+1,i+1,j+2});
      }
    }
  }
  for(int i=0;i<h-1;i++){
    if(m[i][w-1]%2==1){
      m[i+1][w-1]++;
      ret.push_back({i+1,w,i+2,w});
    }
  }
  cout << (int)ret.size() << endl;
  for(auto &x:ret){
    printf("%d %d %d %d\n",x.i,x.j,x.k,x.l);
  }
}


Measured memory_bytes: 5104
#include <iostream>
#include <vector>
#include <algorithm>


int main(){
	std::vector<int> vegetable; //dataset
	int n; //number of purchase
	int m; //capacity of bag

	while(std::cin >> n >> m){ //input dataset
		if(n == 0 && m == 0) //end of input
			break;

		std::vector<int> price; //price of vegetable
		for(int i = 0; i < n; ++i){ //input price
			int data;
			std::cin >> data;
			price.push_back(data);
		}

		
		std::sort(price.begin(), price.end(), std::greater<int>()); //sort price in descending order


		for(int i = 0; i < n; ++i){
			vegetable.push_back(price[i]);
		}

		int ans = 0; //minimum cost
		int count = 1; //counter
		while(!vegetable.empty()){
			if(count % m == 0){
				vegetable.erase(vegetable.begin());
				++count;
			} else if(count % m != 0){
				ans += (int)vegetable.front();
				vegetable.erase(vegetable.begin());
				++count;
			}
		}
		std::cout << ans << std::endl; //output answer
		
	}


	return 0;
}

Measured memory_bytes: 3148
#include<iostream>
using namespace std;
int main()
{
int n;
int ans=0;
cin>>n;
if(n==2)
{
	cout<<4;
	return 0;
}
if(n==1)
{
	cout<<4;
	return 0;
}
while(1)
{
	ans++;
if(n==4)
break;
if(n%2==1)
{
	n=n*3+1;
}
else
n/=2;

}
cout<<ans+3;
}

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

const int N=1010;
const int mod=1000000007;
typedef long long ll;
int ksm(ll a,int b,int c=1){
	for(;b;b/=2,a=a*a%mod)
		if(b&1)c=c*a%mod;
	return c;
}
ll K;
int n,m,a[N][N],cnt,cmt;
char s[N];
struct node{
	int x,y,z;
	node(int x=1,int y=0,int z=1):x(x),y(y),z(z){}
	node operator * (const node&a)const{return node((ll)x*a.x%mod,((ll)x*a.y+(ll)y*a.z)%mod,(ll)z*a.z%mod);}
}M,ans;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>K;
	if(!K){
		cout<<1<<'\n';
		return 0;
	}
	for(int i=1;i<=n;++i){
		cin>>s;
		for(int j=1;j<=m;++j)
			if(s[j-1]=='#')a[i][j]=1,++cnt;
	}
	int flag1=0,flag2=0;
	for(int i=1;i<=n;++i)if(a[i][1]&&a[i][m])++flag1;
	for(int i=1;i<=m;++i)if(a[1][i]&&a[n][i])++flag2;
	if(flag1&&flag2){
		cout<<1<<'\n';
		return 0;
	}
	if(!flag1&&!flag2){
		cout<<ksm(cnt,(K-1)%(mod-1))<<'\n';
		return 0;
	}
	if(flag2){
		int u=max(n,m);
		for(int i=1;i<=u;++i)
			for(int j=1;j<i;++j)swap(a[i][j],a[j][i]);
		swap(n,m);swap(flag1,flag2);
	}
	for(int i=1;i<=n;++i)
		for(int j=1;j<m;++j)
			if(a[i][j]&&a[i][j+1])++cmt;
	M.x=cnt;M.y=cmt;M.z=flag1;
	for(--K;K;K/=2,M=M*M)
		if(K&1)ans=ans*M;
	cout<<(ans.x-ans.y+mod)%mod<<'\n';
	return 0;
}


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

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 3588
n = int(input())
b = list(map(int, input().split()))


def solve(b, a):
  #print(f'solve called with, b = {b}, a = {a}')
  if len(b) == 0:
    return a

  ## check if legal
  for bb, ii in zip(b, range(1, len(b)+1)):
    if bb > ii:
      return None

  for bb, ii in zip(b, range(1, len(b)+1)):
    if bb == ii:
      #print(f'found {bb} in {b}[{ii-1}]')
      a_cp = a[:]
      a_cp.append(bb)
      b_cp = b[:]
      b_cp.pop(ii-1)
      ans = solve(b_cp, a_cp)
      if ans is not None:
        return ans

answer = solve(b, [])
if answer == None:
  print(-1)
else:
  for aa in reversed(answer):
    print(aa)



Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}


int main(){
	int h,w,d;
	cin>>h>>w>>d;
	vector<vector<int>> b(h*w);
	rep(i,h){
		rep(j,w){
			int x;
			cin>>x;
			b[x-1].resize(2);
			b[x-1][0]=i;
			b[x-1][1]=j;
		}
	}
	int q;
	cin>>q;
	vector<int> l(q),r(q);
	rep(i,q){
		cin>>l[i]>>r[i];
	}
	vector<int> c(h*w+1);
	FOR(i,1,h*w+1){
		if(i<=d){
			c[i]=0;
		}else{
			c[i]=c[i-d]+abs( b[i-1][0]-b[i-d-1][0])+abs( b[i-1][1]-b[i-d-1][1]);
		}
	}
	rep(i,q){
		cout<<c[r[i]]-c[l[i]]<<endl;
	}
}





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

#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define mod 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN

ll n,w;

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

ll knapsack(ll a[],ll b[],ll dp[][101],ll i,ll wt){
     if(i==n or wt==0)return 0;
     if(dp[wt][i]!=-1)return dp[wt][i];
    
     if(b[i]>wt)return dp[wt][i]=knapsack(a,b,dp,i+1,wt);
       return dp[wt][i]=max(knapsack(a,b,dp,i+1,wt),a[i]+knapsack(a,b,dp,i+1,wt-b[i]));

     

}

int32_t main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    
    cin>>n>>w;
    ll a[n],b[n];
    for(int i=0;i<n;i++)cin>>b[i]>>a[i];
    ll dp[w+1][101];
     memset(dp,-1,sizeof dp);
    cout<<knapsack(a,b,dp,0,w);


    return 0; 
 }
    

Measured memory_bytes: 82500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);

int main(){
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int time = (h2-h1) * 60 + (m2-m1);
    //cout << time << endl;
    cout << time - k << endl;
}

Measured memory_bytes: 3596
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)

	p, q, r := oneInt(), oneInt(), oneInt()

	fmt.Println(min(p+q, q+r, r+p))
}

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

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

func scanNums(len int) (nums []int) {
	for i := 0; i < len; i++ {
		nums = append(nums, oneInt())
	}
	return nums
}

func scanStrings(len int) (strs []string) {
	for i := 0; i < len; i++ {
		strs = append(strs, oneStr())
	}
	return strs
}

func abs(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}

func cumSum(nums []int) []int {
	sums := []int{0}

	for i := 0; i < len(nums); i++ {
		sums = append(sums, sums[i]+nums[i])
	}
	return sums
}


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

int main(){
    int n;
    cin>>n;
    
    int max = 0;
    long long temp,sum=0;
    
    for(int i=0;i<n;i++){
        cin>>temp;
        if(temp>max){
            max = temp;
        }
        else{
            sum += max-temp;
        }
    }
    cout<<sum<<endl;
}

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

int main()
{
  int n;
  cin >> n;
  n %= 10;
  if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9) cout << "hon" << endl;
  else if(n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
  else cout << "bon" << endl;
}


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

#define int long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define ss second
#define ff first

#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

const int inf = 2e18;
const int ninf = -2e18;

map<int, int> m;

bool pf(int n) {
	if (n == 1) return 1;
	for (int i = 2; i < sqrt(n) + 1; i++) {
		if (n % i == 0 && m[i] > 0) return 0;
		while (n % i == 0) {
			n /= i;
			m[i]++;
		}
		if (n == 1) break;
	}
	if (n > 1) {
		if (m[n] > 0) return 0;
		m[n]++;
	}
	
	return 1;
}

signed main() {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
		freopen("error.txt", "w", stderr);
	#endif

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

	int g = 0;
	for (int i = 0; i < n; i++) g = __gcd(g, v[i]);

	if (g > 1) cout << "not coprime" << endl;
	else {
		for (int i = 0; i < n; i++) {
			if (!pf(v[i])) {
				cout << "setwise coprime" << endl;
				return 0;
			}
		}
		cout << "pairwise coprime" << endl;
	}

	return 0;
}

Measured memory_bytes: 11080
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int ma, md, ms;

	public static void main(String[] args) {
		System.out.println(solve());
	}

	static int solve() {
		int N = Integer.parseInt(sc.next());
		int mh = Integer.parseInt(sc.next());
		ma = Integer.parseInt(sc.next());
		md = Integer.parseInt(sc.next());
		ms = Integer.parseInt(sc.next());
		long cmh = mh;
		ArrayList<Enemy> es = new ArrayList<Enemy>();
		long sum = 0;
		for (int i = 0; i < N; ++i) {
			int h = Integer.parseInt(sc.next());
			int a = Integer.parseInt(sc.next());
			int d = Integer.parseInt(sc.next());
			int s = Integer.parseInt(sc.next());
			int receive = a - md;
			if (receive <= 0) continue;
			int attack = ma - d;
			if (attack <= 0) return -1;
			sum += receive;
			Enemy e = new Enemy(h, a, d, s);
			es.add(e);
			e.turn = (h + attack - 1) / attack;
			e.dm = receive;
		}
		Collections.sort(es);
		for (int i = 0; i < es.size(); ++i) {
			sum -= es.get(i).a - md;
			cmh -= sum * es.get(i).turn;
			cmh -= es.get(i).dm * (es.get(i).s > ms ? es.get(i).turn : es.get(i).turn - 1);
			if (cmh <= 0) return -1;
		}
		return (int) (mh - cmh);
	}

	static class Enemy implements Comparable<Enemy> {
		int h, a, d, s;
		long turn;
		int dm;

		public Enemy(int h, int a, int d, int s) {
			this.h = h;
			this.a = a;
			this.d = d;
			this.s = s;
		}

		public int compareTo(Enemy o) {
			long totalTurn = this.turn + o.turn;
			long d1 = (this.a - md) * (this.s > ms ? this.turn : this.turn - 1); // this -> o
			d1 += (o.a - md) * (o.s > ms ? totalTurn : totalTurn - 1);
			long d2 = (o.a - md) * (o.s > ms ? o.turn : o.turn - 1); // o -> this
			d2 += (this.a - md) * (this.s > ms ? totalTurn : totalTurn - 1);
			if (d1 != d2) return d1 < d2 ? -1 : 1;
			return 0;
		}
	}
}

Measured memory_bytes: 73900
#include <iostream>
#include <unordered_map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main() {
  int n,count=0;
  cin >> n;
  
  for (int i = 1; i <= n; i++) {
    if ((to_string(i).size())%2==1) {
      count++;
    }
  }

  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 256
def read():
    return int(input())


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


def readmap():
    return map(int, input().split())


N, P = readmap()
A = readlist()

for i in range(N):
    A[i] = A[i] % 2

cnt_0 = A.count(0)
cnt_1 = A.count(1)


def fact(n):
    if n == 0:
        return 1
    elif n > 0:
        return n*fact(n-1)


def nCr(n,r):
    return fact(n)/(fact(r)*fact(n-r))


if P == 0:
    ans = 2 ** cnt_0
    num = 0
    for i in range(cnt_1 // 2 + 1):
        num += nCr(cnt_1, 2*i)
    ans *= num
    print(int(ans))
else:
    ans = 2 ** cnt_0
    num = 0
    for i in range((cnt_1 - 1) // 2 + 1):
        num += nCr(cnt_1, 2 * i + 1)
    ans *= num
    print(int(ans))


Measured memory_bytes: 3064
L,R = map(int,input().split())
mn = 10**10
cal = 0
for i in range(L,R+1):
    for j in range(i+1,R+1):
        
        cal = ((i%2019)*(j%2019))%2019
        if cal < mn:
            mn = cal
        if cal == 0:
            break
    else:
        continue
    break
print(mn)
        

Measured memory_bytes: 9180
#include<stdio.h>

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

int main() {
	long long i, j, a, b, n, c, g;
	bool flag;
	while(scanf("%d",&n)!=EOF) {
		flag = 1;
		for(i = 1; i < 3501; i++) {
			if(flag)
			for(j = i; j < 3501; j++) {
				g = i*j / gcd(i,j);
				g = g*n / gcd(g,n);
				a = (4*g)/n - g/i - g/j;
				if(a>0&&g % a == 0) {
					if(g/a<0) continue;
					printf("%d %d %d\n", i, j, g/a);
					flag = 0;
					break;
				}
			}
		}
	}
}

//(4*g)/n-g/a-g/b = g/c;


Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

#define INF -1

double dRetMinkowski(int* aiVecX, int* aiVecY, int iVecSize, int iValueP);

// 要素数Nの二つのベクトルが与えられ、ミンコフスキー距離(p=1,2,3,∞)をそれぞれ出力
int main()
{
	int iInputN;
	double dLength;
	int* iInputVecX, * iInputVecY;
	int iCnt;

	scanf("%d", &iInputN);

	// メモリ確保
	iInputVecX = (int*)malloc(sizeof(int) * iInputN);
	iInputVecY = (int*)malloc(sizeof(int) * iInputN);


	// Xベクトル
	for (iCnt = 0; iCnt < iInputN; iCnt++)
	{
		scanf("%d", iInputVecX + iCnt);
	}
	// Yベクトル
	for (iCnt = 0; iCnt < iInputN; iCnt++)
	{
		scanf("%d", iInputVecY + iCnt);
	}

	// 距離計算
	dLength = dRetMinkowski(iInputVecX, iInputVecY, iInputN, 1);
	printf("%.6lf\n", dLength);
	dLength = dRetMinkowski(iInputVecX, iInputVecY, iInputN, 2);
	printf("%.6lf\n", dLength);
	dLength = dRetMinkowski(iInputVecX, iInputVecY, iInputN, 3);
	printf("%.6lf\n", dLength);
	dLength = dRetMinkowski(iInputVecX, iInputVecY, iInputN, INF);
	printf("%.6lf\n", dLength);

	free(iInputVecX);
	free(iInputVecY);

	return 0;
}

// 引数iValuePに基づいてミンコフスキー距離を計算
double dRetMinkowski(int* aiVecX, int *aiVecY, int iVecSize, int iValueP)
{
	int iCnt;
	double dRetLength = 0;
	double dAbs;

	// p=∞の時
	if (iValueP == INF)
	{
		for (iCnt = 0; iCnt < iVecSize; iCnt++)
		{
			dAbs = abs(*(aiVecX + iCnt) - *(aiVecY + iCnt));
			if (dRetLength < dAbs)
			{
				dRetLength = dAbs;
			}
		}
	}
	else
	{
		for (iCnt = 0; iCnt < iVecSize; iCnt++)
		{
			dAbs = abs(*(aiVecX + iCnt) - *(aiVecY + iCnt));
			dRetLength += pow(dAbs, iValueP);
		}
		dRetLength = pow(dRetLength, (double) 1 / iValueP);
	}
	

	return dRetLength;
}


Measured memory_bytes: 2036