akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
using namespace std;

int main() {
    long long X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<long long>A(X), B(Y), C(Z);
    for (int i = 0; i < X; i++)cin >> A[i];
    for (int i = 0; i < Y; i++)cin >> B[i];
    for (int i = 0; i < Z; i++)cin >> C[i];

    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    sort(B.begin(), B.end());
    reverse(B.begin(), B.end());
    sort(C.begin(), C.end());
    reverse(C.begin(), C.end());

    vector<long long>ans;
    for (int i = 0; i < X; i++) {
        for (int j = 0; j < Y; j++) {
            for (int k = 0; k < Z; k++) {
                if((i+1)*(j+1)*(k+1)<=K)ans.push_back(A[i] + B[j] + C[k]);
                else break;
            }
        }
    }

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

    for (int i = 0; i < K; i++) {
        cout << ans[i] << endl;
    }

    return 0;

}

Measured memory_bytes: 1404
#include<iostream>
using namespace std;
long gcd(long a,long b){return b?gcd(b,a%b):a;}
long n,m;
string s,t;
main()
{
	cin>>n>>m>>s>>t;
	long U=gcd(n,m);
	for(int j=0;j<U;j++)
	{
		if(s[n/U*j]!=t[m/U*j])
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<n*m/U<<endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

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

int p[510][510];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,q;
    cin>>n>>m>>q;
    for(int i = 1; i <=m; i++)
    {
        int l,r;
        cin>>l>>r;
        p[l][r]++;
    }
    for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) p[i][j]+=p[i][j-1];
    for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) p[i][j]+=p[i-1][j];

    for(int i = 1; i <= q; i++)
    {
        int l,r;cin>>l>>r;
        cout<<p[r][r]+p[l-1][l-1]-p[l-1][r]-p[r][l-1]<<endl;
    }
    
}

Measured memory_bytes: 1920
#include<iostream>
using namespace std ;
int main () {
  
  int N ;
  cin >> N ;
  int b[N] ;
  for(int i =1 ; i < N ;i++)
    cin >> b[i] ;
  
  
  int sum = b[1] ;
  for(int i =1 ; i < N - 1;i++)
    sum+=min(b[i],b[i + 1]) ;
  sum+=b[N-1] ;
  
  cout<<sum<<endl;
  
  return 0 ;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

struct Edge {
  const int from, to;
  Edge(int from, int to) : from(from), to(to) {}
};

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
 public:
  FiniteField(int64 x) : x(x) {
    if (x > P || x < 0) { cerr << "Invalied FiniteField!" << endl; exit(1); }
  }
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

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

  int n;
  cin >> n;
  n++;

  vector<vector<Edge>> graph(n);
  for (int i = 1; i < n; i++) {
    int p;
    cin >> p;
    graph[i].emplace_back(i, p);
    graph[p].emplace_back(p, i);
  }

  // cout << "DEBUG 1" << endl;

  using FFTriple = tuple<FiniteField, FiniteField, FiniteField>;
  function<deque<FFTriple>(int, int)> dfs_fn =
      [&](int v, int p) -> deque<FFTriple> {
    vector<int> cs;
    for (const auto& e : graph[v]) {
      if (e.to == p) continue;
      cs.push_back(e.to);
    }

    deque<FFTriple> r;
    int max_c = 0;
    for (int c : cs) {
      auto q = dfs_fn(c, v);
      if (q.size() > r.size()) {
        swap(r, q);
      }

      for (int i = 0; i < q.size(); i++) {
        FiniteField r0, r1, r2;
        tie(r0, r1, r2) = r[i];
        FiniteField q0, q1, q2;
        tie(q0, q1, q2) = q[i];
        FiniteField v0 = r0 * q0;
        FiniteField v1 = r0 * q1 + r1 * q0;
        FiniteField v2 = (r0 + r1 + r2) * (q0 + q1 + q2) - v0  - v1;
        r[i] = make_tuple(v0, v1, v2);
      }

      if (max_c < q.size()) {
        max_c = q.size();
      }
    }
    for (int i = 0; i < max_c; i++) {
      FiniteField r0, r1, r2;
      tie(r0, r1, r2) = r[i];
      r[i] = make_tuple(r0 + r2, r1, 0);
    }
    r.push_front(make_tuple(1, 1, 0));
    return r;
  };
  auto q = dfs_fn(0, -1);

  FiniteField ans = 0;
  FiniteField total = 1;
  for (int i = 0; i < n; i++) total *= 2;
  for (const auto& e : q) {
    FiniteField v0, v1, v2;
    tie(v0, v1, v2) = e;
    // cout << "(" << v0.Value() << ", " << v1.Value() << ", " << v2.Value()
    //      << "), ";
    ans += v1 * total / (v0 + v1 + v2);
  }
  cout << ans.Value() << endl;
}

Measured memory_bytes: 195584
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

int N, M;
vvi r, l, u, d, start;
vvb used, s;

void dfs(P p) {
	start[p.first][p.second] = 1;
	stack<P> st;
	st.push(p);
	while (!st.empty()) {
		P pos = st.top();
		st.pop();
		int y = pos.first;
		int x = pos.second;
		used[y][x] = true;
		if (!used[y - 1][x] && s[y - 1][x]) {
			u[y][x] = 1;
			st.push(mp(y - 1, x));
		}
		if (!used[y + 1][x] && s[y + 1][x]) {
			d[y][x] = 1;
			st.push(mp(y + 1, x));
		}
		if (!used[y][x - 1] && s[y][x - 1]) {
			l[y][x] = 1;
			st.push(mp(y, x - 1));
		}
		if (!used[y][x + 1] && s[y][x + 1]) {
			r[y][x] = 1;
			st.push(mp(y, x + 1));
		}
	}
}

int main() {
	int Q;
	cin >> N >> M >> Q;
	N += 2;
	M += 2;
	s = vvb(N);
	rep(i, N) {
		s[i] = vb(M);
	}
	rep(i, N - 2) {
		string str;
		cin >> str;
		rep(j, M - 2) {
			s[i + 1][j + 1] = (str[j] == '1');
		}
	}

	r = vvi(N);
	l = vvi(N);
	u = vvi(N);
	d = vvi(N);
	start = vvi(N);
	used = vvb(N);
	rep(i, N) {
		r[i] = vi(M, 0);
		l[i] = vi(M, 0);
		u[i] = vi(M, 0);
		d[i] = vi(M, 0);
		start[i] = vi(M, 0);
		used[i] = vb(M, false);
	}
	rep(i, N) {
		rep(j, M) {
			if (s[i][j] && !used[i][j]) {
				dfs(mp(i, j));
			}
		}
	}

	rep(i, N) {
		repl(j, 1, M) {
			u[i][j] += u[i][j - 1];
			d[i][j] += d[i][j - 1];
			start[i][j] += start[i][j - 1];
		}
	}
	rep(j, M) {
		repl(i, 1, N) {
			r[i][j] += r[i - 1][j];
			l[i][j] += l[i - 1][j];
			start[i][j] += start[i - 1][j];
		}
	}

	rep(q, Q) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		int ans = 0;
		ans += d[x1 - 1][y2] - d[x1 - 1][y1 - 1];
		ans += u[x2 + 1][y2] - u[x2 + 1][y1 - 1];
		ans += r[x2][y1 - 1] - r[x1 - 1][y1 - 1];
		ans += l[x2][y2 + 1] - l[x1 - 1][y2 + 1];
		ans += start[x2][y2] - start[x1 - 1][y2] - start[x2][y1 - 1] + start[x1 - 1][y1 - 1];
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 82852
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int H, A;
    cin >> H >> A;
    if(H%A == 0) cout << H/A << endl;
    else cout << H/A + 1 << endl;
}

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define VEC vector

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				Vint;
typedef vector<Vint>			VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		400010

const ll LINF = (ll)9e18+7;		//
const int INF = 100100100;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//

// int DP[MAX];

//
int main(){
	int N;cin>>N;
	Vint D(N);
	REP(i,N)cin>>D[i];

	ll ans = 0;
	REP(i,N-1)REPS(j,i+1,N){
		if(i==j)continue;
		ans += D[i]*D[j];
	}

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 256
N, M = map(int, input().split())
A = []
K = []
for i in range(N):
	k, *A_i = map(int, input().split())
	K.append(k)
	A.append(A_i)
cnt = 0
for i in range(M):
	flg = 0
	for j in range(N):
		if not i + 1 in A[j]:
			flg = 1
	if flg == 1:
		continue
	cnt += 1
print(cnt)
		

Measured memory_bytes: 3060
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme cout<<"IMPOSSIBLE"<<endl;return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
//19234567892927;
const int mod=1e9+7;
const llint big=1e13+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}

//aKIHa BaRa
int main(void){
	string str;cin>>str;
	vector<string>a={"KIH","AKIH","KIHA","AKIHA"};
	vector<string>b={"BR","BAR","BRA","BARA"};
	for(auto sa:a){
		for(auto sb:b){
			if(sa+sb==str){cout<<"YES"<<endl;return 0;}
		}
	}cout<<"NO"<<endl;
	return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int n;
int l[2005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	cin >> n;
	rep(i, 0, n) cin >> l[i];
	ll ans = 0;
	sort(l, l + n);
	rep(i, 0, n) rep(j, 0, n) if (i != j) {
		int p1 = upper_bound(l, l + n, max(l[i], l[j]) - min(l[i], l[j])) - l;
		int p2 = lower_bound(l, l + n, l[i] + l[j]) - l;
		// valid range: [p1, p2)
		ans += p2 - p1;
		if (p1 <= i && i < p2) ans--;
		if (p1 <= j && j < p2) ans--;
		//rep(k, p1, p2) if (k != i && k != j) {
		//	printf("%d %d %d\n", l[i], l[j], l[k]);
		//}
	}
	cout << (ans / 6) << endl;
}


Measured memory_bytes: 256
import math
def RA():
    l = input().split()
    return [int(i) for i in l]
 
[n, m] = RA()
votes = RA()
 
s = [0] * 1001
for v in votes:
  s[v] = 1
 
start = math.ceil(sum(votes)/(4 * m))
count = 0
for i in range(start, 1001):
  if s[i] == 1:
    count += 1
    if count == m:
      print("Yes")
      break
if count < m:
  print("No")

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

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

  int max = 0;
  int x = 0;

  for(int i = 0; i < n; i++){
    char c;
    cin >> c;

    if(c == 'I') x++;
    else x--;

    if(max < x) max = x;

  }

  cout << max << endl;

  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n;cin>>n;
    vector<ll>a(n);
    multiset<ll>st;
    rep(i,n){
        cin>>a[i];
        st.insert(a[i]);
    }
    sort(all(a));
    reverse(all(a));
    ll cnt=0;
    rep(i,n){
        if(!st.count(a[i]))continue;
        auto itr=st.lower_bound(a[i]);
        st.erase(itr);
        ll w=1;
        while(w<=a[i])w*=2;
        ll x=w-a[i];
        itr=st.lower_bound(x);
        if(*itr==x){
            cnt++;
            st.erase(itr);
        }
    }
    cout<<cnt<<endl;
}

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

int main()
{
  string s1, s2;
  cin >> s1 >> s2;
  // cout << s2;
  int n = s1.size();

  rep(i,n){
    if(s1.at(i) != s2.at(n-i-1)){
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<algorithm>
using namespace std;
int p[10];
int main()
{
    int a,b,c;
    while(~scanf("%d%d%d",&a,&b,&c))
    {
        printf("%d\n",min(a+b,min(a+c,b+c)));
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double ra = (h * 60 + m) * 0.5;
  double rb = m * 6;
  double th = ra > rb ? ra - rb : rb - ra;
  if (180 < th) th = 360.0 - th;
  th = th * M_PI / 180.0;
  double ans = a * a + b * b - 2 * a * b * cos(th);
  printf("%.20f\n", sqrt(ans));
  return 0;
}

Measured memory_bytes: 4224
n, m, x = map(int, input().split())
ca = [(list(map(int, input().split()))) for _ in range(n)]
caca = [0]*(m+1)
ans = 12 * 10**5 +1
chk = 0
for nn in range(2**n):
    for j in range(m+1):
        caca[j] = 0
    cnt = 0
    for i in range(n):
        if (nn>>i) & 1:
            for j in range(m+1):
                caca[j] += ca[i][j]
    for j in range(1, m+1):
        if caca[j] >= x:
            cnt += 1
        else:
            break
    if cnt == m:
        ans = min(ans, caca[0])
        chk = 1
print(ans if chk == 1 else -1)

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

int main(){
  long long int K,A,B;
  cin>>K>>A>>B;
  if(A+1>=B){
    cout<<K+1<<endl;
  }else{
    if(A>K-1){
      cout<<K+1<<endl;
    }else{
      if((K-A+1)%2==0){
        cout<<A+(B-A)*(K-A+1)/2<<endl;
      }else{
        cout<<A+1+(B-A)*(K-A)/2<<endl;
      }
    }
  }
  
  
  
}

Measured memory_bytes: 256
// B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>

using namespace std;
int main()
{
    int a, b;

    cin >> a >> b;

    cout << a * b - a - b + 1 << endl;

    return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int a, b; cin >> a >> b;

    int t = 1;
    int ans = 0;
    
    while (b > t) {
        t += a - 1;
        ++ans;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
6
)");
#define cin input
#endif

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

    map<int, int> x;

    vector<int> pre(n), post(n);

    vector<int> res;
    res.reserve(n * n);

    REP (i, n)
    {
        int a;
        cin >> a;
        x[a] = i;
        pre[i] = i;
    }

    auto it = x.begin();
    auto itpre = x.begin();
    auto itpost = x.begin();
    REP (i, n * n)
    {
        if (it != x.end() && it->first == i + 1)
        {
            if (pre[it->second])
                break;
            res.push_back(it->second);
            post[it->second] = n - it->second - 1;
            ++it;
        } else
        {
            while (itpre != x.end() && (it == x.end() || itpre != x.end() || itpre->first <= it->first) && pre[itpre->second] == 0)
                ++itpre;
            if (itpre == x.end() || pre[itpre->second] == 0)
            {
                while (itpost != x.end() && post[itpost->second] == 0)
                    ++itpost;
                if (itpost == x.end() || post[itpost->second] == 0)
                    break;
                res.push_back(itpost->second);
                --post[itpost->second];
            } else
            {
                res.push_back(itpre->second);
                --pre[itpre->second];
            }
        }
    }

	if (res.size() == n * n)
	{
		cout << "Yes" << endl;
        REP (i, n * n - 1)
            cout << (res[i] + 1) << ' ';
        cout << (res[n * n - 1] + 1) << endl;
	} else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int n, a[100010];
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(a, a+n);
	int num = a[n-1];
	pair<int, int> mn = { 999999999, 0 };
	int half = (num+1)/2;
	int half2 = half + ((n%2) == 0);
	for (int i = 0; i < n-1; i++)
	{
		mn = min(mn, { abs(a[i]-half), a[i]});
		mn = min(mn, { abs(a[i]-half2), a[i]});
	}
	printf("%d %d\n", num, mn.second);
}

Measured memory_bytes: 640
print([0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][int(input())])

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
  int l, k;
  cin >> l >> k;
  vector<vector<long long>> dp(l + 1, vector<long long>(l + 1, 0));
  dp[0][0] = 1;
  for (int i = 0; i < l; i++){
    for (int j = 0; j < l; j++){
      if (i % 2 == 0){
        if (j + k <= l){
          dp[i + 1][j + k] += dp[i][j];
        }
      }
      dp[i + 1][j + 1] += dp[i][j];
    }
  }
  long long ans = 0;
  for (int i = 1; i <= l; i += 2){
    for (int j = 0; j <= l; j++){
      ans += dp[i][j];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3244
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int h, w;
string s[100];
bool u[100][100];

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

bool valid(int x, int y){
    return x >= 0 && x < h && y >= 0 && y < w;
}

bool go(int x, int y){
    int cnt = 0;
    for(int i = 0; i < 4; ++i){
        int nx = dx[i] + x;
        int ny = dy[i] + y;
        if(valid(nx, ny) && s[nx][ny] == '#' && !u[nx][ny]){
            cnt++;
        }
    }
    return cnt > 0;
}

string solve(){
    cin >> h >> w;
    for(int i = 0; i < h; ++i){
        cin >> s[i];
    }
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(s[i][j] == '#' && !u[i][j] && !go(i, j)) return "No";
        }
    }
    return "Yes";
}

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

    cout << solve() << "\n";
    
    return 0;
}

Measured memory_bytes: 256
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n,k=NM()
l=L()
l.sort()
print(sum(l[:k]))

Measured memory_bytes: 9244
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007 
typedef long long ll;

int main(void)
{
	ios_base::sync_with_stdio(false);    
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll n;
	cin>>n;
	set<string> s;
	string str;
	while(n--)
	{
		cin>>str;
		s.insert(str);
	}
	cout<<s.size()<<"\n";
	
	return 0;
}

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

#define MOD 1000000007

int dp[3000][3000] = {};

void add(int &a, int b) {
    a = (a + b) % MOD;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    string s;
    cin >> n >> s;

    for (int j=0; j<n; j++)
        dp[0][j] = 1;
    for (int i=1; i<n; i++)
        for (int j=0; j<=i; j++) {
            if (s[i-1] == '<')
                add(dp[i][j], j > 0 ? dp[i-1][j-1] : 0);
            else
                add(dp[i][j], (dp[i-1][i-1] - (j > 0 ? dp[i-1][j-1] : 0) + MOD) % MOD);
            if (j > 0)
                add(dp[i][j], dp[i][j-1]);
        }

    cout << dp[n-1][n-1] << "\n";

    return 0;
}


Measured memory_bytes: 34176
#include <bits/stdc++.h>
using namespace std;
 
int main(void) {
  int N,X,T,a,t;
  cin >> N >> X >> T >> a >> t;
  if ( N % X == 0){
  a = N / X;
  t = T*( a );}
  else{ a = N / X;
  t = T*( a + 1);}
  cout << t << endl;
  
  return 0;
}

Measured memory_bytes: 3620
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] arg) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt()*2;
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int ans1 = C*Math.max(X,Y);
		int ans2 = C*Math.min(X,Y);
		if(X<Y) {
			ans2 += Math.abs(Y-X)*B;
		} else {
			ans2 += Math.abs(Y-X)*A;
		}
		int ans3= A*X+B*Y;
		System.out.println(Math.min(ans1,Math.min(ans2, ans3)));
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
int main(){
    int n; cin >> n;
    long long ans = 0;
    map<string, int> mp;
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    for(auto& it:mp){
        ans += (long long)it.second*(it.second-1)/2;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int l, r, d, n, count=0;
    cin >> l >> r >> d;
    n = d;
    while (l > d) {
        d += n;
    }
    while (r >= d) {
        
        count++;
        d += n;
    }

    cout << count << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, c;
  in3(a, b, c);
  if(a + b == c || b + c == a || c + a == b)
    out("Yes");
  else
    out("No");
  memi;
}

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

int main(){
    int r,D,x;
    cin >> r >> D >> x;
    
    int res = x;
    for (int i = 1; i <= 10; i++) {
        int X;
        X = r*res - D;
        cout << X << endl;
        res = X;
    }
}


Measured memory_bytes: 256
#!/usr/bin/env python3

# input
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

# calc
d = {}
for i in s:
    if i in d.keys():
        d[i] += 1
    else:
        d[i] = 1 

for i in t:
    if i in d.keys():
        d[i] -= 1
    else:
        d[i] = -1

a = list(d.values())
a.append(0)
print(max(a))


Measured memory_bytes: 3064
//
//  main.cpp
//  A
//
//  Created by Hashizo on 2020/01/11.
//  Copyright © 2020 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
int main(int argc, const char * argv[]) {
	ll ans = 0;

	
	ll n;
	cin >> n;

	vector<string> s(n);
	vector<ll> t(n);

	REP(i, n) {
		cin >> s[i] >> t[i];
	}

	string x;
	cin >> x;
	
	bool flag = false;
	REP(i, n) {
		if(!flag) {
			if (x == s[i]) {
				flag = true;
			}
		}
		else {
			ans += t[i];
		}
		
	}
	
	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef unsigned long long ull;

const int MOD = 1e9 + 7;
const int LOG = 61;

int main() {
   ios_base :: sync_with_stdio(0);
   cin.tie(0) , cout.tie(0);
   int n;
   cin >> n;
   vector<ull> a(n + 1 , 0LL);
   vector<vector<int> > dp(LOG , vector<int>(2 , 0));
   for (int i = 1; i <= n; i++) {
      cin >> a[i];
      for (int j = 0; j < LOG; j++) {
         ull st = 1LL << j;
         bool bit = a[i] & st;
         dp[j][bit]++;
      }
   }
   long long ans = 0LL;
   for (int i = 0; i < LOG; i++) {
      long long st = (1LL << i);
      ans += (((dp[i][0] * 1LL * dp[i][1]) % MOD) * (st % MOD));
      ans %= MOD;
   }
   cout << ans << '\n';
   return 0;
}


Measured memory_bytes: 2560
n = int(input())
a = list(map(int, input().split()))
a = [0] + a

c = [0] * (n+1)

for i in range(n, 0, -1):
    c[i] = a[i]
    tmp = i * 2
    while tmp <= n:
        c[i] -= c[tmp]
        tmp += i
    c[i] = c[i] % 2

print(sum(c))
for i in range(1, n+1):
    if c[i] == 1:
        print(i)

Measured memory_bytes: 70108
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, string> P;
typedef tuple<int, string, string> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m;

int solve() {
    return n * (n-1) / 2 + m * (m-1) / 2;
}

void input() {
    cin >> n >> m;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 3168
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		sc.close();
		int max = 0;
		for (int i = 1; i <= 1000; ++i) {
			if (i != 1) {
				for (int j = 2; j <= 10; ++j) {
					int tmp = (int) Math.pow(i, j);
					if (tmp <= x)
						max = Math.max(max, tmp);
					else
						break;
				}
			} else {
				if (i <= x)
					max = Math.max(max, i);
			}
		}
		System.out.println(max);
	}

}


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


int main() {
int N,M;
cin >>N >>M;
vector<int> A(N);
for(int i=0;i<N;i++) cin >>A[i];
int64_t sum =0;
for(int i=0;i<N;i++) sum += A[i];
sort(A.begin(),A.end());
reverse(A.begin(),A.end());
  double q = 4 * M;
  double p = sum / q;
  bool f = true;
for(int i=0;i<M;i++){
 if(A[i] < p) f= false ; 
}
  if(f) cout <<"Yes" <<endl;
  else cout <<"No" <<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
 
int main(){
 
  int i,j,n,tmp,count=0,a[N];
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
 
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(a[j]<a[j-1]){
    tmp=a[j-1];
    a[j-1]=a[j];
    a[j]=tmp;
    count++;
      }
    }
  }
  printf("%d",a[0]);
 
  for(i=1;i<n;i++){
 
    printf(" %d",a[i]);
  }
  printf("\n%d\n",count);
 
  return 0;
}

Measured memory_bytes: 600
n,m = map(int,input().split(" "))
a = list(map(int,input().split(" ")))

sum = sum(a)
border = sum/(4*m)

#print(border)
ans = len(list(filter(lambda x:x>=border,a)))
#print(ans)
if m <= ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>  
using namespace std;
 
#define mod 1e9+7
 
typedef long long ll;
 
int ans=INT_MAX;
bool visited=false;

 
int main()
{
    string s="";
    cin>>s;

    if(s.size()%2){
    	cout<<"No";
    	return 0;
    }

    for(int i=0;i<s.size();i+=2){
    	if(s[i]!='h' || s[i+1]!='i')
    	{
    		cout<<"No";
    		return 0;
    	}
    }

	cout<<"Yes";

    return 0;
}
     

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace ALDS1_2_D {
    class Problem {
        private List<int> _nums, _intervalList;
        private int _len, _cnt;

        public Problem(List<int> nums, int len) {
            _nums = nums;
            _len = len;
        }

        public void Run() {
            ShellSort();

            StringBuilder sb = new StringBuilder();
            sb.AppendLine(_intervalList.Count.ToString());
            sb.AppendLine(ListToString(_intervalList));
            sb.AppendLine(_cnt.ToString());
            _nums.ForEach(n => sb.AppendLine(n.ToString()));
            Console.Write(sb);
        }

        private void ShellSort() {
            _cnt = 0;
            _intervalList = new List<int>();
            for (int h = 1; h <= _len; h = 3 * h + 1) {
                _intervalList.Insert(0, h);
            }
            _intervalList.ForEach(n => InsertionSort(n));
        }

        private void InsertionSort(int g) {
            for (int i = g; i < _len; i++) {
                int v = _nums[i];
                int j = i - g;
                while (j >= 0 && _nums[j] > v) {
                    _nums[j + g] = _nums[j];
                    j -= g;
                    _cnt++;
                }
                _nums[j + g] = v;
            }
        }

        private string ListToString(List<int> list) {
            StringBuilder sb = new StringBuilder();
            list.ForEach(n => sb.AppendFormat(" {0}", n));
            return sb.ToString().TrimStart();
        }
    }

    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            List<int> A = new List<int>();
            for(int i = 0; i < n; i++) {
                A.Add(int.Parse(Console.ReadLine()));
            }

            Problem p = new Problem(A, n);
            p.Run();
        }
    }
}

Measured memory_bytes: 89128
n,ma,mb = map(int, input().split())
abcl = []
for _ in range(n):
    a,b,c = map(int, input().split())
    abcl.append((a,b,c))

dp = [ [ [10**9]*401  for _ in range(401) ] for _ in range(n+1) ]
dp[0][0][0] = 0
for i in range(n):
    ai,bi,ci = abcl[i]
    for a in range(401):
        for b in range(401):
            dp[i+1][a][b] = min(dp[i][a][b], dp[i+1][a][b])
            if a+ai < 401 and b+bi < 401:
                dp[i+1][a+ai][b+bi] = min(dp[i][a][b] + ci, dp[i+1][a+ai][b+bi])


ans = 10**9
dp_row = dp[n]
for a in range(1,401):
    for b in range(1,401):
        if ma*b == mb*a:
            v = dp[n][a][b]
            ans = min(ans,v)

if ans == 10**9: ans = -1
print(ans)

Measured memory_bytes: 127540
#include <bits/stdc++.h>
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int main() {
	lnt x; read(x);
	lnt t = x/11*2;
	if (x%11 >= 1 && x%11 <= 6) t++;
	else if (x%11 > 6) t += 2;
	return printf("%lld\n", t), 0;
}


Measured memory_bytes: 256
/*input
20
*/
#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;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=1e4;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int cnt[maxn+5];
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n;
    cin>>n;
    for(int x=1;x<=10000;x++){
        for(int y=1;y<=10000;y++){
            if(x*x+y*y+x*y>maxn) break;
            for(int z=1;z<=10000;z++){
                if(x*x+y*y+z*z+x*y+x*z+y*z>maxn) break;
                cnt[x*x+y*y+z*z+x*y+x*z+y*z]++;
            }
        }
    }
    REP1(i,n) cout<<cnt[i]<<'\n';
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main{
	static long MOD = 1000000007;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long m = scan.nextInt();
		long n = scan.nextInt();
		scan.close();
		long ans = modPow(m, n);
		System.out.println(ans);
	}
	static long modPow(long x, long n) {
		long res = 1;
		while(n > 0) {
			if(n % 2 == 1) {
				res = res * x % MOD;
			}
			x = x * x % MOD;
			n = n / 2;
		}
		return res;
	}
}


Measured memory_bytes: 26308
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var a0 = int.Parse(Console.ReadLine().Trim());
        if (a0 != 0) { Console.WriteLine(-1); goto end; }
        var p = 0; var ret = 0L; var pre = 0;
        for (int i = 1; i < n; i++)
        {
            var aw = int.Parse(Console.ReadLine().Trim());
            var w = aw - pre;
            if (w >= 2) { Console.WriteLine(-1); goto end; }
            if (w <= 0) {  ret += i - 1 - p; p = i - aw;  }
            pre = aw;
        }
        ret += n - 1 - p;
        Console.WriteLine(ret);
    end:;
    }
}


Measured memory_bytes: 17360
/*
     * yaswanth phani kommineni
     */
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

void solve(){
  ll n,m;
  cin >> n >> m;
  cout << n*m << endl;
}

int main(){
  //freopen("input.txt","r",stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll z;
  //cin >> t;	 
  z=1;
  while(z--){
    solve();
  }
  return 0;
}

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

int main(){

  int N;
  long long ans=0,num=1;
  cin >> N;
  string S[N],T;
  For(i, N){
    cin >> T;
    sort(T.begin(),T.end());
    S[i] = T;
  }

  sort(S, S+N);
  For(i, N){
    int j=i+1;
    while(S[i]==S[j]){
      num++;
      j++;
    }
    if(num>1) ans += num*(num-1)/2;
    i=j-1;
    num=1;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5760
g1=[1,3,5,7,8,10,12]
g2=[4,6,9,11]
g3=[2]

x,y=map(int,input().split())

if x in g1 and y in g1:
    print("Yes")
else:

    if x in g2 and y in g2:
      print("Yes")
    else:
      print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> lP;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    int n;
    cin>>n;
    vector<ll> a;
    rep(i,n){
        int b;
        cin>>b;
        a.push_back(b);
    }

    vector<ll> s(n+1);
    s[0]=0;
    rep1(i,n){
        s[i]=s[i-1]+a[i-1];
        s[i]%=mod;
    }

    ll ans=0;
    rep(i,n-1){
        int v=s[n]-s[i+1];
        if(s[n]-s[i+1]<0){
            v+=mod;
        }
        ans+=a[i]*v;
        ans%=mod;
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 6300
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int main(void) {

    int i, j, k;
    long long n, m;
    long long sum = 0;
    long long temp;
    vector<long long> a;

    cin >> n >> m;

    for (i = 0; i < m; i++) {
        cin >> temp;
        sum += temp;
    }

    if (n < sum) {
        cout << -1 << endl;
    }else {
        cout << n - sum << endl;
    }

    return 0;    
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush=
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var N = cin.ReadInt;
			var M = cin.ReadInt;
			var candids = new List<int>[N];
			for(int i = 0; i<N; i++) {
				candids[i]=new List<int>();
			}
			var H = cin.ReadIntArray(N);
			for(int j = 0; j<M; j++) {
				var rd = cin.ReadIntArray(2);
				candids[rd[0]-1].Add(rd[1]-1);
				candids[rd[1]-1].Add(rd[0]-1);
			}
			var good = new bool[N];
			for(int i = 0; i<N; i++) {
				good[i]=!candids[i].Any()||candids[i].Max(k => H[k])<H[i];
			}
			Console.WriteLine(good.Count(b=>b));
		}
	}
	static class ExtendClass {
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator=separator;
			this._stream=stream;
			inputStream=new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count!=0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i<tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i<N; ++i)
				ret[i]=Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i<N; ++i) ret[i]=ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i<N; ++i) ret[i]=ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i<N; ++i) ret[i]=ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek()==-1; }
		}
	}
}

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

const int MAXN = 50005;

int W, N;
int x[MAXN];
bool dp[MAXN];

bool test(int w) {
  int a, b;
  int sumA, numA, sumB, numB;
  fill(dp, dp+MAXN, false);
  dp[0] = true;
  a = b = 0;
  sumA = numA = sumB = numB = 0;

  for(int i = 0; i < N; ++i) {
    for(; a < N && W-sumA > w*(numA-1); ++numA, sumA += x[a++]);
    for(; b < N && W-sumB >= (numB-1); ++numB, sumB += x[b++]);
    if(!(W-sumB >= (numB-1))) {
      sumB -= x[--b]; --numB;
    }

    if(dp[i]) {
      for(int j = a; j <= b; ++j) {
        dp[j] = true;
      }
      a = b;
      sumA = sumB;
      numA = numB;
    }

    sumA -= x[i];
    sumB -= x[i];
    numA -= 1;
    numB -= 1;
  }
  return dp[N];
}

int main() {
  while(cin >> W >> N && (W|N)) {
    for(int i = 0; i < N; ++i) cin >> x[i];
    int l, r;
    l = 1;
    r = W+1;
    while(r-l) {
      int m = (l+r)/2;
      if(test(m)) {
        r = m;
      } else {
        l = m+1;
      }
    }
    cout << l << endl;
  }
  return 0;
}

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

int main()
{
    string s;
    cin >> s;
    vector<int> line(26, 0);
    for (int i = 0; i < s.size(); i++)
    {
        int num = s.at(i) - 'a';
        line.at(num)++;
        if (line.at(num) == 2)
        {
            puts("no");
            return 0;
        }
    }
    puts("yes");
}

Measured memory_bytes: 3636
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
origin_len = 0
for i in range(n+1):
    origin_len += abs(a[i] - a[i+1])

for i in range(n):
    if a[i] <= a[i+1] <= a[i+2] or a[i+2] <= a[i+1] <= a[i]:
        print(origin_len)
    else:
        len_a = abs(a[i+1] - a[i])
        len_b = abs(a[i+1] - a[i+2])

        print(origin_len - 2 * min(len_a, len_b))

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

using namespace std;

int main()
{
    int N, M, A, B;
    cin >> N >> M >> A >> B;
    vector<int> D(N);
    for (int i = 0; i < N; i++) {
        cin >> D[i];
    }
    
    int cnt = 0;
    vector<int> p;
    for (int i = 0; i < N; i++) {
        if (D[i] >= A) {
            if (D[i] <= B) cnt++;
            p.emplace_back(D[i]);
        } else {
            break;
        }
    }
    
    int n = p.size(), res = n;
    if (N - n < M) {
        for (int i = n - 1; i >= 0 && cnt > 0; i--) {
            if (p[i] <= B) {
                res--;
                cnt--;
            } else {
                break;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3160
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    string S;
    bool ok=true;

    cin >> S;

    rep(i,S.size()) {
        if(i%2==0) {
            if(S[i]=='L') {
                ok = false;
            }
        } else {
           if(S[i]=='R') {
                ok = false;
            } 
        }
    }

    if(ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=1e6+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a) memset(a,0,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first 
#define se second
int main(){
	int n;
	scanf("%d",&n);
	ll ans=1LL*n*(n+1)*(n+2)/6;
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		if(u>v) swap(u,v);
		ans-=1LL*u*(n-v+1); 
	}
	printf("%lld\n",ans); 
	return 0;
}


Measured memory_bytes: 3828