akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;

ll nCr(ll n, ll r) {
	if (r > n) { return 0; }
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
ll sumdigit(ll n) {
	ll dig = 0, sum = 0;
	while (n) {
		dig = n % 10;
		sum = sum + dig;
		n = n / 10;
	}
	return sum;
}



int main() {
	int a, b, c;
	std::cin >> a >> b >> c;
	if (b - a == c - b) {
		std::cout << "YES" << std::endl;
	}
	else {
		std::cout << "NO" << std::endl;
	}
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int n,k;
    cin >> n >> k;
    vector<double> v(n);
    rep(i,n){
        double a; cin >> a;
        v[i] = (a + 1) / 2;
    }
    double tmp = 0.0;
    rep(i,k){
        tmp += v[i];
    }
    double ans = tmp;
    rep(i,n-k){
        tmp += v[i + k] - v[i];
        ans = max(ans,tmp);
    }
    cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>

const int MAXN = 5e5 + 10, K = 707;
int n, q;
int cnt[MAXN];
int a[MAXN];
int ans;

void add(int x) {
    if(!cnt[x]) ans++;
    cnt[x]++;
}

void del(int x) {
    cnt[x]--;
    if(!cnt[x]) ans--;
}

struct qu {
    int l, r, idx;
    bool operator < (qu x) {
        if(l / K != x.l / K) return (l / K < x.l / K);
        return (r < x.r);
    }
} qq[MAXN];
int anss[MAXN];
void solve() {
    cin >> n >> q;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    int L = 1, R = 0;
    for(int i = 1; i <= q; ++i)
        cin >> qq[i].l >> qq[i].r, qq[i].idx = i;
    sort(qq + 1, qq + q + 1);
    for(int i = 1; i <= q; ++i) {
        int tmpl = qq[i].l, tmpr = qq[i].r;
        while(L < tmpl) del(a[L++]);
        while(L > tmpl) add(a[--L]);
        while(R < tmpr) add(a[++R]);
        while(R > tmpr) del(a[R--]);
        anss[qq[i].idx] = ans;
    }
    for(int i = 1; i <= q; ++i) cout << anss[i] << '\n';
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
    ///cin >> t;
    while(t--) solve(), cout << '\n';
    return 0;
}


Measured memory_bytes: 15424
n,k=map(int,input().split())

W=[int(input()) for _ in range(n)]

def Wcheck(W,P,k):
    i=0
    for j in range(k):
        temp_w=0
        while temp_w+W[i]<=P:
            temp_w=temp_w+W[i]
            i=i+1
            if i==len(W):
                return len(W)

    return i

def PSearch(W,start,end,k):
    if start==end:
        return start
    mid=(start+end)//2
    v=Wcheck(W,mid,k)
    if v>=n:
        return PSearch(W,start,mid,k)
    else:
        return PSearch(W,mid+1,end,k)

print(PSearch(W,0,1000000000,k))


Measured memory_bytes: 9560
using System;
using System.Linq;

class P
{
  static void Swap<T>(ref T a, ref T b)
  {
    var c = a;
    a = b;
    b = c;
  }

  static void Main()
  {
    for(;;) {
      var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
      if(a[0] > a[1])
        Swap(ref a[0], ref a[1]);
      if(a[1] == 0) break;
      Console.WriteLine("{0} {1}", a[0], a[1]);
    }
  }
}

Measured memory_bytes: 9820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
const int inf=1e9;
const int N=2e5+20;
const int M=2e3+20;
int a[N];// a[i] 编号i的左右人数之差绝对值为a[i] 求满足条件的排列个数 
map<int,int> mp;
int main()
{
	ll ans=1;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		mp[a[i]]++;
	} 
	if(mp[0]>1)
	{
		//左右人数之差为0 只能在中间  
		cout<<0<<endl;
	}
	else
	{
	
		bool flag=true;
		for(int i=1;i<=n;i++)
		{
			if(mp[i])
			{
				//相同的最多只能有两个 
				if(mp[i]>2)
				{
					flag=false;
					break;
				}
				
				//这两个人的位置可以互换 
				if(mp[i]==2)
				ans=(ans*2)%mod;
				
			}
		}
		if(!flag)
		cout<<0<<endl;
		else
		cout<<ans<<endl;
	}
	
	return 0;	
} 

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;


const ll mod = 1000000007; // faster if const

ll modpow(ll b, ll e) {
	ll ans = 1;
	for (; e; b = b * b % mod, e /= 2)
		if (e & 1) ans = ans * b % mod;
	return ans;
}
const int N = 300005;
ll fat[N];
ll line(ll a,  ll b){
	if(a < b) return 0;
	ll c = (a-b);
	ll p = 1;
	while(a > c){
		p = (p*a)%mod;
		a-- ;
	}
	p = (p*modpow(fat[b] , mod - 2))%mod;
	return p;
}

int32_t main(){
	fat[0] = 1;
	rep(i,1,N) fat[i] = (i*fat[i-1])%mod;
	ll n , a, b;
	cin >> n>>a>>b;
	ll ans = (modpow(2, n) - 1 + mod)%mod;
	ans = (ans - line(n , b) - line(n, a))%mod;
	if(ans < 0) ans += mod;
	cout << ans << endl;

}

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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
	char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
	vector<char*> v({token});
	while(token = strtok(NULL,", ")) v.push_back(token);
	return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
	debug() << " [" << args.back() << ": " << H << "] ";
	args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

int main(){
	IOS;
	int n,i,u,v;
	cin>>n;
	vi adj[n+1];
	REP(i,1,n-1){
		cin>>u>>v;
		adj[u].EB(v);
		adj[v].EB(u);
	}
	ll ans=0,prev=0;
	int idx=0,p;
	set<int> s;
	REP(i,1,n){
		set<int> v;
		for(auto u:adj[i]){
			if(s.find(u)!=s.end()) v.insert(u);
		}
		ans+=prev+i;
		prev+=i;
		idx=0;
		p=0;
		for(auto u:v){
			ans-=(u-p)*(sz(v)-idx);
			prev-=(u-p)*(sz(v)-idx);
			idx++;
			p=u;
		}
		s.insert(i);
		// dbg(ans,prev,s,ma,mi);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 33676
#include <bits/stdc++.h>
using namespace std;
// clang-format off

using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
 
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
// clang-format on
const string YES = "Yes";
const string NO = "No";

void solve(std::vector<std::vector<long long>> A, long long N, std::vector<long long> b) {
  // solver code

  vector<vector<bool>> B(3, vector<bool>(3, false));

  REP(i, N) {
    int num = b[i];
    REP(row, 3) {
      REP(col, 3) {
        if (num == A[row][col]) {
          B[row][col] = true;
        }
      }
    }
  }

  REP(i, 3) {
    // check row

    if (B[i][0] && B[i][1] && B[i][2]) {
      cout << YES << endl;
      return;
    }
    if (B[0][i] && B[1][i] && B[2][i]) {
      cout << YES << endl;
      return;
    }
  }
  if (B[0][0] && B[1][1] && B[2][2]) {
    cout << YES << endl;
    return;
  }

  if (B[0][2] && B[1][1] && B[2][0]) {
    cout << YES << endl;
    return;
  }

  cout << NO << endl;

  // cout << B << endl;
}

int main() {
  std::vector<std::vector<long long>> A(3, std::vector<long long>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      scanf("%lld", &A[i][j]);
    }
  }
  long long N;
  scanf("%lld", &N);
  std::vector<long long> b(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &b[i]);
  }
  solve(std::move(A), N, std::move(b));
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define max(a, b) a>b?a:b
using namespace std;

string lcs(string s1, string s2){
    string cs1 = "";
    string cs2 = "";

    const int N = s1.size();
    const int M = s2.size();
    int dp[N+1][M+1];

    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= M; j++){
            if(i == 0 || j == 0)
                dp[i][j] = 0;

            else if(s1[i-1] == s2[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else if(s1[i-1] != s2[j-1])
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    int i = N, j = M;
    while (i > 0 && j > 0){
        if(s1[i-1] == s2[j-1]){
            cs1 = s1[i-1] + cs1;
            i--;
            j--;
        }
        else if(dp[i-1][j] > dp[i][j-1])
            i--;
        else
            j--;
    }

    // cout << dp[N][M] << endl;
    // cout << cs1 << endl << cs2 << endl;
    return cs1;
}

int main(){
    string s1, s2;
    cin >> s1 >> s2;
    cout << lcs(s2, s1);
    return 0;
}

Measured memory_bytes: 38848
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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 x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int n,s,t;
  cin>>n>>s>>t;
  s--;t--;

  vector<vector<int>> g(n);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].pb(b);
    g[b].pb(a);
  }

  vector<int> dis(n,-1);
  deque<int> que;
  dis[t]=0;
  que.pb(t);
  while(!que.empty()){
    int v=que.front();
    que.pop_front();
    for(int nv : g[v]){
      if(dis[nv]!=-1) continue;
      dis[nv]=dis[v]+1;
      que.pb(nv);
    }
  }

  vector<int> dist(n,-1);
  dist[s]=0;
  que.pb(s);
  while(!que.empty()){
    int v=que.front();
    que.pop_front();
    for(int nv : g[v]){
      if(dist[nv]!=-1 || dist[v]+1>=dis[nv]) continue;
      dist[nv]=dist[v]+1;
      que.pb(nv);
    }
  }  

  int an=-1;
  rep(i,n){
    if(dist[i]!=-1) chmax(an,dis[i]);
  }

  cout << an-1 << endl;
}

Measured memory_bytes: 9540
list = [int(input()) for _ in range(5)]
list10 = [i+(10-i)%10 for i in list]
sum_list10 = sum(list10)

min_sum = sum_list10
for i in range(5):
  sum = sum_list10-list10[i]+list[i]
  if sum < min_sum:
    min_sum = sum
    
print(min_sum)

Measured memory_bytes: 2940
#include <array>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int a, b, x;
  cin >> a >> b;
  if (b < 10) {
    x = 10 * a + b;
  } else if (10 <= b and b < 100) {
    x = 100 * a + b;
  } else if (b == 100) {
    x = 1000 * a + b;
  }

  for (int i = 1; i <= 1000; i++) {
    if (x == i * i) {
      cout << "Yes";
      return 0;
    }
  }

  cout << "No";
  return 0;
}

Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int n;
int a[200000];
long long f(long long b) {
    long long sum = 0;
    for (int i = 0; i < n; ++i) {
        sum += abs(a[i] - (b + (i + 1)));
    }
    return sum;
}
int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    long long left = -1e9, right = 1e9; //logN ≈ 9
    while (right - left > 1) {
        long long mid = (left + right) / 2;
        if (f(mid - 1) < f(mid + 1)) {
            right = mid;
        } else {
            left = mid;
        }
    }
    cout << min(f(right), f(left)) << endl;
    return 0;
}





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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr double EPS = 1e-10;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;






int main() {
    int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
    a--; b--; c--; d--;
    string s; cin >> s;

    bool can = true;

    set<int> num;
    int k = -1;
    for (int i = a; i < max(c, d); i++) {
        if (s[i] == '#') {
            if (k != -1) num.insert(i - k);
            k = i;
        }
    }

    if (num.count(1)) can = false;

    if (c > d) {
        bool f = false;
        for (int i = b; i <= d; i++) {
            if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.' ) {
                f = true;
                break;
            }
        }
        if (!f) can = false;
    }

    cout << (can ? "Yes" : "No") << endl;



}



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

const int maxn=16;
vector<pair<int,int>>per[maxn];
int main()
{
    int n;
    cin >> n;
    int num1 ,num2 ;
    for(int i=1;i<=n;i++){
        int len;
        cin >> len;
        for(int j=0;j<len;j++){
            cin >> num1 >> num2 ;
            per[i].push_back({num1,num2});
        }
    }
    int state[17]={0};
    int maxstate=(1<<n);
    //cout << maxstate << endl;
    int ans=0;
    for(int i=0;i<=maxstate;++i){
        int d=i;
        int flag=0;
        num1 = 0;
        for(int j=1;j<=n;++j){
            if(d%2)
                num1++;
            state[j]=(d%2);
            d/=2;
        }
        for(int j=1;j<=n;++j){
            if(state[j]==1){
                for(auto k : per[j]){
                    if(state[k.first]!=k.second){
                        flag=1;
                        break;
                    }
                }
            }
            else{
                flag=1;
                for(auto k : per[j]){
                    if(state[k.first]!=k.second){
                        flag=0;
                        break;
                    }
                }
            }
            if(flag)
                break;
        }
        if(flag)
            continue;
        ans=max(ans,num1);
    }
    cout << ans<< endl;
    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
	long long a,b,c,i,x,y;
	x=0;
	y=0;
	cin>>a>>b>>c;
	arr[a]++;
	arr[b]++;
	arr[c]++;
	for (i=0;i<10;i++)
	{
		if (arr[i]==1)
		{
			x=1;
		}
		if (arr[i]==2)
		{
			y=1;
		}
	}
	if (x==1 && y==1)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n,k,a[305],dp[305][305][305];
ll f(ll i,ll p,ll r)
{
    if(i==n)
        return 0;
    if(dp[i][p][r]!=-1)
        return dp[i][p][r];
    ll ans=a[i]-min(a[i],a[p])+f(i+1,i,r);
    if(r)
    {
        ans=min(ans,f(i+1,n,r-1));
        ans=min(ans,f(i+1,p,r-1));
    }
    dp[i][p][r]=ans;
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    memset(dp,-1,sizeof(dp));
    cin>>n>>k;
    ll p=0;
    rep(i,0,n)
    {
        cin>>a[i];
        p+=(a[i]-min(a[i],(i?a[i-1]:0)));
    }
    if(k==0)
    {
        cout<<p<<"\n";
        return 0;
    }
    ll ans=a[0]+f(1,0,k);
    rep(i,1,n+1)
        ans=min(ans,a[i]+min(ans,f(1,i,k-1)));
    cout<<ans;
}


Measured memory_bytes: 221952
#include <iostream>
#include <stdio.h>
#include <math.h>

char str[]="hoge";

int main(){
  int N,Y;
  int a,b,c;
  std::cin >> N>>Y;
  int flag=0;
  for(int i=0;i<=N;i++){//一万円
    for(int j=0;j<=N-i;j++){//五千円
      if(i*10000+j*5000+(N-i-j)*1000==Y){
        flag=1;
        a=i;
        b=j;
        c=N-i-j;
        break;
      }
    }
  }
  // std::cout <<flag << '\n';
  if(flag==1){
    std::cout << a<<" "<<b<<" "<<c << '\n';
  }else{
    std::cout << "-1 -1 -1" << '\n';
  }



}

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

int main(){
    int x, y, z;
    cin >> x >> y >> z;

    int n = x + y + z;

    vector<pair<long long int,pair<long long int, pair<long long int, long long int>>>> coin(n);
    for(int i=0; i<n; i++){
        cin 
        >> coin[i].second.first 
        >> coin[i].second.second.first
        >> coin[i].second.second.second;

        coin[i].first = coin[i].second.first - coin[i].second.second.first;
    }
    sort(coin.begin(),coin.end());

    vector<long long int> sx(n+1), sy(n+1);
    priority_queue<long long int, vector<long long int>, greater<long long int>> pqx, pqy;

    for(int i=0; i<n; i++){
        long long int b = coin[i].second.second.first;
        long long int c = coin[i].second.second.second;
        if(pqy.size() < y){
            pqy.push(b-c);
            sy[i+1] = sy[i] + b;
        }
        else{
            long long int t = pqy.top();
            if(b-c <= t) sy[i+1] = sy[i] + c;
            else{
                pqy.pop();
                pqy.push(b-c);
                sy[i+1] = sy[i] + b - t;
            }
        }
    }

    for(int i=n-1; i>=0; i--){
        long long int a = coin[i].second.first;
        long long int c = coin[i].second.second.second;
        if(pqx.size() < x){
            pqx.push(a-c);
            sx[i] = sx[i+1] + a;
        }
        else{
            long long int t = pqx.top();
            if(a-c <= t) sx[i] = sx[i+1] + c;
            else{
                pqx.pop();
                pqx.push(a-c);
                sx[i] = sx[i+1] + a - t;
            }
        }
    }

    long long int ans = 0;
    for(int i=y; i+x<=n; i++){
        //cout << sy[i] << " " << sx[i] << endl;
        ans = max(ans, sy[i] + sx[i]);
    }
    cout << ans << endl;
    return 0;
}

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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> v;
  load(v, n);

  int c = 0;
  rep(i, n) {
    if (i == 0) {
      c++;
    } else {
      bool check = true;
      for (int j = 0; j < i; ++j) {
        if (v[j] > v[i]) {
          check = false;
        }
      }
      if (check) {
        c++;
      }
    }
  }
  p(c);
}

Measured memory_bytes: 256
uses math;
var
	ans,n,Ma,Mb,i,j,a,b,c,x,mp,mm:Longint;
	p,m:array[0..100]of Longint;
begin
	read(n,Ma,Mb);
	ans:=10000;
	for i:=1 to 100 do begin
		p[i]:=ans;
		m[i]:=ans;
	end;
	for i:=1 to n do begin
		read(a,b,c);
		x:=Ma*b-Mb*a;
		if x>0 then begin
			mp:=min(mp+x,100);
			for j:=mp-x downto 0 do p[j+x]:=min(p[j+x],p[j]+c);
		end else if x<0 then begin
			mm:=min(mm-x,100);
			for j:=mm+x downto 0 do m[j-x]:=min(m[j-x],m[j]+c);
		end else ans:=min(ans,c);
	end;
	for i:=1 to 100 do ans:=min(ans,p[i]+m[i]);
	if ans<10000 then writeln(ans)else writeln(-1);
end.

Measured memory_bytes: 128
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		long ans = 1;
		for(int i = 0;i < N;i++){
			A[i] = sc.nextLong();
		}
		Arrays.sort(A);
		for(int i = 0;i < N;i++){
			if(A[i] == 0){
				ans = 0;
				break;
			}else if(A[i] <= 1000000000000000000L / ans){
				ans *= A[i];
			}else{
				ans = -1;
				break;
			}
		}
		if(ans > 1000000000000000000L){
			ans = -1;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 50456
s=input()
n=len(s)
list=["A","C","G","T"]
new=[]
a=0
for i in range(n):
  if s[i] in list:
    a+=1
    if i == n-1:
      new.append(a)
  if s[i] not in list:
    new.append(a)
    a=0
print(max(new))

Measured memory_bytes: 3064
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
const long long INF = 1LL << 60;


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

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {//降順second
	if (a.second != b.second) {
		return a.second > b.second;
	}
	else {
		return a.first > b.first;
	}
}

bool compare_by_a(pair<ll, ll> a, pair<ll, ll> b) {//降順first
	if (a.first != b.first) {
		return a.first > b.first;
	}
	else {
		return a.second > b.second;
	}
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd


int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	ll num = 0;
	rep(i, n) {
		cin >> a[i];
		if (a[i] == 1)num = i;
	}
	ll total = 0;
	if ((n - 1) % (k - 1) == 0) {
		total += (n - 1) / (k - 1);
	}
	else {
		total += (n - 1) / (k - 1) + 1;
	}
	cout << total;


	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const long long MAXN=200005;
const long long INF=9223372036854775807ll;
long long n,m,ecnt,key=0;
long long w[MAXN],d[MAXN],z[MAXN];
struct edge
{
	long long v,c,nxt;
	edge(){}
	edge(long long vv,long long cc,long long nn)
	{
		v=vv,c=cc,nxt=nn;
	}
}ed[MAXN*4];
void addedge(long long u,long long v,long long a)
{
	ecnt++;
	ed[ecnt]=edge(v,a,w[u]);
	w[u]=ecnt;
	
	ecnt++;
	ed[ecnt]=edge(u,a,w[v]);
	w[v]=ecnt;
}
void dfs(long long u,long long val,long long k)
{
	if(z[u]==0)
	{
		d[u]=val;
		z[u]=k;
		for(long long i=w[u];i;i=ed[i].nxt)
		{
			long long v=ed[i].v;
			long long c=ed[i].c;
			dfs(v,c-val,-k);
		}
	}
	else
	{
		if(k==z[u])
		{
			if(d[u]!=val)
			{
				printf("0\n");
				exit(0);
			}
			return ;
		}
		else
		{
			int jk=0;
			if(k==1)
			{
				jk=d[u]-val;
				if((jk%2ll==1)||(jk<=0))
				{
					printf("0\n");
					exit(0);
				}
				jk=jk/2;
			}
			else
			{
				jk=val-d[u];
				if((jk%2ll==1)||(jk<=0))
				{
					printf("0\n");
					exit(0);
				}
				jk=jk/2;
			}
			if(key!=-INF&&key!=jk)
			{
				printf("0\n");
				exit(0);
			}
			key=jk;
			return ;
		}
	}
}
int main()
{
	key=-INF;
	scanf("%lld %lld",&n,&m);
	fill(d,d+MAXN,0);
	fill(z,z+MAXN,0);
	for(long long i=1;i<=m;i++)
	{
		long long u,v,s;
		scanf("%lld %lld %lld",&u,&v,&s);
		addedge(u,v,s);
		addedge(v,u,s);
	}
	dfs(1,0,1);
	if(key!=-INF)
	{
		for(long long i=1;i<=n;i++)
		{
			if(d[i]+z[i]*key<=0)
			{
				printf("0\n");
				return 0;
			}
		}
		printf("1\n");
		return 0;
	}
	long long da=-INF,x=INF;
	for(long long i=1;i<=n;i++)
	{
		if(z[i]==1)
		{
			da=max(da,-d[i]);
		}
		else
		{
			x=min(x,d[i]);
		}
	}
	da=max(da,0ll);
	x--;
	da++;
	if(x-da+1<=0)
		printf("0\n");
	else
		printf("%lld\n",x-da+1);
}

Measured memory_bytes: 17792
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
 
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

map<char, int> conv = {{'R', 0}, {'G', 1}, {'B', 2}};

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif
    
    int n;
    cin >> n;
    n *= 3;
    string s;
    cin >> s;
    vector<int> a[3];
    for (int i = 0; i < n; ++i)
    {
        a[conv[s[i]]].pb(i);
    }
    vector<int> c(n, -1);
    for (int it = 0; it < n / 3; ++it)
    {
        vector<int> b = {a[0][it], a[1][it], a[2][it]};
        sort(all(b));
        for (int i = 0; i < 3; ++i)
            c[b[i]] = i;
    }
    int f0 = 0, f1 = 0, f2 = 0;
    int ans = 1;
    for (int i = 0; i < n; ++i)
    {
        if (c[i] == 0)
        {
            ++f0;
        }
        else if (c[i] == 1)
        {
            ans = (ans * (ll)(f0 - f1)) % 998244353;
            ++f1;
        }
        else
        {
            ans = (ans * (ll)(f1 - f2)) % 998244353;
            ++f2;
        }
    }
    for (int x = 1; x <= n / 3; ++x)
    {
        ans = (ans * (ll)x) % 998244353;
    }
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 3340
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
 
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define rank rank228
#define y1 y1228
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define mp make_pair
using ll = long long;
using ld = long double;
// const int MAXMEM = 200 * 1000 * 1024;
// char _memory[MAXMEM];
// size_t _ptr = 0;
// void* operator new(size_t _x) { _ptr += _x; return _memory + _ptr - _x; }
// void operator delete (void*) noexcept {}
const string FILENAME = "input";
const int MAXN = 200228;



int n, m;
vector<pair<int, int> > g[MAXN];
int d[MAXN];
int c[MAXN];
int val[MAXN];


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  	//read(FILENAME);     
    cin >> n >> m;
    vector<pair<int, int> > st;
    for (int i = 0; i < n; i++) {
        cin >> d[i];
        st.pb({d[i], i});
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].pb({b, i});
        g[b].pb({a, i});
        val[i] = 1e9;
    }
    sort(all(st));
    for (int i = 0; i < n; i++) {
        int j = st[i].second;
        if (c[j]) {
            continue;
        }
        bool was = false;
        for (auto x: g[j]) {
            if (d[x.first] == d[j]) {
                if (c[x.first] == 0) {
                    c[x.first] = 1;
                    c[j] = 2; 
                } else {
                    c[j] = 3 - c[x.first];
                }
                val[x.second] = d[j];
                was = true;
                break;
            }
        }
        if (!was) {
            for (auto x: g[j]) {
                if (d[x.first] < d[j]) {
                    val[x.second] = d[j] - d[x.first];
                    was = true;
                    c[j] = c[x.first];
                    break;
                }
            }
        }
        if (!was) {
            cout << -1 << '\n';
            return 0;
        }
    }
    for (int i = 0; i < n; i++) {
        if (c[i] == 1) {
            cout << 'W';
        } else {
            cout << 'B';
        }
    }
    cout << '\n';
    for (int i = 0; i < m; i++) {
        cout << val[i] << '\n';
    }
    return 0;
}            	


Measured memory_bytes: 15348
#pragma GCC optimize(2)
#pragma GCC optimize(3)   
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<cstdlib>
//#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<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
typedef vector < ll > vl;
typedef vector < vl > vvl;
typedef pair < ll, ll > pll;
typedef long double ld;
typedef vector < pair < ll, ll > > vpll;
#define Boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define forn(i,n) for (ll i = 0; i < n; i++)
#define fo(i,n) for (ll i = 1; i <= n; i++)
#define fore(i,l,r) for (ll i = l; i <= r; i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define all(c) c.begin(), c.end()
#define go(c,it) for(auto it=(c).begin(); it!=(c).end(); it++)
#define back(c,it) for(auto it=(c).rbegin(); it!=(c).rend(); it++)
#define fi first
#define se second
#define MOD 998244353
#define MAX 1000000007
ll power(ll a,ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;}a=(a*a)%MOD;b>>=1;}return res;}
ll fact[500009];
ll fermat_inv(ll y){return power(y,MOD-2);}
ll nCrMod(ll n, ll r){ ll p=fact[n];ll q=(fact[r]*fact[n-r])%MOD;return (p*fermat_inv(q))%MOD;} 
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
const ld PI = acos(-1.0);
  int main(){
      #ifndef ONLINE_JUDGE
      freopen("input.cpp","r",stdin);
      freopen("output.cpp","w",stdout);
      #endif
      Boost();
      int t;
      //cin>>t;
      t=1;
      int t1=t;
      while(t--)
      {
        ll n,d;
        cin>>n>>d;
        ll ans=0;
        fo(i,n)
        {
          ll x,y;
          cin>>x>>y;
          ll z=x*x+y*y-d*d;
          if(z<=0)
            ans++;
        }
        cout<<ans<<endl;
      }
      return 0;
      }
  

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

#define dcm(x) cerr << #x << ": " << x << endl;

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

int main() {
    //clock_t start = clock();
    ios::sync_with_stdio(false); cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n; cin >> n;
    int arr[105];
    int sum = 0;
    for (int i=0; i<n; ++i) {
        cin >> arr[i];
        sum += arr[i];
    }
    int best = 0, best1 = 0;
    if (sum % n == 0) best = sum / n;
    else {
        if (sum >= 0) {
            best = sum / n;
            best1 = sum / n + 1;
        } else {
             best = sum / n;
             best1 = sum / n - 1;
        }
    }
    lli res = 0, res1 = 0;
    for (int i=0; i<n; ++i) {
        res += (arr[i] - best) * (arr[i] - best);
        res1 += (arr[i] - best1) * (arr[i] - best1);
    }
    cout << min(res, res1) << endl;
    //clock_t stop = clock();
    //cout << (double)(stop-start)/CLOCKS_PER_SEC << " (s)" << endl;
    return 0;
}


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

int main(void) {
    char s[16];
    int count = 0;
    scanf("%s",s);
    for(int i = 0; i < strlen(s); i++) {
        if(s[i] == 'x') count++;
    }
    if(count > 7) printf("NO\n");
    else printf("YES\n");
    return 0;
}

Measured memory_bytes: 128
from itertools import combinations
from itertools import permutations


def f(x, lst, rem):
    d = int(1e9+7)
    tpl = ()
    for v in range(len(lst) - rem + 1):
        for t in combinations(lst, v + 1):
            if abs(x - sum(t)) + 10 * v < d:
                d = abs(x - sum(t)) + 10 * v
                tpl = t
    for v in tpl:
        lst.remove(v)
    return d, lst


def main():
    N, A, B, C = map(int, input().split())
    L = [int(input()) for i in range(N)]

    ans = int(1e9+7)
    for ABC in permutations((A, B, C), 3):
        lst = L[:]
        accum = 0
        for i, v in enumerate(ABC):
            d, lst = f(v, lst, 3 - i)
            accum += d
        ans = min(ans, accum)
    print(ans)


main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>
#include <map>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 20000;
int v[1 + nmax];

/*
a1 < a2 < .... < an
b1 > b2 > .... > bn
I can increase all sums except one
ap1 + bp1 < ap2 + bp2 < ... apn + bpn
*/
int a[1 + nmax], b[1 + nmax];
int suma[1 + nmax], sumb[1 + nmax];

int main() {
  int n;
  std::cin >> n;
  for(int i = 1;i <= n; i++)
    std::cin >> v[i];
  for(int i = 1; i <= n; i++) {
    suma[v[i] + 1] += (n - i + 1);
    sumb[v[i] - 1] += (n - i + 1);
  }
  for(int i = 1;i <= n; i++)
    suma[i] += suma[i - 1];
  for(int i = n; 1 <= i; i--)
    sumb[i] += sumb[i + 1];
  for(int i = 1;i <= n; i++)
    std::cout << i + suma[i] << " ";
  std::cout << '\n';
  for(int i = 1;i <= n; i++)
    std::cout << n - i + 1 + sumb[i] << " ";
  std::cout << '\n';
  return 0;
}


Measured memory_bytes: 3836
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<functional>
#include<stack>
#include<list>
#include<set>
#include<deque>
#include<climits>
using namespace std;

typedef long long ll;

int Count(int n)
{
	int cnt = 0;
	int i = 1;
	for (; i*i < n; i++)
	{
		if (n % i == 0) cnt++;
	}
	cnt *= 2;
	if (n % (i*i) == 0) cnt++;
	return cnt;
}

int main(){
	int N;
	cin >> N;
	for (int i = 1;; i++)
	{
		if(Count(i) == N)
		{
			printf("%d\n", i);
			return 0;
		}
	}
	return 0;
}

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

struct StronglyConnectedComponents
{
	int V;
	const vector<vector<int>> &g;
	int num_of_comp;
	vector<int> comp;
	vector<vector<int>> dag;
	vector<vector<int>> group_set;

	vector<vector<int>> rg;
	vector<int> order;
	vector<bool> used;

	StronglyConnectedComponents(const vector<vector<int>> &g) : V(g.size()), g(g) {}

	void calc() {
		num_of_comp = 0;
		comp.assign(V, -1);
		used.assign(V, false);
		order.reserve(V);
		rg.resize(V);
		for (int i = 0; i < V; i++) {
			for (int e : g[i]) {
				rg[e].push_back(i);
			}
		}
		for (int i = 0; i < V; i++) {
			if (!used[i]) dfs1(i);
		}
		for (int i = V-1; i >= 0; i--) {
			const int v = order[i];
			if (comp[v] == -1) {
				dfs2(v);
				num_of_comp++;
			}
		}
		dag.resize(num_of_comp);
		group_set.resize(num_of_comp);
		for (int i = 0; i < V; i++) group_set[comp[i]].push_back(i);
		for (int i = 0; i < V; i++) {
			for (int e : g[i]) {
				const int x = comp[i], y = comp[e];
				if (x != y) dag[x].push_back(y);
			}
		}

	}

	void dfs1(int v) {
		used[v] = true;
		for (int nv : g[v]) {
			if (used[nv]) continue;
			dfs1(nv);
		}
		order.push_back(v);
	}

	void dfs2(int v) {
		comp[v] = num_of_comp;
		for (int nv : rg[v]) {
			if (comp[nv] != -1) continue;
			dfs2(nv);
		}
	}
};

struct TwoSAT
{
	int n;
	bool ok;
	vector<bool> ans;

	vector<vector<int>> g;

	TwoSAT(int n) : n(n), g(2*n) {}

	void add_clause(int i, bool bool_i, int j, bool bool_j) {
		g[2*i + !bool_i].push_back(2*j + bool_j);
		g[2*j + !bool_j].push_back(2*i + bool_i);
	}

	void add_clause_not(int i, bool bool_i, int j, bool bool_j) {
		g[2*i + bool_i].push_back(2*j + !bool_j);
		g[2*j + bool_j].push_back(2*i + !bool_i);
	}

	void calc() {
		StronglyConnectedComponents scc(g);
		scc.calc();
		ok = false;
		for (int i = 0; i < n; i++) {
			if (scc.comp[2*i] == scc.comp[2*i + 1]) return;
		}
		ok = true;
		ans.resize(n);
		for (int i = 0; i < n; i++) {
			ans[i] = scc.comp[2*i] < scc.comp[2*i + 1];
		}
	}
};

int main() {
	int n, d;
	cin >> n >> d;
	vector<int> x(n), y(n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &x[i], &y[i]);
	}
	TwoSAT sat(n);
	for(int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			if (abs(x[i]-x[j]) < d) sat.add_clause_not(i, 0, j, 0);
			if (abs(x[i]-y[j]) < d) sat.add_clause_not(i, 0, j, 1);
			if (abs(y[i]-x[j]) < d) sat.add_clause_not(i, 1, j, 0);
			if (abs(y[i]-y[j]) < d) sat.add_clause_not(i, 1, j, 1);
		}
	}
	sat.calc();
	if (sat.ok) {
		cout << "Yes" << endl;
		for (int i = 0; i < n; i++) {
			if (sat.ans[i]) cout << y[i] << '\n';
			else cout << x[i] << '\n';
		}
	} else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a[10010];
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	 }
	 int sum=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			sum+=(a[i]*a[j]);
		
		}
	 } 
	 cout<<sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)
 
#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
 
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert
 
using namespace std;
 
//-------------------------------------------------
//--Range Set Counter
//-------------------------------------------------
template<typename T>
class RangeSet
{
private:
    ::std::vector<int> v;
    ::std::unordered_map<T, int> Map;
    ::std::vector<::std::vector<int> > data;
    int kind;
public:
    RangeSet(const ::std::vector<T> &v_):v(v_.size()){
        int sz = v_.size(); kind = 0;
        for(int i=0;i<sz;i++){
            T t = v_[i];
            if (Map.count(t)){
                data[Map[t]].push_back(i);
            }else{
                Map[t] = kind++;
                data.push_back(::std::vector<int>());
                data.back().push_back(i);
            }
            v[i] = Map[t];
        }
    }
    //query for all elements
    int query(T x){
        if (!Map.count(x)) return 0;
        return data[Map[x]].size();
    }
    //query for [a, b]
    int query(int a, int b, T x){
        if (a>b) return 0;
        if (!Map.count(x)) return 0;
        int xi = Map[x];
        auto right = ::std::upper_bound(data[xi].begin(),data[xi].end(),b);
        auto left  = ::std::lower_bound(data[xi].begin(),data[xi].end(),a);
        return right-left;
    }
    //search x for [k, tail]
    int find(int k, T x){
        if (!Map.count(x)) return -1;
        int xi = Map[x];
        auto itr = ::std::lower_bound(data[xi].begin(),data[xi].end(),k);
        if (itr!=data[xi].end()){
            return *itr;
        }else{
            return -1;
        }
    }
    //update for one point
    void update(int k, T x){
        int ei = v[k];
        auto eitr = ::std::lower_bound(data[ei].begin(),data[ei].end(),k);
        data[ei].erase(eitr);
        v[k] = Map[x];
        if (Map.count(x)){
            int xi = Map[x];
            auto itr = ::std::lower_bound(data[xi].begin(),data[xi].end(),k);
            data[xi].insert(itr, k);
        }else{
            Map[x] = kind++;
            data.push_back(::std::vector<int>());
            data.back().push_back(k);
        }
    }
};
 
//-------------------------------------------------
 
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    ll m; cin>>m;
    vll a(n);
    rep(i,n) cin>>a[i];
    rep(i,n) a[i]=a[i]%m;
    vll sum(n+1);
    rep(i,n) sum[i+1]=(sum[i]+a[i])%m;
    RangeSet<ll> rs(sum);
    ll ans=0;
    rep(i,n){
        ans+=rs.query(i+1,n,sum[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11968
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov

const ll mod=1e9+7;

int main(){
    ll n;
    cin >> n;
    vll t(n);
    rep(i, n) cin >> t[i];
    vll a(n);
    rep(i, n) cin >> a[i];
    ll count=1;
    rep(i,n){
        if(i==0){
            if(a[0]!=a[1]&&a[0]!=t[0]){
                cout << 0 << endl;
                return 0;
            }
        }if(i==n-1){
            if(t[n-2]!=t[n-1]&&a[n-1]!=t[n-1]){
                cout << 0 << endl;
                return 0;
            }
        }else{
            if(t[i-1]!=t[i]&&a[i]!=a[i+1]){
                if(t[i]!=a[i]){
                    cout << 0 << endl;
                    return 0;
                }
            }else if(t[i-1]==t[i]&&a[i]==a[i+1]){
                count*=min(t[i],a[i]);
                count%=mod;
            }else if(t[i-1]==t[i]){
                if(a[i]>t[i-1]){
                    cout << 0 << endl;
                    return 0;
                }
            }else{
                if(t[i]>a[i+1]){
                    cout << 0 << endl;
                    return 0;
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

const int N = 105;

int n,a[N];

int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	n=read(); rep(i,1,n) a[i]=read(); a[0]=-1;
	int now=1,ans=0;
	rep(i,2,n) {
		if (a[i]!=a[i-1]) {
			ans+=(now>>1);
			now=1; 
		}
		else now++;
	}
	ans+=(now>>1);
	
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 256