akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var S = Read();
            var T = Read();

            var a = new int[26];
            var b = new int[26];

            for (int i = 0; i < 26; i++)
            {
                a[i] = -1;
                b[i] = -1;
            }

            for (int i = 0; i < S.Length; i++)
            {
                var s = S[i] - 'a';
                var t = T[i] - 'a';

                if ((a[s] != -1 && a[s] != t) ||
                    (b[t] != -1 && b[t] != s))
                {
                    Println("No");
                    return;
                }
                a[s] = t;
                b[t] = s;
            }

            Println("Yes");
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 13208
N, M = map(int, input().split())

t = [-1] * N
for _ in range(M):
    s, c = map(int, input().split())
    s -= 1
    if t[s] != -1 and t[s] != c:
        print(-1)
        exit()
    t[s] = c

if N == 1 and t[0] == 0:
    print(0)
    exit()

if N == 1 and t[0] == -1:
    print(0)
    exit()

if t[0] == 0:
    print(-1)
    exit()

if t[0] == -1:
    t[0] = 1

for i in range(1, N):
    if t[i] == -1:
        t[i] = 0

print(''.join(map(str, t)))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> sc(M);
  for (int i = 0; i < M; i++) {
    cin >> sc.at(i).first >> sc.at(i).second;
    if (sc.at(i).first == 1 && sc.at(i).second == 0 && N != 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  int Ans = 0;
  int save = 0;
  sort(sc.begin(), sc.end());
  if (M == 0) {
    if (N == 1) {
      cout << 0 << endl;
    } else if (N == 2) {
      cout << 10 << endl;
    } else if (N == 3) {
      cout << 100 << endl;
    }
  } else {
    for (int i = 0; i < M - 1; i++) {
      if ((sc.at(i).first == sc.at(i+1).first) &&
          (sc.at(i).second != sc.at(i+1).second)) {
        cout << -1 << endl;
        return 0;
      }
    }
    if (N == 1) {
      Ans = sc.at(0).second;
    } else if (N == 2)
    {
      if (sc.at(0).first != 1)
      {
        Ans = sc.at(0).second + 10;
      } else
      {
        for (int i = 0; i < M; i++) {
          if (sc.at(i).first == 1) {
            Ans = sc.at(i).second * 10;
          } else if (sc.at(i).first == 2) {
            Ans += sc.at(i).second;
            break;
          }
        }
      }
    } else if (N == 3)
    {
      if (sc.at(0).first != 1)
      {
        Ans = 100;
        for (int i = 0; i < M; i++) {
          if (sc.at(i).first == 2) {
            save = sc.at(i).second * 10;
          } else if (sc.at(i).first == 3) {
            Ans += sc.at(i).second;
            break;
          }
        }
        Ans += save;
      } else
      {
        for (int i = 0; i < M; i++) {
          if (sc.at(i).first == 1) {
            Ans = sc.at(i).second * 100;
          } else if (sc.at(i).first == 2) {
            save = sc.at(i).second * 10;
          } else if (sc.at(i).first == 3) {
            Ans += sc.at(i).second;
            break;
          }
        }
        Ans += save;
      }
    }
    cout << Ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
#define per(i,x,y) for(int i=(x);i>=(y);--i)
using std::sort;
const int N=1e5+10;
int n,c,k,t[N];
int main(){
	scanf("%d%d%d",&n,&c,&k);
	rep(i,1,n)scanf("%d",&t[i]);
	sort(t+1,t+1+n);
	int ans,i;
	for(i=1,ans=0;i<=n;++ans){
		int j;
		for(j=i;j<i+c&&j<=n&&t[j]-t[i]<=k;++j);
		i=j;
	}
	printf("%d",ans);
	return 0;
}


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

int main(){
  int A, B;
  cin >> A >> B;
  
  int a;
  int b;
  int c;
  int d;
  int e;
  int sum = 0;
 
  for (int i=A; i<B+1; i++){
    a = i/10000;
    b = (i-a*10000)/1000;
    c = (i-a*10000-b*1000)/100;
    d = (i-a*10000-b*1000-c*100)/10;
    e = (i-a*10000-b*1000-c*100-d*10);
    
    if ( a == b && a == c && a == d && a == e){
      sum++;
    }
    
    else if (a == e && b == d){
      sum++;
    }    
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
//56
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

#define S(X) ((X)*(X))

int n,hx,hy,dx,dy;
double d[21][21];
double l[21];

bool dfs(int s,double t,int g){
  if(g==(1<<n+1)-1)return true;
  for(int i=1;i<=n;i++){
    if(!(g&1<<i)){
      if(l[i]<t+d[s][i])return false;
    }
  }
  for(int i=1;i<=n;i++){
    if(!(g&1<<i)&&t+d[s][i]<l[i]){
      if(dfs(i,t+d[s][i],g|1<<i))return true;
    }
  }
  return false;
}

int main(){
  while(cin>>n>>hx>>hy>>dx>>dy,n|hx|hy|dx|dy){
    int cx[21]={hx},cy[21]={hy};
    for(int i=1;i<=n;i++){
      cin>>cx[i]>>cy[i];
    }
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	d[i][j]=sqrt(S(cx[i]-cx[j])+S(cy[i]-cy[j]));
      }
    }
    for(int i=1;i<=n;i++){
      l[i]=sqrt(S(dx-cx[i])+S(dy-cy[i]));
    }
    cout<<(dfs(0,0,1)?"YES":"NO")<<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
/*
 * a.c
 *
 *  Created on: 2017/06/13
 *      Author: AWV060608
 */

#include	<stdio.h>

int		main(void)
{
	//W???H???x???y???r

	int		W, H, x, y, r;

	scanf("%d",&W);
	scanf("%d",&H);
	scanf("%d",&x);
	scanf("%d",&y);
	scanf("%d",&r);

	if(( 0 <= x-r ) && ( x+r <= W ))
	{
		if(( 0 <= y-r ) && ( y+r <= H ))
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 584
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
def cumsum(a):
    """※ aを破壊する
    l[i] = sum(a[:i]) なるlを返す
    sum(a[i:j]) == l[j+1] - l[i]
    """
    c = 0
    n = len(a)
    a.insert(0, 0)
    for i in range(1, n+1):
        a[i] = a[i-1]+a[i]
    return a
c = cumsum(a)[1:]
from collections import Counter
cc = Counter(c)
ans = cc[0]
for k,v in cc.items():
    ans += (v-1)*v//2
print(ans)

Measured memory_bytes: 125880
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = N / 100;
    int B = (N / 10) % 10;
    int C = N % 10;
    
    if (A == 7|| B == 7 || C == 7) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

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

int main() {
	int n, mx = 0;
	cin >> n;
	int a[n+1], b[n+1];
	for(int i = 1; i < n+1; i++)
	{
		cin >> a[i];
		b[i] = a[i];
		mx = max(mx, a[i]);
	}
	int c = 0;
	for(int i = 1; i < n+1; i++) if(a[i] == mx) c++;
	
	if(c == 1)
	{
		sort(a+1, a+n+1);
		int mx2 = a[n-1];
		for(int i = 1; i < n+1; i++)
		{
			if(b[i]!= mx) cout << mx << endl;
			else cout << mx2 << endl;
		}
	}
	
	else
	{
		for(int i = 1; i < n+1; i++) cout << mx << endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> v;
ll k; 
void dfs(int d)
{
    if(v.size()==d)
	{
        k--;
        if(k==0)
		{
            for(int tmp=0;tmp<v.size();tmp++)
			cout <<v[tmp];
            cout <<endl;
            exit(0);
        }
        return;
    }
    if(v.empty())
    for(int i=1;i<=9;i++)
	{
        v.push_back(i);
        dfs(d);
        v.pop_back();
    }
    else
    for(int i=v.back()-1;i<=v.back()+1;i++)
	{
        if(i<0||i>9)
		continue;
        v.push_back(i);
        dfs(d);
        v.pop_back();
    }
}

int main()
{
    cin >>k;
    for(ll d=1;;d++)
    dfs(d);
    return 0;
}

Measured memory_bytes: 256
import math
MOD=10**9+7

def powmod(a,p):
  if p==0:
    return 1
  elif p==1:
    return a
  else:
    pow2=powmod(a,p//2)
    if p%2==0:
      return (pow2**2)%MOD
    else:
      return (a*pow2**2)%MOD

def invmod(a):
  return powmod(a,MOD-2)

def comb_mod(n,r):
  nPr=1
  fact_r=1
  for i in range(r):
    nPr*=n-i
    nPr%=MOD
    fact_r*=r-i
    fact_r%=MOD  
  return (nPr*invmod(fact_r))%MOD

N,M=map(int,input().split())
fact={}
for i in range(2,int(math.sqrt(M))+1):
  if M==1:
    break
  while(M%i==0):
    M//=i
    if not i in fact:
      fact[i]=1
    else:
      fact[i]+=1  
if M!=1:
  fact[M]=1
  
#print(fact)
answer=1
for r in fact.values():
  answer*=comb_mod(N+r-1,r)
  answer%=MOD
  
print(answer)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;

ll dp[10000] = {0};

ll lucas(ll n)
{
        if(n == 0) return 2;
        else if(n == 1) return 1;
        else if(dp[n]) return dp[n];
        return dp[n] = lucas(n-1)+lucas(n-2);
}

int main(void)
{
        int n;
        cin >> n;
        cout << lucas(n) << endl;
        return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
int main()
{
 long int x,y,a[100000],i,j,sum,temp;

scanf("%ld%ld",&x,&y);
scanf("%ld",&a[0]);
for(i=1;i<x;i++)
{
    scanf("%ld",&a[i]);
    for(j=0;j<i;j++)
    {
        if(a[j]>a[i])
        {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }
}
sum=0;
for(i=x-1;i>=x-y;i--)
{
    sum+=a[i];
}
printf("%ld",sum);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

ll n;

bool f(ll a[], ll b[])
{
    repf(i,0,n) if(a[i]!=b[i]) return false;
    return true;
}

int main()
{
    IOS;
    cin>>n;
    ll a[n],p[n],q[n];
    repf(i,0,n) a[i]=i+1;
    repf(i,0,n) cin>>p[i];
    repf(i,0,n) cin>>q[i];
    ll x,y;
    ll c=1;
    do
    {
        if(f(a,p))
        {
            x=c;
        }
        if(f(a,q))
        {
            y=c;
        }
        c++;
    }while(next_permutation(a,a+n));
    cout<<abs(x-y)<<endl;
}  

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

#define int long long

void hoge(bool bit[], int x){
  for(int count = 1; x; x/=2) bit[count++] = x%2;
}

signed main(){
  bool bit[40] = {}, bit2[40] = {};
  int a, b;
  
  cin>>a>>b;

  hoge(bit,a); hoge(bit2,b);
  
  for(int i = 32; i; i--) cout<<(bit[i]&bit2[i]);
  cout<<endl;
  for(int i = 32; i; i--) cout<<(bit[i]|bit2[i]);
  cout<<endl;
  for(int i = 32; i; i--) cout<<(bit[i]^bit2[i]);
  cout<<endl;
  
  return 0;
}



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

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

class ARounding {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll x,a;
        in>>x>>a;
        if(x<a) out<<0<<endl;
        else out<<10<<endl;
	}
};


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


Measured memory_bytes: 888
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	int* A = new int[N];
	int score = 0;
	int count = 0;
	for (int i = 0; i < N; i++)
		cin >> A[i];

	
	while (1) {
	for (int i = 0; i < N; i++) {
			if (A[i] % 2 == 0)
				score++;  //2の倍数である要素の数
		}
	if (score == N) { //すべて2の倍数なら
		score = 0; //スコアの初期化
		++count;    //試行できる回数のカウント
			for (int i = 0; i < N; i++)
				A[i] /= 2;
	}
	else break;
}
	cout << count;
}

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



int main() {
    ll n;
    cin >> n;
    
    if(n % 2 == 1)
        cout << 0 << endl;
    else {
        ll cnt = 0, fty = 10;
        while(n >= fty) {
            cnt += n / fty;
            fty *= 5;
        }
        
        cout << cnt << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3592
{-#LANGUAGE FlexibleContexts#-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Reader
import Control.Arrow
-- import Control.Comonad
import Data.Maybe
import Data.List
import Data.Bool
import Data.Fixed
import Data.Tuple
import Data.Ratio
import qualified Data.Map.Strict as M
import qualified Data.Array.IO as IA
import qualified Data.Vector as V

getI = read <$> getLine :: IO Int
getIs = map read . words <$> getLine :: IO [Int]
getD = read <$> getLine :: IO Double
getDs = map read . words <$> getLine :: IO [Double]
getInt = read <$> getLine :: IO Integer
getInts = map read . words <$> getLine :: IO [Integer]

type Row = Integer
type Col = Integer
type PointI = (Integer, Integer)
type Point = (Int, Int)

mmm = 1000000007
fact n
    | n < 1 = 1
    | True = foldr1 (*) [1..n]
ti = toInteger
fi = fromInteger
fig = fromIntegral
rf = realToFrac

(.<.) :: Integer -> Integer -> Integer
(.<.) f g -- combination
    | g < 1 || f < 1 || f < g = 1
    | True = foldr1 (*) (take (fi g) [f,f-1..]) `div` fact g
(.>.) f g --combination with repetition
    | g < 1 || f < 1 = 1
    | True = fact (f + g - 1) `div` (fact (f - 1) * fact g)
comb = (.<.)
combWp = (.>.)

unique a = unique_ (reverse . sort $ a) [] Nothing
    where
        unique_ [] arr _ = arr
        unique_ (x:xs) arr n
            | n == Just x = unique_ xs arr n
            | otherwise = unique_ xs (x:arr) $ Just x
 
zeroume keta num
    | (length . show $ num) > keta = show num
    | otherwise = do 
        let zeros = take keta $ repeat '0'
        reverse . take keta $ (reverse . show $ num) ++ zeros
 
i2b num
    | num < 2 = show num
    | otherwise = i2b_ num []
        where
            i2b_ num str
                | num == 0 = str
                | num == 1 = '1':str
                | otherwise = do
                    let next = num `div` 2
                    let this = if odd num then '1' else '0'
                    i2b_ next (this:str)

mapIncr = mapPlus 1
mapPlus n Nothing = Just n
mapPlus n a = (+) n <$> a

countIf f = length . filter f

enumDivisor :: Int -> [Int]
enumDivisor n = do
    let sqrted = floor $ sqrt (fromIntegral n)
        smaller = filter (\x -> mod n x == 0) [1..sqrted]
        bigger = reverse $ map (div n) smaller
    if head bigger == sqrted then smaller ++ (init bigger)
    else smaller ++ bigger

-- 
--
--

main = do
    n <- getI
    k <- getI
    x <- getI
    y <- getI
    putStrLn . show $ (min (n * x) (k * x)) + (max 0 ((n - k) * y))


Measured memory_bytes: 508
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iterator>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

#define rep(i, n, m) for (int i = n; i <= m; i++)
#define Rep(i, n, m) for (int i = m; i >= 1; i--)

typedef long long ll;

int main() {
    vector<int> an(5);
    vector<int> a1(5);
    rep(i, 0, 4)  {
        cin>> an[i];
        a1[i] = an[i] % 10;
        if (a1[i] == 0) {
            a1[i] = 10;
        }
    }
    int ans = 0, b = 0;
    bool flg = 0;
    decltype(a1)::iterator minf = min_element(a1.begin(), a1.end());
    rep(i, 0, 4) {
        if (a1[i] != *minf) {
            if (a1[i] == 10) {
                ans += (an[i] / 10) * 10;
            } else {
                ans += (an[i] / 10 + 1) * 10;
            }
        } else {
            if (flg == 0) {
                b = an[i];
                flg = true;
            } else {
                if (a1[i] == 10) {
                    ans += (an[i] / 10) * 10;
                } else {
                    ans += (an[i] / 10 + 1) * 10;
                }
            }
        }
    }
    cout << ans + b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s;
    cin >> s;
    ll n = s.size();

    for(ll i = n-2; i >= 2; i -= 2) {
        string t = s.substr(0, i);
        bool ok = true;
        rep(j, i/2) {
            if(t[j] != t[j + i/2]) {
                ok = false;
            }
        }
        if(ok) {
            out(i);
            re0;
        }
    }

    re0;
}

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

int main(){
    int N;
    deque<int> q;

    cin >> N;
    if(N & 1){
        for(int i = 0; i < N; ++i){
            int p;
            cin >> p;
            if(i & 1) q.push_back(p);
            else q.push_front(p);
        }
    }else{
        for(int i = 0; i < N; ++i){
            int p;
            cin >> p;
            if(i & 1) q.push_front(p);
            else q.push_back(p);
        }
    }
    for(auto i : q){
        cout << i << " ";
    }
    cout << endl;
}




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

int main(){
    string s;
    cin >> s;
    ll total;
    if(s=="SUN"){
        total = 7;
    }
    if(s=="MON"){
        total = 6;
    }
    if(s=="TUE"){
        total = 5;
    }
    if(s=="WED"){
        total = 4;
    }
    if(s=="THU"){
        total = 3;
    }
    if(s=="FRI"){
        total = 2;
    }
    if(s=="SAT"){
        total = 1;
    }
    
    cout << total << endl;

    return 0;
}












Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <set>
#include <map>
#define ll long long
#define ull unsigned long long
#define rep(i, to) for(int i = 0; i < (to); ++i)
#define rep1(i, to) for(int i = 1; i <= (to); ++i)
#define ms(x, v) memset(x, v, sizeof(x))
using namespace std;
const int N = 200005;
int pa1[N], pa2[N];
int fpa1(int x){ return pa1[x] == x ? x : pa1[x] = fpa1(pa1[x]); }
int fpa2(int x){ return pa2[x] == x ? x : pa2[x] = fpa2(pa2[x]); }
void lnk1(int x, int y) {x = fpa1(x), y = fpa1(y); if(x != y) pa1[x] = y;}
void lnk2(int x, int y) {x = fpa2(x), y = fpa2(y); if(x != y) pa2[x] = y;}
int ans[N];
vector<int> v[N];
int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
#endif
//    ios::sync_with_stdio(0);
    int n, k, l, a, b;
    while(scanf("%d%d%d", &n, &k, &l) > 0)
    {
        ms(ans, 0);
        rep1(i, n) pa1[i] = pa2[i] = i, v[i].clear();
        rep1(i, k)
        {
            scanf("%d%d", &a, &b);
            lnk1(a, b);
        }
        rep1(i, l)
        {
            scanf("%d%d", &a, &b);
            lnk2(a, b);
        }
        rep1(i, n) v[fpa1(i)].push_back(i);
        rep1(i, n)
        {
            if(v[i].size())
            {
                map<int, int> mp;
                rep(j, (int)v[i].size()) mp[fpa2(v[i][j])]++;
                rep(j, (int)v[i].size())
                {
                    ans[v[i][j]] = mp[fpa2(v[i][j])];
                }
            }
        }
        rep1(i, n) printf("%d ", ans[i]);
        puts("");
    }
    return 0;
}


Measured memory_bytes: 14072
#include <bits/stdc++.h>
using namespace std;
int f(int x)
{
  int flag=0;
  for(int i=2;i<x;i++)
  {
    if(x%i==0){flag=1;break;}
  }
  return flag;
}
int main()
{
  int X,Y;
  cin>>X;
  Y=X;
  while(f(Y)!=0){Y++;f(Y);}
  cout<<Y<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt() * 2;
		if (a <= b) {
			System.out.println(0);
		} else {
			System.out.println(a - b);
		}
	}
}


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

int main(){
    int n;
    cin >> n;
    int v[n];
    for(int i=0; i<n; i++) cin >> v[i];
    sort (v,v+n);
    double ans = v[0];
    for(int i=1; i< n; i++){
        ans = (ans+v[i])/2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

int main(){
    int N,count = 0;
    cin >> N;
    int p[N];
    for(int i=0;i<N;i++)cin >> p[i];
    for(int i=0;i<N-2;i++){
        if(p[i] > p[i+1] && p[i+1] > p[i+2] || p[i] < p[i+1] && p[i+1] < p[i+2])count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
data = {}
while true
  mark, rank = gets.chomp.split(/\s/) rescue break
  data[mark] ||= []
  data[mark][rank.to_i] = 1
end

%w(S H C D).each do |m|
  (1..13).each do |r|
    puts "#{m} #{r}" unless data[m][r]
  end
end

Measured memory_bytes: 8676
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	int minx=0x3fffffff;
	int num=a*x+b*y;
	if(minx>num) minx=num; 
	int num1=min(x,y)*c*2;
	if(x>y) num1+=a*(x-y);
	else num1+=b*(y-x);
	if(minx>num1) minx=num1; 
	int num2=max(x,y)*2*c;
	if(minx>num2) minx=num2; 
	cout<<minx<<endl;
//	cout<<num<<" "<<num1<<" "<<num2; 
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
long long k;
long long c[5100];
int p[5100];
vector <long long> v;
long long find(int x){
	v.clear();
	int now=p[x];
	v.push_back(c[now]);
	while (now!=x){
		now=p[now];
		v.push_back(v[v.size()-1]+c[now]);
	}
//	maxx[0]=v[0];
//	for (int i=1;i<v.size();i++){
//		maxx[i]=max(maxx[i-1],v[i]);
//	}
	long long tmp=-1e18-1,turn=v[v.size()-1];
	for (int i=0;i<v.size();i++){
		if (turn<=0){
			if (k>=i+1) tmp=max(tmp,v[i]);
		}else{
			if (k>=i+1){
					long long xx=v[i]+((k-(i+1))/v.size())*turn;
					tmp=max(tmp,xx);
			}
		}
	}
	return tmp;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>k;
	for (int i=1;i<=n;i++){
		cin>>p[i];
	}
	for (int i=1;i<=n;i++){
		cin>>c[i];
	}
	
	long long ans=-1e18-1;
	for (int i=1;i<=n;i++){
		ans=max(ans,find(i));
	} 
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3748
#include<bits/extc++.h>
#ifdef _debug 
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#include<bits/stdc++.h>
#define dout(i) 0&&0
#endif
#pragma GCC optimize("unroll-loops,no-stack-protector,O3")
#define eout(i) {cout << (i) << '\n';exit(0);}
#define rout(i) {return cout << (i) << '\n', 0;}
#define priority_queue __gnu_pbds::priority_queue
#define unordered_map __gnu_pbds::gp_hash_table
#define rep(a, b) {for(int _i = a;_i > 0;--_i){b;}}
#define multe int _T;for(cin >> _T;_T--;)
using namespace std;
using ll = long long;using ull = unsigned long long;using ul = unsigned;using db = double;
using __gnu_pbds::null_type;
template<typename T> void read(int n, T s){while(n--)cin >> *s, ++s;}
template<typename T> void write(int n, T s){while(n--)cout << *s << " \n"[n==0], ++s;}
template<typename T> using rbtree = __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T> inline ostream& operator << (ostream &ou, const vector<T> &a){for(auto it = a.begin();it != a.end();++it)ou << (it != a.begin() ? " " : "") << *it;return ou;}
template<typename T1, typename T2>inline istream& operator >> (istream &in, pair<T1, T2> &a){return in >> a.first >> a.second;}
template<typename T1, typename T2>inline ostream& operator << (ostream &ou, const pair<T1, T2> &b){return ou << b.first << ' ' << b.second;}
template<typename T> inline long long pow(long long v, long long t, const T &p){long long res = 1;for(;t;t >>= 1, v = v * v % p)if(t & 1)res = res * v % p;return res;}
const int maxn = 300010;
int n, x[maxn], c[maxn];
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	read(n, x+1);
	memcpy(c, x, sizeof x);	
	sort(c+1, c+n+1);
	int mid = n/2;
	for(int i = 1;i <= n;++i){
		if(x[i] > c[mid] || (x[i] == c[mid] and c[mid+1] == c[mid]))cout << c[mid] << '\n';
		else cout << c[mid+1] << '\n';
	}
}

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

int main() {
  int x, y;
  cin >> x >> y;
  int ans = 0;
  if(x == 1) ans += 300000;
  if(y == 1) ans += 300000;
  if(x == 2) ans += 200000;
  if(y == 2) ans += 200000;
  if(x == 3) ans += 100000;
  if(y == 3) ans += 100000;

  if(x == 1 && y == 1) ans += 400000;

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int L,R;
int solve1(){
	int ans=2e9+7;
	for(int i=L;i<=R;i++){
		for(int j=i+1;j<=R;j++){
			ans=min(ans,(i*j)%2019);
		}
	}
	return ans;
}
signed main(){
	scanf("%d %d",&L,&R);
	if(R/2019>L/2019){
		puts("0");
	}
	else {
		printf("%lld",solve1());
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/operators.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	struct max_t
	{
		template<class T>T operator()(T&& lhs, T&& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>T operator()(T&& lhs, T&& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}
}

void Main()
{
	std::string str;
	std::cin >> str;
	std::array<std::int64_t, 2019>count = {};
	int mul = 1, sum = 0;
	for (auto c : str | adaptor::reversed)
	{
		sum += (c - '0') * mul;
		sum %= 2019;
		++count[sum];
		mul *= 10;
		mul %= 2019;
	}
	std::int64_t result = count[0];
	for (auto v : count)
	{
		result += v * (v - 1) / 2;
	}
	std::cout << result << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

// union by size + path having
class UnionFind {
public:
	vector <ll> par; // 各元の親を表す配列
	vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}
};

void solve_abc_e() {
	ll n, m, k;
	cin >> n >> m;
	ll ans = 0;

	V x(m), y(m), z(m);
	UnionFind uf(n);
	rep(i, m) {
		cin >> x[i] >> y[i] >> z[i];
		if (!uf.issame(x[i] - 1, y[i] - 1)) {
			uf.merge(x[i] - 1, y[i] - 1);
		}
	}

	unordered_map<ll, ll> um;
	rep(i, n) {
		um[uf.root(i)]++;
	}

	ans = um.size();

	cout << ans << "\n";
}

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

	solve_abc_e();

	return 0;
}

Measured memory_bytes: 8228
fun main(args:Array<String>){
    val len = readLine()!!.toInt()
    val xs = readLine()!!.split(' ').map(String::toInt)
    val sorted = xs.sortedByDescending { it }
    var ret = 0
    for(i in 0 until len step 2){
        ret += sorted[i] - (if(i + 1 < len) sorted.get(i + 1) else 0)
    }
    print(ret)
}

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

int main(){
  int n; cin>>n;
  vector<int> num(n);
  for(int i=0;i<n;i++){
    cin>>num[i];
  }sort(num.begin(),num.end());
  int a=n/2;
  if(num[a]-num[a-1]==0){
    cout<<0<<endl;
  }else{
    cout<<num[a]-num[a-1]<<endl;
  }
}     

Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

string query(int a, int b) {
    cout << "? " << a << ' ' << b << endl;
    string result;
    cin >> result;
    return result;
}

int main() {
    ios::sync_with_stdio(false);

    int A, B;
    cin >> A >> B;

    if (A <= B) {
        cout << "Impossible" << endl;
        return 0;
    }

    int N = A + B;
    vector<int> chain = {0};

    for (int i = 1; i < N; i++) {
        if (chain.empty())
            chain.push_back(i);
        else if (query(chain.back(), i) == "Y")
            chain.push_back(i);
        else
            chain.pop_back();
    }

    int honest = chain.back();
    string answer(N, '1');

    for (int i = 0; i < N; i++)
        if (i != honest)
            answer[i] = (query(honest, i) == "Y") ? '1' : '0';

    cout << "! " << answer << endl;
}


Measured memory_bytes: 724
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

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

    int N; cin >> N;
    int cur; cin >> cur; cur--;
    int data[N-1]; FOR(i, 1, N) cin >> data[i-1];
    FOR(i, 1, N) {
        int nxt = data[i-1];
        if (nxt > cur) {
            nxt--;
        }
        if (nxt < cur) {
            cout << "No" << endl;
            return 0;
        }
        cur = nxt;
    }

    cout << "Yes" << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343
// license: https://github.com/bqi343/USACO/blob/master/LICENSE

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#define INF 1000000000
using namespace std;
int main() {

	int a, b; cin >> a >> b;
	string aa, bb;
	for (int i = 0; i < b; i++) {
		aa.push_back(a + '0');
	}
	for (int i = 0; i < a; i++) {
		bb.push_back(b + '0');
	}
	if (aa == bb) { cout << aa << endl; return 0; }
	for (int i = 0; i < max(aa.size(), bb.size()); i++) {
		if (aa[i] > bb[i]) { cout << bb << endl; return 0; }
		if (aa[i] < bb[i]) { cout << aa << endl; return 0; }
	}
	if (aa.size() > bb.size()){ cout << bb << endl; return 0; }
	cout << aa << endl; return 0;

	return 0;
}

Measured memory_bytes: 256
//*****Jai Mata di*****//

#include<bits/stdc++.h>
using namespace std;
#define Nitroboost  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int 
const int mod=1e9+7;
const int N=1e5+15;
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl<<flush;

vector<int>adj[N];
int d[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
int h[N];

int main()
{
    Nitroboost;
    int l,r,d;
    cin>>l>>r>>d;
    int d1=(l-1)/d;
    int d2=r/d;
    cout<<d2-d1;
}

Measured memory_bytes: 5940
#include<bits/stdc++.h>
using namespace std;
long long int n,m,a[200010];
long long int ans;
int main(){
	cin>>n;
	int i,j,k;
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	m=n-2;
	ans+=a[n];
	for(i=n-1;i>0;i--){
		if(m==0)break;
		m--;ans+=a[i];
		if(m==0)break;
		m--;ans+=a[i];
	}
	cout<<ans;
} 

Measured memory_bytes: 5184
{-# OPTIONS_GHC -O #-}
import Data.List
import Data.Array.Unboxed

mp = 1000000007

powmod = pd' 1 where
    pd' x _ 0 = x
    pd' x a b
        | odd b = pd' (mod (x*a) mp) a (b-1)
        | otherwise = pd' x (mod (a*a) mp) (div b 2)

facts n = listArray (0,n) $ scanl' (\f n->(mod (f*n) mp)) 1 [1..]
ifacts fs = array (0,n) $ unfoldr psi (n,im) where
    n = snd $ bounds fs
    im = powmod (fs ! n) (mp-2)
    psi (-1,_) = Nothing
    psi (n,im) = Just ((n,im), (n-1, mod (im*n) mp))

cmbmod fs ifs n k = (`mod` mp) $ (* t3) $ (`mod` mp) $ t1*t2 where
    t1 = fs ! n
    t2 = ifs ! k
    t3 = ifs ! (n-k)

main = do
    (h:w:a:b:_)<-map read.words<$>getLine::IO[Int]
    let fs = facts (h+w-2) :: UArray Int Int
    let ifs = ifacts fs :: UArray Int Int
    print $ foldl' (\a x->mod (a+x) mp) 0 $ unfoldr (way fs ifs) (b + (h-a-1), b, a-1 + (w-b-1), w-b-1)
way _ _ (_,_,_,-1) = Nothing
way fs ifs (n1,k1,n2,k2) = Just (mod (w1*w2) mp, (n1+1, k1+1, n2-1, k2-1)) where
    w1 = cmbmod fs ifs n1 k1
    w2 = cmbmod fs ifs n2 k2


Measured memory_bytes: 5372
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n, m; cin >> n >> m;
  int sum = 0;
  for(int i = 0; i < m; i++){
    int a; cin >> a;
    sum += a;
  }
  int ans = n - sum;
  if(ans < 0) ans = -1;
  cout << ans << endl;

  return 0;
}

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

const int Maxm = 287775;
const int lim = 55555;

bool prime[Maxm];
vector <int> pr;
int n;

int main()
{
	fill(prime + 2, prime + Maxm, true);
	for (int i = 2; i < Maxm; i++) if (prime[i]) {
		if (i <= lim && i % 5 == 1) pr.push_back(i);
		for (int j = i + i; j < Maxm; j += i)
			prime[j] = false;
	}
	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++)
		printf("%d%c", pr[i], i + 1 < n? ' ': '\n');
	return 0;
}

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

int k,n,m,kk,rnk[100010],tmp[100010],sa[100010];

bool comp_sa(int i,int j){
	if(rnk[i] != rnk[j]) return rnk[i] < rnk[j];
	else{
		int ri = (i + kk <= n) ? rnk[i + kk] : -1;
		int rj = (j + kk <= n) ? rnk[j + kk] : -1;
		return ri < rj;
	}
}

void const_sa(string s){
	n = s.length();
	for(int i = 0;i <= n;i++){
		sa[i] = i;
		rnk[i] = (i < n) ? s[i] : -1;
	}
	for(kk = 1;kk <= n;kk *= 2){
		sort(sa,sa + n + 1,comp_sa);
		tmp[sa[0]] = 0;
		for(int i = 1;i <= n;i++) tmp[sa[i]] = tmp[sa[i - 1]] + (comp_sa(sa[i - 1],sa[i]) ? 1 : 0);
		for(int i = 0;i <= n;i++) rnk[i] = tmp[i];
	}
}

string s;

bool C(int x){
	int ans = 0,cnt = 0;
	string t = s.substr(sa[x],m);
	while(t.length() != m) t += (char)('0' - 1);
	int flag = 0;
	for(int i = 0;i < n;i++){
		if(s[i] < t[cnt] && !flag) flag = -1;
		if(s[i] > t[cnt] && !flag) flag = 1;
		if(cnt == m - 1 || (flag == 1 && cnt == m - 2) || i == n - 1){
			if(flag == 1 && cnt == m - 1) i--;
			cnt = -1;
			ans++;
			flag = 0;
		}
		cnt++;
	}
	return ans <= k + 1;
}

signed main(){
	cin >> k >> s;
	const_sa(s);
	m = (n + k) / (k + 1);
	if(m == 1){
		char ma = 0;
		for(int i = 0;i < n;i++) ma = max(ma,s[i]);
		cout << ma << endl;
		return 0;
	}
	int low = 0,up = n + 1;
	while(up - low > 1){
		int mid = (up + low) / 2;
		if(C(mid)) up = mid;
		else low = mid;
	}
	cout << s.substr(sa[up],m) << endl;
	return 0;
}

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

struct Graph
{
    int N;
    struct Edge { int source, target, weight; };
    vector<vector<Edge>> adjacency_list;

    Graph(int N) : N(N), adjacency_list(N) {}

    int add_vertex()
    {
        adjacency_list.push_back({});
        return N++;
    }

    void add_edge(int a, int b, int w) { adjacency_list[a].push_back({a, b, w}); }

    int distance(const int start, const int finish) const
    {
        auto seen = vector<bool>(N);
        auto distances = vector<int>(N, -1);

        auto queue = std::priority_queue<pair<int,int>, vector<pair<int, int>>, greater<pair<int, int>>>();
        queue.push({0, start});
        while (!queue.empty())
        {
            auto s = queue.top(); queue.pop();
            if (seen[s.second]) continue;
            seen[s.second] = true;
            distances[s.second] = s.first;

            for (const auto e : adjacency_list[s.second])
                queue.push({s.first+e.weight, e.target});
        }

        return distances[finish];
    }
};

struct Subway { int source, target, company; };

int solve(const int N, const vector<Subway>& subways)
{
    auto graph = Graph(N);

    auto ids = map<pair<int, int>, int>();
    const auto id = [&](int station, int company)
    {
        if (ids.count({station, company})) return ids[{station, company}];
        else
        {
            const auto substation = ids[{station, company}] = graph.add_vertex();
            graph.add_edge(station, substation, 1);
            graph.add_edge(substation, station, 0);
            return substation;
        }
    };

    for (const auto s : subways)
    {
        const auto v = id(s.source, s.company), w = id(s.target, s.company);
        graph.add_edge(v, w, 0);
        graph.add_edge(w, v, 0);
    }

    return graph.distance(0, N-1);
}

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

    auto subways = vector<Subway>();
    for (auto i = 0; i < M; i++)
    {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        subways.push_back({a, b, c});
    }

    cout << solve(N, subways) << endl;
}


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

#define task "E"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (ll i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define db1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define db2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define db3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, n) { cerr << #A << " = "; rep(_, 1, n) cerr << A[_] << ' '; cerr << '\n'; }
#define SZ(x) ((ll)(x).size())
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
string s;
ll k;
ll res;
inline ll C(ll k, ll n)
{
    if (k > n) return 0;
    if (k == 0) return 1;
    if (k == 1) return n;
    if (k == 2) return n * (n - 1) / 2;
    return n * (n - 1) * (n - 2) / 6;
}
inline ll mu(ll k)
{
    if (k == 0) return 1;
    if (k == 1) return 9;
    if (k == 2) return 9 * 9;
    return 9 * 9 * 9;
}
void Solve(ll pos, ll num_l)
{
    if (pos == SZ(s) && num_l > 0)
    {
        res --;
        return;
    }
    if (pos == SZ(s) || num_l == 0) return;
    rep(i, 0, s[pos] - '1') res += C(num_l - (i != 0), SZ(s) - pos - 1) * mu(num_l - (i != 0));
    Solve(pos + 1, num_l - (s[pos] != '0'));
}
int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> s >> k;
	if (SZ(s) < k)
    {
        cout << 0;
        return 0;
    }
	Solve(0, k);
	cout << res + 1;
}


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

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

    map<ll,ll> mp;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }

    ll sum = 0;
    for (auto it : mp) {
        if(it.second <= 1) continue;
        sum += it.second * (it.second - 1) / 2;
    }

    for (int i = 0; i < n; i++) {
        ll val = sum;
        if(mp[a[i]] > 1) {
            ll v = mp[a[i]];
            val -= (v * (v - 1) / 2) - ((v - 1) * (v - 2) / 2);
        }
        cout << val << '\n';
    }

}

Measured memory_bytes: 11008
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }


/*
 update : [s,t) に xを加算
 query  : [s,t) の　最大(小)値を出力する
 */

/* [0..N-1] */
const ll INIT = 0; // 問題に合わせる
struct SegTree {
    int N;
    ll init_v;
    vector<ll> node, lazy;
    
    SegTree(int _N):init_v(INIT) {
        N = 1;
        while (N < _N) N *= 2;
        node.resize(2 * N - 1, init_v);
        lazy.resize(2 * N - 1, init_v);
    }
    
    ll merge(ll l,ll r){
        return min(l,r);
    }
    void build(){
        for(int k = N - 2; k >= 0; k--){
            node[k] = merge(node[2*k+1],node[2*k+2]);
        }
    }
    void direct_update(int k,ll v){
        node[k+N-1] = v;
    }
    
    void lazy_evaluate(int l, int r,int k){
        node[k] += lazy[k];
        if(r - l > 1){
            lazy[2 * k + 1] += lazy[k];
            lazy[2 * k + 2] += lazy[k];
        }
        lazy[k] = 0;
    }
    
    /* [a,b) 引数の範囲に注意!! s~tまでを更新→update(s,t+1,~) */
    void update(int a, int b, ll x) { update(a, b, 0, 0, N, x); }
    void update(int a, int b, int k, int l, int r, ll x) {
        lazy_evaluate(l,r,k);
        if (r <= a || b <= l) return;
        if (a <= l && r <= b) {
            lazy[k] += x;
            lazy_evaluate(l,r,k);
        }
        else {
            update(a, b, 2 * k + 1, l, (l + r) / 2, x);
            update(a, b, 2 * k + 2, (l + r) / 2, r, x);
            node[k] = merge(node[2 * k + 1],node[2 * k + 2]);
        }
    }
    
    /* [a,b) 引数の範囲に注意!! */
    ll query(int a, int b) { return query(a, b, 0, 0, N); }
    ll query(int a, int b, int k, int l, int r) {
        lazy_evaluate(l, r, k);
        if (r <= a || b <= l) return LLONG_MAX; // min : LLONG_MAX , max : LLONG_MIN
        if (a <= l && r <= b) {
            return node[k];
        }
        else {
            ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
            ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return merge(vl, vr);
        }
    }
};

int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    string s,t; cin >> s >> t;

    SegTree ST(n+10);
    vector<ll> dp(n+1);
    
    for(int i = 0; i < n;i++){
        ll minv = INF;
        if(s[i] == t[i]){
            minv = dp[i];
        }
        if(i != 0 && t[i-1] != t[i]){
            ST.update(0,i,1);
        }
        ll Q = ST.query(max(0,i+1-k),i+1);
        minv = min(minv,(Q+1)/2+1);
        ST.update(i+1,i+2,2*minv);
        dp[i+1] = minv;
    }
    cout << dp[n] << endl;
    
    return 0;
}




Measured memory_bytes: 24740
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }


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

	int n;
	cin >> n;

	vector<int> p(n + 1);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (p[i] == i + 1) {
			swap(p[i], p[i + 1]);
			ans++;
		}
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 768
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  n=pI(readline())
  t,a=pM(split(readline()))
  h=[abs(a-t+i*0.006) for i=pM(split(readline()))]
  ans=1
  for i=1:n
    if h[i]<h[ans]
      ans=i
    end
  end
  println(ans)
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 117784