akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 21:04:27 2019

@author: kato yugo
"""

k,x = map(int,input().split())

a = k-1

b = x-a
c = x+a

for i in range(b,c+1):
    if (-100000 <= i <= 1000000):
        print(i, end="")
        print(" ", end="")
  

Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys
INF = float("inf")


def argmin(a):
    m, n = 1 << 31, -1
    for i, v in enumerate(a):
        if m > v:
            m, n = v, i
    return m, n


def ternary_search(f, x0, x3):
    """
    3分探索を行う。下に凸な関数fの、区間[x0, x3]内にある極値を探し、(x, f(x))を返す。
    なければ、区間の端点が返る。
    fは整数引数、x0,x3も整数引数とする。
    """
    if x0 + 2 == x3:
        xs = [x0, x0+1, x0+2]
        v, i = argmin(list(map(f, xs)))
        return xs[i], v

    x1 = (2*x0+x3)//3
    x2 = (x0+2*x3)//3

    if f(x1) >= f(x2):
        return ternary_search(f, x1, x3)
    else:
        return ternary_search(f, x0, x2)


def solve(H: int, W: int):
    if H % 3 == 0 or W % 3 == 0:
        print(0)
        return

    cand = INF
    y = 1

    def g(x, y):
        return max(x*y, W*(H-y), y*(W-x))-min(x*y, W*(H-y), y*(W-x))

    def h(x, y):
        return max(x*y, x*(H-y), H*(W-x))-min(x*y, x*(H-y), H*(W-x))

    if H == W == 2:
        print(1)
        return
    else:
        cand = min(cand, min(H, W))

    y0, y3 = 1, H-1
    x = W//2
    while y0 + 2 < y3:
        y1 = (2*y0+y3)//3
        y2 = (y0+2*y3)//3
        S1 = g(x, y1)
        S2 = g(x, y2)
        if S1 >= S2:
            y0 = y1
        else:
            y3 = y2
    ys = [y0, y0+1, y0+2]
    for y in ys:
        S = g(x, y)
        cand = min(S, cand)

    x0, x3 = 1, W-1
    y = H//2
    while x0 + 2 < x3:
        x1 = (2*x0+x3)//3
        x2 = (x0+2*x3)//3
        S1 = h(x1, y)
        S2 = h(x2, y)
        if S1 >= S2:
            x0 = x1
        else:
            x3 = x2
    xs = [x0, x0+1, x0+2]
    for x in xs:
        S = h(x, y)
        cand = min(S, cand)
    print(cand)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    solve(H, W)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3192
import Data.List
  ( nub )

main :: IO ()
main = do
  s <- getLine
  putStrLn $ if noDuplicate s 
               then "yes"
               else "no"

noDuplicate
  :: String -> Bool
noDuplicate ss
  = let n = length . nub $ ss 
        m = length ss
    in n==m

Measured memory_bytes: 380
# include <iostream>
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

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

const int N = 1e5 + 100;

int n, m;
long long a[N], sm;
pair < long long, long long > pr[N];

int main()
{
	cin >> n >> m;
	
	for ( int i = 1; i <= n; i ++ )
		cin >> a[i];
	
	for ( int i = 1; i <= m; i ++ )
		cin >> pr[i].second >> pr[i].first;
	
	
	sort( a + 1, a + n + 1 );
	sort( pr + 1, pr + m + 1 );
	reverse( pr + 1, pr + m + 1 );
	
	int id = 1;
	for ( int i = 1; i <= m; i ++ ){
		int c = pr[i].first;
		int r = min(id + pr[i].second - 1, n* 1ll);
		while( id <= r ){
			if( a[id] <= c ){
				a[id] = c;
				id++;
			}
			else{
				r++;
				r = min( r, n );
				id ++;
			}
		}
	}
	for ( int i = 1; i <= n; i ++ ){
		sm += a[i];
	}
	cout << sm;
	
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

// 分数を小数に変換する関数
double Fraction(Int numerator, Int denominator) {
    return (double)((double)(numerator) / (double)(denominator));
}

int main(void) {
    Int n, k;
    cin >> n >> k;
    Int timesMax = ceil(log2(k));
    Int array[timesMax + 1];
    for (Int i = 0; i <= timesMax; ++i) {
        array[i] = 0;
    }
    for (Int i = 1; i <= n; ++i) {
        Int tempK = 0;
        Int tempI = i;
        while (1) {
            if (tempI >= k) {
                array[tempK]++;
                //cout << i << " " << tempK << endl;
                break;
            } else {
                tempI *= 2;
                tempK++;
            }
        }
    }
    Int sum = 0;
    for (Int i = 0; i <= timesMax; ++i) {
        // cout << i << " " << array[i] << endl;
        array[i] *= pow(2, timesMax - i);
        sum += array[i];
    }
    cout << fixed << setprecision(10) << Fraction(sum, n * pow(2, timesMax)) << endl;
    return 0;
}


Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int main() {
    ll n;
    cin >> n;
    ll a[n], b[n + 1];
    rep(i, n) cin >> a[i];
    b[0] = a[0];
    rep(i, n - 1) b[i + 1] = a[i + 1] + b[i], b[i + 1] %= mod7;
    ll ans = 0;
    rep(i, n)
        ans += (b[n - 1] - b[i] + mod7) % mod7 * a[i] % mod7, ans %= mod7;
    cout << ans << endl;
}

Measured memory_bytes: 6764
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60
const mod int = 1e9 + 7

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()

	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = float64(ri())
	}

	if len(a) == 1 {
		fmt.Println(a[0])
		return
	}

	x := 1.0
	for _, v := range a {
		x *= v
	}

	y := 0.0
	for _, v := range a {
		y += x / v
	}

	// fmt.Println(x, y)

	ans := x / y
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

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

  vector <ll> a(N);
  ll sum = 0;

  REP(i,N)
  {
    cin >> a[i];
    sum += a[i];
  }

  if(sum % 10 != 0)
  {
    cout << sum << endl;
    return 0;
  }

  sort(a.begin(),a.end());

  REP(i,N)
  {
    if( (sum - a[i]) % 10 != 0)
    {
      sum -= a[i];
      break;
    }
  }

  if(sum % 10 != 0)
  {
    cout << sum << endl;
  }
  else
  {
    cout << 0 << endl;
  }
  
  return 0;

}

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

namespace AtCoderPractice
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] line;
            line = Console.ReadLine().Split(' ');
            int n = int.Parse(line[0]);
            line = Console.ReadLine().Split(' ');
            List<string> _h = new List<string>(line);
            List<int> h = _h.Select(elem => int.Parse(elem)).ToList();


            h.Reverse();
            int x = h[0];

            bool result = true;

            for (int i = 0; i < h.Count; i++)
            {
                int a = h[i];

                if (x >= a)
                {
                    // 単調非増加になっている -> OK
                    x = a;
                }
                else
                {
                    // 要素を-1して再度いけるかチェック
                    if (x >= a - 1)
                    {
                        // OK
                        x = a - 1;
                        //Console.WriteLine("-1したらOK {0}->{1}", a, a - 1);
                    }
                    else
                    {
                        // -1してもダメ
                        result = false;
                        break;
                    }
                }
                //Console.WriteLine("[{0}]; x={1}", i, x);

            }


            Console.WriteLine(result ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 30684
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

int main(void)
{
    string s;
    cin >> s;
    string ans = "";
    string koho = "-+";
    rep(i, 0, 1 << 3)
    {
        int tmp = s[0] - '0';
        ans = s[0];
        rep(j, 0, 3)
        {
            if (i >> j & 1)
                tmp += s[j + 1] - '0';
            else
                tmp -= s[j + 1] - '0';
            ans = ans + koho[(int)(i / pow(2, j)) % 2] + s[j + 1];
        }
        if (tmp == 7)
            break;
        ans = "";
    }
    ans += "=7";
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		int min = Integer.MAX_VALUE;
		int sum = 0;
		for (int i = 0; i < n; i++) {
			int aji = i + l;
			if (Math.abs(aji) < Math.abs(min)) {
				min = aji;
			}
			sum += aji;
		}
		System.out.println(sum - min);
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long i64;
typedef pair<i64, i64> P;


int n, t, a[3030], b[3030];
int dp[3030][3030];
P p[3030];

i64 dfs(int now, int m){
	if(now <= 0 || m == n) return 0;
	if(dp[m][now]) return dp[m][now];
	
	return dp[m][now] = max(dfs(now, m+1), dfs(now-p[m].first, m+1)+p[m].second);
}

int main(){
	cin >> n >> t;
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
		p[i] = P(a[i], b[i]);
	}
	sort(p, p+n);
	
	cout << dfs(t,0) << endl;
	
	return 0;
}

Measured memory_bytes: 35200
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

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; }

//const int dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);

vector<ll> a, b;

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

	if (n % 2 == 0) {
		cout << n / 2 << endl;
	}
	else {
		cout << n / 2 + 1 << endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int N = 100005;
int arr[105];
int n, k;
bool dp[N][2];
bool call(int k, int flag) {
	if(dp[k][flag]) return dp[k][flag];
	bool ans = false;
	for (int i = 0; i < n; i++) {
		if (arr[i] <= k) {
			ans |= !call(k - arr[i], !flag);
		}
	}
	return dp[k][flag] = ans;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> arr[i];
	bool win = call(k, 0);
	if (win) cout << "First" << "\n";
	else cout << "Second" << "\n";
	return 0;

}


Measured memory_bytes: 5120
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

int main(){
	ll a,b,c,ans=INF;
	cin>>a>>b>>c;
	if(a!=1){
		if(a%2)ans=min(ans,b*c);
		else ans=0;
	}
	if(b!=1){
		if(b%2)ans=min(ans,a*c);
		else ans=0;
	}
	if(c!=1){
		if(c%2)ans=min(ans,a*b);
		else ans=0;
	}
	print(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  vector<int> A = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K; cin >> K;
  cout << A[K-1] << endl;

  return 0;
}


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

using namespace std;

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

#define NVALUE 3

int main()
{
    int N, M;
    cin >> N >> M;
    vector<ll> x(N), y(N), z(N);
    for (int i = 0; i < N; i++)
    {
        cin >> x[i] >> y[i] >> z[i];
    }

    array<ll, 1 << NVALUE> sum_total;
    for (int s = 0; s < 1 << NVALUE; s++)
    {
        // calculate total
        vector<ll> total(N, 0);
        for (int i = 0; i < N; i++)
        {
            total[i] += x[i] * ((s >> 0 & 1) ? -1 : 1);
            total[i] += y[i] * ((s >> 1 & 1) ? -1 : 1);
            total[i] += z[i] * ((s >> 2 & 1) ? -1 : 1);
        }

        // sort and sum
        sort(total.rbegin(), total.rend());
        sum_total[s] = accumulate(total.begin(), total.begin() + M, 0LL);
    }

    // get max
    ll max_sum_total = *max_element(sum_total.begin(), sum_total.end());

    cout << max_sum_total << endl;

    return 0;
}

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

namespace Competitive
{
    internal class Solution
    {
        public int N, M;
        public int[] P, Y;
        public long MOD = 1000000007;
        public int[] used;
        public long[,] DP;

        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                N = line[0];
                M = line[1];
            }
            P = new int[M];
            Y = new int[M];
            for (int m = 0; m < M; m++)
            {
                var line = Input.ReadIntArray();
                P[m] = line[0];
                Y[m] = line[1];
            }

            var lst = new List<int>[N+1];
            for (int i = 0; i <= N; i++)
            {
                lst[i] = new List<int>();
            }

            for (int m = 0; m < M; m++)
            {
                lst[P[m]].Add(Y[m]);
            }

            for (int i = 0; i <= N; i++)
            {
                lst[i].Sort();
            }

            Dictionary<Tuple<int, int>, string> dic = new Dictionary<Tuple<int, int>, string>();
            for (int i = 0; i <= N; i++)
            {
                for (int j = 0; j < lst[i].Count; j++)
                {
                    dic.Add(Tuple.Create(i, lst[i][j]), String.Format("{0:000000}{1:000000}", i, j + 1));
                }
            }

            for (int m = 0; m < M; m++)
            {
                var v = dic[Tuple.Create(P[m], Y[m])];
                Console.WriteLine(v);
            }
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 43220
/***********************
*  Author: xuziyuan    * 
***********************/
 
#include <bits/stdc++.h>
 
#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))
 
using namespace std;
 
const LL MOD=1e9+7;
 
LL n,m,a[1010][3],dp[1010][1010][2][2][2],to[2],ans=0;
 
int main()
{
	to[0]=1;
	to[1]=-1;
	memset(dp,-1,sizeof(dp));
	rep(i,1005) rep(j,1005) rep(k,2) rep(p,2) rep(r,2) dp[i][j][k][p][r]=-1e16;
	rep(i,2) rep(j,2) rep(k,2) dp[0][0][i][j][k]=0;
	cin>>n>>m;
	rep(i,n) rep(j,3) scanf("%lld",&a[i][j]);
	rep(i,n)
	{
		rep(j,m+1)
		{
			if(j>i) break;
			rep(k,2) rep(p,2) rep(r,2)
			{
				if(dp[i][j][k][p][r]==-1) continue;
				dp[i+1][j][k][p][r]=max(dp[i+1][j][k][p][r],dp[i][j][k][p][r]);
				dp[i+1][j+1][k][p][r]=max(dp[i+1][j+1][k][p][r],
				dp[i][j][k][p][r]+to[k]*a[i][0]+to[p]*a[i][1]+to[r]*a[i][2]);
			}
		}
	}
	rep(i,2) rep(j,2) rep(k,2) ans=max(ans,dp[n][m][i][j][k]);
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 64128
#include <stdio.h>
#include <stdlib.h>
#define ll long long

typedef struct{
  ll A;
  int B;
}energy;
int cmp(const void *p,const void *q){
  return ((energy*)p)->A-((energy*)q)->A;
}
void init(energy *t,int N);

int main(){
  int N,M;
  energy *E;
  ll ans=0;
  int i;

  scanf("%d%d",&N,&M);
  E=(energy*)malloc(sizeof(energy)*N);

  init(E,N);
  qsort(E,N,sizeof(energy),cmp);

  for(i=0;i<N;i++){
      if(E[i].B<=M){
        ans+=E[i].A*E[i].B;
        M-=E[i].B;
      }else{
        ans+=M*E[i].A;
        break;
      }
  }
  printf("%lld\n",ans);

  free(E);
  return 0;
}

void init(energy *t,int N){
  for(int i=0;i<N;i++)scanf("%lld%lld",&t[i].A,&t[i].B);
}

Measured memory_bytes: 3324
(ns atcoder.agc001-a
  (:require [clojure.string :as str]))

(defn int-line []
  (map #(Integer/parseInt %) (str/split (read-line) #" ")))

(let [[n] (int-line)
      skewers (int-line)]
  (let [combi (partition 2 (sort skewers))]
    (print (reduce + (map first combi)))))


Measured memory_bytes: 66852
'''
????????£????????????????????????

'''

import queue
v,e,s=map(int,input().split())
edge=[]
inf =1000000100
for i in range(v):
    edge.append([])

for i in range(e):
    vs,vt,d=map(int,input().split())
    edge[vs].append((vt,d))
    
dis=[]
for i in range(v):
    dis.append(inf)

dis[s]=0

q = queue.PriorityQueue()
q.put((0,s))

while(not q.empty()):
    now=q.get()
#    print("get",now)
    nowv=now[1]
    for (vt,d) in edge[nowv]:
        if dis[vt]>dis[nowv]+d:
            dis[vt]=dis[nowv]+d
            q.put((dis[vt],vt))
#            print("put",(dis[vt],vt))

    
for i in range(v):
    if dis[i]>=inf:
        print("INF")
    else:
        print(dis[i])

Measured memory_bytes: 90448
N = gets.to_i
V = gets.split(' ').map(&:to_i)
C = gets.split(' ').map(&:to_i)

val = (0..N-1).collect{|i| V[i] - C[i]}.sort.reverse
maxval = 0
cnt = 0
while cnt < N and val[cnt] > 0 
	maxval += val[cnt]
	cnt += 1
end

puts maxval

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int MAX = 1e6+5;

int main(){
    int n;
    cin >> n;
    VI a(n);
    rep(i,n) cin >> a[i];
    VI d(MAX);
    rep(i,n){
        if (d[a[i]] > 2) continue;
        for(int j = a[i]; j <= MAX; j += a[i]){
            d[j]++;
        }
    }
    int ans = 0;
    rep(i,n){
        if (d[a[i]] < 2) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7920
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)


def solve(n, a, b):
    if abs(a-b) % 2 == 0:
        return abs(a-b) // 2

    down_ops = min(a, b)
    up_ops = n - max(a, b) + 1

    if down_ops < up_ops:
        return solve(n, 1, max(a, b) - down_ops) + down_ops

    return solve(n, min(a, b) + up_ops, n) + up_ops


if __name__ == "__main__":
    n, a, b = arr_in()
    out(solve(n, a, b))

Measured memory_bytes: 38384
A, B, C, X = [int(input()) for i in range(4)]

ans = 0
for i in range(0, A+1):
    for j in range(0, B+1):
        for k in range(0, C+1):
            if (i*500 + j*100 + k*50)==X:
                ans+=1

print(ans)

Measured memory_bytes: 3060
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#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 <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

template<class Iter>
bool next_partial_permutation(Iter first, Iter middle, Iter last) {
    reverse(middle, last);
    return next_permutation(first, last);
}

//combination nCr 組み合わせ
//first1・・最初の数
//last1==first2・・r(取り出す数)
//last2・・n(全体数)
template<class Iter>
bool next_combination(Iter first1, Iter last1, Iter first2,
                      Iter last2) {
    if ((first1 == last1) || (first2 == last2)) {
        return false;
    }
    Iter m1 = last1;
    Iter m2 = last2;
    --m2;
    while (--m1 != first1 && !(*m1 < *m2)) {
    }
    bool result = (m1 == first1) && !(*first1 < *m2);
    if (!result) {
        while (first2 != m2 && !(*m1 < *first2)) {
            ++first2;
        }
        first1 = m1;
        std::iter_swap(first1, first2);
        ++first1;
        ++first2;
    }
    if ((first1 != last1) && (first2 != last2)) {
        m1 = last1;
        m2 = first2;
        while ((m1 != first1) && (m2 != last2)) {
            std::iter_swap(--m1, m2);
            ++m2;
        }
        std::reverse(first1, m1);
        std::reverse(first1, last1);
        std::reverse(m2, last2);
        std::reverse(first2, last2);
    }
    return !result;
}

int main() {

    long long N, K;
    cin >> N >> K;

    vector<pair<long long, long long>> points(N);
    for (int i = 0; i < N; i++) {
        long long x, y;
        cin >> x >> y;
        points[i] = make_pair(x, y);
    }

    vector<long long> a(N);
    for (int i = 0; i < N; i++) a[i] = i;

    long long ans = LONG_LONG_MAX;

    do {

        long long minY = min(points[a[0]].second, points[a[1]].second);
        long long maxY = max(points[a[0]].second, points[a[1]].second);

        vector<long long> x;
        for (int i = 0; i < N; i++)
            if (minY <= points[i].second && points[i].second <= maxY)
                x.push_back(points[i].first);

        sort(x.begin(), x.end());

        if (x.size() >= K) {
            for (int i = 0; i < x.size() - K + 1; i++) {
                long long area = (x[i + K - 1] - x[i]) * (maxY - minY);
                ans = min(area, ans);
            }
        }

    } while (next_combination(a.begin(), a.begin() + 2, a.begin() + 2, a.end()));

    cout << ans << endl;

    return 0;
}
































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

int main(){

int i,m,n,p,x,time=0;
int t[100];

cin >> n;

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

cin >> m;

for(i = 0; i < m; i++){
cin >> p >> x;
cout << time - t[p-1] + x << endl;
}

return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <ios>     // std::left, std::right
#include <iomanip> 
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
#define MOD 1'000'000'007

int main(){
    ll N;cin>>N;
    vector<vector<vector<vector<int>>>> dp(N+1,vector<vector<vector<int>>>(4,vector<vector<int>>(4,vector<int>(4,0))));
    //A = 0 C = 1 G = 2 T = 3
    //012を含まない(swapして)
    //長さ0の文字列は1であるとする
    //Sは333Sと考えても問題がない(012に関する制約しかないので)
    dp[0][3][3][3] = 1;
    //文字数
    REP(len,N){
        //最後から1文字目の文字
        REP(c1,4){
            //最後から2文字目の文字
            REP(c2,4){
                //最後から３文字目の文字
                REP(c3,4){
                    //条件にあてはまるものがない場合はcontinue
                    if(dp[len][c1][c2][c3] == 0) continue;
                    //新しく追加する文字
                    REP(a,4){
                        //だめな５つの条件をカットする
                        if(a==2 and c1==1 and c2==0) continue;
                        if(a==2 and c1==0 and c2==1) continue;
                        if(a==1 and c1==2 and c2==0) continue;
                        if(a==2 and c1==1 and c3==0) continue;
                        if(a==2 and c2==1 and c3==0) continue;
                        //だめな条件を抜けたら,aを足した文字列が作れる
                        dp[len+1][a][c1][c2] += dp[len][c1][c2][c3];
                        dp[len+1][a][c1][c2] %= MOD;
                    }
                }
            }
        }
    }
    int ans = 0;
    REP(c1,4){
        //最後から2文字目の文字
        REP(c2,4){
            //最後から３文字目の文字
            REP(c3,4){
                ans += dp[N][c1][c2][c3];
                ans %= MOD;
            }
        }
    }
        
     cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();



int main(){

  int n; cin>>n;
  int d[n];

  REP(i,n){
    cin >> d[i];
  }

  sort(d, d + n, greater<int>());

  int count = 1;
  FOR(i, 1, n)
  {
    if(d[i]!=d[i-1])
      count++;
  }

  cout << count << endl;
}



Measured memory_bytes: 256
H, W = map(int, input().split())
a = [list(input()) for i in range(H)]
A = [[0]*W for i in range(H)]
B = []
for i in range(H):
    for j in range(W):
        if a[i][j] == '#':
            A[i][j] += 1
    if sum(A[i]) > 0:
        B.append(A[i])

ans = [[] for i in range(len(B))]
for y in zip(*B):
    if sum(y) > 0:
        for i, x in enumerate(y):
            if x:
                ans[i].append('#')
            else:
                ans[i].append('.')
for x in ans:
    print(''.join(x))


Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
signed main() {
	int x; cin >> x;
	int ans = x / 500 * 1000;
	x %= 500;
	cout << ans + x - x % 5 << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int n;
int f[110][5][2];
int p[110][10];

int func(bitset<10> bs) {
    int obj = 0;
    imfor(i, n) {
        int cnt = 0;
        imfor(ii, 10) {
            int j = ii / 2;
            int k = ii % 2;
            if (bs[ii] == 1 && f[i][j][k] == 1) {
                cnt++;
            }
        }
        obj += p[i][cnt];
    }
    return obj;
}

int main() {
    cin >> n;
    imfor(i, n) {
        imfor(j, 5) {
            imfor(k, 2) {
                cin >> f[i][j][k];
            }
        }
    }
    imfor(i, n) {
        imfor(j, 11) {
            cin >> p[i][j];
        }
    }
    int opt;
    imfor(i, 1<<10) {
        if (i == 0) {
            continue;
        }
        bitset<10> bs(i);
        int obj = func(bs);
        if (i == 1) {
            opt = obj;
        }
        else if (obj > opt) {
            opt = obj;
        }
    }
    cout << opt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n;
    ll s[112345];
    cin >> n;
    REP(i, n)
    cin >> s[i];

    ll res = 0;

    for (int i = 1; i <= n; i++)
    {
        bool used[112345];
        memset(used, 0, sizeof(used));

        ll sum = 0;
        for (int j = 0; j < n; j += i)
        {
            if (used[j] || used[n - 1 - j] || j == n - 1 - j || n - 1 - j < i)
                break;

            used[j] = true;
            used[n - 1 - j] = true;

            sum += s[j] + s[n - 1 - j];
            res = max(res, sum);
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <boost/format.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>

#ifdef DEBUG
#include "libs/debug.cpp"
#define DEBUG 1
#else
#define DEBUG 0
#endif

#define rep(i, n) repr((i), 0, (n))
#define repr(i, a, t) reps((i), (a), (t), 1)
#define reps(i, a, t, s) for (long long (i) = (a); (i) < (long long)(t); (i) += (s))
#define rrep(i, n) rrepr((i), (n) - 1, 0)
#define rrepr(i, a, t) rreps((i), (a), (t), 1)
#define rreps(i, a, t, s) for (long long (i) = (a); (i) >= (long long)(t); (i) -= (s))
#define each(v, c) for (auto &&(v) : (c))
#define all(c) (c).begin(), (c).end()

using namespace std;
namespace mp = boost::multiprecision;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ml = mp::cpp_int;
template<typename T>
using optional = boost::optional<T>;
const auto none = boost::none;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

int main() {
  cout << fixed << setprecision(10);
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ifstream ifs;
  if (DEBUG) {
    ifs.open("src/_in.txt");
    cin.rdbuf(ifs.rdbuf());
  }

  ll N;
  cin >> N;
  vector<ll> A;
  rep (i, pow(2, N)) {
    ll v0;
    cin >> v0;
    A.push_back(v0);
  }

  // dp[k]: i | j | k == k となる i, j のうち A[i] + A[j] が最大となる i, j
  vector<set<tuple<ll, ll>>> dp(pow(2, N));
  repr (k, 1, pow(2, N)) {
    dp[k] = set<tuple<ll, ll>>{make_tuple(A[0], 0), make_tuple(A[k], k)};
  }

  vector<ll> digits;
  ll n = 1;
  while (n < pow(2, N)) {
    digits.push_back(n);
    n <<= 1;
  }

  repr (k, 1, pow(2, N)) {
    dp[k] = set<tuple<ll, ll>>{*prev(dp[k].end()), *prev(dp[k].end(), 2)};
    each (d, digits) {
      if ((k | d) > k) {
        dp[k | d].insert(all(dp[k]));
      }
    }
  }

  vector<ll> ans(pow(2, N), 0);
  ll m = 0;
  repr (k, 1, pow(2, N)) {
    ll a1, a2, _;
    tie(a1, _) = *prev(dp[k].end());
    tie(a2, _) = *prev(dp[k].end(), 2);
    ans[k] = m = max(m, a1 + a2);
  }

  repr (k, 1, pow(2, N)) {
    cout << ans[k] << "\n";
  }
}

Measured memory_bytes: 74096
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int i,n,x,y,ans,k,a[500010];
int main(){
	scanf("%d%d",&k,&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=1;i<n;i++)ans=max(ans,a[i+1]-a[i]);
	ans=max(ans,k-a[n]+a[1]);
	printf("%d",k-ans);
}

Measured memory_bytes: 1024
X = int(input())
if X <= 2:
    print(2)
    exit()
S = [2]
for i in range(3, 10**6, 2):
    f = True
    for s in S:
        if s > i**(0.5): break
        if i % s == 0:
            f = False
            break
    if f:
        S.append(i)
        if i >= X:
            print(i)
            break


Measured memory_bytes: 9848
X = int(input())

def isprime(x):
  if x == 2:
    return True
  for i in range(2, x//2+1):
    if x % i == 0:
      return False
  return True

def minprime(x):
  while True:
    if isprime(x):
      return x
    x += 1

print(minprime(X))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int W,H;cin>>W>>H;
    vector<vector<int>>V(H+2,vector<int>(W+2));
    for(int i=0;i<W+2;i++)V[0][i]=0;
    for(int i=1;i<H+1;i++){
        V[i][0]=0;V[i][W+1]=0;
        for(int j=1;j<W+1;j++)cin>>V[i][j];
    }
    for(int i=0;i<W+2;i++)V[H+1][i]=0;//縦H+2横W+2の表
    
    vector<vector<int>> Be(H+2,vector<int>(W+2,1));
    pair<int,int>p=make_pair(0,0);
    queue <pair<int,int>> q;
    q.push(p);
    while(q.empty()==false){
        int y=q.front().first;
        int x=q.front().second;
        q.pop();
        if(y%2==0){
            if(y>0 && x>0 && Be[y-1][x-1]==1 && V[y-1][x-1]==0){q.push(make_pair(y-1,x-1));Be[y-1][x-1]=0;}
            if(y>0 && Be[y-1][x]==1 && V[y-1][x]==0){q.push(make_pair(y-1,x));Be[y-1][x]=0;}
            if(x>0 && Be[y][x-1]==1 && V[y][x-1]==0){q.push(make_pair(y,x-1));Be[y][x-1]=0;}
            if(x<W+1 && Be[y][x+1]==1 && V[y][x+1]==0){q.push(make_pair(y,x+1));Be[y][x+1]=0;}
            if(x>0 && y<H+1 && Be[y+1][x-1]==1 && V[y+1][x-1]==0){q.push(make_pair(y+1,x-1));Be[y+1][x-1]=0;}
            if(y<H+1 && Be[y+1][x]==1 && V[y+1][x]==0){q.push(make_pair(y+1,x));Be[y+1][x]=0;}
        }
        if(y%2==1){
            if(y>0 && Be[y-1][x]==1 && V[y-1][x]==0){q.push(make_pair(y-1,x));Be[y-1][x]=0;}
            if(y>0 && x<W+1 && Be[y-1][x+1]==1 && V[y-1][x+1]==0){q.push(make_pair(y-1,x+1));Be[y-1][x+1]=0;}
            if(x>0 && Be[y][x-1]==1 && V[y][x-1]==0){q.push(make_pair(y,x-1));Be[y][x-1]=0;}
            if(x<W+1 && Be[y][x+1]==1 && V[y][x+1]==0){q.push(make_pair(y,x+1));Be[y][x+1]=0;}
            if(y<H+1 && Be[y+1][x]==1 && V[y+1][x]==0){q.push(make_pair(y+1,x));Be[y+1][x]=0;}
            if(y<H+1 && x<W+1 && Be[y+1][x+1]==1 && V[y+1][x+1]==0){q.push(make_pair(y+1,x+1));Be[y+1][x+1]=0;}
        }
    }
    
    int count=0;
    for(int i=1;i<H+1;i++){
        for(int j=1;j<W+1;j++){
            if(Be[i][j]==1){
                if(i%2==0){
                    if(Be[i-1][j-1]==0)count++;
                    if(Be[i-1][j]==0)count++;
                    if(Be[i][j-1]==0)count++;
                    if(Be[i][j+1]==0)count++;
                    if(Be[i+1][j-1]==0)count++;
                    if(Be[i+1][j]==0)count++;
                }
                if(i%2==1){
                    if(Be[i-1][j]==0)count++;
                    if(Be[i-1][j+1]==0)count++;
                    if(Be[i][j-1]==0)count++;
                    if(Be[i][j+1]==0)count++;
                    if(Be[i+1][j]==0)count++;
                    if(Be[i+1][j+1]==0)count++;
                }
            }
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3208
#include<stdio.h>
#include<stdlib.h>

int main(){
  int *data, num, flag=1, cnt=0, i;

  //input data
  scanf("%d",&num);
  data=(int *)malloc(num*sizeof(int));
  for(i=0;i<num;i++) scanf("%d",&data[i]);

  
  //bubble sort
  while(flag==1){//flag==1 sort is not finish
    flag=0;

    for(i=num-1;i>0;i--){
      if(data[i]<data[i-1]){
	//data[i]<->data[i-1]
	flag=data[i];
	data[i]=data[i-1];
	data[i-1]=flag;

	flag=1;
	cnt++;//data change count 
      }
      
    }
    
  }

  //output result
  for(i=0;i<num-1;i++) printf("%d ",data[i]);
  printf("%d\n%d\n",data[i],cnt);

  free(data);
  return 0;
}



Measured memory_bytes: 2104
fun main(args:Array<String>){
    val c=next()
    println(if("aiueo".contains(c))"vowel" else "consonant")
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)

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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst; Cost cost;
  Edge(int s, int d, Cost c) : src(s), dst(d), cost(c) {}
};
typedef vector<Edge>  Edges;
typedef vector<Edges> Graph;
typedef vector<Cost>  Array;
typedef vector<Array> Matrix;

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

map<char, int> table;

int formula(const string &f, int &pos) {
  if (isdigit(f[pos])) return f[pos++] - '0';
  if (f[pos] == 'P' || f[pos] == 'Q' || f[pos] == 'R') return table[f[pos++]];

  if (f[pos] == '-') {
    int ret = formula(f, ++pos);
    return ret == 0 ? 2 : (ret + 2) % 2;
  }

  if (f[pos] == '(') {
    int lhs = formula(f, ++pos);
    char op = f[pos];
    int rhs = formula(f, ++pos);
    int ret;
    if (op == '+') {
      if (lhs == 2 || rhs == 2) ret = 2;
      else if (lhs == 1 || rhs == 1) ret = 1;
      else ret = 0;
    } else if(op == '*') {
      if (lhs == 0 || rhs == 0) ret = 0;
      else if (lhs == 1 || rhs == 1) ret = 1;
      else ret = 2;
    }
    pos++;
    return ret;
  }
}

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  string f;
  while (cin >> f, f != ".") {
    int ans = 0;
    int pos = 0;
    rep(p, 3) rep(q, 3) rep(r, 3) {
      table['P'] = p;
      table['Q'] = q;
      table['R'] = r;

      pos = 0;
      int ret = formula(f, pos);
      if (ret == 2) ans++;
    }
    cout << ans << endl;
  }
  return 0; 
}

Measured memory_bytes: 3028
from collections import deque
n = int(input())
a = list(map(str, input().split()))
b = deque([])
t = 1
for i in a:
    if t == -1:
        b.appendleft(i)
    else :
        b.append(i)
    t *= -1
if t == -1:
    b.reverse()
print(*b)

Measured memory_bytes: 27748
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright  : @Huki_Hara
# Created    : 2015-03-16

for _ in range(int(input())):
    ans = 0
    out = 0
    hit = 0
    while True:
        w = input()
        if w == "OUT":
            out += 1
            if out == 3:
                break
        elif w == "HIT":
            if hit == 3:
                ans += 1
            else:
                hit += 1
        elif w == "HOMERUN":
            ans += hit + 1
            hit = 0
    print(ans)

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

int h,w,n;
string g[1000];

int bfs(int cheese);

int main(){
  cin >> h >> w >> n;
  for(int i=0;i<h;i++)cin >> g[i];

  int ans = 0;
  for(int i=0;i<n;i++){
    ans += bfs(i);
  }
  cout << ans << endl;
}

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

int bfs(int cheese){
  char start = (cheese==0)?'S':('0'+cheese), goal = '1'+cheese;

  queue<int> qy,qx;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      dis[i][j] = -1;
      if(g[i][j] == start){
	dis[i][j] = 0;
	qy.push(i); qx.push(j);
      }
    }
  }

  int res = 0;
  while(qy.size()){
    int y = qy.front(), x = qx.front();
    qy.pop(); qx.pop();
    if(g[y][x] == goal)return dis[y][x];

    for(int i=0;i<4;i++){
      int ny = y+dy[i], nx = x+dx[i];
      if(ny<0 || nx<0 || ny>=h || nx>=w)continue;
      if(g[ny][nx] == 'X')continue;
      
      if(dis[ny][nx]<0){
	dis[ny][nx] = dis[y][x] + 1;
	qy.push(ny); qx.push(nx);
      }
    }
  }
  return -1;
}

Measured memory_bytes: 6176
#include<cstdio>

int main(){
    char ch;
    int counter[26] = {0};

    while(scanf("%c", &ch) != EOF){
        if('A' <= ch && ch <= 'Z'){
            int num = ch + 32 - 'a';
            counter[num] += 1;
        } else if('a' <= ch && ch <= 'z'){
            int num = ch - 'a';
            counter[num] += 1;
        }
    }   

    for (int i = 0; i < 26; i++){
        printf("%c : %d\n", i + 'a', counter[i]);
    }

    return 0;

}


Measured memory_bytes: 2756
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << "\n"; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "tmp.cpp"

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

  int n, m;
  cin >> n >> m;
  vector<vi> g(n);
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(a);
    g[b].push_back(b);
  }

  REP(i, n) {
    if (g[i].size() % 2 != 0) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


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

int main() {
    char s[4]; for (int i = 0; i < 4; ++i) cin >> s[i];

    map<char, int> mp;
    for (int i = 0; i < 4; ++i) {
        if (mp.count(s[i]) == 0) {
            mp[s[i]] = 1;
        } else {
            mp[s[i]]++;
        }
    }

    string res = "No";
    if (mp.size() == 2) {
        for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
            if (itr->second == 2) res = "Yes"; 
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int t;
	int p=1;
	for(int i=0;i<n;i++){
		cin>>t;
		if(t%2==0&&(t%3!=0&&t%5!=0)) p=0;
	}
	if(p==0) cout<<"DENIED";
	else cout<<"APPROVED";
}

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

int main(){
  
  int q, command, x, p;
  vector<int> A;
  
  cin >> q;
  for(int i = 0;i < q;i++){
    cin >> command;
    
    if(command == 0){
      cin >> x;
      A.push_back(x);
    }else if(command == 1){
      cin >> p;
      cout << A[p] << endl;
    }else if(command == 2){
      A.pop_back();
    }
  }
  
  return 0;
}


Measured memory_bytes: 3888
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

LL f(LL n) {
    return n * (n - 1) / 2;
}

int main() {

    LL N, K;
    cin >> N >> K;

    if (N == 2) {
        if (K == 0) {
            cout << 1 << endl;
            cout << 1 << " " << 2 << endl;
            return 0;
        }else{
            cout << -1 << endl;
            return 0;
        }
    }

    LL all_pairs = f(N - 1);
    if (all_pairs < K) {
        cout << -1 << endl;
        return 0;
    }

    LL del = all_pairs - K;

    vector<pair<int, int>> edges;
    for (int i = 0; i < N - 1; i++) edges.push_back(make_pair(i, N - 1));

    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N - 1; j++) {
            if (del > 0) {
                del--;
                edges.push_back(make_pair(i, j));
            }
        }
    }

    cout << edges.size() << endl;
    for (auto x: edges) {
        cout << x.first + 1 << " " << x.second + 1 << endl;
    }

}

































Measured memory_bytes: 384