akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

static class Ex{
	public static int LowerBound<T>  (this IList<T> a, T v) where T:IComparable<T> {
		if(a[0].CompareTo(v) >= 0) return 0;
		int l = 0, r = a.Count;
		while(r - l > 1){
			int c = (r + l) / 2;
			if(a[c].CompareTo(v) < 0) l = c;
			else r = c;
		}
		return r;
	}
}

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long[][] S = new long[2][];
		for(int i=0;i<2;i++) S[i] = new long[N + 1];
		for(int i=0;i<N;i++){
			for(int j=0;j<2;j++){
				S[j][i + 1] = S[j][i] + (i % 2 == j ? A[i] : 0);
			}
		}
		
		long[] ans = new long[Q];
			
		for(int i=0;i<Q;i++){
			var x = X[i];
			int idx = A.LowerBound(x);
			if(idx == N) idx--;
			if(idx > 0 && Math.Abs(x - A[idx - 1]) <= Math.Abs(x - A[idx])) idx--;
			int l = 1, r = N;
			while(r - l > 1){
				// 高橋君が右側c個取れる
				// atatataaAatttT c == 4
				int c = (r + l) / 2;
				if(possible(c, idx, x, A)){
					l = c;
				} else {
					r = c;
				}
			}
	//cerr << "i:" << i << " l:" << l << endl;
			
			long taka = (S[0][N] - S[0][N - l]) + (S[1][N] - S[1][N - l]);
			int rest = N - l - (l - 1);
			if(rest % 2 == 1){
				taka += S[1][rest];
			} else {
				taka += S[0][rest];
			}
			// ll aoki = (S[0][N] + S[1][N]) - taka;
			ans[i] = taka;
			
		}
		Console.WriteLine(String.Join("\n", ans));
		
	}
	

	bool possible(int c, int idx, long x, long[] a){
		// 高橋君が右側c個取れる．青木君はidxから始まる
		// atatataaAatttT c == 4
		int N = a.Length;
		if(c == 1) return true;
		if(N - c <= idx) return false;
		if(2 * c - 2 >= N) return false;
		
		// 高橋君が右側c-1個取り終わっていて，
		// 青木君がc-1個目としてA[N-c]を必ず取らなければいけない場合はfalse，
		// それ以外はtrue
		
		// 右にまだ余裕がある
		if(idx + (c - 2) < N - c) return true;
		
		// 右はN-c-1まで取っているとして，N-cを取るより左側をとる方が理にかなっている
		int nl = N - c - 1 - (c - 2);
		if(nl < 0) return false;
		if(Math.Abs(a[nl] - x) <= Math.Abs(a[N - c] - x)) return true;
		return false;
		
	}
	
	
	
	int N,Q;
	long[] A,X;
	public Sol(){
		var d = ria();
		N = d[0]; Q = d[1];
		A = rla();
		X = new long[Q];
		for(int i=0;i<Q;i++) X[i] = rl();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 35456
nk = list(map(lambda x: int(x), input().split()))
n = nk[0]
k = nk[1]

poss_points = [i+1 for i in range(n)]
needed_wins = [-1 for i in range(n)]

def convert(x):
  if (x == -1):
    return 0
  else:
    return x

def calc(x):
  return (1/n) * 0.5 ** x

for i in range(n):
  times = 0
  point = poss_points[i]
  if (needed_wins[i] != -1):
    continue

  while(True):
    if (point >= k):
      break
    point = point * 2
    times += 1

  if (times == 0):
    break
    
  next_int = i + 1
  while(times > 0 and next_int <= n):
    needed_wins[next_int-1] = times
    next_int = next_int * 2
    times -= 1

# -1 は0に変換
needed_wins = list(map(convert, needed_wins))

array = list(map(calc, needed_wins))
answer = sum(array)

print(answer)

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

bool isYY(string s) {
    if ("00" <= s && s <= "99") return true;
    return false;
}

bool isMM(string s) {
    if ("01" <= s && s <= "12") return true;
    return false;
}


int main() 
{
    string s;
    cin >> s;

    string a = s.substr(0,2);
    string b = s.substr(2,2);

    if (isYY(a) && isMM(b)) {
        if (isMM(a) && isYY(b)) {
            cout << "AMBIGUOUS" << endl;
            return 0;
        }
        cout << "YYMM" << endl;
    } else {
        if (isMM(a) && isYY(b)) {
            cout << "MMYY" << endl;
            return 0;
        }
        cout << "NA" << endl;
    }
    
    return 0;
}


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

public class Main {
    static Deque<String> list = new ArrayDeque<>();

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        for (int i = 0; i < n; i++) {
            String sp = br.readLine();
            if (sp.startsWith("insert")) {
                list.addFirst(sp.substring(sp.indexOf(" ") + 1));
            }else if (sp.equals("deleteFirst")) {
                list.removeFirst();
            } else if (sp.equals("deleteLast")) {
                list.removeLast();
            } else if (sp.startsWith("delete")) {
                list.remove(sp.substring(sp.indexOf(" ") + 1));
            }
        }
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringBuilder ans = new StringBuilder();
        ans.append(list.poll());
        for (String s : list) {
            ans.append(" ");
            ans.append(s);
        }
        bw.write(ans.toString());
        bw.newLine();
        bw.close();
        br.close();
    }
}



Measured memory_bytes: 159716
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Ptoblem0513 : Shuffle The Cards **/
int main()
{
	int N, K;
	cin>>N>>K;
	vector<int> A(2*N);
	
	rep(i, 2*N) A[i] = i;
	
	rep(i, K) {
		int t; cin>>t;
		vector<int> B;

		if (t==0) {
			rep(j, N) {
				B.push_back(A[j]);
				B.push_back(A[N+j]);
			}
		} else {
			for (int j=t; j<2*N; j++)
				B.push_back(A[j]);
			
			for (int j=0; j<t; j++)
				B.push_back(A[j]);
		}
		A = B;
	}
	
	rep(i, 2*N) {
		cout << A[i]+1 << endl;
	}
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<(int)(r); i++)
#define rep_eq(i,l,r) for(int i=l; i<=(int)(r); i++)
#define all(vec) vec.begin(),vec.end()
#define allr(vec) vec.rbegin(),vec.rend()
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; }

using ll=int64_t;

using vb=vector<bool>;
using vc=vector<char>;
using vs=vector<string>;
using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;

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

  int MAX=pow(10,5)+1;
  vb is_prime(MAX,true);
  is_prime[0]=false;
  is_prime[1]=false;
  rep(i,2,MAX) {
    if (!is_prime[i]) {
      continue;
    }
    for (int j=i*2;j<MAX;j=j+i) {
      is_prime[j]=false;
    }
  }

  vi a(MAX,0);
  for (int i=1;i<MAX;i+=2) {
    if (is_prime[i] && is_prime[(i+1)/2]) {
      a[i]=1;
    }
  }

  vi s(MAX+1,0);
  rep(i,0,MAX) {
    s[i+1]=s[i]+a[i];
  }

  int Q; cin >>Q;
  rep(q,0,Q) {
    int left,right; cin >>left >>right;
    right++;

    cout <<s[right]-s[left] <<'\n';
  }
  return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> v(M);
    for (int i = 0; i < N; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int a;
            cin >> a;
            a--;
            v[a]++;
        }
    }
    int res = 0;
    for (int i = 0; i < M; i++) {
        if (v[i] == N) res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in [0]*M]

E = [{} for _ in [0]*N]
Eb = [{} for _ in [0]*N]
for a,b in AB:
    E[a-1][b-1] = 1
    Eb[b-1][a-1] = 1

import heapq
def Dijkstra(N,E,start):
    d = [-1]*N
    q = [(0,start)]
    while q:
        ci,i = heapq.heappop(q)
        if d[i]!= -1:continue
        d[i] = ci
        for j,cj in E[i].items():
            if d[j]!=-1:continue
            heapq.heappush(q,(ci+cj,j))
    return d
INF = N*10
ans = [INF]
for i in range(N):
    d = Dijkstra(N,E,i)
    j = -1
    dj = INF
    for k in Eb[i]:
        if d[k]>0 and d[k]<dj:
            j = k
            dj = d[k]
    if (j!=-1) and ((dj+1) < ans[0]):
        ans = [dj+1,i+1]
        while j!=i:
            ans.append(j+1)
            dj = d[j]
            for k in Eb[j]:
                if d[k] == dj-1:
                    j = k
                    dj = d[k]
                    break

if ans[0] == INF : ans = [-1]
for out in ans:
    print(out)

Measured memory_bytes: 97496
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFLL = 1LL<<60;

ll calc_num_of_combination(ll n, ll r) {
  ll num = 1;
  for(ll i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

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

  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  map<int, int> mp;
  vector<ll> s(n);
  s[0] = a[0] % m;
  mp[s[0]]++;
  for (int i = 1; i < n; i++) {
    s[i] = (s[i-1] + a[i]) % m;
    mp[s[i]]++;
  }

  ll ans = 0;
  for (auto& p : mp) {
    if (p.first == 0) ans += p.second;
    if (p.second >= 2) ans += calc_num_of_combination(p.second, 2);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define x             first
#define y             second
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define PI            3.14159265358979
#define N             200005

int solve(){
    double r; cin>>r;
    cout<<6.28*r;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 3776
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        int n; cin >> n;
       int mx = 0;
       int num = 0;
       for(int i = 1; i<=n; i++){
                int temp = i;
                int cnt = 0;
                while(temp){
                    cnt++;
                    temp/=2;
                }
                if(cnt>mx){
                    num = i;
                    mx = cnt;
                }
            }
        cout<<num<<endl;



return 0;
}




Measured memory_bytes: 256
char S[2001*2002];
m[4][2001*2002],H,W,z,d[4]={1,-1};

f(i,k){
	if(S[i]=='.'){
		return m[k][i]=m[k][i]?:1+f(i+d[k],k);
	}else{
		return 0;
	}
}

main(){
	scanf("%d%d ",&H,&W);
	d[2]=-~W;
	d[3]=~W;
	for(int y=1;y<=H;++y){
		for(int x=0;x<=W;++x){
			S[y*-~W+x]=getchar();
		}
	}
	for(int y=1;y<=H;++y){
		for(int x=0;x<=W;++x){
			int t=0;
			for(int k=0;k<4;++k){
				t+=f(y*-~W+x,k);
			}
			z=fmax(z,t);
		}
	}
	printf("%d",z-3);
}


Measured memory_bytes: 66688
# 実際にシミュレーションしていく方針で解く
N, A, B, C = map(int, input().split())
d = {}
d["A"] = A
d["B"] = B
d["C"] = C
S = [input() for _ in range(N)]
ans = []
for i in range(N):
    s = S[i]
    if s == "AB":
        if d["A"] > d["B"]:
            d["A"] -= 1
            d["B"] += 1
            ans.append("B")
        elif d["A"] < d["B"]:
            d["B"] -= 1
            d["A"] += 1
            ans.append("A")
        else:  # 同じ場合
            if d["A"] == d["B"] == 0:
                print("No")
                exit()
            if N > i+1:
                if "A" in S[i+1]:
                    d["B"] -= 1
                    d["A"] += 1
                    ans.append("A")
                elif "B" in S[i+1]:
                    d["A"] -= 1
                    d["B"] += 1
                    ans.append("B")
                else:
                    d["A"] -= 1
                    d["B"] += 1
                    ans.append("B")
            else:
                if d["A"] > 0:
                    ans.append("A")
                elif d["B"] > 0:
                    ans.append("B")

    if s == "AC":
        if d["A"] > d["C"]:
            d["A"] -= 1
            d["C"] += 1
            ans.append("C")
        elif d["A"] < d["C"]:
            d["C"] -= 1
            d["A"] += 1
            ans.append("A")
        else:
            if d["A"] == d["C"] == 0:
                print("No")
                exit()
            if N > i+1:
                if "A" in S[i+1]:
                    d["C"] -= 1
                    d["A"] += 1
                    ans.append("A")
                elif "C" in S[i+1]:
                    d["A"] -= 1
                    d["C"] += 1
                    ans.append("C")
                else:
                    d["A"] -= 1
                    d["C"] += 1
                    ans.append("C")
            else:
                if d["A"] > 0:
                    ans.append("A")
                elif d["C"] > 0:
                    ans.append("C")

    if s == "BC":
        if d["B"] > d["C"]:
            d["B"] -= 1
            d["C"] += 1
            ans.append("C")
        elif d["B"] < d["C"]:
            d["C"] -= 1
            d["B"] += 1
            ans.append("B")
        else:
            if d["B"] == d["C"] == 0:
                print("No")
                exit()
            if N > i+1:
                if "B" in S[i+1]:
                    d["C"] -= 1
                    d["B"] += 1
                    ans.append("B")
                elif "C" in S[i+1]:
                    d["B"] -= 1
                    d["C"] += 1
                    ans.append("C")
                else:
                    d["B"] -= 1
                    d["C"] += 1
                    ans.append("C")
            else:
                if d["B"] > 0:
                    ans.append("B")
                elif d["C"] > 0:
                    ans.append("C")

    if -1 in d.values():
        print("No")
        exit()

print("Yes")
for a in ans:
    print(a)


Measured memory_bytes: 16872
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 100050

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

char table[4][10] = {
    "maerd",
    "remaerd",
    "esare",
    "resare",
};

int lens[4] = {
    5,7,5,6
};

enum {
    ENUM_DREAM,
    ENUM_DREAMER,
    ENUM_ERASE,
    ENUM_ERASER,
    ENUM_ALL,
};

#define ALL_STATE ((1<<ENUM_ALL)-1)

int main(void) {
    char str[BUF_SIZE];
    get_str(str, BUF_SIZE);
    int len = strlen(str)-1;
    int pos;
    int cur_state = ALL_STATE;
    int idx = 0;
    int i;
    int flag = 1;
    for(pos = len-1; pos >= 0; pos--) {
#ifdef DEBUG
        printf("[%d: %c] %d\n", pos, str[pos], cur_state);
#endif
        int next_state = 0;
        for(i = 0; i < ENUM_ALL; i++) {
            if(!(cur_state & (1<<i))) continue;
            if(str[pos] == table[i][idx]) {
                next_state |= (1<<i);
            }
        }
        cur_state = next_state;
        idx++;
        for(i = 0; i < ENUM_ALL; i++) {
            if(!(cur_state & (1<<i))) continue;
            if(lens[i] == idx) {
                idx = 0;
                cur_state = ALL_STATE;
                break;
            }
        }
        // impossible to move back
        if(cur_state == 0) { flag = 0; break; }
    }
    printf("%s\n", flag ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()
l=0
h=n-1
while l<h:
    t=(l+h)//2
    b=sum(a[:t+1])
    for i in range(t+1,n):
        if b*2>=a[-1]:
            h=t
            break
        if b*2<a[i]:
            l=t+1
            break
        b+=a[i]
    else:
        h=t
print(n-l)

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


int main() {
	string S;
	cin >> S;
	int ans = 0;
	for (int i = 0;i<4;++i) {
		if ('+' == S[i]) {
			ans++;
		}
		else {
			ans--;
		}
	}
	cout << ans <<  endl;
	return 0;
}


Measured memory_bytes: 3472
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
string s[310];
char t[610][610];

bool check(int a, int b) {
    for (int i = a; i < a+n; i++) {
        for (int j = b; j < b+n; j++) {
            if (t[i][j] != t[j-b+a][i-a+b])
                return false;
        }
    }
    return true;
}

int solve() {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            t[i][j] = t[i+n][j] = t[i][j+n] = t[i+n][j+n] = s[i][j];
        }
    }
    int res = n * check(0, 0);
    for (int i = 1; i < n; i++) {
        res += (n-i) * check(i, 0);
        res += (n-i) * check(0, i);
    }
    return res;
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> s[i];
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 768
#include <stdio.h>
int Esearch(int,int);

int n,A[20];

int main(){
  int i,q,m;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(Esearch(0,m))printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

int Esearch(int i, int m){
  int key1,key2;
  if(m==0)return 1;
  if(i>=n)return 0;
  key1=Esearch(i+1,m-A[i]);
  key2=Esearch(i+1,m);
  if(key1==1||key2==1)return 1;
}

Measured memory_bytes: 580
from collections import Counter
n, m = map(int, input().split())

def factorize(m):
    c = Counter()
    t = 2
    while t**2 <= m:
        if m % t:
            t += 1
            continue
        while not m%t:
            c[t] += 1
            m //= t
    if m > 1:
        c[m] += 1
    return c
yakusu = [1]
for key, value in factorize(m).items():
    next_yakusu = []
    for i in range(value+1):
        for j in yakusu:
            next_yakusu.append(j*key**i)
    yakusu = next_yakusu

ans = 1
for i in yakusu:
    if n <= m//i:
        ans = max(ans, i)
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <stdio.h>
#include <ios>     
#include <iomanip> 

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  long N, M;
  cin >> N >> M;

  // output
  long ans = 0;
  if(N == 1 && M == 1){
    ans = 1;
  }else if(N == 1 && M > 1){
    ans = M-2;
  }else if(M == 1 && N > 1){
    ans = N-2;
  }else{  
    ans = (N-2)*(M-2);
  }
  output(ans);
  
  return 0;
}

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

int main() {
  int K;
  string S;
  cin >> K;
  cin >> S;
  if (S.size() <= K) {
    cout << S;
  }
  else {
    for (int i = 0; i < K; i++) {
      cout << S[i];
    }
    cout << "...";
  }
}


Measured memory_bytes: 3628
#include<cstdio>
#include<cstring>
#include<iostream>

using namespace std;

int a[100010];long long mx=0,sm=0;
int main()
{
    int n;scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]),mx=max(mx,(long long)a[i]),sm+=a[i];
    if (mx<sm-mx) puts("Yes");
    else puts("No");
}


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

lint rec(lint N, lint x){
	if(N == 0) return 1;
	if(x == 0) return 0;
	if(x == 1) return 0;
  lint len = (1LL << (N + 1)) - 3;
	lint num = (1LL << N) - 1;
	if(x <= 1 + len) return rec(N - 1, x - 1);
	if(x == 2 + len) return num + 1;
	if(x > 2 + len && x <= 2 + 2 * len) return num + 1 + rec(N - 1, x - len - 2);
	if(x == 3 + 2 * len) return 2 * num + 1;
}

signed main(){
	lint N, X; cin >> N >> X;
	cout << rec(N, X) << endl;
}


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

int main(){
	int n=0,x=0;
	int counter;
	int i=0,j=0,k=0;

	while(1){
		cin >> n >> x;
		if(n==0&&x==0){
			break;
		}
		
		for(i=1;i<=n;i++){
			for(j=i+1;j<=n;j++){
				for(k=j+1;k<=n;k++){
					if(i+j+k==x){
						counter +=1;
					}
				}
			}

		}
		cout << counter << endl;
		counter = 0;

	}
return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
ll b_pow(ll x,ll n){return n ? n==1 ? x: b_pow(x,n>>1)*b_pow(x,(n>>1)+(n&1)) : 1;}

int main(){
	ll z;
	while(cin >> z && z){
		ll ans = 0;
		for(ll x = 1 ; x*x*x <= z*z*z ; x++){
			ll y = pow(z*z*z-x*x*x,1.0/3);
			if(y!=0)ans = max(ans,x*x*x+y*y*y);
		}
		cout << z*z*z-ans << endl;
	}
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  int N, K;
  cin >> N >> K;
  vector<int> a(N);

  for (int i=0; i < N; ++i) {
    cin >> a[i];
  }
  sort(rbegin(a), rend(a));

  int sum = 0;
  for (int i= 0; i < K; ++i) sum += a[i];

  cout << sum << endl;


  return 0;
}



Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
from collections import defaultdict
n = int(readline())
lst1 = []
dic1 = defaultdict(int)
for i in range(n):
    dic1[readline().rstrip().decode('utf-8')] += 1
print(len(list(dic1.values())))

Measured memory_bytes: 105088
#![allow(non_snake_case, unused_mut, unused_assignments)]
use proconio::input;
use std::cmp::*;

fn main() {
  input! {
    N:usize, A:[String;N]
  }
  let N: usize = N;
  let A: Vec<String> = A;
  let mut cnt = vec![vec![0; 19]; 19];
  let mut p2 = vec![0; N];
  let mut p5 = vec![0; N];
  for i in 0..N {
    let s = A[i].clone();
    let mut ip = 0usize;
    let mut dp = 0usize;
    if let Some(i) = s.find('.') {
      // 入力値が小数の場合
      ip = s[0..i].parse().unwrap();
      let ss = s[(i + 1)..].to_string() + "0000000000";
      dp = ss[0..9].parse::<usize>().unwrap()
    } else {
      // 入力値が整数の場合
      ip = s.parse::<usize>().unwrap();
    }
    let mut x = ip * 1_000_000_000 + dp;
    while x % 2 == 0 {
      x /= 2;
      p2[i] += 1;
    }
    while x % 5 == 0 {
      x /= 5;
      p5[i] += 1;
    }
    p2[i] = min(p2[i], 18);
    p5[i] = min(p5[i], 18);
    cnt[p2[i]][p5[i]] += 1;
  }

  let mut ans = 0usize;
  for i in 0..N {
    let remain2 = 18 - p2[i];
    let remain5 = 18 - p5[i];
    for j in remain2..19 {
      for k in remain5..19 {
        ans += cnt[j][k];
      }
    }
    if p2[i] >= remain2 && p5[i] >= remain5 {
      ans -= 1;
    }
  }
  println!("{}", ans / 2);
}


Measured memory_bytes: 18732
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
    	int N, X;
    	int[] L;
    	int ans = 1;
    	
        void solve(InputReader in, PrintWriter out) {
        	N = in.nextInt();
        	X = in.nextInt();
        	L = in.nextIntArray(N);
        	
        	int d = 0;
        	for (int l : L) {
        		d += l;
        		if (d <= X) ans++;
        		else break;
        	}
        	
        	out.println(ans);
        }
        
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

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

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 21204
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <utility>
#include <set>
#include <map>
#include <vector>
#include <queue>
#define LL long long
#define PII pair<int, int>
#define f first
#define s second
using namespace std;
const int MAXN = 200005;

string s;
LL n, mod, pw[MAXN], suff[MAXN];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);

    cin >> n >> mod >> s;

    if (mod == 2 || mod == 5) {
        LL ans = 0;
        for (int i = 0; i < n; i++) {
            if ((s[i] - '0') % mod == 0) {
                ans += i + 1;
            }
        }
        cout << ans << '\n';
        return 0;
    }

    pw[0] = 1;
    for (int i = 1; i < MAXN; i++) {
        pw[i] = pw[i - 1] * 10 % mod;
    }

    LL ans = 0;
    map<LL, int> cnt;
    cnt[0]++;
    for (int i = n - 1; i >= 0; i--) {
        suff[i] = (suff[i + 1] + pw[n - i - 1] * (s[i] - '0')) % mod;
        ans += cnt[suff[i]];
        cnt[suff[i]]++;
    }

    cout << ans << '\n';
}


Measured memory_bytes: 4116
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> pii;
using namespace std;
using ll = long long;



int main(){
    int k;
    string s;
    cin >> k >> s;
    if (s.size() <= k){
        cout << s;
    }
    else{
        cout << s.substr(0,k) + "...";
    }
    
}
















Measured memory_bytes: 3628
import java.util.*;

// ARC 84-A
// https://beta.atcoder.jp/contests/arc084/tasks/arc084_a

public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];
		int[] C = new int[N];
		
		TreeSet<Integer> aSet = new TreeSet<Integer>();
		TreeSet<Integer> cSet = new TreeSet<Integer>();
		
		for (int i = 0; i < N; i++) {
			A[i] = in.nextInt();
			aSet.add(A[i]);
		}
		for (int i = 0; i < N; i++) {
			B[i] = in.nextInt();
		}
		for (int i = 0; i < N; i++) {
			C[i] = in.nextInt();
			cSet.add(C[i]);
		}
		
		Arrays.sort(A);
		Arrays.sort(B);
		Arrays.sort(C);
		
		long answer = 0;
		for (int i = 0; i < N; i++) {
			Integer a = aSet.lower(B[i]);
			Integer c = cSet.higher(B[i]);
			
			
			if (a != null && c != null) {
				long aIndex = binarySearch1(A, a);
				long cIndex = binarySearch2(C, c);
				
				answer += (aIndex + 1) * (N - cIndex);
			}
		}
		System.out.println(answer);
	}
	
	public static int binarySearch1(int[] arr, int n) {
		int low = 0;
		int high = arr.length - 1;
		
		while (low <= high) {
			int mid = (low + high) / 2;
			
			if (arr[mid] == n && (mid == arr.length - 1 || arr[mid + 1] != arr[mid])) {
				return mid;
			} else if (arr[mid] > n) {
				high = mid - 1;
			} else {
				low = mid + 1;
			}
		}
		return -1;
	}
	
	public static int binarySearch2(int[] arr, int n) {
		int low = 0;
		int high = arr.length - 1;
		
		while (low <= high) {
			int mid = (low + high) / 2;
			
			if (arr[mid] == n && (mid == 0 || (mid > 0 && arr[mid - 1] != arr[mid]))) {
				return mid;
			} else if (arr[mid] < n) {
				low = mid + 1;
			} else {
				high = mid - 1;
			}
		}
		return -1;
	}
}

Measured memory_bytes: 107020
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

long long N;

char C[3] = { '7', '5', '3' };

long long func( string s, int d ) {
    if ( d == 0 ) {

        bool x,y,z;
        x = y = z = false;
        for ( int i = 0; i < s.length(); i++ ) {
            if ( s[i] == '7' ) { x = true; }
            if ( s[i] == '5' ) { y = true; }
            if ( s[i] == '3' ) { z = true; }
        }
        
        return ( ( x && y && z && stoll(s) <= N ) ? 1 : 0 );
    }

    long long ret = 0;
    for ( int i = 0; i < 3; i++ ) {
        ret += func( s+C[i], d-1 );
    }
    return ret;

}

int main() {
    
    cin >> N;

    long long ans = 0;
    for ( int i = 1; i < 10; i++ ) {
        string s = "";
        ans += func( s, i );
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std ;

int main(){
    int N,K,X,Y;
    int a = 0;
    int b = 0;
    cin >> N >> K >> X >> Y;
    if(N <= K){
        a = N*X;
    }else{
        a = K*X;
        b = (N-K)*Y;
    }
    cout << a+b << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

int main(){
  int h,w,cnt=0;
  cin >> h >> w;
  int sx,sy,gx,gy;
  sx=1,sy=1,gx=h,gy=w;
  sx--,sy--,gx--,gy--;
  char c[h][w];
  int d[h][w];
  rep(i,h){
    rep(j,w){
      cin >> c[i][j];
      if(c[i][j]=='#')cnt++;
      d[i][j]=inf;
    }
  }
  queue<pint> que;
  int direct[5]={0,1,0,-1,0};
  d[sx][sy]=0;
  que.push({sx,sy});
  while(que.size()){
    int x=que.front().first;
    int y=que.front().second;
    que.pop();
    rep(i,4){
      int nx=x+direct[i];
      int ny=y+direct[i+1];
      if(0<=nx && nx<h && 0<=ny && ny<w && c[nx][ny]=='.' && d[nx][ny]==inf){
        d[nx][ny]=d[x][y]+1;
        que.push({nx,ny});
      }
    }
  }
  if(d[gx][gy]==inf){
    cout << -1 << endl;
    return 0;
  }
  cout << h*w-1-d[gx][gy]-cnt << endl;
  return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;

int memo[31];

int solve(int remain){
    int cnt = 0;

    if(memo[remain] != -1) return memo[remain];

    if(remain <= 0) return 0;
    if(remain == 1) return 1;
    if(remain == 2) return 2;
    if(remain == 3) return 4;

    for(int i=1;i<=3;++i){
        cnt += solve(remain - i);
    }

    return memo[remain] = cnt;
}


int main(void){
    int n;
    int val;

    while(cin >> n, n > 0){
        memset(memo,-1,sizeof(int)*31);

        val = solve(n)/10;
        val = val < 366 ? 1 : val % 365 == 0 ? val / 365 : val/365 + 1;
        cout << val << endl;
    }
}

Measured memory_bytes: 1164
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
static const int MAX_N = 100;

int N;
int a[MAX_N], b[MAX_N], c[MAX_N], d[MAX_N];

vector<int> G[2 * MAX_N];
int match[2 * MAX_N];
bool used[2 * MAX_N];

void add_edge(int u, int v){
  G[u].push_back(v);
}
 
bool dfs(int v){
  used[v] = true;
  for(int i = 0; i < G[v].size(); i++){
    int u = G[v][i], w = match[u];
    if(w < 0 || !used[w] && dfs(w)){
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}
 
int bipartite_matching(){
  int res = 0;
  fill(match, match + 2 * N, -1);
  for(int v = 0; v < 2 * N; v++){
    if(match[v] < 0){
      fill(used, used + 2 * N, 0);
      if(dfs(v)){
        res++;
      }
    }
  }
  return res;
}
 
int main(){
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> a[i] >> b[i];
  }
  for(int i = 0; i < N; i++){
    cin >> c[i] >> d[i];
  }
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(a[i] < c[j] && b[i] < d[j]){
        add_edge(i, j + N);
        add_edge(j + N, i);
      }
    }
  }
  cout << bipartite_matching() << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#pragma GCC optimize("O3")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 300*1000+15;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> tree_set;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    /*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int h,w;
    cin>>h>>w;
    cout<<(ll)ceil(h/(ld)w);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int cnt,n,a[101010],du[101010],to[101010],nxt[101010],fir[101010];
priority_queue<pair<int,int> > q;
priority_queue<int,vector<int>,greater<int> > eg[101010];
bool bok[101010];
void add(int x,int y)
{
	nxt[++cnt]=fir[x];fir[x]=cnt;
	to[cnt]=y; du[y]++;
}
int gcd(int x,int y){ return y?gcd(y,x%y):x;}
void top()
{
	for(int i=1;i<=n;i++) 
		if(!du[i]) q.push(make_pair(a[i],i));
	while(!q.empty())
	{
		int x=q.top().second;q.pop();
		printf("%d ",a[x]);
		for(int i=fir[x];i;i=nxt[i])
		{
			du[to[i]]--;
			if(!du[to[i]]) q.push(make_pair(a[to[i]],to[i]));
		}
	}
	puts("");
}
void dfs(int x)
{
	bok[x]=1;
	while(!eg[x].empty())
	{
		int y=eg[x].top();eg[x].pop();
		if(!bok[y])
		{
			add(x,y);
			dfs(y);
		}
	}
}		
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(gcd(a[i],a[j])!=1) eg[i].push(j),eg[j].push(i);
	for(int i=1;i<=n;i++)
		if(!bok[i]) dfs(i);
	top();
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int tpng = 0;
  for(int i = 0;i < 3;i++){
    if(s.at(i) == 'o'){
      tpng++;}
  }
  cout << tpng * 100 + 700 << endl;
}

Measured memory_bytes: 256
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (a, b) = listOfDouble()
    println(Math.ceil((a + b)/2).toInt())
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfDouble()= listOfString().map { it.toDouble() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 37940
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

static size_t A[100000];

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) < *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

int main(void) {
	char s[4];

	scanf("%s", s);

	size_t count = 0;
	for (size_t idx = 0; idx < strlen(s); idx++) {
		if (s[idx] == '1') {
			count++;
		}
	}

	printf("%zu\n", count);

	return 0;
}


Measured memory_bytes: 128
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  c <- T.getLine :: IO T.Text
  T.putStrLn . T.map succ $ c

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():

    N = list(map(int, input()))
    K = int(input())

    if K == 1:
        ans = (len(N) - 1) * 9 + N[0]

    elif K == 2:

        if len(N) < 2:
            print(0)
            exit()

        ans = (9 ** 2) * (len(N) - 1) * (len(N) - 2) // 2
        ans += (N[0] - 1) * (len(N) - 1) * 9

        for i in range(1, len(N)):
            if N[i] != 0:
                ans += N[i] + (len(N) - i - 1) * 9
                break

    elif K == 3:

        if len(N) < 3:
            print(0)
            exit()

        ans = (9 ** 3) * (len(N) - 1) * (len(N) - 2) * (len(N) - 3) // 6
        ans += (N[0] - 1) * (9 ** 2) * (len(N) - 1) * (len(N) - 2) // 2

        for i in range(1, len(N) - 1):
            if N[i] != 0:
                ans += (9 ** 2) * (len(N) - i - 1) * (len(N) - i - 2) // 2
                ans += (N[i] - 1) * (len(N) - i - 1) * 9
                for j in range(i + 1, len(N)):
                    if N[j] != 0:
                        ans += N[j] + (len(N) - j - 1) * 9
                        break
                break

    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)

int main() {

	int N;

	scanf("%d", &N);

	int ans = 112345;
	rep(i, N + 1) {
		int c = 0;
		int a = i, b = N - i;
		while (a) {
			c += a % 6;
			a /= 6;
		}
		while (b) {
			c += b % 9;
			b /= 9;
		}
		ans = min(ans, c);
	}

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

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.awt.geom.*;
public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			int [][] data = new int[n+1][n+1];
			for(int i= 0; i < n; i++){
				for(int j = 0 ; j< n; j++){
					data[i][j] = sc.nextInt();
				}
			}
			
			for(int i = 0; i < n; i++){
				int sum = 0;
				for(int j = 0; j < n; j++){
					sum+= data[j][i];
				}
				data[n][i] = sum;
			}
			
			for(int i = 0; i <= n; i++){
				int sum = 0;
				for(int j = 0; j < n; j++){
					sum += data[i][j];
				}
				data[i][n] = sum;
			}
			
			for(int i = 0; i <= n; i++){
				for(int j = 0; j <= n; j++){
					System.out.printf("%5d", data[i][j]);
				}
				System.out.println();
			}
		}
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

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

int main (){
    long long n;
    cin>>n;
    long long ans = n+1;
    for(long long i =1;i<=pow(n,0.5);i++){
        if(n%i == 0){
            if(ans>i+n/i)ans = i+n/i;
        }
        
    }
    cout<<ans-2<<endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import java.util.Scanner;

public class Main {
	static int N;

	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			N = s.nextInt();
			final int M = s.nextInt();

			List<BitSet> sw = new ArrayList<BitSet>((int) Math.pow(2, N));
			addSw(0, new BitSet(N), sw);

			List<BitSet> ri = new ArrayList<BitSet>((int) Math.pow(2, M));
			for (int i = 0; i < M; i++) {
				final int k = s.nextInt();
				BitSet bs = new BitSet(N);
				for (int j = 0; j < k; j++) {
					bs.set(s.nextInt() - 1, true);
				}
				ri.add(bs);
			}

			for (int i = 0; i < M; i++) {
				final int p = s.nextInt();
				List<BitSet> next = new ArrayList<BitSet>(sw.size());
				for (BitSet bs : sw) {
					BitSet w = (BitSet) bs.clone();
					w.and(ri.get(i));
					if (w.cardinality() % 2 == p) {
						next.add(bs);
					}
				}
				sw = next;
				if (next.size() == 0) {
					break;
				}
			}
			System.out.println(sw.size());
		}
	}

	static void addSw(int n, BitSet bs, List<BitSet> sw) {
		if (n == N) {
			sw.add((BitSet) bs.clone());
			return;
		}

		bs.set(n, true);
		addSw(n + 1, bs, sw);
		bs.set(n, false);
		addSw(n + 1, bs, sw);
	}
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

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

	int n;
	cin >> n;

	vi a(n), b(n), c(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i]  >> b[i] >> c[i];

	int dp[n][3];
	for (int i = 0; i < n; ++i)
		dp[i][0] = dp[i][1] = dp[i][2] = 0;

	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];

	for (int i = 1; i < n; ++i){
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
		dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + c[i];
	}

	cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << '\n';
}

Measured memory_bytes: 2560
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        int i;
        for(i=0;i<n;i++){
            a[i] = sc.nextInt();
        }
        int j;
        
        for(i=n-1;i>=0;i--){
            System.out.printf("%d",a[i]);
            if(i>=1){
                System.out.printf(" ");
            }
        
        }
        
        System.out.println();
    }
}


Measured memory_bytes: 26348