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

bool condition( string s)
{
    char t = s[0];
    for(int i=0;i<s.length();i++)
    {
        if( s[i] != t)
            return false;
    }
    return true;
}
int val ( string s , char a)
{
    int ans =0;
    while( !condition(s ) )
    {
        string temp;
        for(int i=0;i<s.length() -1 ;i++)
        {
            if( s[i] == a || s[i+1] == a )
            {
                temp.push_back(a);
            }
            else temp.push_back( s[i] );
        }
        ans++;
        s = temp;
    }
    return ans;
}

int main()
{
    string s;
    cin>>s;
    int ans = INT_MAX ;
    for(int i=0;i<26;i++)
    {
        int temp  = val( s , 'a' + i);
        ans = min( ans , temp);
    }
    cout<<ans;

}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
    char ch;
    int counter[26] = {};

    while(cin >> ch){
        if(ch >= 'a' && ch <= 'z'){
            int num = ch - 'a';
            counter[num]++;
        }else if(ch >= 'A' && ch <= 'Z'){
            int NUM = ch - 'A';
            counter[NUM]++;
        }
    }

    for(int i = 0; i < 26; i++){
        char c = 97 + i;
        cout << c << " : " << counter[i] << endl;
    }
}


Measured memory_bytes: 3104
n = int(input())
a = list(map(int,input().split()))
ans = 0
cnt = [0,] * 100001
for i in range(n):
    if a[i] > 100000:
        ans += 1
    else:
        cnt[a[i]] += 1
for i in range(100001):
    if cnt[i] > i:
        ans += cnt[i] - i
    elif cnt[i] < i:
        ans += cnt[i]
print(str(ans))

Measured memory_bytes: 14692
#include<bits/stdc++.h>//万能头 
using namespace std;
int main()
{
	int xiaopengyou;//定义小朋友人数 
    cin>>xiaopengyou;//输入小朋友人数 
    cout<<xiaopengyou*(xiaopengyou+1)/2<<endl;//套用公式计算并输出 
    return 0; 
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// 어떻게 xor basis까지 사랑하겠어...
//
bool chosen[100000];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	vector<ll> a(n);
	ll all = 0;
	for(int i=0; i<n; i++) {
		cin >> a[i];
		all ^= a[i];
	}
	for(int b=59; b>=0; b--) {
		if(all&(1ll<<b)) continue;
		for(int i=0; i<n; i++) {
			if(chosen[i]) continue;
			if(a[i]&(1ll<<b)) {
				chosen[i] = 1;
				ll v = a[i];
				for(int j=0; j<n; j++) {
					if(i==j) continue;
					if(a[j]&(1ll<<b))
						a[j] ^= v;
				}
				break;
			}
		}
	}
	memset(chosen, 0, sizeof chosen);
	ll add = 0;
	for(int i=0; i<n; i++) {
		add ^= a[i];
	}
	cout << (add + (all^add));
}

Measured memory_bytes: 1152
#if _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#ifndef ONLINE_JUDGE 
const bool DEBUG = true;
#else
const bool DEBUG = false;
#endif

// Reads a 1D vector
template <class T>
void read1d(vector<T> & arg) {
	const int l = arg.size();
	for (int i = 0; i < l; ++i) cin >> arg[i];
}

void read() {}
// Reads arbitrary values
template <class T1, class... T2>
void read(T1& var1, T2&... var2) { cin >> var1; read(var2...); }



void pln() { cout << (DEBUG ? "]\n" : "\n"); }
template <class T1, class... T2>
void pln(const T1& var1, const T2& ... var2) { cout << var1 << " "; pln(var2...); }

// Prints arbitrary values and goes to next line
template <class T1, class... T2>
constexpr void print(const T1& var1, const T2& ... var2) { cout << (DEBUG ? " [ " : ""); pln(var1, var2...); }

// Prints arbitrary values and goes to next line ONLY IF IN DEBUG MODE
template <class T1, class... T2>
constexpr void debug(const T1& var1, const T2& ... var2) { if (!DEBUG) return;  cout << " debug : [ "; pln(var1, var2...); }





using ll = long long;
using ull = unsigned long long;


#define all(x) begin(x), end(x)

const bool MULTIPLE_TEST_CASES = 0;


void exec() 
{
	string s, t;
	read(s, t);

	int ans = INT_MAX;
	int size = int(t.size());

	for (int i = 0; i < int(s.size()) - size + 1; ++i) {
		int thisAns = 0;
		for (int j = 0; j < size; ++j)
			thisAns += (s[i + j] != t[j]);
		ans = min(ans, thisAns);
	}

	print(ans);
}

















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

	if (!MULTIPLE_TEST_CASES)
		exec();
	else {
		int n;
		cin >> n;

		while (n--)
			exec();
	}

    return 0;
}

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

#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define All(obj) (obj).begin(),(obj).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=0; i>=(n);--i)
#define FOR(i,b,n) for(int i=(b);i<(n);++i)

typedef long long ll;

const int M=2e5+5;
const int INF=2e9;
const int MOD=1e9+7; //prime number


void Solve()
{
    int D,T,S;
    cin >> D >> T >> S;
    if(D<=T*S)
        cout << "Yes";
    else
        cout << "No";

}
int main()
{
    fastio;
    Solve();

    return 0;
}



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

const int N = 100005, M = N;
int n, m, a[N], g, o[M];
long long tp, fp, e[M];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		if(i == 1) continue;
		if(a[i - 1] < a[i]) {
			int ab = a[i] - a[i - 1];
			tp += ab;
			--o[a[i - 1] + 1];
			++o[a[i]];
			e[a[i]] += ab - 1;
		} else {
			int ab = m - a[i - 1] + a[i];
			tp += a[i];
			--o[1];
			++o[a[i]];
			e[a[i]] += ab - 1;
			--o[a[i - 1] + 1];
		}
	}
	for(int i = 1; i <= m; ++i) {
		fp = ((i == 1 || fp > tp) ? tp : fp);
		g += o[i];
		tp += e[i] + g;
	}
	cout << fp << endl;
	return 0;
}


Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

// 文字列を1行入力
func StrStdin() (stringInput string) {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	stringInput = scanner.Text()

	stringInput = strings.TrimSpace(stringInput)
	return
}

// 整数値1つ取得
func IntStdin() (int, error) {
	stringInput := StrStdin()
	return strconv.Atoi(strings.TrimSpace(stringInput))
}

func main() {
	D, err := IntStdin()
	if err != nil {
		fmt.Println(err)
	}

	if D == 22 {
		fmt.Println("Christmas Eve Eve Eve")
	} else if D == 23 {
		fmt.Println("Christmas Eve Eve")
	} else if D == 24 {
		fmt.Println("Christmas Eve ")
	} else if D == 25 {
		fmt.Println("Christmas")
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,n,m,s=0,a,min_v=1000,sum;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a);
		s+=a;
		min_v=min(min_v,a);
	}
	sum=n;
	m-=s;
	sum+=m/min_v;
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 256
/*

 Remember, Hope is a good thing... May be the best of things... And No Good thing ever Dies !!!

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(0); cout.tie(0);
#define endl "\n"
#define MOD 1000000007
const ll inf=(1LL<<60)-1;
int dx[]= {-1,1,0,0};
int dy[]= {0,0,-1,1};
void solve()
{
   ll a,b,t,c=0;
    double d;
   cin>>t>>d;
   while(t--)
   {
       cin>>a>>b;
       double x=sqrtl(a*a+b*b);
   if(x<=d)
    c++;
   }
   cout<<c<<endl;
}
int main()
{
    IOS;
    //ll t;
    //cin>>t;
    //while(t--)
    solve();
    return 0;
}


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

int c[10][10];

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

    rep(i,10)rep(j,10) c[i][j] = 0;

    int first, last;
    for(int i = 1; i <= n; i++){
        int j = i;
        last = j % 10;
        while(j >= 10){
            j /= 10;
        }
        first = j;
        c[first][last]++;
    }

    long long ans = 0;
    for(int i = 0; i <= 9; i++){
        for(int j = 0; j <= 9; j++){
            ans += c[i][j] * c[j][i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
first = [False] * n
second = [set() for _ in range(max(m,n)+1)]

for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        first[b] = True
    else:
        second[a].add(b)

f = True
for i in range(1, n):
    if first[i]:
        if n in second[i]:
            f = False
            break
if f:
    print('IM', end='')
print('POSSIBLE')


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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

bool isPrime(int x) {
   if (x <= 1) return false;
   if (x % 2 == 0 && x != 2) return false;
   for (int i = 3; i*i <= x; i+=2) {
      if (x % i == 0) {
         return false;
      }
   }
   return true;
}

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

   int cnt = 0;
   for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      if ( isPrime(x) ) {
         cnt++;
      }
   }

   cout << cnt << endl;

   return 0;
}

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

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

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

    int sz = s.size();

    ll all_pat = pow(2, sz - 1);

    ll ans = 0;
    reverse(s.begin(), s.end());
    rep(pat, all_pat){
        ll d = 1;
        
        for(int i = 0; i < sz - 1; i ++){
            ans += (s.at(i) - '0') * d;
            if((pat >> i) & 1) d = 1;
            else d *= 10;
        }

        ans += (s.at(sz - 1) - '0') * d;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3940
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Test.HUnit

main :: IO ()
-- main = runTestTT (TestList tests) >> return ()
main = do
  n <- getl toInt
  xs <- rgetl n $ split toDbl
  mapM_ putStrLn $ map solve xs

solve :: [Double] -> String
solve [xp1,yp1,xp2,yp2,xp3,yp3,xk,yk,xs,ys]
  | inside (p1,p2,p3) pk `xor` inside (p1,p2,p3) ps = "OK"
  | otherwise = "NG"
  where
    p1 = Point xp1 yp1
    p2 = Point xp2 yp2
    p3 = Point xp3 yp3
    pk = Point xk yk
    ps = Point xs ys

inside :: (Point, Point, Point) -> Point -> Bool
inside (p1, p2, p3) p = all (> 0) [c1,c2,c3] || all (< 0) [c1,c2,c3]
  where
    c1 = cross (toVect p1 p2) (toVect p1 p)
    c2 = cross (toVect p2 p3) (toVect p2 p)
    c3 = cross (toVect p3 p1) (toVect p3 p)

xor :: Bool -> Bool -> Bool
xor x y | x == True && y == False = True
        | x == False && y == True = True
        | otherwise = False
    
toInt :: String -> Int
toInt s = read s

toDbl :: String -> Double
toDbl s = read s

split :: (String -> a) -> String -> [a]
split f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

rgetl :: Int -> (String -> a) -> IO [a]
rgetl n f = map f <$> replicateM n getLine


data Point = Point {xop :: Double, yop :: Double} deriving Show
data Vect = Vect {xov :: Double, yov :: Double} deriving Show

cross :: Vect -> Vect -> Double
cross v1 v2 = xov v1 * yov v2 - yov v1 * xov v2

toVect :: Point -> Point -> Vect
toVect p1 p2 = Vect (xop p2 - xop p1) (yop p2 - yop p1)


tests :: [Test]
tests = [
  "test1" ~: True ~=? inside ((Point 10 1),(Point 10 10),(Point 1 10)) (Point 9 9),
  "test2" ~: False ~=? inside ((Point 10 1),(Point 10 10),(Point 1 10)) (Point 1 1),
  "test3" ~: "OK" ~=? solve [10, 1, 10, 10, 1, 10, 9, 9, 1, 1],
  "test3" ~: "NG" ~=? solve [10, 1, 10, 10, 1, 10, 9, 9, 8, 8]
  ]

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

int main(){
	double w,h,x,y;
	cin>>w>>h>>x>>y;
	cout<<w*h/2;
	if(w/2==x && h/2==y){
		cout<<" "<<1<<endl;
	}else{
		cout<<" "<<0<<endl;
	}
}


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

using namespace std;

int main(){
    int r,c;
    cin >> r >> c;
    vector<vector<int> > list(r+1,vector<int>(c+1,0));
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cin >> list[i][j];
            list[i][c]+=list[i][j];
            list[r][j]+=list[i][j];
        }
        list[r][c]+=list[i][c];
    }
    for(int i=0;i<=r;i++){
        for(int j=0;j<=c;j++){
            cout << list[i][j];
            if(j!=c)cout << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3144
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> bool max_self(T & a, const T & b){ 
  return b > a ? a = b, true : false; 
}
template<class T> bool min_self(T & a, const T & b){ 
  return b < a ? a = b, true : false;    
}
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int T, x;

int main(){
  FAST_IO
  cin >> T >> x;
  PRECISION(3);
  cout << (double)T / x;
  return 0;
}


Measured memory_bytes: 3744
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
multiset<int>R,B;
struct node
{
	int x,y;
	bool operator<(const node &b)const{return x<b.x;}
}p[200010];
int n;
ll solve()
{
	return 1ll*((*--R.end())-(*R.begin()))*((*--B.end())-(*B.begin()));
}
int main(){
	n=gi();
	for(int i=1;i<=n;i++)
	{
		int x=gi(),y=gi();if(x>y)swap(x,y);
		p[i]=(node){x,y};R.insert(x);B.insert(y);
	}
	sort(p+1,p+n+1);
	ll ans=solve();
	for(int i=1;i<=n;i++)
	{
		R.erase(R.find(p[i].x));B.erase(B.find(p[i].y));
		R.insert(p[i].y);B.insert(p[i].x);
		ans=min(ans,solve());
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 22656
x, n = map(int, input().split())

if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  for j in range(0, int(n/2)+ 2):
    #print(j)
    if x-j not in p:
      print(x-j)
      break
    else:
      if x+j not in p:
        print(x+j)
        break

Measured memory_bytes: 9128
#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>

using namespace std;

long long N, M, H, W,re;
long long A[200001];
string S;
vector <long long>vl;

int main() {
	cin >> N>>M>>H>>W;
	re = max(N, M);
	A[0] = max(re, H);
	A[1] = A[0];
	for (int i = 0; i < W; i++) {
		A[1] *= 2;
	}

	cout << A[1] + N+M+H-A[0] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main()
{
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    int x=a,y=b;
    if(u==s)x--;
    else y--;
    cout<<x<<" "<<y;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
  unsigned long long int a,b,c;
  long long int k;
  cin>>a>>b>>c;
  k=a+b-c;
  cout<<(k>=0?"No":(k*k>4*a*b?"Yes":"No"));
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
typedef pair<int, P> PP;
int p[105];
signed main() {
	int n, c; cin >> n >> c;
	rep(i, c)cin >> p[i];
	int sum = 0;
	rep(i, c)sum += p[i];
	cout << (sum + n) / (n+1) << endl;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
 int n;
 cin >> n;
 n%=10;
 if(n==3)
 cout << "bon";
 else if(n<=1 || n==6 || n==8)
 cout << "pon";
 else
 cout << "hon";
 return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  string S;
  cin>>S;
  string W;
  
  for(ll i=0;i<S.size();i++) {
    if(S[i]=='1') {
W.push_back('1');
    }
else if(S[i]=='0') {
W.push_back('0');
}
    else if(W.size()>0&&S[i]=='B') {
W.pop_back();
    }
  }
  
  
 
  cout<<W<<endl;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<ll, ll> P;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
vi dy = { 0,0,1,-1 };
vi dx = { 1,-1,0,0 };
constexpr auto INF = INT_MAX/2;
constexpr auto MOD = 1000000007;

int main() {
	ll n;
	cin >> n;
	vector<vector<P>> path(n, vector<P>(0));

	rep(i, n - 1) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--;b--;
		path[a].push_back(make_pair(b,c));
		path[b].push_back(make_pair(a,c));
	}

	ll q, k;
	cin >> q >> k; k--;
	vector<ll> x(q), y(q);
	rep(i, q) { cin >> x[i] >> y[i]; x[i]--;y[i]--; }

	vector<ll> dist(n,5000000000000000);
	dist[k] = 0;

	priority_queue<P> que;
	que.push(make_pair(0, k));

	while (!que.empty()) {

		ll sv = que.top().second; que.pop();

		rep(i, path[sv].size()) {
			ll gv = path[sv][i].first;
			ll d = path[sv][i].second;

			if (dist[gv] < dist[sv] + d)continue;

			dist[gv] = dist[sv] + d;
			que.push(make_pair(dist[gv], gv));
		}
	}

	rep(i, q) cout << dist[x[i]] + dist[y[i]] << endl;

}

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

int main()
{
	int k, a, b;
  	cin >> k >> a >> b;
  	for(int i = 1; i <= 10000; i++)
    {
    	if(a <= k * i && k * i <= b)
        {
        	cout << "OK" << endl;
          	break;
        }
      	else if(i == 10000)
        {
        	cout << "NG" << endl;
        }
    }
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 1; i <= N; i++){
        if(i < 10){
            ans++;
        }else if(i >= 100 && i < 1000){
            ans++;
        }else if(i >= 10000 && i < 100000){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<int> a(N, 0);
  bool flag = false;
  REP(i, N){
    cin >> a[i];
    if(a[i]%2) flag = true;
  }
  if(flag){
    cout << "first" << endl;
  }else{
    cout << "second" << endl;
  }
}

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

int main(){
    int n;
    cin >> n;
    vector<int>a(n, 0);
    for(int i = 0; i < n; i++){
        int ai;
        cin >> ai;
        a.at(i) = ai;
    }
    vector<int> b(n,0);
    for( int i = 0; i < n; i++){
        b.at(i)  = a.at(i);
    }
    sort(b.begin(), b.end());
    int c = b.at(n/2- 1);
    int d = b.at(n/2 );
    for(int i =0 ; i< n; i++){
        if(a.at(i) >= d){
            cout<<c << endl;
        }else{
            cout << d << endl;
        }
    }
    
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int n;
int b[1000],a[1000];
int Par[10001],Rank[10001];
bool sorted[1000];

void init(int n)
{
	for(int i =0;i<n;i++)
	{
		Par[i] = i;
		Rank[i] = 0;
	}
}

int find(int x)
{
	if(Par[x]==x)return x;
	return Par[x] = find(Par[x]);
}

void unite(int x,int y)
{
	x = find(x);
	y = find(y);
	if(x==y)return;
	if(Rank[x]>Rank[y])
	{
		Par[y] = x; 
	}
	else
	{
		Par[x] = y;
		if(Rank[x]==Rank[y])Rank[y]++;
	}
}



void marge_sort(int l,int r)
{
	if(r-l==1)return;

	int mid = (l+r)/2;
	//cout<<mid<<endl;
	marge_sort(l,mid);
	marge_sort(mid,r);
	vector<int> v;
	vector<char> v2;
	int i = l,j=mid;
	while(i!=mid&&j!=r)
	{
		if(b[i]<=b[j])
		{
			v.push_back(b[i]);
			i++;
		}
		else
		{
			v.push_back(b[j]);
			j++;
		}
	}
	for(;i<mid;i++){v.push_back(b[i]);}
	for(;j<r;++j){v.push_back(b[j]);}
	for(int k = l;k<r;k++)
	{
		b[k]=v[k-l];
	}
}


int main()
{
	cin >> n;
	for(int i = 0;i<n;i++)
	{
		cin >> a[i];
	}
	int minimam = 1000000;
	for(int i = 0;i<n;i++)
	{
		b[i] = a[i];
		minimam = min(minimam,a[i]);
	}
	init(10001);
	//for(int i = 0;i<n;i++)cout<<b[i]<<';'<<find(b[i])<<endl;
	marge_sort(0,n);
	for(int i = 0;i<n;++i)
	{
		if(a[i]==b[i])continue;
		unite(a[i],b[i]);
	}
	
	int ans  = 0;
	for(int i =0;i<n;i++)
	{
		if(sorted[i])continue;
		int grope = find(a[i]);
		vector<int> now;
		now.push_back(a[i]);
		sorted[i]=true;
		for(int j =0;j<n;j++)
		{
			if(grope==find(a[j])&&a[i]!=a[j])
			{
				now.push_back(a[j]);
				sorted[j] = true;
			}
		}
		if(now.size()==1)continue;
		int mi = MAX,sum = 0;
		//for(auto i = now.begin();i!=now.end();i++)cout<<*i<<endl;cout<<endl;
		for(int j = 0;j<now.size();j++)
		{
			sum+= now[j];
			mi = min(mi,now[j]);
		}
		ans += min(sum+(now.size()-2)*mi,sum+mi+(now.size()+1)*minimam);
	}
	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int main() {
    string S, T;
    cin >> S >> T;
    if (S == T.substr(0, S.size()))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<int>A(N);
	map<int, int>mp;
	rep(i, 0, N) {
		cin >> A[i];
		mp[(i + 1) - A[i]]++;
	}
	ll ans = 0;
	rep(i, 0, N) {
		ans += mp[A[i] + i + 1];
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 21024
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll n = in();
	vector<ll>d(n); REP(i, n)d[i] = in();
	sort(ALL(d));
	cout << unique(ALL(d)) - d.begin() << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{ string S;
  for(int i=0;i<1;i++)
  {  cin>>S;
   if(S[0]==S[1]&&S[1]==S[2])
     cout<<"No"<<endl;
  else
  cout<<"Yes"<<endl;
}
 return 0;
}

Measured memory_bytes: 256
n,m,q=map(int,input().split())

mat=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
    l,r=map(int,input().split())
    mat[l][r]+=1

for i in range(n+1):
    for j in range(n+1):
        mat[i][j]+=mat[i-1][j]
        mat[i][j]+=mat[i][j-1]
        mat[i][j]-=mat[i-1][j-1]

for i in range(q):
    l,r=map(int,input().split())
    ans=mat[r][r]+mat[l-1][l-1]-mat[l-1][r]-mat[r][l-1]
    print(ans)


Measured memory_bytes: 13584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
ll N;
void solve()
{
    cin>>s;
    ll maxu=0;
    ll R=0;
    N=s.length();
    for(ll i=0;i<N;i++)
    {
        if(s[i]=='R')
        {
            R++;
            if(R>maxu)
            maxu=R;
        }
        else
        R=0;    
    }
    cout<<maxu<<"\n";
}
signed main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    solve();
}

Measured memory_bytes: 3648
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;
int main(void){
    int N;
    cin>>N;
    int P[N];
    for(int i=0;i<N;i++){
        cin>>P[i];
    }
    int count=0;
    for(int i=1;i<N-1;i++){
        if(P[i-1]<=P[i] & P[i]<P[i+1]){
            count++;
        }
        else if(P[i]<P[i-1] & P[i+1]<=P[i]){
            count++;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
struct Comb {
    fac: Vec<u64>,
    finv: Vec<u64>,
    inv: Vec<u64>,
    m: u64,
}

impl Comb {
    fn new(n: usize, m: u64) -> Comb {
        let mut fac = vec![0u64; n];
        let mut finv = vec![0u64; n];
        let mut inv = vec![0u64; n];

        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;

        for i in 2..n {
            fac[i] = fac[(i - 1) as usize] * i as u64 % m;
            inv[i] = m - inv[(m % i as u64) as usize] * (m / i as u64) % m;
            finv[i] = finv[(i - 1) as usize] * inv[i] % m;
        }
        Comb {
            fac: fac,
            finv: finv,
            inv: inv,
            m: m,
        }
    }
    fn calc(&self, n: usize, k: usize) -> u64 {
        if n < k {
            return 0;
        }

        return self.fac[n] * (self.finv[k] * self.finv[n - k] % self.m) % self.m;
    }
}

fn main() {
    input! {
        n: usize, k: usize,
        s: chars,
    }
    let mut cnt = 0;
    for i in 0..n - 1 {
        if s[i] == s[i + 1] {
            cnt += 1;
        }
    }

    println!("{}", min(cnt + 2 * k, n - 1));
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
constexpr long INF = 1LL << 62;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n; 
    long a[200000]; for(int i=0; i < n; ++i) cin >> a[i];

    // sum [l, r) => s[r] - s[l]
    vector<long> s(n + 1);
    for(int i=0; i < n; ++i) s[i+1] = s[i] + a[i];


    // center : しきり a[c-1] : a[c]
    // l : しきり sum(a[0] ~ a[l-1]), sum(a[l] ~ a[c-1])
    // r : しきり sum(a[c] ~ a[r-1]), sum(a[r] ~ a[n-1])
    long ans = INF;
    int l = 1, r = 3;

    // 区間 a1 a2 a3 a4
    // c が　右へ動く -> a2が増加することでa1, a2の差が増加, a3が減少することでa3, a4の差が増加
    // 差が単調増加なので、l, rは右へ動かすことのみ考えればよい? 差が減少する場合のみスライドする尺取り法
    for(int c = 2; c < n-1; ++c) {
        while(l < c && abs((s[c] - s[l]) - (s[l] - s[0])) > abs((s[c] - s[l+1]) - (s[l+1] - s[0]))) ++l;
        while(r < n && abs((s[n] - s[r]) - (s[r] - s[c])) > abs((s[n] - s[r+1]) - (s[r+1] - s[c]))) ++r;

        long a1 = s[l] - s[0], a2 = s[c] - s[l], a3 = s[r] - s[c], a4 = s[n] - s[r];

        ans = min(ans, max(a1, max(a2, max(a3, a4))) - min(a1, min(a2, min(a3, a4))));
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3328
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

#include "bits/stdc++.h"
using namespace std;

int main() {
	long long int N;
	cin >> N;

	for (long long int h = 0; h <= 3500; h++) {
		for (long long int n = h; n <= 3500; n++) {
			long long int bunbo = 4 * h * n - N * (h + n);
			long long int bunshi = N * h * n;
			if ( (bunbo > 0) && (bunshi % bunbo == 0) ) {
				cout << n << " " << h << " " << bunshi / bunbo << endl;
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
using ll = long long;
using namespace std;
int main(){
    string s,t;
    cin >> s >> t;
    vector<int> vec1(26,-1);
    vector<int> vec2(26,-1);
    for(int i=0;i<s.size();i++){
        int x=s[i]-'a';
        int y=t[i]-'a';
        if(vec1[x]!=-1){
            if(vec1[x]!=y){
                cout<<"No"<<endl;
                return 0;
            }
            continue;
        }
        if(vec2[y]!=-1){
            if(vec2[y]!=x){
                cout<<"No"<<endl;
                return 0;
            }
            continue;
        }
        vec1[x]=y;
        vec2[y]=x;
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 776
from collections import deque

n, k = map(int, input().split())
org = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
kod = set(map(int, input().split()))
ele = list(org ^ kod)
que = deque(ele)

if n < 10:
    for i in ele:
        if i >= n:
            print(i)
            exit()

while que:
    x = que.popleft()
    for i in ele:
        y = 10 * x + i
        if y >= n:
            print(y)
            exit()
        else:
            que.append(y)
            


Measured memory_bytes: 3572
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define     FAST            ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
int main()
{
    FAST;
    ll n,q;
    cin>>n;
    ll ar[n],sm=0;
    map<ll,ll>mp;
    for(ll i=1;i<=n;i++)
    {
        cin>>ar[i];
        mp[ar[i]]++;
        sm+=ar[i];
    }
    cin>>q;
    vector<pair<ll,ll> >v;
    for(ll i=1;i<=q;i++)
    {
        ll x,y;
        cin>>x>>y;
        v.push_back(make_pair(x,y));
    }


    //cout<<sm<<endl;
    int f=0;
    ll ans=0;
    for(ll i=0;i<q;i++)
    {
        ll x=mp[v[i].first];
        mp[v[i].second]+=x;
        mp[v[i].first]=0;
        ll y=x*(v[i].second-v[i].first);

        sm=sm+y;
        cout<<sm<<endl;
    }








    return 0;

}


Measured memory_bytes: 11672
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] h = new int[N];
    for(int i = 0; i < N; i++){
      h[i] = sc.nextInt();
    }
    System.out.println(solve(h));
  }
  
  public static long solve(int[] array){
    long[] ans = new long[array.length];
    ans[0] = 0L;
    ans[1] = Math.abs(array[1] - array[0]);
    for(int i = 2; i < array.length; i++){
      long tmp1 = ans[i-1] + Math.abs(array[i] - array[i-1]);
      long tmp2 = ans[i-2] + Math.abs(array[i] - array[i-2]);
      ans[i] = Math.min(tmp1, tmp2);
    }
    return ans[array.length - 1];
  }
}

Measured memory_bytes: 49652
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
bool cmp(pair<ll, ll>& a, pair<ll, ll>& b)
{
  if(a.first == b.first)
  {
    return a.second < b.second;
  }
  return a.first > b.first;
}

int main()
{
 ll q,n, r, avg, i, j, c;
 while(cin >> n)
 {
   ll a[n + 5];
   map<pair<ll, ll> , ll> m;
   map<ll, ll>::iterator it;
   for(i = 0; i < n; i++)
   {
     cin >> a[i];
   }
   c = 1,j = a[0];
   for(i = 1; i < n; i++)
   {
     if(a[i] >= j){
       j = a[i];
       c++;
     }
   }
   cout << c << endl;
   
 }
 return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
matrix = []
for _ in range(H):
    row = input()
    matrix.append(row)
no_flag = False
for i, row in enumerate(matrix):
    for j, y in enumerate(row):
        if y == '#':
            if j != 0 and matrix[i][j - 1] == '#':
                continue
            elif j != W - 1 and matrix[i][j + 1] == '#':
                continue
            elif i != 0 and matrix[i - 1][j] == '#':
                continue
            elif i != H - 1 and matrix[i + 1][j] == '#':
                continue
            else:
                no_flag = True
                break
    if no_flag == True:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n, a[200005];
long long ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%d", &a[i]);
	int j=1, s=0;
	for(int i=1;i<=n;i++) {
		while((s^a[i])!=s+a[i]) s^=a[j], j++;
		s^=a[i];
		ans+=i-j+1;
	}
	cout<<ans;
}

Measured memory_bytes: 1024
from itertools import combinations
from copy import deepcopy
def main():
    n, m, x = map(int, input().split())
    books = []
    for _ in range(n):
        books.append(list(map(int, input().split())))
    books_pattern = []
    books_num = [i for i in range(n)]
    for i1 in range(1, n + 1):
        books_pattern += list(combinations(books_num, i1))
    skill_set = []

    for ebp in books_pattern:
        skill_pattern = [0] * (m + 1)
        for ebpe in ebp:
            book_e = books[ebpe]
            for i2 in range(m + 1):
                skill_pattern[i2] += book_e[i2]
        skill_set.append(skill_pattern)

    skill_set_ok = []
    for ess in skill_set:
        tess = deepcopy(ess[1:])
        tessc = [i for i in tess if i >= x]
        if len(tessc) == m:
            skill_set_ok.append(ess[0])
    if len(skill_set_ok) > 0:
        print(min(skill_set_ok))
    else:
        print(-1)





if __name__ == '__main__':
    main()


Measured memory_bytes: 11780
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

int main(){
  int N; cin >> N;
  string S; cin >> S;

  vector <int> B(N), W(N);

  for (int i = 0; i < N; i++){
    if (S[i] == '#'){
      if (i == 0) B[i] = 1;
      else B[i] = B[i - 1] + 1;
     }else if(i != 0){
       B[i] = B[i - 1];
     }
  }
  
  for (int i = N - 1; i >= 0; i--){
    if (S[i] == '.'){
      if (i == N - 1) W[i] = 1;
      else W[i] = W[i + 1] + 1;
    }else if(i < N - 1){
      W[i] = W[i + 1];
    }
  }

  int ans = N;
  for (int i = 0; i < N; i++){
    ans = min(ans, W[i] + B[i]);
  }
  cout << ans - 1 << endl;

  return 0;
}

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

const ll MOD = 1'000'000'007;

ll mod(ll val, ll m) {
  ll res = val % m;
  if (res < 0) res += m;
  return res;
}

ll f(ll l, ll r) {
  ll res = (r * (r + 1)) / 2 - ((l - 1) * l) / 2;
  return res;
}

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

  ll res = 0;
  for (ll i = k; i <= n + 1; ++i) {
    ll maxV = f(n - i + 1, n);
    ll minV = f(0, i - 1);
    res = (res + ((maxV - minV + 1) % MOD)) % MOD;
  }
  cout << res << endl;

  return 0;
}


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

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<char>> A(H, vector<char>(W));
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            cin >> A.at(i).at(j);
        }
    }
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            if (A.at(i).at(j) == '#'){
                cout << '#';
            }else{
                int count = 0;
                for (int k = i - 1; k <= i + 1; k++){
                    if (k >= 0 && k < H){
                        for (int l = j - 1; l <= j + 1; l++){
                            if (l >= 0 && l < W){
                                if (A.at(k).at(l) == '#') count++;
                            }
                        }
                    }
                }
                cout << count;
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<queue>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int maxn=100000+10;
struct dong{
	int id,data;
	friend bool operator <(dong a,dong b){
		return a.data>b.data;
	}
} zlt;
struct suan{
	int a,b,c;
	friend bool operator <(suan a,suan b){
		return a.a-a.b>b.a-b.b;
	}
} p[maxn];
priority_queue<dong> s,emp;
ll sum[maxn],num[maxn],ans,cnt;
int i,j,k,l,t,n,m,x,y,z;
int main(){
	scanf("%d%d%d",&x,&y,&z);
	n=x+y+z;
	fo(i,1,n) scanf("%d%d%d",&p[i].a,&p[i].b,&p[i].c);
	sort(p+1,p+n+1);
	cnt=0;
	fo(i,1,x){
		zlt.id=i;
		zlt.data=p[i].a-p[i].c;
		s.push(zlt);
		cnt+=(ll)p[i].a;
	}
	sum[x]=cnt;
	fo(i,x+1,n){
		cnt+=(ll)p[i].a;
		zlt.id=i;
		zlt.data=p[i].a-p[i].c;
		s.push(zlt);
		zlt=s.top();
		s.pop();
		cnt-=(ll)p[zlt.id].a;
		cnt+=(ll)p[zlt.id].c;
		sum[i]=cnt;
	}
	s=emp;
	cnt=0;
	fd(i,n,n-y+1){
		zlt.id=i;
		zlt.data=p[i].b-p[i].c;
		s.push(zlt);
		cnt+=(ll)p[i].b;
	}
	num[n-y+1]=cnt;
	fd(i,n-y,1){
		cnt+=(ll)p[i].b;
		zlt.id=i;
		zlt.data=p[i].b-p[i].c;
		s.push(zlt);
		zlt=s.top();
		s.pop();
		cnt-=(ll)p[zlt.id].b;
		cnt+=(ll)p[zlt.id].c;
		num[i]=cnt;
	}
	ans=0;
	fo(i,x,n-y) ans=max(ans,sum[i]+num[i+1]);
	printf("%lld\n",ans);
}

Measured memory_bytes: 3320
main :: IO ()
main = putChar =<< solve <$> getLine <*> getLine <*> getLine

solve :: String -> String -> String -> Char
solve = go 'a' 
  where
    go 'a' [] _ _ = 'A'
    go 'a' (x:xs) ys zs = go x xs ys zs
    go 'b' _ [] _ = 'B'
    go 'b' xs (y:ys) zs = go y xs ys zs
    go 'c' _ _ [] = 'C'
    go 'c' xs ys (z:zs) = go z xs ys zs


Measured memory_bytes: 508
#include <iostream>
#define MAX 100001
using namespace std;

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

  int count[MAX]={};

  for(int i=1;i<=N;i++){
    int k;
    cin>>k;
    count[k-1]++;
    count[k]++;
    count[k+1]++;
  }

  int max=0;
  for(int i=0;i<MAX;i++){
    if(max < count[i]) max = count[i];
  }
  
  cout<<max<<endl;
  

}


Measured memory_bytes: 640
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int K = nextInt();
		int[] x = nextInts();

		long ans = 0;
		for(int i=0;i<N;i++){
			ans+=Math.min(Math.abs(x[i]-K), x[i])*2;
		}

		System.out.println(ans);

	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

template <typename T>
struct RAQ //calculateはadd(区間加算 not update)
{
    int n;
    const T ex = 0; //初期値
    vector<T> dat, lazy; //tree本体
    RAQ(vector<T> v){
        int x = 1;
        int i;
        n = v.size();
        while(x < n) x <<= 1;
        n = x; 
        dat.resize(2*n-1, ex);
        lazy.resize(2*n-1, ex);
        for(i = 0;i < v.size();++i){
            dat.at(i + n - 1) = v.at(i);
        }
        for(i = n-2;i >= 0;--i){
            dat.at(i) = calculate(dat.at(2*i+1), dat.at(2*i+2));
        }
    }
    
    T calculate(T a, T b){
        return a + b;
    }
    
    void eval(int now){
        if(lazy.at(now) == ex) return;
        if(now < n - 1){
            lazy.at(2*now + 1) += lazy.at(now)/2;
            lazy.at(2*now + 2) += lazy.at(now)/2;
        }
        dat.at(now) += lazy.at(now);
        lazy.at(now) = ex;
    }
    
    void update(int a, int b, T x, int now, int l, int r){
        eval(now);
        if(a <= l && r<= b){
            lazy.at(now) += (r - l)*x; //上から書き換える。
            eval(now);
        }else if(a < r && l < b){
            update(a, b, x, 2*now + 1, l, (l + r)/2);
            update(a, b, x, 2*now + 2, (l + r)/2, r);
            dat.at(now) = calculate(dat.at(2*now + 1), dat.at(2*now + 2));
        }
    }
    void update(int a, int b, T x){update(a, b, x, 0, 0, n);}
    
    T query(int a, int b){return query_sub(a, b, 0, 0, n);}
    T query_sub(int a, int b, int now, int l, int r){
        eval(now);
        if(r <= a || b <= l) return ex;
        else if(a <= l && r <= b) return dat.at(now);
        else{
            T vl = query_sub(a, b, 2*now + 1, l, (l + r)/2);
            T vr = query_sub(a, b, 2*now + 2, (l + r)/2, r);
            return calculate(vl, vr);
        }
    }
};

int main()
{
    ll i,j;
    ll n,q;
    cin >> n >> q;
    vector<ll> a(n, 0);
    RAQ<ll> raq(a);
    for(i = 0;i < q;++i){
        ll com;
        cin >> com;
        if(com == 0){
            ll s,t,x;
            cin >> s >> t >> x;
            raq.update(s-1, t, x);
        }else{
            ll s,t;
            cin >> s >> t;
            cout << raq.query(s-1, t) << endl;
        }
    }
    

    return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N; ll W; cin >> N >> W;
  map<int, vector<ll>> m;
  ll w1;
  rep(_, N) {
    int w, v; cin >> w >> v;
    if (_ == 0) w1 = w;
    m[w].push_back(v);
  }
  for (auto& e: m) {
    sort(e.second.rbegin(), e.second.rend());
    REP(i, 1, e.second.size()) {
      e.second[i] += e.second[i - 1];
    }
  }
  ll ans = 0;
  rep(i, N + 1) rep(j, N + 1 - i) rep(k, N + 1 - i - j) rep(l, N + 1 - i - j - k) {
    if (m[w1 + 0].size() < i) continue;
    if (m[w1 + 1].size() < j) continue;
    if (m[w1 + 2].size() < k) continue;
    if (m[w1 + 3].size() < l) continue;
    if ((w1 + 0) * i + (w1 + 1) * j + (w1 + 2) * k + (w1 + 3) * l > W) continue;
    ans = max(ans, (i ? m[w1 + 0][i - 1] : 0) + (j ? m[w1 + 1][j - 1] : 0) + (k ? m[w1 + 2][k - 1] : 0) + (l ? m[w1 + 3][l - 1] : 0));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3644
#include <iostream>

using namespace std;

int main() {
    int n,k,di,c=0;
    cin>>n>>k;
    int v[n+1]={0};
    for(int i=0;i<k;i++)
    {
        cin>>di;
        int a[di];
        for(int j=0;j<di;j++)
        cin>>a[j];
        for(int j=0;j<di;j++)
        {
            if(v[a[j]]==0)
            {
                v[a[j]]=1;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(v[i]==0)
        c++;
    }
    cout<<c;
}


Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define break break
#define continue continue
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;


int main(void){
	int n; cin >> n;
	double ans = 0.0;
	rep(i, n){
		double val;
		string str;
		cin >> val >> str;
		if(str == "BTC") ans += val * 380000.0;
		else ans += val;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    ll n, a, b;
    cin >> n >> a >> b;

    if (a>b){
        cout << '0' << endl;
        return 0;
    }
    if (n == 1){
        if (a == b) cout << '1' << endl;
        else cout << '0' << endl;
        return 0;
    }
    cout << (b-a)*(n-2) + 1 << endl;
}


Measured memory_bytes: 256
from sys import stdin
def make_divisors(n):
    mod0 = set()
    mod1 = set()
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            mod0.add(i)
            mod0.add(n//i)
        if (n-1)%i==0:
            mod1.add(i)
            mod1.add((n-1)//i)
    return mod0,mod1

N=list(map(int,(stdin.readline().strip().split())))
num=N[0]
K=0
mod0,mod1=(make_divisors(num))
mod0.remove(1)
mod1.remove(1)
for i in mod0:
    num = N[0]
    while(num % i == 0):
        num//=i

    if num%i==1:
        K+=1
K+=len(mod1)
print(K)


Measured memory_bytes: 3828