akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;

struct aa {
	pair<int,int> prev_place;
	int prev_char;
	pair<int,int>now_place;
};
int main() {
	string A,B;cin>>A>>B;
	vector<vector<pair<int,int>>>prev_places(A.size()+2,vector<pair<int,int>>(B.size()+2,make_pair(-1,-1)));
	vector<vector<int>>prev_chars(A.size() + 2, vector<int>(B.size() + 2, -1));

	vector<vector<int>>A_nexts(A.size()+2,vector<int>(2)),B_nexts(B.size()+2,vector<int>(2));
	for (int i = A.size()+1; i >= 0; --i) {
		for (int j = 0; j < 2; ++j) {

			if (i >= A.size())A_nexts[i][j] = A.size() + 1;
			else {
				A_nexts[i][j] = A_nexts[i + 1][j];
				int k=A[i]-'0';
				if (j == k) {
					A_nexts[i][j]=i+1;
				}
			}
		}
		
	}
	for (int i = B.size() + 1; i >= 0; --i) {
		for (int j = 0; j < 2; ++j) {

			if (i >= B.size())B_nexts[i][j] = B.size() + 1;
			else {
				B_nexts[i][j] = B_nexts[i + 1][j];
				int k = B[i] - '0';
				if (j == k) {
					B_nexts[i][j] = i + 1;
				}
			}
		}

	}
	queue<aa>que;
	que.push(aa{ make_pair(-1,-1),-1,make_pair(0,0) });
	string ans;
	while (!que.empty()) {
		auto atop(que.front());
		que.pop();
		auto pre_place=atop.prev_place;
		auto now_place=atop.now_place;
		int prev_char=atop.prev_char;
		
		if(now_place==make_pair(int(A.size()+1),int(B.size()+1)))
		{
			auto pl=now_place;
			while (pl.first != 0) {
				ans.push_back('0'+prev_chars[pl.first][pl.second]);
				pl=prev_places[pl.first][pl.second];
			}
		}

		for(int next_char=0;next_char<2;++next_char)	{
			auto next_place=make_pair(A_nexts[now_place.first][next_char],B_nexts[now_place.second][next_char]);

			if (prev_chars[next_place.first][next_place.second]==-1) {
				prev_chars[next_place.first][next_place.second]=next_char;
				prev_places[next_place.first][next_place.second]=now_place;
				que.push(aa{ now_place,next_char,next_place });
			}
		}
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 191528
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    string s;
    cin >> s;
    int cnt = s.size();
    string b;
    b += s[0];
    string now;
    for( int i = 1; i < s.size(); ++i ) {
        now += s[i];
        if( b == now ) --cnt;
        else {
            b = now;
            now = "";
            
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 720
{-# LANGUAGE BangPatterns #-}
import Data.Word
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U

-- Input: s t
-- Output: arr
--   (arr ! i) ! j == length of lcs of (drop i s, drop j t)
lcsTable :: BS.ByteString -> BS.ByteString -> V.Vector (U.Vector Word16)
lcsTable s t = V.scanr' (\ !x !v ->
                           -- for some i (0 <= i < m),
                           --   x = BS.index s i :: Char
                           --   v = arr ! (i+1) :: U.Vector Word16
                           U.scanr (\(!y,!w,!u) !l ->
                                      -- for some j (0 <= j < n)
                                      --   y = BS.index t j :: Char
                                      --   w = (arr ! (i+1)) ! j :: Word16
                                      --   u = (arr ! (i+1)) ! (j + 1) :: Word16
                                      --   l = (arr ! i) ! (j + 1) :: Word16
                                      if x == y
                                      then u + 1
                                      else max w l
                                   ) 0 (U.zip3 t' (U.init v) (U.tail v))
                        ) (U.replicate (n+1) 0) (V.fromListN m $ BS.unpack s)
  where !m = BS.length s
        !n = BS.length t
        !t' = U.fromListN n (BS.unpack t)

main = do
  s <- BS.getLine
  t <- BS.getLine
  -- BS.length s <= 3000, BS.length t <= 3000, BS.all isAsciiLower s, BS.all isAsciiLower t
  let !table = lcsTable s t
      !m = BS.length s
      !n = BS.length t
  let recon !i !j | i >= m || j >= n = Nothing
                  | x == y = let !i' = i+1 ; !j' = j+1
                             in Just (x, (i', j'))
                  | (table V.! (i+1)) U.! j >= (table V.! i) U.! (j+1) = recon (i+1) j
                  | otherwise = recon i (j+1)
        where x = BS.index s i
              y = BS.index t j
      (result, _) = BS.unfoldrN (fromIntegral $ (table V.! 0) U.! 0) (\(!i,!j) -> recon i j) (0,0)
  BS.putStrLn result


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

int main()
{
   int a,b,c,d;
   cin >>a;
   cin >>b;
   c=(a*b);
   d=(c%2);
   if (d==0)
   {
     cout << "Even"<< endl;
   }
   else 
   {
     cout << "Odd"<< endl;
   }
   return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int v[N];
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  
  int ans = 0;
  
  // 取り出す総数
  for (int a = 0; a <= (min(N, K)); a++) {
    //左から取り出す個数 i 右から取り出す個数 a-i
    for (int i = 0; i <= a; i++) {
      priority_queue<int> que;
      
      for (int l = 0; l < i; l++) {
        que.push(v[l]);
      }
      for (int r = 0; r < a-i; r++) {
        que.push(v[N-1-r]);
      }
      
        
      //取り出した玉a個をpriority queueに入れた
      //a-min(a, K-a)個以上priority queueから取り出した合計を求める
      int sum = 0;
      for (int j = 0; j < a-min(a, K-a); j++) {
        int q = que.top();
        sum += q;
        que.pop();
      }
      for (int j = a-min(a, K-a); j < a; j++) {
        int q = que.top();
        if (q < 0) {
          break;
        } else {
          sum += q;
          que.pop();
        }
      }
      //sumは取り出した合計の最大値
      ans = max(ans, sum);
      
    }
  }
  cout << ans << endl;
}

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

#define weight first
#define value second

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

	int N,W;
	cin>>N>>W;

	vector<pair<int,int>> v(N);
	sort(v.begin(),v.end());

	for (int i = 0; i < N ; ++i) {
		cin>>v[i].weight>>v[i].value;
	}

	vector<long long> dp(W+1);

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

	cout<<dp[W];

	return 0;
}

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

int main() {
  int n,m;
  cin>>n>>m;
  priority_queue<int> q;    
  for (int i=0; i<n; i++) {
    int a;
    cin>>a;
    q.push(a);
  }
  for (int i=0; i<m; i++) {
    int a;
    a=q.top(); q.pop();
    a/=2;
    q.push(a);
  }
  ll ans=0;
  while(!q.empty()) {
    ans+=q.top(); q.pop();
  }
  cout<<ans<<endl;
  return 0;
}




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

int digit(int x) {
  int cnt = 0;

  while (true) {
    x = x >> 1ll;
    cnt++;
    if (x < 1ll) break;
  }

  return cnt;
}

signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto&& w : a) cin >> w;

  int d = digit(k);
  bool flg = false;
  int x = 0;
  // cerr << d << endl;

  for (int i = d; i >= 0; i--) {
    if (!flg && ((k >> i & 1ll) == 0)) continue;
    int m = 0;
    for (auto&& w : a)
      if ((w >> i & 1ll) > 0) m++;
    if (n - m > m)
      x += 1ll << i;
    else
      flg = true;
  }
  // cerr << x << endl;
  int ans = 0;
  for (auto&& w : a) ans += x ^ w;
  cout << ans << endl;
}


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

int arr[200001];


long long solve(int n){
    
    sort(arr, arr + n, greater<int>());
    
    long long res = arr[0];
    
    int idx = 1;
    int current = 0;
    int total = 1;
    while(total <= n-2){
        res += arr[idx];
        if(current == 0){
            current = 1;
        }else if(current == 1){
            current = 0;
            idx += 1;
        }
        total += 1;
    } 
    
    
    
    return res;
    
    
}




int main(){
    
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    
    cout << solve(n) << endl;
    
    
    
}


Measured memory_bytes: 4408
#include <bits/stdc++.h>
using namespace std;
class Seq {
	private:
		// data
		map<int, int> mem;
		int removeCount;
	public:
		Seq() {
			removeCount = 0;
			mem.clear();
		}
		void add(int x) {
			if(mem[x] < x)
				mem[x] += 1;
			else
				removeCount++;
		}
		void sync() {
			for(map<int,int>::iterator it = mem.begin(); it != mem.end(); it++) {
				if(it->first != it->second) {
					removeCount += it->second;
					it->second = 0;
				}
			}
		}
		int countRemoved() {
			return removeCount;
		}
};
int main()
{
	// fasten
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	Seq db;
	int N;
	cin >> N;
	while(N--)
	{
		int x;
		cin >> x;
		db.add(x); // add x
	}
	db.sync(); // sync
	cout << db.countRemoved() << "\n";
	return 0;
}

Measured memory_bytes: 4736
#include <iostream>

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

void printArray(int *A, int n) {
  rep(i, n) {
    std::cout << A[i];
    if (i == n - 1)
      std::cout << '\n';
    else
      std::cout << ' ';
  }
}

void combi(int k, int *S, int n) {
  if (k == 0) {
    printArray(S, n);
    return;
  }

  S[k - 1] = 0;
  combi(k - 1, S, n);
  S[k - 1] = 1;
  combi(k - 1, S, n);
}

void combi2(int k, int *S, int n) {
  if (k == n) {
    printArray(S, n);
    return;
  }

  S[k] = 0;
  combi2(k + 1, S, n);
  S[k] = 1;
  combi2(k + 1, S, n);
}

bool solve(int *A, int n, int k, int m) {
  if (m == 0) {
    return true;
  }
  if (k == n) {
    return false;
  }

  return solve(A, n, k + 1, m - A[k]) || solve(A, n, k + 1, m);
}

bool solve2(int *A, int n, int k, int m) {
  if (m == 0) {
    return true;
  }
  if (k == n) {
    return false;
  }
  return solve2(A, n, k + 1, m) || solve2(A, n, k + 1, m - A[k]);
}

bool solve3(int *A, int n, int k, int m) {
  if (m == 0) {
    return true;
  }
  if (k < 0 || m < 0) {
    return false;
  }
  return solve3(A, n, k - 1, m) || solve3(A, n, k - 1, m - A[k]);
}

int main() {
  int n, q;
  std::cin >> n;
  int a[n];
  rep(i, n) std::cin >> a[i];
  std::cin >> q;
  int m[q];
  rep(i, q) std::cin >> m[i];

  int *S = new int[n];
  rep(i, n) S[n] = 0;

  rep(i, q) {
    int ans = solve3(a, n, n - 1, m[i]);
    if (ans) {
      std::cout << "yes" << '\n';
    } else {
      std::cout << "no" << '\n';
    }
  }
  return 0;
}



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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

void MAIN() {
  int n;
  cin >> n;
  vector<vector<int>> a(3, vector<int>(n));
  vector<vector<int>> d(3, vector<int>(n));
  for (auto &i : a) {
    for (auto &j : i) cin >> j;
    sort(all(i));
  }
  for (int i = n - 1; i >= 0; i--) {
    d[2][i] = 1;
    if (i != n - 1) d[2][i] += d[2][i + 1];
  }
  for (int i = 1; i >= 0; i--) {
    for (int j = n - 1; j >= 0; j--) {
      int p = upper_bound(all(a[i + 1]), a[i][j]) - a[i + 1].begin();
      if (p != n) d[i][j] = d[i + 1][p];
      if (j != n - 1) d[i][j] += d[i][j + 1];
    }
  }
  cout << d[0][0] << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 8628
def longest_common(m, n):
	N = len(n)
	dp = [0]*(N+1)
	for x in m:
		dp_kari = dp[:]
		for j, y in enumerate(n):
			if x == y:
				dp[j+1] = dp_kari[j]+1
			elif dp[j+1] < dp[j]:
				dp[j+1] = dp[j]
	return dp[N]


for _ in range(int(input())):
    x = input()
    y = input()
    print(longest_common(x, y))



Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
int cmp(int a,int b){
    return a>b;
}
int main(){
	int n,k;
	cin>>n>>k;
	long long h[n],t=0;
	for(int i=1;i<=n;i++){
		cin>>h[i];
		t+=h[i];
	}
	if(k==0){
		cout<<t<<endl;
		return 0;
	}
	else if(k>n){
		cout<<0;
		return 0;
	}
	sort(h+1,h+n+1,cmp);
	for(int i=1;i<=k;i++){
		t-=h[i];
	}
	cout<<t<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    vector<P> a;
    rep(i,m){
      int x,y;
      cin>>x>>y;
      a.push_back(P(x,y));
      a.push_back(P(y,x));
    }
    rep(i,n){
      int ans=0;
      rep(j,2*m){
        if(a[j].first==i+1){
          ans++;
        }
      }
      cout<<ans<<endl;
    }
}

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

public class Program{
    public static void Main(){
        var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var A = ab[0];
        var B = ab[1];
        var ans = A+B>=10 ? "error" : (A+B).ToString(); 
        Console.WriteLine(ans);
    }
}


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

int main(){
  int N,M;cin>>N>>M;
  vector<int> H(N+1);
  for(int i=1;i<=N;i++) cin>>H.at(i);
  vector<bool> good(N+1,true);
  int count=N;
  for(int j=0;j<M;j++){
    int a,b;cin>>a>>b;
    if(H.at(a)>=H.at(b) && good.at(b)){
      good.at(b)=false;
      count--;
    }
    if(H.at(a)<=H.at(b) && good.at(a)){
      good.at(a)=false;
      count--;
    }
  }
  cout<<count<<endl;
}


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

int main() {
  int x,y;
  cin >> x >> y;
  
  if(x == 1 && y == 1){
    cout << "1000000" <<endl;
  }
  
  else if(x == 1 && y == 2){
    cout << "500000" <<endl;
  }
  
  else if(x == 2 && y == 1){
    cout << "500000" <<endl;
  }
  
  else if(x == 2 && y == 2){
    cout << "400000" <<endl;
  }
  
  else if(x == 1 && y == 3){
    cout << "400000" <<endl;
  }
  
  else if(x == 3 && y == 1){
    cout << "400000" <<endl;
  }
  
  else if(x == 2 && y == 3){
    cout << "300000" <<endl;
  }
  
  else if(x == 3 && y == 2){
    cout << "300000" <<endl;
  }
  
  else if(x == 3 && y == 3){
    cout << "200000" <<endl;
  }
  
  else if(x == 1 || y == 1){
    cout << "300000" <<endl;
  }
  
  else if(x == 2 || y == 2){
    cout << "200000" <<endl;
  }
  
  else if(x == 3 || y == 3){
    cout << "100000" <<endl;
  }
  
  else{
    cout << "0" <<endl;
  }
}

Measured memory_bytes: 256
li = list(map(int, input().split()))
k = int(input())

for i in range(k):

    if li[0] >= li[1]:
        li[1]=li[1]*2
    elif li[2] <= li[1]:
        li[2]=li[2]*2
    if li[0] < li[1] and li[1] < li[2]:
        print("Yes")
        quit()
print("No")

Measured memory_bytes: 9188
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int check_c(int arr[], int nc);
int check_min(int arr[]);
int n;

int main()
{
	int cont = 0, nowc, total = 0;
	int hcont, tcont;
	int temp;
	bool flg,nxflg, isgoto = 0;
	int arr[202];
	for(;;){
		cont = 0;
		total = 0;
		for(int i = 0; i < 202; i++){
			arr[i] = 0;
		}
			
		cin >> n;
		if(n == 0){
			break;
		}
		
		vector<int> taro(n);
		vector<int> hanako(n);
		for(int i = 0; i < n; i++){
			cin >> taro[i];
			arr[taro[i]] = 1;
		}
		for(int i = 1; i < n*2+1; i++){
			if(arr[i] == 1){
			}
			else{
				hanako[cont] = i;
				cont++;
			}
		}
		sort(taro.begin(), taro.end());
		sort(hanako.begin(), hanako.end());
		hcont = 0;
		tcont = 0;
		for(int i = 0;;i++){
			if(i == 0){
				nowc = taro[0];
				taro[0] = 0;
				tcont++;
				flg = 1;
			}
			
			if((isgoto == 1 && nxflg == 0)||(flg != 0 && nowc < hanako[check_c(&hanako[0], nowc)] && !isgoto)){
				if(!isgoto){
					temp = check_c(&hanako[0], nowc);
					nowc = hanako[temp];
					hanako[temp] = 0;
				}
				else{
					temp = check_min(&hanako[0]);
					nowc = hanako[temp];
					hanako[temp] = 0;
					isgoto = 0;
				}
				hcont++;
				flg = 0;
				nxflg = 0;
			}
			else if((isgoto == 1 && nxflg == 1)||(flg != 1 && nowc < taro[check_c(&taro[0], nowc)] && !isgoto)){
				if(!isgoto){
					temp = check_c(&taro[0], nowc);
					nowc = taro[temp];
					taro[temp] = 0;
				}
				else{
					temp = check_min(&taro[0]);
					nowc = taro[temp];
					taro[temp] = 0;
					isgoto = 0;
				}
				tcont++;
				flg = 1;
				nxflg = 1;
			}
			else{
				nowc = 0;
				isgoto = 1;
			}
			
			if(hcont == n || tcont == n){
				break;
			}
		}
		
		if(hcont == n){
			for(int i = 0; i < n; i++){
				if(taro[i] != 0){
					total++;
				}
			}
		cout << 0 << endl;
		cout << total << endl;
		}
		else{
			for(int i = 0; i < n; i++){
				if(hanako[i] != 0){
					total++;
				}
			}
			cout << total << endl;
			cout << 0 << endl;
		}
	}
	
}

int check_c(int arr[], int nc)
{
	for(int i = 0; i < n; i++){
		if(arr[i] > nc){
			return i;
		}
	}
	return 0;
}

int check_min(int arr[])
{
	for(int i = 0; i < n; i++){
		if(arr[i] > 0){
			return i;
		}
	}
	return 0;
}

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

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

    while (1)
    {
        ll b;
        cin >> b;
        if (b == 0)
            return 0;
        ll Max = 0;
        ll ans1;
        for (ll i = 1; i * i <= 2 * b; ++i)
        {
            if ((2 * b) % i != 0)
                continue;
            ll m = 2 * b / i;
            if (m - i + 1 >= 2 && (m - i + 1) % 2 == 0)
            {
                if (Max < i)
                {
                    Max = i;
                    ans1 = (m - i + 1) / 2;
                }
            }
            ll j = 2 * b / i;
            m = i;
            if (m - j + 1 >= 2 && (m - j + 1) % 2 == 0)
            {
                if (Max < j)
                {
                    Max = j;
                    ans1 = (m - j + 1) / 2;
                }
            }
        }
        cout << ans1 << " " << Max << "\n";
    }

    return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 200000+10
int n, q;
string s;
char t[maxn], d[maxn];

bool left(int pos)
{
    for (int i = 0; i < q; i++) {
        if (s[pos] == t[i]) {
            if (d[i] == 'L') pos--;
            else pos++;
        }
        if (pos == -1) return true;
    }
    return false;
}

bool right(int pos)
{
    for (int i = 0; i < q; i++) {
        if (s[pos] == t[i]) {
            if (d[i] == 'L') pos--;
            else pos++;
        }
        if (pos == n) return true;
    }
    return false;
}

int main()
{
    //freopen("in.txt", "r", stdin);
    cin >> n >> q;
    cin >> s;
    for (int i = 0; i < q; i++) {
        scanf(" %c %c", &t[i], &d[i]);
        //cout << t[i] << " " << d[i] << endl;
    }
    int l1 = 0, r1 = n-1;
    while (l1 <= r1) {
        int mid = l1 + (r1 - l1) / 2;
        if (left(mid)) l1 = mid+1;
        else r1 = mid-1;
    }
    int l2 = 0, r2 = n-1;
    while (l2 <= r2) {
        int mid = (r2+l2)/2;
        if (right(mid)) r2 = mid-1;
        else l2 = mid+1;
    }
    printf("%d\n", r2-l1+1);
    return 0;
}


Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{ 
    int N,W,w[200],v[200],i,j;
    ll dp[106][100005];
    cin>>N>>W;
    for(i=1;i<=N;i++)
    {
        cin>>w[i]>>v[i];
    }
    
   memset(dp,-1,sizeof dp);
    dp[0][0]=0;
    
    
    for(i=0;i<=N;i++)
    {
        for(j=0;j<=W;j++)
        {
            if(dp[i][j]!=-1)
            {
                dp[i+1][j] = max(dp[i][j],dp[i+1][j]);
               if(j+w[i+1]<=W)
               {
                   dp[i+1][j+w[i+1]] = max(dp[i][j]+ v[i+1],dp[i+1][j+w[i]]);
               }
            }
        }
    }
    ll mx=0;
    for(i=0;i<=W;i++)
    {
        if(mx<dp[N][i])
        mx = dp[N][i];
    }
    cout<< mx;
    return 0;   
}

Measured memory_bytes: 83072
#include <bits/stdc++.h> 
using namespace std;  
long INF=1000000000000000;
int main() {
    long N;
    cin>>N;
    
    
    long ans=0;
    
    for(int i=1;i<=N;i++){
        long n=i;
        bool odd=false;
        while(n>0){
            n/=10;
            odd=(!odd);
        }
        
        ans+=odd;
    }
    cout<<ans<<endl;
}


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

ll dp[20001], a[20000];
int main() {
	ll n, m, k; scanf("%lld%lld%lld", &n, &m, &k);
	rep(i, n)scanf("%lld", &a[i]);
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;
	rep(i, n) {
		ll Min = INT_MAX, Max = 0;
		for (ll j = 0; j < m&&j + i < n; j++) {
			Min = min(Min, a[j + i]);
			Max = max(Max, a[j + i]);
			dp[i + j + 1] = min(dp[i + j + 1], dp[i] + (Max - Min)*(j + 1) + k);
		}
	}
	printf("%lld\n", dp[n]);
}

Measured memory_bytes: 3520
#include <iostream>
#include <cstdio>
#include <cctype>
#define il inline
#define vd void
#define rg register
#define ll long long
#define mn 305
#define INF 100000000000000000ll
#define rep(i,x,y) for(rg int i=x;i<=y;++i)
#define drp(i,x,y) for(rg int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il int rd(); il vd pc(char c); il vd rt(ll x); il vd flush();
template<class T> il T Max(T a,T b){return a>b?a:b;}
template<class T> il T Min(T a,T b){return a<b?a:b;}
int n,m,l,u,v,q;
ll d[mn][mn],g[mn][mn];
int main(){
	n=rd(),m=rd(),l=rd();
	rep(i,1,n) rep(j,1,n) if(i!=j) d[i][j]=INF;
	while(m--) u=rd(),v=rd(),d[u][v]=d[v][u]=rd();
	rep(k,1,n) rep(i,1,n) if(i!=k) rep(j,1,n) if(j!=i&&j!=k){
		d[i][j]=Min(d[i][j],d[i][k]+d[k][j]);
	}
	rep(i,1,n) rep(j,1,n) if(i!=j) g[i][j]=d[i][j]<=l?0:INF;
	rep(k,1,n) rep(i,1,n) if(i!=k) rep(j,1,n) if(j!=i&&j!=k){
		g[i][j]=Min(g[i][j],g[i][k]+g[k][j]+1ll);
	}
	q=rd();
	while(q--) u=rd(),v=rd(),rt(g[u][v]<INF?g[u][v]:-1),pc('\n');
	return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il int rd(){char c;
	while(!isdigit(c=gc())&&c!='-');
	int f=c=='-'?c=gc(),1:0,x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(ll x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}

Measured memory_bytes: 5120
N, Q = map(int, input().split())
S = input()

sum_table = [0] * (N+1)

for i in range(N):
    sum_table[i+1] = sum_table[i] + (1 if S[i:i+2] == "AC" else 0)
for i in range(Q):
    left, right = map(int, input().split())
    print(sum_table[right-1] - sum_table[left-1])



Measured memory_bytes: 7748
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 3000
#define MO 1000000007
using namespace std;
int N,M,dp[MAXN+5][MAXN+5][2];
int main()
{
	scanf("%d %d",&N,&M);
	dp[0][0][1]=1;
	for(int i=1;i<=N;i++)
		dp[0][i][0]=1;
	for(int i=0;i<M;i++)
		for(int j=0;j<=N;j++)
			for(int k=0;k<2;k++)
			{
				int res=N-j;
				if(j>0)
				{
					if(j-1==0)
						dp[i+1][j-1][1]=(1LL*dp[i+1][j-1][1]+1LL*dp[i][j][k])%MO;
					else
						dp[i+1][j-1][k]=(1LL*dp[i+1][j-1][k]+1LL*dp[i][j][k])%MO;
				}
				if(res>0)
					dp[i+1][j+1][k]=(1LL*dp[i+1][j+1][k]+1LL*dp[i][j][k])%MO;
				if(j>0)
					dp[i+1][j][k|(j==1)]=(1LL*dp[i+1][j][k|(j==1)]+1LL*dp[i][j][k])%MO;
				if(res>0)
					dp[i+1][j][k]=(1LL*dp[i+1][j][k]+1LL*dp[i][j][k])%MO;
			}
	int ans=0;
	for(int i=0;i<=N;i++)
		ans=(1LL*ans+1LL*dp[M][i][1])%MO;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 70656
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <assert.h>

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
#define trace(x) cerr << #x << " = " << x << endl;



/////////////////////////////////////////////
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

///////////////////////////////////////////////////////////////////////
#define int long long
const int N = 3002;
int dp[N][N][4];
int a[N][N];
int r , c , k;
int calc(int i , int j , int taken){

	if(i >= r || j >= c)
		return 0;

	int &ans = dp[i][j][taken];
	if(ans!=-1)
		return ans;
	ans = 0;
	if(taken > 0)
		ans = max(ans , a[i][j] + calc(i+1 , j , 3));
	ans = max(ans , calc(i + 1 , j , 3));
	if(taken > 0)
		ans = max(ans , a[i][j] + calc(i , j + 1 , taken-1));
	ans = max(ans , calc(i, j + 1 , taken));

	return ans;
}
void solve(){

	cin>>r>>c>>k;

	while(k--){

		int x , y , v;
		cin>>x>>y>>v;
		--x;
		--y;
		a[x][y] = v;
	}
	memset(dp , -1 , sizeof dp);
	int ans = calc(0 , 0 , 3);

	cout<<ans<<endl;
}
signed main(){
 
    fast;
    int t = 1;
    //cin>>t;
    for(int i = 1 ; i <= t ; ++i)
        solve();
}


Measured memory_bytes: 356184
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = Integer.parseInt(sc.next());
		Arrays.sort(a);
		boolean able = true;
		if (n % 2 > 0) {
			for (int i = 0; i < n; i++) {
				if (i % 2 == 0 && a[i] == i) continue;
				if (i % 2 > 0 && a[i] == i + 1) continue;
				able = false;
			}
		}
		else {
			for (int i = 0; i < n; i++) {
				if (i % 2 == 0 && a[i] == i + 1) continue;
				if (i % 2 > 0 && a[i] == i) continue;
				able = false;
			}
		}
		if (able) {
			long ans = 1;
			for (int i = 1; i <= n / 2; i++)
				ans = ans * 2 % 1000000007;
			System.out.println(ans);
		}
		else
			System.out.println("0");
	}
}

Measured memory_bytes: 48644
n = int(input())
S = list(map(int, input().split()))
count = 0


def merge(A, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    L = A[left: left + n1]
    R = A[mid: mid + n2]
    L.append(float('inf'))
    R.append(float('inf'))
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
        count += 1


def merge_sort(A, left, right):
    if (left + 1) < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)


merge_sort(S, 0, n)
print(*S)
print(count)



Measured memory_bytes: 61652
#include<string>
#include<iostream>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define ll unsigned long long

bool Prime(int a)
{
	if(a==1)
		return false;
	if(a<4)
		return true;
	if(a%2==0)
		return false;
	int k=sqrt((double)a);
	for(int i=3;i<=k;i++)
	{
		if(a%i==0)
			return false;
	}
	return true;
}

int main()
{
	int n, k=1;
	cin>>n;
	vector<int>val;
	cout<<3;
	while(1)
	{
		for(int i=4;i<555555;i++)
		{
			if(Prime(i)&&i%10==3)
			{
				cout<<' '<<i;
				k++;
				if(k==n)
					return 0;
			}
		}
	}

	system("pause");
	return 0;
}

Measured memory_bytes: 256
using System;
namespace ConsoleApplication1{
    class Program{
        static void Main(string[] args){
            string str;
            while((str=Console.ReadLine())!=null){
                double v=double.Parse(str);
                double t=v/9.8;
                double y=4.9*t*t;
                double n=0;
                while(true){
                    if ((5*n-5)>y) {
                        Console.WriteLine((int)n);
                        break;
                    }
                    n++;
                }
            }
        }
    }
}

Measured memory_bytes: 5688
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\n"
#define MOD 3000000000000000000
#define inf -100000000
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
using namespace __gnu_pbds; 
ll int power(ll int x,ll int y) 
{ 
    ll int res = 1;     // Initialize result 
   
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = res*x; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = x*x;  // Change x to x^2 
    } 
    return res; 
}
int main()
{
    fast;
   // #ifndef ONLINE_JUDGE
   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);
    //#endif
    ll int a,b,n;
    cin>>a>>b>>n;
    ll int i,z,w,q,val,ans=INT_MIN;
    z=(a*(b-1))/b;
    w=0;

    if(b>n+1)
   	{
   		z=(a*(n))/b;
   	}
    cout<<z-w<<endl;
}

Measured memory_bytes: 3656
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int mp[101][101];
bool ans;
int w,h,tmp;
int xs,ys,xg,yg;

void dfs(int y,int x,int c){
  if(y>0&&y<=h&&x>0&&x<=w&&mp[y][x]==c){
    mp[y][x]=0;
    rep(i,4){
      dfs(y+dy[i],x+dx[i],c);
    }
  }else return;
  if(y==yg&&x==xg){
    ans=true;
    return;
  }
}

signed main(){
  while(cin>>w>>h,w){
    rep(i,w)rep(j,h)mp[i][j]==0;
    ans=false;
    cin>>xs>>ys>>xg>>yg;
    int n;
    cin>>n;
    rep(i,n){
      int c,d,x,y;
      cin>>c>>d>>x>>y;
      if(d==0)rep(i,2)rep(j,4)mp[y+i][x+j]=c;
      else rep(i,2)rep(j,4)mp[y+j][x+i]=c;
    }
    tmp=mp[ys][xs];
    if(mp[ys][xs]==tmp&&mp[yg][xg]==tmp)dfs(ys,xs,tmp);
    cout<<(ans?"OK":"NG")<<endl;
  }
return 0;
}

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

int main() {
	int N;
	cin >> N;
	cout << N*N << endl;
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<tuple<string,int,int>> S(N);
  for(int i=0; i<N; i++){
    cin >> get<0>(S.at(i)) >> get<1>(S.at(i));
    get<1>(S.at(i))=100-get<1>(S.at(i));
    get<2>(S.at(i))=i+1;
  }
  sort(S.begin(),S.end());
  for(int i=0; i<N; i++){
    cout << get<2>(S.at(i)) << endl;
  }
}

Measured memory_bytes: 256
n, k = map(int, input().split())
g = [1] * k
mod = 10 ** 9 + 7

for i in range(k, 0, -1):
    x = k // i
    m = n
    while m > 0:
        if m & 1:
            g[i-1] = g[i-1] * x % mod
        x = x * x % mod
        m >>= 1

    y = 2
    while i * y <= k:
        g[i-1] -= g[i*y-1]
        y += 1

ans = 0
for i in range(k):
    ans = (ans + g[i] * (i + 1)) % mod

print(ans)


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

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

    string s;
    cin >> s;
    
    int count[26];
    rep(i, 26){
        count[i] = 0;
    }
    
    for(auto c : s){
        count[c - 'a']++;
    }

    int a = -1;
    rep(i, 26){
        if(count[i]%2 != 0){
            a = i;
            break;
        }
    }
    
    string ans = "No";
    if(a==-1){
        ans = "Yes";
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7

ans = 1
color = 3
counter = [0 for i in range(n+1)]
for i,value in enumerate(a):
    if value == 0:
        tmp = 3 - counter[0]
    else:
        tmp = counter[value - 1] - counter[value]
    ans = ans * tmp % mod
    counter[value] += 1
print(ans)


Measured memory_bytes: 14056
using System;

public class Hello{
    public static void Main(){
        string[] str;
        int x = 1;
        int y = 1;
        while(x != 0 || y != 0){
            str = Console.ReadLine().Split(' ');
            x = int.Parse(str[0]);
            y = int.Parse(str[1]);
            if(x != 0 || y != 0){
                if(x < y){
                    Console.WriteLine(x + " " + y);
                }
                else{
                    Console.WriteLine(y + " " + x);
                }
            }
        }
    }
}



Measured memory_bytes: 17944
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Control.Monad


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)


main :: IO ()
main = do
    [a,p] <- r'
    print $ (a*3+p) `div` 2


Measured memory_bytes: 380
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
arr.some(function(v){
   if(v=="0 0")return true;
   var ns=v.split(" ").map(Number);
   var n=ns[0];
   var s=ns[1];
   var all=[];
   var loop=function(start,sum,cnt){
      if(cnt==n)all.push(sum);
      else{
         for(var i=start;i<=9;i++){
            loop(i+1,sum+i,cnt+1);
         }
      }
   }
   loop(0,0,0);
   var cnt=0;
   all.forEach(function(v){
      if(v==s)cnt++;
   });
   console.log(cnt);
});

Measured memory_bytes: 15736
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
r = sum(int(i) for i in str(n))
print('No' if n%r else 'Yes')

Measured memory_bytes: 64108
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#define LL long long
#define num1 200
#define num2 100
#define rep(i,n) for(i=0;i<(n);i++)
using namespace std;

int main(){
  
  LL i, N, L, apple[num1], ans, minval,taste_all;
  
  scanf("%lld %lld",&N,&L);
  
  taste_all=0;
  
  rep(i,N){
  
   apple[i]=L+(i+1)-1;
   taste_all+=apple[i];
	
  }

  minval=apple[0];
  
  rep(i,N){
  	
    if(abs(minval)>abs(apple[i])){
    	minval=apple[i];
    }
    
  }
  
  ans = taste_all-minval;
    
  printf("%lld",ans);
  
  
  return 0;
  
}

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

long long mod_pow(long long x, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

struct Combination {
  std::vector<long long> fac, finv, inv;
  int mod;

  Combination(int max_n, int _mod) {
    fac = finv = inv = std::vector<long long>(max_n + 10, 0);
    mod = _mod;
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < max_n + 10; i++) {
      fac[i] = fac[i - 1] * i % mod;
      inv[i] = mod - inv[mod % i] * (mod / i) % mod;
      finv[i] = finv[i - 1] * inv[i] % mod;
    }
  }

  long long mod_comb(int n, int k) {
    if (n < k || n < 0 || k < 0) {
      return 0;
    }
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
  }
};

int main() {
  const int mod = 998244353;
  long long N, M, K;
  std::cin >> N >> M >> K;

  Combination comb(N, mod);

  long long ans = 0;
  for (int k = 0; k <= K; k++) {
    long long a = M * mod_pow(M - 1, N - k - 1, mod) % mod;
    a = (a * comb.mod_comb(N - 1, k)) % mod;
    ans = (ans + a) % mod;
  }
  std::cout << ans << "\n";

  return 0;
}

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    int a; cin >> a;
    string S; cin >> S;
    cout << (a>=3200?S:"red") << endl;




    return 0;
}


Measured memory_bytes: 256
package main

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

var b2i = map[bool]int8{false: 0, true: 1}

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func main() {
	io := newIo()
	N := io.nextInt()
	type whenWhere struct {
		t, x, y int
	}
	flgNG := false
	pre := whenWhere{0, 0, 0}
	for range make([]struct{}, N) {
		now := whenWhere{io.nextInt(), io.nextInt(), io.nextInt()}
		t := now.t - pre.t
		d := abs((now.x + now.y) - (pre.x + pre.y))
		if d > t || t%2 != d%2 {
			flgNG = true
		}
		pre = now
	}
	fmt.Println([...]string{"Yes", "No"}[b2i[flgNG]])
}

type io struct {
	reader    *bufio.Reader
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
	}
}

func (io *io) nextLine() string {
	var buffer []byte
	for {
		line, isPrefix, _ := io.reader.ReadLine()
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) nextString() string {
	for io.nextToken >= len(io.tokens) {
		line := io.nextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) nextInt() int {
	i, _ := strconv.Atoi(io.nextString())
	return i
}


Measured memory_bytes: 5504
/*  ex2_3
    yy8332  */

#include <stdio.h>

int main(void){
  int N, A;

  //入力受け取り
  scanf("%d", &N);
  scanf("%d", &A);

  //出力
  printf("%d\n", (N * N) - A);

  return 0;
}

Measured memory_bytes: 1736
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/*
 * AtCoder Beginner Contest 081 A "Placing Marbles"
 */
public class Main {

	public static void main(String[] args) {

		InputScanner in = new InputScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		String s = in.next();

		int ans = 0;
		for (char si : s.toCharArray()) {
			if (si == '1') {
				ans++;
			}
		}

		out.println(ans);

		in.close();
		out.close();
	}

	/*
	 * extends java.util.Scanner
	 */
	static class InputScanner {

		Scanner scanner;

		public InputScanner(InputStream inputStream) {
			this.scanner = new Scanner(inputStream);
		}

		public int nextInt() {
			return scanner.nextInt();
		}

		public long nextLong() {
			return scanner.nextLong();
		}

		public double nextDouble() {
			return scanner.nextDouble();
		}
		public String next() {
			return scanner.next();
		}

		public int[] nextIntArray(int n) {
			int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextInt();
			}
			return ret;
		}

		public int[][] nextIntArray(int h, int w) {
			int[][] ret = new int[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.nextInt();
				}
			}
			return ret;
		}

		public long[] nextLongArray(int n) {
			long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextLong();
			}
			return ret;
		}

		public long[][] nextlongArray(int h, int w) {
			long[][] ret = new long[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.nextLong();
				}
			}
			return ret;
		}

		public double[] nextDoubleArray(int n) {
			double[] ret = new double[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextDouble();
			}
			return ret;
		}

		public double[][] nextDoubleArray(int h, int w) {
			double[][] ret = new double[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.nextLong();
				}
			}
			return ret;
		}

		public String[] nextStringArray(int n) {
			String[] ret = new String[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.next();
			}
			return ret;
		}

		public String[] nextStringArray(int n, String split) {
			String[] ret = scanner.next().split(split);
			return ret;
		}

		public String[][] nextStringArray(int h, int w) {
			String[][] ret = new String[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.next();
				}
			}
			return ret;
		}

		public String[][] nextStringArray(int h, int w, String split) {
			String[][] ret = new String[h][w];
			for (int i = 0; i < h; i++) {
				ret[i] = scanner.next().split(split);
			}
			return ret;
		}

		public void close() {
			scanner.close();
		}

	}

}


Measured memory_bytes: 21844
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
TD = [lr() for _ in range(N)]
TD.sort(key=lambda x: x[1], reverse=True)
used = set()
overlap = []
for t, d in TD[:K]:
    if t in used:
        overlap.append(d)
    else:
        used.add(t)

delicious = sum([x[1] for x in TD[:K]])
answer = delicious + len(used) ** 2
for i in range(K, N):
    if not overlap:
        break
    if TD[i][0] in used:
        continue
    delicious += (TD[i][1] -  overlap.pop())
    used.add(TD[i][0])
    if answer < delicious + len(used)**2:
        answer = delicious + len(used)**2

print(answer)
# 30

Measured memory_bytes: 31220
def solve():
    n = int(input())
    H = [int(i) for i in input().split()]
    P = [0] + [abs(H[0]-H[1])] + [0]*(n-2)
    for i in range(2,n):
        P[i] = min(abs(H[i-1]-H[i])+P[i-1],abs(H[i-2]-H[i])+P[i-2])
    return P[-1]
    
if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 13976
'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf8');

let input = '';

process.stdin.on('data', chunk => input += chunk);
process.stdin.on('end', () => {
  let number = Number(input);
  let numEvens = (number / 2) >>> 0;
  console.log(numEvens * (numEvens + number % 2));
});

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

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

ll gcd(ll a, ll b)
{
    return (b == 0) ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    ll r1 = B / C - (A-1) / C;
    ll r2 = B / D - (A-1) / D;
    ll r3 = B / lcm(C, D) -(A-1) / lcm(C, D);

    cout << B - A + 1 - (r1 + r2 - r3) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<cstring>
using namespace std;
int main(){
  char cc[1000000];
  cin.getline(cc,1000000);
  for(int i=0;i<strlen(cc);i++){
    cc[i] = toupper(cc[i]);
    cout << cc[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1132
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
using namespace std;
int main(void){
    int N; cin >> N;
    int i = 1;
    int counter = 0;
    while (i <= N) {
        if ((i) % 2 == 0) {
            i++;
            continue;
        } 
        int localCouter = 0;
        for (int j = 1; j <= N; j++) {
           if (i % j == 0) localCouter++;
        }
        if (localCouter == 8) counter++;
        i++;
    }
    cout << counter << endl;

}


Measured memory_bytes: 3556