akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int cnt = 0;
  char c = 'N';
  for(int i = 0;i < s.size();i++){
    if(c != s[i]){
      cnt++;
      c = s[i];
    }
  }
  cout << cnt - 1 << endl;
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#define MAX 1000000007
int main(void){
    // Your code here!
    
    char tap[101];
    
    scanf("%s",&tap);
    int i;
    int flag = 0;
    for(i=0;100>i;i++){
        if((i+1)%2==0){
            if(tap[i]=='R'){
                flag = 1;
                break;
            }
            else if(tap[i]==NULL) break;
        }
        else{
            if(tap[i]=='L'){
                flag = 1;
                break;
            }
            else if(tap[i]==NULL) break;
        }
    }
    
    if(flag) printf("No\n");
    else     printf("Yes\n");

    
    return 0;
}


Measured memory_bytes: 128
N, M = map(int, input().split());
A = [[] for i in range(N+1)];
B = [0] * M;
SUM = 0;
for i in range(N):
    sum = 0;
    A[i] = list(map(int, input().split()));
    for j in range(M):
        sum = sum + A[i][j];
        B[j] = B[j] + A[i][j];
        print(A[i][j], end=" ");
    print(sum);
    SUM = SUM + sum;
for k in range(M):
    print(B[k], end=" ");
print(SUM);



Measured memory_bytes: 5728
import math
n,d=map(int,input().split())
zahyou=[]
for i in range(n):
    point=[]
    for i in input().split():
        point.append(int(i))
    zahyou.append(point)

ans=0
for i1 in range(n-1):
    for i2 in range(i1+1,n):
        p1=zahyou[i1]
        p2=zahyou[i2]
        dist=0
        for i in range(d):
            tmp = (p1[i]-p2[i])**2
            dist+=tmp
        dist=math.sqrt(dist)
        if dist==int(dist):
            ans+=1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define INF 1000000000
#define CL(x) memset(x,0,sizeof(x))
#define DEB(x) cout << #x << " : " << x << '\n'
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
#define UI(x) (int)(x-'A')
#define LI(x) (int)(x-'a')
typedef long long ll;

#define MXN 1005
typedef pair<pdd,double> ddd;
int N;
ddd pt[MXN];
double d[MXN];

double dis(int i, int j)
{
    double dx = pt[i].f.f-pt[j].f.f, dy = pt[i].f.s-pt[j].f.s;
    double pd = sqrt(dx*dx+dy*dy);
    double rs = pt[i].s+pt[j].s;
    return max(0.0,pd-rs);
}

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

    cin>>pt[1].f.f>>pt[1].f.s;
    pt[1].s=0;
    cin>>pt[2].f.f>>pt[2].f.s;
    pt[2].s=0;

    cin>>N;
    int P = N+2;

    FOR(i,3,P)
    {
        cin>>pt[i].f.f>>pt[i].f.s>>pt[i].s;
    }

    d[1]=0;
    FOR(i,2,P)d[i]=1e10;
    typedef pair<double,int> pdi;
    priority_queue< pdi, vector<pdi>, greater<pdi> > pq;
    pq.push( mkp(0,1) );

    while(!pq.empty())
    {
        int u = pq.top().s;
        double nd = pq.top().f;
        pq.pop();
        if(nd!=d[u])continue;
        if(u==2)break;

        FOR(i,1,P)
        {
            double dui = dis(u,i);
            if( nd+dui<d[i] )
            {
                d[i]=nd+dui;
                pq.push(mkp(d[i],i));
            }
        }
    }

    cout<<fixed<<setprecision(10)<<d[2]<<'\n';

    return 0;
}


Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
typedef pair<int,int> pii;
typedef long long ll;	

ll n,arr[200005],sum;


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

	
	cin >> n;
	for (int i=0;i<n;i++){
		cin >> arr[i];
	}
	for (int i=1;i<n;i++){
		if (arr[i] < arr[i-1]){
			sum += arr[i-1]-arr[i];
			arr[i] = arr[i-1];
		}
	}
	cout << sum << "\n";
	return 0;
}

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

using namespace std;

int n, m;
vector<pair<int, int>> edges;
vector<int> pset, comp;
vector<long long> ans;
long long cnt;

int findSet(int i) {
    return (pset[i] == i) ? i : (pset[i] = findSet(pset[i]));
}

void unionSet(int i, int j) {
    int p = findSet(i), q = findSet(j);
    if (p == q) return;

    cnt -= 1LL * comp[p] * comp[q];
    pset[p] = q;
    comp[q] += comp[p];
}

int main() {
    scanf("%d%d", &n, &m);

    edges.resize(m);
    for(int i = 0; i < m; ++i) {
        scanf("%d%d", &edges[i].first, &edges[i].second);
        --edges[i].first;
        --edges[i].second;
    }

    pset.resize(n);
    for(int u = 0; u < n; ++u)
        pset[u] = u;
    comp.assign(n, 1);

    cnt = 1LL * n*(n-1)/2;

    ans.push_back(cnt);
    for(int i = m-1; i >= 0; --i) {
        unionSet(edges[i].first, edges[i].second);
        ans.push_back(cnt);
    }

    for(int i = m-1; i >= 0; --i)
        printf("%lld\n", ans[i]);

    return 0;
}


Measured memory_bytes: 3828
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

map<set<pair<int, int>>, int>mp;

int main() {
	mp[set<pair<int, int>>{make_pair(0, 0), make_pair(0, 1), make_pair(0, 2), make_pair(0, 3)}] = 1;
	mp[set<pair<int, int>>{make_pair(0, 0), make_pair(0, 1), make_pair(1, 1), make_pair(1, 0)}] = 0;
	mp[set<pair<int, int>>{make_pair(0, 0), make_pair(1, 0), make_pair(2, 0), make_pair(3, 0)}] = 2;
	mp[set<pair<int, int>>{make_pair(0, 1), make_pair(1, 0), make_pair(0, 2), make_pair(1, 1)}] = 3;
	mp[set<pair<int, int>>{make_pair(0, 0), make_pair(1, 0), make_pair(2,1), make_pair(1, 1)}] = 4;
	mp[set<pair<int, int>>{make_pair(0, 0), make_pair(0, 1), make_pair(1, 1), make_pair(1, 2)}] = 5;
	mp[set<pair<int, int>>{make_pair(1, 0), make_pair(0, 1), make_pair(1, 1), make_pair(2, 0)}] = 6;
	vector<string>sts(8);
	while (cin >> sts[0]) {
		for (int i = 1; i < 8; ++i)cin >> sts[i];
		int minx = 10;
		int miny = 10;
		
		for (int i = 0; i < 8; ++i) {
			for (int j = 0; j < 8; ++j) {
				if (sts[i][j] == '1') {
					minx = min(minx, j);
					miny = min(miny, i);
				}
			}
		}
		set<pair<int, int>>ps;
		for (int i = 0; i < 8; ++i) {
			for (int j = 0; j < 8; ++j) {
				if (sts[i][j] == '1') {
					ps.emplace(j - minx, i - miny);
				}
			}
		}
		if (mp.find(ps) == mp.end())assert(false);
		cout <<char( 'A' + mp[ps]) << endl;
	}
	return 0;
}

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

int main() {
  int h,w; cin>>h>>w;
  graph v(h,vector<char>(w));
  rep(i,h){
    rep(j,w){cin>>v[i][j];}
  }
  int i=0,j=0;
  bool b=true;
  while(true){
    if(i!=0){
      if(v[i-1][j]=='#'){b=false; break;}
    }
    if(j!=0){
      if(v[i][j-1]=='#'){b=false; break;}
    }
    if(i!=h-1&&j!=w-1){
      if((v[i][j+1]=='#'&&v[i+1][j]=='#')
         ||(v[i][j+1]=='.'&&v[i+1][j]=='.')){b=false; break;}
    }
    if(i==h-1 && j==w-1){break;} 
    bool d=false;
    if(i!=h-1){
      if(v[i+1][j]=='#'){v[i][j]='.'; i++;d=true;}
    }
    if(!d && j!=w-1){
      if(v[i][j+1]=='#'){v[i][j]='.'; j++;}
    }
  }
  if(b)cout<<"Possible";
  else{cout<<"Impossible";}
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
#include <bitset>
#include <string>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)


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

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

int main() {
    int N, i; cin >> N >> i;
    
    cout << N+1-i << endl;

    return 0;
}


Measured memory_bytes: 256
import numpy as np

N, L = map(int, input().split())

taste = np.arange(1, N+1) + L -1
min_ind = np.argmin(np.abs(taste))

mask_1 = np.ones(N, dtype=bool)
mask_1[min_ind] = False

ans = np.sum(taste[mask_1])

print(ans)


Measured memory_bytes: 27244
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int A = s.nextInt(), B = s.nextInt(), C = s.nextInt();
        int temp = A;
        A = B; B = temp;
        temp = A; A = C; C = temp;
        System.out.println(A + " " + B + " " + C);
    }
}

Measured memory_bytes: 23636
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n, t, s;
    cin >> n >> t >> s;

    vector<int> dp(t+1, 0);

    while(--n >= 0){
        int a, b;
        cin >> a >> b;

        for(int i=t; i>=0; --i){
            int x = i + b;
            if(i < s && i+b > s)
                x = s + b;
            if(x > t)
                continue;
            dp[x] = max(dp[x], dp[i] + a);
        }
    }

    int ret = *max_element(dp.begin(), dp.end());
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 0
import Foundation

extension String {
    func split(separator: String) -> [Int] {
        return self.componentsSeparatedByString(separator).map { Int($0)! }
    }
}

let input = readLine()!.split("/")
let month = input[1]

var result = "TBD"
if month <= 4 {
    result = "Heisei"
}

print(result)

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

int main(){
  int n;
  cin>>n;
  for(int i=1;i*(i-1)<=2*n;i++){
    if(i*(i-1)==2*n){
      cout<<"Yes"<<endl;
      cout<<i<<endl;
      vector<vector<int>> s(i);
      int p=1;
      for(int j=0;j<i-1;j++){
        for(int k=j+1;k<i;k++){
          s[j].pb(p);
          s[k].pb(p);
          p++;
        }
      }
      rep(j,i){
        cout<<i-1<<" ";
        rep(k,i-1) cout<<s[j][k]<<" ";
        cout<<endl;
      }
      return 0;
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 4248
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
const int maxn = 1e3+10;
const int maxm = 1e4+10;
const int INF = 1e9;
int n,h;
int a[maxn],b[maxn];
int dp[2*maxm];
int main()
{
	scanf("%d%d",&h,&n);
	for(int i=1;i<=n;i++)
	scanf("%d%d",&a[i],&b[i]);
	dp[0]=0;
	for(int i=1;i<=20000;i++) dp[i]=INF;
	for(int i=0;i<=20000;i++)
		for(int j=1;j<=n;j++)
		{
			if(i<a[j]) continue;
			dp[i]=min(dp[i],dp[i-a[j]]+b[j]);
		}
	int ans=INF;
	for(int i=h;i<=20000;i++) ans=min(ans,dp[i]);
	printf("%d",ans);
	return 0;
}

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

int main(){
   int W,H,x,y,r;
   cin >> W >> H >> x >> y >> r;

   if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H){
       cout << "Yes" << endl;
   }else{
       cout << "No" << endl;
   }

return 0;
}


Measured memory_bytes: 3096
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void run() {
		int n, q;
		int[] date = new int[101];
		while (true) {
			n = sc.nextInt(); q = sc.nextInt();
			if (n == 0) break;
			Arrays.fill(date, 0);
			for (int i = 0; i < n; i++) {
				int k = sc.nextInt();
				for (int j = 0; j < k; j++) {
					date[sc.nextInt()]++;
				}
			}
			
			int index = 0;
			int max = -1;
			for (int i = 0; i < 101; i++) {
				if (max < date[i] && q <= date[i]) {
					max = date[i];
					index = i;
				}
			}
			out.println(index);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 62556
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int p[41];
int t[41];
int memo[41][4];

#define MAX (100000000)

int main(){
  int n;

  memo[0][1] = memo[0][2] = memo[0][3] = MAX;

  while(n = getInt()){
    int ans = MAX;

    REP(i,n) REP(j,4) memo[i+1][j] = MAX;

    REP(i,n){
      p[i+1] = getInt();
      t[i+1] = getInt();
    }

    REP(i,n){
      int distance = abs(p[i+1] - p[i]);
      int time     = t[i+1] - t[i];
      bool ok = false;
      REP(j,4){
        if(memo[i][j] != MAX){
          int take  = distance * (j + 1);
          int take2 = p[i+1] + p[i] * (j + 1);
          if(take <= time){
            if(j != 3){
              memo[i+1][j+1] = min(memo[i+1][j+1], memo[i][j] + distance);
              ok = true;
            }
          }
          if(take2 <= time){
            memo[i+1][1]   = min(memo[i+1][  1], memo[i][j] + p[i+1] + p[i]);
            ok = true;
          }
        }
      }
      if(!ok){
        printf("NG %d\n",i+1);
        goto end;
      }
    }

    REP(i,4) ans = min(ans, memo[n][i]);
    ans += p[n];
    printf("OK %d\n",ans);
  end:;
  }
  return 0;
}

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

int main() {
  vector<int> p(3);
  rep(i,3) cin >> p[i];
  sort(p.begin(),p.end());
  cout << p[0] + p[1] << endl;
  return 0;
}

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

int main(){

  int N; cin >> N;
  int A[N], B[N];
  for(int i=0; i < N; i++){
    cin >> A[i];
  }
  copy(A, A+N, B);
  sort(B, B+N);
  for(int i=0; i < N; i++){
    int ans;
    if(A[i] == B[N-1]){
      ans = B[N-2];
    } else{
      ans = B[N-1];
    }
    cout << ans << endl;
  }

}


Measured memory_bytes: 3200
N=int(input())

contain=[[0 for i in range(10)] for _ in range(10)]
ans=0

for i in range(N+1):
    if str(i)[-1]!='0' or str(i)[-1]!='0':
        contain[int(str(i)[0])][int(str(i)[-1])]+=1

for i in range(10):
    for j in range(10):
        ans+=contain[i][j]*contain[j][i]
        
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
using namespace std;


int main(int argc, char* argv[])
{
	char N[3];
	scanf("%s", N);

	int flag = 0;
	for(int i; i<3; i++){
		if(N[i] == '7'){
			flag = 1;
			break;
		}
	}

	if(flag==1){
		printf("Yes");
	}else{
		printf("No");
	}

	return 0;
}





Measured memory_bytes: 3824
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char in[110000];
int at[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	scanf("%s",in);
	int sz=0;
	int now=0;
	at[sz++]=0;
	for(int i=0;i<a;i++){
		if(in[i]-'0'!=now){
			at[sz++]=i;
			now=!now;
		}
	}
	at[sz++]=a;
	int ret=0;
	for(int i=0;i<sz;i++){
		if(i%2==0)ret=max(ret,at[min(sz-1,i+2*b)]-at[i]);
		else ret=max(ret,at[min(sz-1,i+2*b+1)]-at[i]);
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int H, W; 
  cin >> H >> W;

  map<char, int> m;
  REP(i, H){
    string s;
    cin >> s;
    REP(j, s.size()){
      m[s[j]]++;
    }
  }

  vector<int> cnt(3, 0);
  for(auto p : m){
    while(p.second >= 4){
      p.second -= 4;
      cnt[2]++;
    }
    while(p.second >= 2){
      p.second -= 2;
      cnt[1]++;
    }
    while(p.second >= 1){
      p.second -= 1;
      cnt[0]++;
    }
  }

  vector<int> req(3, 0);
  if(H%2 == 0 && W%2 == 0){
    req[2] = H*W/4;
  }else if(H%2 == 1 && W%2 == 1){
    req[2] = (H*W-W/2*2-H/2*2-1)/4;
    req[1] = W/2+H/2;
    req[0] = 1;
  }else if(H%2 == 1){
    req[2] = (H*W-W/2*2)/4;
    req[1] = W/2;
  }else{
    req[2] = (H*W-H/2*2)/4;
    req[1] = H/2;
  }

  bool ans = true;
  RREP(i, 3){
    if(req[i] > cnt[i]) ans = false;
    if(i != 0){
      cnt[i-1] += (cnt[i]-req[i])*2;
    }
  }

  ans? Yes: No;

  return 0;
}

Measured memory_bytes: 256
MAX = 1000005
MOD = 10**9+7
factrial = [0]*MAX
inverse = [0]*MAX
factrial_inverse = [0]*MAX


# テーブルを作る前処理
def COMinit():
    global factrial, inverse, factrial_inverse
    factrial[0] = 1
    factrial[1] = 1
    inverse[1] = 1
    factrial_inverse[0] = 1
    factrial_inverse[1] = 1
    for i in range(2, MAX):
        factrial[i] = factrial[i-1] * i % MOD
        inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD
        factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD


# 二項係数計算
def COM(n, k):
    global factrial, inverse, factrial_inverse
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD


# 前処理完了
COMinit()


N, K = map(int, input().split())
ans = 0
for i in range(min(K, N)+1):  # 空にできるのはK部屋または、N-1部屋までのみ。
    ans += COM(N, i) * COM(N-1, i)
    ans %= MOD
print(ans)


Measured memory_bytes: 121716
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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

#処理内容
def main():
	K = int(input())
	S = input()
	M = len(S)
	if K >= M:
		print(S)
	else:
		ans = S[:K] + "..."
		print(ans)





if __name__ == '__main__':
	main()

Measured memory_bytes: 64652
/*
ID: rchalam1
LANG: C++14
TASK:
*/
// For train.usaco.org, fill the template above.

// Competitive Coding Template

// GCC OPTIMIAZTION FLAGS
#ifdef ONLINE_JUDGE
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif

#include <bits/stdc++.h>

/*
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
*/
// All Includes for Competitive Coding Template

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

using vi = std::vector<int>;
using vll = std::vector<long long>;
using vull = std::vector<unsigned long long>;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (auto i = (a); i >= (b); --i)
#define R0F(i, a) ROF(i, a, 0)
#define ITR(a, x) for (auto& a: x)

#define FSRT(set) sort((set).begin(),(set).end())
#define RSRT(set) sort((set).rbegin(),(set).rend())
#define CSRT(set, function) sort((set).begin(),(set).end(), (function))
#define TRS(set) sort((set).begin(),(set).end(), greater<>())
#define REV(set) reverse((set).begin(),(set).end());

#define ALL(set) (set).begin(), (set).end()

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// For stdio, call setIO() or setIO("").
void setIO(std::ifstream &readFile, std::ofstream &writeFile, const std::string &name = "", bool stdIO = false)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	if(!name.empty() && !stdIO)
	{
		readFile.open(name + ".in");
		if(readFile.fail()) return;
		writeFile.open(name + ".out");
		std::cin.rdbuf(readFile.rdbuf());
		std::cout.rdbuf(writeFile.rdbuf());
	}
}

// To time program, create object Timer  to start timing, and call Timer.elapsed().
#include <chrono>

class Timer
{
	std::chrono::time_point<std::chrono::high_resolution_clock> m_beg;
public:
	Timer() : m_beg(std::chrono::high_resolution_clock::now())
	{}

	void reset()
	{ m_beg = std::chrono::high_resolution_clock::now(); }

	[[nodiscard]] long double elapsed() const
	{
		return std::chrono::duration_cast<std::chrono::duration<long double, std::ratio<1> >>(
				std::chrono::high_resolution_clock::now() - m_beg).count();
	}
};

// Defines datatype
using dt = int;
// Defines MAXN value
constexpr dt MAXN = 1e5 + 1;
// Defines Modulus
constexpr dt MOD = 1e9 + 7;
// Defines Floating Point Correction
constexpr long double EPS = 1e-9;

//*****
//START CODE BELOW
//*****

int main(int argc, char *argv[])
{
	static std::ifstream readFile;
	static std::ofstream writeFile;
	setIO(readFile, writeFile);
	int a, b, k;
	cin >> a >> b >> k;
	set<int> numbers;
	for(int i = 0; i < k; ++i)
	{
		if(a + i <= b) numbers.insert(a + i);
		if(b - i >= a) numbers.insert(b - i);
	}
	for(auto &number : numbers) cout << number << '\n';
}

Measured memory_bytes: 3656
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scanf("%s", &s)
	n := len(s)
	if isPalindrome(s) && isPalindrome(s[0:(n-1)/2]) && isPalindrome(s[(n+3)/2-1:n]) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func isPalindrome(s string) bool {
	r := []rune(s)
	n := len(r)
	var mid int
	var f, b []rune
	if n % 2 == 1 {
		mid = (n - 1) / 2
		f = append([]rune{}, r[0:mid]...)
		b = append([]rune{}, r[mid+1:n]...)
	} else {
		mid = n / 2
		f = append([]rune{}, r[0:mid]...)
		b = append([]rune{}, r[mid:n]...)
	}

	for i := 0; i < mid; i++ {
		if f[i] != b[mid-1-i] {
			return false
		}
	}
	return true
}


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

int lcs(string X, string Y){
  int c[1001][1001];
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = " " + X;
  Y = " " + Y;
  for(int i = 0;i <= m;i++) c[i][0] = 0;
  for(int j = 1;j <= n;j++) c[0][j] = 0;

  for(int i = 1;i <= m;i++){
    for(int j = 1;j <= n;j++){
      if(X[i] == Y[j]){
        c[i][j] = c[i-1][j-1] + 1;
      } else {
        c[i][j] = max(c[i-1][j], c[i][j-1]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }

  return maxl;
}

int main(){
  string s1, s2;
  int n;

  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }
  return 0;
}

Measured memory_bytes: 7052
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


//main function
fn main() {
    let mut sum: i32 = 0;
    let mut min: i32 = 10;
    for _i in 0..5{
	let menu: i32 = read();
	if min > menu%10 && menu%10 != 0{
	    min = menu%10;
	}
	if menu%10==0{
	    sum += menu;
	}else {
	    sum += (menu/10+1)*10;
	}
    }
    println!("{}",sum-10+min);
}


Measured memory_bytes: 4352
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll ans = 0;
    ans += (N / (A+B)) * A;
    N = N % (A+B);
    ans += min(N, A);
    cout << ans << endl;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int N, A[100009], sum = 0, minx =10000;
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i]; sum += A[i];
		if (A[i] % 2 == 1) minx = min(minx, A[i]);
	}
	if (sum % 2 == 0) cout << sum / 2 << endl;
	else {
		cout << (sum - minx) / 2 << endl;
	}
	return 0;
}



Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define bitget(a, b) (((a) >> (b)) & 1)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vsort(x) sort(x.begin(), x.end())

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;

int main() {
	string s;
	cin >> s;
	int c[26] = {};
	rep(i, 0, s.length()){
		c[s[i] - 'a']++;
	}
	char ans;
	int f = 0;
	rep(i, 0, 26){
		if (c[i] == 0){
			ans = 'a' + i;
			f = 1;
			break;
		}
	}
	if (f){
		cout << ans << endl;
	}
	else{
		cout << "None" << endl;
		}
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(){
  int i, j, n, v, count = 0;
  int a[100];

  scanf("%d", &n);
  for ( i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  
  for ( i = 0; i < n; i++){
    for ( j = n - 1; j > 0; j--)
      if(a[j] < a[j - 1]){
        v = a[j];
        a[j] = a[j - 1];
        a[j - 1] = v;
        count++;
      }
  }
  for ( i = 0; i < n; i++){
    if (i > 0)
      printf(" ");
    printf("%d", a[i]);
  }

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

  return 0;
}

Measured memory_bytes: 1852
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long  i = 0; i < (long long)(n); i++)






int main() {
	int s,k,t;
		
	cin >> s>>k>>t;
	
	
	

		cout << (t/s)*k<< endl;
	
}

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

#define MAX_N 100'001

using namespace std;

int A[MAX_N]{};

int main() {
  int N, K;
  cin >> N >> K;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  int M = N - K;
  int res = 1;
  if (M > 0) {
    res += (int)(M / (K - 1)) + (M % (K - 1) != 0);
  }
  printf("%d\n", res);
}

Measured memory_bytes: 3512
# 18:57-
def bfs(m, sx, sy)
  
  inf = 10 ** 12
  
  h = m.size
  w = m[0].size
  d = Array.new(h){ [inf] * w }
  
  q = [[sx, sy]]
  d[sx][sy] = 0
  
  while q.any?
    
    x, y = q.shift
    cost = d[x][y]
    
    nx = x - 1
    if 0 <= nx && m[nx][y] == 46 && d[nx][y] > 1 + cost
      d[nx][y] = 1 + cost
      q << [nx, y]
    end
    nx = x + 1
    if nx < h && m[nx][y] == 46 && d[nx][y] > 1 + cost
      d[nx][y] = 1 + cost
      q << [nx, y]
    end
    ny = y - 1
    if 0 <= ny && m[x][ny] == 46 && d[x][ny] > 1 + cost
      d[x][ny] = 1 + cost
      q << [x, ny]
    end
    ny = y + 1
    if ny < w && m[x][ny] == 46 && d[x][ny] > 1 + cost
      d[x][ny] = 1 + cost
      q << [x, ny]
    end
  end
  # p d
  res = d.flatten.uniq.sort[-2..-1]
  res[-1] == inf ? res[-2] : res[-1]
end

h, w = gets.to_s.split.map{|t|t.to_i}
a = Array.new(h){ gets.to_s.chomp.bytes }

ans = 0
h.times do |sx|
  w.times do |sy|
    next if a[sx][sy] == 35
    t = bfs(a, sx, sy) #if a[sx][sy] == 46
    ans = t if ans < t
  end
end

puts ans

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

ll dp[105][100005];

void show_table(ll I, ll J) {
  for (ll i = 0; i <= I; i++) {
    for (ll j = 0; j <= J; j++) {
      cout << dp[i][j] << " ";
    }
    cout << "" << endl;
  }
  cout << "" << endl;
}

ll mod(ll n) { return ((n % MOD) + MOD) % MOD; }

int main() {
  ll N, K;
  scanf("%lld %lld", &N, &K);

  vector<ll> list(N);
  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    list[i] = v;
  }

  dp[0][0] = 1;
  for (ll i = 0; i < N; i++) {
    // show_table(3, 4);
    ll a = list[i];

    ll csum[K + 1];
    fill_n(csum, K, 0);
    for (ll c = 1; c <= K + 1; c++) {
      // csum[c] = csum[c - 1] + a[c - 1];
      csum[c] = (csum[c - 1] + dp[i][c - 1]) % MOD;
    }
    // // [2] + [3] + [4]
    // cout << (csum[4 + 1] - csum[2]) << endl;
    // // [1] + [2] + [3]
    // cout << (csum[3 + 1] - csum[1]) << endl;

    for (ll j = 0; j <= K; j++) {
      // ll plus = 0;
      // ll plus2 = 0;
      // for (ll k = 0; k <= a; k++) {
      //   // cout << (j - k) << endl;
      //   if (j - k < 0) {
      //     continue;
      //   }
      //   // cout << (i + 1) << "," << j << " <- " << i << "," << (j - k) <<
      //   endl;
      //   // dp[i + 1][j] = dp[i + 1][j] + dp[i][j - k];
      //   plus += dp[i][j - k];  // j-a ~ j
      // }
      ll plus2 = mod(csum[j + 1] - csum[max(j - a, 0LL)]);
      // cout << "plus:" << plus << endl;
      // cout << "plus2:" << plus2 << endl;
      dp[i + 1][j] = mod(dp[i + 1][j] + plus2);
    }
  }
  // show_table(N, K);

  cout << dp[N][K] << endl;
}

/*
1 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

1,0 <- 0,0
1,1 <- 0,1
1,1 <- 0,0
1,2 <- 0,2
1,2 <- 0,1
1,3 <- 0,3
1,3 <- 0,2
1,4 <- 0,4
1,4 <- 0,3

1 0 0 0 0
1 1 0 0 0
0 0 0 0 0
0 0 0 0 0

2,0 <- 1,0
2,1 <- 1,1
2,1 <- 1,0
2,2 <- 1,2
2,2 <- 1,1
2,2 <- 1,0
2,3 <- 1,3
2,3 <- 1,2
2,3 <- 1,1
2,4 <- 1,4
2,4 <- 1,3
2,4 <- 1,2

1 0 0 0 0
1 1 0 0 0
1 2 2 1 0
0 0 0 0 0

3,0 <- 2,0
3,1 <- 2,1
3,1 <- 2,0
3,2 <- 2,2
3,2 <- 2,1
3,2 <- 2,0
3,3 <- 2,3
3,3 <- 2,2
3,3 <- 2,1
3,3 <- 2,0
3,4 <- 2,4
3,4 <- 2,3
3,4 <- 2,2
3,4 <- 2,1

1 0 0 0 0
1 1 0 0 0
1 2 2 1 0
1 3 5 6 5
*/


Measured memory_bytes: 80128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<pair<int, int>> ed;
	for (int i = 0; i + 1 < n; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		if (u > v) swap(u, v);
		ed.push_back({u, v});
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += (i + 1) * (n - i);
	}
	for (auto [u, v] : ed) {
		ans -= (u + 1) * (n - v);
	}
	cout << ans << endl;
}

Measured memory_bytes: 7428
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
    int a;
    int b;
    cin >> a >> b;
    int d=a/b;
    int e=a%b;
    double c = 1.0*a/b;
    printf("%d %d %f", d ,e ,c);
   
    return 0;
}


Measured memory_bytes: 3216
def main():
    S=input()
    res=""

    for i in range(len(S)):
        if S[i]=="?":
            if len(S)==1:
                res+="D"
                continue
            if i==0:
                if S[i+1]=="?":
                    res+="P"
                else:
                    res+="D"
            elif i==len(S)-1:
                res+="D"
            else:
                if res[i-1]=="P":
                    res+="D"
                elif S[i+1]=="?":
                    res+="P"
                else:
                    res+="D"
        else:
            res+=S[i]
    print(res)

if __name__=="__main__":
    main()


Measured memory_bytes: 9480
n = gets.to_i

cnt = 0
max = 0

n.times do
    d1, d2 = gets.chomp.split
    if d1 == d2
        cnt += 1
    else
        cnt = 0
    end
    max = [max, cnt].max
end

puts (max >= 3 ? "Yes" : "No")

Measured memory_bytes: 14352
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var map = xArray(0,19,19);
  var ans = 0;
  for(var i = 0; i < n; i++){
    var a = next();
    a = Math.round(a*1e9);
    var t = 0, f = 0;
    while(a%2 === 0 && t < 18)a /= 2, t++;
    while(a%5 === 0 && f < 18)a /= 5, f++;
    for(var j = 18-t; j < 19; j++)for(var k = 18-f; k < 19; k++){
      ans += map[j][k];
    }
    map[t][f]++;
  }
  return ans;
}

Measured memory_bytes: 64140
#include <iostream>

using namespace std;

typedef struct {
	int value;
	int weight;
} Item;

const int MAX = 100;
Item items[101];

int S[MAX+1][10001];

int main() {
	int N,W;
	cin >> N >> W;
	for (int i=1;i<=N;i++) {
		cin >> items[i].value >> items[i].weight;
	}
	for (int i=0;i<=N;i++) {
		for (int j=0;j<=W;j++) {
			S[i][j] = 0;
		}
	}
	for (int i=1;i<=N;i++) {
		Item item = items[i];
		for (int j=1;j<=W;j++) {
			if (j >= item.weight)
			S[i][j] = max(S[i-1][j-item.weight] + item.value,S[i-1][j]);
			else
			S[i][j] = S[i-1][j];
		}
	}
	cout << S[N][W] << endl;
	return 0;
} 


Measured memory_bytes: 7052
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;


int main() {
    int n;
    cin >> n;
    vi A;
    rep(i, n) {
        int a;
        cin >> a;
        A.emplace_back(a);
    }
    sort(A.begin(), A.end());
    vi vec(1, 0);
    rep(i, n-1) {
        if(A[i] == A[i+1]) {
            ++*(vec.end()-1);
        } else {
            vec.emplace_back(0);
        }
    } 

    int sum = 0;
    rep(i, vec.size()) {
        sum += vec[i];
    }
    sum += (sum&1);
    cout << n-sum << endl;
}

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

int main(){
  int N,M;
  cin>>N>>M;
  vector<vector<char>> A(N,vector<char>(N));
  vector<vector<char>> B(M,vector<char>(M));
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin>>A.at(i).at(j);
    }
  }
  for(int i=0;i<M;i++){
    for(int j=0;j<M;j++){
      cin>>B.at(i).at(j);
    }
  }
  bool match=false;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if((i+M-1>=N)||(j+M-1>=N)) continue;
      bool judge=true;
      for(int k=0;k<M;k++){
        for(int l=0;l<M;l++){
          if(A.at(i+k).at(j+l)!=B.at(k).at(l)) judge=false;
        }
      }
      if(judge==true) match=true;
    }
  }
  if(match==true)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long ll;


typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

vector<int> G[100005];
std::vector<P> tree[100010];

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

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++)

ll i,j,ii,jj;
ll n,m;
ll now=0,tyakuti=0,memo=0;
ll kaisi,k,hazime,owari;
ll a[100005];
long double x[100005],y[100005],r[100005];
long double d[1005][1005];//d[i][j]:i~j
long double cost[1005];
bool kakutei[1005];


int main(){
    cin>>x[0]>>y[0]>>x[1]>>y[1];
    r[0]=r[1]=0;
    /*x[0]/=100.0000;
    x[1]/=100.0000;
    y[0]/=100.0000;
    y[1]/=100.0000;*/
    cin>>n;
    for(i=2;i<n+2;i++){
        cin>>x[i]>>y[i]>>r[i];
        /*x[i]/=100.0000;
        r[i]/=100.0000;
        y[i]/=100.0000;*/
    }
    for(i=0;i<n+2;i++){
        cost[i]=INF;
    }
    for(i=0;i<n+2;i++){
        for(j=0;j<n+2;j++){
            long double ddx=x[i]-x[j],ddy=y[i]-y[j];
            d[i][j]=sqrt(ddx*ddx+ddy*ddy)-r[i]-r[j];
            if(d[i][j]<0)d[i][j]=0;
        }
    }
    cost[0]=0;
    while(true){
        ll v=-1;
        for(i=0;i<n+2;i++){
            if(!kakutei[i] && (v==-1 || cost[i]<cost[v])){
                v=i;
            }
        }
        
        if(v==-1)break;
        kakutei[v]=true;
        bool flag=false;
        for(i=0;i<n+2;i++){
            if(!kakutei[i]){
                cost[i] = min(cost[i],cost[v] + d[i][v]);
                flag = true;
            }
        }
        if(!flag)break;
    }
    cout<< fixed << setprecision(20) <<(double)cost[1]*1.0000000000000<<endl;
    
    
    
    
    return 0;
}


Measured memory_bytes: 26240
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        int count = 0;
        while ((line = reader.readLine()) != null) {
            if (line.isEmpty()) {
                continue;
            }
            String[] values = line.split(" ");
            int a = Integer.parseInt(values[0]);
            int b = Integer.parseInt(values[1]);
            if (a == 0 && b == 0) {
                break;
            }
            if (count > 0) {
                out.println();
            }
            boolean found = false;
            for (int i = a; i <= b; i++) {
                if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) {
                    out.println(i);
                    found = true;
                }
            }
            if (!found) {
                out.println("NA");
            }
            count++;
        }
    }
}

Measured memory_bytes: 9952
h,n=map(int,input().split())
dp=[10**10 for i in range(h+1)]
dp[0]=0
for i in range(n):
    x,y=map(int,input().split())
    for j in range(h+1):
        nj=min(h,j+x)
        dp[nj]=min(dp[nj],dp[j]+y)
print(dp[h])

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


int money[20];
int memo[20][50050];
int n, m;



int dfs(int mm, int nkr){

  if(nkr == 0) return 0;

  if(mm == 0){
    return nkr;
  }

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

  if(nkr < money[mm]){
    return memo[mm][nkr] = dfs(mm-1,nkr);
  }

  return memo[mm][nkr] = min(dfs(mm-1,nkr),dfs(mm,nkr-money[mm])+1);
}


int main(){
  cin >> n >> m;
  for(int i = 0;i < m;i++){
    cin >> money[i];
  }

  for(int i = 0;i < 20;i++) for(int j = 0; j < 50050;j++) memo[i][j] = -1;

  sort(money,money+m);

  cout << dfs(m-1,n) << endl;
  return 0;
}


Measured memory_bytes: 7092
#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define in(s,x) s.find(x) != s.end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<pair<int,int>> VPII;
const ll mod=1000000007;
ll powmod(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;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
void chmin(int64_t& a, int64_t b){
    a = min(a, b);
}
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}

// head
int m,n,k,res,tmp,tmp2,tmp3,h,w,ans;
int a[3200] = {};
int b[8000100] = {};
int r[100001][25];
deque<PII> que;
string s;
map<int,VPII> kukan;
vector<PII> g[3000];
//int dp[200000];
int flag;
//VPII g2[200000];
int cost[200005];
double dp[1020][2] = {};
double dp2[1020][2] = {};
//VVI g(200005);

signed main() {
	cin.tie(0);
    ios::sync_with_stdio(false);
	cin>>n;
    rep(i,0,n){cin>>a[i];}
    res = 0;
    int MAX = 0;
    rep(i,0,n){
        if (MAX <= a[i]){
            MAX = a[i];res+=1;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in); 
		String s = sc.nextLine(); 
		if (s.length()%2==0) {
			System.out.println("Yes");
			return; 
		}
		int N = s.length(); 
		String s1 = s.substring(0, (N-1)/2);
		String s2 = s.substring((N+3)/2-1, N); 
		String res = s2 + s.charAt((N+1)/2-1) + s1; 
		if (res.equals(s)) System.out.println("Yes");
		else System.out.println("No");
		sc.close();
	}

}

Measured memory_bytes: 39396
#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<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#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)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

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

struct mint {
    long long x;
    mint(long long x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
    	return *this;
    }
    mint& operator*=(const mint a) {
    	(x *= a.x) %= MOD;
    	return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
    	if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
    	return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main(void){
    ll n,m; cin >> n >> m;
    vector<ll> x(n), y(m); REP(i,n) cin >> x[i]; REP(i,m) cin >> y[i];

    mint ans_x(0), ans_y(0);
    REP(i,n){
        ans_x += x[i]*i;
        ans_x -= x[i]*(n-1-i);
    }
    REP(i,m){
        ans_y += y[i]*i;
        ans_y -= y[i]*(m-1-i);
    }
    mint ans = ans_x*ans_y;
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 1792
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main() {
    int N;
    cin >> N;
    int cnt = 0;
    for (int i = 1; i <= N; i++) {
        int digit = 1;
        while (true) {
            if (pow(10.0, digit-1) <= i && i < pow(10.0, digit)) {
                break;
            }
            digit++;
        }
        if (digit % 2 == 1) {
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 888