akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
typedef unsigned long long ull;
typedef signed long long sll;
using namespace std;

#define INF 0x7FFFFFFFFFFFFFFF
#define BIG_PRIME 1000000007

vector<vector<ull>> dp;
vector<ull> a,sum;

int main()
{
  ull i,j,k,N;
  cin >> N;
  a.resize(N);
  sum.resize(N+1);
  dp.resize(N);
  sum[0]=0;
  for(i=0;i<N;++i)
  {
    cin >> a[i];
    sum[i+1]=sum[i]+a[i];
    dp[i].resize(N,0);
  }
  for(i=1;i<N;++i)
  {
    for(j=0;i+j<N;++j)
    {
      dp[j][j+i]=INF;
      for(k=0;k<i;++k)
      {
        dp[j][j+i]=min(dp[j][j+i],dp[j][j+k]+dp[j+k+1][j+i]+sum[j+i+1]-sum[j]);
      }
    }
  }
  cout << dp[0][N-1];
  return 0;
}

Measured memory_bytes: 1536
from bisect import bisect

N=int(input())

Lis=[1]
temp=6
while temp<=100000:
    Lis.append(temp)
    temp*=6
temp=9
while temp<=100000:
    Lis.append(temp)
    temp*=9

Lis=list(set(Lis))
Lis.sort()

DP=[100001]*(N+1)

DP[0]=0

for i in range(1,N+1):
    temp=[]
    idx=bisect(Lis,i)
    for j in range(idx):
        tem=1+DP[i-Lis[j]]
        temp.append(tem)
    DP[i]=min(temp)
print(DP[N])

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
long long ans=0, ha[10]={0}, wi[10]={0}, k, h, w;
string c[10];
bool judge(void){
    int i, j, cntk=0;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            if(c[i][j]=='#' && ha[i]==0 && wi[j]==0) cntk++; 
        }
    }
    if(cntk==k) return true;
    else return false;
}
int dfs(int cnt){
    if(cnt==(h+w)){
        if(judge()) ans++;
        return 0;
    }
    if(cnt<h){
        cnt++;
        ha[cnt-1]=0;
        dfs(cnt);
        ha[cnt-1]=1;
        dfs(cnt);
    }
    else{
        cnt++;
        wi[cnt-h-1]=0;
        dfs(cnt);
        wi[cnt-h-1]=1;
        dfs(cnt);
    }
    return 0;
}
int main(){
    long long i;
    cin >> h >> w >> k;
    for(i=0;i<h;i++){
        cin >> c[i];
    }
    dfs(0);
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
     
using namespace std;
    
     
int main() {
  std::string s;
  cin >> s;
        
  char cary[10]; 
  s.copy(cary, 10);
      
  std::string sn("");
  for (int i=0;i<10;i++){
    if (i != 4) {
      if (i != 7){
        sn += cary[i];
      }
    }
  }
      
  int num = atoi(sn.c_str());
  if(num>20190430){
    cout << "TBD" << endl;
  } else {
    cout << "Heisei" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(void)
{
  ll R,G,B,N;
  cin >>R>>G>>B>>N;
  ll ans=0;
  for(ll r=0;r*R<=N;r++) {
    for(ll g=0;g*G<=N;g++) {
      ll bn=N-r*R-g*G;
      if(bn>=0&&bn<=N&&bn%B==0){
        ans++;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  vector<int> a(5);
  for(int i=0;i<5;i++){
    cin >> a.at(i);
    if(a.at(i)==0){
      cout << i+1 << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3616
s=input()
t=input()
n=len(s)
dic={}
se=set()
ans='Yes'
for i in range(n):
    if s[i] not in dic:
        dic[s[i]]=t[i]
        if t[i] in se:
            ans='No'
        se.add(t[i])
    else:
        if dic[s[i]]!=t[i]:
            ans='No'
print(ans)
                


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long

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

 ll m=h[0]-1;

 for(ll i=1;i<n;i++){
     if((h[i]<m)&&(h[i]<(m+1))){
         cout<<"No";
         return 0;
     }
     m=max(m,h[i]-1);
 }
 cout<<"Yes";
}

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

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <int, ii> iii;

const int Maxn = 1005;
const int mod = 1000000007;

int n, m;
ll x;
int par[Maxn], siz[Maxn];
vector <iii> E;
vector <ii> neigh[Maxn];
vector <iii> tk, un;
int L[Maxn], P[Maxn], C[Maxn];
int res;

int getPar(int x) { return par[x] == x? x: par[x] = getPar(par[x]); }

bool unionSet(int a, int b)
{
	a = getPar(a), b = getPar(b);
	if (a == b) return false;
	if (siz[a] < siz[b]) swap(a, b);
	siz[a] += siz[b]; par[b] = a;
	return true;
}

void Build(int v, int p = 0)
{
	for (int i = 0; i < neigh[v].size(); i++) {
		ii u = neigh[v][i];
		if (p == u.first) continue;
		L[u.first] = L[v] + 1; P[u.first] = v; C[u.first] = u.second;
		Build(u.first, v);
	}
}

int getMax(int a, int b)
{
	int res = 0;
	while (a != b)
		if (L[a] > L[b]) {
			res = max(res, C[a]);
			a = P[a];
		} else {
			res = max(res, C[b]);
			b = P[b];
		}
	return res;
}

int main()
{
	scanf("%d %d", &n, &m);
	scanf("%lld", &x);
	for (int i = 1; i <= n; i++)
		par[i] = i, siz[i] = 1;
	for (int i = 0; i < m; i++) {
		int a, b, c; scanf("%d %d %d", &a, &b, &c);
		E.push_back(iii(c, ii(a, b)));
	}
	sort(E.begin(), E.end());
	ll tot = 0;
	for (int i = 0; i < E.size(); i++) {
		int a = E[i].second.first, b = E[i].second.second;
		if (unionSet(a, b)) {
			tot += E[i].first;
			neigh[a].push_back(ii(b, E[i].first));
			neigh[b].push_back(ii(a, E[i].first));
			tk.push_back(E[i]);
		} else un.push_back(E[i]);
	}
	if (tot > x) { printf("0\n"); return 0; }
	Build(1);
	if (tot == x) {
		int my = 1;
		for (int i = 0; i < tk.size(); i++)
			my = ll(my) * 2 % mod;
		my = (my - 2 + mod) % mod;
		for (int i = 0; i < un.size(); i++)
		my = ll(my) * 2 % mod;
		res = (res + my) % mod; 
	}
	int ways = 2;
	int ok = 0, notok = 0;
	for (int i = 0; i < un.size(); i++) {
		ll cur = tot + un[i].first - getMax(un[i].second.first, un[i].second.second);
		if (cur == x) ok++;
		else if (cur > x) notok++;
	}
	int add = 1;
	while (ok--) add = ll(add) * 2 % mod;
	add = (add - 1 + mod) % mod;
	ways = ll(ways) * add % mod;
	while (notok--) ways = ll(ways) * 2 % mod;
	res = (res + ways) % mod;
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 384
s = input()
i = 0
j = len(s)-1
ist = 0

while i < j:
    if s[i] == s[j]:
        i += 1
        j -= 1
    elif s[i] == 'x':
        ist += 1
        i += 1
    elif s[j] == 'x':
        ist += 1
        j -= 1
    else:
        print(-1)
        exit()

print(ist)


Measured memory_bytes: 3316
function Main(input) {
  const A = input.split('\n')[0];
  const B = input.split('\n')[1];
  const C = input.split('\n')[2];
  const X = input.split('\n')[3];
  
  var count = 0;
  
  for (var i =0; i <= A; i++) {
    for (var j =0; j <= B; j++) {
      for (var k =0; k <= C; k++){
        var total = 500 * i + 100 * j + 50 * k;
        if (total == X) {
          count ++;
        }
      }
    }
  }
console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));


Measured memory_bytes: 7500
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n), b(m);
    rep(i, n) cin >> a.at(i);
    rep(i, m) cin >> b.at(i);

    ll t = 0;
    rep(i, m) t += b.at(i);

    int j = m;
    int ans = 0;
    rep(i, n + 1) {
        while (j > 0 && t > k) {
            j--;
            t -= b.at(j);
        }
        if (t > k) break;
        ans = max(ans, i + j);
        if (i == n) break;
        t += a.at(i);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6384
#include<iostream>
using namespace std;
int n, m, i, j, q, ii1, jj1, ii2, jj2, sol;
char a[2005][2005], viz[2005][2005];
int lin[2][2005][2005], col[2][2005][2005], b[2005][2005];
int di[4] = {-1, 1, 0, 0};
int dj[4] = {0, 0, -1, 1};
void dfs(int ii, int jj){
    viz[ii][jj] = 1;
    for(int dir = 0; dir < 4; dir++){
        int iv = ii + di[dir];
        int jv = jj + dj[dir];
        if(a[iv][jv] == '1' && viz[iv][jv] == 0){
            if(ii == iv - 1){
                lin[0][iv][jv]++;
            }
            if(ii == iv + 1){
                lin[1][iv][jv]++;
            }
            if(jj == jv - 1){
                col[0][iv][jv]++;
            }
            if(jj == jv + 1){
                col[1][iv][jv]++;
            }
            dfs(iv, jv);
        }
    }
}
int main(){
    cin>> n >> m >> q;
    for(i = 1; i <= n; i++){
        cin>> a[i] + 1;
    }
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            if(a[i][j] == '1' && viz[i][j] == 0){
                b[i][j] = 1;
                dfs(i, j);
            }
        }
    }
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            b[i][j] += b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1];
            lin[0][i][j] += lin[0][i][j - 1];
            lin[1][i][j] += lin[1][i][j - 1];
            col[0][i][j] += col[0][i - 1][j];
            col[1][i][j] += col[01][i - 1][j];
        }
    }
    for(; q; q--){
        cin>> ii1 >> jj1 >> ii2 >> jj2;
        sol = b[ii2][jj2] - b[ii1 - 1][jj2] - b[ii2][jj1 - 1] + b[ii1 - 1][jj1 - 1];
        sol += lin[0][ii1][jj2] - lin[0][ii1][jj1 - 1];
        sol += lin[1][ii2][jj2] - lin[1][ii2][jj1 - 1];
        sol += col[0][ii2][jj1] - col[0][ii1 - 1][jj1];
        sol += col[1][ii2][jj2] - col[1][ii1 - 1][jj2];
        cout<< sol <<"\n";
    }
}


Measured memory_bytes: 88320
#include <bits/stdc++.h>
  using namespace std;
  long long MOD=1000000007;
  #define IOS() ios_base::sync_with_stdio(0); cin.tie(0);
  typedef long long ll;
  #define pb push_back
  typedef pair<int,int> pi;
  std::vector<int> g[100010];
  ll dp[100010][2];

ll solve(int node , int constraint , int parent)
{ 
  
   if(dp[node][constraint]!=-1)
    return dp[node][constraint];

  ll ans=0ll;
  ll w1=1ll;



   for(auto child : g[node])
   {
       if(child!=parent)
       {
          w1= ( w1 * solve(child , 0 , node)) %MOD;
       }
   }

   ans=(ans+w1)%MOD;

   if(!constraint)
   {  
    ll w2=1ll;

      for(auto child : g[node])
      {
         if(child!=parent)
         {
            w2= ( w2 * solve(child , 1 , node)) %MOD;
         }
     }

     ans=(ans+w2)%MOD;

   }


   return dp[node][constraint]=ans;

    
}

int main()
{

    int n;
    cin>>n;
    int a,b;
    memset(dp, -1, sizeof dp);

    for (int i = 0; i < n-1; ++i)
    {
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    

    cout<<solve(1,0,-1)<<endl;


    return 0;
    
} 

Measured memory_bytes: 18916
S = input()
K = int(input())

A = [0]
a = 0
for i in range(1, len(S)):
  if S[i-1] != S[i]:
    a += 1
    A.append(i)
A.append(len(S))
if a == 0:
  print((K * len(S)) // 2)
u = 0
if a != 0:
  B = [A[i] - A[i-1] for i in range(1, len(A))]
  for i in range(1, len(B) - 1):
    u += B[i] // 2
  u *= K
  if S[0] == S[len(S)-1]:
    u += B[0] // 2 + B[len(B)-1] // 2 + (K-1) * ((B[0] + B[len(B)-1]) // 2)
  else:
    u += K * (B[0] // 2 + B[len(B)-1] // 2)
  print(u)

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

const long MAX_N=10000000;
bool isPrime[MAX_N];

int main(){
	//素数テーブルの設定
	for(long i=2; i<=MAX_N; ++i)
		isPrime[i]=true;
		
	for(long i=2; i<=MAX_N; ++i){
		if(isPrime[i]){
			for(long j=2; i*j<=MAX_N; ++j) isPrime[i*j]=false;
		}
	}
	
	//実際の問題処理
	long n;
	
	while( scanf("%ld", &n) != EOF ){
		long count=0;
		
		for(long i=2; i<=n; ++i){
			if(isPrime[i]) ++count;
		}
		
		printf("%ld\n", count);
	}	 

	return 0;
}

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

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

int gcd(int x, int y){
	if(x % y == 0) return y;
	return gcd(x, x % y);
}
int lcm(int x, int y){
	return x * y / gcd(x, y);
}

int main(){
  int n;
  cin >> n;
  int room[4][3][10] = {};
  rep(i,n){
    int b, f, r, v;
    cin >> b >> f >> r >> v;
    room[b-1][f-1][r-1] += v;
  }

  rep(i,4){
    rep(j, 3){
      rep(k,10){
        cout << " " << room[i][j][k];
      }
      cout << endl;
    }
    if(i == 3) return 0;
    cout << "####################" << endl;
  }
}





Measured memory_bytes: 3112
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll A, B;
    cin >> A >> B;
    if (A % 2 != B % 2) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << (A + B) / 2 << endl;
    }
}

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

// 入力
int n, W;
int weight[110], value[110];

// DPテーブル
int dp[110][10010];

int main() {
  cin >> n >> W;
  for (int i = 0; i < n; ++i) cin >> value[i] >> weight[i];

  // DP初期条件: dp[0][w] = 0
  for (int w = 0; w <= W; ++w) dp[0][w] = 0;

  // DPループ
  for (int i = 0; i < n; ++i) {
    for (int w = 0; w <= W; ++w) {
      if (w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
      else dp[i+1][w] = dp[i][w];
    }
  }

  cout << dp[n][W] << endl;
}


Measured memory_bytes: 7044
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  int r,g;
  cin >> r >> g;
  cout << 2*g - r << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>
#include<boost/multiprecision/cpp_int.hpp>


using namespace std;
using namespace boost::multiprecision;

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
template<typename A, typename B>
void mins(A & a, const B & b) { a = min(a, (A)b); };
template<typename A, typename B>
void maxs(A & a, const B & b) { a = max(a, (A)b); };


//拡張ユークリッドの互除法。戻り値は最大公約数、x,yはax+by=gcd(a,b)を満たす組の一つ
long long gcdext(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long g = gcdext(b, a % b, y, x);
	y -= a / b * x;
	return g;
}

//モジュラ逆数
long long modinv(long long a, long long mod) {
	long long x, y;
	gcdext(a, mod, x, y);
	x = ((x % mod) + mod) % mod;
	return x;
}


//コンビネーション
class com_table {
public:
	vector<long long> frac;
	vector<long long> finv;
	long long mod;
	com_table() = default;
	void init(long long size, long long mod) {
		this->mod = mod;
		frac.resize(size + 1);
		finv.resize(size + 1);
		frac[0] = 1;
		finv[0] = 1;
		for (int i = 1; i <= size; ++i) frac[i] = frac[i - 1] * i % mod;
		finv[size] = modinv(frac[size], mod);
		for (int i = size; i >= 2; --i) finv[i - 1] = finv[i] * i % mod;
	}
	long long operator()(int a, int b) {
		if (a < b)return 0;
		return ((frac[a] * finv[b] % mod) * finv[a - b]) % mod;
	}
};


int main() {
	ll mod = 1e9 + 7;
	ll n; cin >> n;
	unordered_map<ll,ll> mp;
	ll x, y;
	vector<ll> A(n+1); 
	REP(i, 0, n + 1) {
		cin >> A[i];
		if (mp.count(A[i]) > 0) {
			x = mp[A[i]];
			y = i;
		}
		mp[A[i]] = i;
	}
	com_table com;
	com.init(n + 1, mod);
	ll a = x;
	ll c = n - y;
	REP(k, 1, n + 2) {
		PRI(((com(n + 1, k) - com(a + c, k - 1)) % mod + mod) % mod);
	}
	return 0;
}

Measured memory_bytes: 9756
let eqs a b o =
  let a, b, o = if o < 0 then b, a, -o else a, b, o in
  let rec f i =
    if i+o >= String.length a || i >= String.length b then true
    else (a.[i+o] = '?' || b.[i] = '?' || a.[i+o] = b.[i]) && f (i+1)
  in f 0

let max3 a b = max (max a b)
let min3 a b = min (min a b)

let () =
  Scanf.scanf "%s %s %s" @@ fun a b c ->
  let la, lb, lc = String.(length a, length b, length c) in
  let ab = Array.init 4001 (fun i -> eqs a b (i-2000)) in
  let bc = Array.init 4001 (fun i -> eqs b c (i-2000)) in
  let ac = Array.init 4001 (fun i -> eqs a c (i-2000)) in

  let ans = ref 6000 in
  for i = -4000 to 4000 do
    if la - i < !ans && i < (!ans - lb) && (abs i > 2000 || ab.(i+2000)) then
      for j = -4000 to 4000 do
        if (la - j < !ans) && j < (!ans - lc) &&
           (abs j > 2000 || ac.(j+2000)) &&
           (abs (j-i) > 2000 || bc.(j-i+2000))
        then
          ans := min !ans (max3 la (i+lb) (j+lc) - min3 0 i j)
      done;
  done;
  Printf.printf "%d\n" !ans


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define reg register

using namespace std;

typedef long long ll;
const int maxn = 100005;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int main() {
    int a; string s;
    cin >> a >> s;
    if (a >= 3200) cout << s << endl;
    else cout << "red" << endl;
    return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    ll n; cin >> n;

    vector<char> tbl(1, '*');
    for(char c = 'a'; c <= 'z'; c++) tbl.push_back(c);
    vector<char> ans;
    while(n > 0) {
        if(n % 26 != 0){
            ans.push_back(tbl[n % 26]);
            n /= 26;
        } else {
            ans.push_back(tbl[26]);
            n = (n - 1) / 26;
        }
    }
    reverse(all(ans));

    for(char t : ans){
        cout << t;
    }
    cout << endl;
    return 0;
}

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

using namespace std;
int main()
{
    // 整数の入力
    long d, n;
    cin >> d;
    cin >> n;
    if(n == 100)n+=1;
    
    long a = 1;
    for(int i = 0; i < d; i++){
        a*=100;
    }
    cout << a * n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e8;
const ll infl = 1LL << 60;
int main(){
  int n,k;
  cin >> n >> k;
  int res = 1;
  for(int i=0;i<n;i++){
    if(res * 2 < res + k){
      res*=2;
    }else{
      res+=k;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

int MOD = 998244353;
// int MOD = 1000000007;


//----------------------------------------------------------------
signed main(){

	ll  n;
	cin >> n;

	cout << (n-n/2)*1.0/(double)(n)  << endl;
	

	
	

	return 0;
}

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

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2017-final.contest.atcoder.jp/tasks/ddcc2017_final_b
// rm -r -f test;oj dl https://abc142.contest.atcoder.jp/tasks/abc142_b

Measured memory_bytes: 256
S = input()[::-1]
MOD = 2019

r = 0
C = [0 for _ in range(MOD)]
C[0] = 1

for i,s in enumerate(S):
    r += int(s)*pow(10,i,MOD)
    r %= MOD
    C[r] += 1

a = 0
for c in C:
    a += c*(c-1)/2

print(int(a))


Measured memory_bytes: 9392
// Aizu 0260: Salary for a Plumber
// 2017.9.8 bal4u@uu

#include <stdio.h>

#define max(a,b) ((a)>=(b)?(a):(b))
int j[65003];

int cmp(int *a, int *b) { return *b - *a; }

int main()
{
	int n, i, a;
    long long sum, ans;

	while (scanf("%d", &n) && n) {
        for (sum = i = 0; i < n; i++) scanf("%d", &a), sum += a;
        for (i = 0; i < n-1; i++) scanf("%d", j+i);
        qsort(j, n-1, sizeof(int), cmp);
        for (ans = sum*n, i = 0; i < n-1; i++) {
            sum += j[i];
            ans = max(ans, sum*(n-1-i));
        }
        printf("%lld\n", ans);
	}
	return 0;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int q;
  cin >> q;
  
  ll a, b;
  for(int i = 0; i < q; i++){
    cin >> a >> b;
    if(a > b) swap(a, b);
    
    if(a == b || a + 1 == b){
      cout << 2 * (a - 1) << '\n';
      continue;
    }
    
    ll x = sqrt(a * b);
    if(x * x == a * b) cout << 2 * (x - 1) - 1 << '\n';
    else{
      if(x * (x + 1) < a * b) cout << 2 * x - 1 << '\n';
      else cout << 2 * x - 2 << '\n';
    }
  }
}

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

int main(void){
    string S;
    string bef="";
    string aft="";
    cin >> S;
    int Q;
    cin >> Q;
    bool isReverse=false;
    
    for(int i=0;i<Q;i++){
        int T;
        cin >> T;
        if(T==1){
            if(isReverse){
                isReverse=false;
            }else{
                isReverse=true;
            }
        }else{
            int F;
            cin >> F;
            if(isReverse){
                if(F==2){
                    string C;
                    cin >> C;
                    bef=bef+C;
                }else{
                    string C;
                    cin >> C;
                    aft=aft+C;
                }
            }else{
                if(F==1){
                    string C;
                    cin >> C;
                    bef=bef+C;
                }else{
                    string C;
                    cin >> C;
                    aft=aft+C;
                }
            }
        }
    }
    
    reverse(bef.begin(),bef.end());
    string T=bef+S+aft;
    
    if(isReverse){
        reverse(T.begin(),T.end());
    }
    
    cout << T << endl;
}


Measured memory_bytes: 1596
x, y, z, k = gets.chomp.split(' ').map(&:to_i)
a = gets.chomp.split(' ').map(&:to_i).sort.reverse.slice(0...k)
b = gets.chomp.split(' ').map(&:to_i).sort.reverse.slice(0...k)
c = gets.chomp.split(' ').map(&:to_i).sort.reverse.slice(0...k)
ab = []
(0...[x, k].min).each do |i|
  (0...[y, k].min).each do |j|
    ab << a[i] + b[j]
  end
end
ab.sort!
ab.reverse!
ab = ab.slice(0...k)
abc = []
(0...[x * y, k].min).each do |i|
  (0...[z, k].min).each do |j|
    abc << ab[i] + c[j]
  end
end
abc.sort!
abc.reverse!
abc = abc.slice(0...k)
abc.each { |i| puts i }

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



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    L = list(map(int,input().split()))

    s = sum(L)/2

    S = (s*(s-L[0])*(s-L[1])*(s-L[2])) ** 0.5

    print(int(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>

using namespace std;

//typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)));
#define Mx(a , b) ((a) > (b) ? (a) : (b))
#define Mn(a , b) ((a) < (b) ? (a) : (b))

const double EPS = 1e-10;
const int INF = 2147483647;

char w[500001];
char r[500000];
int n , m , ans;
queue<int> Q[2];
stack<int> P;

int main(){
	scanf("%s" , w);
	for(m = 1 ; 'a' <= w[n] && w[n] <= 'z' ; ++n){
		if(w[0] != w[n]) m = 0;
	}
	if(m == 1){
		printf("%d\n1\n" , n);
		return 0;
	}
	for(int i = 2 ; i * 2 <= n ; ++i){
		if(n % i != 0) continue;
		bool b = 1;
		for(int j = 0 ; j < i ; ++j){
			for(int k = 1 ; k < n / i ; ++k){
				if(w[j] != w[j + i * k]){
					b = 0;
					j = i;
					break;
				}
			}
		}
		if(b){
			m = i;
			break;
		}
	}
	if(m == 0){
		printf("1\n1\n");
		return 0;
	}
	ans = n / m * (m - 1) + (n / m == 2 ? 1 : 0);
	int s , t , x , y , z = m;
	r[z - 1] = w[0];
	for(int i = 1 ; i < z ; ++i){
		if(w[0] == w[i]) Q[1].push(i);
		r[z - i - 1] = w[i];
	}
	y = 0;
	for(int i = 1 ; !Q[i % 2].empty() && i < m ; ++i){
		s = t = 0;
		while(!Q[i % 2].empty()){
			x = Q[i % 2].front();
			//printf("%d %d %d %d %d " , i , x , y, s,t);
			Q[i % 2].pop();
			if(y + i == x){
				y = x;
				--ans;
				++s;
			} else {
				if(!P.empty() && t + i != x){
					for(int j = 0 ; !P.empty() ; ++j){
						if(j == s) Q[(i + 1) % 2].push(P.top());
						P.pop();
					}
					t = 0;
				}
				if(s > 0 && (t == 0 || t + i == x)){
					if(t == 0){
						Q[(i + 1) % 2].push(x);
					} else {
						P.push(x);
					}
					t = x;
				} else if(w[i] == w[x + i]){
					Q[(i + 1) % 2].push(x);
				}
				y = 0;
			}
			//printf("%d\n" , ans);
		}
		if(!P.empty()){
			for(int j = 0 ; !P.empty() ; ++j){
				if(j == s) Q[(i + 1) % 2].push(P.top());
				P.pop();
			}
		}
	}
	for(int i = 1 ; i < z ; ++i){
		if(r[0] == r[i]) Q[1].push(i);
	}
	y = 0;
	for(int i = 1 ; !Q[i % 2].empty() && i < m ; ++i){
		s = t = 0;
		while(!Q[i % 2].empty()){
			x = Q[i % 2].front();
			//printf("%d %d %d %d %d " , i , x , y, s,t);
			Q[i % 2].pop();
			if(y + i == x){
				y = x;
				--ans;
				++s;
			} else {
				if(!P.empty() && t + i != x){
					for(int j = 0 ; !P.empty() ; ++j){
						if(j == s) Q[(i + 1) % 2].push(P.top());
						P.pop();
					}
					t = 0;
				}
				if(s > 0 && (t == 0 || t + i == x)){
					if(t == 0){
						Q[(i + 1) % 2].push(x);
					} else {
						P.push(x);
					}
					t = x;
				} else if(r[i] == r[x + i]){
					Q[(i + 1) % 2].push(x);
				}
				y = 0;
			}
			//printf("%d\n" , ans);
		}
		if(!P.empty()){
			for(int j = 0 ; !P.empty() ; ++j){
				if(j == s) Q[(i + 1) % 2].push(P.top());
				P.pop();
			}
		}
	}
	printf("2\n%d\n" , ans);
	return 0;
}


Measured memory_bytes: 1664
//I_love_algorithm_problems
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mx=1e5+10;
int cnt[mx];
int can[mx];
int main(){
   int n,m,u,v;
   scanf("%d %d",&n,&m);
   can[0]=1;
   for(int i=0;i<n;i++)cnt[i]=1;
   while(m--){
      scanf("%d %d",&u,&v);
      --u,--v;
      cnt[u]--;
      cnt[v]++;
      if(can[u]){
         can[v]=1;      
         if(cnt[u]==0)can[u]=0;
      }
   }
   int ans=0;
   for(int i=0;i<n;i++)ans+=can[i];
   printf("%d\n",ans);
   return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

S = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
S=S[::-1]
s=input()
print(S.index(s)+1)


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

int main() {
  int count = 0;
  string s;
  cin >> s;
  	for(int i = 0; i < 3; i++){
      	if (s.at(i) == '1'){
        	count++;
        }
      	else{
        	count += 0;
        }
    }
  cout << count << endl;
}

Measured memory_bytes: 3596
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
using namespace std;
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) ((x)&1)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define rep_it(it,x) for (__typeof((x).begin()) it=(x).begin(); it!=(x).end(); it++)
#define ____ puts("\n_______________\n\n")
#define debug(x) ____; cout<< #x << " => " << (x) << endl
#define debug_pair(x) cout<<"\n{ "<<(x).fir<<" , "<<(x).sec<<" }\n"
#define debug_arr(x,n) ____; cout<<#x<<":\n"; rep(i,0,n) cout<<#x<<"["<<(i)<<"] => "<<x[i]<<endl
#define debug_set(x) ____; cout<<#x<<": \n"; rep_it(it,x) cout<<(*it)<<" "; cout<<endl
#define debug_map(x) ____; cout<<#x<<": \n"; rep_it(it,x) debug_pair(*it)
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000 + 7;
const int _p = 1000 * 1000 * 1000 + 7;
const double PI=acos(-1);
const double eps=1e-9;
int o(int x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

int n,a[305][305];
ll s=0;

int main() {
    //file_put();

    scanf("%d",&n);
    rep(i,1,n) rep(j,1,n) { scanf("%d",&a[i][j]); s+=a[i][j]; }
    s/=2;
    rep(i,1,n-1) rep(j,i+1,n) {
        bool f=false;
    rep(k,1,n) {
        if (k==i || k==j) continue;
        if (!f && a[i][k]+a[k][j]==a[i][j]) s-=a[i][j],f=true;
        if (a[i][k]+a[k][j]<a[i][j]) return 0*printf("-1\n");
    }
    }
    cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

// rep(i, 100) { cout << i << endl; } => 0 1 2 ... 99
#define rep(i, n) for(int i = 0, i##_len = (n); i < (int)n; i++)

// std::sort(all(v));
#define all(x) (x).begin(), (x).end()

// long long int
using ll = long long;

// utility to cast return value of size function to int
#define SZ(x) ((int)(x).size())

// VS defines "_DEBUG" macro when debug configuration.
#if _DEBUG
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define dump(x)
#define debug(x)
#endif

// update max
template<class T>bool chmax(T & prov, const T & cur)
{
	if (cur > prov)
	{
		prov = cur;
		return true;
	}
	return false;
}

// update min
template<class T>bool chmin(T & prov, const T & cur)
{
	if (cur < prov)
	{
		prov = cur;
		return true;
	}
	return false;
}


void wf(vector<int> & out, const vector<vector<bool>> & E, const vector<vector<int>> & v_edge, int node, int dist)
{
	// if (out[node] <= dist) { return; }

	// out[node] = dist;

	queue<int> q;
	q.push(node);
	out[node] = dist;

	while (!q.empty())
	{
		int cur = q.front();
		q.pop();
		for (auto && to : v_edge[cur])
		{
			if (out[to] > out[cur] + 1)
			{
				out[to] = out[cur] + 1;
				q.push(to);
			}
		}
	}
}

int main()
{
	int N;
	cin >> N;
	vector<vector<bool>> E(N, vector<bool>(N, false));
	vector<vector<int>> v_edge(N);
	rep(i, N)
	{
		string S;
		cin >> S;
		rep(j, N)
		{
			E[i][j] = S[j] == '1';
			if (E[i][j])
			{
				v_edge[i].push_back(j);
				v_edge[j].push_back(i);
			}
		}
	}

	int ans = -1;

	rep(j, N)
	{
		vector<int> V_dist(N, 1000);
		wf(V_dist, E, v_edge , j, 1);

		bool is_check = false;

		int tmp = -1;

		rep(i, N)
		{
			// cout << i << ": dist = " << V_dist[i] << endl;
			if (ans < V_dist[i])
			{
				chmax(tmp, V_dist[i]);
				is_check = true;
			}
		}


		if (is_check)
		{
			bool is_valid = true;
			rep(u, N)
			{
				rep(v, N)
				{
					if (E[v][u])
					{
						if (V_dist[v] == V_dist[u])
						{
							is_valid = false;
						}
					}
				}
			}

			if (is_valid)
			{
				ans = tmp;
			}
		}
	}

	cout << ans << endl;

	// cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<functional>
#include<queue>
using namespace std;
int p[10000], q[10000], a, b, c, d, e, f, maxid1, maxid2; long double maxn = -1;
int main() {
	cin >> a >> b >> c >> d >> e >> f;
	q[0] = 1;
	for (int i = 0; i <= 3000; i++) {
		for (int j = 0; j <= 3000; j++) {
			int s = i*a + j*b;
			if (s >= 1 && s <= f)p[s] = 1;
		}
	}
	for (int i = 0; i <= 3000; i++) {
		for (int j = 0; j <= 3000; j++) {
			int s = i*c + j*d;
			if (s >= 1 && s <= f)q[s] = 1;
		}
	}
	for (int i = 0; i <= f; i++) {
		for (int j = 0; j <= f; j++) {
			int G = i * 100 + j; if (G > f)continue;
			if (i*e < j)continue;
			if (p[i] == 0 || q[j] == 0)continue;
			if (maxn < 1.0L*j / i) {
				maxn = 1.0L*j / i; maxid1 = i * 100; maxid2 = j;
			}
		}
	}
	cout << maxid1 + maxid2 << " " << maxid2 << endl;
	return 0;
}

Measured memory_bytes: 256
// Copyright 2017 wu_qing
#include <cstdio>
#include <cstdint>
const int N = 1e5 + 10;
int n;
int64_t ans, a[N];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%lld", a + i);
    for (int i = 1; i <= n; i++) {
        if (a[i] == 0)
            continue;
        a[i] += a[i - 1];
        ans += a[i] >> 1;
        a[i] &= 1;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 896
n,m = map(int,input().split())
ans = [0] * n
e = [False] * n
for _ in range(m):
    s,c = map(int, input().split())
    s = s - 1
    if e[s] and ans[s] != c:
        print(-1)
        exit()
    if s == 0 and c == 0 and n != 1:
        print(-1)
        exit()
    ans[s] = c
    e[s] = True


if ans[0] == 0 and n != 1:
    print(1, end='')
else:
    print(ans[0], end='')

for i in range(1,n):
    if not e[i]:
        print(0, end='')
    else:
        print(ans[i], end='')
print()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T> inline T sqr(T t) {return t*t;}
#define pb push_back
#define mp make_pair
#define endl "\n"

inline void files(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef _WIN32
        return;
    #endif // _WIN32
    //freopen("lca.in", "r", stdin);//freopen("output.out", "w", stdout);
}

string s, s1;

int main(){
    files();
    cin >> s;
    for (int i = 0; i < s.size(); i++)
        s1 = s[i] + s1;
    if (s1 == s)
        cout << "Yes"; else
        cout << "No";
}


Measured memory_bytes: 256
#include<iostream>                    
using namespace std;
int main(){
 
  int H,W,i,j;
 for(int i=0;i<300; i++){
	 cin>>H>>W;
if (H==0 && W==0)
	break;
for ( int i = 0; i < H; i++ ){
    for ( int j = 0; j < W; j++ ){
        cout << "#";}
    cout << endl;
}
cout<<endl;
}

  return 0;
  }


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int H,W; cin >> H >> W;
    VS A(H);
    REP(i,H) cin >> A[i];
    bool ok = true;
    map<int,int> mp;
    REP(i,H) REP(j,W){
        if(A[i][j] == '#'){
            mp[i+j]++;
        }
    }
    for(auto p : mp){
        if(p.second != 1) ok = false;
    }
    if(ok){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MAX = 303;
const Int INF = 1e9;
Int dp[MAX][MAX];
Int fr[MAX][MAX];
signed main(){
  Int h,w;
  cin>>h>>w;
  vector<string> ss(h);
  for(Int i=0;i<h;i++) cin>>ss[i];

  auto cost=
    [&](string a,string b)->Int{
      fr[0][0]=0;
      for(Int i=0;i<h;i++){
        fr[i+1][0]=0;
        fr[0][i+1]=0;
      }

      for(Int i=0;i<h;i++)
        for(Int j=0;j<h;j++)
          fr[i+1][j+1]=fr[i][j]+(a[i]==b[j]);

      for(Int i=0;i<MAX;i++)
        for(Int j=0;j<MAX;j++)
          dp[i][j]=INF;

      dp[h][h]=0;
      for(Int i=h;i>=0;i--){
        for(Int j=h;j>=0;j--){
          if(i) chmin(dp[i-1][j],dp[i][j]+fr[i][j]);
          if(j) chmin(dp[i][j-1],dp[i][j]+fr[i][j]);
        }
      }

      return dp[0][0];
    };

  Int ans=0;
  for(Int j=0;j+1<w;j++){
    string a,b;
    for(Int i=0;i<h;i++) a+=ss[i][j];
    for(Int i=0;i<h;i++) b+=ss[i][j+1];
    //reverse(a.begin(),a.end());
    //reverse(b.begin(),b.end());
    ans+=cost(a,b);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_HUMAN_MAX		100000									// 最大人数

// 内部構造体 - 人情報
typedef struct Human {
	int miNo;													// 出席番号
	int miHCnt;													// 人数
} Human;

// 内部変数
static FILE *szpFpI;											// 入力
static Human sz1Human[D_HUMAN_MAX];								// 人
static int siHCnt;												// 人数
static char sc1Out[D_HUMAN_MAX * 6];							// 出力内容
static char *scpOut;											// 出力位置

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 出力内容 - 追加
int
fOutAdd(
	int piVal					// <I> 値
)
{
	char lc1Buf[1024];
	sprintf(lc1Buf, "%d ", piVal);
	int liLen = strlen(lc1Buf);
	memcpy(scpOut, lc1Buf, liLen);
	scpOut += liLen;

	return 0;
}

// ソート関数 - 人数昇順
int
fSortFnc(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	Human *lzpVal1 = (Human *)pzpVal1;
	Human *lzpVal2 = (Human *)pzpVal2;

	// 人数昇順
	if (lzpVal1->miHCnt > lzpVal2->miHCnt) {
		return 1;
	}
	else if (lzpVal1->miHCnt < lzpVal2->miHCnt) {
		return -1;
	}

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 人数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siHCnt);

	// 人 - 取得
	for (i = 0; i < siHCnt; i++) {
		sz1Human[i].miNo = i + 1;
		fscanf(szpFpI, "%d", &sz1Human[i].miHCnt);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	qsort(sz1Human, siHCnt, sizeof(Human), fSortFnc);

	// 出力内容 - 追加
	for (i = 0; i < siHCnt; i++) {
		fOutAdd(sz1Human[i].miNo);
	}

	// 出力
	*scpOut = '\0';
	scpOut--;
	*scpOut = '\n';
	fOutLine(sc1Out);

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// データ - 初期化
	scpOut = sc1Out;											// 出力位置

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 2156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,sum=0,i;
    cin>>n;
    for(i=1;i<=n;i++)
    {
      if(i%3&&i%5)
            sum+=i;
    }
    cout<<sum<<endl;





    return 0;
}


Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt(); //health
		int b = scanner.nextInt(); //strengh
		int c = scanner.nextInt(); 
		int d = scanner.nextInt(); 
		
		while(true) {
			c = c - b;
			if (c <= 0) {
				System.out.println("Yes");
				break;
			} 
			a = a - d;
			if (a <= 0) {
				System.out.println("No");
				break;
			}
			
		}
		return;
	} 
}

Measured memory_bytes: 35716
n,m = map(int,input().split())
mat = [0 for i in range(n+1)]

for i in range(m):
    mat[int(input())] = -1

for i in range(n):
    if i == 0:
        mat[i] = 1
    if mat[i] == -1:
        continue
    if i + 1 < n+1:
        if mat[i+1] != -1:
            mat[i+1] += mat[i]
    if i + 2 < n+1:
        if mat[i+2] != -1:
            mat[i+2] += mat[i]
if mat[-1] >= 0:
    print(mat[-1]%1000000007)
else:
    print(0)

Measured memory_bytes: 462716
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>
#include <iomanip>
#include <bitset>


using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

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

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

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

vector<ll> divisor(ll n){
	vector<ll> res;

	for(ll i = 1; i * i <= n; i++){
		if (n % i==0){
			res.push_back(i);
			if (i != n / i){
				res.push_back(n / i);
			}
		}
	}

	// sort(all(res));  //O(\sprt(n)log(n))

	return res;
}


int main()
{
	ll a,b;
	cin>>a>>b;
	if(a>b){
		ll tmp=a;
		a=b;
		b=tmp;
	}
	vector<ll> div_a = divisor(a);

	set<ll> s;
	for(auto x:div_a) if(b%x==0)s.insert(x);
	set<ll> ans;
	ans.insert(1);
	s.erase(1);
	while(!s.empty()){
		ll x = *s.begin();
		ans.insert(x);
		s.erase(x);
		vector<ll> z;
		for(auto y:s)if(gcd(x,y)!=1) z.push_back(y);
		for(auto y:z)s.erase(y);
	}
	// for(auto x:ans)cout<<x<<endl;
	cout<<ans.size()<<endl;

	return 0;
}

Measured memory_bytes: 768
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n, x, y;
int ans[2010];

int main()
{
	scanf("%d%d%d", &n, &x, &y);
	for (int i = 1 ; i <= n ; i++) {
		ans[i] = n - i;
	}
	
	for (int dx = 1 ; dx <= n ; dx++) {
		for (int dy = dx + 1 ; dy <= n ; dy++) {
			int realDist = dy - dx;
			int changeDist = abs(x - dx) + abs(y - dy) + 1;
			
			if (changeDist < realDist) {
//				printf("%d %d | %d %d\n", dx, dy, realDist, changeDist);
				ans[realDist]--;
				ans[changeDist]++;
			}
		}
	}
	
	for (int i = 1 ; i <= n - 1 ; i++) {
		printf("%d\n", ans[i]);
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int N; cin >> N;
    VL A(N),B(N);
    REP(i,N){
        cin >> A[i] >> B[i];
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    if(N%2 == 1){
        cout << B[N/2] - A[N/2] + 1 << endl;

    }else{
        LL ta = A[N/2] + A[N/2-1];
        LL tb = B[N/2] + B[N/2-1];
        cout << tb - ta + 1 << endl;
    }

}

Measured memory_bytes: 6340