akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

void merge(int A[],int n,int left,int mid,int right);
void mergeSort(int A[],int n,int left,int right);

int count=0;
int L[500000],R[500000];

int main(void)
{
  int n,i;
  int *A;

  scanf("%d",&n);

  A=calloc(n,sizeof(int));

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

  mergeSort(A,n,0,n);

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

      if(i!=n-1)
	{
	  putchar(' ');
	}
      
      else
	{
	  putchar('\n');
	}
    }
  
   printf("%d\n",count);

   free(A);
  
  return 0; 
}

void merge(int A[],int n,int left,int mid,int right)
{
  int n1=mid-left;
  int n2=right-mid;
  int i,j,k;
    
  for(i=0;i<n1;i++)
    {
      L[i]=A[left+i];
    }
  
  for(i=0;i<n2;i++)
    {
      R[i]=A[mid+i];
    }
      
  L[n1]=1000000000;
  R[n2]=1000000000;
      
  i = 0;
  j = 0;
      
  for(k=left;k<right;k++)
    {
      count++;
	
      if (L[i]<=R[j])
	{
	  A[k]=L[i];
	  i=i+1;
	}
      
      else
	{
	  A[k]=R[j];
	  j=j+1;
	}
    }
}
  
void mergeSort(int A[],int n,int left,int right)
{
  if (left+1<right)
    {
      int mid=(left+right)/2;
	
      mergeSort(A,n,left,mid);
      mergeSort(A,n,mid,right);
      merge(A,n,left,mid,right);
    }
}



Measured memory_bytes: 5488
#!/usr/bin/env python
# coding: utf-8
import math

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    lp = []
    dist = [[0 for _ in range(n)] for _ in range(n)]
    for i in range(n):
        x, y = rli()
        lp.append([x, y])
    ans = 0
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            dist[i][j] = math.sqrt((lp[i][0]-lp[j][0])**2+(lp[i][1]-lp[j][1])**2)
            ans += dist[i][j]
    ans /= n
    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 105

int diff_row_KI[6] = {-1,-1,0,0,1,1},diff_col_KI[6] = {0,1,-1,1,0,1};
int diff_row_GU[6] = {-1,-1,0,0,1,1},diff_col_GU[6] = {-1,0,-1,1,-1,0};

int H,W;

struct Info{
	Info(){
		row = col = 0;
	}
	Info(int arg_row,int arg_col){
		row = arg_row;
		col = arg_col;
	}
	int row,col;
};

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= NUM-1 && col >= 0 && col <= NUM-1){
		return true;
	}else{
		return false;
	}
}

int main(){

	int table[NUM][NUM];
	bool check[NUM][NUM];

	for(int i = 0; i < NUM; i++){
		for(int k = 0; k < NUM; k++){
			table[i][k] = 0;
			check[i][k] = false;
		}
	}


	scanf("%d %d",&W,&H);

	for(int i = 1; i <= H; i++){
		for(int k = 1; k <= W; k++)scanf("%d",&table[i][k]);
	}

	Info first;
	first.row = 0;
	first.col = 0;
	table[0][0] = 1;
	check[0][0] = true;

	queue<Info> Q;
	Q.push(first);

	int next_row,next_col;

	while(!Q.empty()){

		if(Q.front().row % 2 == 1){

			for(int i = 0; i < 6; i++){
				next_row = Q.front().row + diff_row_KI[i];
				next_col = Q.front().col + diff_col_KI[i];

				if(rangeCheck(next_row,next_col) == true && check[next_row][next_col] == false){
					check[next_row][next_col] = true;
					if(table[next_row][next_col] == 0){
						table[next_row][next_col] = 3;
						Q.push(Info(next_row,next_col));
					}
				}
			}

		}else{
			for(int i = 0; i < 6; i++){
				next_row = Q.front().row + diff_row_GU[i];
				next_col = Q.front().col + diff_col_GU[i];

				if(rangeCheck(next_row,next_col) == true && check[next_row][next_col] == false){
					check[next_row][next_col] = true;
					if(table[next_row][next_col] == 0){
						table[next_row][next_col] = 3;
						Q.push(Info(next_row,next_col));
					}
				}
			}
		}

		Q.pop();
	}

	for(int row = 1; row <= H; row++){
		for(int col = 1; col <= W; col++){
			if(table[row][col] == 0){
				table[row][col] = 2;
			}
		}
	}

	int ans = 0,tmp_row,tmp_col;

	for(int row = 1; row <= H; row++){
		for(int col = 1; col <= W; col++){
			if(table[row][col] == 1){
				for(int a = 0; a < 6; a++){
					if(row%2 == 1){
						tmp_row = row + diff_row_KI[a];
						tmp_col = col + diff_col_KI[a];
					}else{
						tmp_row = row + diff_row_GU[a];
						tmp_col = col + diff_col_GU[a];
					}
					if(table[tmp_row][tmp_col] == 3)ans++;
				}
			}
		}
	}

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 2856
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
using namespace std;

char buf[1001];
map<string, int> cnt;
string mode;
string longest;

int main() {
  while (1) {
    if (scanf("%s", buf) != 1) break;

    string word = buf;
    int n = strlen(buf);
    if (n > longest.size()) longest = buf;
    ++cnt[word];
    if (cnt[word] > cnt[mode]) mode = word;
  }

  printf("%s %s\n", mode.c_str(), longest.c_str());
}

Measured memory_bytes: 2820
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include<bitset>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); ++i)
#define loops(i,f,n) for(int i = (f); i < (n); ++i)
#define INF 999999999
#define llint long long int
#define vec vector<int>
#define vec2 vector<vector<int>>

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<string> s(n);
	loop(i, n)cin >> s[i];
	string ans;
	for (char c = 'a'; c <= 'z'; c++)
	{
		int m = INF;
		loop(i, n)
		{
			int cnt = 0;
			loop(j, s[i].length())
			{
				if (s[i][j] == c)cnt++;
			}
			m = min(m, cnt);
		}
		loop(k, m)ans += c;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,M,ans;
  cin >>N >>M;
  if(2*N>M){
    ans=M/2;
  }
  else{
    ans=N*2+M;
    ans/=4;
  }
  cout <<ans <<endl;
}


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

int main() {
	string s;
	cin >> s;
	int n=s.size();
	if(n==1){
		cout << s << endl;
		return 0;
	}
	long long ans=0;
	for(int bit=0;bit<(1<<n-1);bit++){
		long long t=0;
		t+=s[0]-'0';
		for(int i=0;i<n-1;i++){
			if(bit&(1<<i)){
				ans+=t;
				t=0;
				t+=s[i+1]-'0';
			}
			else{
				t=t*10+s[i+1]-'0';
			}
		}
		ans+=t;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
		Integer[] height = new Integer[] {0,0,0,0,0,0,0,0,0,0};
		
		for(int i=0;i<10;i++) {
			height[i] = sc.nextInt();
		}
	
		Arrays.sort(height, Collections.reverseOrder());
		
		for(int i=0; i<3; i++) {
			System.out.println(height[i]);
		}
		
	}
}


Measured memory_bytes: 26380
package main

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

func main() {
	n, k, q := readInt(), readInt(), readInt()
	m := make(map[int]int, n)
	for i := 0; i < q; i++ {
		a := readInt()
		if _, ok := m[a]; !ok {
			m[a] = 0
		}
		m[a]++
	}
	for i := 0; i < n; i++ {
		v, ok := m[i+1]
		if !ok {
			v = 0
		}
		if q-v < k {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
ll N,M;
ll ans=0;
cin>>N>>M;
if(N==2||M==2){
}else if(N==1||M==1){
	if(N==1){
		ans=max(1LL,M-2);
	}else{
		ans=max(1LL,N-2);
	}
	
}else{
	ans=(N-2)*(M-2);
}
ce(ans)
}


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

int main(){
	unsigned long long a,b,x;
	unsigned long long lower, top, ans;
	scanf("%lld %lld %lld", &a, &b, &x);

	lower = (a-1+x) / x;
	top = (b+ x) / x;
	ans = top - lower;
	printf("%lld\n", ans);
	
	return 0;

}


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

#define         ull             unsigned long long
#define         ll              long long
#define         inf             INT_MAX
#define         pi              acos(-1.0)
#define         vi              vector<int>
#define         vl              vector<long long>
#define         pii             pair<int,int>
#define         pll             pair<long long,long long>
#define         mp              make_pair
#define         mii             map<int,int>
#define         mll             map<int,int>
#define         mli             multimap<int,int>
#define         mlll            multimap<long long,long long>
#define         msi             multiset<int>
#define         msl             multiset<long long>
#define         si              set<int>
#define         sl              set<long long>
#define         FOR(I,A,B)      for(int I = (A); I < (B); I++)
#define         rev(I,A,B)      for(int I = A ; I >= B ; I--)
#define         mem(a, v)       memset(a, v, sizeof (a))
#define         mod             1000000007
#define         all(a)          a.begin(),a.end()
#define         rall(a)         a.rbegin(),a.rend()
#define         ff              first
#define         ss              second
#define         arsort(ar,n)    sort(ar,ar+n);
#define         vsort(v)        sort(v.begin(),v.end())
#define         vrev(v)         reverse(v.begin(),v.end())
#define         arrev(ar,n)     reverse(ar,ar+n)
#define         pb              push_back
#define         popb            pop_back
#define         booster()       ios_base::sync_with_stdio(0); cin.tie(0);
#define         read(f)         freopen(f, "r", stdin)


#define         min3(a,b,c)     min(a,min(b,c))
#define         max3(a,b,c)     max(a,max(b,c))
#define         min4(a,b,c,d)   min(min(a,b),min(c,d))
#define         max4(a,b,c,d)   max(max(a,b),max(c,d))
#define         max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define         min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))


#define         bitCheck(a,k)     ((bool)(a&(1<<(k))))
#define         bitOff(a,k)       (a&(~(1<<(k))))
#define         bitOn(a,k)        (a|(1<<(k)))
#define         bitFlip(a,k)      (a^(1<<(k)))


int fx[] = {-1,+0,+1,+0,+1,+1,-1,-1,+0};
int fy[] = {+0,-1,+0,+1,+1,-1,+1,-1,+0};
int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

using namespace std;

bool comp(int x, int y) { return x > y; }

/*********************** let the play begin() ***********************************/

int main()
{
    booster()
    int n;
    cin>>n;
    cout<<"ABC"<<n;
    return 0;
}


Measured memory_bytes: 256
n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
a.sort()
used=[False]*n
idx=n-1
cnt=0
while True:
    if idx-cnt<0:
        break
    tmp=sum(a[idx-cnt:idx+1])
    if tmp<k:
        cnt+=1
        continue
    for i in xrange(idx-cnt,idx+1):
        used[i]=True
    tmp-=a[idx-cnt]
    for i in xrange(idx-cnt-1,-1,-1):
        if tmp+a[i]>=k:
            used[i]=True
        else:
            break
    idx-=1
    cnt=0
ans=0
for i in xrange(n):
    if not used[i]:
        ans+=1
print ans

Measured memory_bytes: 33640
/*
https://atcoder.jp/contests/abc134/tasks/abc134_e
N個同時に最小部分列を作る


部分列では常に増加
dp[][]がある
a[i]を見た時, どこを更新するべきか?
30 40 50 60
新たに20が来た
30 40 50 60
20
新たに45が気来た
30 40 50 60
45
vs 
30 40 45
50 60
どちらも嬉しさは変わらない 前者の方がいい


最後尾に対して数列を持っておくと,
最後尾のうちxより小さい最大のものをxに更新
条件を満たすものがなければ追加
だから全部-1にしておいて, 

20
10
-1
-1

[30が来たら]
30
10
-1
-1

[15が来たら]
20
15
-1
-1
[10が来たら]
20
10
10
-1

dp[j]<A[i]を満たす最小のjを更新


*/
#include<bits/stdc++.h>
using namespace std;
long bs(long x,const vector<long>& v){
  long l=-1,r=v.size();
  while(r-l!=1){
    long z=(l+r)/2;
    if(v[z]<x)r=z;
    else l=z;
  }
  return r;
}
int main(){
  long N;cin>>N;vector<long>A(N),dp(N,-1);
  for(long i=0;i<N;i++)cin>>A[i];
  for(long i=0;i<N;i++){
    long z=bs(A[i],dp);
    dp[z]=A[i];
  }
  long ans=0;
  for(long i=0;i<N;i++)ans+=(dp[i]!=-1);
  cout<<ans<<endl;
  
}
    
  




Measured memory_bytes: 4808
# -*- coding:utf-8 -*-

def solve():
    # O(NlogN)解放
    #
    # f(1)~f(N)までの総和を求めるということは、
    # 1の倍数の数
    # 2の倍数の数
    # 3の倍数の数...
    # を1からNまで計算して足していけばよい。
    #
    # 配列 anss[i] := iの倍数の個数
    # に対して、
    # i=1からNまで順に足して行けば良い。
    N = int(input())

    anss = [0]*(N+1)

    for i in range(1, N+1):
        j = 1
        while i*j <= N:
            anss[i*j] += 1
            j += 1

    ans = 0
    for i, a in enumerate(anss[1:]):
        ans += (i+1)*a
    print(ans)


def solve2():
    # O(N)の解法。
    #
    # f(1)~f(N)までの総和を求めるということは、
    # 1の倍数の数
    # 2の倍数の数
    # 3の倍数の数...
    # を1からNまで計算して足していけばよい。
    #
    # 1の倍数は    1,2,3,4,5,...
    # 2の倍数は 2*(1,2,3,4,5,...)
    # 3の倍数は 3*(1,2,3,4,5,...)
    # よって、Nまでの1の倍数の個数をg(N)とすると、
    # Nまでの2の倍数の個数は、g(N//2)
    # Nまでの3の倍数の個数は、g(N//3)
    #
    # これを利用すると、kの倍数の個数の計算はO(1)でできるので、
    # 全体の計算量はO(N)
    N = int(input())

    i = 1
    ans = 0
    while N//i != 0:
        n = N//i
        ans += i*((n*(n+1))//2)
        i += 1
    print(ans)


if __name__ == "__main__":
    solve2()


Measured memory_bytes: 9220
import heapq

def dijkstra_priorityqueue(s):
    global pq
    global d
    color=[0]*n
    d=[float('inf')]*n
    d[s]=0
    heapq.heappush(pq,[0,s])
    while len(pq)!=0:
        t,u=heapq.heappop(pq)
        color[u]=2
        if d[u]<t:
            continue
        j=-1
        for v in m[u][0::2]:
            j+=2
            if color[v]!= 2:
                if d[u]+m[u][j]<d[v]:
                    d[v]=d[u]+m[u][j]
                    color[v]=1
                    heapq.heappush(pq,[d[v],v])

n=input()
pq=[]
en=[]
m=[]
for i in xrange(n):
    en.append(map(int,raw_input().split()))
en.sort()
for i in xrange(n):
    m.append(en[i][2:])
dijkstra_priorityqueue(0)
for i in xrange(n):
    print i,d[i]

Measured memory_bytes: 42736
#include <bits/stdc++.h>
using namespace std;
typedef long long int intl;
typedef unsigned long long intu;
#define int           long long // change here

#define sfi(x)        scanf("%lld", &x) // change here
#define sfi2(x, y)    sfi(x) , sfi(y)
#define sfi3(x, y, z) sfi(x) , sfi(y) , sfi(z)
#define sfc(x)        scanf(" %c", &x)
#define sfs(x)        scanf(" %s", x)
#define sfsn(x)       scanf(" %[^\n]s", x)

#define pfi(x)        printf("%lld", (intl)x)
#define pfin(x)       printf("%lld", (intl)x), printf("\n")
#define pfis(x)       printf("%lld", (intl)x), printf(" ")
#define pfc(x)        printf("%c", x)
#define pfs(x)        printf("%s", x)
#define pfsn(x)       printf("%s", x), printf("\n")
#define space         printf(" ")
#define newline       printf("\n")
#define endl          '\n'
#define sp            ' '

#define watch(x)      cout<<"::debug::   "<< #x <<" : "<<x<<endl
#define watchi(x, i)  cout<<"::debug::   "<< #x <<"-> ["<<i<<"]"<<" : "<<x<<endl

#define INPUT         freopen("input.txt","r",stdin);
#define OUTPUT        freopen("output.txt","w",stdout);
#define FastRead      ios::sync_with_stdio(false), cin.tie(0);

#define FOR(i, begin, end)  for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define repit(it, x)        for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); ++it)
#define perit(it, x)        for(__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); ++it)
#define rep(i, begin, end)  for(int i = (begin), ed = (end); i < (ed); ++i)
#define per(i, end, begin)  for(int i = (end)-1, bg = (begin); i >= (bg); --i)

#define setval(a, v)  for(int i = 0, sz = (sizeof(a)/sizeof(*a)); i<sz; i++){ a[i] = v; }
#define ZERO(a)       memset(a, 0, sizeof(a))
#define MINUS(a)      memset(a, 0xff, sizeof(a))

#define all(a)        a.begin(), a.end()
#define min3(x, y, z) min(x,min(y,z))
#define max3(x, y, z) max(x,max(y,z))
#define PI            2*acos(0)
#define INF           1000000007
#define debug         if( 0 )



int32_t main()
{
    int a, b;
    cin >> a >> b;
    int  x1, x2;
    for(int i = 1; i < 1000;i++){
        x1 = (i * (i + 1)) / 2 - a;
        x2 = ((i+2) * (i + 1)) / 2 - b;
        if(x1 >= 1 && x1 == x2) {
            cout << x1  << endl;
            break;
        }

    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
long long N;
 
bool is_valid(int n) {
  bool is_3 = false;
  bool is_5 = false;
  bool is_7 = false;
  
  while(n!=0) {
    int res = n % 10;
    if(res==3) {
      is_3 = true;
    } else if(res==5) {
      is_5 = true;
    } else if(res==7) {
      is_7 = true;
    }
    if(is_3==true && is_5==true && is_7==true) {
      return true;
    }
    n /= 10;
  }
  
  return false;
}
 
long long func(long long n) {  
  if(n>N) {
    return 0;
  }
   
  int res = 0;
  if (is_valid(n)) {
    res = 1;
  }
  
  res += func(n*10+3);
  res += func(n*10+5);
  res += func(n*10+7);
 
  return res;
}
 
int main (){
  cin >> N;
  
  cout << func(0) << endl;  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=500;
int n,m,a[maxn][maxn],s[maxn];
int main()
{
	cin>>n>>m;
	for (int i=1;i<=n;i++)
	    for (int j=1;j<=m;j++)
	        scanf("%d",&a[i][j]);
	int ans=n;
	for (int k=1;k<m;k++)
	{
		memset(s,0,sizeof(s));
		for (int i=1;i<=n;i++) s[a[i][1]]++;
		int p=1;
		for (int i=2;i<=m;i++)
		    if (s[i]>s[p])
		        p=i;
		ans=min(ans,s[p]);
		for (int i=1;i<=n;i++)
		{
			int o=1;
			while (a[i][o]!=p) o++;
			for (int j=o;j<=m-k;j++) a[i][j]=a[i][j+1];
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define MODNUMBER 1000000007

int main() {
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	int N;
	char s;
	scanf("%d", &N);
	scanf("%c", &s);  // 改行文字空読み

	vector<int> c_num(26, 0);
	for (int i = 0; i < N; i++) {
		scanf("%c", &s);
		c_num[s - 'a']++;
	}

	long long result = 1;
	for (int i = 0; i < 26; i++) {
		result = (result * (c_num[i] + 1)) % MODNUMBER;
	}

	result = ((result - 1) + MODNUMBER) % MODNUMBER;
	cout << result;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
	string str;
	cin >>  str;
	if (str[2] == str[3] && str[4] == str[5])
	{
		puts("Yes");
	}
	else
	{
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k, *a = map(int, read().split())
dict = [-1] * (n + 1)
now = a[0]
dict[0] = 0
for i in range(1, n * 2):
    if i == k:
        print(now)
        exit()
    now = a[now - 1]
    if dict[now] != -1:
        k -= (i + 1)
        k %= (i - dict[now])
        break
    else:
        dict[now] = i
for i in range(k):
    now = a[now - 1]
print(now)


Measured memory_bytes: 27896
#include <iostream>
#include <cstring>
#define MOD 1000000007
using namespace std;

long long int n, a, b, c, d;

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>a>>b;
	if((b-a)%2==0){
		cout<<(b-a)/2;
		return 0;
	}
	cout<<min(a+(b-a-1)/2, n-b+1+(b-a-1)/2);
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(){

int x, y, tmp;

 while(1){
  scanf("%d%d", &x, &y);
  if(x == 0 && y == 0){
    break;
  } else if(x > y){
   tmp = x; x = y; y = tmp;
  }
   printf("%d %d\n",x, y);

 }



  return 0;
}



Measured memory_bytes: 1844
n=int(input())
x=0
y=0
t=0
fl=True
for i in range(n):
  nt,nx,ny=map(int,input().split())
  dist=abs(x-nx)+abs(y-ny)
  if (nt-t)%2!=dist%2 or (nt-t)<dist:
    print("No")
    break
  x,y=nx,ny
  t=nt
else:
  print("Yes")

Measured memory_bytes: 9192
#include<stdio.h>

int main()
{
    int a;
    char s[100];
    
    scanf("%d",&a);
    
    
    scanf("%s",s);
    
    if(a>=3200)
    {
        printf("%s",s);
    }
    else if(a<3200)
    {
        
        printf("red\n");
    }
    

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    int N, T;
    cin >> N >> T;
    vector<int> A(N);
    for(int i=0; i<N; ++i) {
        cin >> A[N-1-i];
    }
    int ma = -1, mi = 1e9;
    int ma_cnt = 0, mi_cnt = 0;
    int sub = 0;
    int res = 0;
    for(int i=0; i<N; ++i) {
        if(A[i] > ma) {
            ma = A[i];
            ma_cnt = 1;
            mi = 1e9;
        } else if(A[i] == ma) {
            ma_cnt++;
        } else if(A[i] < mi) {
            mi = A[i];
            mi_cnt = 1;
            if(ma - mi > sub) {
                res = max(ma_cnt, mi_cnt);
                sub = ma - mi;
            } else if(ma - mi == sub) {
                res++;
            }
        } else if(A[i] == mi) {
            mi_cnt++;
            res = max(ma_cnt, mi_cnt);
        }
    }
    cout << res << endl;
}



Measured memory_bytes: 640
package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b int
	fmt.Scanf("%d %d\n", &a, &b)

	nums := make([]int, 3)

	nums[0] = a + b
	nums[1] = a - b
	nums[2] = a * b
	sort.Ints(nums)

	fmt.Println(nums[2])
}


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

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(NULL);
    int n,i,j; int w;
    cin >> n >> w;
    int weight[n];long int val[n];
    for(i=0;i<n;i++){
        cin >> weight[i] >> val[i];
    }
    long int dp[n+1][w+1];
    for(i=0;i<=w;i++)
    dp[0][i]=0;
    for(i=0;i<=n;i++)
    dp[i][0]=0;
    
    for(i=1;i<=n;i++){
        for(j=1;j<=w;j++){
            if(j-weight[i-1] >= 0)
            dp[i][j] = max(dp[i-1][j-weight[i-1]]+val[i-1] , max (dp[i-1][j],dp[i][j-1]));
            else
            dp[i][j]= max(dp[i-1][j],dp[i][j-1]);
        }
    }
   
    cout << dp[n][w];
}

Measured memory_bytes: 79232
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 100100;
int v[maxn];
int n;
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i ++)
		cin >> v[i];
	sort(v + 1, v + n + 1);
	int cnt = 0, a = 0;
	int p = 1;
	for(int i = n; i >= 1; i --)
	{
		while(v[p] <= a)
			p ++;
		if(p > i)
		{
			cout << "First" << endl;
			return 0;
		}
		if(v[p] == v[i])
		{
			if((v[i] - a + i - p) & 1)
				cout << "Second" << endl;
			else
				cout << "First" << endl;
			return 0;
		}
		if(v[p] == v[i - 1] && v[p] == a + 1)
		{
			if(((i - p) & 1) | ((v[i] - a - 1) & 1))
				cout << "First" << endl;
			else
				cout << "Second" << endl;
			return 0;
		}
		cnt += 2;
		a ++;
	}
	return 0;
}
/*
5
2 2 4 1 3 
*/

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")

typedef long long ll;
typedef unsigned long long ull;
// typedef __int128_t lll;
#define fatnet ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

const ll MOD1 = 1e9 + 7;
const ll MOD2 = 2000003983; // 3571 1e9 + 97
const ll MOD3 = 1e9 + 9;
const ll p1 = 1e6 + 3;
const ll p2 = 2017; // 131 37
const ll p3 = 37;
const ll INF = 5e18;

ll binpow(ll a, ll n, ll MOD) {
    if (n == 0)
        return 1;
    if (n % 2 == 1)
        return a * binpow(a, n - 1, MOD) % MOD;
    else
        return binpow(a * a % MOD, n / 2, MOD);
}

int main() {
    fatnet;

    ll n, m;
    cin >> n >> m;
    vector < ll > a(n);
    vector < ll > b(m);
    ll dp[n][m]{};
    ll sum[n + 1][m + 1]{};
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < m; ++i)
        cin >> b[i];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (a[i] == b[j]) {
                dp[i][j] = (1 + sum[i][j]) % MOD1;
                sum[i + 1][j + 1] = (sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + MOD1 + dp[i][j]) % MOD1;
            }
            else {
                sum[i + 1][j + 1] = (sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + MOD1) % MOD1;
                dp[i][j] = 0;
            }
        }
    }
    ll ans = 1;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            ans = (ans + dp[i][j]) % MOD1;
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 62848
<?php
/*
    Problem URL : http://agc003.contest.atcoder.jp/tasks/agc003_c

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

ini_set('error_reporting', E_ALL & ~E_NOTICE);

$a = array();
$c = array();
fscanf(STDIN, "%d", $N);
for ($i = 0; $i < $N; $i++) {
	fscanf(STDIN, "%d", $a[$i]);
}
$b = $a;

// 座標圧縮
sort($b);
$b = array_flip($b);

$ans = 0;
for ($i = 0; $i < $N; $i++) {
	$c[$i] = $b[$a[$i]];
	$x = $i % 2;
	$y = $b[$a[$i]] % 2;
	if ($x === $y) {

	} else {
		$ans++;
	}
}

echo ($ans / 2) . PHP_EOL;


Measured memory_bytes: 42460
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;

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


int lis(vector<int> const& a) {
    int n = a.size();
    const int INF = 1e9;
    vector<int> d(n+1, INF);
    d[0] = -INF;

    for (int i = 0; i < n; i++) {
        int j = upper_bound(d.begin(), d.end(), a[i]) - d.begin();
        if (d[j-1] <= a[i] && a[i] <= d[j])
            d[j] = a[i];
    }

    int ans = 0;
    for (int i = 0; i <= n; i++) {
        if (d[i] < INF)
            ans = i;
    }
    return ans;
}

int32_t  main()
{ 
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
 
  #ifndef ONLINE_JUDGE
  freopen("input.txt","rt",stdin);
  freopen("output.txt","wt",stdout);
  #endif

  int n,k;
  cin>>n>>k;
  vector<int>v(n); for(int i=0;i<n;i++)cin>>v[i];

  int ans=1e9;

  int s=1,e=1e9+10;
  while(s<=e)
  {
    int mid=(s+e)/2;

    int cnt=0;
    for(int i=0;i<n;i++)
    {
      if(v[i]>mid){
      int z=v[i]/mid;
      cnt+=z;
      }
    }

    if(cnt<=k)
    {
      ans=mid; e=mid-1;
    }
    else s=mid+1;
  }

  cout<<ans<<"\n";

}

Measured memory_bytes: 4688
#include <stdio.h>

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  long int n;
  scanf("%ld",&n);
  long int A[n+100];
  for(int i=0;i<n+100;i++){
    A[i]=0;
  }

  for(int i=1;i<=n;i++){
    for(int j=i;j<=n+10;j+=i){
      A[j]++;
    }
  }

  long int ans=0;
  for(long int i=1;i<=n;i++){
    ans+=A[i]*i;
  }

  printf("%ld\n",ans);
  return 0;
}

Measured memory_bytes: 79852
#include<iostream>
#include<vector>
#include<string>

using ll = long long;
const ll MOD = 1000000007;

int main(){
    ll n;
    std::cin >> n;
    if(n == 1){
        std::cout << 0 << std::endl;
        return 0;
    }else if(n == 2){
        std::cout << 2 << std::endl;
        return 0;
    }

    // 1つも0を含まない個数
    ll one = 1;
    ll two = 1;
    ll all = 1;
    for(int i = 0; i < n; i++){
        one *= 9;
        one %= MOD;
        all *= 10;
        all %= MOD;
        two *= 8;
        two %= MOD;
    }


    ll ans = all + two + 2 * MOD - one * 2;
    ans %= MOD;
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3616
#include<iostream>

using namespace std;
bool Judge(int *list,int n)
{
	for(int i = 0; i < n; i++)
		if(list[i]&1) return false;
		else list[i] /= 2;
	return true;
}
int main( )
{
	int n;
	cin >> n;
	int num[205];
	for(int i = 0; i < n; cin >> num[i++]);
	int ans = 0;
	while(Judge(num,n)) ans++;
	cout << ans << endl;
 } 



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>    
#define inf 100000000
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
double dmax(double a,double b){
    return a>b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct

int main(void){
    int x=in(),f[1001]={0,1,},i,j;
    for(i=2;i<1000;i++){
        for(j=i*i;j<=x;j*=i)
            f[j]=1;
    }
    for(i=x;i>0;i--){
        if(f[i]){
            print(i);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll a[1000][1000];
ll x[200000] = {};
ll y[200000] = {};
ll x2[200000] = {};
ll y2[200000] = {};

int main() {
	ll h, w; cin >> h >> w;
	ll v;

	rep(i, 0, h)rep(j, 0, w) {
		cin >> v;
		a[i][j] = v % 2;
	}

	ll cnt = 0;
	rep(i, 0, h) {
		rep(j, 0, w - 1) {
			if (a[i][j] % 2) {
				a[i][j]--;
				a[i][j + 1]++;

				y[cnt] = i + 1;
				x[cnt] = j + 1;
				y2[cnt] = i + 1;
				x2[cnt] = j + 2;
				cnt++;
			}
		}
		if (i != h - 1) {
			if (a[i][w - 1] % 2) {
				a[i][w - 1]--;
				a[i + 1][w - 1]++;

				y[cnt] = i + 1;
				x[cnt] = w;
				y2[cnt] = i + 2;
				x2[cnt] = w;
				cnt++;
			}
		}
	}

	//rep(i, 0, h - 1) {
	//	if (a[i][w - 1] % 2) {
	//		a[i][w - 1]--;
	//		a[i + 1][w - 1]++;

	//		y[cnt] = i + 1;
	//		x[cnt] = w;
	//		y2[cnt] = i + 2;
	//		x2[cnt] = w;
	//		cnt++;
	//	}
	//}
	printf("%d\n", cnt);
	//cout << cnt << endl;
	rep(i, 0, cnt) {
		printf("%d %d %d %d\n", y[i], x[i], y2[i], x2[i]);
		//cout << y[i] << " " << x[i] << " " << y2[i] << " " << x2[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 11776
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<int, string> PSI;

int w, h, sx, sy, gx, gy;
int n, c, d, x, y;

int table[110][110];
int dis[110][110];

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

void solve(){
	REP(i, 110)REP(j, 110)dis[i][j] = INF;
	dis[sy][sx] = 0;

	queue<P> que;
	que.push(P(sy, sx));

	while (que.size()){
		P p = que.front(); que.pop();
		int cx = p.second, cy = p.first;

		if (y == gy&&x == gx)break;

		REP(i, 4){
			int nx = cx + dx[i], ny = cy + dy[i];
			if (nx >= 0 && nx < w&&ny >= 0 && ny < h){
				if (table[ny][nx] == table[cy][cx]
					&&dis[ny][nx] == INF){
					dis[ny][nx] = dis[cy][cx] + 1;
					que.push(P(ny, nx));
				}
			}
		}
	}
}

int main(){
	while (cin >> w >> h&&w + h){
		REP(i, 110)REP(j, 110){
			table[i][j] = 0;
		}
		cin >> sx >> sy >> gx >> gy;
		sx--;
		sy--;
		gx--;
		gy--;

		cin >> n;
		REP(i, n){
			cin >> c >> d >> x >> y;
			x--;
			y--;
			if (d == 0){
				REP(i, 2){
					REP(j, 4){
						table[y + i][x + j] = c;
					}
				}
			}
			else{
				REP(i, 4){
					REP(j, 2){
						table[y + i][x + j] = c;
					}
				}
			}
		}

		solve();

		if (dis[gy][gx] != INF&&table[sy][sx] != 0 && table[gy][gx] != 0)cout << "OK" << endl;
		else cout << "NG" << endl;
	}
}

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

using LL = long long;

bool check(auto S, auto A, auto B) {
  vector<bool> dp(51);
  dp[A] = true;
  for(auto k: S) {
    auto dup = dp;
    for(auto i=1; i<=50; ++i) if(dup[i]) dp[i%k] = true;
  }
  return dp[B];
}

int main() {
  LL N;
  cin >> N;
  vector<LL> A(N), B(N);
  for(auto& i: A) cin >> i;
  for(auto& i: B) cin >> i;

  set<LL, greater<LL>> S;
  for(LL k=1; k<=50; ++k) S.emplace(k);

  auto ng = false;
  for(auto i=0; i<N; ++i) ng |= !check(S, A[i], B[i]);
  if(ng) {
    cout << -1 << endl;
    return 0;
  }

  for(LL k=50; 1<=k; --k) {
    S.erase(k);
    auto ng = false;
    for(auto i=0; i<N; ++i) ng |= !check(S, A[i], B[i]);
    if(ng) S.emplace(k);
  }

  cout << accumulate(begin(S), end(S), 0ll, [](auto s, auto i) {return s + (1ll << i);}) << endl;
}


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

string o, e;

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

    cin >> o >> e;

    int id1 = 0, id2 = 0;
    for (int i = 0; i < o.size() + e.size(); i++) {
        if (i&1) {
            cout << e[id2++];
        }
        else {
            cout << o[id1++];
        }
    }
    cout << '\n';

    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  string a,b,c;
  cin >> a >> b >> c;
  int A=0,B=0,C=0;
  char see='a';
  while(1){
  if(see=='a'){
      if(A == a.size()){
          cout << 'A' << endl;
                return 0;
      }
      see=a[A];
      A += 1;
  }else if(see=='b'){
    if(B == b.size()){
        cout << 'B' << endl;
                return 0;   
    }
      see=b[B];
      B += 1;
  }else if(see=='c'){
      if(C == c.size()){
          cout << 'C' << endl;
                return 0;
      }
      see=c[C];
      C += 1;
  }
  }
}

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

int gcd(int a, int b) {
  int c=0;
  while (a%b) {
    c = a%b;
    a = b;
    b = c;
  }
  return b;
}

int main() {
  int n=0, k=0, a=0, m=0, maxa=0;
  cin >> n >> k;
  
  string ans="IMPOSSIBLE";
  
  cin >> m;
  
  maxa = m;
  
  for (int i=1; i<n; i++) {
    cin >> a;
    if (a > maxa) maxa = a;
    m = gcd(m, a);
  }
  
  if (k <= maxa && k%m == 0) ans = "POSSIBLE";
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 300;

int N;

double getEx(int z, int a, int b, int c);

double dp[MAX_N + 1][MAX_N + 1][MAX_N + 1];

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

    cin >> N;

    int a = 0;
    int b = 0;
    int c = 0;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        if (x == 1) {
            a++;
        } else if (x == 2) {
            b++;
        } else {
            c++;
        }
    }

    fill(dp[0][0], dp[N + 1][0], -1.0);

    cout << fixed << setprecision(14) << getEx(0, a, b, c) << "\n";

    return 0;
}

double getEx(int z, int a, int b, int c)
{
    if (dp[a][b][c] >= 0.0) {
        return dp[a][b][c];
    }
    if (z == N) {
        return dp[a][b][c] = 0.0;
    }

    double sum = 0.0;
    if (a > 0) {
        sum += a * getEx(z + 1, a - 1, b, c) + a;
    }
    if (b > 0) {
        sum += b * getEx(z, a + 1, b - 1, c) + b;
    }
    if (c > 0) {
        sum += c * getEx(z, a, b + 1, c - 1) + c;
    }

    return dp[a][b][c] = (sum + z) / double(N - z);
}

Measured memory_bytes: 216892
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N, M, C,a=0,ans=0; cin >> N >> M >> C;
  int B[M],A[N*M];
  for (int i=0;i<M;i++) {
    cin >> B[i];
  }
  for (int i=0;i<M*N;i++) {
    cin >> A[i];
  }
  for (int i=0;i<N;i++) {
    for (int I=0;I<M;I++){
      a=a+A[M*i+I]*B[I];
    }
    if (a+C>0) ans=ans+1;
    a=0;
  }
  cout << ans << endl;
}

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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  int n;
  cin >> n;
  vector<int> w(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
    sum += w[i];
  }

  int s1 = 0, res = sum;

  for (int i = 0; i < n; i++) {
    s1 += w[i];
    res = min(res, abs(s1 - (sum - s1)));
  }

  cout << res << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define endl "\n"
inline bool EQ(double a, double b)
{
    return fabs(a - b) < 1e-9;
}
const int INF = 1 << 29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }

inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int &n, int b) { n |= two(b); }
inline void unset_bit(int &n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n)
{
    int res = 0;
    while (n && ++res)
        n -= n & (-n);
    return res;
}
template <class T>
void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
void chmin(T &a, const T &b) { a = min(a, b); }

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

    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}

Measured memory_bytes: 3648
#!/bin/bash
export LC_ALL=C
read w h n
((--w));((--h))
rm -rf *.f
cat|eval tee '>(awk -vw=$w -vh=$h -v k='{0..7}\ \''
NR%8==k{
	s=$1<3?2:$1-1
	t=w<$1+1?w:$1+1
	u=$2<3?2:$2-1
	v=h<$2+1?h:$2+1
	for(i=s;i<=t;i++)for(j=u;j<=v;j++)print i,j|"sort -nk1,2 -o "k".f";echo -n
}
'\'\) \>/dev/null|cat
sort -mnk1,2 ?.f|uniq -c|sort -snk1|uniq -cw7|awk -vw=$w -vh=$h '{a[$2]=$1;a[0]=a[0]"-"$1}END{a[0]=--w"*"--h""a[0];for(i=0;i<=9;i++)printf"$((%s))\n",a[i]?a[i]:0|"eval echo $(cat)"}'|tr \  \\n

Measured memory_bytes: 74220
# -*- coding: utf-8 -*-

N = int(input())
S = input()

nb, lb = 0, [0]
for i in range(N):
    if S[i] == '#':
        nb += 1
    lb.append(nb)

ans = N
for i in range(N + 1):
    ans = min(ans, lb[i] + (N - lb[-1]) - (i - lb[i]))
print(ans)


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

int main()
{
    int i;
    int k,x;
    cin >> k >> x;
    for(i = x-k+1;i <= x+k-1;++i){
        if(i < -1000000 || i > 1000000){
            continue;
        }
        cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int k, nums[32] = {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};

    cin >> k;
    cout << nums[k - 1];
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

ll dp[100][100];

int main(){
	//egg iter
	memset(dp, -1, sizeof(dp));
	rep(i, 100) rep(j, 100){
		if(i == 0) dp[i][j] = 1;
		if(j == 0) dp[i][j] = 1;
		if(dp[i][j] < 0) dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1];
	}
	int t; cin >> t;
	while(t--){
		ll n; int e; cin >> n >> e;
		for(int i = 0; ; i++){
			if(dp[e][i] > n){
				cout << i << endl;
				break;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 3176
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;
 
 int main(void){
	 int A,B,C;
	 cin >> A >> B >>C;
	 if(A==B){
		 cout << C << endl;
	 }else if(B==C){
		 cout << A << endl;
	 }else{
		 cout << B << endl;
	 }
 }

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

int main(){
 	int arr[5];
	for(int i = 0;i<5;i++){
      cin >> arr[i];
      if(arr[i] == 0){
        	cout << i+1 << endl;
        	break;
      }
    }
  
  
  return 0;
}


Measured memory_bytes: 3160
#!/usr/bin/env python3


def solve(n: int, m: int):
    if n == 1 and m == 1:
        return 1
    if n >= 2 and m >= 2:
        return n * m - 2 * (n + m - 2)
    return max(n - 2, 0) + max(m - 2, 0)


def main():
    N, M = map(int, input().split())
    print(solve(N, M))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
#include <stdio.h>

using namespace std;

int main(void) {
    int x, y;
    cin >> x >> y;
    if (x > y) swap(x, y);

    while(true) {
        auto a = x % y;
        if (a == 0) break;
        x = y;
        y = a;
    }
    cout << y << endl;
}



Measured memory_bytes: 3084
void main() {
    import std.stdio, std.string, std.conv;
    import std.algorithm;

    auto rd = readln.split.to!(int[]);
    int N = rd[0], H = rd[1];

    auto b = new int[](N);
    int amax;

    foreach (i ; 0 .. N) {
        rd = readln.split.to!(int[]);
        int ai = rd[0], bi = rd[1];
        b[i] = bi;
        amax = max(amax, ai);
    }

    b.sort!"a > b"();

    auto bs = new long[](N + 1);
    foreach (i ; 1 .. N + 1) {
        bs[i] = bs[i-1] + b[i-1];
    }

    int ans = H;

    foreach (i ; 0 .. N + 1) {
        int tmp = i;
        long rm = H - bs[i];
        if (rm > 0) {
            tmp += (rm + amax - 1) / amax;
        }
        ans = min(ans, tmp);
    }

    writeln(ans);
}

Measured memory_bytes: 4348
#pragma region template

#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#pragma region random

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> T randint(T a, T b) {
    return uniform_int_distribution<T>(a, b)(rng);
}

#pragma endregion

#pragma region debug
string to_string(string s) { return '"' + s + '"'; }

string to_string(const char *s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B> string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A> string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first)
            res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

#pragma endregion

#pragma endregion

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    for(int i=1;i<10;i++)
    {
        if(n%i==0&&n/i<10)
        {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D) {
   cout << "Left" << endl;
  }
  else if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }

}

Measured memory_bytes: 256