akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    string S; cin >> S;
    cout << S.substr(0,3) << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3612
# -*- coding: UTF-8 -*-

n = int(input())
b = list(map(int, input().split()))

s = b[0]+b[-1]
p = b[0]


if n > 2:
    for i in range(1,n-1):
        s += min(b[i],p)
        p = b[i]

print(s)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;
double x[100], y[100], z[100], r[100],sum,mn,maxd=99999999.9;
int n,m,mx=(1<<20),a,b,c,t,hozon;
double map[100][100];
double sumcor;
int p[100];
double d[100];
int visited[100];

double compute(int i, int j) {
  double ret;

  ret = sqrt((x[i]-x[j]) * (x[i]-x[j]) + (y[i]-y[j]) * (y[i]-y[j]) + (z[i]-z[j]) * (z[i]-z[j]));

  return ret;
}

int main(){
  while(1){
    cin>>n;
    if(n==0)break;

    for(int i=0;i<n;i++) {
      cin>>x[i]; cin>>y[i]; cin>>z[i]; cin>>r[i];
    }

    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	map[i][j]=maxd;
      }
      p[i]=0;
      d[i]=maxd;
      visited[i]=0;
    }
    
    for(int i=0; i<n; i++) {
      for(int j=0; j<n; j++) {
	if(i==j) continue;
	map[i][j] = compute(i, j);
	map[i][j]-=(r[i]+r[j]);
	if(map[i][j]<0)map[i][j]=0;
      }
    }


    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	//	cout<<map[i][j]<<endl;
      }
    }
    
    sumcor=0.0;
    d[0]=0.0;
    while(1){
      mn=maxd;
      for(int i=0;i<n;i++){
	if(d[i]<mn&&visited[i]==0){
	  mn=d[i];
	  t=i;
	}
      }
      if(mn==maxd)break;
      visited[t]=1;
      for(int v=0;v<n;v++){
	if(map[t][v]<d[v]&&visited[v]==0){
	  d[v]=map[t][v];
	  p[v]=t;
	}
      }
    }
    for(int i=0;i<n;i++)if(map[i][p[i]]!=maxd)sumcor+=map[i][p[i]];
    printf("%4.3f\n",sumcor);
  }
  return 0;
}

Measured memory_bytes: 1324
# B
S = input()
S_lst = []
for i in range(len(S)):
    S_lst.append(S[i])
S_lst.sort()
flag = True
for i in range(len(S)-1):
    if S_lst[i] == S_lst[i+1]:
        flag = False
if flag:
    print('yes')
else:
    print('no')

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace SandboxForAtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var line = Console.In.ReadLine();
 
            var n = int.Parse(line.Split(' ')[0]);
 
            var m = int.Parse(line.Split(' ')[1]);
 
            var line2 = Console.In.ReadLine();
 			
            var sum = 0;
 			
            var sp = line2.Split(' ');
          
            for (int i = 1; i <= m; i += 1)
            {
                sum += int.Parse(sp[i - 1]);
            }
 
 
            var rest = n - sum;
 
 
            if (rest < 0)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(rest);
            }
        }
    }
}

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

using namespace std;
typedef long long ll;
#define mp make_pair

const int N = 2e5 + 10;
bool A[N];
bool B[N];

int main() {
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);	
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		if (a == 1) 
			A[b] = true;
		if (b == 1)
			A[a] = true;
		if (a == n)
			B[b] = true;
		if (b == n)
			B[a] = true;
	}
	for (int i = 2; i < n; i++) {
		if (A[i] && B[i]) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 640
n = int(input())
A = list(map(int,input().split()))
while True:
    if A.count(0) == n - 1:
        print(max(A))
        exit()
    else:
        B = [ _  for _ in A if _ != 0  ]
        attack = min(B)
        sn = A.index(attack)
        
        for i in range(n):
            if A[i] == 0:
                pass
            else:
                if i != sn:
                    A[i] = A[i] % attack
                else:
                    pass


Measured memory_bytes: 14252
from collections import defaultdict
n = int(input())
d = defaultdict(int)
sens = set()
ans = 0
for _ in range(n):
  s = sorted(input())
  s = ''.join(s)
  if s in sens:
    d[s] += 1
    ans += d[s]
  else:
    sens.add(s)
print(ans)

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

vector<pair<long long, long long> >pre[100005];
pair<long long, long long> ans[100005];
int main(){
	long long N, M;
	cin >> N >> M;
	for(long long i = 0; i < M; i++){
		long long p, y;
		cin >> p >> y;
		pre[p].push_back(make_pair(y, i));
	}
	for(long long i = 0; i <= N; i++){
		sort(pre[i].begin(), pre[i].end());
		for(long long j = 0; j < pre[i].size(); j++){
			long long shi = pre[i][j].second;
			ans[shi] = make_pair(i, j+1);
		}
	}
	for(long long i = 0; i < M; i++){
		printf("%06ld%06ld\n", ans[i].first, ans[i].second);
	}
}


Measured memory_bytes: 8576
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int A[1000000],n;
int bs(int k){
	int left=0;
	int right=n;
	int mid;
	while(left<right){
		mid=(left+right)/2;
		if(k==A[mid]){
			return 1;
		}
		if(k>A[mid]){
			left=mid+1;
		}else if(k<A[mid]){
			right=mid;
		}
	}
	return 0;
}
int main(){
	int i,q,k,sum=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>A[i];
	}
	cin>>q;
	for(i=0;i<q;i++){
		cin>>k;
		if(bs(k)){
			sum++;
		}
	}
	cout<<sum<<endl;
	return 0;
	
}


Measured memory_bytes: 3488
#include <stdio.h>
 
int main(void)
{
	int A, B;
	
	scanf("%d %d", &A, &B);
 
	if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
		puts("Possible");
	} else {
		puts("Impossible");
	}
  
	return(0);
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;

namespace HelloWorld
{
    class Program
    {
        static void Main()
        {
            const int MAX = 50;
            string line;
            Stack<string> car = new Stack<string>(MAX);
            while ((line = Console.ReadLine()) != null)
            {
                if (line != "0")
                {
                    car.Push(line);
                }
                else
                {
                    string dep = car.Pop();
                    Console.Out.WriteLine(dep);
                }
            }
        }
    }
}


Measured memory_bytes: 16204
package main

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

func main() {
	var m = 0
	var d = -1000000000
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	var n, _ = strconv.Atoi(stdin.Text())

	for i := 0; i < n; i++ {
		stdin.Scan()
		var v, _ = strconv.Atoi(stdin.Text())
		if n == i+1 && d == 0 {
			d = v - m
		}
		if m == 0 {
			m = v
			continue
		}
		if d <= v-m {
			d = v - m
		}

		if m >= v {
			m = v
		}
	}
	fmt.Println(d)
}



Measured memory_bytes: 4164
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define ylol1 y1
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
#define codejam cout<<"Case #"<<ii+1<<": ";
#define impossible cout<<"IMPOSSIBLE"<<endl;
#define error(s) throw runtime_error(s)
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=1e14;
const int32_t LOG=21;
const int MOD=MOD1;

int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      {
         string s,t;
         cin>>s>>t;         
         if(s==t.substr(0,(int)s.length()) && s.length()+1==t.length()) 
         cout<<"Yes"<<endl;
         else
         	cout<<"No"<<endl;
      }
      return 0;                         
}

/*
 TIPS:
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/

Measured memory_bytes: 3648
from collections import deque

n,m = map(int,input().split())
graph = [[] for i in range(n)]
mark = [0]*n

for i in range(m):
    a, b = map(int,input().split())
    a -=1; b -=1
    graph[a].append(b)
    graph[b].append(a)

d = deque([0])
visited = [False]*n
visited[0] = True

while d:
    v = d.popleft()
    for i in graph[v]:
        if visited[i]:continue
        visited[i] = True
        mark[i] = v
        d.append(i)



print('Yes')

for i in mark[1:]:
    print(i+1)

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

long long A[100005], B[100005];

int main()
{
    int N;
    cin >> N;

    for(int i=1; i<=N; i++)
        cin >> A[i] >> B[i];

    long long ans = 0;

    for(int i=N; i>=1; i--)
    {
        A[i] += ans;
        ans += (A[i]/B[i]+(A[i]%B[i]>0))*B[i] - A[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int n, k;
   cin >> n >> k;
   vector<int> p(n);
   rep(i, 0, n) cin >> p[i];

   sort(all(p));
   int ans = 0;
   rep(i, 0, k) ans += p[i];
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 3616
package main

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

func convert(a int) {
	hour := a / 3600
	a = a % 3600
	minute := a / 60
	second := a % 60
	fmt.Printf("%d:%d:%d\n", hour, minute, second)
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	num, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(1)
	}
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	a := nextInt(scanner)
	convert(a)
}



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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

struct RollingHash {
  typedef tuple<ll,ll,ll> HashType;

  const ll mod1 = 999999893;
  const ll mod2 = 999999929;
  const ll mod3 = 999999937;
  const ll b1 = 3422539;
  const ll b2 = 1245103;
  const ll b3 = 22961;
  vector<ll> h1, h2, h3;
  vector<ll> pow1, pow2, pow3;

  RollingHash(const string &s) {
    const int n = s.size();
    h1.assign(n+1, 0);
    h2.assign(n+1, 0);
    h3.assign(n+1, 0);
    pow1.assign(n+1, 1);
    pow2.assign(n+1, 1);
    pow3.assign(n+1, 1);
    REP(i, n) {
      h1[i+1] = (h1[i] * b1 + s[i]) % mod1;
      h2[i+1] = (h2[i] * b2 + s[i]) % mod2;
      h3[i+1] = (h3[i] * b3 + s[i]) % mod3;
      pow1[i+1] = pow1[i] * b1 % mod1;
      pow2[i+1] = pow2[i] * b2 % mod2;
      pow3[i+1] = pow3[i] * b3 % mod3;
    }
  }

  HashType get(int l, int r) const {
    ll v1 = ((h1[r] - h1[l] * pow1[r-l]) % mod1 + mod1) % mod1;
    ll v2 = ((h2[r] - h2[l] * pow2[r-l]) % mod2 + mod2) % mod2;
    ll v3 = ((h3[r] - h3[l] * pow3[r-l]) % mod3 + mod3) % mod3;
    return HashType {v1, v2, v3};
  }
};


bool possible(const RollingHash& r, const int N, const int L) {
  set<RollingHash::HashType> ex;
  for (int i = N - L; i >= 0; i--) {
    if (i + L + L <= N) {
      ex.insert(r.get(i+L, i+L+L));
    }
    auto h = r.get(i, i+L);
    if (ex.count(h) > 0) return true;
  }
  return false;
}

int main2() {
  int N; cin >> N;
  string S; cin >> S;

  RollingHash r(S);

  int lo = 0;
  int hi = N/2 + 1;
  while (hi - lo > 1) {
    int mid = (hi + lo) / 2;
    if (possible(S, N, mid)) {
      lo = mid;
    } else {
      hi = mid;
    }
  }

  cout << lo << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 1076
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int r;
	cin>>r;
    if(r<1200) cout<<"ABC"<<endl;
    else if(1200<=r&&r<2800) cout<<"ARC"<<endl;
    else  if(r>=2800) cout<<"AGC"<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	var max, cnt int
	for _, v := range s {
		if v == 'A' || v == 'T' || v == 'C' || v == 'G' {
			cnt++
		} else {
			cnt = 0
		}
		if cnt > max {
			max = cnt
		}
	}
	fmt.Println(max)
}


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

using namespace std;

#define ll unsigned long long

const int mod  = 1e9 + 7;
const ll INF = 1e14;

void solve(){

    char c; cin >> c;
    cout << (c & (1<<5) ? 'a' : 'A');

}


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

	return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define mod         (ll)1000000007
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = (ll)1e18;
ld pi = 3.141592653589;
using namespace std;

ll bpow(ll x, ll v) {	
	if (v == 0)
		return 1 % mod;
	if (v % 2 == 1)
		return (x * bpow(x, v - 1)) % mod;
	ll r = bpow(x, v / 2);
	return (r * r) % mod;	
}

ll lcm(ll a,ll b)
{
	ll ret=(a*b)/__gcd(a,b);
	return ret;
} 

ll solve(){ 
	ll n,a,b; cin>>n>>a>>b;
	if(a==0) {cout<<0; return 0;}
	ll d = a+b;
	ll ans = (n/d)*a;
	ans+= min(a,n%d);
	cout<<ans;
}
int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
    	solve();
    }
}

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

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

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

int main() {
  int N, M;
  std::cin >> N >> M;

  std::vector<int> a(M + 1, 0);
  std::vector<int> c(M + 1, 0);
  rep(i, M) {
    int b;
    std::cin >> a[i + 1] >> b;
    rep(j, b) {
      int tmp;
      std::cin >> tmp;
      c[i + 1] |= 1 << (tmp - 1);
    }
  }

  const int MAX_STATE = 1 << N;
  const int TARGET = MAX_STATE - 1;

  std::vector<std::vector<int>> dp(M + 1, std::vector<int>(MAX_STATE, INF));
  rep(i, M + 1) dp[i][0] = 0;
  for(int i = 0; i < M; ++i) {
    for(int s = 0; s < MAX_STATE; ++s) {
      dp[i + 1][s] = std::min(dp[i + 1][s], dp[i][s]);
      int tmp = std::min(dp[i][s | c[i + 1]], dp[i][s] + a[i + 1]);
      dp[i + 1][s | c[i + 1]] = std::min(dp[i + 1][s | c[i + 1]], tmp);
    }
  }

  int ans = dp[M][TARGET];
  if(ans < INF) {
    std::cout << ans << '\n';
    return 0;
  }
  std::cout << -1 << '\n';
}


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

int main() {
  int N;
  string Si;
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> Si;
    
    if (Si == "Y"){
      cout << "Four" << endl;
      break;
    }
  }
  
  if (Si == "P" || Si == "W" || Si == "G"){
    cout << "Three" << endl;
  }
  

}

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

int n, h1, h2, hl, s, m;

int main(){
	cin >> n;
	s = m = h1 = hl = 0;
	for (int i = 0; i <= n; ++i){
		if (i < n) cin >> h2;
		else h2 = 0;
		if ((m > h1 && h2 > h1) || i == n){
			s += m - hl;
			hl = h1;
			m = 0;
		}
		if (m < h2) m = h2;
		h1 = h2;
	}
	cout << s;
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 1e18+1
const ll mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
   ll a,b;
   cin>>a>>b;
   cout<<a*b<<endl;
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

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

using namespace std;


string s, t;
int lcs[4010][4010];
int main() {
	while (cin >> s >> t)
	{
		lcs[0][0] = 0;
		for (int i = 0; i < s.size(); i++) {
			for (int j = 0; j < t.size(); j++) {
				if (s[i] == t[j]) {
					lcs[i+1][j+1] = lcs[i][j] + 1;
				}
				else {
					lcs[i + 1][j + 1] = 0;
				}
			}
		}


		int ans = 0;
		for (int i = 1; i <= s.size(); i++) {
			for (int j = 1; j <= t.size(); j++) {
				ans = max(ans, lcs[i][j]);
			}
		}


		cout << ans << endl;
		
	}

	return 0;
}



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

int gcd(int a, int b) {
  return b == 0 ? a : gcd(b, a%b);
}

int main() {
  string line;
  int Tc;
  cin >> Tc;
  cin.ignore();
  while(Tc--) {
    getline(cin, line);
    for(int a = 1; a < 26; ++a) {
      for(int b = 0; b < 26; ++b) {
	if(gcd(a, 26) != 1) continue;
	string t = line;
	for(int i = 0; i < t.size(); ++i) {
	  if(isalpha(t[i])) {
	    int r = t[i] - 'a';
	    t[i] = (a*r+b)%26+'a';
	  }
	}
	if(t.find("that") != string::npos ||
	   t.find("this") != string::npos) {
	  cout << t << endl;
	  a = b = (1<<28);
	  break;
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (ll)max({a * c, a * d, b * c, b * d}); 
}
int main() {
    solve();
    return 0;
}

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

class Cmondai
{
    static void Main()
    {
        var nq = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var N = nq[0];
        var Q = nq[1];
        var S = Console.ReadLine();
        var array = new int[S.Length];
        array[0] = 0;
        var count = 0;
        for (int i=0;i<S.Length-1;++i)
        {
            if (S[i] == 'A' && S[i + 1] == 'C')
            {
                count++;
            }
            array[i+1] = count;
        }
        for (int i=0;i<Q;++i)
        {
            var lr = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
            var l = lr[0];
            var r = lr[1];
            var ans = array[r - 1] - array[l - 1];
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 18496
#include <bits/stdc++.h>
#include <cstring>
#include <map>
#include <set>
#define int long long int
#define cons 1000000007 
using namespace std;
 
 
signed main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
 
    int n, i, c=0, ss=1;
    cin>>n;
    string s[n];
    for(i=0;i<n;i++){
        cin>>s[i];
        sort(s[i].begin(), s[i].end());
    }
    sort(s, s+n);
    for(i=0;i<n-1;i++){
        if(s[i]==s[i+1]){
            c+=ss;
            ss++;
        }
        else{
            ss=1;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 5760
n, m = map(int, input().split())
MOD = 1000000007
 
def fac(n):
    ans = 1
    for i in range(1, n + 1):
        ans = (ans * i) % MOD
    return ans
 
if abs(m - n) > 1:
    print(0)
elif m == n:
    print((2 * fac(m) * fac(n)) % MOD)
else:
    print((fac(m) * fac(n)) % MOD)

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

using namespace std;

#define int long long

void solve() {
    int k, q;
    cin >> k >> q;
    int d[k];
    for (int i = 0; i < k; ++i) cin >> d[i];
    while (q) {
        --q;
        int n, x, m;
        cin >> n >> x >> m;
        --n;
        int sum = 0, nols = 0;
        for (int j = 0; j < k; ++j) {
            sum += d[j] % m;
            if (d[j] % m == 0) ++nols;
        }
        x %= m;
        x += (n / k) * sum;
        nols *= (n / k);
        for (int j = 0; j < (n % k); ++j) {
            x += d[j] % m;
            if (d[j] % m == 0) ++nols;
        }
        cout << n - x / m - nols << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int a[6];
    int n,m,x,y;
    int result,flag=0;
    memset(a,0,sizeof(a));
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        if(x>n)
            flag=1;
        if(n>1&&x==1&&y==0)
            flag=1;
        if(a[x]!=0&&a[x]!=y)
            flag=1;
        a[x]=y;
    }
    if(n==3)
        result=a[1]*100+a[2]*10+a[3]+(a[1]==0)*100;
    if(n==2)
        result=a[1]*10+a[2]+(a[1]==0)*10;
    if(n==1)
        result=a[1];
    if(flag)
        cout<<-1<<endl;
    else
        cout<<result<<endl;
    return 0;
}

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

int main() {
  int N, K, x, y;
  cin >> N >> K;
  
  y = 0;
  for (int i = 0; i < N; i ++) {
    cin >> x;
       
    if (abs (K - x) <= abs (x)) {
      y += abs (K - x) * 2;
    }
    
    else if (abs (K - x) > abs (x)) {
      y += abs (x) * 2;
    }
  }
  
  cout << y << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
    int n,d,r,x,y,ans=0;
    cin>>n>>d;
    d=d*d;
    while(n--){
        cin>>x>>y;
        r=x*x+y*y;
        if(r<=d)ans++;
    }cout<<ans;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    long long a,b,c,d,f;
    cin>>a>>b>>c>>d;
    f=0;
    while (a>0 && c>0)
    {
    	if (f==0)
    	{
    		f=1;
    		c=c-b;
		}
		else
		{
			a=a-d;
			f=0;
		}
	}
	if (a>0)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define nn 2008
#define lf double
#define mp make_pair
#define ll long long
#define err {puts("No");exit(0);}
#define pii pair<int,int>
vector<int> ops;
vector<int> v[nn];
int vis[nn];int leaf[nn];int prio[nn];
int need[nn];int pa[nn];int dep[nn];
int n;int col[nn];int leaves;
int fullfill[nn];
void dfs(int x)
{
	leaf[x]=2;
	for(int i=0;i<v[x].size();i++)
	{
		if(vis[v[x][i]]==2) continue;
		dep[v[x][i]]=dep[x]+1;
		leaf[x]--;
		dfs(v[x][i]);
		if(!leaf[v[x][i]]) leaf[x]=0;
	}
	leaf[x]=max(leaf[x],0);
	if(leaf[x]) need[x]=1,leaves++;
}
void pushtree(int x)
{
	ops.push_back(x);
	int y=pa[x];int bef=col[x];col[x]=col[1];
	while(y)
	{
		swap(bef,col[y]);
		y=pa[y];
	}
//	for(int i=1;i<=n;i++) cout<<col[i];cout<<";\n";
}
pair<int,int> bst;int thrown[nn];
void findbst(int x)
{
	// return ;
	for(int i=0;i<v[x].size();i++)
	{
		if(vis[v[x][i]]==2) continue;
		findbst(v[x][i]);
	}
	if(prio[col[x]] or thrown[col[x]]) ; 
	else bst=max(bst,make_pair(dep[x],x));
	return;
}
int stretch(int x,int t)
{
	while(t--)
	{
		for(int i=0;i<v[x].size();i++)
		{
			if(vis[v[x][i]]!=2)
			{
				x=v[x][i];
				break;
			}  
		}
	}
	return x;
}
int count(int x)
{
	int o=x;
	x=stretch(x,2000);
	while(1)
	{
		if(prio[col[x]]==0 or (dep[col[x]]<dep[o]))
		{
			return x;
		}
		x=pa[x];
	}
}
int loc[nn];
int main()
{
	cin>>n;
	for(int i=2;i<=n;i++)
	{
		cin>>pa[i];
		pa[i]++;
		v[pa[i]].push_back(i);
	}
	for(int i=1;i<=n;i++) cin>>col[i],col[i]++;
//	for(int i=1;i<=n;i++) col[i]=loc[i];
	while(1)
	{
		if(vis[1]) break ;
		leaves=0;dfs(1);
		memset(thrown,0,sizeof(thrown));
		while(leaves)
		{
			if(need[col[1]])
			{
				leaves--;
				int t=count(col[1]);
				int x=col[1];
				vis[x]=1;prio[x]=1;
				pushtree(t);
			}
			else
			{
				bst=make_pair(0,0);
				findbst(1);thrown[col[1]]=1;
				pushtree(bst.second);
			}
		}
		int tt=0;
		for(int i=1;i<=n;i++) if(vis[i]) vis[i]=2,tt++;//else cout<<i<<" ";
		if(tt==n) break;//system("pause");
	}
	cout<<ops.size()<<"\n";
//	reverse(ops.begin(),ops.end());
	for(int i=0;i<ops.size();i++) printf("%d\n",ops[i]-1);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a[150],zd,zx,ans;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    zd=zx=a[0];
    for(int j=1;j<n;j++)
    {
        zd=max(zd,a[j]);
        zx=min(zx,a[j]);
    }
    ans=zd-zx;
    cout<<ans<<endl;
    return 0;
}


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

#define int 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; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

signed main(){
    int a,b; cin >> a >> b;
    int res=INF;
    rep(i,1500){
        if(floor(i*0.08)==a && floor(i*0.1)==b){
            cout<< i<<endl;
            return 0;
        }
    }
    
    cout<<-1<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LOCAL
#pragma region Macros
typedef long long ll;
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<ll> L(N); cin >> L;
    sort(ALL(L));
    int ans=0;
    for (int i=0;i<N;++i){
        for (int j=i+1;j<N;++j){
            for (int k=j+1;k<N;++k){
                if (L[i]!=L[j]&&L[j]!=L[k]&&L[i]+L[j]>L[k]){
                    ++ans;
                }
            }
        }
    }
    cout << ans << '\n';
}

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

int main() {
  string s; cin >> s;
  int A[s.size()]; 
  for (int i = 0; i < s.size(); i++) A[i] = s[i] - '0';
  
  long long sum = 0;
  long long currentSum = 0;
  long long current = A[0];
  
  for (int i = 0; i < pow(2, (s.size() - 1)); i++) {
    for (int j = 0; j < s.size() - 1; j++) {
      if (i & (1 << j)) {
        currentSum += current;
        current = A[j + 1];
      } else {
        current = current * 10 + A[j + 1];
      }
    }
    currentSum += current;
    sum += currentSum;
    current = A[0];
    currentSum = 0;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
//#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007
//#define N 12
#define sz 1000*1000

 int main(){

 int n; cin>>n;
 vector<int>v(n+10),y(n+10);

 for(int i=0;i<n;i++){
            cin>>v[i];
          y[i] = v[i];
 }


 sort(y.begin(),y.begin()+n); // used to sort only first n elements of the vector
  int mid = n/2;

  for(int i=0;i<n;i++){
      if(v[i] >= y[mid])
            cout<<y[mid-1]<<endl;
      else
            cout<<y[mid]<<endl;
  }

 return 0;
 }


Measured memory_bytes: 4844
#include<stdio.h>
int main(){
	int t,i,book;
	for(;;){
		scanf("%d",&t);
		if(t==0)break;
		for(i=0;i<9;i++){
			scanf("%d",&book);
			t-=book;
		}
		printf("%d\n",t);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define db double
const int mod = 1e9+7;
const int maxn = 4e6+5;
const double eps = 1e-6;
using namespace std;
bool eq(const db &a,const db &b){
	return fabs(a-b)<eps;
}

bool ls(const db &a,const db &b){
	return a+eps<b;
}

bool le(const db &a,const db &b){
	return eq(a, b)||ls(a, b);
}

ll kpow(ll a,ll b){
	ll res=1;
	a%=mod;
	assert(b>=0);
	for(;b;b>>=1){
		if(b&1)res=res*a%mod;
		a=a*a%mod;
	}
	return res;
}

bitset<maxn> bt;
int main(){
	int n,a,sum = 0;
	scanf("%d",&n);
	bt[0]=1;
	rep(i,0,n){
		scanf("%d",&a);
		bt|=bt<<a;
		sum+=a;
	}
	rep(j,(sum+1)/2,sum+1)
		if(bt[j]) return printf("%d",j),0;
	return 0;
}

Measured memory_bytes: 1664
n, k = [int(_) for _ in input().split()]
dict = {}
for i in range(0, n):
    ai, bi = [int(_) for _ in input().split()]
    if ai in dict:
        dict[ai] += bi
    else:
        dict[ai] = bi

sorted_list = sorted(dict.items(), key=lambda x: x[0])

total = 0
for i in range(0, len(sorted_list)):
    total += sorted_list[i][1]
    if total >= k:
        print(sorted_list[i][0])
        break


Measured memory_bytes: 15076
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=2e5+5,OO=1e9;

int t[N*4],mod[N*4];
int sh=1;
void apply(int v,int x){ 
    if(x==-1)return;
    t[v]=x; //<--
    mod[v]=x; //<--
}
void push(int v,int tl,int tr){//tl,tr мб не надо
    if(mod[v]!=-1){
        apply(v+v,mod[v]);
        int tm=(tl+tr)/2;
        apply(v+v+1,mod[v]+(tm-tl+1));
        mod[v]=-1; //<--
    }
}
void recalc(int v){
    t[v]=min(t[v+v],t[v+v+1]); //<--
}
void build(int n){
    while(sh<n)sh*=2;
    forn(i,sh+sh)t[i]=OO;//<--
    forn(i,n)t[i+sh+1]=0;
    forn(i,sh+sh)mod[i]=-1;//<--
    for(int i=sh-1;i>0;--i)recalc(i);
}
int get(int v,int tl,int tr,int l,int r){
    if(l>tr||r<tl)return OO;//<--
    if(l<=tl&&tr<=r)return t[v];
    push(v,tl,tr);
    int tm=(tl+tr)/2;
    int res=OO; //<--
    if(tm>=l)upn(res,get(v+v,tl,tm,l,r)); //<--
    if(tm+1<=r)upn(res,get(v+v+1,tm+1,tr,l,r)); //<--
    return res;
}
void put(int v,int tl,int tr,int l,int r,int val){
    if(l<=tl&&tr<=r){
        apply(v,val+tl-l);
        return;
    }
    push(v,tl,tr);
    int tm=(tl+tr)/2;
    if(tm>=l)put(v+v,tl,tm,l,r,val);
    if(tm+1<=r)put(v+v+1,tm+1,tr,l,r,val);
    recalc(v);
}
void put(int l,int r,int val){
    put(1,0,sh-1,l,r,val);
}
int get(int l,int r){
    return get(1,0,sh-1,l,r);
}


int32_t main(){

    int h,w;
    cin>>h>>w;
    build(w+1);
    for(int i=1;i<=h;++i){
        int l,r;
        cin>>l>>r;
        put(l,r,OO);
        int res=get(1,w);
        if(res==OO)res=-i-1;
        cout<<res+i<<'\n';
        int f=get(l-1,l-1);
        put(l,r,f+1);
    }

    return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> snuke(n);
    rep(i,k) {
        int d;
        cin >> d;
        rep(j,d) {
            int a;
            cin >> a;
            a--;
            snuke[a]++;
        }
    }
    int ans = 0;
    rep(i,n) {
        if (snuke[i] == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
import java.util.Arrays;
import java.util.Scanner;



public class Main{
	public static void main(String[] args) throws Exception {
		try(Scanner sc = new Scanner(System.in)) {

			int N = sc.nextInt();
			while(N-->0) {

				//家と家の距離感が長いものは結ばなくていい
				int n = sc.nextInt();
				int k = sc.nextInt();
				k--;
				int[] s = new int[n-1];
				int x = sc.nextInt();
				int pre = x;

				for(int i=1; i<n; i++) {
					x = sc.nextInt();
					s[i-1] = x - pre;
					pre = x;
				}
				Arrays.sort(s);
				long ans = 0;

				for(int i=0; i<s.length - k; i++) {
					ans += s[i];
				}
				System.out.println(ans);

			}
		}
	}
}




Measured memory_bytes: 101876
import math
n = int(input())
s = math.ceil(math.sqrt(n))
tmp = []
for i in range(2,s+1):
    if n%i == 0:
        m = max(i, n//i)
        tmp.append(int(math.log10(m))+1)
if len(tmp) == 0:
    print(int(math.log10(n))+1)
else:
    print(min(tmp))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  ll A, B, C, K; std::cin >> A >> B >> C >> K;
  if ( A >= K ) std::cout << K << std::endl;
  else {
    ll rest = K - A;
    if ( B >= rest ) std::cout << A << std::endl;
    else {
      ll r = rest - B;
      ll cmin = std::min<ll>(r, C);
      std::cout << A - cmin << std::endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
const int INF = 1e9;
const ll LLINF = 1e16;

int main(void)
{
    ll x;
    cin >> x;
    ll n = 0;
    ll m = 100;
    while(m < x){
        m *= 1.01;
        n++;
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>

using namespace std;

int main()
{
	int a, b, c;
	int nums[3];
	int cnt = 0;
	cin >> nums[0] >> nums[1] >> nums[2];
	sort(nums, nums + 3);
	
	while (nums[1] != nums[2]) {
		nums[0]++;
		nums[1]++;
		cnt++;
	}
	if ((nums[2] - nums[0]) % 2 == 0) {
		cnt += (nums[2] - nums[0]) / 2;
	}
	else {
		cnt += (nums[2] - nums[0]) / 2;
		cnt += 2;
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n;
  cin >> n;

  int cnt = 0;
  rep(i,n)
  {
    cnt += i + 1;
  }

  cout << cnt << endl;

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

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

map<int, int> h;

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int a, i = 0; i < n; ++i) {
    scanf("%d", &a);
    ++h[a];
  }
  if ((int)h.size() <= k) return !printf("0");
  vector<int> v;
  for (auto it = h.rbegin(); it != h.rend(); it++)
    v.push_back(it->second);
  int ans = 0, dif = h.size()-k;
  sort(v.begin(), v.end(), greater<int>());
  while (dif--) {
    ans += v.back();
    v.pop_back();
  }

  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 10748
#include<map>
#include<cstdio>

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

using namespace std;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
struct P{ int x,y; P(){} P(int X,int Y):x(X),y(Y){} };

map<int,int> dp[24];
int adj[24][4][23],deg[24][4],house_num;

int dfs(int id,int picked){
	if(dp[id].find(picked)!=dp[id].end()) return dp[id][picked];

	if(picked==(1<<(house_num+1))-1){
		rep(k,4) rep(a,deg[id][k]) if(adj[id][k][a]==house_num) return 1;
		return 0;
	}

	int ans=0;
	rep(k,4) rep(a,deg[id][k]) {
		int next_id=adj[id][k][a];
		if((picked&(1<<next_id))==0){
			ans+=dfs(next_id,picked|(1<<next_id));
			break;
		}
	}

	if(dp[id].size()<50000) dp[id][picked]=ans;
	return ans;
}

int main(){
	for(int n,m;scanf("%d%d",&n,&m),n;){
		int field[10][10],charch_x,charch_y,f[10][10];
		house_num=0;
		rep(i,m) rep(j,n) {
			scanf("%d",field[i]+j);
			if(field[i][j]==1) f[i][j]=house_num++;
			if(field[i][j]==2) charch_x=j,charch_y=i;
		}
		f[charch_y][charch_x]=house_num;

		rep(i,m) rep(j,n) if(field[i][j]!=0) {
			int id=f[i][j];
			dp[id].clear();
			rep(k,4){
				deg[id][k]=0;
				int x=j+dx[k],y=i+dy[k];
				while(0<=y && y<m && 0<=x && x<n){
					if(field[y][x]!=0) adj[id][k][deg[id][k]++]=f[y][x];
					x+=dx[k],y+=dy[k];
				}
			}
		}

		printf("%d\n",dfs(house_num,1<<house_num));
	}

	return 0;
}

Measured memory_bytes: 32000
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b;
	while(cin>>a>>b){
	int t=8650;
	for(int i=t;i;i--){
		for(int j=i;j;j--){
			if(i+j==2)a+=b;
		}
	}
	int cnt=0;
	while(a)a/=10,cnt++;
	cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 2992
N = int(input())
S = input()
#左からスタートするとして，全てWならば0になるため
E_count = S.count('E')
W_count = 0
mini_count = E_count

for i in S:
  if i == 'E':
    #リーダーはどちらを向いていても良いので1を引く
    E_count -= 1
  else:
    #Wの場合は，今後向きを変えてもらう必要があるため
    W_count += 1
  if mini_count > E_count + W_count:
    mini_count = E_count + W_count
print(mini_count)

Measured memory_bytes: 3700
#include <stdio.h>
int main(){
 
  int i=0,j=0,x=0;
  char ch,p[101]={},s[101]={};
 
  //input p
  while(1){
 
    scanf("%c",&ch);
 
    if(ch != '\n'){
 
      p[i]=ch;
 
      i++;
 
    } else {
 
      break;
 
    }
 
  }
 
  i=0;
 
  //input s
  while(1){
 
    scanf("%c",&ch);
     
    if(ch != '\n'){
 
      s[i]=ch;
 
      i++;
 
    } else {
 
      break;
 
    }
 
  }
 
  i=0;
   
  //search
  while(1){
 
    if(s[j] != '\0'){
       
      if(p[i] != '\0'){
     
    if(p[i] == s[j]){
       
      i++;
      j++;
       
    } else {
 
      if(i == 0 && j != 0){
 
        printf("No\n");
 
        break;
 
      } else {
 
      x++;
      i=x;
      j=0;
 
      }
       
    }   
     
      } else {
 
    if(j != 0){
 
      i=0;
 
    } else {
 
      printf("No\n");
 
      break;
 
    }
 
      }
       
    } else {
 
      printf("Yes\n");
 
      break;
 
    }
 
  }
 
  return 0;
   
}


Measured memory_bytes: 2112
#include <stdio.h>
#include <math.h>
int main(){
	int n,d,a[11][11]={0},t=0;
	scanf("%d%d",&n,&d);
	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			float sum=0;
			for(int k=0;k<d;k++){
				sum=sum+pow(a[i][k]-a[j][k],2);
			}
		 	int c=(int)sqrt(sum),m=(int)(sqrt(sum)+0.999999);
			if(c==m)t++;
		}	
	}
	printf("%d",t);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>

using namespace std;
using llong = long long;
using ullong = unsigned long long;

vector<ullong> divisors(ullong n) {
    vector<ullong> res;
    for(ullong i = 1; i*i <= n; ++i) {
        if(n % i != 0) continue;
        res.push_back(i);
        if(n/i == i) continue;
        res.push_back(n/i);
    }
    sort(res.begin(),res.end());
    return res;
}

bool isprime(ullong num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; 

    for (ullong i = 3; i*i <= num; i += 2){
        if (num % i == 0){
            return false;
        }
    }
    return true;
}
int main() {
  ullong A,B;
  cin >> A >> B;
  auto divA = divisors(A);
  auto divB = divisors(B);

  vector<ullong> interAB;
  set_intersection(divA.begin(), divA.end()
      , divB.begin(), divB.end()
      , inserter(interAB, interAB.end()));
  ullong cnt = 1;
  for(auto ab:interAB) {
    if( isprime(ab) ) cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 512