akhauriyash/Code-Regression huggingface dataset:
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <set>
using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
typedef long long LL;

string s;
int main() {
	cin >> s;
	int count = 0;
	REP(i, 0, s.size()) {
		if (s[i] == 'g') {
			++count;
		} else {
			--count;
		}
	}
	cout << count / 2 << endl;
	return 0;
}

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

int main(){
    int n,k;
    cin>>n>>k;
    int h[n];
    int ans=0;
    rep(i, n){
        cin>>h[i];
        if(h[i]>=k) ans++;
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 4028
import sys
input=sys.stdin.buffer.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
A,B,C,D = map(int,input().split())
e = (C-1) // B +1
f = (A-1) // D +1
if e <= f:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9228
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();
  
function main(){
  var read = 0;
  var resultCase = 1;
  while(true){
    var maxWeight = +input[read++];
    if(!maxWeight){
      break;
    }
      
    var treasures = +input[read++];
    var dp = [];//new Int16Array(maxWeight + 1);
    dp.length = maxWeight + 1;
    
    for(var i = treasures; i--;){
      var c = input[read++].split(",");
      var tv = +c[0];
      var tw = +c[1];
  
      for(var w = maxWeight; w - tw >= 0; w--){
        dp[w] = max((dp[w-tw]|0) + tv, (dp[w]|0));
      }
    }
  
    var resultWeight = 1001;
    var resultCost = 0;
    for(var i = 0; i <= maxWeight; i++){
      var dpi = dp[i];
      if(dpi > resultCost){
        resultCost = dpi;
        resultWeight = i;
      }
    }
      
    console.log("Case " + resultCase++ + ":\n" + resultCost + "\n" + resultWeight);
  }
}
 
 
function max(a, b) {
  var t = a - b;
  return a - (t & (t >> 31));
}

Measured memory_bytes: 8628
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int main(){
    int n;cin >> n;
    vector<string> s(n);
    LL ans = 0;
    int a = 0 , b = 0 , c = 0;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        for (int j = 0; j < s[i].length()-1; j++) {
            if(s[i][j]=='A'&&s[i][j+1]=='B') ans++;
        }
        if(s[i][0]=='B'&&s[i][s[i].length()-1]=='A') c++;
        else if(s[i][0]=='B') a++;
        else if(s[i][s[i].length()-1]=='A') b++;
    }
    if(c>=1){
        if(a>=1) a--,ans++;
        if(b>=1) b--,ans++;
        cout << ans + c - 1 + min(a,b) << endl;
    }
    else cout << ans + min(a,b) << endl;
    return 0;
}


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

int main(void){
    ll n, k;
    cin >> n >> k;

    ll h[n];
    ll count = 0;
    rep(i, n){
        cin >> h[i];
        if(h[i] >= k)
            count++;
    }

    cout << count << endl;
    return 0;

}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll a, b;
    cin >> a >> b;
    if(16 - (a + b) >= abs(a - b)){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}


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

int main(void){
    int n;
	int *a;
	cin >> n;

	a = new int[n]; 
	
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 1; i < n; i++){
        cout << a[n - i] << " ";
    }
    cout << a[0] << "\n";
	delete a;
}

Measured memory_bytes: 1200
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(void){
  vector<string> s;
  vector<int> cnt;
  string ss,str;
  getline(cin,str);
  string longest="";
  string max;
  int maxv=-1;
  str+=" ";
  for(int i = 0; i < str.size() ; i ++  ){
    if(str[i] == ' '){
      bool used=true;
      
      for(int j = 0 ; j < s.size() ; j ++){
	//second time
	if(s[j] == ss){
	  cnt[j]++;
	  //cout<<ss<<cnt[j]<<maxv<<endl;
	   
	  if(maxv<cnt[j]){
	    longest=ss;
	    maxv=cnt[j];
	  }
	  
	  ss="";
	  used=false;
	}
      }
      if(used){
	//first time
	s.push_back(ss);
	cnt.push_back(1);
	//cout<<ss<<cnt[cnt.size()-1]<<endl;
	/*
	if(s.size() == 1){
	  longest=ss;
	  max=ss;
	  maxv=ss.size();
	}
	//*/
	if(ss.size()>max.size())max=ss;
	ss="";
      }
      
    }else{
      ss+=str[i];
    }
    // cout<<str[i]<<endl;
  }
  cout<<longest<<" ";
  cout<<max<<endl;
  /*
  for(int i = 0 ; i < s.size() ; i ++){
    cout<<s[i]<<endl;;
  }
  cout<<endl;
  //*/
}

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

using namespace std;
#define int int64_t
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define gsort(x) sort((x).begin(), (x).end(), greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define pii pair<int, int>
#define re(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

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

   int cnt = 0;
   vector<int> x(5), y;

   rep(i, 5)
   {
      cin >> x[i];
   }

   sort(all(x));

   do
   {
      cnt = 0;
      rep(i, 5)
      {
         if (x[i] % 10 == 0)
            cnt += x[i];
         else if (i == 4)
            cnt += x[i];
         else
            cnt += (x[i] + (10 - x[i] % 10));
      }
      y.push_back(cnt);
   } while (next_permutation(all(x)));

   sort(all(y));

   cout << y[0] << '\n';
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  int i,j,k;
  int build[4][3][10]={{{}}};
  cin >> n;
  int b,f,r,v;
  for(i=0;i<n;i++){
    cin >> b >> f >> r >> v;
    build[b-1][f-1][r-1]+=v;
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	cout << " ";
	cout << build[i][j][k];
      }
      cout << endl;
    }
    if(i<3)cout << "####################" << endl;
  }
  return 0;
}


Measured memory_bytes: 3072
#include <stdio.h>
int tri=0,le=0,eq=0,mo=0;//tri for all tris,le for < (pi/2),eq for = (pi/2),mo for > (pi/2)
int judge(int a,int b,int c);
int main() {
	int a,b,c;
	while (scanf("%d%d%d",&a,&b,&c)==3)
	    if (!judge(a,b,c))
	        break;
	printf("%d %d %d %d\n",tri,eq,le,mo);
	return 0;
}
int judge(int a,int b,int c){
	int t;
	if (c>b)
	    t=b,b=c,c=t;
	if (b>a)
	    t=a,a=b,b=t;
	//Now a is the max one
	if (b+c<=a)
	    return 0;
	//a^2=b^2+c^2-2bccosA
	//2bccosA=b^2+c^2-a^2
	tri++;
	t=b*b+c*c-a*a;
	if (t>0){
	    le++;
	}
	else {
	    if (t==0){
	        eq++;
	    }
	    else {
	        mo++;
	    }
	}
	return 1;
}


Measured memory_bytes: 2096
#include <bits/stdc++.h>
#define ll    long long int
#define ld    long double
#define pb    push_back
#define mp    make_pair
#define Maxn  1000007
#define ff    first
#define se    second
using namespace std;
 

int main() {
	ll n;
	cin>>n;
	cout<<(n*n)*3;
}


Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int main() {
    int N;cin >> N;
    vector<P> retu(N);
    for(int i = 0;i<N;i++) cin >> retu.at(i).first,retu.at(i).second = i;
    vector<int> ans(N);
    sort(retu.begin(),retu.end());
    int lesshalf = retu.at(N/2).first;
    int morehalf = retu.at(N/2-1).first;
    for(int i = 0;i<N;i++){
        if(i < N/2){
            ans.at(retu.at(i).second) = lesshalf;
        }
        else{
            ans.at(retu.at(i).second) = morehalf;
        }
    }

    for(int A : ans) cout << A << endl;

}


Measured memory_bytes: 4480
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


N = int(input())

prime = dict()
for i in range(2, N+1):
    prime_i = factorization(i)
    for p, num in prime_i:
        if p in prime:
            prime[p] += num
        else:
            prime[p] = num

divisor_75 = 0
divisor_25 = 0
divisor_15 = 0
divisor_5 = 0
divisor_3 = 0
for v in prime.values():
    if v >= 74:
        divisor_75 += 1
    if v >= 24:
        divisor_25 += 1
    if v >= 14:
        divisor_15 += 1
    if v >= 4:
        divisor_5 += 1
    if v >= 2:
        divisor_3 += 1

ans = 0
ans += divisor_75
ans = max(ans, ans + divisor_25 * (divisor_3 - 1))
ans = max(ans, ans + divisor_15 * (divisor_5 - 1))
ans = max(ans, ans + ((divisor_5 * (divisor_5 - 1)) // 2) * (divisor_3 - 2))

print(ans)

Measured memory_bytes: 9540
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------

signed main() {
	int n = read(), a;
	int ma = -Inf, mi = Inf, sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		ma = max(ma, a);
		mi = min(mi, a);
		sum += a;
	}
	cout << mi << " " << ma << " " << sum << endl;
}


Measured memory_bytes: 3236
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL maxn=1e4;
struct node{
	int p,l,r;
};
node T[maxn];
void preOrder(int n){
     if(n==-1) return;
	 printf(" %d",n);
	 preOrder(T[n].l);
	 preOrder(T[n].r);	
}
void inOrder(int n){
    if(n==-1) return;
    inOrder(T[n].l);
    printf(" %d",n);
    inOrder(T[n].r);
}
void PostOrder(int n){
    if(n==-1) return;
    PostOrder(T[n].l);
    PostOrder(T[n].r);
    printf(" %d",n);
}
int main()
{
    int N, v, l, r, root;
    scanf("%d",&N);
    for(int i = 0; i <= N; i++) T[i].p=-1;
    for(int i = 0; i < N; i++){
        scanf("%d%d%d",&v,&l,&r);
        T[v].l = l, T[v].r = r;
        if(l!=-1) T[l].p = v;
        if(r!=-1) T[r].p = v;
    }
    for(int i = 0; i < N; i++)
        if(T[i].p==-1)//找到根节点 
            root = i;
    printf("Preorder\n");
    preOrder(root);
    printf("\nInorder\n");
    inOrder(root);
    printf("\nPostorder\n");
    PostOrder(root);
    printf("\n");
	return 0;
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	int X[110], Y[110], H[110];
	int pos = -1;  
	for(int i = 0; i < N; i++){
		cin >> X[i] >> Y[i] >> H[i]; 
		if(H[i]) pos = i; 
	}
	for(int i = 0; i <= 100; i++){
		for(int j = 0; j <= 100; j++){
			int height = H[pos] + abs(i - X[pos]) + abs(j - Y[pos]); 
			bool ok = true; 
			for(int k = 0; k < N; k++){
				if(H[k] != max(0, height - abs(i - X[k]) - abs(j - Y[k]))){
					ok = false; break; 
				}
			}
			if(ok){
				cout << i << " " << j << " " << height << endl; 
				return 0; 
			}
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<long long> lunlun;
void make(long long x){
  if(x > 3234566667LL) return;
  lunlun.emplace_back(x);
  if(x%10 <= 8) make(x*10+(x%10+1));
  if(x%10 >= 1) make(x*10+(x%10-1));
  make(x*10+x%10);
}
int main(){
  int k; cin >> k;
  for(int i = 1; i <= 9; ++i) make(i);
  sort(lunlun.begin(), lunlun.end());
  cout << lunlun[--k] << '\n';
  return 0; 
}


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

#define ll long long

int main() {
  int N;
  cin >> N;
  
  vector<ll> L(1010, 0);
  
  for (int i = 0; i < N; i++) {
    ll l;
    cin >> l;
    L[l]++;
  }
  
  vector<ll> sum(1010, 0);
  
  for (int i = 0; i < 1000; i++) {
    sum[i+1] = sum[i] + L[i+1];
  }
  
  ll ans = 0;
  for (int i = 1; i <= 1000; i++) {
    if (L[i] == 0) continue;
      
    for (int j = i; j <= 1000; j++) {
      if (L[j] == 0) continue;
      
      if (i == j) {
        ans += ((L[i] * (L[i]-1) / 2) * (sum[min(1000, 2*i-1)] - sum[i]) );
        ans += L[i] * (L[i]-1) * (L[i]-2) / 6;
      } else {
        ans += (L[i] * L[j] * (sum[min(1000, i+j-1)] - sum[j]));
        ans += L[i] * L[j] * (L[j]-1) / 2;
      }
    }
  }
  
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int N;
	cin >> N;
	cout << N/3 << endl;

	return 0;
}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vec> mat;
int main(){
    int n,a,b;
    vec P,Q,R;
    cin>>n;
    rep(i,n) cin>>a,P.push_back(a);
    rep(i,n) cin>>a,Q.push_back(a);
    a=0,b=0;
    rep(i,n) R.push_back(i+1);
    do{
        int z=1;
        rep(i,n) if(R[i]!=P[i]) z=0;
        if(z) break; 
        a++;
    }while(next_permutation(R.begin(),R.end()));
    sort(R.begin(),R.end());
    do{
        int z=1;
        rep(i,n) if(R[i]!=Q[i]) z=0;
        if(z) break; 
        b++;
    }while(next_permutation(R.begin(),R.end()));
    cout<<abs(a-b);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    b--;
    cout << (b / (a - 1)) + (b % (a - 1) > 0) << endl;
}


Measured memory_bytes: 256
import sys

if __name__ == '__main__':

    nums = []
    piles = [0 for i in range(0,101)]

    for n in sys.stdin:
        if n == "\n":
            break
        else :
            nums.append(int(n))

    for n in nums:
        piles[n] += 1


    maxnum = 0
    for p in piles:
        if maxnum < p:
            maxnum = p

    for i,p in enumerate(piles):
        if maxnum == p:
            print(i)

Measured memory_bytes: 7620
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    string s[n];
    cin(i,s);
    vector<string> v(n);
    char c = s[0][0];
    bool f = true;
    rep(i,n){
        if(c != s[i][0]){
            f = false;
            break;
        }
        c = s[i][s[i].length()-1];
        if(find(all(v),s[i]) != v.end()){
            f = false;
            break;
        }
        v.pb(s[i]);
    }
    fp(f);
    return 0;
}

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

int main() {
  string szo;
cin >> szo;
if (szo[2] == szo[3]) {
  if (szo[4] == szo[5]) {
    cout << "Yes";
} else {
      cout << "No";
}
} else {
      cout << "No";
}
	return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <string>

using namespace std;

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

    string s = to_string(n);

    for (int i = 0; i < 3; i++){
        if (s[i] == '1'){
            s[i] = '9';
        } else {
            s[i] = '1';
        }
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    Scanner sc = new Scanner(System.in);
 
    public static void main(String[] args) {
    	new Main(); 
    }
 
    public Main() {
    	new A().doIt();
    }
    class A{
    	void doIt(){
    		while(true){
    			int n = sc.nextInt();
    			if(n == 0)break;
    			boolean left = false;
    			boolean right = false;
    			boolean up = false;
    			int cnt = 0;
    			for(int i = 0;i < n;i++){
    				String str = sc.next();
    				if(str.equals("lu"))left = true;
    				else if(str.equals("ld"))left = false;
    				else if(str.equals("ru"))right = true;
    				else if(str.equals("rd"))right = false;
    				if(!up){
    					if(left && right){
    						cnt++;
    						up = true;
    					}
    				}else{
    					if(!left && !right){
    						cnt++;
    						up = false;
    					}
    				}
    			}
    			System.out.println(cnt);
    		}
    	}
    }
}

Measured memory_bytes: 37928
from collections import deque
h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
INF = 1000000

def bfs(sx, sy):
    reached = [[INF for _ in range(w)] for _ in range(h)]
    reached[sx][sy] = 0
    dx = [-1, 0, 1, 0]
    dy = [0, 1, 0, -1]
    d = deque()
    d.append([sx, sy])

    while d:
        x, y = d.popleft()
        for i in range(4):
            nx, ny = x + dx[i], y + dy[i]
            if nx < 0 or nx > h - 1 or ny < 0 or ny > w - 1 or  maze[nx][ny] == "#" or reached[nx][ny] != INF:
                continue
            d.append([nx, ny])
            reached[nx][ny] = reached[x][y] + 1
    gl = 0
    for i in range(h):
        for j in range(w):
            if reached[i][j] != INF:
                gl = max(gl, reached[i][j])
    return gl
ans = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] != "#":
            ans = max(ans, bfs(i, j))

print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;

int f(int n, int k, vector<int> a){
	int c1 = 0;
	for(int i=0;i<=n-k;i++){
		int num = 1;
		for(int j=0;j<k;j++){
			num *= a[i+j];
		}
		c1 = max(c1, num);
	}
	return c1;
}

bool solve(){
	int n, k;
	cin>> n>> k;
	if(n==0 && k==0) return false;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>> a[i];
	}
	int c1 = f(n, k, a);
	//cout<< c1<< endl;
	int ans = -1;
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			vector<int> b = a;
			swap(b[i],b[j]);
			int c2 = f(n, k, b);
			if(c2 >= c1) ans = max(ans, c2-c1);
		}
	}
	if(ans != -1){
		cout<< ans<< endl;
	}else{
		cout<< "NO GAME"<< endl;
	}
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	while(solve());

	return 0;
}

 

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  cout << count_if(arr.begin(), arr.end(), [&k](int x){return x >= k;}) << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

struct Graph {
    struct Edge {
        int d, i;
    };
    Graph(int n) : n(n), d(n, vector<int>(n, 1 << 29)) {
        for (int i = 0; i < n; i++) d[i][i] = 0;
    }
    void add_edge(int i, int j, int l) {
        d[i][j] = l;
    }
    void warshall_floyd() {
        for (int k = 0; k < n; k++)
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
    vector<vector<int>> d;
    int n;
};

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

    int n, m, R;
    cin >> n >> m >> R;

    int r[8];
    for (int i = 0; i < R; i++) {
        cin >> r[i];
        r[i]--;
    }
    sort(r, r + R);

    Graph g(n);
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;

        g.add_edge(a, b, c);
        g.add_edge(b, a, c);
    }
    g.warshall_floyd();

    int s = 1 << 30;
    do {
        int t = 0;
        for (int i = 1; i < R; i++) {
            t += g.d[r[i]][r[i - 1]];
        }
        s = min(s, t);
    } while (next_permutation(r, r + R));

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 384
while True:
    N = int(input())
    if not N:
        break
    X = [False if i else True for i in range(N)]
    ans = 0

    V = [list(map(float, input().split())) for i in range(N)]
    dp = [[0 for i in range(N)] for j in range(N)]

    # とりあえずすべての変の距離を測る
    for i in range(N):
        for j in range(N):
            if i == j:
                dp[i][j] = float('inf')
            else:
                tmp = ((V[i][0] - V[j][0]) ** 2 + (V[i][1] - V[j][1]) ** 2 + (V[i][2] - V[j][2]) ** 2) ** 0.5
                dp[i][j] = max(0, tmp - V[i][3] - V[j][3])

    # おそらくプリム法
    for loop in range(N - 1):
        tmpmin = float('inf')
        for i in range(N):
            for j in range(N):
                if X[i] and not X[j]:
                    if dp[i][j] < tmpmin:
                        tmpmin = dp[i][j]
                        tmp = j
        ans += tmpmin
        X[tmp] = True

    print('{0:.3f}'.format(ans))



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

int main() {
	// your code goes here
	int a,b;
	
	cin >> a >> b;
	
	if (a > b){
		cout << "a > b" << endl;
	}else if (a < b){
		cout << "a < b" << endl;
	}else if (a == b) {
		cout << "a == b" << endl;
	}
	
	return 0;
}

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

const int N = 3e2 + 10;
int dp[N][N][N];

int main()
{
	string s;
	cin >> s;
	int k;
	cin >> k;
	int n = s.size();
	for (int tool = 1; tool <= n; tool++)
	{
		for (int l = 0; l + tool <= n; l++)
		{
			int r = l + tool - 1;
			if (tool == 1)
			{
				for (int kk = 0; kk <= k; kk++)
				{
					dp[l][r][kk] = 1;
				}
				continue;
			}
			for (int kk = 0; kk <= k; kk++)
			{
				if (kk > tool)
				{
					dp[l][r][kk] = dp[l][r][tool];
					continue;
				}
				if (s[l] == s[r])
				{
					dp[l][r][kk] = 2 + dp[l + 1][r - 1][kk];
					continue;
				}
				if (kk == 0)
				{
					dp[l][r][kk] = max(dp[l + 1][r][kk], dp[l][r - 1][kk]);
					continue;
				}
				dp[l][r][kk] = max({2 + dp[l + 1][r - 1][kk - 1], dp[l + 1][r][kk], dp[l][r - 1][kk]});
			}
		}
	}
	cout << dp[0][n - 1][k];
}


Measured memory_bytes: 59308
#include<iostream>
#include <string>
#define ll long long
using namespace std;
int main(){
	string str;
	int sum=0;
	while(true) {
		cin >> str;
		if(str[0]=='0') break;
		for (int i = 0; i < str.size(); i++) {
			sum+=str[i]-'0';
		}
		cout << sum << endl;
		sum=0;
	}
}


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

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	long MODULO = 1_000_000_000 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] t = new int[n];
		int[] p = new int[n];
		int[] x = new int[s];
		for (int i = 0; i < s; ++i) {
			x[i] = sc.nextInt();
		}
		for (int i = 0; i < n; ++i) {
			t[i] = sc.nextInt();
			p[i] = sc.nextInt();
			--p[i];
		}
		int[] w = new int[n];
		for (int i = 0; i < n; ++i) {
			w[i] = t[i] - x[p[i]];
		}
		Arrays.sort(w);
		long ans = 0;
		for (long v : w) {
			ans -= v;
		}
		long[][] f = new long[n + 1][m + 1];
		for (int i = 0; i < f.length; ++i) {
			for (int j = 0; j < f[i].length; ++j) {
				f[i][j] = Integer.MAX_VALUE / 16;
			}
		}
		for (int i = 1; i < f.length; ++i) {
			f[i][1] = w[i - 1] * i;
		}

		for (int j = 2; j <= m; ++j) {
			// j??????????????????
			// h[i][k]:=f[k][j-1]+w[i-1]*(i-k)???Monge??§???????????¨?????¨????????????
			// min(h[i][])???n*log(n)??§?¨?????????????
			// f[i][j]=min(h[i][])
			long[] v = calc(f, w, j);
			for (int i = 1; i <= n; ++i) {
				// for (int k = 1; k <= i - 1; ++k) {
				// f[i][j] = Math.min(f[i][j], h(f, w, i, j, k));
				// }
				f[i][j] = v[i];
			}
		}

		long min = Integer.MAX_VALUE / 16;
		for (int j = 1; j <= m; ++j) {
			min = Math.min(min, f[n][j]);
		}
		ans += min;
		System.out.println(ans);
	}

	long[] calc(long[][] f, int[] w, int j) {
		int n = f.length - 1;
		int m = f[0].length - 1;
		long[] ret = new long[n + 1];
		Arrays.fill(ret, Integer.MAX_VALUE / 16);
		rec(ret, 1, n, 2, n + 1, f, w, j);
		return ret;
	}

	// [low,high)
	// [left,right)
	long rec(long[] ret, int low, int high, int left, int right, long[][] f, int[] w, int j) {
		int mid = (left + right) / 2;// ?????°i??????
		long v = Long.MAX_VALUE / 16;
		int arg = -1;
		for (int k = Math.max(0, low); k <= Math.min(mid - 1, high); ++k) {
			v = Math.min(v, h(f, w, mid, j, k));
			if (v == h(f, w, mid, j, k))
				arg = k;
		}
		if (right - left > 1) {
			rec(ret, low, arg, left, mid, f, w, j);
			rec(ret, arg, high, mid, right, f, w, j);
		}
		ret[mid] = v;
		return v;
	}

	long h(long[][] f, int[] w, int i, int j, int k) {
		return f[k][j - 1] + w[i - 1] * (i - k);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 79052
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int N=2e5+2;
int ar[N];
vector<int> lis,lis1;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,ans=0;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>j;
		lis.push_back(j);
	}	
	for(j=30;j>=0;j--){
		if(!(j&1)){
			sort(lis.begin(),lis.end());
			lis1.clear();
			k=0;
			l=lis.size()-1;
			while(l>k){
				if(lis[k]+lis[l]==(1<<j)){
					ans++;
					k++;
					l--;
				}
				else{
					if(lis[k]+lis[l]>(1<<j)){
						lis1.push_back(lis[l]);
						l--;
					}
					else{
						lis1.push_back(lis[k]);
						k++;
					}
				}
			}
			if(l==k){
				lis1.push_back(lis[l]);
			}
		}
		else{
			sort(lis1.begin(),lis1.end());
			lis.clear();
			k=0;
			l=lis1.size()-1;
			while(l>k){
				if(lis1[k]+lis1[l]==(1<<j)){
					ans++;
					k++;
					l--;
				}
				else{
					if(lis1[k]+lis1[l]>(1<<j)){
						lis.push_back(lis1[l]);
						l--;
					}
					else{
						lis.push_back(lis1[k]);
						k++;
					}
				}
			}
			if(l==k){
				lis.push_back(lis1[l]);
			}
		}
	}
	cout<<ans;
}

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

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i < n; i++)
		ans += (n - 1) / i;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define sz(c) ((int)c.size())
#define	pb push_back

typedef long long ll;
typedef pair<ll, ll> state;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;

constexpr int MAX_N = 510;
constexpr ll INF = 5'000'000'000'000'000'000LL;
constexpr ll P = 9'982'443'53;
constexpr int SIGMA = 28;
constexpr double PI = 3.14159265359;
constexpr double toRad = PI/180.;

struct Edge {
	ll np, cost;

	bool operator<(const Edge & o)const{
		if(cost != o.cost){
			return cost < o.cost;
		}
		return np < o.np;
	}
};

ll N, D;
map<ll,ll> costs;
ll brute(){
	set<Edge> q;
	set<ll> vis;
	q.insert(Edge({N,0}));	
	while(q.size()){
		auto e = q.begin();
		if(e->np == 0) {
			return e->cost;
		}
		
		if(vis.find(e->np) != vis.end()) {
			q.erase(e); 
			continue;	
		}

		vis.insert(e->np);		
		if(D < (INF-e->cost)/e->np){
			q.insert(Edge({
				0,
				e->cost + e->np*D
			}));
		}
		
		for(auto c : costs){			
			ll r = e->np % c.first;
			if(r == 0){
				q.insert(Edge({
					e->np / c.first,
					e->cost + c.second
				}));
				continue ;
			}

			q.insert(Edge({
				(e->np - r) / c.first,
				e->cost + c.second + r*D
			}));
		
			ll m = e->np - r + c.first;
			q.insert(Edge({
				m / c.first,
				e->cost + c.second + (m  - e->np)*D
			}));		
		}
		q.erase(e); 
	}
	return -1;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int T;
	cin >> T;
	costs[2] = costs[3] = costs[5] = 0;
	while(T--){
		cin >> N >> costs[2] >> costs[3] >> costs[5] >> D;
		cout << brute() << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 5172
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#define maxn 100009
using namespace std;
int a[maxn], n, b[maxn];
vector<int>G;
int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", &b[i]);
	}
	int m = 1;
	a[1] = b[1];
	for(int i = 2; i <= n; i++){
		if(b[i] != b[i - 1])
			a[++m] = b[i];
	}
	n = m;
	int ans = 0;
	int cur = 1;
	while(cur <= n){
		ans++;
		if(cur == n)
			break;
		if(a[cur + 1] >= a[cur]){
			while(cur + 1 <= n && a[cur + 1] >= a[cur])
				cur++;
		}
		else{
			while(cur + 1 <= n && a[cur + 1] <= a[cur])
				cur++;
		}
		cur++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
int n;
char s[105],t[105];
int main(void){
    scanf("%d %s %s",&n,s,t);
    for(int i=n;i>0;i--){
        int k=n-i;
        bool o=true;
        for(int j=0;j<i&&o;j++)if(s[k+j]!=t[j])o=false;
        if(o){
            printf("%d\n",2*n-i);
            return 0;
        }
    }
    printf("%d\n",n*2);
}

Measured memory_bytes: 256
N=int(input())
C=int(N**0.5)
if int(N**0.5)**2==N:
    C-=1
ans=0
for i in range(1,C+1):
    if (N-i)%i==0:
        num=(N-i)//i
        if num>i:
            ans+=num
    
print(ans)

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

int divnum(int N){
	int ret = 0;
	int issqrt = 0;
	for (int i = 1; i*i < N; i++)
	{
		if(i*i==N) issqrt = 1;
		else if(N%i==0) ret++;
	}
	return ret*2 + issqrt; 
}

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		if((i+1)%2==1&&divnum(i+1)==8) ans++;
	}
	
	cout << ans << endl;
}

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

int n, k;
vector<bool> snuke(200, false);

int main()
{
    cin >> n >> k;
    rep(i, k)
    {
        int d;
        cin >> d;
        rep(i, d)
        {
            int a;
            cin >> a;
            snuke[a] = true;
        }
    }
    
    int res = 0;
    for(int i = 1; i <= n; i++)
    {
        if(!snuke[i])
        {
            res++;
        }
    }
    cout << res << endl;

    
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using P = pair<int, int>;
int n, a, b, ax, ay, dd, c, d;
long long ans;
set<P> x, y, x2, y2;
vector<P> x3, y3;
void dfs(P u){
	x2.insert(u);
	y2.insert(P(u.second, u.first));
	x.erase(u);
	y.erase(P(u.second, u.first));
	set<P>::iterator it;
	P f = P(u.first-dd, u.second-dd), e = P(u.first-dd, u.second+dd);
	for(;(it = x.lower_bound(f)) != x.end() && *it <= e;) dfs(*it);
	f.first += dd*2; e.first += dd*2;
	for(;(it = x.lower_bound(f)) != x.end() && *it <= e;) dfs(*it);
	f = P(u.second-dd, u.first-dd); e = P(u.second-dd, u.first+dd);
	for(;(it = y.lower_bound(f)) != y.end() && *it <= e;) dfs(P(it->second, it->first));
	f.first += dd*2; e.first += dd*2;
	for(;(it = y.lower_bound(f)) != y.end() && *it <= e;) dfs(P(it->second, it->first));
}
int main(){
	scanf("%d%d%d", &n, &a, &b); a--; b--;
	rep(i,n){
		scanf("%d%d", &c, &d);
		x.insert(P(c+d,c-d));
		y.insert(P(c-d,c+d));
		if(a == i){
			ax = c+d;
			ay = c-d;
		}else if(b == i) dd = max(abs(ax - (c+d)), abs(ay - (c-d)));
	}
	dfs(P(ax, ay));
	for(auto t: x2) x3.push_back(t);
	for(auto t: y2) y3.push_back(t);
	for(auto t: x3){
		ans += upper_bound(x3.begin(), x3.end(), P(t.first-dd,t.second+dd)) - lower_bound(x3.begin(), x3.end(), P(t.first-dd,t.second-dd));
		ans +=  upper_bound(x3.begin(), x3.end(), P(t.first+dd,t.second+dd)) - lower_bound(x3.begin(), x3.end(), P(t.first+dd,t.second-dd));
		ans += lower_bound(y3.begin(), y3.end(), P(t.second-dd,t.first+dd)) - upper_bound(y3.begin(), y3.end(), P(t.second-dd,t.first-dd));
		ans +=  lower_bound(y3.begin(), y3.end(), P(t.second-dd,t.first+dd)) - upper_bound(y3.begin(), y3.end(), P(t.second-dd,t.first-dd));
	}
	
	printf("%lld\n", ans/2);
}

Measured memory_bytes: 18168
#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 int64_t Int;

int main(){
    int X, Y, A, B, C;
    vector<Int> P(100010), Q(100010), R(100010);

    cin >> X >> Y >> A >> B >> C;
    rep(i,A) cin >> P[i];
    rep(i,B) cin >> Q[i];
    rep(i,C) cin >> R[i];

    sort(P.begin(), P.begin()+A, greater<Int>());
    sort(Q.begin(), Q.begin()+B, greater<Int>());
    sort(R.begin(), R.begin()+C, greater<Int>());

    Int ans = 0;
    priority_queue<Int, vector<Int>, greater<Int>> Pmin, Qmin;
    rep(i,X) {ans += P[i]; Pmin.push(P[i]);}
    rep(i,Y) {ans += Q[i]; Qmin.push(Q[i]);}
    Pmin.push(1e10); Qmin.push(1e10);

    rep(i,C){
        int p = Pmin.top(), q = Qmin.top();

        if(min(p,q) < R[i]){
            if(p < q){
                ans += R[i] - p;
                Pmin.pop();
            } else {
                ans += R[i] - q;
                Qmin.pop();
            }
        } else {
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4852
#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define enl cout<<endl
#define PB(x) push_back(x)
#define xx first
#define yy second
typedef long long ll;
typedef pair<int,int>PI;
typedef pair<pair<int,int>,int>PII;

int grid[333][333];
int vis[333][333];
int main()
{
    int n;
    cin>>n;
    loop(i,1,n)loop(j,1,n)cin>>grid[i][j];
    loop(i,1,n)if(grid[i][i]!=0)
    {
        cout<<-1<<endl;
        return 0;
    }
    loop(i,1,n)
    {
        loop(j,1,n)
        {
            if(grid[i][j]!=grid[j][i])
            {
                cout<<-1<<endl;
                return 0;
            }
        }
    }
    loop(i,1,n)
    {
        loop(j,1,n)
        {
            loop(k,1,n)
            {
                if(k==i || k==j)continue;
                if(grid[i][k]+grid[k][j]<grid[i][j])
                {
                    cout<<-1<<endl;
                    return 0;
                }
                else if(grid[i][k]+grid[k][j]==grid[i][j])
                {
                    //cout<<i<<" "<<k<<" "<<j<<endl;
                    vis[i][j]=1;
                }
            }
        }
    }
    ll ans=0;
    loop(i,1,n)
    {
        loop(j,1,n)
        {
            if(!vis[i][j])ans+=grid[i][j];
        }
    }
    cout<<ans/2<<endl;
    return 0;
}


Measured memory_bytes: 1024
N,K=map(int,input().split())
A=[int(x)-1 for x in input().split()]
B=[0]
visited=[False]*N
for g,here in enumerate(B):
	if visited[here]:
		break
	visited[here]=True
	B.append(A[here])
s=B.index(here)
r=(K-s)%(g-s)
ans=B[s:][r]+1 if K>=s else B[K]+1
print(ans)

Measured memory_bytes: 32212
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int n; cin >> n;
  vector<int> d(n); REP(i, n) cin >> d[i];
  long long ans = 0;
  REP(i, n) FOR(j, i + 1, n) ans += d[i] * d[j];
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int S,h,m,s;
	scanf("%d",&S);
	m=S/60;
	s=S%60;
	m=m%60;
	h=S/3600;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = x + [X]
x.sort()
# 最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)
diff = [x[i+1] - x[i] for i in range(N)]
if len(diff) == 1:
    print(diff[0])
    exit()
ans = gcd(diff[0], diff[1])
for i in range(2, N):
    ans = gcd(ans, diff[i])
print(ans)

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

int main(){
	int N;
	long long L;
	cin >> N >> L;
	vector<long long> a(N);
	for(auto &k:a)cin >> k;
	long long max_sum=0;
	int maxi=-1;
	for(int i=0;i<N-1;i++){
		if(a[i]+a[i+1]>max_sum){
			max_sum=a[i]+a[i+1];
			maxi=i;
		}
	}
	if(maxi==-1 || max_sum<L)cout << "Impossible" << endl;
	else{
		cout << "Possible" << endl;
		for(int i=1;i<maxi+1;i++)cout << i << endl;
		for(int i=N-1;i>maxi+1;i--)cout << i << endl;
		cout << maxi+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  int n;
  cin>>n;
  string x;
  cin>>x;
  int cnt=0;
  for(int i=0;i<n;i++){
    if(x[i]=='1') cnt++;
  }
  int ue[n];
  int temp=1;
  ue[n-1]=temp%(cnt+1);
  for(int i=n-2;i>=0;i--){
    temp*=2;
    ue[i]=temp%(cnt+1);
    temp%=(cnt+1);
  }
  int sum_u=0;
  for(int i=0;i<n;i++){
    if(x[i]=='0') continue;
    sum_u=mod(sum_u+ue[i],cnt+1);
  }
  int shita[n];
  int sum_s=0;
  if(cnt>1){
  int temp_b=1;
  shita[n-1]=temp_b%(cnt-1);
  for(int i=n-2;i>=0;i--){
      temp_b*=2;
      shita[i]=temp_b%(cnt-1);
      temp_b%=(cnt-1);
  }
  for(int i=0;i<n;i++){
      if(x[i]=='0') continue;
      sum_s=mod(sum_s+shita[i],cnt-1);
  }
  }
  for(int i=0;i<n;i++){
    if(x[i]=='1' and cnt==1) {
      cout<<0<<endl;
      continue;
    }
    int ans=0;
    if(x[i]=='1'){
      int cur=mod(sum_s-shita[i],cnt-1);
      ans++;
      while(cur!=0){
        int y=0;
        for(int j=0;j<19;j++){
          if(cur&(1<<j)) y++;
        }
        cur%=y;
        ans++;
      }
      cout<<ans<<endl;
      continue;
    }
    else{
      int cur=mod(sum_u+ue[i],cnt+1);
      ans++;
      while(cur!=0){
        int y=0;
        for(int j=0;j<19;j++){
          if(cur&(1<<j)) y++;
        }
        cur%=y;
        ans++;
      }
      cout<<ans<<endl;  
      continue;
    }
  }
}



Measured memory_bytes: 5320
import sys
from fractions import gcd

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def lcm(x, y):
    return x * y // gcd(x, y)


def f(a):
    ans = 0
    while a % 2 == 0:
        a //= 2
        ans += 1
    return ans


def main():
    N, M, *A = map(int, read().split())
    A = [a // 2 for a in A]

    p2 = f(A[0])
    for a in A[1:]:
        if p2 != f(a):
            print(0)
            return

    semi_lcm = A[0]
    for a in A[1:]:
        semi_lcm = lcm(semi_lcm, a)

    print((M // semi_lcm + 1) // 2)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 16148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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; }
const ll INF = 1LL<<60;

int main() {
    int N; ll W;    cin >> N >> W;
    ll weight[110], value[110];
    ll dp[110][100100] = {0};
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    for (int i = 0; i < N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {
            if (sum_w - weight[i] >= 0) chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    cout << dp[N][W] << endl;
}

Measured memory_bytes: 86272
k,n=gets.split.map(&:to_i)
as=gets.split.map(&:to_i)
diff=[]
n.times do |i|
  if i==n-1
    diff<<(k-as[i]+as[0])
  else
    diff<<(as[i+1]-as[i])
  end
end
diff.sort!
puts diff[0..-2].inject(:+)


Measured memory_bytes: 19200