akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
  int n,m;
  int h[100000];
  int j[100000]={};
  int i,a,b,c=0;

  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++)
  {
    scanf("%d",&h[i]);
  }
  for(i=0;i<m;i++)
  {
    scanf("%d %d",&a,&b);
    if(h[a-1]<=h[b-1]) j[a-1]=1;
    if(h[a-1]>=h[b-1]) j[b-1]=1;
  }

  for(i=0;i<n;i++)
  {
    if(j[i]==0) c++;
  }

  printf("%d\n",c);

  return 0;
}

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

const int N = 200010;

int n, m, a[N], cnt[N];
int T[N << 2];
int leaf[N];

#define mid ((l + r) >> 1)

void upd(int v, int l, int r, int x, int val) {
	if (l > r || x < l || r < x) return;
	if (l == r) { 
		leaf[x] += val; 
		if (leaf[x] == 1 && val == 1) T[v] = 1;
		else if (leaf[x] == 0 && val == -1) T[v] = 0; 
		return;
	}
	upd(v << 1, l, mid, x, val); upd(v << 1 | 1, mid + 1, r, x, val);
	T[v] = T[v << 1] + T[v << 1 | 1];
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) cin >> a[i], cnt[a[i]]++;
	for (int i = 1; i <= n; ++i) {
		for (int j = i - cnt[i] + 1; j <= i; ++j) upd(1, 1, n, j, 1);
	}

	while(m--) {
		int x, y; cin >> x >> y;
		upd(1, 1, n, a[x] - cnt[a[x]] + 1, -1);
		cnt[a[x]]--;
		cnt[y]++;
		a[x] = y;
		upd(1, 1, n, y - cnt[y] + 1, 1);

		printf("%d\n", n - T[1]);
	}
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
int main(){
  ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
  int n; cin >> n;
  vector<ll> a(n);
  for(int i = 0 ; i < n ; i++) cin >> a[i];
  priority_queue<pll, vector<pll>, greater<pll> > pq;
  for(int i = 0 ; i < n ; i++){
    pq.push({a[i],i});
  }
  set<int> s;
  s.insert(-1);
  s.insert(n);
  ll ans = 0;
  while(!pq.empty()){
    auto tp = pq.top(); pq.pop();
    auto it = s.lower_bound(tp.second);
    int r = *it;
    int l = *(--it) + 1;
    ans += (tp.second-l+1)*(r-tp.second)*tp.first;
    s.insert(tp.second);
  }
  cout << ans;
}


Measured memory_bytes: 14956
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const LL INF = 1e14;
const LL MOD = 1e9 + 7;

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

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a, b;
  cin >> n >> a >> b;
  int f = 0, s = 0, t = 0;
  REP(i, n)
  {
    int p;
    cin >> p;
    if (p <= a) f++;
    else if (a+1 <= p && p <= b) s++;
    else t++;
  }
  cout << min(min(f, s), min(s, t)) << endl;

  return 0;
}

Measured memory_bytes: 256
a,b,c=map(int,input().split())
if a==1 and b==0 and c==0:
    print('Close')
if a==0 and b==1 and c==0:
    print('Close')
if a==1 and b==1 and c==0:
    print('Open')
if a==0 and b==0 and c==1:
    print('Open')
if a==0 and b==0 and c==0:
    print('Close')



Measured memory_bytes: 5596
import math

def append_factor(f, p):
    if p not in f:
        f[p] = 0
    f[p] += 1

def factors(n):
    l = int(math.sqrt(n)) + 1
    ret = {}
    while n % 2 == 0:
        append_factor(ret, 2)
        n //= 2
    while n % 3 == 0:
        append_factor(ret, 3)
        n //= 3
    i = 6
    while i*i <= n + 1:
        while n % (i - 1) == 0:
            append_factor(ret, i - 1)
            n //= (i - 1)
        while n % (i + 1) == 0:
            append_factor(ret, i + 1)
            n //= (i + 1)
        i += 6
    if n != 1:
        append_factor(ret, n)

    return ret

def minimum_sum(x):
    # find the minimum integer n where n(n+1)/2 <= x
    # n^2 < n(n+1) <= 2x < (n+1)(n+2) < (n+2)^2

    n = int(math.sqrt(x))
    while (n + 1)*(n + 2) <= 2*x:
        n += 1

    return n

def main():
    N = int(input())
    fs = factors(N)
    # print(fs)
    ans = 0
    for f in fs:
        ans += minimum_sum(fs[f])
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    string s;
    cin >> s;
    int n = sz(s);
    vector<int> r(2019),las(2019);
    int a = s[0] - '0';
    int ans = 0;
    r[a]++;
    las[a]++;
    rep(i,1,n-1){
        int b = s[i] - '0';
        vector<int> now(2019);
        rep(j,0,2018){
            if(las[j] >0){
                if((j*10+b)%2019 == 0)ans+=las[j];
                now[(j*10+b)%2019] = las[j];
            }
        }
        now[b]++;
        swap(las,now);
    }

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 3728
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = []
i = 1
if x not in p:
  print(x)
else:
  while len(ans)==0:
    if x+i not in p and x-i not in p:
      ans.append(x+i)
      ans.append(x-i)
    elif x+i not in p:
      ans.append(x+i)
    elif x-i not in p:
      ans.append(x-i)
    else:
      i+=1
  print(min(ans))

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

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

    vector <pair <int, int>> gusu(100000), kisu(100000);
    rep (i, 100000) gusu[i] = kisu[i] = make_pair(0, i + 1);

    rep (i, n) {
        int v;
        cin >> v;
        (i % 2 ? gusu[v - 1] : kisu[v - 1]).first += 1;
    }

    sort(gusu.rbegin(), gusu.rend());
    sort(kisu.rbegin(), kisu.rend());

    int ans = 1000000000;
    for (auto & pvpiivpii : {make_pair(&gusu, &kisu), make_pair(&kisu, &gusu)}) {
        for (auto & pii : *(pvpiivpii.first)) {
            auto macs = pvpiivpii.second->begin();
            if (pii.second == macs->second) macs += 1;
            ans = min(ans, n - pii.first - macs->first);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1920
#include<iostream>
using namespace std;
int main(){
	int arr[3][3];
  	for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
        cin>>arr[i][j];
      }
    }
  	int k,l;
  	cin>>k;
  	for(int m=0;m<k;m++){
      cin>>l;
      for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
          if(arr[i][j]==l) arr[i][j]=0;
        }
      }
    }
 	for(int i=0;i<3;i++){
      if(arr[i][0]==0&&arr[i][1]==0&&arr[i][2]==0) {cout<<"Yes";return 0;}
	}
  	for(int i=0;i<3;i++){
      if(arr[0][i]==0&&arr[1][i]==0&&arr[2][i]==0) {cout<<"Yes";return 0;}
	}
  	if(arr[0][0]==0&&arr[1][1]==0&&arr[2][2]==0) {cout<<"Yes";return 0;}
  	if(arr[0][2]==0&&arr[1][1]==0&&arr[2][0]==0) {cout<<"Yes";return 0;}
  
  	cout<<"No";
  
}


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

int h, m, h2, m2, k, minutes;

int main() {
    cin >> h >> m >> h2 >> m2 >> k;

    if (m2 < m) {
        m2 += 60;
        --h2;
    }
    m2 -= m;
    
    if (h2 < h)
        h2 += 24;
    h2 -= h;
    
    minutes = h2*60 + m2;
    cout << minutes - k;
    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 
 using namespace std;
 
 double abs(double x)
 {
   if(x>=0) return x;
   else return -x;       
 }
 
 int main()
 {
   long long int q;
   while(cin>>q&&(q!=-1))
   {
     double x;
     x=(1.0*q)/2;
     while(abs(pow(x,3)-q)>=(0.00001*q))
     {
       x=1.0*2/3*x+q/(3*x*x);                                
     }                        
     printf("%.6lf\n",x);
   }
   //while(1);
   return 0; 
 }

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

int main(){
	string str;
	
	while(1){
		stack <int> sta;
		int si = 0, f = 1;
		getline(cin, str);
		
		if(str == ".") break;
		
		si = str.size();
		
		for(int i = 0; i < si; i++){
			switch(str[i]){
				case '[': sta.push(1); break;
				case ']': if(!sta.empty()){if(sta.top() != 1)f = 0; sta.pop();}else f = 0;break;
				case '(': sta.push(2); break;
				case ')': if(!sta.empty()){if(sta.top() != 2)f = 0; sta.pop();}else f = 0;break;
			}
			if(f == 0) break;
		}
		
		if(!sta.empty())f = 0;
		
		if(f) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
		
	}
	return 0;
}


Measured memory_bytes: 3004
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)<<"\n"
#define vll vector<ll>
#define pb push_back

using namespace std;
using ll = long long;

static inline void ignore_ret(int x) {x++;}
template<class T> bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> T nCr(T n,T k){return factorial<T>(n)/(factorial<T>(k)*factorial<T>(n-k));}
template<class T> T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> T sum(vector<T>v){return reduce(all(v),0LL);}

// Template ends here

void solve(string S){
    int cnt = 0;
    rep(i, S.size()) cnt += (int(S.at(i) - '0') == (i % 2));
    cout << min(cnt, int(S.size()) - cnt) << "\n";
}

int main() {
    string S;
    cin >> S;
    solve(S);
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int H,W; cin>>H>>W;

    int ans=1e18;
    REP(k,2){
        for(int i=1;i<=W-1;i++){
        /*
                    W
            -----------------
            |       |   b   | H/2
            |       |       |
           H|   a   ---------
            |       |   c   |(H+1)/2
            |       |       |
            -----------------
                i      W-i
        */
            int a=H*i;
            int b=(H/2)*(W-i);
            int c=((H+1)/2)*(W-i);
            ans=min(ans,max(a,c)-min(a,b));
        /*
                    W
            -----------------
            |       |   |   | 
            |       |   |   |
           H|   a   | d | e |
            |       |   |   | 
            |       |   |   |
            -----------------
                i   (W-i)/2,(W-i+1)/2

        */
            int d=H*((W-i)/2);
            int e=H*((W-i+1)/2);
            ans=min(ans,max(a,e)-min(a,d));
        }
        swap(H,W);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N=input()
dp=[ float("inf") for _ in range(N+1) ]
dp[0]=0

#1円
for i in range(N+1):
    if i+1<=N:
        dp[i+1]=min(dp[i+1],dp[i]+1)
#6円
for k in range(1,10**5):
    yen=6**k
    for i in range(N+1):
        if i+yen<=N:
            dp[i+yen]=min(dp[i+yen],dp[i]+1)
    if N<=yen:break

#9円
for k in range(1,10**5):
    yen=9**k
    for i in range(N+1):
        if i+yen<=N:
            dp[i+yen]=min(dp[i+yen],dp[i]+1)
    if N<=yen:break

print dp[N]


Measured memory_bytes: 33900
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
//#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    cout << 180 * (N - 2) << endl;
}


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

    int main() {
        int A1,A2,B1,B2;
        cin >> A1 >> A2 >> B1 >> B2;
        while(1){
            B1 = B1-A2;
            if(B1<=0){
                cout << "Yes" << endl;
                break;
            }
            A1 = A1-B2;
            if(A1<=0){
                cout << "No" << endl;
                break;
            }
        }
        return 0;

    }


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include <stdio.h>
#include <bitset>
#include<math.h>
#include<list>
#include<map>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
#define PI 3.14159265358979323846  
typedef pair<int, int> P;

int main() {
	int h, w, k;
	int count=0;
	int ans=0;
	cin >> h >> w >> k;
	Graph g(h+1);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char c;
			int t;
			cin >> c;
			if (c == '#') {
				t = 1;
				count++;
			}
			else {
				t = 0;
			}
			g.at(i).push_back(t);
			//cout << g.at(i).at(j) << ',' << h << ',' << j << endl;
		}
	}
	for (int biti = 0; biti < (1 << h); ++biti) {
		for (int bitj = 0; bitj < (1 << w); ++bitj) {
			Graph gc;
			gc = g;
			int ansm = 0;
			for (int i = 0; i < h; i++) {
				if (biti & (1 << i)) {
					for (int t = 0; t < w; t++) {
						if (gc.at(i).at(t) == 1) {
							ansm++;
							gc.at(i).at(t) = -1;
						}

					}
				}
			}
			for (int j = 0; j < w; j++) {
				if (bitj & (1 << j)) {
					for (int t = 0; t < h; t++) {
						if (gc.at(t).at(j) == 1) {
							ansm++;
							gc.at(t).at(j) = -1;
						}

					}
				}
			}
			//cout << ansm << endl;
			if (k == count - ansm) {
				ans++;
			}
		}
		
	}
	cout << ans << endl;
}


Measured memory_bytes: 3632
{-# LANGUAGE BangPatterns, MultiWayIf #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import Debug.Trace

solve :: Int -> Int -> VU.Vector Int -> Int
solve !n !k !vn = maximum
  [ calc i a b | i <- [0 .. k `min` n], a <- [0 .. i], let b = i - a ]
 where
  calc !i !a !b =
    let (a1, a2) =
          (\vec -> (VU.filter (> 0) vec, VU.filter (< 0) vec)) $ VU.take a vn
        (b1, b2) =
          (\vec -> (VU.filter (> 0) vec, VU.filter (< 0) vec))
            $ VU.take b
            $ VU.reverse vn
        r = sum $ drop (k - i) $ sort $ VU.toList a2 ++ VU.toList b2
    in  VU.sum a1 + VU.sum b1 + r

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (n, k) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  vn <- VU.unfoldrN n readInt <$> B.getLine

  print $ solve n k vn


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

int main() {
    int n;
    cin >> n;
    int k=(n-1)/1000+1;
    cout << 1000*k-n << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
	string str;
	while(cin>>str){
		if(str[2]==str[3]&&str[4]==str[5]){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

typedef struct {
	int id;
	int time;
} Team;

using namespace std;

bool operator < (const Team &a, const Team &b)
{
	return (a.time < b.time);
}

int main()
{
	int n;
	
	while (scanf("%d", &n) && n){
		vector<Team> in(n);
		
		for (int i = 0; i < n; i++){
			int m, s;
			scanf("%d", &in[i].id);
			in[i].time = 0;
			for (int j = 0; j < 4; j++){
				scanf("%d %d", &m, &s);
				in[i].time += m * 60 + s;
			}
		}
		
		sort(in.begin(), in.end());
		
		printf("%d\n%d\n%d\n", in[0].id, in[1].id, in[n - 2].id);
	}
	
	return (0);
}

Measured memory_bytes: 1084
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=1e5;
const int inf=1e9;
int main(){
	string s,t; cin>>s>>t;
	int n = s.size();
	rep(i,0,n){
		bool flag = true;
		rep(j,0,n)if(s[j] != t[(i+j)%n]) flag = false;
		if(flag){ cout<<"Yes"<<endl; return 0; }
	}cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int h, n;
    cin >> h >> n;
    int a[n];
    int sum = 0;
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }

    if(sum >= h)yn;

    return 0;
}
 
 


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int compare(const void *a,const void *b){
  return *(char *)a - *(char *)b;
}

int compare_line(const void *a,const void *b){
  int i  = 0;
  char *p = (char *)a;
  char *q = (char *)b;
  while(i < 10){
    if(p[i] - q[i] < 0) return -1;
    else if(p[i] - q[i] > 0) return 1;
    else i++;
  }
  return 0;
}
  

int main(void){ 
  long int N,count = 1;
  long int answer = 0;
  scanf("%ld",&N);
  char s[N + 1][11];
  char check[N][11];
  long int check_number[N + 1];
  long int number = 0;
  for(int i = 0;i < N;i++){
    check_number[i] = 0;
    scanf("%s",s[i]);
    qsort(s[i],10,sizeof(char),compare);    
  }
  
  qsort(s,N,sizeof(s[0]),compare_line);
    
  for(int i = 1;i < N;i++){
    if(compare_line(s[i - 1],s[i]) == 0)
      count++;
    else{
      answer += count * (count - 1) / 2;
      count = 1;
    }
  }
  answer += count * (count - 1) / 2;
  printf("%ld",answer);
  return 0;
}


Measured memory_bytes: 3068
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//String line = br.readLine();
		Scanner scan = new Scanner(System.in);

	String str = scan.next();
	System.out.print("ABC");
	System.out.println(str);
		
	}
}

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

using namespace std;

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

int main() {
	int l, r;
	scanf("%d%d", &l, &r);
	const int n = 2019;
	if (r - l > n) {
		printf("0\n");
	} else {
		long long ans = n + 1;
		for (int i = l; i <= r; i ++) {
			for (int j = i + 1; j <= r; j ++) {
				ans = min(ans, (long long) i * j % n);
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 256
// I want to AC


#include <vector>
#include<stdio.h>
#include<string.h>
#include <cstring>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <set>
#include<cstring>
#include<queue>
#include<assert.h>
#define ll long long
#define MODD 1000000007
#define  pii  pair<int,int>
#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
//#define  ll long long
using namespace std;
const int maxn = 1e6+7;
#define FOR(i, x, y) for (ll i = (x), _##i = (y); i < _##i; ++i)

ll mod = 1e9+7;
//const int maxn = 100010;
//ll f[maxn];
//ll inv[maxn]; // 阶乘的逆元
//void CalFact()
//{
//    f[0] = 1;
//    for (int i = 1; i < maxn; i++) f[i] = (f[i - 1] * i) % p;
//    inv[maxn - 1] = Pow(f[maxn - 1], p - 2, p);
//    for (int i = maxn - 2; ~i; i--) inv[i] = inv[i + 1] * (i + 1) % p;
//}
//ll C(int n, int m) { return f[n] * inv[m] % p * inv[n - m] % p; }
int n , m ,q;
map<string , int > mp;
int main() {
	cin >>n;
	while ( n--){
         string s; cin >>s;
         mp[s] ++;
	}
    int sum =0 ;
    for(auto it  : mp){
        sum = max(sum ,it.second);
    }
    //cout<<sum<<endl;
    for(auto it : mp){
        if(sum == it.second )cout<<it.first<<endl;
    }


	return 0;

}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int fc(vector<int> &v,int k, int lc, int rc){
  if(k < lc + rc) return -1e9;
  int n = v.size();
  vector<bool> chk(n, false);
  vector<int> now;
  rep(i, lc){
    now.push_back(v.at(i));
    k--;
    chk.at(i) = true;
  }
  rep(i, rc){
    if(chk.at(n-i-1) == false){
      k--;
      now.push_back(v.at(n-i-1));
    }else break;
  }
  
  sort(now.begin(), now.end());
  int ret = accumulate(now.begin(), now.end(), 0);
  rep(i, k){
    if(i >= now.size() || now.at(i) >= 0) break;
    ret -= now.at(i);
  }
  // cerr << ret << endl;
  return ret;
}

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  rep(snip_i, n) cin >> v.at(snip_i);
  int ans = -1e9-5;
  rep(i, n+1){
    rep(j, n+1){
      // cerr << i << " " << j << " " << ans << endl;
      ans = max(ans, fc(v, k, i, j));
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
function f(n) {
    if (n % 2 == 0) {
        return parseInt(n / 2);
    } else {
        return parseInt(3 * n + 1);
    }
}
function Main(input) {
    input = input.split(" ");
    var s = parseInt(input[0]);
    var n = 1;
    var set = new Set();
    var ai = s;
    set.add(ai);
    var loop = true;
    while (loop) {
        n += 1;

      ai = f(ai);
        if (set.has(ai)) {
            console.log(n);
            return;
        }
        set.add(ai);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#include <bits/stdc++.h>
#define ri register int
using namespace std;
const int rlen = 1 << 20 | 5;
char buf[rlen], *ib = buf, *ob = buf;
#define gc() (((ib == ob) && (ob = (ib = buf) + fread(buf, 1, rlen, stdin))), ib == ob ? -1: *ib++)
inline int read() {
  static int ans;
  static char ch;
  for (ans = 0, ch = gc(); !isdigit(ch); ch = gc());
  while (isdigit(ch)) {
    ans = ((ans << 2) + ans << 1) + (ch ^ 48);
    ch = gc();
  }
  return ans;
}
typedef long long ll;
typedef vector <int> poly;
#define pb push_back
#define rez resize
bitset <4000001> S;
int main() {
  #ifdef ldxcaicai
  freopen("lx.in", "r", stdin);
  #endif
  S[0] = 1;
  for (ri tt = read(); tt; --tt) {
    S |= S << read();
  }
  S[0] = 0;
  int t = (S.count() + 1) / 2, ct = 0;
  for (ri i = 1; i <= 4000000; ++i) {
    if (S[i]) {
      ++ct;
    }
    if (ct == t) {
      cout << i;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 5076
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9
typedef pair<mp,mp> mmp;

int main(){

ll n,m,x;
cin>>n>>m>>x;
vector<int> t(n);
vector<vector<mp> > g(n);
for(ll i=0;i<n;i++)cin>>t[i];
for(ll i=0;i<m;i++){
	ll a,b,d;
	cin>>a>>b>>d;
	a--,b--;
	g[a].push_back( mp(d,b) );
	g[b].push_back( mp(d,a) );
}
priority_queue<mmp , vector<mmp> ,greater<mmp> > q;
q.push( mmp(mp(0,x),mp(0,0) ) );
vector<vector<vector<bool> > > used(n,vector<vector<bool>  >(3,vector<bool> (x+1,true) ) );
while(!q.empty()){
	mmp now = q.top();
	q.pop();
	ll type = now.second.first;
	ll nn = now.second.second;
	ll nr = now.first.second;
	ll nt = now.first.first;
	//cout<<type<<' '<<nr<<nn<<' '<<nt<<endl;
	if(nn == n-1) {
	//	cout<<"ok"<<n<<' '<<nn<<endl;
		cout<<nt<<endl;
		break;
	}
	//cout<<"kkk"<<endl;
	if(!used[nn][type][nr]) continue;
	//cout<<nn<<' '<<nt<<' '<<nr<<endl;
	//cout<<nn<<endl;
	used[nn][type][nr] = false;
	for(ll i=0;i<g[nn].size();i++){
		ll cost = g[nn][i].first;
		ll next = g[nn][i].second;
		ll nexttype = t[next];
		ll nextr = max( (ll) 0,nr - cost);
		if(nextr != 0  && t[next] != 1 && t[next] != type){
			//q.push(mmp( mp(nt+x,x),mp(nexttype,next) ));
			continue;
		}
		if(nexttype != 1 ) nextr = x;
		if(nexttype == 1 && nextr != 0) {
			nexttype = type;
		}
	//	cout<<"ok2"<<nn<<' '<<next<<endl;
		q.push( mmp( mp( nt+cost , nextr ), mp( nexttype,next )  ) );
		
	}
}


	return 0;
}



Measured memory_bytes: 7356
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define inf 1000000000
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(i) cout<<i<<endl;
const int mod=1e9 +7;
lli dp[3001][3001];
int main(){
IOS;
lli n,a,b,i,j;
cin>>n;
string s;
cin>>s;
dp[1][1]=1;
for(i=2;i<=n;i++){
    lli rightsum=0,leftsum=0;
    for(j=1;j<=n;j++){
        rightsum=(rightsum+dp[i-1][j])%mod;
    }
    for(b=1;b<=i;b++){
            if(s[i-2]=='<'){
                dp[i][b]=(dp[i][b]+leftsum)%mod;
            }
            else{
                dp[i][b]=(dp[i][b]+rightsum)%mod;
            }
            rightsum-=dp[i-1][b];
            if(rightsum<0)
                rightsum+=mod;
            leftsum+=dp[i-1][b];
            if(leftsum>=mod)
                leftsum-=mod;
        /*for(a=1;a<=i-1;a++){
            int real_a=a;
            if(a>=b)
                real_a++;
            if((real_a<b)!=(s[i-2]=='<'))
                continue;
            dp[i][b]+=dp[i-1][a];
        }*/
    }
}
lli ans=0;
for(i=1;i<=n;i++){
    ans=(ans+dp[n][i])%mod;
}
cout<<ans<<endl;
}


Measured memory_bytes: 68992
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H,W;
  cin>>H>>W;
  for(int i=0;i<W+1;i++){
    cout<<"#";
  }
  cout<<"#"<<endl;
  for(int i=0;i<H;i++){
    vector<char> a(W);
    cout<<"#";
    for(int j=0;j<W;j++){
      cin>>a.at(j);
      cout<<a.at(j);
  }
    cout<<"#"<<endl;
  }
   for(int i=0;i<W+2;i++){
    cout<<"#";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb     push_back
using namespace std;
const int nax = 2e5+10;
vector<int> v[nax];
int main(){
    int n,m;
    cin >> n >> m;
    
    for(int i=0;i<m;i++){
    	int a,b;
    	cin >> a >> b;
    	v[a].pb(b);
	}
	
	if(binary_search(v[1].begin(),v[1].end(),n)){
		cout <<"POSSIBLE";
		return 0;
	}
	
	string ans = "IMPOSSIBLE";
	
	for(int i=0;i<v[1].size();i++){
		int x = v[1][i];
		if(binary_search(v[x].begin(),v[x].end(),n)){
			ans = "POSSIBLE";
			break;
		}
	}
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 8576
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class CTogether {
public:
	void solve(istream& in, ostream& out) {
        int n;
        in >> n;
        vector<int> a(n),b(1e5);
        rep(i,n){
            in >> a[i];
            b[a[i]]++;
        }
        int ans = 0;
        rep(i,1e5){
            int check  = 0;
            rep(j,3){
                check += b[i+j];
            }
            ans = max(ans,check);
        }
        out << ans <<endl;

	}
};

int main() {
	CTogether solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 1024
from collections import deque

s = deque(input())
q = int(input())
flag = True
for _ in range(q):
    query = input().split()
    if query[0] == "1":
        flag = not flag
    else:
        if (query[1] == "1" and flag) or (query[1] == "2" and not flag):
            s.appendleft(query[2])
        else:
            s.append(query[2])
if not flag:
    s.reverse()
print(''.join(s))


Measured memory_bytes: 76504
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <utility>
#include <functional>
#include <map>
#include <string>
#include <set>
#include <math.h>

using namespace std;

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

  int n, q;
  cin >> n >> q;

  string s;
  cin >> s;

  int l[q], r[q];
  for (int i = 0; i < q; i++) {
    cin >> l[i] >> r[i];
  }

  int count[n];
  for (int i = 0; i < n; i++) {
    count[i] = 0;
  }

  for (int i = 1; i < n; i ++) {
    char pre = s[i - 1];
    char cur = s[i];

    if (pre == 'A' && cur == 'C') {
      count[i] = 1;
    }

    count[i] += count[i - 1];
  }

  for (int i = 0; i < q; i++) {
    int left = l[i] - 1;
    int right = r[i] - 1;

    if (left == 0) {
      cout << count[right] - count[left] << endl;
    }
    else if (count[left] == count[left - 1]) {
      cout << count[right] - count[left - 1] << endl;
    }
    else {
      cout << count[right] - count[left - 1] - 1 << endl;
    }
  }

}

Measured memory_bytes: 2256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = Integer.parseInt(sc.next());
    int t = Integer.parseInt(sc.next());

    int msg = 0;
    if (X > t) {
      msg = X - t;
    }

    System.out.println(msg);

  }
}


Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>


using ll = long long;
#define reps(i,s,n) for(ll (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;

const ll MOD = 998244353;
int MAX = 3e6 + 10;
vector<ll> f(MAX);
vector<ll>  rf(MAX);

ll power(ll a, ll b){
    ll res = 1;
    while(b > 0){
        if(b & 1) res = res*a % MOD;
        a = a*a % MOD;
        b >>= 1;
    }
    return res;
}

ll comb(ll n,ll r){
    return (f[n] * rf[r] ) % MOD * rf[n-r] % MOD;
}

int main(){
    ll n,A,B;
    ll K;
    ll ans = 0;
    cin >> n >> A >> B >> K;

    f[0] = 1;
    rep(i,n) f[i+1] = f[i] * (i+1)  % MOD;
    rf[n] = power(f[n], MOD - 2);

    for(ll i = n-1; i >= 0 ; i--){
        rf[i] = rf[i+1] * (i+1) % MOD;
    }

    rep(a,n+1){
        ll left = K - a*A;
        if(left < 0 || left % B || left/B > n) continue;
        int j = left / B;
        ans += comb(n,a) * comb(n,j);
        ans %= MOD;
    }

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


Measured memory_bytes: 47104
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define lld long long int

int main(){
    int n;
    scanf("%d", &n);
    int a[n+1], f[n+1];
    rep(i, 1, n+1){
        scanf("%d", &a[i]);
        f[i] = 0;
    }
    int x=1;
    int ans = 0;
    while(1){
        if(x == 2){
            printf("%d", ans);
            break;
        }else if(f[a[x]]){
            printf("-1");
            break;
        }else{
            f[a[x]] = 1;
            x = a[x];
            ans++;
        }
    }

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max();
 
 
signed main(){

  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  int A[N], sum[N];
  cin >> A[0];
  sum[0] = A[0];
  for(int i=1;i<N;i++){
    cin >> A[i];
    sum[i] = sum[i-1] + A[i];
  }

  int ans = INF;
  for(int i=0;i<N;i++){
    ans = min(ans, abs((sum[N-1] - sum[i])- sum[i] ));
  }

  cout << ans << endl;

}

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

using namespace std;

const long long MOD = 998244353;

long long bin_pow(long long a, long long n, long long m)
{
    if(n == 0)
        return 1;
    long long p = bin_pow(a, n / 2, m);
    if(n % 2 == 0)
        return (p * p) % m;
    else
        return (((a * p) % m) * p) % m;
}

int main()
{
    int n, m;
    cin >> n >> m;
    int a[n], sum = 0;;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(4 * a[i] * m >= sum)
            ans++;
    }
    if(ans >= m)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
while True:
    (n, m) = [int(x) for x in input().split()]
    if n==0 and m==0:
        exit()
    a = []
    b = []
    for i in range(n):
        a.append(int(input()))
    for i in range(m):
        b.append(int(input()))
    a_sum = sum(a)
    b_sum = sum(b)
    target = a_sum - b_sum
    found = False
    for ai in a:
        for bi in b:
            if (ai-bi)*2 == target:
                print(ai, bi)
                found = True
            if found:
                break
        if found:
            break
    if found == False:
        print(-1)

Measured memory_bytes: 6724
N = int(input())
S = list(input() for i in range(N))  #スペース抜きの単語を複数行

import collections
A = collections.Counter(S)

B = max(A.values())
C = [i for i in A if A[i] == B]
C = sorted(C)
 
for i in C:
    print(i)

Measured memory_bytes: 35480
n = int(input())
hs = [int(i) for i in input().split()]

result = 'Yes'

for i in range(n - 1):
    if hs[i] < hs[i + 1]:
        hs[i + 1] -= 1
    elif hs[i] > hs[i + 1]:
        result = 'No'
        break

print(result)



Measured memory_bytes: 14396
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define inf ((ll)1e18+5)
#define maxx ((ll)1e6+5)
#define pb push_back
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[1000007]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
*/
using namespace std;
signed main(){
  fast;
  //usefile;
  //test
  {
    string s;
    cin>>s;
    if(s[0]==s[1]&& s[1]==s[2])
        cout<<"No"<<endl;
    else
    {
        cout<<"Yes"<<endl;
    }
    
  }
  //time("");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define nl '\n'

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	setprecision(10);
	cout << fixed;
	ll a, b, c, d, ans;
	scanf("%lld %lld.%lld", &a, &b, &c);
	d = b*100+c;
	ans = a * d / 100;
	cout << ans << nl;
}

Measured memory_bytes: 3704
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    cout << t + s << endl;
    return 0;
}

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

int main() {

    int N, D;
    cin >> N >> D; 
	set<int> s;
	vector<vector<int>> data(N, vector<int>(D));
	for(int i=1;i<2000;i++){
		s.insert(i*i);
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<D;j++){
			cin >> data.at(i).at(j);
		}
	}
	// cout << "finish input" << endl;
	int count = 0;
	for(int i=0;i<N;i++){
		
		for(int j=i+1;j<N;j++){
			int distance = 0;
			for(int k=0;k<D;k++){
				distance += (data.at(i).at(k) - data.at(j).at(k)) * (data.at(i).at(k) - data.at(j).at(k));
			}
			// cout << "dis = " << distance << endl;
			if(s.count(distance) > 0){
				count++;
			}
		}
		
	}
	cout << count << endl;
	return 0;
}

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

char str[1 << 16];

inline int maj(int a)
{
	return a / 2 + 1;
}

int calc(char *s, char *e)
{
	/*
	for (char *p = s; p != e; p++){
		printf("%c", *p);
	}
	puts("");
	*/
	
	if (*s != '['){
		return maj(atoi(s));
	}
	
	vector<int> v;
	
	char *p = s;
	while (p != e){
		char *a = p;
		char *b = p;
		int cnt = 0;
		while (true){
			if (*b == '[') cnt++;
			if (*b == ']') cnt--;
			if (cnt == 0) break;
			b++;
		}
		v.push_back(calc(a + 1, b));
		p = b + 1;
	}
	
	int res = 0;
	sort(v.begin(), v.end());
	for (int i = 0; i < maj(v.size()); i++){
		res += v[i];
	}
	
	return res;
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%s", str);
		char *e = str + strlen(str);
		printf("%d\n", calc(str, e));
	}
	return 0;
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
using namespace std;
string str;
set<string>que;
set<string>::iterator it;
int main(void)
{
    cin>>str;
    int k;
    cin>>k;
    int n = str.length();
    for(int i = 0;i < n;i++)
    {
        for(int j = i;j < i+k&&j < n;j++)
        {
            que.insert(str.substr(i,j - i + 1));
            //cout<<str.substr(i,j+1)<<endl;
        }
    }
    int i = 1;
    for(it = que.begin();it!=que.end();it++)
    {
            if(i == k)
            {
             cout<<*it<<endl;
            }
            i++;

    }
    return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
bool arr[100100];
vector<long long int>v;
void sieve()
{
    long long int a, b, c, i, j, k;
    v.push_back(2);
    for (i = 3; i * i <= 100050; i = i + 2)
    {
        if (arr[i] == false)
        {
            v.push_back(i);
            for (j = i * i; j <= 100050; j = j + i)
            {
                arr[j] = true;
            }
        }
    }
    for (; i <= 100050; i = i + 2)
    {
        if (arr[i] == false)
            v.push_back(i);
    }

}
int main()
{
	long long int a, b, c, d, i, j, k, m, l, t;
    sieve();
    cin >> a;
    l = 0;
    long long int h = v.size() - 1;
   auto it= lower_bound(v.begin(), v.end(), a);
   b = it - v.begin();
   cout << v[b] << endl;
  
    return 0;
}

Measured memory_bytes: 512
def solve(X):
    N = len(X)
    #print("X=", X)
    A = sorted([(x, i) for i, x in enumerate(X)])
    #print("A=", A)
    R = sorted([(i, x, rank) for rank, (x, i) in enumerate(A)])
    #print("R=", R)
    #   t
    # 0 1 2 3
    #   x o x
    # x   o x
    # x o   x
    # x o x  
    t = N // 2 - 1
    for i, x, rank in R:
        if rank <= t:
            print(A[t+1][0])
        else:
            print(A[t+0][0])

#solve([0,10,20,30])
N = int(input())
X = [int(x) for x in input().split()]
solve(X)


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

const int tmax=55440;

int main(void){
	int n;
	const int prime[4]={13,17,19,23};
	while(cin >> n,n){
		int any[4][24],acc[tmax];
		memset(acc,0,sizeof(acc));
		memset(any,0,sizeof(any));
		rep(loop,n){
			int d,t;
			int q[24];
			cin >> d >> t;
			rep(i,d) cin >> q[i];

			bool ok=false;
			rep(i,4){
				if(d!=prime[i]) continue;
				ok=true;
				rep(j,d){
					int cur=(j+t)%d;
					any[i][j]+=q[cur];
				}
			}
			if(ok) continue;
			rep(i,tmax){
				int cur=(i+t)%d;
				acc[i]+=q[cur];
			}
		}
		int ans=*max_element(acc,acc+tmax);
		rep(i,4) ans+=*max_element(any[i],any[i]+prime[i]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1380
fn main() {
  let mut n = String::new();
  std::io::stdin().read_line(&mut n).unwrap();
  let n: i32 = n.trim().parse().unwrap();

  let mut v = String::new();
  std::io::stdin().read_line(&mut v).unwrap();
  let v: Vec<i32> = v.trim().split_whitespace().map(|x| x.parse().unwrap()).collect();

  let mut q = String::new();
  std::io::stdin().read_line(&mut q).unwrap();
  let _q:i32 = q.trim().parse().unwrap();

  let mut queries = String::new();
  std::io::stdin().read_line(&mut queries).unwrap();
  let queries: Vec<i32> = queries.trim().split_whitespace().map(|x| x.parse().unwrap()).collect();

  let mut ans = 0;
  for x in queries.iter() {
    let mut low: i32 = -1;
    let mut hi: i32 = n;
    while 1 < hi - low {
      let mid = (low + hi) / 2;
      if x <= &v[mid as usize] {
        hi = mid;
      } else {
        low = mid
      }
    }
    ans += if hi < n && &v[hi as usize] == x { 1 } else { 0 };
  }
  println!("{}", ans);
}



Measured memory_bytes: 7068
#include <iostream>
#include <vector>

using namespace std;

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

		if (a[i] > i) {
			cout << -1 << endl;
			return 0;
		}
	}

	vector<int> ans(n);
	for (int i = n - 1; i >= 0; i--) {
		for (int j = i; j >= 0; j--) {
			if (a[j] == j) {
				ans[i] = j + 1;
				for (int k = j; k < i; k++) {
					a[k] = a[k + 1];
				}
				break;
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int[] h = new int[n+k];
    for(int i=0;i<n;i++){
      h[i]=sc.nextInt();
    }
    int[] dp = new int[n+k];
    Arrays.fill(dp,Integer.MAX_VALUE);
    dp[0]=0;
    dp[1]=Math.abs(h[0]-h[1]);
    
    for(int i=0;i<n-1;i++){
      for(int j=1;j<=k;j++){
        dp[i+j]=Math.min(dp[i]+Math.abs(h[i]-h[i+j]),dp[i+j]);
      }
    }
    
    System.out.println(dp[n-1]);
  }
}

Measured memory_bytes: 52124
function bsearch(T::Array{Int},x::Int)
	L=0
	R=length(T)+1
	while R-L>1
		M=(L+R)>>1
		if T[M]<x
			L=M
		else
			R=M
		end
	end
	R
end
function calc(A::Array{Int},B::Array{Int},T::Int)
	cnt=0
	for a=A
		cnt+=bsearch(B,2T-a)-bsearch(B,T-a)+bsearch(B,4T-a)-bsearch(B,3T-a)
	end
	cnt%2
end
f(A::Array{Int},mod::Int)=[x%mod for x=A]
function main()
	N=parse(Int,readline())
	A=map(x->parse(Int,x),split(readline()))
	B=map(x->parse(Int,x),split(readline()))
	ans=0
	for k=0:28
		T=2^k
		ans+=calc(f(A,2T),sort(f(B,2T)),T)*T
	end
	println(ans)
end
main()


Measured memory_bytes: 171080
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef pair<double,double> P;
typedef complex<double> CP;
typedef long long ll;


map<string,string> bef;
map<string,string> aft;


int main(){
	bef[" "]="101";
	bef["'"]="000000";   bef[","]="000011";   bef["-"]="10010001";
	bef["."]="010001";   bef["?"]="000001";   bef["A"]="100101";
	bef["B"]="10011010";   bef["C"]="0101";   bef["D"]="0001";
	bef["E"]="110";   bef["F"]="01001";   bef["G"]="10011011";
	bef["H"]="010000";   bef["I"]="0111";   bef["J"]="10011000";
	bef["K"]="0110";   bef["L"]="00100";   bef["M"]="10011001";
	bef["N"]="10011110";   bef["O"]="00101";   bef["P"]="111";
	bef["Q"]="10011111";   bef["R"]="1000";   bef["S"]="00110";
	bef["T"]="00111";   bef["U"]="10011100";   bef["V"]="10011101";
	bef["W"]="000010";   bef["X"]="10010010";   bef["Y"]="10010011";
	bef["Z"]="10010000";
	
	aft["00000"]="A";
	aft["00001"]="B";  aft["00010"]="C";  aft["00011"]="D";
	aft["00100"]="E";  aft["00101"]="F";  aft["00110"]="G";
	aft["00111"]="H";  aft["01000"]="I";  aft["01001"]="J";
	aft["01010"]="K";  aft["01011"]="L";  aft["01100"]="M";
	aft["01101"]="N";  aft["01110"]="O";  aft["01111"]="P";
	aft["10000"]="Q";  aft["10001"]="R";  aft["10010"]="S";  aft["10011"]="T";
	aft["10100"]="U";  aft["10101"]="V";  aft["10110"]="W";
	aft["10111"]="X";  aft["11000"]="Y";  aft["11001"]="Z";
	aft["11010"]=" ";  aft["11011"]=".";  aft["11100"]=",";
	aft["11101"]="-";  aft["11110"]="'";  aft["11111"]="?";
	
	string s1;
	string s2;
	string s3;
	string t;
	while(getline(cin,s1)){
		s2.clear();
		rep(i,s1.size()){
			t=s1[i];
			s2+=bef[t];
		}
		//cout<<s2.size()<<endl;
		while(s2.size()%5!=0) s2+="0";
		//cout<<s2<<endl;
		s3.clear();
		for(int i=0;i<s2.size();i+=5){
			s3+=aft[s2.substr(i,5)];
		}
		cout<<s3<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int t;
  cin >> t;
  double ma = 0;
  REP(i, t) {
    int n, m;
    cin >> n >> m;
    double tmp = 0;
    double v[100], r[100];
    double R = 0;
    REP(i, m) {
      cin >> v[i] >> r[i];
      R += r[i];
    }
    REP(i, m)
      tmp += v[i]*r[i]/R;
    ma = max(ma, tmp);
  }
  int n, m;
  cin >> n >> m;
  double exp = 0;
  double v[100], r[100];
  double R = 0;
  REP(i, m) {
    cin >> v[i] >> r[i];
    R += r[i];
  }
  REP(i,m) {
    exp += v[i]*r[i]/R;
  }

  cout <<  ((ma > exp+0.0000001) ? "YES" : "NO") << endl;

}

Measured memory_bytes: 0