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

#define M 200005
#define MOD 1000000007
#define PI 3.14159265358979323846
#define ep emplace_back
#define mk make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> PII;
typedef pair<lli,lli> PLL;

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

	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);

	int x,y;
	cin>>x>>y;

	if(y>4*x || y<2*x)
		cout<<"No\n";
	else 
	{
		if(y%2==1)
			cout<<"No\n";
		else
			cout<<"Yes\n";
	}

}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

const int N = 11111;
int ans[N];
int n;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int x = 1; x * x <= n; x++) {
        for(int y = 1; y * y <= n; y++) {
            for(int z = 1; z * z <= n; z++) {
                int cur = x * x + y * y + z * z + x * y + y * z + z * x;
                if(cur <= n) {
                    ans[cur]++;
                }
            }
        }
    }
    rep(i, 1, n) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3608
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
constexpr int MAXN = (1 << 20) + 5;
constexpr int MOD = 1e9 + 7;
constexpr double eps = 1e-6;
constexpr int INF = 1e9 + 7;
int dir[4][2] = { { -1,0 },{ 0,1 },{ 1,0 },{ 0,-1 } };

map <string, int> mp,mp2;
int main()
{
	//freopen("in.in", "r", stdin);&
	//freopen("out.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);

	int n, m;
	string s;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> s;
		mp[s]++;
	}
	cin >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> s;
		mp2[s]++;
	}

	int ans = 0;
	for (auto it = mp.begin(); it != mp.end(); it++)
		ans = max(it->second - mp2[it->first], ans);
		//string tmp = it->first;
		//cout<< "test" << tmp << it->second << endl;
	cout << ans << endl;
	system("pause");
	return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int WWW = 0;WWW < (n);WWW++)cerr << v[WWW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

set<string> s;
int dp[1 << 16];
int place;

int dfs2(string str){
	if(str[place] == '-'){
		place++;
		return 1 - dfs2(str);
	}
	else if(str[place] == '('){
		place++;
		int a = dfs2(str);
		char c = str[place];
		place++;
		int b = dfs2(str);
		place++;
		if(c == '^')return a ^ b;
		else return a & b;
	}
	else{
		return str[place++] - '0';
	}
}

int f(string str){
	place = 0;
	return dfs2(str);
}

int investigate(string str){
	int ret = 0;
	REP(i,(1<<4)){
		string now = "";
		REP(j,str.size()){
			if(str[j] >= 'a' && str[j] <= 'd'){
				now += (char)('0' + ((i & (1 << (str[j] - 'a')))>0));
			}
			else{
				now += str[j];
			}
		}
		ret |= (f(now) << i);
	}
	return dp[ret] = min(dp[ret],(int)str.size());
}


void check(string str){
	int cou = 0;
	REP(i,str.size()){
		if(str[i] == 'X')cou++;
	}
	int num = 1;
	REP(i,cou)num *= 6;
	REP(i,num){
		string now = "";
		int tmp = i;
		REP(j,str.size()){
			if(str[j] == 'X'){
				int seica = tmp % 6;
				if(seica < 4){
					now += (char)('a' + seica);
				}
				else{
					now += (char)('0' + (seica - 4));
				}
				tmp /= 6;
			}
			else{
				now += str[j];
			}
		}
		investigate(now);
	}
}

void dfs(string str){
	if(str.size() > 14 || s.count(str))return;
	s.insert(str);
	check(str);
	REP(i,str.size()){
		if(str[i] == 'X'){
			dfs(str.substr(0,max(0LL,i)) + "(X*X)" + str.substr(i+1));
			dfs(str.substr(0,max(0LL,i)) + "(X^X)" + str.substr(i+1));
			if(!(i > 0 && str[i-1] == '-'))dfs(str.substr(0,max(0LL,i)) + "-X" + str.substr(i+1));
		}
	}
}	
	

int main(){
	REP(i,1<<16)dp[i] = INF;
	dfs("X");
	string str;
	while(cin >> str,str[0] != '.'){
		cout << investigate(str) << endl;
	}
	return 0;
}



Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int x, y, z;
  cin >> x >> y >> z;

  swap(x, y);
  swap(x, z);

  cout << x << " " << y << " " << z << endl;
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

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

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int left = 0;
  int cnt = 0;
  int target = 0;
  ll ans[s.size()];
  int n = s.size();
  memset(ans,0,sizeof(ans));
  rep(i,n){
    if(i != n-1 && s[i] == 'R' && s[i+1] == 'L'){
      ans[i] = 1 + (left)/2;
      ans[i+1] = 1 + (left+1)/2;
      target = i+1;
      cnt = 0;
      left=0;
      i++;
    }else if(s[i] == 'R'){
      left++;
    }else if(s[i] == 'L'){
      if(cnt % 2 == 0) ans[target-1]++;
      else ans[target]++;
      cnt++;
    }
  }

  rep(i,n){
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}


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

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	char b;

	cin >> b;

	switch(b){
		case 'A': cout << 'T' << endl; break;
		case 'T': cout << 'A' << endl; break;
		case 'C': cout << 'G' << endl; break;
		case 'G': cout << 'C' << endl; break;
	}

	return 0;
}


Measured memory_bytes: 256
n = int(input())
W = list(map(int, input().split()))
sumw = sum(W)
x = 100 * 150
ct = 0
for i in range(n):
    xum = sumw - ct
    sa = abs(xum - ct)
    if sa > x:
        break
    ct += W[i]
    x = sa
print(x)

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

public class Main{
	static class Team implements Comparable<Team>{
		String name;
		int score;

		Team(String name) {
			this.name = name;
			this.score = 0;
		}

		public int compareTo(Team t) {
			return t.score - this.score;
		}
	}

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		Team t[];
		String enter = "";

		while (true) {
			n = sc.nextInt();
			if (n == 0) {
				break;
			}
			t = new Team[n];
			for (int i = 0; i < n; i++) {
				String name = sc.next();
				int win = sc.nextInt();
				int lose = sc.nextInt();
				int draw = sc.nextInt();
				t[i] = new Team(name);
				t[i].score = win * 3 + draw;
			}
			Arrays.sort(t);
			System.out.print(enter);
			for (int i = 0; i < n; i++) {
				System.out.println(t[i].name + "," + t[i].score);
			}
			enter = "\n";
		}
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<string>
using namespace std;
int nowtrain[864000];
int main(){
	int n;
	string a;
	int bef,aft;
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<86400;i++)
		nowtrain[i]=0;
	for(int i=0;i<n;i++){
		cin>>a;
		bef=3600*((a[0]-'0')*10+a[1]-'0');
		bef+=60*((a[3]-'0')*10+a[4]-'0');
		bef+=a[6]*10+a[7];
		cin>>a;
		aft=3600*((a[0]-'0')*10+a[1]-'0');
		aft+=60*((a[3]-'0')*10+a[4]-'0');
		aft+=a[6]*10+a[7];
		for(int j=bef;j<aft;j++)
			nowtrain[j]++;
	}
	int best=0;
	for(int i=0;i<86400;i++)
		best=max(best,nowtrain[i]);
	cout<<best<<endl;
	}
	return 0;
}

Measured memory_bytes: 1540
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll LNF = 1LL<<60;

constexpr int INF = 1e9+7;

const double PI=3.14159265358979323846;


vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<pair<ll,ll>> a(n);
    rep(i,0,n){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(all(a));
    int ans = 0;
    rep(i,0,n){
        int d = i%2;
        if(a[i].second%2!=d){
            ans++;
        }
    }
    cout << ans/2 << endl;
} 

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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    int num = 0;
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
        if(a == num+1)num++;
    }
    if(num == 0)cout << -1;
    else cout << n - num;
    cout << endl;

    return 0;
}

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

int main()
{
    int a,b,c,d,n,m;
    while(~scanf("%d",&a))
    {
        scanf("%d",&b);
        scanf("%d",&c);
        scanf("%d",&d);
        if(a<b)
        {
            n=a;
        }
        else
        {
            n=b;
        }
        if(c<d)
        {
            m=c;
        }
        else
        {
            m=d;
        }
        printf("%d\n",n+m);
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define w while
#define loop(i,l,r) for(int i=l;i<r;i++)
#define ci cin>>
#define co cout<<
#define mm 1000000007
#define ll long long
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

     int n;
     cin>>n;
  vector<double>dp(n+1,0);
  dp[0]=1;
  for(int i=0;i<n;i++){
        double ph;
        cin>>ph;
      for(int toss=i+1;toss>=0;toss--){
          dp[toss]= (toss==0?0:dp[toss-1]*ph ) + dp[toss]*(1-ph) ;
      }
    }
   double ans=0;
  for(int head=0;head<=n;head++){
    int tail=n-head;
    if(head>tail)
    ans+=dp[head];
   }
    cout<< fixed << setprecision(9)<<ans;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int i, j, k;
	int n, m, l;
	int A[100][100] = { 0 };
	int B[100][100] = { 0 };
	long int C[100][100] = { 0 };

	scanf("%d %d %d", &n, &m, &l);

	// input A
	for(i=0; i<n; i++) {
		for(j=0; j<m; j++) {
			scanf("%d", &A[i][j]);
		}
	}

	// input B
	for(i=0; i<m; i++) {
		for(j=0; j<l; j++) {
			scanf("%d", &B[i][j]);
		}
	}

	// output C
	for(i=0; i<n; i++) {
		for(j=0; j<l; j++) {
			for(k=0; k<m; k++) {
				C[i][j] += A[i][k]*B[k][j];
			}
			printf("%ld", C[i][j]);
			if(j==l-1) printf("\n");
			else printf(" ");
		}
	}

	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
#define mo 1000000007
#define maxn 5005
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
inline void Add(int &x,int y){x+=y;x-=(x>=mo?mo:0);}
inline int add(int x,int y){x+=y;return x>=mo?x-mo:x;}
inline int ksm(int x,int y)
{
    int a=1;
    while(y)
    {
        if(y&1)a=1ll*a*x%mo;
        x=1ll*x*x%mo;y>>=1;
    }return a;
}
int n;
vector<int>G[maxn];
int jc[maxn],inv[maxn];
int dp[maxn][maxn],tmp[maxn],size[maxn];
inline void dfs(int u,int f)
{
    dp[u][1]=1;size[u]=1;
    for(int v:G[u])if(v!=f)
    {
        dfs(v,u);
        memset(tmp,0,sizeof tmp);
        for(int i=1;i<=size[u];++i)
            for(int j=1;j<=size[v];++j)
            {
                Add(tmp[i+j],1ll*dp[u][i]*dp[v][j]%mo);
                if(!(j&1))Add(tmp[i],mo-1ll*dp[u][i]*jc[j]%mo*inv[j/2]%mo*dp[v][j]%mo);
            }
        memcpy(dp[u],tmp,sizeof tmp);size[u]+=size[v];
    }
}
int main()
{
    n=read();
    reg int i,u,v;
    jc[0]=inv[0]=inv[1]=1;
    for(i=1;i<=n;++i)jc[i]=1ll*jc[i-1]*i%mo;
    for(i=2;i<=n;++i)inv[i]=1ll*inv[mo%i]*(mo-mo/i)%mo;
    for(i=2;i<=n;++i)inv[i]=1ll*inv[i-1]*inv[i]%mo;
    for(i=1;i<n;++i)
    {
        u=read(),v=read();
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1,0);reg int ans=0;
    for(i=2;i<=n;i+=2)Add(ans,1ll*dp[1][i]*jc[i]%mo*inv[i/2]%mo);
    ans=1ll*ans*ksm(500000004,n/2)%mo;printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 98560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

constexpr int mod = 1000000007;
lint mod_pow(lint x, lint y) {
    if (!y) return 1;
    lint a = mod_pow(x, y >> 1);
    x %= mod;
    if (y & 1) return a * a % mod * x % mod;
    else return a * a % mod;
}
vector<lint> fac = {1}, ifac = {1};
lint fact(int N) {
    while (fac.size() <= N) {
        fac.push_back(fac.back() * (int)fac.size() % mod);
    }
    return fac[N];
}
lint ifact(int N) {
    while (ifac.size() <= N) {
        ifac.push_back(mod_pow(fact((int)ifac.size()), mod - 2));
    }
    return ifac[N];
}

vector<vector<int>> G;
vector<vector<pair<int, lint>>> DP;

pair<int, lint> dfs1(int v = 0, int par = -1) {
    int sz = 0;
    vector<int> S;
    lint res = 1;
    rep(i, G[v].size()) {
        if (G[v][i] == par) {
            DP[v].push_back(pair<int, lint>{-1, -1});
            continue;
        }
        auto d = dfs1(G[v][i], v);
        DP[v].push_back(d);
        sz += d.first;
        S.push_back(d.first);
        res = res * d.second % mod;
    }
    res = res * fact(sz) % mod;
    for (int s : S) res = res * ifact(s) % mod;
    ++sz;
    return {sz, res};
}

void dfs2(int v = 0, int par = -1, pair<int, lint> val = pair<int, lint>{-1, -1}) {
    rep(i, G[v].size()) {
        if (DP[v][i] == pair<int, lint>{-1, -1}) DP[v][i] = val;
    }
    int sz = 0;
    lint sum = 1, kaijo_sum = 1;
    rep(i, G[v].size()) {
        sz += DP[v][i].first;
        sum = sum * DP[v][i].second % mod;
        kaijo_sum = kaijo_sum * fact(DP[v][i].first) % mod;
    }
    rep(i, G[v].size()) {
        if (G[v][i] == par) continue;
        dfs2(G[v][i], v, pair<int, lint>{sz - DP[v][i].first + 1, sum * mod_pow(DP[v][i].second, mod - 2) % mod * fact(sz - DP[v][i].first) % mod * fact(DP[v][i].first) % mod * mod_pow(kaijo_sum, mod - 2) % mod});
    }
}

int main() {
    int N;
    cin >> N;
    G = vector<vector<int>>(N);
    DP = vector<vector<pair<int, lint>>>(N);
    rep(i, N - 1) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs1();
    dfs2();
    
    rep(v, N) {
        lint res = 1;
        res = res * fact(N - 1) % mod;
        rep(i, G[v].size()) {
            res = res * ifact(DP[v][i].first) % mod;
            res = res * DP[v][i].second % mod;
        }
        cout << res << "\n";
    }
    return 0;
}


Measured memory_bytes: 34924
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>

using namespace std;
using ll = long long;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<int>;

int main()
{
	vec P(3);
	cin >> P[0] >> P[1] >> P[2];

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

	cout << P[0] + P[1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int N;
    while(cin >> N){
        int cnt = 0;
        for(int i=1;i<=N;i++){
            int t; cin >> t;
            if(t != i) ++cnt;
        }
        cout << (cnt <= 2 ? "YES" : "NO") << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>

using namespace std;
typedef long long llint;
typedef long double ld;
#define inf 1e18

llint n,m;
string s;
void solve(){
	cin >> n >> m;
	llint ans=0;
	for(int i=1;i<n;i++){
		ans+=i;
	}
	for(int i=1;i<m;i++){
		ans+=i;
	}
	cout << ans << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n,a[101000],sum[101000],ans,now;
int main()
{
	int i;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+abs(a[i]-now);
		now=a[i];
	}
	for(i=1;i<n;i++)
	{
		ans=sum[n]-sum[i+1]+sum[i-1]+abs(a[i-1]-a[i+1])+abs(a[n]);
		printf("%d\n",ans);
	}
	ans=sum[n-1]+abs(a[n-1]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2048
package main

import "fmt"
var N, W int
var w, v []int
var dp []int

const MaxInt = 1<<31 - 1
func max(a, b int) int {
	if a > b { return a }
	return b
}

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

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

func main() {
	_,e := fmt.Scanf("%d%d", &N, &W)
	if e != nil { return }
	w,v = make([]int, N), make([]int, N)
	sum := 0
	for i:=0; i<N; i++ {
		_,e = fmt.Scanf("%d%d", &w[i], &v[i])
		sum += v[i]
	}
	dp = make([]int, sum+1)
	for i:=1; i<=sum; i++ {
		dp[i] = MaxInt
	}
	for i:=0; i<N; i++ {
		for j:=sum-v[i]; j>=0; j-- {
			dp[j+v[i]] = min(dp[j+v[i]], dp[j] + w[i])
		}
	}
	ans := 0
	for j:=1; j<=sum; j++ {
		if dp[j] <= W {
			ans = max(ans, j)
		}
	}
	fmt.Println(ans)
}


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

typedef struct nodetag {
    unsigned int key;
    struct nodetag *next;
    struct nodetag *prev;
} Node;

Node *createNode(int key)
{
    Node *node = malloc(sizeof(Node));
    node->key = key;
    node->next = node->prev = NULL;

    return node;
}

void insert(Node *node, Node **head, Node **tail)
{
    if(*tail == NULL || *head == NULL) {
        node->next = node->prev = NULL;
        *head = *tail = node;
    } else {
        (*tail)->next = node;
        node->prev = *tail;
        node->next = NULL;
        *tail = node; 
    }
}

void delete(int key, Node **head, Node **tail)
{
    Node *node = *tail;

    while(node != NULL && node->key != key) {
        node = node->prev;
    }
    if(node == NULL)
        return;
    if(node->prev == NULL) {
        (node->next)->prev = NULL;
        *head = node->next;
    } else if(node->next == NULL) {
        (node->prev)->next = NULL;
        *tail = node->prev;
    } else {
        (node->prev)->next = node->next;
        (node->next)->prev = node->prev;
    }
    free(node);
}

void deleteFirst(Node **head, Node **tail)
{
    Node *node = *tail;

    if(tail == NULL)
        return;

    *tail = (*tail)->prev;
    if(*tail == NULL) {
        *head = NULL;
        free(node);
        return;
    }
    (*tail)->next = NULL;
    free(node);
}

void deleteLast(Node **head, Node **tail)
{
    Node *node = *head;

    if(node == NULL)
        return;

    *head = (*head)->next;
    if(*head == NULL) {
        *tail = NULL;
        free(node);
        return;
    }
    (*head)->prev = NULL;
    free(node);
}

int main(void)
{
    int i, n, key;
    char command[11];
    Node *tail = NULL, *head = NULL, *node;

    scanf("%d", &n);
    for(i = 0; i < n; i++) {
        scanf("%s", command); 
        if(strcmp(command, "insert") == 0) {
            scanf("%d", &key);
            node = createNode(key);
            insert(node, &head, &tail); 
        } else if(strcmp(command, "delete") == 0) {
            scanf("%d", &key);
            delete(key, &head, &tail);
        } else if(strcmp(command, "deleteFirst") == 0) {
            deleteFirst(&head, &tail);
        } else if(strcmp(command, "deleteLast") == 0){
            deleteLast(&head, &tail);
        } else {
            printf("command not found: %s\n", command);
        }
    }
    printf("%d", tail->key);
    tail = tail->prev;
    while(tail != NULL) {
        printf(" %d", tail->key);
        tail = tail->prev;
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 31788
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int main(void){
    LL A,B,C,K;
    GLL(A);GLL(B);GLL(C);GLL(K);
    if(K%2==0)
        printf("%lld\n",A-B);
    else
        printf("%lld\n",(B+C)-(A+C));
    return 0;
}

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

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>a;
	cout<<(a-2)*180<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


ll power(ll a, ll b) {
    ll ans = 1;
    ll till = a;
    for (ll i = 0; (1 << i) <= b; i++) {
        if (b & (1 << i)) {
            ans = (ans * till) % mod;
        }

        till = (till * till) % mod;
    }

    return ans;
}


int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    double a, b, x, y;
    cin >> a >> b >> x >> y;
    cout << a * b / 2 << ' ' << (x == a / 2 && y == b / 2 ? 1 : 0);


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 998244353;
constexpr lint INF = mod*mod;
constexpr int MAX = 1000010;

template<int_fast64_t MOD> struct modint{
    using i64=int_fast64_t;
    i64 a;
    modint(const i64 a_=0): a(a_){
        if(a > MOD) a%=MOD;
        else if(a<0) (a%=MOD)+=MOD;
    }
    modint inv(){
        i64 t=1, n= MOD-2, x=a;
        while(n){
            if(n&1) (t*=x)%=MOD;
            (x*=x)%=MOD;
            n>>=1;
        }
        modint ret(t);
        return ret;
    }
    bool operator==(const modint x){return a==x.a;}
    bool operator!=(const modint x){return a!=x.a;}
    modint operator+(const modint x){
        return modint(*this)+=x;
    }
    modint operator-(const modint x){
        return modint(*this)-=x;
    }
    modint operator*(const modint x){
        return modint(*this)*=x;
    }
    modint operator/(const modint x){
        return modint(*this)/=x;
    }
    modint operator^(const modint x){
        return modint(*this)^=x;
    }
    modint &operator+=(const modint &x){
        a+=x.a;
        if(a >= MOD) a-=MOD;
        return *this;
    }
    modint &operator-=(const modint &x){
        a-=x.a;
        if(a<0) a+=MOD;
        return *this;
    }
    modint &operator*=(const modint &x){
        (a*=x.a)%=MOD;
        return *this;
    }
    modint &operator/=(modint x){
        (a*=x.inv().a)%=MOD;
        return *this;
    }
    modint &operator^=(lint n){
        lint ret=1;
        while(n){
            if(n&1) (ret*=a)%=MOD;
            (a*=a)%=MOD;
            n>>=1;
        }
        a=ret;
        return *this;
    }
};

using mint=modint<1000000007>;

vector<mint> fact;
vector<mint> revfact;

void setfact(int n){
    fact.resize(n+1); revfact.resize(n+1);
    fact[0] = 1;
    rep(i, n) fact[i+1] = fact[i] * mint(i+1);

    revfact[n] = fact[n].inv();
    for(int i=n-1; i>=0; i--) revfact[i] = revfact[i+1] * mint(i+1);
}

mint getC(int n, int r){
    if(n<r) return 0;
    return fact[n] * revfact[r] * revfact[n-r];
}

int main(){
    int n;
    string s;
    cin>>n>>s;
    if(s[0]=='W' || s[n*2-1]=='W'){
        printf("%d\n", 0);
        return 0;
    }

    setfact(n);
    int d[2*n];
    rep(i, 2*n) d[i]=0;
    mint L=1, ans=fact[n];
    For(i, 1, 2*n){
        d[i]=(s[i]==s[i-1] ? d[i-1]^1 : d[i-1]);
        if(d[i]==1){
            if(L==0){
                printf("%d\n", 0);
                return 0;
            }
            ans*=L;
            L-=1;
        }
        else L+=1;
    }
    printf("%lld\n", L==0 && d[2*n-1]==1 ? ans.a : 0);
}

Measured memory_bytes: 2948
#include<bits/stdc++.h>
int main(){
    int n,a,b;std::cin>>n>>a>>b;
    int ab=a+b;
    while(n--){
        char c;std::cin>>c;
        std::cout<<(c=='a'&&ab-->0||c=='b'&&b-->0&&ab-->0?"Yes":"No")<<std::endl;
    }
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+9;
int n,m,q;
struct edge{
    int to,next;
}edges[maxn<<1];
int col[maxn];
int head[maxn];
int ceng[maxn];
int no;
void addedge(int from,int to){
    edges[no].to=to;
    edges[no].next=head[from];
    head[from]=no++;
}
int arr[maxn][3];
void bfs(int o,int dis,int c){
    if(ceng[o]>=dis)return;
    ceng[o]=max(ceng[o],dis);
    if(!col[o]){
        col[o]=c;
    }
    for(int i=head[o];~i;i=edges[i].next){
        int e=edges[i].to;
        if(ceng[e]<dis-1){
            bfs(e,dis-1,c);
        }
    }
}
int main(){
    int a,b,c,d,e,f,g,h;
    memset(head,-1,sizeof(head));
    memset(ceng,-1,sizeof(ceng));
    ios::sync_with_stdio(0);
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>e>>f;
        addedge(e,f);
        addedge(f,e);
    }
    cin>>q;
    for(int i=0;i<q;i++){
        for(int j=0;j<3;j++){
            cin>>arr[i][j];
        }
    }
    for(int i=q-1;i>-1;i--){
        bfs(arr[i][0],arr[i][1],arr[i][2]);
    }
    for(int i=1;i<=n;i++){
        cout<<col[i]<<endl;
    }
    return 0;
}


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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n, p;
    cin >> n >> p;
    map<i64, i64> factor;
    for (i64 i = 2; i * i <= p; i++) {
        while (p % i == 0) {
            factor[i]++;
            p /= i;
        }
    }
    if (p != 1) factor[p]++;

    i64 ans = 1;
    for (auto& e : factor) ans *= (i64) pow(e.first, e.second / n);
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 256
MOD = 10 ** 9 + 7


def comb(n, k):
    t = 1
    for i in range(n - k + 1, n + 1):
        t *= i
        t %= MOD
    a = 1
    for i in range(1, k + 1):
        a *= i
        a %= MOD
    return t * pow(a, MOD - 2, MOD) % MOD


n, a, b = map(int, input().split())
ans = pow(2, n, MOD) - comb(n, a) - comb(n, b) - 1
ans %= MOD
print(ans)


Measured memory_bytes: 38896
#include <stdio.h>

void dfs(int x,int y,int mp[14][14]){

  if(mp[x][y] == 0) return;

  mp[x][y] = 0;
  if(mp[x-1][y] == 1) dfs(x-1,y,mp);
  if(mp[x][y-1] == 1) dfs(x,y-1,mp);
  if(mp[x+1][y] == 1) dfs(x+1,y,mp);
  if(mp[x][y+1] == 1) dfs(x,y+1,mp);
  
}

int main(){
  int i,j,cnt,mp[14][14];
   
  for(i = 0 ; i < 14 ; i++)
    for(j = 0 ; j < 14 ; j++)
      mp[i][j] = 0;


  while(1){ 
    cnt = 0;

    for(i = 1 ; i < 13 ; i++)   
      for(j = 1 ; j < 13 ; j++)
        if(scanf("%1d" ,&mp[i][j]) == EOF) return 0;   

    for(i = 1 ; i < 13 ; i++){   
      for(j = 1 ; j < 13 ; j++){
        
        if(mp[i][j] == 1){
          cnt++;
          dfs(i,j,mp);
        }      

      }
    }  

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

  return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	vector<ll> h(n);
	rep(i,n){
		cin>>h[i];
	}
	vector<vector<ll>> g(n);
	vector<bool> used(n,true);
	rep(i,m){
		ll a,b;
		cin>>a>>b;
		a--,b--;
		if(h[a]>h[b]){
			used[b]=false;
		}
		if(h[a]<h[b]){
			used[a]=false;
		}
		if(h[a]==h[b]){
			used[a]=used[b]=false;
		}
		g[a].push_back(b);
		g[b].push_back(a);
	}
	ll ans=0;
	rep(i,n){
		if(used[i]) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 9732
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}

int main(){
  ll A,B,C,K; cin >> A >> B >> C >> K;
  ll ans = 0;
  ans = min(K,A);
  K -= A;
  K -= B;
  if(K>0) ans -= K;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define N 30005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

ll f[N];
ll inv[N];

ll bigmod(ll a,ll n)
{
    if(n==0)
        return 1;
    ll ans=bigmod(a,n/2);
    ans=(ans*ans)%M;
    if(n%2==1)
        ans=(ans*a)%M;
    return ans;
}

ll C(ll n,ll r)
{
    ll l=inv[r]*inv[n-r];
    l%=M;
    return f[n]*l%M;
}

main()
{
    f[0]=1;
    for(int i=1;i<N;i++)
        f[i]=(f[i-1]*i)%M;

    for(int i=0;i<N;i++)
    {
        inv[i]=bigmod(f[i],M-2);
    }
    ll s;
    ll ans=0;
    cin>>s;
    for(int len=1;len<=2000;len++)
    {
        ll baki=s-len*3;
        if(baki>=0)
        {
            ans+=C(baki+len-1,len-1);
            ans%=M;
        }
    }
    cout<<ans;
}



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


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<ld> doble(30,1);
    FOR(i,1,30){
      doble[i] = 2*doble[i-1];
    }
    ll n,k;
    cin>>n>>k;
    ll po = 20;
    ld ans = 0;
    FOR(i,1,n+1){
      while(i*doble[po]>=k){
        po--;
      }
      ans = ans + (ld)(1/doble[po+1]);
    }
    ans = ans/(ld)n;
    cout(10)<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int N, a[maxn];
long long sum[maxn];
int main() {
    cin >> N;
    for(int i = 0; i < N; ++i) cin >> a[i], sum[i+1] = sum[i] + a[i];
    int ans = 0;
    for(int i = 0; i < N-1; ++i) {
        ans = (ans + a[i] * ((sum[N] - sum[i+1]) % mod)) % mod;// [i+1, N-1]
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5968
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define MEM(x) memset(x,0,sizeof(x))
#define vc vector<int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define inf 0x3f3f3f3f
#define t_case int tt; cin>>tt; while (tt--)
#define lnginf 9223372036854775807
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define For(i,j,k) for (int i=(int)(j);i<(int)(k);i++)
#define ins insert
#define in(x); { for (auto &i : x) cin >> i; }
#define out(x); { for (auto i : x) cout<<i<<' ' ; }
#define PI 3.14159265359
const long long LL_INF = (long long) 2e18 + 5;
using namespace std;
void solve() {
	int n; cin >> n;
	int need = (n + 1000 - 1) / 1000;
	need *= 1000;
	cout << need - n << '\n';
}
int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif


	fastio solve();


}


Measured memory_bytes: 3644
from collections import Counter, defaultdict
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_CEILING
from functools import lru_cache, reduce
from itertools import combinations_with_replacement, product, combinations


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


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


def read_str():
    return input()


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


def mt(f):
    import time
    import sys

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

        print(e - s, 'sec', file=sys.stderr)
        return ret

    return wrap


@mt
def slv(S, X, P):
    X_ = [[P[i], [x]] for i, x in enumerate(X)]
    while len(X_) != 1:
        if X_[0][0] >= X_[-1][0]:
            di = -1
            li = 0
        else:
            di = 0
            li = -1
        X_[li][0] += X_[di][0]
        X_[li][1] += X_[di][1]
        X_.pop(di)

    t = 0
    pos = S
    p0 = S
    p1 = S
    for o in X_[0][1]:
        if p0 < o < p1:
            continue

        t += abs(pos - o)
        if o < pos:
            p0 = o
        else:
            p1 = o
        pos = o

    return t


def main():

    N, S = read_int_n()
    X = []
    P = []
    for _ in range(N):
        x, p = read_int_n()
        X.append(x)
        P.append(p)

    print(slv(S, X, P))


if __name__ == '__main__':
    main()

Measured memory_bytes: 32612
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;
  
#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
  
#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
  
const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
  
  
  
int main(){
	int i,j,n,k;
	
	cin>>n>>k;
	int ans=1;
	FOR(i,0,n){
		if(ans<=k)ans*=2;
		else ans+=k;
	}
	
	
	cout<<ans<<endl;
	
	
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> x;
	cout<<(1000-x%1000)%1000<<endl;
}

Measured memory_bytes: 3608
a,b,c,d,e,f=map(int,input().split())
dp=[-1]*(f+1)
dp[0]=0
flag=True
for i in range(1,f+1):
  for j in [a*100,b*100]:
    if i-j>=0 and dp[i-j]!=-1:
      dp[i]=max(0,dp[i])
  for j in [c,d]:
    if i-j>=0 and dp[i-j]!=-1:
      if 100*(dp[i-j]+j)<=e*(i-(dp[i-j]+j)):
        dp[i]=max(dp[i],dp[i-j]+j)
      else:
        for k in [a*100,b*100]:
          if i-k-j>=0 and dp[i-k-j]!=-1:
            if 100*(dp[i-k-j]+j)<=e*(i-(dp[i-k-j]+j)):
              dp[i]=max(dp[i],dp[i-k-j]+j)
stack=0
index=min(a*100,b*100)
for i in range(index+1,f+1):
  if dp[i]>0:
    if stack<(dp[i]*100)/i:
      stack=(dp[i]*100)/i
      index=i
print(index,dp[index])

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

const int p=998244353;
int qpow(int a,int k){
	int ans=1;
	while(k){
		if(k&1) ans=1LL*ans*a%p;
		a=1LL*a*a%p;
		k>>=1;
	}
	return ans;
}

int N;
int fac[405],ifac[405],inv[405];
int A[405],S,iS,B[405],T; 

int P[405][405];int G[405];

int main(){
	fac[0]=fac[1]=ifac[0]=ifac[1]=inv[1]=1;
	for(int i=2;i<=400;i++)
		inv[i]=1LL*(p-p/i)*inv[p%i]%p,
		fac[i]=1LL*fac[i-1]*i%p,
		ifac[i]=1LL*ifac[i-1]*inv[i]%p;
	scanf("%d",&N);
	for(int i=0;i<N;i++) scanf("%d%d",&A[i],&B[i]),S+=A[i],T+=B[i]-1;
	iS=qpow(S,p-2);
	
	P[0][0]=1;int tS=0,tT=0;
	for(int i=0;i<N;i++){
		for(int j=0,mul=1;j<=B[i]-1;j++) G[j]=1LL*mul*ifac[j]%p,mul=1LL*mul*A[i]%p*iS%p;
		tS+=A[i];tT+=B[i]-1;
		for(int j=tS;j>=0;j--){
			for(int k=tT;k>=0;k--){
				int tmp=0;
				for(int kk=0;kk<=B[i]-1&&kk<=k;kk++)
					tmp=(tmp+1LL*G[kk]*P[j][k-kk]%p)%p;
				P[j][k]=(p-tmp)%p;
			}
			if(j>=A[i]) for(int k=0;k<=tT;k++) P[j][k]=(P[j][k]+P[j-A[i]][k])%p;
		}
	}
	int ans=0;
	for(int i=0;i<S;i++){
		int x=1LL*i*iS%p,ix=qpow(x,p-2);
		int F=qpow(1-x+p,p-2),FF=F;
		for(int j=0;j<=T;j++){
			ans=(ans+1LL*P[i][j]*fac[j]%p*F%p)%p;
			F=1LL*F*FF%p;
		}
	}
	printf("%d\n",(p-ans)%p);
}

Measured memory_bytes: 4476
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0 ; i < int(N);i++)
#define all(x) (x.begin(),x.end())
using namespace std ;
typedef long long ll;
typedef pair <int , int >pi;
typedef vector <int> vi ;
typedef vector <string> si;



int main (){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin >> s;
	if(s.back() == 's') cout << s <<"es" <<endl;
	else cout << s <<"s" <<endl;


	return 0 ;
}

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

#define LL long long
#define LD long double
#define pdd pair<LD, LD>
#define mp make_pair
#define Vector Point

const int maxN = 2e5 + 105;

struct Point
{
	LD x, y;
	Point(LD X = 0, LD Y = 0) { x = X; y = Y; }
}p[maxN + 1];

Vector operator - (Vector a, Vector b) { return Vector(a.x - b.x, a.y - b.y); }

int n;
int stk[maxN + 1], top;
LL a[maxN + 1], b[maxN + 1];
LD c[maxN + 1];

pdd t[maxN + 1];

inline LL read()
{
	LL num = 0, f = 1;
	char ch = getchar();
	while( !isdigit( ch ) ) { if(ch == '-') f = -1; ch = getchar(); }
	while( isdigit( ch ) ) num = (num << 3) + (num << 1) + (ch ^ 48), ch = getchar();
	return num * f;
}

inline void get()
{
	t[1] = mp(0, 0); t[2] = mp(1.0, 0);
	for(int i = 2; i <= n; i++)
	{
		t[i + 1].first = 2 * t[i].first - t[i - 1].first;
		t[i + 1].second = 2 * t[i].second - t[i - 1].second + 2.0 * b[i];
	}
	LD x = -t[n + 1].second / t[n + 1].first;
	for(int i = 2; i <= n; i++) c[i] = x * t[i].first + t[i].second;
}

inline LD Cross(Vector a, Vector b)
{
	return a.x * b.y - a.y * b.x;
}

int main()
{
	n = read();

	for(int i = 1; i <= n; i++) a[i] = read();
	for(int i = 1; i <= n; i++) b[i] = read();

	int id = 1;
	for(int i = 2; i <= n; i++) if(a[i] > a[id]) id = i;
	rotate(a + 1, a + id, a + n + 1);
	rotate(b + 1, b + id, b + n + 1);
	a[n + 1] = a[1];

	get();

	p[1] = Point(1, a[1]); p[n + 1] = Point(n + 1, a[1]);
	for(int i = 2; i <= n; i++) p[i] = Point(i, (LD)a[i] - c[i]);
	
	stk[ top = 1 ] = 1;
	for(int i = 2; i <= n + 1; i++)
	{
		while(top > 1 && Cross(p[ stk[top] ] - p[ stk[top - 1] ], p[i] - p[ stk[top - 1] ]) >= 0) top --;
		stk[++ top] = i;
	}

	LD ans = 0;
	for(int i = 1; i < top; i++)
	{
		int l = stk[i], r = stk[i + 1];
		LD s = p[l].y, d = (p[r].y - p[l].y) / (LD)(r - l);
		for(int j = l; j < r; j++, s += d) ans += s + c[j];
	}
	ans /= (LD)n;

	printf("%.15Lf\n", ans);
	return 0;
}


Measured memory_bytes: 23120
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <queue>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define sort_key(struct_name,key_name) [](const struct_name &x, const struct_name &y){return x.key_name < y.key_name;}
#define pb(x) push_back(x)
typedef long long ll;
const long long MOD = 1e9 + 7;
using namespace std;

//main
int main(){
  ll N,M; cin >> N >> M;
  priority_queue<ll> A;
  ll a;
  ll t;
  ll ans=0;
  rep(i,N){
    cin >> a;
    A.push(a);
  }
  rep(i,M){
    t = A.top();
    A.pop();
    A.push(t/2);
  }
  while(!A.empty()){
    ans += A.top();
    A.pop();
  }
  cout << ans << endl;
}



Measured memory_bytes: 1400