akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define int long long
using namespace std;
int f(int k) {
	int r = 0;
	while (k) {
		r += k % 10; k /= 10;
	}
	return r;
}
int a, n, m, ans;
signed main() {
	cin >> a >> n >> m;
	for (int i = 0;; i++) {
		int x = 1;
		for (int p = 0; p < n; p++)x *= i + a;
		if (x > m) {
			cout << ans << endl;
			return 0;
		}
		if (x > 0 && f(x) == i) {
			ans++;
		}
	}
}


Measured memory_bytes: 3096
#include<iostream>
using std::cin;
using std::cout;
using std::endl;

#include<map>
using std::map;

#include<string>
using std::string;


int main(void){
	map<string,int> memo;
	int n;

	scanf("%d",&n);
	string s;
	for(int i=0;i<n;i++){
		cin >> s;
		memo[s]+=1;
	}
	int maxv = 0 ,v;
	for(auto &x: memo){
		v=x.second;
		if(v>maxv)maxv = v;
	}
	for(auto it=memo.begin();it != memo.end();it++){
		if(it->second == maxv){
			//cout << endl;
			cout<< it->first << endl;
		}
	}
}





Measured memory_bytes: 25216
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

template <class _T> static _T tp_gcd(_T first, _T second)
{
	_T num1 = first, num2 = second;
	_T remainder = 0, common = 0;

	if (!num1) return num2;
	if (!num2) return num1;

	while (!common) {
		remainder = num1 % num2;

		if (remainder == 0) {
			common = num2;
		}
		else {
			num1 = num2;
			num2 = remainder;
		}
	}
	return(common);
}
template <class _T> static _T tp_lcm(_T first, _T second) {
	_T gcd = tp_gcd<_T>(first, second);
	if (first > second) {
		first /= gcd;
	}
	else {
		second /= gcd;
	}
	return first * second;
}

static void exec()
{
	int N;
	get(N);

	std::vector<LLONG> ti(N);
	for (int i = 0; i < N; i++) {
		get(ti[i]);
	}

	LLONG lcm = 1;
	for (int i = 0; i < N; i++) {
		lcm = tp_lcm<LLONG>(lcm, ti[i]);
	}
	printf("%lld\n", lcm);
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,x=0,y=0;
    cin >> n;
    long long a[n];
    for(int i=0;i<n;i++){
      cin >> a[i];
      if(a[i]%4==0){
        x++;
      }else if(a[i]%2==0&&a[i]%4!=0){
        y++;
      }
    }
    n-=y;
    if(y!=0){
      if((n+1)/2<=x){
        cout << "Yes" << endl;
      }else{
        cout << "No" << endl;
      }
    }else{
      if(n/2<=x){
        cout << "Yes" << endl;
      }else{
        cout << "No" << endl;
      }
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iomanip>
#include<iostream>
#include<vector>

using namespace std;

typedef long long int ll;
const int INF = 1e9 + 7;

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


int dp[10005];

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	int H,N;
	cin >> H >> N;
	vector<int> A(N), B(N);
	for (int i = 0; i < N;i++){
		cin >> A[i] >> B[i];
	}
	for (int i = 0; i < 10005;i++){
		dp[i] = INF;
	}

	dp[0] = 0;

	for (int i = 0; i < N;i++){
		for (int j = 0; j <= H;j++){
			if(dp[j] == INF)continue;
			chmin(dp[min(H, j + A[i])], dp[j] + B[i]);
		}
	}
	cout << dp[H] << endl;

	return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N >> M >> K;
	K = min(K,M - 1);
	cout << N * K / M - N * (K / M) << endl;
}

Measured memory_bytes: 3640
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

enum MOD = 10 ^^ 9 + 7;

void main()
{
    long a = lread();
    long b = lread();
    long c = lread();
    long d = lread();
    long e = lread();
    long k = lread();
    writeln((k < e - a) ? ":(" : "Yay!");
}


Measured memory_bytes: 256
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s+=j; c+=1
        j += 1
    x[c][s] += 1

while 1:
    n,s = map(int, raw_input().split())
    if n==0 and s==0: break
    print 0 if s>=50 else x[n][s]

Measured memory_bytes: 4252
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)


int main()
{
	string s;
	cin >> s;
	for (auto i = s.length()-1; i > 0;--i) {
		if (s[i] != 'Z') {
			s.pop_back();
		}
		if (s[i] == 'Z') {
			break;
		}
	}
	reverse(s.begin(), s.end());
	for (auto i = s.length() - 1; i > 0; --i) {
		if (s[i] != 'A') {
			s.pop_back();
		}
		if (s[i] == 'A') {
			break;
		}
	}
	cout << s.length() << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#undef int
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int N, h[100100], dp[100100];

signed main()
{
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> h[i];
        dp[i] = INFL;
    }
    dp[0] = 0ll;
    for(int i = 0; i < N; i++){
        for(int j = i - 1; j >= i - 2 && j >= 0; j--){
            dp[i] = min(dp[i], dp[j] + max(h[i] - h[j], h[j] - h[i]));
        }
    }
    cout << dp[N - 1] << endl;


    return 0;
}
/*



*/



Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
    int r,c;
    cin >>r >>c;
    int a[r+1][c+1];

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




Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define int long long
#define double long double
#define N 14
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
int G[N][N];
int n;
double p;

double calc(int b,int c){
  double res = 1;
  for(int i=0;i<n;i++) 
    for(int j=i+1;j<n;j++)
      if(((b>>i&1) && (c>>j&1) && G[i][j]) ||
         ((b>>j&1) && (c>>i&1) && G[i][j])) res *= p;
      return res;
}


double mem[1<<N],used[1<<N];
double dfs(int bit){
  if(bit == 0) return 0;
  if((bit&-bit) == bit) return 1;
  if(used[bit]++) return mem[bit];

  double res = 1;
  for(int i = (i-1)&bit;i > 0;i=(i-1)&bit){
    if(i % 2 == 0) continue;
    int j = bit ^ i;
    double p = dfs(i);    
    res -= p * calc(i,j); 
  } 
  return mem[bit] = res;
}


signed main(){
  int m;
  cin>>n>>m>>p; p/=100;
  for(int i=0,a,b;i<m;i++){
    cin>>a>>b;
    G[a-1][b-1] = G[b-1][a-1] = 1;
  }
  
  printf("%.10Lf\n",dfs((1<<n)-1));
  return 0;
}

Measured memory_bytes: 3800
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE BangPatterns #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Map.Strict (Map)
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import Data.Set (Set)

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Mutable as MVector
import Data.Vector.Mutable (STVector)
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToVector :: ByteString -> Vector Int
readIntToVector = Vector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToVectorN :: Int -> ByteString -> Vector.Vector Int
readIntToVectorN n = Vector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace


first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

average :: Fractional a => [a] -> a
average xs = sum xs / (fromIntegral . length) xs

-- ----------

main :: IO ()
main = do
	a <- getLine
	if 'A' <= head a && head a <= 'Z'
		then putStrLn "A"
		else putStrLn "a"


Measured memory_bytes: 3668
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

x, y = MAP()

if x == y:
	print(0)

elif x < y :
	print(min(y-x, abs(y+x)+1))

else:
	print(min(-y+x+2, abs(y+x)+1))


Measured memory_bytes: 5200
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 = sc.nextInt();
        int l = sc.nextInt();
        String[] strs = new String[n];
        for (int i = 0; i < strs.length; i++) {
            strs[i] = sc.next();
        }

        Arrays.sort(strs);
        String ans = "";
        for (String str : strs) {
            ans += str;
        }
        System.out.println(ans);
    }
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;
int Q;
int r[111111];
int num[111111];

signed main(){
    cin>>N>>M;
    cin>>Q;
    vint A(Q);rep(i,Q)cin>>A[i];

    memset(r,-1,sizeof(r));

    int n=0;
    for(int i=Q-1;i>=0;i--){
        int a=A[i]-1;
        if(r[a]==-1){
            r[a]=n;
            n++;
        }
        if(r[a]&&num[r[a]-1]<=num[r[a]]);
        else num[r[a]]++;
    }

    vint x(n);
    rep(i,M)if(r[i]!=-1)x[r[i]]=i;
    rep(i,M)if(r[i]==-1)x.pb(i);

    int k=n;
    rep(i,n)if(num[i]<N){
        k=i;
        break;
    }
    bool flag=true;
    for(int i=k;i+1<M;i++)if(x[i]>x[i+1])flag=false;
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n;
string s;

signed main() {
	cin >> n >> s;
	int k = 0;
	for (int i = 0; i < n; i++) {
		int x = s[i] - '1';
		if ((i | n - 1) == n - 1)k += x;
	}
	if (k % 2) {
		cout << 1 << endl;
		return 0;
	}
	for (int i = 0; i < n; i++)if (s[i] - '1' == 1) {
		cout << 0 << endl;
		return 0;
	}
	k = 0;
	for (int i = 0; i < n; i++) {
		int x = s[i] - '1';
		if ((i | n - 1) == n - 1)k += x / 2;
	}
	if (k % 2)cout << 2 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 1412
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int dx[]={0,0,-1,1};
int dy[]={-1,1,0,0};
char dir[7]="<>^v";
char m[30][30];
int bfs[30][30][20][4];
struct wolf{
	int r,c,b,d;
	wolf(){}
	wolf(int R,int C,int B,int D){
		r=R;c=C;b=B;d=D;
	}
};
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%s",m[i]);
	queue<wolf>Q;
	if(m[0][0]=='?'){
		for(int i=0;i<4;i++){
			bfs[0][0][0][i]=1;
			Q.push(wolf(0,0,0,i));
		}
	}else{
		int fb=0;int fd=1;
		
		if(m[0][0]=='|'){
			fd=3;
		}
		if(m[0][0]=='_'){
			fd=1;
		}
		for(int i=0;i<4;i++){
			if(m[0][0]==dir[i]){
				fd=i;
			}
		}
		if(m[0][0]=='+')fb=1;
		if(m[0][0]=='-')fb=15;
		if('0'<=m[0][0]&&m[0][0]<='9')fb=m[0][0]-'0';
		
		bfs[0][0][fb][fd]=1;
		Q.push(wolf(0,0,fb,fd));
	}
	while(Q.size()){
		wolf at=Q.front();
		Q.pop();
		int tr=(at.r+dx[at.d]+a)%a;
		int tc=(at.c+dy[at.d]+b)%b;
		int tb=at.b;
		int td=at.d;
		if(m[tr][tc]=='?'){
			for(int i=0;i<4;i++){
				if(!bfs[tr][tc][tb][i]){
					bfs[tr][tc][tb][i]=1;
					Q.push(wolf(tr,tc,tb,i));
				}
			}continue;
		}
		if(m[tr][tc]=='|'){
			if(tb){
				td=2;
			}else{
				td=3;
			}
		}
		if(m[tr][tc]=='_'){
			if(tb)td=0;
			else td=1;
		}
		for(int i=0;i<4;i++){
			if(m[tr][tc]==dir[i]){
				td=i;
			}
		}
		if(m[tr][tc]=='+')tb=(tb+1)%16;
		if(m[tr][tc]=='-')tb=(tb+15)%16;
		if('0'<=m[tr][tc]&&m[tr][tc]<='9')tb=m[tr][tc]-'0';
		if(!bfs[tr][tc][tb][td]){
			bfs[tr][tc][tb][td]=1;
			Q.push(wolf(tr,tc,tb,td));
		}
	}
	bool ok=false;
	for(int i=0;i<a;i++)for(int j=0;j<b;j++)if(m[i][j]=='@'){
		for(int k=0;k<16;k++)for(int l=0;l<4;l++)if(bfs[i][j][k][l])ok=true;
	}
	if(ok)printf("YES\n");else printf("NO\n");
}

Measured memory_bytes: 1240
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int len = Integer.parseInt(scanner.nextLine());
        String cards[] = scanner.nextLine().split(" ", len);

        Main main = new Main();

        String sorted[] = main.bubbleSort(cards);
        main.printStrings(sorted);
        System.out.println(main.stablySorted(cards, sorted) ? "Stable" : "Not stable");

        sorted = main.selectionSort(cards);
        main.printStrings(sorted);
        System.out.println(main.stablySorted(cards, sorted) ? "Stable" : "Not stable");
    }

    private String[] bubbleSort(String cards[]) {
        String sorted[] = cards.clone();
        boolean found = true;

        int i = 0; // count of sorted cards
        while (found) {
            found = false;
            for (int j = sorted.length - 1; j > i; j--) {
                if (sorted[j - 1].substring(1).compareTo(sorted[j].substring(1)) > 0) {
                    String temp = sorted[j - 1];
                    sorted[j - 1] = sorted[j];
                    sorted[j] = temp;

                    found = true;
                }
            }
            i++;
        }
        return sorted;
    }

    private String[] selectionSort(String cards[]) {
        String sorted[] = cards.clone();
        for (int i = 0; i < sorted.length; i++) {
            int minJ = i;
            for (int j = i; j < sorted.length; j++) {
                if (sorted[j].substring(1).compareTo(sorted[minJ].substring(1)) < 0) {
                    minJ = j;
                }
            }

            if (i != minJ) {
                String temp = sorted[i];
                sorted[i] = sorted[minJ];
                sorted[minJ] = temp;
            }
        }
        return sorted;
    }

    private void printStrings(String strs[]) {
        for (int i = 0; i < strs.length; i++) {
            System.out.print(strs[i]);
            if (i == strs.length - 1) {
                System.out.print("\n");
            } else {
                System.out.print(" ");
            }
        }
    }

    private boolean stablySorted(String original[], String sorted[]) {
        List<String> sortedList = Arrays.asList(sorted);
        for (int i = 0; i < original.length; i++) {
            String card = original[i];
            int iIndex = sortedList.indexOf(original[i]);
            for (int j = i + 1; j < original.length; j++) {
                if (original[i].substring(1).compareTo(original[j].substring(1)) <= 0
                        && iIndex > sortedList.indexOf(original[j])) {
                    return false;
                }
            }
        }
        return true;
    }
}



Measured memory_bytes: 26556
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>

int main(int argc,char *argv[])
{
	int N;
	std::cin >> N;
	
	int tmp;
	int *person = new int[N+1];
	for(int i = 0;i < N;i++){
		std::cin >> tmp;
		person[tmp] = i+1;
	}

	for(int i = 1;i < N+1;i++) std::cout << person[i] << " ";
	std::cout << std::endl;

	delete[] person;
	return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#define num_element 123
int main(void)
{
	int i,n,m;
	char array[num_element];
	char a[2];
	char b[2];
	char input[2];
	while(1)
	{
		for(i=0;i<num_element;i++)
		{
			array[i] = i;
		}
		scanf("%d",&n);
		if(n == 0)return 0;
		for(i=0;i<n;i++)
		{
			scanf("%s %s",a,b);
			array[a[0]] = b[0];
		}
		scanf("%d",&m);
		for(i=0;i<m;i++)
		{
			scanf("%s",input);
			printf("%c",array[input[0]]);
		}
		printf("\n");
	}
	return 0;
}

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

int A = 500;
int B = 100;
int C = 50;

int count(int a, int b, int c, int x){
    int counter = 0;
    for (int ai=0; ai<=a; ai++) {
        for (int bi=0; bi<=b; bi++) {
            int total = A * ai + B * bi;
            int rest = x - total;
            if (rest < 0) break;
            int ci = rest / C;
            if (ci >= 0 && ci <= c) {
                counter++;
            }
        }
    }
    return counter;
}

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    cout << count(a, b, c, x) << endl;
}



Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	A := sc.NextIntArray()

	mp := map[int]int{}
	for i := 0; i < N; i++ {
		mp[A[i]]++
	}

	count := []int{}

	for _, v := range mp {
		count = append(count, v)
	}
	sort.Ints(count)

	ans := 0
	for i := 0; i < len(count)-K; i++ {
		ans += count[i]
	}
	fmt.Println(ans)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 20736
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<string>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
//#include<chrono>
//#include<time.h>
//#include<windows.h>
using namespace std;
 
//#define int ll
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define YESNO(x) puts((x)?"YES":"NO")
struct edge {int /*from,*/to,cost;};

bool palin(int n){
    string s = to_string(n);
    REP(i,LEN(s)){
        if(s[i]!=s[LEN(s)-1-i]) return false;
    }
    return true;
}

signed main(){
    int a,b;
    cin >> a >> b;
    bool p[114514];
    REP(i,114514) p[i] = palin(i);

    int ans = 0;
    FOR(i,a,b+1) ans += p[i];
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N, Y;
    cin >> N >> Y;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
            long long k = N - i - j;
            long long t = 10000*i + 5000*j + 1000*k;
            if(k >= 0 && t == Y){
                cout << i << ' ' << j << ' ' << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}

Measured memory_bytes: 256
# coding: utf-8
S = gets
K = gets.to_i
lim = K
lim = S.size if S.size < K

# 1文字目からK文字目まで探して、1以外が現れたらその文字が答え
(0..lim-1).each do |i|
  if S[i] >= "2"
    puts S[i]
    exit 0
  end
end

# 見つからなかったので答えは1
puts "1"



Measured memory_bytes: 3836
#Educational DP b frog2
#1次元dp
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * n
for i in range(1, n):#もらうDP
    dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-k), i))
print(dp[-1])


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

struct block{

  int tate, yoko, step;

};

struct xy{
  int x, y, step;
};
block maze[31][31];
int ww, hh;
queue<xy> qu;
int xx[4] = {0, 0, 1, -1};
int yy[4] = {-1, 1, 0, 0};
int h, w;
int d[31][31];

void wide(){

  memset(d,0,sizeof(d));
  maze[0][0].step = 1;
  qu.push((xy){0,0,1});
  int x = 0, y = 0;
  d[0][0] = 1;

  while(!qu.empty()){

    xy st;
    st = qu.front();
    qu.pop();

   
    if(st.x+1 >= 0 && st.x+1 < w && st.y >= 0 && st.y < h && d[st.x+1][st.y] == 0 && maze[st.x][st.y].tate == 0){
      qu.push((xy){st.x+1,st.y,st.step+1});
      d[st.x+1][st.y] = st.step + 1;
    }
    if(st.x-1 >= 0 && st.x-1 < w && st.y >= 0 && st.y < h && d[st.x-1][st.y] == 0 && maze[st.x-1][st.y].tate == 0){
      qu.push((xy){st.x-1,st.y,st.step+1});
      d[st.x-1][st.y] =  st.step + 1;
    }
    if(st.x >= 0 && st.x < w && st.y+1 >= 0 && st.y+1 < h && d[st.x][st.y+1] == 0 && maze[st.x][st.y].yoko == 0){
      qu.push((xy){st.x,st.y+1,st.step+1});
      d[st.x][st.y+1] =  st.step + 1;
    }
    if(st.x >= 0 && st.x < w && st.y-1 >= 0 && st.y-1 < h && d[st.x][st.y-1] == 0 && maze[st.x][st.y-1].yoko == 0){
      qu.push((xy){st.x,st.y-1,st.step+1});
      d[st.x][st.y-1] =  st.step + 1;
    }

  }
 cout << d[w-1][h-1] << endl;
 /* for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cout << d[j][i] << " ";
    }
    cout << endl;
    }*/

}

int main(){

 
  while(cin >> w >> h && (w || h)){

   

    for(int i = 0; i < h; i++){

     
      for(int j = 0; j < w-1; j++){
	cin >> maze[j][i].tate;
      }

      if(i != h-1){
	for(int t = 0; t < w; t++){
	  cin >> maze[t][i].yoko;
	}
      }
    }
    wide();
  }


}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int no=1,n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        if(no*2<=no+k)no*= 2;
        else no+=k;
    }
    cout<<no<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

template <typename T1, typename T2>
bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int MOD = 1e9 + 7, N = 2e6 + 3;

int add(int a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
    if (a < 0) a += MOD;
    return a;
}

int mul(int a, int b) {
    return 1LL * a * b % MOD;
}

int binpow(int a, int n) {
    int res = 1;
    while (n) {
        if (n % 2)
            res = mul(res, a);
        a = mul(a, a);
        n /= 2;
    }
    return res;
}

int inv(int a) {
    return binpow(a, MOD - 2);
}

int fact[N];

int C(int n, int k) {
    return mul(fact[n], inv(mul(fact[n - k], fact[k])));
}

void solve() {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    
    fact[0] = 1;
    for (int i = 1; i < N; ++i)
        fact[i] = mul(fact[i - 1], i);
    
    int ans = 0;
    for (int r = r1; r <= r2; ++r) {
        ans = add(ans, add(C(c2 + r + 1, c2), -C((c1 - 1) + r + 1, c1 - 1)));
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));
    
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    
    return 0;
}


Measured memory_bytes: 8064
import java.io.PrintWriter

fun main(args: Array<String>) = Thread(null, ::abc138d_test, "", 64 * 1024 * 1024).start()

@OptIn(ExperimentalStdlibApi::class)
fun abc138d_test() {

    val pw = PrintWriter(System.out)

    val (n, q) = readLine()!!.split(' ').map { it.toInt() }

    val paths = Array(n) { java.util.ArrayDeque<Int>() }
    val values = IntArray(n) { 0 }

    repeat(n - 1) {
        val line = readLine()!!.split(' ').map { it.toInt() }
        paths[line[0] - 1].add(line[1] - 1)
        paths[line[1] - 1].add(line[0] - 1)
    }

    repeat(q) {
        val line = readLine()!!.split(' ').map { it.toInt() }
        values[line[0] - 1] += line[1]
    }
    val visited = BooleanArray(n) { false }

    fun dfs(i: Int) {
        visited[i] = true

        repeat(paths[i].size) {
            val index = paths[i].poll()
            if (!visited[index]) {
                values[index] += values[i]
                dfs(index)
            }
        }
    }

    dfs(0)

    pw.print(values[0])
    values.drop(1).forEach {
        pw.print(" $it")
    }

    pw.println()
    pw.flush()
}


Measured memory_bytes: 139276
#include<stdio.h>
#include<string.h>
int main()
{
    char s[100],s1[100];
    int i,cnt=0,l1,l2;
    scanf("%s\n %s",s,s1);
    l1 = strlen(s);
    l2 = strlen(s1);
    for(i=0; i<l1; i++)
    {
        if(s[i]==s1[i])cnt++;

    }
    if(cnt==l1 )printf("Yes\n");
    else printf("No\n");
    return 0;

}


Measured memory_bytes: 1648
N=int(input())
s=[[-1]*N for i in range(N)]
for i in range(N):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        s[i][x-1]=y
from itertools import product
r=0
for t in product((0,1),repeat=N):
    f=1
    for i in range(N):
        for j in range(N):
            if not ((t[i]==1 and s[i][j] in (t[j],-1)) or t[i]==0):
                f=0
    if f==1:
        r=max(r,sum(t))
print(r)

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

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    queue<vector<int>> q;
    for (int i = 1; i <= 9; i++)
    {
        q.push(vector<int>(1, i));
    }
    int counter = 0;
    vector<int> t;
    int k;
    while (true)
    {
        counter++;
        t = q.front();
        if (counter == n)
        {
            break;
        }
        q.pop();
        k = t.back();

        if (k == 0)
        {
            t.push_back(0);
            q.push(t);
            t.back() = 1;
            q.push(t);
        }
        else if (k == 9)
        {
            t.push_back(8);
            q.push(t);
            t.back() = 9;
            q.push(t);
        }
        else
        {
            t.push_back(k - 1);
            q.push(t);
            t.back() = k;
            q.push(t);
            t.back() = k + 1;
            q.push(t);
        }
    }
    for (int i = 0; i < t.size(); i++)
    {
        cout << t.at(i);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 15360
using System;
// using System.Collections.Generic;
// using System.Linq;

class Program
{
    static void Main()
    {
        int K = int.Parse(Console.ReadLine());
        String[] arr = Console.ReadLine().Split();
        int A, B;
        A = int.Parse(arr[0]);
        B = int.Parse(arr[1]);
        Console.WriteLine(A <= B / K * K ? "OK" : "NG");
        return;
    }
}

Measured memory_bytes: 27428
import bisect
N=int(input())
ls=[int(input()) for _ in range(N)]
color=[ls[-1]]
ans=1
for i in range(N-1):
  a=ls[-2-i]
  k=bisect.bisect_right(color,a)
  if k==ans:
    color.append(a)
    ans+=1
  else:
    color[k]=a
print(ans)

Measured memory_bytes: 7836
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    vector<ll> a(n);
    for(auto &x:a)cin >> x;

    int ans=-1;
    for(int i=0;i<30;i++){
        for(int j=0;j<n;j++){
            if(a[j]%2==1){
                ans=i;
                break;
            }
            a[j]=a[j]/2;
        }
        if(ans!=-1)break;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3568
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);
		int A=sc.nextInt();
		int B=sc.nextInt();
		PriorityQueue<Integer> pq=new PriorityQueue<Integer>();
		pq.add(-A);
		pq.add(-B);
		int ans=0;
		for(int t=0;t<2;++t) {
			int v=-pq.poll();
			ans+=v;
			pq.add(-(v-1));
		}
		pw.println(ans);
		pw.close();
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
    	return Integer.parseInt(next());
    }
    
    public long nextLong() {
    	return Long.parseLong(next());
    }
}

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

int main() {
  long long n;
  cin >> n;
  long long mini = LONG_LONG_MAX;
  long long x=0, y=0;
  for(long long i = 1; i <= sqrt(n); i++){
    if(n%i == 0){
      mini = min(mini , n/i + i);
    }
  }
  cout << mini-2 << endl;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 110;

int n, p[N];
int m, x[N];

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

    cin >> m;
    while(m--)
    {
        int id, x;
        cin >> id >> x;
        int res = x;

        for(int i = 1; i <= n; i++)
            if(i != id)
                res += p[i];

        cout << res << endl;
    }



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
inline int scan(){ return getchar(); }
inline void scan(int &a){ scanf("%d", &a); }
inline void scan(unsigned &a){ scanf("%u", &a); }
inline void scan(long &a){ scanf("%ld", &a); }
inline void scan(long long &a){ scanf("%lld", &a); }
inline void scan(unsigned long long &a){ scanf("%llu", &a); }
inline void scan(char &a){ cin >> a; }
inline void scan(float &a){ scanf("%f", &a); }
inline void scan(double &a){ scanf("%lf", &a); }
inline void scan(long double &a){ scanf("%Lf", &a); }
inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } }
inline void scan(string &a){ cin >> a; }
template<class T> inline void scan(vector<T> &vec);
template<class T, size_t size> inline void scan(array<T, size> &vec);
template<class T, class L> inline void scan(pair<T, L> &p);
template<class T, size_t size> inline void scan(T (&vec)[size]);
template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); }
template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); }
template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(T &a){ cin>>a; }
inline void in(){}
template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); }
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;
int main(){
    STR(S);
    ll ans1 = 0LL;
    ll ans2 = 0LL;

    for(int i = 0; i < S.size(); ++i){
        if(i%2 != S[i] - '0'){
            ans1++;
        } else {
            ans2++;
        }
    }
    cout << min(ans1,ans2) << endl;
    
}

Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>

int main(){
	double a,n,s[1001] = {0},m,sum=0;
	int i;
	
	scanf("%lf",&n);
	
	while(n!=0){
		
	
		for(i=0;i<n;i++){
			scanf("%lf",&s[i]);
			sum+=s[i];
		}
		m=sum/n;
		
		for(i=0;i<n;i++){
			a+=pow(s[i]-m,2.0);
		}

		a=sqrt(a/n);
		
		printf("%0.8f\n",a);
		sum=0; a=0;
		scanf("%lf",&n);
	}
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    string S;
    cin >> S;
    vector<string> A;
    vector<int> pos;
    vector<int> X;
    vector<int> begin;
    vector<int> ans(S.size());

    REP(i,S.size()) ans[i] = 0;

    bool flagR = true;
    int count = 0;
    int res;
    int resb = 0;
    REP(i,S.size()){
        if(S[i]=='R'){
            if(!flagR){
                pos.push_back(res);
                X.push_back(count);
                begin.push_back(resb);
                count = 0;
                flagR = true;
                resb = i;
            }
            count++;
        }else{
            if(flagR){
                res = i;
                count++;
                flagR = false;
            }
            else count++;
        }
    }
    pos.push_back(res);
    X.push_back(count);
    begin.push_back(resb);

    REP(i,pos.size()){
        if(X[i] % 2 == 0){
            ans[pos[i]] = X[i] / 2;
            ans[pos[i]-1] = X[i] / 2;
        }else{
            int dif = pos[i] - begin[i];
            int a = X[i] - dif;
            if(dif > a){
                if(dif % 2 == 0){
                    ans[pos[i]-1] = X[i] / 2;
                    ans[pos[i]] = X[i] / 2 + 1;
                }else{
                    ans[pos[i]-1] = X[i] / 2 + 1;
                    ans[pos[i]] = X[i] / 2;
                }
            }else{
                if(a % 2 == 0){
                    ans[pos[i]-1] = X[i] / 2 + 1;
                    ans[pos[i]] = X[i] / 2;
                }else{
                    ans[pos[i]-1] = X[i] / 2;
                    ans[pos[i]] = X[i] / 2 + 1;
                }
            }
        }
    }
    REP(i,S.size()-1) cout << ans[i] << " ";
    cout << ans[S.size()-1] << endl;  
}

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

signed main() {
    int n;
    cin >> n;
    int cnta[n]={}, cntc[n]={};
    vector<int> a(n), b(n), c(n);
    for (int i=0;i<n;i++) cin >> a[i];
    for (int i=0;i<n;i++) cin >> b[i];
    for (int i=0;i<n;i++) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    for (int i=0;i<n;i++) {
        // cout << a[i] << b[i] << c[i] << endl;
        auto ai = upper_bound(a.begin(), a.end(), b[i]-1);
        cnta[i] = ai - a.begin();
        auto ci = lower_bound(c.begin(), c.end(), b[i]+1);
        cntc[i] = c.end() - ci;
        // cout << cnta[i] << " " << cntc[i] << endl;
    }
    int sum=0;
    for (int i=0;i<n;i++) {
        sum += cnta[i]*cntc[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 4096
object Main extends App {
    val Array(x, y) = io.StdIn.readLine.split(" ").map(_.toInt)

    var flag = false
    for {
        bird <- 0 to (y/2).ceil.toInt
        turtle <- 0 to (y/4).ceil.toInt
        if bird + turtle == x
        if bird*2 + turtle*4 == y
    } flag = true

    if (flag) println("Yes") else println("No")
}

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

using namespace std;
// (setq-default c-basic-offset 2)

int m = 2019;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  reverse(s.begin(), s.end());
  int x = 1;
  int tot = 0;
  vector<int> cnt(m);
  long long ret = 0;

  for (int i = 0; i < n; ++i) {
    cnt[tot]++;

    tot = (tot + (s[i] - '0') * x) % m;
    x = (x * 10) % m;

    ret += cnt[tot];
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3724
#include <stdio.h>

#define MIN(x,y) ((x)<(y)?(x):(y))

typedef long long int ll;

int a[2000];

int dp[2000];
ll dp2[2];

int main(){
  int n, x, i, j;
  scanf("%d%d", &n, &x);
  for(i=0;i<n;i++){
    scanf("%d", a+i);
    dp2[0] += dp[i] = a[i];
  }

  for(j=1;j<n;j++){
    int b = j&1;
    dp2[b] = (ll) j*x;
    for(i=0;i<j;i++)
      dp2[b] += dp[i] = MIN(dp[i], a[i + n - j]);
    for(;i<n;i++)
      dp2[b] += dp[i] = MIN(dp[i], a[i - j]);
    dp2[b] = MIN(dp2[b^1], dp2[b]);
  }

  printf("%lld\n", dp2[~n&1]);
  return 0;
}


Measured memory_bytes: 128
import numpy as np

def calc(op1, op2, op3):
    # op... True...+, False...-
    op1_flag = op2_flag = op3_flag = 1
    if not op1:
        op1_flag = -1
    if not op2:
        op2_flag = -1
    if not op3:
        op3_flag = -1
    return xyz[:, 0]*op1_flag + xyz[:, 1]*op2_flag + xyz[:, 2]*op3_flag

N, M = list(map(int, input().split()))
xyz = np.array([list(map(int, input().split())) for i in range(N)])
ans = 0
ops = [[1,1,1], [1,1,0], [1,0,1], [1,0,0], [0,1,1], [0,1,0], [0,0,1], [0,0,0]]
for op1, op2, op3 in ops:
    table = np.sort(calc(op1, op2, op3))[::-1]
    ans = max(ans, np.sum(table[:M]))

print(ans)

Measured memory_bytes: 12556
#!/usr/bin/python
import sys
if sys.version_info[0]>=3: raw_input=input

try:
	while True:
		n=int(raw_input())
		if n==0: break
		r=0
		i=1
		while 1:
			n-=i
			if n<=i: break
			i+=1
			if n%i==0: r+=1
		print(r)
except EOFError:
	pass

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

typedef unsigned long long ull;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	ull n;
	cin >> n;
	for (ull a=1; a<=3500; a++) {
		for (ull b=1; b<=3500; b++) {
			ull p = n*a*b;
			ull q = 4*a*b - n*(a+b);

			if (q && p % q == 0) {
				cout << a << ' ' << b << ' ' << p/q << '\n';
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256