akhauriyash/Code-Regression huggingface dataset:
from sys import stdin
import numpy as np

s = int(input())
lst = [s]

num = s
cnt = 1
while(True):
  cnt += 1
  if (num % 2 == 0):
    num /= 2
  else:
    num = 3*num + 1
  if num in lst:
    break
  else:
    lst.append(num)

print(cnt)
    
    
    



Measured memory_bytes: 14420
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long l,r;
	cin>>l>>r;
	if (r-l>=2018){
		cout<<"0";
		return 0;
	}
    long long minv=2020;
    for(long long i=l;i<r;i++) {
        for(long long j=r;j>l;j--) {
            int cur=(i*j)%2019;
            if(cur<=minv){
				minv=cur;
			}
        }
    }
    cout<<minv;
	return 0;
}


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

int a,b,c,k,mx;

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

	cin>>a>>b>>c>>k;
	mx=max(c,max(a,b));
	if(mx==a)
		cout<<(mx*pow(2,k))+b+c;
	else if(mx==b)
		cout<<(mx*pow(2,k))+a+c;
	else
		cout<<(mx*pow(2,k))+a+b;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();
		int[] p = new int[n];
		int ans = 0;
		
		for(int i=0;i<n;i++) {
			p[i] = scan.nextInt();
		}
		
		Arrays.sort(p);
		
		for(int j=0;j<k;j++) {
			ans += p[j];
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 38864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
const long long INF = INT64_MAX;

#define REP(i, n) for(ll i=0;i<n;i++)
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve() {
    str S;
    cin >> S;
    S.erase(unique(S.begin(), S.end()), S.end());
    cout << S.size() - 1 << endl;
}

int main() {
    FIO;
    solve();
    return 0;
}


Measured memory_bytes: 512
N = int(input())
L = [int(s) for s in input().rstrip().split(' ')]
D = {}
for x in L:
  if x not in D.keys():
    D[x] = 1
  else:
    D[x] += 1
S = 0
for y in D.values():
  if y > 1:
    S += y*(y-1) // 2
for i in range(N):
  print(S-D[L[i]]+1)

Measured memory_bytes: 26012
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
	int n;
	double x[1001], y[1001];
	double dm, du, dc, d3, tmp;

	dm = 0.0; du = 0.0; dc = 0.0; d3 = 0.0;
	cin >> n;
	
	for(int i=0; i<n; i++) cin >> x[i];
	for(int i=0; i<n; i++) cin >> y[i];

	for(int i=0; i<n; i++) {
		tmp = abs(x[i] - y[i]);
		if(dc < tmp) dc = tmp;
		dm += tmp;
		du += pow(tmp, 2);
		d3 += pow(tmp, 3);
	}

	cout << fixed << setprecision(8);
	cout << dm << endl;
	cout << sqrt(du) << endl;
	cout << pow(d3, 1.0/3.0) << endl;
	cout << dc << endl;

	return 0;
}

Measured memory_bytes: 3468
N = int(input())
T,A=map(int,input().split())
List = list(map(int, input().split()))
t = 0
mid = 0
MID = 100000000000
res = 100000000000
for i in range(N):
  t = T - 0.006*List[i]
  mid = abs(A-t)
  if mid < MID:
    MID = mid
    res = i+1
print(res)

Measured memory_bytes: 9104
#include<cstdio>
int F[46];
int fib(int flag){
	if(flag<2){
		return 1;
	}else if(F[flag]){
		return F[flag];
	}else{
		return F[flag]=fib(flag-1)+fib(flag-2);
	}
}
int main(){
	int num;
	scanf("%d", &num);
	printf("%d\n", fib(num));
	return 0;
}


Measured memory_bytes: 2752
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
	int R;
	scanf("%d",&R);
	if(R<1200)printf("ABC\n");
	else if(R<2800)printf("ARC\n");
	else printf("AGC\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int h,w;
string ss[100];
bool x[100][100];
int ans=0;

void f(int k,int l){
	if(k!=0&&x[k-1][l]&&ss[k][l]==ss[k-1][l]){
		x[k-1][l]=false;
		f(k-1,l);
	}
	if(l!=0&&x[k][l-1]&&ss[k][l]==ss[k][l-1]){
		x[k][l-1]=false;
		f(k,l-1);
	}
	if(k!=h-1&&x[k+1][l]&&ss[k][l]==ss[k+1][l]){
		x[k+1][l]=false;
		f(k+1,l);
	}
	if(l!=w-1&&x[k][l+1]&&ss[k][l]==ss[k][l+1]){
		x[k][l+1]=false;
		f(k,l+1);
	}
}
int main()
{
	while(true){
		for(int i=0;i<100;i++)for(int j=0;j<100;j++)x[i][j]=true;
		scanf("%d%d",&h,&w);
		if(h==0&&w==0)return 0;
		for(int i=0;i<h;i++)cin >> ss[i];

		ans=0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(x[i][j]){
					ans++;
					f(i,j);
				}
			}
		}
		cout << ans << "\n";
	}
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main()
{
  string s;
  cin >> s;
  if(s.length() == 2) {
    cout << s << endl;
  } else {
    cout << s[2] << s[1] << s[0] << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pii pair<ll,ll>
using namespace std;
typedef long long ll;
const ll modd=1000000007;
ll n,k,fac[2000006];
string s;
ll qpow(ll a,ll b) {
	ll ans=1,base=a;
	while(b) {
		if(b&1) ans=ans*base%modd;
		b>>=1,base=base*base%modd;
	}
	return ans;
}

ll C(ll n,ll m) {
	return fac[n]*qpow(fac[m],modd-2)%modd*qpow(fac[n-m],modd-2)%modd;
}
void solve() {
	ll ans=0;
	for(int i=n; i<=n+k; i++)
		(ans+=C(i-1,n-1)*qpow(25,i-n)%modd*qpow(26,n+k-i)%modd)%=modd;
	cout<<ans;
}
void init() {
	n=s.size();
	fac[0]=1;
	for(ll i=1; i<=n+k; i++)
		fac[i]=fac[i-1]*i%modd;
}
int main() {
	cin>>k>>s;
	init();
	solve();
	return 0;
}

Measured memory_bytes: 20056
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
using namespace std;

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<int>>

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


int main(){
  vint a(3);cin >> a[0] >> a[1] >> a[2];
  VSORT(a);
  cout << a[0] + a[1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//D - Handstand
int a[100001];
int main(void){
    int n,k,m=0;
    string s;
    std::cin >> n >> k >>s;
    
    s += '1';
    for (int i = 0; i < n; i++) {
        a[i+1]=a[i];
        if(s[i]=='0' && s[i+1] =='1')
            a[i+1]++;
    }
    for(int l=0,r=1;r<=n;){
        if(a[r]-a[l]>k)l++;
        else{
            if(r==n || s[r-1]=='1')
                m=max(m,r-l);
            r++;
        }
    }
    std::cout << m << std::endl;
    return 0;
}

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

using namespace std;

int calcscore()
{
	int score=0,strike=0,spare=0,pin[2];

	for(int i=1;i<=9;i++){
		for(int j=0;j<2;j++){
			if(j==1 && pin[0]==10)	continue;
			cin>>pin[j];
			if(strike>0)	score+=(strike%10)*pin[j],strike/=10;
			if(spare>0)		score+=pin[j],spare--;
			score+=pin[j];
			if(j==1)	pin[j]+=pin[j-1];
			if(pin[j]==10){
				if(j==0)	strike+=11;
				if(j==1)	spare++;
			}
		}
	}

	for(int i=0;i<2;i++){
		cin>>pin[i];
		if(strike>0)	score+=(strike%10)*pin[i],strike/=10;
		if(spare>0)		score+=pin[i],spare--;
		score+=pin[i];
	}
	if(pin[0]+pin[1]>=10){
		cin>>pin[0];
		score+=pin[0];
	}

	return score;
}

int main()
{
	for(int m;cin>>m,m;){
		vector< pair<int,int> > data(m);
		for(int i=0;i<m;i++){
			int id;	cin>>id;
			data[i]=make_pair(-calcscore(),id);
		}
		sort(data.begin(),data.end());
		for(int i=0;i<m;i++)
			cout<<data[i].second<<' '<<-data[i].first<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
//CODING ME ACCHHA KARNEKA HAI TERKO TO BAS PRACTICE KARTE REH
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define aisort sort(a,a+n)
#define adsort sort(a,a+n,greater<ll>())
#define PI 2 * acos(0)

typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef set<ll> Set;

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;

//MODULO OPEARTIONS
    inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
    inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
    inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
    ll fastpow(ll x,ll y)
    {ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}

//MODULAR INVERSE
    ll inv(ll x){ return fastpow(x , mod - 2);}
    
//PRIME
    bool isPrime(ll n) { if (n <= 1)  return false; if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } 


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,r;
    cin>>n>>r;
    if(n>=10)
    cout<<r;
    else
    cout<<r+(100*(10-n));
}



Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A = Integer.parseInt(scanner.next());
        int B = Integer.parseInt(scanner.next());
        scanner.close();

        if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
            System.out.println("Possible");
        } else {
            System.out.println("Impossible");
        }
    }
}


Measured memory_bytes: 21588
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}


map <char, int> m;

int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
    	m[s[i]] = 1;
    }
    if (m['N'] != m['S'] || m['W'] != m['E']) {
    	cout << "No";
    } else {
    	cout << "Yes";
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        Solver s = new Solver();
        int test = 1;
        for (int i = 1; i <= test; i++) {
            s.solve(i, in, out);
        }
        out.close();
    }

    static class Solver {
        int[] dp = new int[10];
        int[][] c;
        void solve(int test_case, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            Arrays.fill(dp, Integer.MAX_VALUE);
            c = new int[10][10];
            for (int i = 0; i <= 9; i++)
                for (int j = 0; j <= 9; j++)
                    c[i][j] = in.nextInt();
            int[][] a = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) a[i][j] = in.nextInt();
            }
            Queue<Integer> q = new LinkedList<>();
            int[] get = new int[10];
            for (int i = 0; i <= 9; i++) {
                q.clear();
                Arrays.fill(dp, Integer.MAX_VALUE);
                q.add(i);
                dp[i] = 0;
                while (!q.isEmpty()) {
                    int x = q.remove();
                    for (int j = 0; j <= 9; j++) {
                        if (j == i) continue;
                        if (dp[j] > dp[x] + c[x][j]) {
                            dp[j] = dp[x] + c[x][j];
                            q.add(j);
                        }
                    }
                }
                get[i] = dp[1];
            }
            int ans = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (a[i][j] == 1 || a[i][j] == -1) continue;
                    ans += get[a[i][j]];
                }
            }
            out.println(ans);
        }
    }

    static class InputReader {

        BufferedReader br;
        StringTokenizer st;

        public InputReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 27732
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getChar >>= putChar . f >> putChar '\n'

f 'A' = 'T'
f 'T' = 'A'
f 'G' = 'C'
f 'C' = 'G'

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

using namespace std;

int main() {

	char c;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}
}

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

double n,m,sumv,ans=0;
double a[100005];

signed main()
{
	cin>>n>>m;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
		sumv+=a[i];
	}
	double num=sumv*(1.00/(4.00*m));
	
	for (int i=1;i<=n;i++)
	{
		if (a[i]>=num)  ans++;
	}
	if (ans>=m)  cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int x,y,A;
    double S,W,H;
    scanf("%lf %lf %d %d",&W,&H,&x,&y);
    
    if(x==W/2.0&&y==H/2.0)
    A=1;
    else A=0;
    
    S=W*H;
    printf("%lf %d",S/2.0,A);
    return(0);
}


Measured memory_bytes: 384
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int main() {
    int N, ans=0;
    cin >> N;
    for (int i = 1;; i++) {
        if (i*i <= N)ans = i*i;
        else break;
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (a[a[i] - 1] == i + 1) count++;
  }
  cout << count / 2 << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

void swap(int *a,int *b){
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

void babbleSort(int *a,int n){
	for(int i=0;i<n;i++){
		for(int j=n-1;j>i;j--){
			if(a[j]>=a[j-1]){
				swap(&a[j],&a[j-1]);
			}
		}
	}
}

int main(){

	int k,t;
	int *a;

	cin>>k>>t;
	a = new int[t];

	for(int i=0;i<t;i++){
		cin>>a[i];
	}

	babbleSort(a,t);

	int sum=0;

	if(t==1){
		cout<<a[0]-1<<endl;
	}
	else{
		for(int i=1;i<t;i++){
			sum+=a[i];
		}
		if(a[0]-sum-1<=0){
			cout<<0<<endl;
		}
		else{
			cout<<a[0]-sum-1<<endl;
		}
	}

	return 0;




}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc081/tasks/abc081_b


def two_factor(x):
    cnt = 0
    while x % 2 == 0:
        cnt += 1
        x //= 2
    return cnt


N = int(input())
a = map(two_factor, map(int, input().split()))
print(min(a))


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int h, w; std::cin >> h >> w;
  int cost[10][10];
  rep(i, 10) rep(j, 10) {
    int c; std::cin >> c;
    cost[i][j] = c;
  }
  rep(k, 10) rep(i, 10) rep(j, 10)
    chmin(cost[i][j], cost[i][k] + cost[k][j]);
  int ans = 0;
  rep(i, h) rep(j, w) {
    int a; std::cin >> a;
    if (a == -1 || a == 1) continue;
    ans += cost[a][1];
  }
  std::cout << ans << "\n";
}


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

int main(){

	int a , b;
	cin >> a >> b ;


	if(a < b){
	cout<< "a < b" << endl;
	}
	else if (a > b){
	cout<< "a > b" << endl;
	} else {
	cout<< "a == b" << endl;
	}

	return 0;
}


Measured memory_bytes: 3056
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class Main  implements Runnable { //Runnableを実装する

    public static void main(String[] args) {

        new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行

    }

    public void run() {
		Scanner sc = new Scanner(System.in);
		//Scanner sc = new Scanner("3 10 2 5 6 3 4");
		int n = Integer.parseInt(sc.next());
		//int b = Integer.parseInt(sc.next());
		//int t = Integer.parseInt(sc.next());
		//int k = 0;
		//int k = Integer.parseInt(sc.next());
		//String str = sc.next();
		//char c[] = str.toCharArray();
		int v[] = new int[n];
		int c[] = new int[n];
		for (int i = 0; i < n; i++)
		{
			v[i]= Integer.parseInt(sc.next());
		}
		for (int i = 0; i < n; i++)
		{
			c[i]= Integer.parseInt(sc.next());
		}
		int ans = 0;
		for (int i = 0; i < n; i++)
		{
			if(v[i]>c[i])
			{
				ans += v[i]-c[i];
			}
		}

		PrintWriter out = new PrintWriter(System.out);
		out.println(ans);
		out.flush();
	}
}

Measured memory_bytes: 22868
#include<stdio.h>
#define N 100000

int partition(int *,int, int);

int main(){

  int i,n,a,S[N];

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&S[i]);
  a = partition(S,0,n-1);

  for(i=0;i<n;i++){
    if(i==a) printf("[%d]",S[i]);
    else printf("%d",S[i]);
    if(i != n-1) printf(" ");  
	 

  }
  printf("\n");


  return 0;
}

int partition(int *S,int p,int r){
  int x,i,j,temp;

  x = S[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(S[j]<= x){
      i = i+1;
      temp = S[i];
      S[i] = S[j];
      S[j] = temp;

    }

  }
  temp = S[i+1];
  S[i+1] = S[r];
  S[r] = temp;

  return i+1;
  


}



Measured memory_bytes: 2188
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
 
signed main() {
    int A1,A2,A3;
    cin>>A1>>A2>>A3;
    cout<<(int)max(abs(A2-A3),max(abs(A1-A2),abs(A1-A3)));
    return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
        cin.tie(0);
	int n;
	cin >> n;
	set<string> st;
	while(n--){
		string order;
		string str;
		
		cin>>order;
		cin>>str;
		
		if(order=="insert"){
			st.insert(str);
		}else{
			if(st.find(str)!=st.end()){
				cout<<"yes"<<endl;
			}else{
				cout<<"no"<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 27056
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
typedef vector<P> Pol;
struct C{P p;D r;};
D inf=1e50,eps=1e-10,PI=acos(0.0)*2;
bool eq(D a, D b) { return abs(a-b)<eps;}
bool eq(P a, P b) { return abs(a-b)<eps;}
int sig(D a) { return eq(a,0) ? 0 : (a>0 ? 1 : -1);}
int large(D a,D b){return eq(a,b)?0:(a>b?1:-1);}
bool compxy (const P& l, const P& r){
	return eq(l.X,r.X) ? l.Y<r.Y : l.X < r.X;
}
inline D dot(P a, P b) { return real(conj(a)*b);}
inline D cro(P a, P b) { return imag(conj(a)*b);}
//enum ENCCW{CCW(left)=1, CW(right)=-1, FRONT=-2, BACK=2, ON=0};
//ON優先(including endpoint)
inline int ccw (P a, P b, P c){
	if(sig(cro(b-a,c-a))==1) return 1;
	if(sig(cro(b-a,c-a))==-1) return -1;
	if(eq(abs(a-c)+abs(c-b),abs(a-b))) return 0;
	if(eq(abs(a-b)+abs(b-c),abs(a-c))) return -2;
	if(eq(abs(c-a)+abs(a-b),abs(c-b))) return 2;
}

inline Pol convex(Pol p){		//convex
	int n=p.size(),k=0;
	sort(all(p),compxy);
	Pol ret(2*n);
	rep(i,n){
		while(k>=2 && ccw(ret[k-2],ret[k-1],p[i])<=0) --k;
		ret[k++]=p[i];
	}
	for(int i=n-2,t=k+1;i>=0;i--){
		while(k>=t && ccw(ret[k-2],ret[k-1],p[i])<=0) --k;
		ret[k++]=p[i];
	}
	ret.resize(k-1);
	return ret;
}

double ans[110];
double pi = acos(-1);

int main(){
	int N;
	cin>>N;
	using Pii = pair<int,int>;
	map<Pii,int> p2id;

	Pol pol;
	rep(i,N){
		int x,y;
		cin>>x>>y;
		p2id[Pii(x,y)] = i;
		pol.pb(P(x,y));
	}
	Pol conv = convex(pol);

	int K = conv.size();
	rep(i,K){
		P a = conv[(i-1+K)%K] - conv[i];
		P b = conv[(i+1)%K] - conv[i];
		double theta = arg(b/a);
		double res = 1.0-(pi-theta)/(2.0*pi);
		int id = p2id[Pii(conv[i].X,conv[i].Y)];
		ans[id] = res;
	}
	rep(i,N){
		printf("%.12f\n",ans[i]);
	}
}


Measured memory_bytes: 384
n=int(input())
a=[-1]+list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
d=0
for i in range(1,n+1):
    if a[i-1]+1==a[i]:
        d+=c[a[i-1]-1]
    d+=b[a[i]-1]
print(d)

Measured memory_bytes: 38492
// Aizu Vol0 0023: Circles Intersection
// 2017.8.1

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

char *gets(char *);

#define MAX 500
char buf[MAX + 5], *p;

long long getDouble(void)
{
	int minus = 0, len = 0;
	long long n = 0;

	while (isspace(*p)) p++;
	if (*p == '-') p++, minus = 1;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	if (*p == '.') p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0'), len++;
#define MAGIC 8
	if (len > MAGIC) while (1);
	while (len < MAGIC) n = 10 * n, len++;
	if (minus) n = -n;
	return n;
}

int main()
{
	long long xa, ya, ra;
	long long xb, yb, rb;
	long long d;
	int di, dn;    // for dataset

	gets(buf), dn = atoi(buf);
	for (di = 1; di <= dn; di++) {
		gets(p = buf);
		xa = getDouble(), ya = getDouble(), ra = getDouble();
		xb = getDouble(), yb = getDouble(), rb = getDouble();

		d = (xa - xb)*(xa - xb) + (ya - yb)*(ya - yb);

		if      (d > (ra + rb)*(ra + rb)) puts("0");
		else if (d < (ra - rb)*(ra - rb)) puts(ra > rb ? "2" : "-2");
		else puts("1");
	}
	return 0;
}

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

using namespace std;

using ll = long long int;

#define REP(i, N) for (int i = 0; i < (N); ++i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    REP(four, 26){
        REP(seven, 15){
            if (4 * four + 7 * seven == N){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
    int H,W;
    for(int a = 0; a < 100; a++){
        cin >> H >> W ;
        if (H == 0 && W == 0) break;
        for(int b = 0; b < H; b++){
            for(int c = 0; c < W; c++){
                if(b % 2 == 0){
                    if(c % 2 == 0){
                        cout << "#";
                    } else {
                        cout << ".";
                    }
                } else if(b % 2 == 1){
                    if(c % 2 == 0){
                        cout << ".";
                    }else {
                        cout << "#";
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3052
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = 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()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

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 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)...); }
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 N; cin >> N;
	V<double> p(N+1,0);
	FOR(i,1,N + 1) cin >> p[i];

	V<V<double>> dp(N + 1, V<double>(N + 1, 0.));
	dp[0][0] = 1.;
	FOR(i,1,N+1){
		REP(j,N+1){
			if (j > i) continue;
			dp[i][j] += dp[i - 1][j] * (1. - p[i]);
			dp[i][j] += dp[i - 1][j - 1] * p[i];
		}
	}
	double ans = 0.;
	REP(i, N + 1) if (i > N / 2) ans += dp[N][i];
	printf("%.12f", ans);
	return 0;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
int main(){

    int A,B;
    int x=0;
    cin>>A>>B;
    if(A>=0&&B<=24){
        x=A+B;
       if(x>=24){
           x=x%24;
       }
       printf("%d",x);
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
using namespace std;
using ll = unsigned long long;
using p = pair<int, int>;

int main()
{
    ll a;
    cin >> a;

    std::cout << a + pow(a, 2) + pow(a, 3) << endl;

    return 0;
}

Measured memory_bytes: 4308
from fractions import gcd
A, B, C, D = map(int,input().split())
print(B - A + 1 - ((B // C - (A - 1) // C) + (B // D - (A - 1) // D) - (B // ((C * D) // gcd(C, D)) - (A - 1) // ((C * D) // gcd(C, D)))))


Measured memory_bytes: 66412
#include<stdio.h>

int A[1000000],n;

int binarySearch(int key){
  int left=0;
  int right=n;
  int mid;
  while(left<right){
    mid=(left+right)/2;
    if(key==A[mid])return 1;
    if(key>A[mid])left=mid+1;
    else if(key<A[mid])right=mid;
  }
  return 0;
}

int main(){
  int i,q,k,sum=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&k);
    if(binarySearch(k))sum++;
  }
  printf("%d\n",sum);

  return 0;
}

Measured memory_bytes: 3076
import java.util.*

fun main(args: Array<String>){
    val sc = Scanner(System.`in`)
    val A = sc.nextInt()
    val B = sc.nextInt()
    val C = sc.nextInt()
    val X = sc.nextInt()
    var ans = 0
    for (i in (0..A)){
        for (j in (0..B)){
            if(i * 500 + j * 100 <= X && X <= i * 500 + j * 100 + C * 50){
                ans += 1
            }
        }
    }
    println(ans)
}


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

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
    }
    if n * m % 2 == 0 {
        println!("Even");
        return;
    }
    println!("Odd");
}


Measured memory_bytes: 4352
import java.util.*;
import java.io.*;

public class Main {

    static StreamTokenizer in;

    static int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    public static void main(String[] args) throws Exception {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = nextInt();
        Flower[] flowers = new Flower[n];

        for (int i = 0; i < n; i++) {
            flowers[i] = new Flower(nextInt(), 0);
        }

        for (int i = 0; i < n; i++) {
            flowers[i].beauty = nextInt();
        }

        Flower[] dp = new Flower[n];

        TreeSet<Flower> treeSet = new TreeSet<>();

        for (int i = 0; i < n; i++) {
            dp[i] = flowers[i];

            if (treeSet.lower(dp[i]) != null) {
                dp[i].beauty = flowers[i].beauty + treeSet.lower(dp[i]).beauty;
            }

            if (treeSet.lower(dp[i]) != null && treeSet.lower(dp[i]).beauty >= dp[i].beauty) continue;
            else {
                treeSet.add(dp[i]);
                while (treeSet.higher(dp[i]) != null && treeSet.higher(dp[i]).beauty <= dp[i].beauty) {
                    treeSet.remove(treeSet.higher(dp[i]));
                }
            }
        }

        long result = 0;

        for (int i = 0; i < n; i++) {
            result = Math.max(result, dp[i].beauty);
        }

        out.println(result);

        out.close();
    }

    static class Flower implements Comparable<Flower>{
        int height;
        long beauty;

        Flower(int height, long beauty) {
            this.height = height;
            this.beauty = beauty;
        }

        @Override
        public int compareTo(Flower o) {
            return this.height - o.height;
        }
    }
}

Measured memory_bytes: 55204
/*
これを入れて実行
g++ code.cpp
./a.out
*/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <stack>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
	if (r == 0 || r == n){
		return 1;
	}
	else if (r == 1){
		return n;
	}
	return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
	r = n - r;
	ll ret = 1;
	for (ll i = n; i >= r + 1; i--) ret *= i;
	return ret;
}

//-----------------------ここから-----------

int main(void){
	int n, m;
	cin >> n >> m;

	if (n == m){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int[] num = new int[n];
			for(int i = 0;i < n;i++){
				num[i] = scan.nextInt();
			}
			Arrays.sort(num);
			System.out.println(1);
			for(int i = 2;i <= num[0];i++){
				for(int j = 0;j < n;j++){
					if(num[j]%i != 0){
						break;
					}
					if(j == n-1){
						System.out.println(i);
					}
				}
			}
		}
	}
}

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

if N == 1 and M == 1:
  print(0)
elif N == 0 and M == 1:
  print(0)
elif N == 1 and M == 0:
  print(0)
elif N == 0 and M == 0:
  print(0)
  
else:
  c = N*(N-1) / 2
  d = M*(M-1) / 2
  print(int(c+d))

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

int a, b;

int main()
{
  int ans=0;

  cin >> a >> b;

  for (int i=0; i<2; i++) {
    if (a > b) {
      ans += a;
      a--;
    } else {
      ans += b;
      b--;
    }
  }
  cout << ans << endl;

  return 0;
}


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

#n!とその逆元を求めておく
N=4*10**5+10
g1=[1,1] #n!
g2=[1,1] #n!の逆元
inverse=[0,1]
for i in range(2,N+1):
    g1.append((g1[-1]*i)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1])%mod)

def cmb(n,r): #nCrを求める
    if (r<0 or r>n):
        return 0
    r=min(r,n-r)
    return g1[n]*g2[r]*g2[n-r]%mod

if n<=k-1:
    print(cmb(2*n-1,n))
else:
    ans=0
    for a in range(k+1):
        ans+=cmb(n,a)*cmb(n-1,a)%mod
        ans%=mod
    print(ans)

Measured memory_bytes: 50832
from copy import deepcopy
from operator import add, sub

class TwoPointers:
    def __init__(self, cond, init=0, right=add, left=sub):
        self.cond = cond
        self.init = init
        self.next_right = right
        self.next_left = left
    
    def __call__(self, A, uniq=True):
        cond = self.cond
        next_right, next_left = self.next_right, self.next_left
        s = deepcopy(self.init)
        n = len(A)
        X = {}
        r = 0
        for l in range(n):
            if not uniq:
                X[l] = r
            while r < n and cond(s, A[r]):
                s = next_right(s, A[r])
                r += 1
                X[l] = r
            if l == r:
                r += 1
            else:
                s = next_left(s, A[l]) if l+1 != r else deepcopy(self.init)
        return list(X.items())
    
    def maximum(self, A):
        X = self.__call__(A)
        return max(r-l for l, r in X) if X else 0
    
    def count(self, A):
        X = self.__call__(A, False)
        return sum(r-l for l, r in X)

n, *A = map(int, open(0).read().split())
print(TwoPointers(lambda s, n: s + n == s ^ n).count(A))

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

#define ll long long

int main() {
    string s;
    cin >> s;
    int size = s.size();
    char pre_char = '0';
    int count = 0;
    for(int i = 0;i < size;i++) {
        if(pre_char == '0' && s[i] == '0') {
            count++;
            pre_char = '1';
        }else if(pre_char == '1' && s[i] == '1') {
            count++;
            pre_char = '0';
        }else if(pre_char == '0' && s[i] == '1') {
            pre_char = '1';
        }else if(pre_char == '1' && s[i] == '0') {
            pre_char = '0';
        }
    }
    printf("%d\n", min<int>(count, size - count));
    return 0;
}


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

int main()
{
    int i = 1;
    while(1) {
        int x;
        
        cin >> x;
        
        if (x != 0) {
            cout << "Case " << i << ": " << x << endl; 
            i += 1;
        } else {
            break;
        }
    }
}


Measured memory_bytes: 2988
s = input()
ans = 1

if s[0] == "A":
    ans += 1
    
part = s[2:-1]
if part.count("C") == 1:
    ans += 1
      
for i in range(len(s)):
    if 65 < ord(s[i]) <91 and ord(s[i]) != 67:
        ans -= 1
        
print("AWCA"[ans<3::2])

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int N,D,y,x,f;
char S[105][105];


int main()
{
	scanf("%d",&N);
	for(;N--;)
	{
		scanf("%d",&D);
		memset(S,0,sizeof(S));
		for(y=D,x=1,f=-1;;)
		{
			if(f!=-1)S[--y][++x]=0;
			for(f=0;y>=1&&!S[y-1][x]&&!S[y][x+1]&&!S[y][x-1];y--)
			{
				f=1;
				S[y][x]=1;
			}
			if(!f)break;
			for(f=0,S[++y][++x]=0;x<=D&&!S[y][x+1]&&!S[y-1][x+1]&&!S[y+1][x];x++)
			{
				f=1;
				S[y][x]=1;
			}
			if(!f)break;
			for(f=0,S[++y][--x]=0;y<=D&&!S[y+1][x]&&!S[y][x+1]&&!S[y][x-1];y++)
			{
				f=1;
				S[y][x]=1;
			}
			if(!f)break;
			for(f=0,S[--y][--x]=0;x>=1&&!S[y][x-1]&&!S[y-1][x]&&!S[y+1][x];x--)
			{
				f=1;
				S[y][x]=1;
			}
			if(!f)break;
		}
		for(y=1;y<D+1;y++,puts(""))
			for(x=1;x<D+1;x++)
				putchar(S[y][x]==1?'#':' ');
		if(N)puts("");
	}
	return 0;
}

Measured memory_bytes: 600
def cost(x,a,b):
    cost=0
    for i in range(b):
        cost+=(x-a[i])**2
    return cost

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
    ans+=a[i]
ans/=n
ans=int(ans)
print(min(cost(ans,a,n),cost(ans+1,a,n)))

Measured memory_bytes: 9192
#include<stdio.h>
int main(void){
  int n,x,i;
  long int sum=0,min=1000000,max=-1000000;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&x);
    sum += x;
    if(x>max)max = x;
    if(x<min)min = x;
  }
  printf("%ld %ld %ld\n",min,max,sum);
  return(0);
}

Measured memory_bytes: 1848
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    if(a%b==c){
        cout << "YES" << endl; 
    }
    for(int i=2;i<=1000000;i++){
        if((a+i*a)%b==c){
            cout << "YES" << endl;
            return 0;
        }
        
    }
    cout << "NO" << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vct vector<ll>
#define pr pair<ll,ll>
#define vpt vector<pr>
ll n,m;
ll mod=1LL*1000000007;
void deb(string s, ll vl){
  cout<<s<<" : "<<vl<<"\n";
}
void prv(vct v){
  for(ll i=0;i<v.size();i++)cout<<v[i]<<" ";
  cout<<"\n";
}

ll dp[1000001][2][2];

ll sol(ll rm, ll in0, ll in9){
  if((rm==0) && (in0>0) && (in9>0))return 1;
  if((rm==0) && ((in0==0) || (in9==0)))return 0;
  if(dp[rm][in0][in9]!=-1)return dp[rm][in0][in9];
  ll ans=0;
  for(ll i=0;i<=9;i++){
    if(i==0){
      ans=(ans+sol(rm-1,in0||1,in9))%mod;
    }
    else if(i==9){
      ans=(ans+sol(rm-1,in0,in9||1))%mod;
    }
    else 
      ans=(ans+sol(rm-1,in0,in9))%mod;
  }
  dp[rm][in0][in9] = (ans%mod);
  return dp[rm][in0][in9];

}

void solve(){
  cin>>n;
  for(ll i=0;i<=n;i++){
    for(ll j=0;j<2;j++){
      for(ll k=0;k<2;k++){
        dp[i][j][k]=-1;
      }
    }
  }
  cout<<sol(n,0,0)<<"\n";
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll t;
  t=1;
  // cin>>t;
  while(t--){
    solve();
  }
}

Measured memory_bytes: 97296
#include<iostream>
int n,a,x,y;
main(){
  std::cin>>n;
  for(int i=0;i<n;++i){
    std::cin>>a;
    if(a%4==0)x++;
    else if(a%2==0)y++;
  }
  std::cout<<(x+y/2+1>n/2?"Yes\n":"No\n");
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		char c=s.charAt(0);
		int sum=0;
		for(int i=0;i<s.length();i++){
			if(c!=s.charAt(i)){
				sum++;
				c=s.charAt(i);
			}
		}
		System.out.print(sum);
	}
}


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

int main() {
  int n;
  cin >> n;
  ll s_min = 2e9, s_max = -2e9, d_min = 2e9, d_max = -2e9;
  while (n--) {
    ll x, y;
    cin >> x >> y;
    s_min = min(s_min, x + y);
    s_max = max(s_max, x + y);
    d_min = min(d_min, x - y);
    d_max = max(d_max, x - y);
  }
  cout << max(s_max - s_min, d_max - d_min) << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;


int main() {
	int N, K;
	cin >> N >> K;
	if (K == 1)
		cout << 0;
	else
		cout << N - K;
}




Measured memory_bytes: 256
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
M = lines[0][1]

entree = []  #rooms which enters room i
sortie = []  #rooms one can enter from room i
for i in 1..N do
  entree[i-1] = []
  sortie[i-1] = []
end

for i in 1..M do
  from = lines[i][0]
  to = lines[i][1]
  entree[to-1].push(from)
  sortie[from-1].push(to)
end

num_entree = []
num_sortie = []
for i in 1..N do
  num_entree[i-1] = entree[i-1].length.to_f
  num_sortie[i-1] = sortie[i-1].length.to_f
end

exp_remain = []  #how many rooms on average to room N
for i in 1..N do  #initialization
  exp_remain[i-1] = 0.0
end
for i in 1..N do
  if i == 1 then
    exp_remain[-i] = 0.0
  else
    sortie[-i].each do |j|
      exp_remain[-i] += exp_remain[j-1] / num_sortie[-i]
    end
    exp_remain[-i] += 1
  end
end
  
prob_entree = []  #probality to enter the room
for i in 1..N do  #initialization
  prob_entree[i-1] = 0.0
end
for i in 1..N do
  if i == 1 then
    prob_entree[i-1] = 1.0
  else
    entree[i-1].each do |j|
      prob_entree[i-1] += prob_entree[j-1] / num_sortie[j-1]
    end
  end
end
  
exp_reduction = [] #expected reduction of rooms by blocking the room
max_exp_reduction = 0.0
blocked_path = -1
for k in 1..M do
  i = lines[k][0]  #room where the path begins (from)
  j = lines[k][1]  #room where the path ends (to)
  if sortie[i-1].length == 1 then
    exp_reduction[k-1] = -1.0  #can't block this!
  else
    temp = 1 / (num_sortie[i-1] - 1)
    after_exp_remain = (1 + temp) * exp_remain[i-1] - temp * (exp_remain[j-1] + 1)
    exp_reduction[k-1] = prob_entree[i-1] * (exp_remain[i-1] - after_exp_remain)
  end
  if exp_reduction[k-1] > max_exp_reduction then
    max_exp_reduction = exp_reduction[k-1]
  end
end
  
print exp_remain[0] - max_exp_reduction

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


ll mod = 1e9+7;

ll gcd(ll a,ll b){
	if(b==0)return a;return gcd(b,a%b);
}
ll expo(ll base,ll pow){
    ll ans = 1;
    while(pow!=0){
        if(pow&1==1){ans = ans*base;}
        base *= base;pow/=2;}return ans;
}
ll inv(ll x){return expo(x,mod-2);}

ll dist[210][210];


int main(){
    //freopen("ip.txt", "rt", stdin);
    //freopen("op.txt", "wt", stdout);
    int n, m, r;
    cin >> n >> m >> r;
    vector <int> R(r);
    for(int i = 0; i < r; i++) cin >> R[i];
    sort(R.begin(), R.end());
    //vector <map <int, int> > vec(n+1);
    for(int i = 0; i <= 200; i++){
        for(int j = 0; j <= 200; j++) dist[i][j] = 1e9;
    }
    for(int i = 0; i < m; i++){
        int u, v, w;
        cin >> u >> v >> w;
        dist[u][v] = w;
        dist[v][u] = w;
    }
    for(int k = 1; k <= n; k++){
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            dist[i][j] = min( dist[i][j], dist[i][k] + dist[k][j] );
        }
    }
   }

    ll ans = INT_MAX;
    ll ans1 = 0;
    for(int i = 1; i < r; i++){
        ans1 += dist[R[i]][R[i-1]];
    }
    ans = min(ans1, ans);
    while(next_permutation(R.begin(), R.end())){
          ll ans1 = 0;
           for(int i = 1; i < r; i++){
           ans1 += dist[R[i]][R[i-1]];
           }
           ans = min(ans1, ans);
    }
    cout << ans;
}


Measured memory_bytes: 512