akhauriyash/Code-Regression huggingface dataset:
l,r= list(map(int, input().split()))
if (r-l)//2019>1:
    print(0)
else:
    mi=1000000000
    for i in range(l,r):
        for j in range(i+1,r+1):
            I=i%2019
            J=j%2019
            mi=min(mi,I*J%2019)
    print(mi)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+1;
int A[N],n,cnt,In[N];
int main()
{
    A[0]=11;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
        if(A[i]==i){
            cnt++;
            if(A[i-1]==i-1 && !In[i-1]){
                cnt--;              //swap to adjenct
                In[i]=1;
            }
        }
    }
    printf("%d",cnt);
    return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

char c;

void solve() {
    cin >> c;
    cout << (char)(c + 1);
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


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

const int INF = 1e9;
#define DEBUG(x) cout << "DEBUG PRINT (" << #x << " = " << x  << ")" << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)

struct edge {
  int target;
  int capacity;
  int reversal;
};

void add_edge(vector<vector<edge>> &g, int source, int target, int capacity) {
  g[source].push_back((edge){target, capacity, (int)g[target].size()});
  g[target].push_back((edge){source, 0, (int)g[source].size()-1});
}

int dfs(vector<vector<edge>> &g, vector<bool> &used, int vertex, int target, int flow) {
  if(vertex == target) return flow;
  used[vertex] = true;
  for(int i = 0; i < (int)g[vertex].size(); i++) {
    edge &e = g[vertex][i];
    if(!used[e.target] && e.capacity > 0) {
      int d = dfs(g, used, e.target, target, min(flow, e.capacity));
      if(d > 0) {
        e.capacity -= d;
        g[e.target][e.reversal].capacity += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(vector<vector<edge>> &g, int source, int target) {
  int max_flow = 0;
  while(true) {
    vector<bool> used(g.size(), false);
    int flow = dfs(g, used, source, target, INF);
    if(flow == 0) return max_flow;
    max_flow += flow;
  }
}

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> red(N), blue(N);
  REP(i, N) {
    cin >> red[i].first >> red[i].second;
  }
  REP(i, N) {
    cin >> blue[i].first >> blue[i].second;
  }
  vector<vector<edge>> g(2 * N + 2);
  int source = 2 * N;
  int target = source + 1;
  REP(i, N) {
    add_edge(g, source, i, 1);
    add_edge(g, i + N, target, 1);
  }
  REP(i, N) {
    REP(j, N) {
      if(red[i].first < blue[j].first && red[i].second < blue[j].second) {
        add_edge(g, i, N + j, 1);
      }
    }
  }
  int ans = max_flow(g, source, target);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
	int n,i,j,count=0,max,big,bj;
	cin>>n;
	int a[n];
	for(i=0; i<n; i++)
		cin>>a[i];
	max=a[0];
	for(j=0; j<n; j++)
		if(a[j]>max) max=a[j];
	count++;
	while(big!=-1){
		big=-1;
		bj=0;
		for(j=0; j<n; j++){
			if(a[j]>=max) continue;
			if(a[j]>big){
				bj=1;
				big=a[j];
			}
		}
		if(bj==1){
			max=big;
			count++;
		}
	}
	cout<<count;
}

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

int c[1000005];
int main(){
    int n;
    cin >> n;
    int a[n+1];
    for(int i=0;i<n;i++)cin >> a[i];
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=a[i];j<=a[n-1];j+=a[i])c[j]++;
    }
    for(int i=0;i<n;i++)if(c[a[i]]==1)ans++;
    cout << ans << endl;
}


Measured memory_bytes: 8176
#include <iostream>
 
int main(void){
	int result = 0;
  	int N;
  	std::cin >> N;
  
  	int* array = new int[N];
  
  	for(int i = 0; i < N; ++i){
    	std::cin >> array[i];
    }
  
  	int count = N;
  
  	for(int i = N-1; i > 0; --i){
      for(int j = i-1; j >=0; --j){
     	if(array[i] < array[j]){
          --count;
          break;
        }
      }
    }
          
  	std::cout << count;
    delete array;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,t,x,y,i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d%d",&t,&x,&y);
		if(x+y>t||(x+y+t)%2==1){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

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

bool primeNumber(int n){
    if(n < 2) return false;
    else{
        for(int i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}

signed main() {
  int N;
  cin >> N;
  
  for( int i = N; ; i++ ){
    if( primeNumber(i) == true ){
      cout << i << endl;
      break;
    }
  }
  
    
}


Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.IntMap as IM
import Data.Bool (bool)
import Data.List (mapAccumR)

main :: IO ()
main = do
  [n, m] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    comp0 = IM.empty :: UF
    size0 = IM.empty :: IM.IntMap Int
    f :: [(Int, Int)] -> [Int]
    f = snd . mapAccumR step (comp0, size0)
      where
        step :: (UF, IM.IntMap Int) -> (Int, Int) -> ((UF, IM.IntMap Int), Int)
        step (u, v) (i, j)
          | b
              = ((u', v), 0)
          | otherwise
              = let
                    vi = IM.findWithDefault 1 (snd $ root i u') v :: Int
                    vj = IM.findWithDefault 1 (snd $ root j u') v :: Int
                    (u'', v') = unite i j v u' :: (UF, IM.IntMap Int)
                    vij = v' IM.! (snd $ root j u'')
                    c' = count vij - count vi - count vj
                  in
                    ((u'', v'), c')
          where
            (u', b) = isSame i j u :: (UF, Bool)
  abs <- sequence . replicate m $ unsafeListToPair . map unsafeTextToInt . T.words <$> T.getLine :: IO [(Int, Int)]
  mapM_ print . tail . scanl (+) 0 . f $ abs

count :: Int -> Int
count k = k * pred k `div` 2
{-# INLINE count #-}

type UF = IM.IntMap Int

parent :: Int -> UF -> Maybe Int
parent = IM.lookup
{-# INLINE parent #-}

root :: Int -> UF -> (UF, Int)
root i u = maybe (u, i) (\j -> let (u', j') = root j u in (bool (IM.insert i j' u') u (j' == j), j')) (parent i u)
{-# INLINE root #-}

unite :: Int -> Int -> IM.IntMap Int -> UF -> (UF, IM.IntMap Int)
unite i j v u | i' == j'  = (u'', v)
              | otherwise = (IM.insert j' i' u'', v')
  where
    (u', i') = root i u
    (u'', j') = root j u'
    v' = IM.insert i' (vi + vj) v
      where
        vi = IM.findWithDefault 1 i' v :: Int
        vj = IM.findWithDefault 1 j' v :: Int
{-# INLINE unite #-}

isSame :: Int -> Int -> UF -> (UF, Bool)
isSame i j u = (u'', i' == j')
  where
    (u', i') = root i u
    (u'', j') = root j u'
{-# INLINE isSame #-}

unsafeListToPair :: [a] -> (a, a)
unsafeListToPair [x, y] = (x, y)
{-# INLINE unsafeListToPair #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 435580
#include <stdio.h>


int
main(void)
{
	int X, A, B;
	scanf("%d %d %d", &X, &A, &B);

	if (A >= B)
		puts("delicious");
	else if (B - A <= X)
		puts("safe");
	else
		puts("dangerous");
	return 0;
}

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

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r)
{
	if (l >= r)return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l, m);
	rec(m + 1, r);
	post.push_back(root);
}

void solve()
{
	pos = 0;
	rec(0, pre.size());
	for (int i = 0; i < n; ++i)
	{
		if (i)putchar(' ');
		cout << post[i];
	}
	putchar('\n');
}

int main()
{
	int k;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> k;
		pre.push_back(k);
	}
	for (int i = 0; i < n; ++i)
	{
		cin >> k;
		in.push_back(k);
	}
	solve();
	return 0;
}


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

using namespace std;
typedef long long ll;
using Graph =vector<int>;
typedef pair<ll,int> P;

const ll MAX_N=131072;
int bit[MAX_N*2-1];
ll n;
int main(){
  int a,b,h;cin>>a>>b>>h;
  cout<<((a+b)*h)/2<<endl;
}


Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return len(divisors)

n=int(input())
ans=0

for i in range(1,n+1,2):
    if make_divisors(i)==8:
        ans+=1

print(ans)

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

int main() {
	int n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	for (int i = k; i < n; i++) {
		if (a[i - k] < a[i]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

struct mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    bool operator <(const mint& r){return this->x<r.x;}
    bool operator ==(const mint& r){return this->x==r.x;}
    bool operator !=(const mint& r){return this->x!=r.x;}
    void operator++() {
        x++;
    }
    void operator--() {
        x--;
        if(x<0) x += mod;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

int main(){
  mint N;
  cin>>N.x;
  string S;
  cin>>S;
  vector<int> v(N.x*2);
  rep(i,N.x*2){
    if(S[i] == 'B') v[i] = 0;
    else v[i] = 1;
  }
  mint ans = 0;
  if(v[0] == 0&& v[N.x*2-1] == 0){
    vector<int> t(N.x * 2);
    t[0] == 0;
    rep(i,N.x*2-1){
      if(v[i+1]!=v[i]) t[i+1] = t[i];
      else t[i+1] = 1-t[i];
    }
    ll check = 0;
    rep(i,N.x*2) check += t[i];
    if(check == N.x){
      if(t[N.x*2-1]==1) {
        mint cnt = 0;
        ans = 1;
        rep(i,N.x * 2){
          cnt += t[N.x*2-1-i];
          if(t[N.x*2-1-i]==0) {
            ans*=cnt;
            --cnt;
          }
        }
        rep(i,N.x) ans *= (mint)(i+1);
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5152
#include <stdio.h>

int main(){
  int x,y,a;

  scanf("%d%d",&x,&y);

  if(x<y){
    a=y;
    y=x;
    x=a;
  }

  while(1){
    a=x%y;
    if(a==0){
      printf("%d\n",y);
      break;
    }
    x=y;
    y=a;
  }
    
  return 0;
}



Measured memory_bytes: 2128
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,k;//要开long long 
ll ans,t;
int main(){
	scanf("%d%d",&n,&k);
	ans=n/k;
	ans=ans*ans*ans;
	if(k%2==0)t=(n+k/2)/k,t=t*t*t;
	cout<<ans+t;
	return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using M = map<string,ll>;





int main(){
    int N;
    cin >> N;
    vector<ll> A(N+1,0);
    vector<ll> B(N+1,0);
    for(int i=1;i<N+1;i++){
        cin>>A[i]>>B[i]
    ;}
    vector<P> pai(N+1);
    for(int i=1;i<N+1;i++){
        pai[i]=P(B[i],A[i])
    ;}
    sort(pai.begin(), pai.end());
    ll check=0;
    bool ans=1;
    for(int i=1;i<N+1;i++){
        check+=pai[i].second;
        if(check>pai[i].first){ans=0;break;}
    ;}
    if(ans==0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;

return 0;


}  



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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{

  int x;
  cin >> x >> a >> b;
  pr(((x - a) % b));
}

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

int main(){
  string s;
  cin >> s;
  bool ans = true;
  if (s.at(0)=='A' && s.at(1) =='A'&& s.at(2)=='A'){
    ans = false;
  }
  if (s.at(0)=='B' && s.at(1) =='B' && s.at(2)=='B'){
    ans = false;
  }
  cout <<(ans ? "Yes":"No")<<endl;
  return 0;
  
  
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{

	public static void main(String[] args) {
		try (Scanner scTmp = new Scanner(System.in);) {

			int iCount = scTmp.nextInt();

			int iTmp[] = new int[iCount];

			IntStream.rangeClosed(0, iCount - 1).forEach(i -> iTmp[i] = scTmp.nextInt());
	
			int iAve = (int) Math.round(Arrays.stream(iTmp).average().getAsDouble());

			System.out.println(Arrays.stream(iTmp).map(i -> (iAve - i) * (iAve - i)).sum());

		}
	}
}

Measured memory_bytes: 26964
//Night's template
//orzakyrt
#include <bits/stdc++.h>
#define R register
#define LL long long
#ifdef __DEBUG__
	#define Debug (fprintf(stderr,"orzyrt\n"),fflush(stderr))
	#define debug(__a...) (fprintf(stderr,__a),fflush(stderr))
	#define setfile(__a) ('orzyrt')
	#define Compile(__a) system("g++ "__a".cpp -lm -o "__a)
#else
	#define Debug ('orzyrt')
	#define debug(__a...) ('orzyrt')
	#define setfile(__a) freopen(__a".in","r",stdin);freopen(__a".out","w",stdout)
	#define Compile(__a) ('orzyrt')
#endif
template<class TT>inline TT Max(R TT a,R TT b){return a<b?b:a;}
template<class TT>inline TT Min(R TT a,R TT b){return a<b?a:b;}
template<class TT>inline TT Abs(R TT a){return a<0?-a:a;}
template<class TT>inline TT cmin(R TT &a,R TT b){(b<a)&&(a=b);}
template<class TT>inline TT cmax(R TT &a,R TT b){(a<b)&&(a=b);}
using namespace std;
template<class TT>inline void read(R TT &x){
	x=0;R bool f=false;R char c=getchar();
	for(;c<48||c>57;c=getchar())f|=(c=='-');
	for(;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	(f)&&(x=-x);
}
//end template

namespace Night{
	const int maxn = 1000010;
	int n;
	char s[maxn];
	int a[maxn];
	int main(){
		read(n);
		scanf("%s",s+1);
		int q;
		read(q);
		for(R int k;q--;){
			read(k);
			R LL cd=0,cm=0,cdm=0;
			R LL ans=0;
			for(R int i=1;i<=n;++i){
				if(i>k){
					if(s[i-k]=='D'){
						--cd;
						cdm-=cm;
					}else if(s[i-k]=='M'){
						--cm;
					}
				}
				if(s[i]=='D'){
					++cd;
				}else if(s[i]=='M'){
					++cm;
					cdm+=cd;
				}else if(s[i]=='C'){
					ans+=cdm;
				}
			}
			printf("%lld\n",ans);
		}
		return 0;
	}
}
int main(){
	return Night::main();
}

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

using namespace std;

///dir array for Queen int dxq[10] = {-1,-1,-1,1,1,1,0,0};
///dir array for Queen int dyq[10] = {-1,0,1,-1,0,1,-1,1};
///dir array for knight int dxk[10] = {-2,-2,-1,-1,1,1,2,2};
///dir array for knight int dyk[10] = {1,-1,-2,2,-2,2,-1,1};

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b,ans;
    while(cin>>a>>b){
        cout<<max((a*b),max((a+b),(a-b)))<<endl;
    }


}


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

class Dmondai {
    static void Main()
    {
        var line = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var N = line[0];
        var M = line[1];
        var A= Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).OrderBy(x=>x).ToArray();
        var cost = new int[] { 2,5,5,4,5,6,3,7,6};
        var dp = new int[N+1];
        dp[0] = 0;
        for (int i = 1; i <= N; ++i) dp[i] = int.MinValue;
        for (int i=0;i<=N;++i)
        {
            if (i != 0 && dp[i] == int.MinValue) continue;
            for (int j=0;j<M;++j)
            {
                if (N < i + cost[A[j] - 1]) continue;
                dp[i+cost[A[j] - 1]] = dp[i]+1;
            }
        }
        var ans = string.Empty;
        for (int i=N;0<i;)
        {
            for (int j=M-1;-1<j;--j)
            {
                if (i - cost[A[j] - 1] < 0) continue;
                if (dp[i - cost[A[j] - 1]] == dp[i]-1) {
                    ans += A[j];
                    i = i - cost[A[j] - 1];
                    break;
                }
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 27220
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        var c = int.Parse(line[2]);
        var k = int.Parse(Console.ReadLine().Trim());
        var ret = 0;  
        for (int i = 0; i <= k; i++)
            for (int j = 0; j <= k -i; j++)
                for (int L= 0; L<=  k -i -j; L++)
                {
                    var w = (int)a * Math.Pow(2, i) + (int)b * Math.Pow(2, j) + (int)c * Math.Pow(2, L);
                    ret = (int) Math.Max(w, ret);
                }
        Console.WriteLine(ret);
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
#include <algorithm>
#include <vector>
#pragma warning(disable:4996)

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

int main(int argc, char* argv[])
{
    long n;
    char str[105]={0};
    scanf("%ld", &n);
    scanf("%s", str);


    long i;
    long max=0;
    for(i=0; i<=n; i++) {
        long a[30]={0};
        long b[30]={0};
        long k;
        for(k=0; k<n; k++) {
            if(k<i)
                a[str[k]-'a']++;
            else
                b[str[k]-'a']++;
        }
        long count=0;
        for(k=0; k<26; k++) {
            if(a[k] && b[k])
                count ++;
        }
        if(max<count)
            max=count;
    }
    
    printf("%ld\n", max);
    return 0;
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    ll cnt_odd = 0,cnt_four=0,cnt_two=0;
    for(i=0;i<n;i++){
        ll x;
        cin >> x;
        if(x%2)cnt_odd++;
        else{
            if(x%4==0)cnt_four++;
            else cnt_two++;
        }
    }
    if(cnt_four>=cnt_odd+(cnt_two>0)-1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
N,A,B = map(int,input().split())
s = 0
j = 0
for i in range(1,N+1):
  j = i
  x0 = j // 10000
  j -= x0 * 10000
  x1 = j // 1000
  j -= x1 * 1000
  x2 = j // 100
  j -= x2 * 100
  x3 = j // 10
  j -= x3 * 10
  x4 = j
  if (A <= x0 + x1 + x2 + x3 + x4 and B >= x0 + x1 + x2 + x3 + x4):
    s += i
print(s)


Measured memory_bytes: 3060
#import<bits/stdc++.h>

           using
         namespace
         std;;long
        long N,a,b,
        n,i,j=0;long
       long s[2];main
       (){j   ++;scanf
      ("       %lld",&N
     );--      j;scanf(
    "%lld       %lld",s,
    s+1);       for(i=1;i
   < N; i       ++){scanf(
   "%lld%lld",&a,&b);n=max
  (((s[0]-1)/a+1),((s[1]-1)/
  b+1));         *s=a*n;s[1]
 =b*n;}           cout<<s[0]
+s[1]<<            endl;j++;}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N=readLine()!!.toLong()
    val sq = Math.sqrt(N.toDouble()).toLong()
    var sum = 0.toLong()
    for(i in 1 .. sq){
        if(N%i==0L){
            if(N/i-1>i){
                sum+=N/i-1
            }
        }
    }
    print(sum)
}

Measured memory_bytes: 31836
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

//
void no_cost_graphmake(ll E,vector<vector<ll>> &G){
  rep(i,E){
    ll a,b;
    cin >> a >> b;
    G.at(a-1).push_back(b-1);
    G.at(b-1).push_back(a-1);
  }
}

int main(){
  ll N,Q;
  cin >> N >> Q;
  vector<vector<ll>> G(N,vector<ll>(0));
  no_cost_graphmake(N-1,G);
  vector<ll> A(N,0);
  rep(i,Q){
    ll p,x;
    cin >> p >> x;
    A.at(p-1)+=x;
  }
  queue<ll> Queue;
  vector<ll> U(N,0);
  Queue.push(0);
  U.at(0)=1;
  while(!Queue.empty()){
    ll i=Queue.front();
    Queue.pop();
    rep(j,G.at(i).size()){
      if(U.at(G.at(i).at(j))==0){
        A.at(G.at(i).at(j))+=A.at(i);
        Queue.push(G.at(i).at(j));
        U.at(G.at(i).at(j))=1;
      }
    }
  }
  rep(i,N){
    cout << A.at(i) << " ";
  }
  cout << endl;
}


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

void call(int n) {
  int i = 1;

  for (int x = i; i <= n; i++, x = i) {
    if (x % 3 == 0) {
      cout << " " << i;
      continue;
    }

    do {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
      x /= 10;
    } while (x);
  }

  cout << endl;
}

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

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

const int N = 20;

int n, A[N];
std::map<std::pair<int, int>, long long> map[N][N];

long long dfs(int l, int r, int L, int R) {
  if (r == l + 1) return 0;
  if (map[l][r].count({ L, R }))
    return map[l][r][{ L, R }];
  long long ret = 1e18;
  for (int k = l + 1; k < r; ++k)
    ret = std::min(ret, dfs(l, k, L, L + R) + dfs(k, r, L + R, R)
      + 1ll * (L + R) * A[k]);
  return map[l][r][{ L, R }] = ret;
}

int main() {
  std::cin >> n;
  for (int i = 1; i <= n; ++i)
    std::cin >> A[i];
  std::cout << dfs(1, n, 1, 1) + A[1] + A[n] << std::endl;
  return 0;
}


Measured memory_bytes: 16512
import sys

for line in sys.stdin:
    n = ''
    lis = []
    for c in line.rstrip():
        if c.isdigit() or c == 'X':
            n += c
        elif c == '+':
            lis.append(n)
            n = ''
        elif c == '=':
            lis.append(n)
            n = ''
    else:
        lis.append(n)
     
    c_lis = lis[:]   
    for n in range(10):
        for i, v in enumerate(lis):
            if 'X' in v:
                c_lis[i] = c_lis[i].replace('X', str(n))
        else:
            flag = False
            if n == 0:
                for v in c_lis:
                    if len(v) >= 2 and v[0] == '0':
                        flag = True
                        break
            if not flag:
                if int(c_lis[0]) + int(c_lis[1]) == int(c_lis[2]):
                    print n
                    break
            c_lis = lis[:]
    else:
        print 'NA'

Measured memory_bytes: 4284
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

map<string, int> wt;
int mol(string s) {
	int k, i, sum = 0;
	k = 0;
	while (k < s.size()) {
		int w, n = 1;
		if (s[k] == '(') {
			int nest = 0;
			i = 0;
			k++;
			while (1) {
				if (s[k + i] == '(') nest++;
				if (s[k + i] == ')') {
					if (nest == 0) {
						w = mol(s.substr(k, i));
						if (w == -1) return -1;
						break;
					}
					nest--;
				}
				i++;
			}
			k += i + 1;
			if ('0' <= s[k] && s[k] <= '9') {
				i = 1;
				while (k + i < s.size() && '0' <= s[k + i] && s[k + i] <= '9') i++;
				n = stoi(s.substr(k, i));
				k += i;
			}
			sum += w * n;
		}
		else {
			if (k + 1 < s.size() && 'a' <= s[k + 1] && s[k + 1] <= 'z') {
				if(wt.find(s.substr(k, 2)) == wt.end()) return -1;
				w = wt[s.substr(k, 2)];
				k += 2;
			}
			else {
				if (wt.find(s.substr(k, 1)) == wt.end()) return -1;
				w = wt[s.substr(k, 1)];
				k++;
			}
			if ('0' <= s[k] && s[k] <= '9') {
				i = 1;
				while (k + i < s.size() && '0' <= s[k + i] && s[k + i] <= '9') i++;
				n = stoi(s.substr(k, i));
				k += i;
			}
			sum += w * n;
		}
	}
	return sum;
}
int main() {
	while (1) {
		string s;
		cin >> s;
		if (s == "END_OF_FIRST_PART") break;
		int n;
		cin >> n;
		wt[s] = n;
	}
	while (1) {
		string s;
		cin >> s;
		if (s == "0") break;
		int n;
		n = mol(s);
		if (n == -1) cout << "UNKNOWN" << endl;
		else cout << n << endl;
	}
	return 0;
}





Measured memory_bytes: 3184
# WIP
import sys
sys_input = sys.stdin.readline

N = int(input())
AAA = list(map(int, sys_input().split()))
AAA = [0] + AAA + [0]

basic_cost = sum([abs(AAA[i + 1] - A) for i, A in enumerate(AAA[:N + 1])])

for i, A in enumerate(AAA[:N + 1]):
    if i == 0:
        continue
    adjusted_cost = basic_cost - abs(A - AAA[i-1]) - abs(A - AAA[i+1]) + \
        abs(AAA[i+1]-AAA[i-1])
    print(adjusted_cost)


Measured memory_bytes: 13924
N = int(input())
a = list(map(int,input().split()))

d = {}
for i in range(N):
  if(a[i] not in d):
    d[a[i]] = 1
  else:
    d[a[i]] += 1
cnt = 0
for k, v in d.items():
  if(k > v):
    cnt += v
  elif(k < v):
    cnt += v - k
print(cnt) 

Measured memory_bytes: 17780
#include<stdio.h>
typedef struct{
  char c;
  int n;
}kard;

void quicksort(kard *,int,int);
int partition(kard *,int,int);
int main(){
  int n,i,j,k;
  kard K[100000],B[100000];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c %d",&K[i].c,&K[i].n);
    B[i]=K[i];
  }
  
  quicksort(K,0,n-1);
  //はんてい
  i=j=k=0;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(B[j].n==K[i].n){
	if(B[j].c==K[i].c){
	  if(K[i].n==K[i+1].n&&i<n-1){i++;continue;}
	}else goto NS;
      }
    }
  }
  
  printf("Stable\n");
  goto END;
 NS:
  printf("Not stable\n");
 END:
  for(i=0;i<n;i++)printf("%c %d\n",K[i].c,K[i].n);
  
  return 0;
}
void quicksort(kard *k,int p,int r){
  int q;
  if(p<r){
    q=partition(k,p,r);
    quicksort(k, p, q-1);
    quicksort(k, q+1, r);
  }
}
int partition(kard *k,int p,int r){
  int i,j;
  kard ch,x;
  x=k[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(k[j].n<=x.n){
      i++;
      ch=k[i];
      k[i]=k[j];
      k[j]=ch;
    }
  }
  ch=k[i+1];
  k[i+1]=k[r];
  k[r]=ch;
  return i+1;
}



Measured memory_bytes: 3292
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

//********************************template END****************************************//

void solve(void){
	int N, M;
	cin >> N >> M;
	if (N+M==15)
	{
		cout << "+" << endl;
		return;
	}
	if (N*M==15)
	{
		cout << "*" << endl;
		return;
	}
	cout << "x" << endl;
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 764
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    auto c = new string[](2);
    c[0] = readln.chomp;
    c[1] = readln.chomp;
    writeln(equal(c[0], c[1].retro) ? "YES" : "NO");
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N;
	cin >> N;
	vector<int> h( N );
	for( int i = 0; i < N; i++ ) {
		cin >> h[i];
	}

	int ans = 0;
	while( 1 ) {
		int l = -1;
		int r = -1;
		for( int i = 0; i < N; i++ ) {
			if( h[i] > 0 ) {
				l = i;
				break;
			}
		}
		if( l < 0 ) break;
		for( int i =  l + 1; i < N; i++ ) {
			if( h[i] == 0 ) {
				r = i;
				break;
			}
		}
		if( r < 0 ) r = N;
		const int INF = 101;
		int mi = INF;
		for( int i =  l; i < r; i++ ) {
			if( mi > h[i] ) mi = h[i];
		}
		for( int i =  l; i < r; i++ ) {
			h[i] -= mi;
		}
		ans += mi;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    lint N, L;
    cin >> N >> L;
    lint ans = 0, minimum = 1e18;
    lint all = 0;
    for(int i = 0; i < N; i++){
        all += L + i;
    }
    for(int i = 0; i < N; i++){
        lint sum = 0;
        for(int j = 0; j < N; j++){
            sum += (i != j) * (L + j);
        }
        if(minimum > abs(all - sum)){
            minimum = abs(all - sum);
            ans = sum;
        }
    }
    cout << ans << endl;
}


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

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

  for (int i = 0; i < N; i++) {
    cout << S.at(i) << T.at(i);
  }

  cout << endl;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
from collections import deque

h, w = map(int, input().split())
maze = [[i == "#" for i in input()] for _ in range(h)]

dx = [1, 0]
dy = [0, 1]

que = deque([])
que.append((0, 0, maze[0][0], 1 if maze[0][0] else 0))
count = [[h + w] * w for _ in range(h)]

while que:
    x, y, b, c = que.pop()
    if c >= count[x][y]:
        continue
    count[x][y] = c
    if x == h - 1 and y == w - 1:
        continue
    for i in range(2):
        nx = x + dx[i]
        ny = y + dy[i]

        if not (0 <= nx < h and 0 <= ny < w):
            continue
        que.append((nx, ny, maze[nx][ny], c + (not b and maze[nx][ny])))
print(count[h - 1][w - 1])


Measured memory_bytes: 9524
/**
 * @author: Jun
 * @date  : 03-18-2019
 **/
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define el '\n'
#define MOD 1000000007

string s;
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> s;
    stack<char> g;
    for(int i=0;i<s.length();i++){
            if(s[i]!='B'){
                g.push(s[i]);
            } else {
                if(!g.empty()){
                    g.pop();
                }
            }
    }
    string res="";
    while(!g.empty()){
        res += g.top();
        g.pop();
    }
    for(int i=res.length()-1;i>=0;i--){
        cout << res[i];
    }
    return 0;
}

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

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

int w, h;
inline bool get(ll S, int y, int x) {
  return S>>(y*w+x)&1;
}
inline ll bit(int y, int x) {
  return 1LL<<(y*w+x);
}
inline bool valid(int y, int x) {
  return !(y<0||y>=h||x<0||x>=w);
}
inline bool ok(ll S, int y, int x) {
  if (!valid(y,x)) return 0;
  if (get(S,y,x)) return 0;
  return 1;
}
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
int sy,sx;
ll adj[7][7];
ll hline[3][7];
ll vline[3][7];

bool dfs(ll S, int y, int x, int num) {
  // cout << y << "," << x << "," << num << endl;
  // REP(i,h) {
  //   REP(j,w) cout << get(S,i,j);
  //   cout << endl;
  // }
  if (num == 0) return abs(y-sy)+abs(x-sx) == 1;
  // 上下の分裂
  if ((hline[0][y]&S) == hline[0][y]) {
    if ((hline[1][y]&S) != hline[1][y] &&
        (hline[2][y]&S) != hline[2][y]) return 0;
  }
  // 左右の分裂
  if ((vline[0][x]&S) == vline[0][x]) {
    if ((vline[1][x]&S) != vline[1][x] &&
        (vline[2][x]&S) != vline[2][x]) return 0;
  }
  // スタート地点に戻れない
  if ((adj[sy][sx]&S)==adj[sy][sx]) return 0;
  // 今のセルと隣接しているセルで袋小路になっている
  ll T = S&~bit(sy,sx)&~bit(y,x);
  REP(k,4) {
    int yy=y+dy[k];
    int xx=x+dx[k];
    if (ok(S,yy,xx)) {
      if (__builtin_popcount(adj[yy][xx]&T) >= 3) return 0;
    }
  }
  REP(k,4) {
    int yy=y+dy[k];
    int xx=x+dx[k];
    if (!ok(S,yy,xx)) continue;
    if (dfs(S|bit(yy,xx),yy,xx,num-1)) return 1;
  }
  return 0;
}

int main() {
  while(cin>>w>>h, h||w) {
    ll S = 0;
    int num = 0;
    int d[2]={};
    REP(i,h)REP(j,w) {
      int a; cin >> a;
      if (a) S |= bit(i,j);
      else {
        ++num;
        sy=i,sx=j;
        d[(i+j)&1]++;
      }
    }
    if (d[0]!=d[1] || num <= 3) {
      puts("No");
      continue;
    }
    memset(hline,0,sizeof(hline));
    REP(i,h) {
      REP(j,w) hline[0][i] |= bit(i,j);
      REP(k,i) REP(j,w) hline[1][i] |= bit(k,j);
      for (int k=i+1; k<h; ++k) REP(j,w) hline[2][i] |= bit(k,j);
    }
    memset(vline,0,sizeof(vline));
    REP(j,w) {
      REP(i,h) vline[0][j] |= bit(i,j);
      REP(k,j) REP(i,h) vline[1][j] |= bit(i,k);
      for (int k=j+1; k<w; ++k) REP(i,h) vline[2][j] |= bit(i,k);
    }
    memset(adj,0,sizeof(adj));
    REP(i,h)REP(j,w) {
      REP(k,4) {
        int ii=i+dy[k];
        int jj=j+dx[k];
        if (valid(ii,jj)) adj[i][j] |= bit(ii,jj);
      }
    }
    S |= bit(sy,sx); --num;
    cout << (dfs(S,sy,sx,num)?"Yes":"No") << endl;
  }
}

Measured memory_bytes: 1164
#include <iostream>
#include <cstdio>
#pragma warning(disable:4996)
using namespace std;

int main()
{
	int n; scanf("%d", &n);
	long long ans = 0;
	int k1 = n / 500;
	ans += k1 * 1000;
	n %= 500;
	ans += 5 * (n / 5);
	/*ans += 100 * (n / 100);
	n %= 100;
	ans += 50 * (n / 50);
	n %= 50;
	ans += 10 * (n / 10);
	n %= 10;
	ans += n;*/
	printf("%lld", ans);
	
	return 0;
}

Measured memory_bytes: 256
// dijkstra algorithm with priority queuec
// reference Programming Contest Challenge Book Second Edition
//verify https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/1/GRL_1_A
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;

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

template<typename T> struct edge {
  int to;
  T cost;
  edge (int to_,T cost_) : to(to_),cost(cost_) {}
};

template<typename T,template <typename ELEM> class C> struct Dijkstra {
  vector<vector<C<T>>> G;
  int V;
  T INF;
  using P = pair<T,int>;

  Dijkstra (int V_, T INF_ = 1e9) {
    init(V_,INF_);
  }

  void init(int V_,T INF_ = 1e9) {
    V = V_;
    INF = INF_;

    G.clear();
    G.resize(V);
  }

  void add_edge_directed(int from,int to,T cost) { // Directed Edge!!
    G[from].push_back(C<T>(to,cost));
  }

  void add_edge_non_directed(int from,int to,T cost){
    add_edge_directed(from,to,cost);
    add_edge_directed(to,from,cost);
  }

  void shortest_path(int s,T *d) {
    priority_queue<P,vector<P>,greater<P>> que;

    fill(d,d+V,INF);
    d[s] = 0; 
    que.push(P(0,s));

    while(!que.empty()) {
      P p = que.top(); que.pop();
      int v = p.second;

      if (d[v] < p.first) continue;

      for (auto e : G[v]) {
        if (d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};

using ll = long long;

ll d[100010];

int main() {
  ll V,E,r;
  cin >> V >> E >> r;
  Dijkstra<ll,edge> dijkstra(V);
  rep(i,E) {
    ll s,t,d;
    cin >> s >> t >> d;
    dijkstra.add_edge_directed(s,t,d);
  }

  dijkstra.shortest_path(r,d);

  rep(i,V) 
    if(d[i] < 1e9)
      cout  << d[i] << endl;
    else 
      cout << "INF" << endl;
  return 0;
}



Measured memory_bytes: 19288
n=input()
m=input()
alphabet={'a':1,'b':2,'c':3,'d':4,'e':5,'f':6,'g':7,'h':8,'i':9,'j':10,'k':11,'l':12,'m':13,'n':14,'o':15,'p':16,'q':17,'r':18,'s':19,'t':20,'u':21,'v':22,'w':23,'x':24,'y':25,'z':26}
a=[]
for i in range(len(n)):
  a.append(alphabet[n[i]])
a.sort()
b=[]
for i in range(len(m)):
  b.append(alphabet[m[i]])
b.sort(reverse=True)

for i in range(min(len(n),len(m))):
  if a[i]<b[i]:
    print('Yes')
    exit()
if len(n)<len(m):
  for i in range(len(n)):
    if a[i]>b[i]:
      print('No')
      exit()
  print('Yes')
  exit()
print('No')

Measured memory_bytes: 3188
from collections import deque



def main():
    S = input()
    Q = int(input())

    order = 1

    ans = deque()
    for i in range(len(S)):
        ans.append(S[i])

    for i in range(Q):
        tfc = list(map(str, input().split()))

        if tfc[0] == "1":
            order *= -1
        else:
            if order == 1:
                if tfc[1] == "1":
                    #ans = tfc[2] + ans
                    ans.appendleft(tfc[2])
                else:
                    #ans = ans + tfc[2]
                    ans.append(tfc[2])

            else:
                if tfc[1] == "2":
                    #ans = tfc[2] + ans
                    ans.appendleft(tfc[2])
                else:
                    #ans = ans + tfc[2]
                    ans.append(tfc[2])


    ans = "".join(ans)

    if order == 1:
        print(ans)
    else:
        print(ans[::-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 78808
"""
an,a(n-2),          a(n-3) , a(n-1)
"""
import sys
input = sys.stdin.readline

n = int(input())
nums = list(map(int, input().split()))
ri = []
le = []
if n % 2 == 0:
    for i in range(n//2):
        ri.append(nums[2*i])
        le.append(nums[2*i+1])
    le.reverse()
else:
    for i in range(n//2):
        ri.append(nums[2*i+1])
        le.append(nums[2*i])
    le.append(nums[n-1])
    le.reverse()
print(*le, end = " ")
print(*ri)

Measured memory_bytes: 26192
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n, k;
  cin >> n >> k;
  vl a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vl v;
  for (int i = 0; i < n; ++i) {
    ll s = 0;
    for (int j = i; j < n; ++j) {
      s += a[j];
      v.push_back(s);
    }
  }
  ll res = 0;
  vl nv = v;
  for (int b = 60; b >= 0; --b) {
    ll B = 1LL << b;
    int c = 0;
    for (ll x : v) if (x & B) {
      ++c;
    }
    if (c >= k) {
      res += B;
      nv.clear();
      for (ll x : v) if (x & B) {
        nv.push_back(x);
      }
      v.swap(nv);
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 8172
#include<iostream>
#include<cstring>

using namespace std;

int main(){
	char s[100];
	int i, j, slong;
	bool flag = 0;

	cin >> s;
	slong = strlen(s);

	for(i = 0; i < slong; i ++){
		if(s[i] == 'C'){
			for(j = i + 1; j < slong; j ++){
				if(s[j] == 'F'){
					if(flag == 0){
						cout << "Yes" << endl;
						flag = 1;
						break;
					}
				}
			}
		}
	}
	if(flag == 0) cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  
  int k, a, b, i = 1;
  cin>>k;
  cin>>a>>b;
  int large = (b / k) * k;
  if(a <= large)
    cout<<"OK\n";
  else
    cout<<"NG\n";
  return 0;
}

Measured memory_bytes: 3572
n,k = map(int, input().split())
x = list(map(int, input().split()))
ans = 10 ** 9
for i in range(n-k+1):
  a = abs(x[i+k-1] - x[i])
  ans = min(ans,min(abs(x[i+k-1])+a,abs(x[i])+a))
print(ans)

Measured memory_bytes: 14384
import collections, math, bisect

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]


if local:
    start=time.time()

S = inp()

months = ["01","02","03","04","05","06","07","08","09","10","11","12"]

YYMMvalid = S[2::] in months
MMYYvalid = S[0:2] in months

if YYMMvalid and MMYYvalid:
    print("AMBIGUOUS")
elif YYMMvalid:
    print("YYMM")
elif MMYYvalid:
    print("MMYY")
else:
    print("NA")

if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")





Measured memory_bytes: 38384
from collections import Counter


def solve(n, aaa):
    if all(a == 0 for a in aaa):
        return True

    if n % 3 != 0:
        return False

    cnt = list(Counter(aaa).items())
    if len(cnt) == 2:
        (a1, c1), (a2, c2) = cnt
        if c1 > c2:
            c1, c2 = c2, c1
        if c1 != n // 3 or c2 != n * 2 // 3:
            return False
        return a1 == 0

    if len(cnt) == 3:
        if any(c[1] != n // 3 for c in cnt):
            return False
        a1, a2, a3 = (c[0] for c in cnt)
        return a1 ^ a2 == a3

    return False


n = int(input())
aaa = list(map(int, input().split()))
print('Yes' if solve(n, aaa) else 'No')


Measured memory_bytes: 15516
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9 + 7;
int INF = 2e18;

signed main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> job(M);
    for (int i = 0; i < N; i++) {
        int A, B;
        cin >> A >> B;
        if (A > M) continue;
        job[M - A].push_back(B);
    }
    priority_queue<int> queue1;
    int ans = 0;
    for (int i = M - 1; i >= 0; --i) {
        for (int j = 0; j < job[i].size(); j++) {
            queue1.push(job[i][j]);
        }
        if (!queue1.empty()) {
            ans += queue1.top();
            queue1.pop();
        }
        cerr << ans << endl;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5632