akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

bool isp[1000011];
int last[1000011];
ll A,B,a,b;

int main(){
	cin>>A>>B;
	a=max(2LL,A-B);
	b=A+B;
	fill(isp,isp+1000011,1);
	fill(last,last+2*B+1,INF);
	for(ll i=2;i*i<=b;i++){
		if(isp[i]){
			for(ll j=2*i;j*j<=b;j+=i) isp[j]=0;
			for(ll j=max(2LL,(a+i-1)/i)*i;j<=b;j+=i){
				if(last[j-a]>-1){
					ll x=j,y=0;
					while(x%i==0)x/=i,y++;
					if(last[j-a]<y)last[j-a]=-1;
					else last[j-a]=y;
				}
			}
		}
	}
	int ans=0;
	for(ll i=a;i<=b;i++)ans+=last[i-a]>-1;
	cout<<ans<<endl;
}

Measured memory_bytes: 5712
#include<stdio.h>
#define N 250

int main(){
  int T[N], n, i;

  scanf("%d\n",&n);
  for(i = 1 ; i <= n ; i++){
    scanf("%d", &T[i]);
  }
  
  for(i = 1 ; i <= n ; i++){
    printf("node %d: key = %d, ", i, T[i]);
    if(i/2 >= 1){
      printf("parent key = %d, ", T[i/2]);
    }
    if(2*i <= n){
      printf("left key = %d, ", T[2*i]);
    }
    if(2*i+1 <= n){
      printf("right key = %d, ", T[2*i+1]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main() {
    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    ll taka = a1 * t1 + a2 * t2;
    ll aoki = b1 * t1 + b2 * t2;
    if (taka == aoki) {
        cout << "infinity" << endl;
        return 0;
    }
    if (((taka - aoki > 0) && (a1 > b1)) || ((taka - aoki < 0) && (a1 < b1))) {
        cout << 0 << endl;
        return 0;
    }
    ll first_dis = abs(a1 * t1 - b1 * t1);
    ll second_dis = abs(taka - aoki);
    //first_dis が second_disずつ縮まっていく
    ll count = 0;
    count += (first_dis / second_dis) * 2;
    if (first_dis % second_dis) {
        count++;
    }
    cout << count << endl;
    return 0;
}

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

int main()
{
	int l, r, d;

	cin >> l >> r >> d;

	int now = 0;
	int count = 0;
	for (int i = 0; now <= r; i++) {
		if (l <= now && now <= r) {
			count += 1;
		}
		now += d;
	}

	cout << count;
}

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

int main() {
    int count = 1;
    vector<int> x(5);
    for (int i = 0; i < 5; i++) {
        cin >> x.at(i);
    }
    
    for (int i = 0; i < 5; i++) {
        if (x.at(i) == 0) {
            count += i;
        }
    }

    cout << count << endl;

}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

ll dp[333][333][333];

void chmin(ll &a, ll b){
	a = min(a, b);
}

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
	REP(i, 333)REP(j, 333)REP(k, 333)dp[i][j][k] = LLINF;

	ll n, k;cin >> n >> k;
	vector<ll> v(n+1);
	REP(i, n)cin >> v[i+1];

	dp[1][0][0] = 0;
	for(int i = 1;i <= n;i++){
		REP(j, 333){
			REP(k, 333){
				if(dp[i][j][k] == LLINF)continue;
				chmin(dp[i+1][j][k+1], dp[i][j][k]);
				chmin(dp[i+1][i][k], dp[i][j][k] + max(0LL, v[i] - v[j]));
			}
		}
	}

	ll ans = LLINF;
	REP(i, n+1)REP(j, k+1)chmin(ans, dp[n+1][i][j]);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 288768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string s,t;
  cin>>s>>t;
  int a=s.size();
  int b=t.size();
  int dp[a+1][b+1];
  rep(i,0,b+1) dp[0][i]=0;
  rep(i,0,a+1) dp[i][0]=0;
  rep(i,0,a){
    rep(j,0,b){
      if(s[i]==t[j]){
        dp[i+1][j+1]=dp[i][j]+1;
      }
      else{
        dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
      }
    }
  }
  int i=a,j=b;
  string u;
  while(i>0 && j>0){
    if(dp[i][j]==dp[i][j-1]){
      j--;
    }
    else if(dp[i][j]==dp[i-1][j]){
      i--;
    }
    else{
      i--;
      j--;
      u+=s[i];
    }
  }
  reverse(u.begin(),u.end());
  cout<<u<<endl;
}

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

const int MAX = 510000;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  COMinit();
  ll n,k;
  cin >> n >> k;
  for(int i=1;i<=k;i++){
    cout << (COM(n-k+1,i)*COM(k-1,i-1))%mod << endl;
  }
return 0;}

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

int n;
int x[24],y[24],r[24],c[24];
bool memo[1<<24];
char bit_count[1<<24];

bool ok(int a,int bit){
    for(int i=0;i<a;i++){
        if(((bit>>i)&1)==0)continue;
        int dist=(x[i]-x[a])*(x[i]-x[a])+(y[i]-y[a])*(y[i]-y[a]);
        int sum=(r[i]+r[a])*(r[i]+r[a]);
        if(dist<sum)return false;
    }
    return true;
}

int dfs(int bit){
    memo[bit]=true;

    int ret=n;
    for(int i=0;i<n;i++)if((bit>>i)&1)ret--;

    for(int i=0;i<n;i++){
        if(((bit>>i)&1)==0||ok(i,bit)==false)continue;
        for(int j=i+1;j<n;j++){
            if(ok(j,bit)==false||((bit>>j)&1)==0||c[i]!=c[j])continue;
            int to_bit=(bit^(1<<i))^(1<<j);
            if(!memo[to_bit])ret=max(ret,dfs(to_bit));

        }
    }

    return ret;
}

void solve(){
    fill_n(memo,1<<n,false);

    cout<<dfs((1<<n)-1)<<endl;
}

bool input(){
    cin>>n;
    if(!n)return false;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>r[i]>>c[i];
    return true;
}

void init(){
    for(int i=0;i<(1<<24);i++){
        for(int j=0;j<24;j++)if((i>>j)&1){
            bit_count[i]++;
        }
    }
}

int main(){
    //init();
    while(input())solve();
    return 0;
}

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

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

  int yymm = 0;
  int mmyy = 0;

  int first = stoi(s.substr(0, 2)); 
  int second = stoi(s.substr(2, 2));
    
  if (first >= 1 && first < 13)
	mmyy = 1;
  if (second >= 1 && second < 13)
	yymm = 1;

  if (yymm & mmyy) {
	cout << "AMBIGUOUS" << endl;
  } else {
	if (yymm)
	  cout << "YYMM" << endl;
	else if (mmyy)
	  cout << "MMYY" << endl;
	else
	  cout << "NA" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>

#define all(v) v.begin(), v.end()
typedef long long ll;
#define rep(i, z, n) for(int i = z; i < n; i++)
//const int INF = 1<<29;
//const ll MOD = 1000000007;
#define P pair<int, int>
using namespace std;

int main(){
    string S, T;
    cin >> S >> T;
    int s = S.size(), t = T.size();
    int ans = 10000;
    rep(i, 0, s - t + 1){
        int count = 0;
        rep(j, 0, t){
            if(S.at(i + j) == T.at(j)) continue;
            else{
                count++;
            }
        }
        ans = min(ans, count);
    }
    cout << ans << endl;
}


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

string s,t;

vector<int> mp[30];

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  cin>>s>>t;

  int sn=s.size();
  int tn=t.size();
  char c;

  for(int i=0;i<sn;i++){
    c = s[i];
    mp[c].push_back(i);
  }

  for(int i=0;i<tn;i++){
    c = t[i];
    if(mp[c].size()==0){
      cout<<-1<<endl;
      return 0;
    }
  }

  ll res=0;
  int s_p=0;
  std::vector<int>::iterator it;

  for(int i=0;i<tn;i++){
    c = t[i];
    it = lower_bound(mp[c].begin(), mp[c].end(), s_p);
    if(it == mp[c].end()){
      res += sn - s_p;
      s_p = 0;
      res += mp[c][0] - s_p + 1;
      s_p = mp[c][0] + 1;
    } else {
      res += *it - s_p + 1;
      s_p = *it + 1;
    }
  }

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 1228
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>

using namespace std;

/// 各桁の和
int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;
    }
    return sum;
}
/// 最小公倍数 
int gcd(int x, int y){
      if(x<y){
          int temp = x;
          x = y;
          y = temp;
      }
      int r = x % y;
       while(r!=0){
           x = y;
           y = r;
           r = x % y;
       }
      return y;
   }



int main(){
 vector<int> A(3);
 vector<int> B(3);
 for(int i = 0; i < 3; i++){
     cin >> A[i] >> B[i];
 }
 int cnt_1 = 0;
 int cnt_2 = 0;
 int cnt_3 = 0;
 int cnt_4 = 0;
 for(int i = 0 ; i < 3; i++){
     if(A[i] == 1)cnt_1++;
     else if(A[i] == 2)cnt_2++;
     else if(A[i] == 3)cnt_3++;
     else cnt_4++;
 }
 for(int i = 0 ; i < 3; i++){
     if(B[i] == 1)cnt_1++;
     else if(B[i] == 2)cnt_2++;
     else if(B[i] == 3)cnt_3++;
     else cnt_4++;
 }
 
if(cnt_1 == 3 || cnt_2 == 3 || cnt_3 == 3 || cnt_4 == 3)cout << "NO" << endl;
else cout << "YES" << endl;
}

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

int main(){
  int h,n,s;
  cin >> h >> n;
  for(int i=0;i<n;i++){
  
    cin >> s;
	h-=s;
  }
  if(h<=0)cout << "Yes";
  else cout << "No";
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(a: int, b: int):

    N = int(str(a) + str(b))

    for i in range(1000):
        if i**2 == N:
            print(YES)
            return
        elif i**2 > N:
            break

    print(NO)
    return


# 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():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(void)
{
  LL a,b;
  cin >> a >> b;
  if(a==b) cout << a+b << endl;
  else cout << max(a,b) *2 -1 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for(int i = 1;i <= 5; i++) {
			int a = sc.nextInt();
			if(a==0) {
				System.out.println(i);
			}
		}
	}
}

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

main()
{
    char arr[100100];
    scanf("%s",arr);
    int ans=0;
    for(int i=1;arr[i];i++)
    {
        if(arr[i]!=arr[i-1])
            ans++;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 3876
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>

using namespace std;

void c_step(void) {
	int n;
	long long* a;
	long long* b;
	cin >> n;
	a = (long long*)calloc(n, sizeof(long long));
	b = (long long*)calloc(n, sizeof(long long));
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	b[0] = a[0];
	long long sum = 0;
	for (int i = 1; i < n; i++) {
		if (a[i] < b[i - 1]) {
			b[i] = b[i - 1];
			sum += (b[i - 1] - a[i]);
		}
		else {
			b[i] = a[i];
		}
	}

	cout << sum << endl;

	free(a);
	free(b);
}

int main()
{
    c_step();

    return 0;
}

Measured memory_bytes: 6356
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if (x >= r && y >= r && x <= w - r && y <= h - r) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
    
}


Measured memory_bytes: 3096
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5)

def dfs(v, p, c):
    color[v] = c
    for e in graph[v]:
        if e[0] == p: continue
        if e[1] % 2: dfs(e[0], v, 1-c)
        else: dfs(e[0], v, c)


n = int(input())
color = [-1] * n
graph = [[] for _ in range(n)]

for _ in range(n-1):
    u, v, w = [int(x) for x in input().split()]
    u, v = u-1, v-1
    graph[u].append((v, w))
    graph[v].append((u, w))

dfs(0, -1, 1)
for c in color: print(c)

Measured memory_bytes: 79428
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
struct mouse{
	int x;
	int y;
	int cnt;
};
int used[1000][1000]={0};
char map[1000][1000];
int maps[1000][1000]={0};
int main(){
	int h,w,n,p=1,i,j,fx,fy,k;
	int mx[4]={-1,0,1,0};
	int my[4]={0,-1,0,1};
	char num[11]="0123456789";
	queue<mouse> m;
	mouse v,u;
	scanf("%d %d %d",&h,&w,&n);
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cin>>map[i][j];
			if(map[i][j]=='S'){
				v.x=j;
				v.y=i;
			}
			for(k=0;k<10;k++){
				if(num[k]==map[i][j]){
					maps[i][j]=k;
				}
			}
		}
	}
	v.cnt=0;
	m.push(v);
	while(1){
		v=m.front();
		m.pop();
		if(used[v.y][v.x]==1){
			continue;
		}
		
		else{
			used[v.y][v.x]=1;
		}
		if(maps[v.y][v.x]==p){
			if(p==n){
				break;
			}
			memset(used,0,sizeof(used));
			while(!m.empty()){
				m.pop();
			}
			p++;
			m.push(v);
			continue;
		}
		for(i=0;i<4;i++){
			if((v.x+mx[i])>=0&&(v.x+mx[i])<w&&(v.y+my[i])>=0&&(v.y+my[i])<h){
				u=v;
				u.x=v.x+mx[i];
				u.y=v.y+my[i];
				if(map[u.y][u.x]!='X'){
					u.cnt++;
					m.push(u);
				}
			}
		}
	}
	printf("%d\n",v.cnt);
	return 0;
}

Measured memory_bytes: 8164
// 2020-09-20 17:09:31
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
#include <atcoder/convolution>
// #include <atcoder/dsu>
// #include <atcoder/fenwicktree>
// #include <atcoder/lazysegtree>
// #include <atcoder/math>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/modint>
// #include <atcoder/scc>
// #include <atcoder/segtree>
// #include <atcoder/string>
// #include <atcoder/twosat>
// #include <atcoder/all>
using namespace atcoder;

// clang-format on
void answer() {
  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> b(m);
  rep(i, m) cin >> b[i];
  vector<ll> c = convolution(a, b);
  rep(i, c.size()) {
    if (i) cout << ' ';
    cout << c[i];
  }
  cout << '\n';
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 27256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
int k, a, b;
int main(){
	cin >> k >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i%k == 0) { puts("OK"); return 0; }
	}
	puts("NG");
	return 0;
}

Measured memory_bytes: 3648
def yumiri(L, n):
  for i in range(len(L)):
    if L[i] > n:
      return i - 1

def parunyasu(a, b, p, q):
  reans = ans
  rd1, rq1, d1, nd1, nq1, q1, newans = naobou(a, q, reans)
  rd2, rq2, d2, nd2, nq2, q2, newans = naobou(b, p, newans)

  if reans <= newans:
    t[d1 - 1] = q1
    t[d2 - 1] = q2
    return newans
  else:
    ayaneru(rd2, rq2, d2, nd2, nq2)
    ayaneru(rd1, rq1, d1, nd1, nq1)
    return reans

def ayaneru(rd, rq, d, nd, nq):
  ZL[rd].insert(rq, d)
  del ZL[nd][nq + 1]

def gaochan(d, q):
  reans = ans
  rd1, rq1, d1, nd1, nq1, q1, newans = naobou(d, q, ans)
  if reans <= newans:
    t[d1 - 1] = q1
    return newans
  else:
    ayaneru(rd1, rq1, d1, nd1, nq1)
    return reans

def naobou(d, q, ans):
  newans = ans

  rd = t[d - 1] - 1
  rq = yumiri(ZL[rd], d)
  newans += SUMD[ZL[rd][rq] - ZL[rd][rq - 1] - 1] * c[rd]
  newans += SUMD[ZL[rd][rq + 1] - ZL[rd][rq] - 1] * c[rd]
  newans -= SUMD[ZL[rd][rq + 1] - ZL[rd][rq - 1] - 1] * c[rd] 
  del ZL[rd][rq]

  nd = q - 1
  nq = yumiri(ZL[nd], d)
  newans += SUMD[ZL[nd][nq + 1] - ZL[nd][nq] - 1] * c[nd]
  newans -= SUMD[d - ZL[nd][nq] - 1] * c[nd]
  newans -= SUMD[ZL[nd][nq + 1] - d - 1] * c[nd]
  ZL[nd].insert(nq + 1, d)

  newans -= s[d - 1][rd]
  newans += s[d - 1][nd]

  return rd, rq, d, nd, nq, q, newans

def rieshon():
  ans = 0
  for i in range(D):
    ans += s[i][t[i] - 1]
    for j in range(26):
      if t[i] - 1 == j:
        L[j] = 0
        ZL[j].append(i + 1)
      else:
        L[j] += 1
        ans -= L[j] * c[j]
  for i in range(26):
    ZL[i].append(D + 1)
  return ans

import time
import random
startTime = time.time()

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

L = [0] * 26
ZL = [[0] for _ in range(26)]
SUMD = [0] * (D + 1)
for i in range(1, D + 1):
  SUMD[i] = SUMD[i - 1] + i

RD = [0] * 26
t = [0] * D
for i in range(D):
  RD[0] += 1
  ma = s[i][0] + RD[0] * c[0]
  man = 0
  for j in range(1, 26):
    RD[j] += 1
    k = s[i][j] + RD[j] * c[j]
    if k > ma:
      ma = k
      man = j
  t[i] = man + 1
  RD[man] = 0

ans = rieshon()
while time.time() - startTime < 1.8:
  n = random.randrange(3)
  if n == 1:
    d = random.randrange(D) + 1
    q = random.randrange(26) + 1
    if t[d - 1] == q: continue
    ans = gaochan(d, q)
  else:
    l = random.randrange(min(D - 1, 13)) + 1
    d = random.randrange(D - l) + 1
    p = t[d - 1]
    q = t[d + l - 1]
    if p == q: continue
    ans = parunyasu(d, d + l, p, q)

for i in range(D):
  print(t[i])


Measured memory_bytes: 85452
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        d: i64,
    }
    let v = vec![
        a*c,
        a*d,
        b*c,
        b*d
    ];
    println!("{}", v.iter().max().unwrap());
}


Measured memory_bytes: 2200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+4;
vector<ll> adj[N];
vector<vector<ll>> dp(N,vector<ll>(2));
const ll mod=1e9+7;
void dfs(ll u,ll p){
 dp[u][0]=1;
 dp[u][1]=1;
 for(ll v:adj[u]){
  if(v==p) continue;
  dfs(v,u);
  dp[u][0]=dp[u][0]*((dp[v][0]+dp[v][1])%mod)%mod;
  dp[u][1]=dp[u][1]*dp[v][0]%mod;
 }
}
int main(){
 ll n;
 cin>>n;
 for(ll i=1;i<n;i++){
  ll u,v;
  cin>>u>>v;
  adj[u].push_back(v);
  adj[v].push_back(u);
 }
 dfs(1,-1);
 cout<<(dp[1][0]+dp[1][1])%mod<<endl;
 return 0;
}

Measured memory_bytes: 18176
import collections

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

odd = []
even = []

for i in range(len(v)):
    if i % 2:
        even.append(v[i])
    else:
        odd.append(v[i])

odd = collections.Counter(odd)
even = collections.Counter(even)
max_odd = 0
max_odd2 = 0
max_even = 0
max_even2 = 0
for i in odd:
    if max_odd < odd[i]:
        max_odd2 = max_odd
        max_odd = odd[i]
        x = i
    elif max_odd2 < odd[i]:
        max_odd2 = odd[i]
    

for j in even:
    if max_even < even[j]:
        max_even2 = max_even
        max_even = even[j]
        y = j
    elif max_even2 < even[j]:
        max_even2 = even[j]

if x != y:
    print(n - max_odd - max_even)
else:
    print(min(n - max_odd - max_even2, n - max_odd2 - max_even))

Measured memory_bytes: 19160
N = int(input())
t = 0
ans = "Yes"
tasks = []
for i in range(N):
  tasks.append(list(map(int, input().split())))
tasks.sort(key=lambda task: task[1])
for task in tasks:
  t += task[0]
  if task[1] < t:
    ans = "No"
    break
print(ans)

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

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  int N, K;
  cin >> N >> K;
  if(K & 1) {
    ll res = 0;
    FOR(i, 1, N) {
      if(i % K == 0) {
        res++;
      }
    }
    ll ans = pow(res, 3);
    cout << ans << endl;
  } else {
    ll res1 = 0;
    ll res2 = 0;
    FOR(i, 1, N) {
      if(i % K == 0) {
        res1++;
      }
      if(i % K == K / 2) {
        res2++;
      }
    }
    ll ans = pow(res1, 3) + pow(res2, 3);
    cout << ans << endl;
  }
  return 0;
}


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


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

  vector<int> L(N);
  vector<int> place(N);
  int count=1;

  for(int i=0;i<N;i++){
    cin >> L.at(i);
  }

   /* for(int i=0;i<N;i++){
    cout << L.at(i);
  }*/

  place.at(0)=L.at(0);
  for(int i=1;i<N;i++){
    place.at(i)=place.at(i-1)+L.at(i);
 //  cout << place.at(i) <<endl;

  }
  for(int i=0;i<N;i++){
        if(place.at(i)<=X){
      count++;
    }
  }

  cout <<count<< endl;


  }










Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}
  
/*------------------------------------------------------------------*/
  
int main(){
    int w, h, x, y; cin >> w >> h >> x >> y;
    if(2 * x == w and 2 * y == h){
        cout << double(w) * double(h) / 2 << " " << 1 << endl;
    }else{
        cout << double(w) * double(h) / 2 << " " << 0 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define fr(i,a,b) for(ll i=a;i < b;i++)
#define fe(i,a,b) for(ll i=a;i <= b;i++)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fir first
#define sec second
#define tr(it,x) for(auto it = x.begin();it != x.end();it++)
#define mp make_pair
#define sz(x) (ll)x.size()
#define rep(i,n) for(ll i=0;i<n;i++)
#define double long double
#define accuracy ll precision = numeric_limits<double>::digits10
#define pll pair<ll,ll>
#define MAXN 100005
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define case(x) cout<<"Case #"<<x+1<<": "
#define endl "\n"
#define preturn(X) cout<<(X)<<endl; return 0
const int MOD = 1e9+7;
ll powmod(ll a,ll b,ll m=MOD){ll r=1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}
ll power(ll a,ll b){ll r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
ll gcd(ll a,ll b){if(!b)return a;return gcd(b,a%b);}
ll inv(ll a, ll m = MOD){return powmod(a,m-2,m);}
ll lcm(ll a,ll b){return(a*b)/gcd(a,b);}

inline void minself(int &a, int b){
    a = min(a,b);
}


int32_t main(){
       int N,W;
       cin>>N>>W;
       int lim = 1e5 + 1;
       vector<int> dp(lim+1,MOD);
       dp[0] = 0;
       // MIN weight for given value
       rep(i,N){
           int w,v;
           cin>>w>>v;
           for(int val = lim - v; val >= 0; val--){
               minself(dp[val + v],dp[val] + w);
           }
       }
       for(int val = lim; val >= 0; val--){
           if(dp[val] <= W){
               cout<<val<<endl;
               return 0;
           }
       }
}

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

typedef long long ll;
const int INF = 1e9;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	ll d;
	cin>>n>>d;
	d *= d;
	int ans = 0;
	for (int i = 0; i < n; i++){
		ll x, y;
		cin>>x>>y;
		if (x * x + y * y <= d){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

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

As = [int(i) for i in input().split(" ")]


current_max_height = 0


need_height = 0
for i in range(N):

    if As[i] > current_max_height:
        current_max_height = As[i]

    need_height += current_max_height - As[i]

print(need_height)

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

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

    bool jdg=true;

    reverse(s.begin(),s.end());
    for (int i=0;i<s.size();){
        if(s.substr(i,5)=="maerd"||
                s.substr(i,5)=="esare"){
            i+=5;
        }
        else if(s.substr(i,6)=="resare"){
            i+=6;
        }
        else if(s.substr(i,7)=="remaerd"){
            i+=7;
        }
        else {
            jdg=false;
            break;
        }
    }
    if(jdg){
        cout<<"YES"<<endl;
    }
    else {
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 640
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int, readline().split()))

four = len([a for a in A if a%4 == 0])
two = len([a for a in A if a%2 == 0]) - four
one = N - four - two

ans = 'No'
if two:
    one += 1
N = one + four
if N//2 <= four:
    ans = 'Yes'

print(ans)

Measured memory_bytes: 96356
N,K,Q = list(map(int , input().split()))
As = [int(input()) for _ in range(Q)]

#特典初期設定
Score = [0 for _ in range(N)]

for A in As:
    Score[A-1] +=1

for ans in Score:
    if(K + ans - Q > 0):
        print("Yes")
    
    else:
        print("No")


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

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

bool isprime(ll val) {
    if (val <= 1)return false;
    for (ll i = 2; i*i <= val; i++) {
        if (val%i == 0LL)return false;
    }
    return true;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    ll a,b;
    cin>>a>>b;
    ll g = gcd(a,b);
    if(isprime(a) || isprime(b) || a==1 || b==1){
        if(a==b && a!=1){
            cout << 2 << endl;
            return 0;
        }
        cout << 1 << endl;
        return 0;
    }
    ll ans = 1;
    for(ll i=1;i*i<=g;i++){
        if(g%i==0){
            if(isprime(i)) ans++;
            if(i*i!=g && isprime(g/i)) ans++;
        }
    }
    cout << ans << endl;



}

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

using namespace std;
 
#define PB(x)	push_back(x)
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP(x)	make_pair(x)
 
#define debug(_x)		cerr << #_x << '=' << _x << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << _x << ' ' << #_y << '=' << _y << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << _x << ' '; cerr << endl;

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX;
const int NINF = LONG_LONG_MIN/2;

//MODULAR ARITHMATIC
const int mmod = 1000000007 ;

//ADD
int add(int a, int b, int m=mmod) {
	a += b;
	a %= m;
	return a;
}

//SUB
int sub(int a, int b, int m=mmod) {
    return (a%m - b%m + m)%m;
}

//MUL
int mul(int a, int b, int m=mmod) {
	return ((a%m) * (b%m) % m);
}

//POW
int pow(int a, int b, int m=mmod) {
    a %= m;
    int r = 1;
    while (b) {
		if (b&1) r = r*a%m;
		b >>= 1;
		a = a*a%m;
    }
    return r;
}

//INV
int inv(int a, int m=mmod) {
	return pow(a, m-2, m);
}

int32_t main() {
	FAST_IO;
	
	int n, k;
	cin >> n >> k;
	
	int ans = 0;
	for (int i = k; i <= n+1; i++) {
		ans = add(ans, sub(sub(n*(n+1)/2,(n-i)*(n-i+1)/2), (i*(i-1)/2-1)));
	}
	cout << ans << endl;
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined


Measured memory_bytes: 3640
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int A = nextInt();
		int B = nextInt();

		if(A>=13)out.println(B);
		else if(A>=6)out.println(B/2);
		else out.println(0);

		sc.close();
	}

	private static int nextInt() {
		return Integer.parseInt(next());
	}
	private static long nextLong() {
		return Long.parseLong(next());
	}
	private static String next() {
		return sc.next();
	}
}

Measured memory_bytes: 24020
from itertools import groupby

def calc(time):
  t = 0
  for i in range(h):
    gr = groupby(g[i])
    lst = []
    p = 0
    for key,it in gr:
      j = len(list(it))
      lst.append([p,key,j])
      p += j
    for j in range(len(lst)):
      if lst[j][1] == -1:
        continue
      if lst[j][2] >= K:
        t += (2**time)*lst[j][1]*lst[j][2]
        for k in range(lst[j][0],lst[j][0]+lst[j][2]):
          g[i][k] = 0

  return t

def flatten():
  for j in range(w):
    lst = []
    for i in range(h-1, -1, -1):
      if g[i][j] > 0:
        lst.append(g[i][j])

    lst += [-1] * (h - len(lst))

    for i in range(h-1, -1, -1):
      g[i][j] = lst[h-i-1]

h,w,K = map(int,input().split())
mat = [ [int(e) for e in list(input())] for _ in range(h) ]

res = 0
for i in range(h):
  for j in range(w):
    score = 0
    g = [ [ mat[n][m] for m in range(w) ] for n in range(h) ]
    g[i][j] = -1
    time = 0
    flatten()
    while True:
      s = calc(time)
      if s==0: break
      score += s
      flatten()
      time += 1
    res = max(res, score)

print(res)


Measured memory_bytes: 77328
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <random>

#include <ctime>
#include <cmath>
#include <cassert>

using namespace std;

mt19937 rng(735);

const long long INF = 4e18;
const long long inf = 1e9 + 7;

const long long P = 6666622222487;
const long long Q = 150001;

template <typename T>
T sqr(T x) {
    return x * x;
}

long long powmod(long long x, long long a, long long mod) {
    return (a <= 0) ? 1 : (((a % 2) ? (x * powmod(x, a - 1, mod)) : sqr(powmod(x, a / 2, mod))) % mod);
}

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

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

    int A, B, C;
    cin >> A >> B >> C;
    int max_num = max(A, max(B, C));
    if (max_num % 2 != (A + B + C) % 2) max_num++;
    cout << (3 * max_num - A - B - C) / 2 << endl;
    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define foi(i,k,n) for (int i = (int)k; i < (int)n; ++i)

using namespace std;
using ii = pair<int,int>;
using ll = long long;

constexpr int MAXN = 5 + 100000;
ll a1[MAXN], a2[MAXN], a3[MAXN];

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  int x,y,a,b,c; cin >> x >> y >> a >> b >> c;

  foi (i,0,a) cin >> a1[i];
  foi (i,0,b) cin >> a2[i];
  foi (i,0,c) cin >> a3[i];

  sort(a1, a1 + a, greater<ll>());
  sort(a2, a2 + b, greater<ll>());
  sort(a3, a3 + c, greater<ll>());

  multiset<ll> r1, r2;
  foi (i,0,x) r1.insert(a1[i]);
  foi (i,0,y) r2.insert(a2[i]);

  foi (i,0,c) {
    ll d1 = a3[i] - *r1.begin(), d2 = a3[i] - *r2.begin();
    if (d1 <= 0 && d2 <= 0) break;
    if (d1 >= d2) {
      r1.erase(r1.begin());
      r1.insert(a3[i]);
    } else {
      r2.erase(r2.begin());
      r2.insert(a3[i]);
    }
  }

  ll ans = 0;
  for (auto p : r1) ans += p;
  for (auto p : r2) ans += p;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 11008
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const int mod=998244353;
int main(){
    ll m,k;cin>>m>>k;
    if(k==0){
        rep(i,1<<m){
            cout<<i<<' '<<i<<' ';
        }
        cout<<endl;
        return 0;
    }
    if((1<<m)<=k||(m==1&&k==1)){
        cout<<-1<<endl;
        return 0;
    }
    cout<<0<<' '<<k<<' '<<0<<' ';
    REP(i,1,1<<m){
        if(i!=k)cout<<i<<' ';
    }
    cout<<k<<' ';
    for(int i=(1<<m)-1;i>0;i--){
        if(i!=k)cout<<i<<' ';
    }
    cout<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <stack>

using namespace std;

vector<int> a[100000];
int b[100000];
signed main(void)
{
  int v, e;
  cin >> v >> e;
  long long i;
  for(i = 0;i < e; ++i){
    int s, t;
    cin >> s >> t;
    a[s].push_back(t);
    b[t]++;
  }

  stack<int> st;

  for(i = 0; i < v; ++i){
    if(b[i] == 0) st.push(i);
  }
  vector<int> ans;

  while(st.size()) {
    int i = st.top(); st.pop();
    ans.push_back(i);
    for(auto& j: a[i]) {
      b[j]--;
      if(b[j] == 0) st.push(j);
    }
  }

  if (ans.size() == v) {
		cout << "0" << endl;
	}
	else {
		cout << "1" << endl;
	}

  return 0;
}



Measured memory_bytes: 5524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
 
int main(){
	ll A,B;
    cin>>A>>B;
    if(A==B)cout<<"Draw";
    else if(A==1)cout<<"Alice";
    else if(B==1)cout<<"Bob";
    else if(A>B) cout<<"Alice";
    else if(A<B) cout<<"Bob";
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
vector <int> des[500010];
int fa[500010];
int dfs(int s)
{
	if (des[s].size()==0) return 0;
	vector <int> vec;int ans=0;
	for (int k=0;k<des[s].size();k++) vec.push_back(dfs(des[s][k]));
	sort(vec.begin(),vec.end());
	for (int i=0;i<vec.size();i++) ans=max(ans,vec[i]+(int)vec.size()-i);
	return ans;
}
int main()
{
	int n;scanf("%d",&n);
	for (int i=2;i<=n;i++)
	{
		scanf("%d",&fa[i]);
		des[fa[i]].push_back(i);
	}//cout<<dfs(2)<<endl;
	printf("%d\n",dfs(1));
}

Measured memory_bytes: 23296
#include<bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
 
#define ulli unsigned long long int
 
#define Pi 3.14159265358979323846264338327950288419716939937510
 
int main(){
   
    ios :: sync_with_stdio(false);
   
    //ifstream cin; ofstream cout; cin.open("input.txt"); cout.open("output.txt");
    
    int n;
    
    cin>>n;
    
    cout<<n/2+(n%2);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
typedef long long ll;

template <class S> int LevenshteinDistance(const S &A, const S &B) {
   vector< vector<int> > dist(A.size()+1,vector<int>(B.size()+1));
   for (int i = 0; i <= A.size(); i++) dist[i][0] = i;
   for (int i = 0; i <= B.size(); i++) dist[0][i] = i;
   for (int i = 0; i < A.size(); i++) {
      for (int j = 0; j < B.size(); j++) {
         dist[i+1][j+1] = min(dist[i][j+1], dist[i+1][j]) + 1;
         dist[i+1][j+1] = min(dist[i+1][j+1], dist[i][j] + (A[i]!=B[j]));
      }
   }
   return dist[A.size()][B.size()];
}

int main() {

  string A,B; cin >> A >> B;

  cout << LevenshteinDistance(A,B) << endl;

  return 0;
}

Measured memory_bytes: 6844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String s2 = sc.next();
		String s3 = sc.next();
		System.out.println(""+s.charAt(0)+s2.charAt(1)+s3.charAt(2));
	}
}

Measured memory_bytes: 21076
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
    char n[100],i,p=0;



    scanf("%s",&n);

    p=strlen(n);
    if(p==1){
    if(n[0]=='2'||n[0]=='4'||n[0]=='5'||n[0]=='7'||n[0]=='9'){
        printf("hon\n");
        }

        else if(n[0]=='0'||n[0]=='1'||n[0]=='6'||n[0]=='8'){
            printf("pon\n");
            }

            else printf("bon\n");


    }
    if(p==2){
         if(n[1]=='2'||n[1]=='4'||n[1]=='5'||n[1]=='7'||n[1]=='9'){
            printf("hon\n");
        }
         else if(n[1]=='0'||n[1]=='1'||n[1]=='6'||n[1]=='8'){
            printf("pon\n");
        }
        else printf("bon\n");
    }

        if(p==3){
            if(n[2]=='2'||n[2]=='4'||n[2]=='5'||n[2]=='7'||n[2]=='9'){
            printf("hon\n");
        }
         else if(p==3&&(n[2]=='0'||n[2]=='1'||n[2]=='6'||n[2]=='8')){
            printf("pon\n");
        }

        else printf("bon\n");
        }



    return 0;
}


Measured memory_bytes: 1664
from fractions import gcd

lcm = lambda x, y: x*y // gcd(x, y)

a, b, c, d = map(int, input().split())

b_ = b
b_ -= b // c
b_ -= b // d
b_ += b // lcm(c, d)

a -= 1
a_ = a
a_ -= a // c
a_ -= a // d
a_ += a // lcm(c, d)


print(b_ - a_)


Measured memory_bytes: 5048
#!/usr/bin/env python3
import sys

from bisect import bisect_left, bisect_right



def solve(N: int, L: "List[int]"):
    ans = 0
    L.sort()

    for x in range(N):
        for y in range(x+1,N):
            ze = bisect_left(L, L[x]+L[y])            
            ans += (ze-y-1)
            
    print(ans)

    return
 


# Generated by 1.1.6 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():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1e18;

int main() {
  //
  ll n;
  cin >> n;
  string s;
  cin >> s;
  vl b(n, 0), w(n, 0);
  if (s[0] == '#') {
    b[0] = 1, w[0] = 0;
  } else {
    b[0] = 0, w[0] = 1;
  }
  REP(i, 1, n) {
    if (s[i] == '#') {
      b[i] = b[i - 1] + 1;
      w[i] = w[i - 1];
    } else {
      w[i] = w[i - 1] + 1;
      b[i] = b[i - 1];
    }
  }
  ll ans = w[n - 1];
  rep(i, n) { ans = min(ans, b[i] + w[n - 1] - w[i]); }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3708
#ifndef COMPETITIVE_HEADER
    #pragma GCC optimize ("Ofast")
    #ifdef ONLINE_JUDGE
        #pragma GCC target ("avx512f")
    #else
        #pragma GCC target ("avx")
    #endif
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #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 REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;
#endif

int n;
string s;
bool left_have[10][30000], right_have[10][30000];
set<int> ans;

signed main(){
    cin >> n;
    cin >> s;
    REP(i,n){
        int c = s[i] - '0';
        if (!left_have[c][i]) FOR(j,i+1,n) left_have[c][j] = 1;
    }
    REPN(i,n){
        int c = s[i] - '0';
        if (!right_have[c][i]) REP(j,i) right_have[c][j] = 1;
    }
    REP(i,n){
        int c = s[i] - '0';
        REP(l,10) REP(r,10) 
            if (left_have[l][i] && right_have[r][i]) 
                ans.insert(l*100+c*10+r);
    }
    // for(auto p : ans) cerr << p << ", "; cerr << endl;
    cout << sz(ans) << endl;
}

Measured memory_bytes: 4256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  pll a[n+1],b[n+1];
  for(ll i=1;i<=n;i++) {
    cin >> a[i].first;
    a[i].second=i;
  }
  for(ll i=1;i<=n;i++) {
    cin >> b[i].first;
    b[i].second=i;
  }
  sort(a+1,a+n+1);
  sort(b+1,b+n+1);
  vec p(n+1);
  for(ll i=1;i<=n;i++) {
    if(a[i].first>b[i].first) {
      cout << "No" << endl;
      return 0;
    }
    p[a[i].second]=b[i].second;
  }
  for(ll i=1;i<n;i++) {
    if(a[i+1].first<=b[i].first) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  ll x=1;
  ll cnt=0;
  do cnt++,x=p[x]; while(x!=1);
  if(cnt==n) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 6988
#include<stdio.h>
int main()
{
    long long a,b;
    while(scanf("%lld %lld",&a,&b)==2)
    {
        long long c=0,s=0;
        c=a+b;
        while(c!=0)
        {
          c/=10;
          s++;
        }
        printf("%lld\n",s);
    }
}

Measured memory_bytes: 1028
#include <iostream>
int N;
int a[80];

int find_locallow(int idx){
  for(int i=idx;i<N-1;i++){
    if(a[i]<a[i+1])return i;
  }
  return -1;
}

int find_localhigh(int idx){
  int i;
  for(i=idx;i<N-1;i++){
    if(a[i]>a[i+1])break;
  }
  return i;
}



int main(void){
  long long int money=1000;
  long long int kabu=0;
  std::cin>>N;
  for(int i=0;i<N;i++){
    std::cin>>a[i];
  }
  for(int i=0;i<N;i++){
    int buy=find_locallow(i);
    if(buy==-1)break;
    {
      kabu+=money/a[buy];
      money-=(money/a[buy])*a[buy];
      i=buy;
    }
    int sell=find_localhigh(i);
    {
      money+=a[sell]*kabu;
      kabu=0;
      i=sell;
    }    
  }
  std::cout<<money<<std::endl;
  
  return 0;
}


Measured memory_bytes: 3628
N = int(input())
if N % 2 == 1:
    odd = 1
else:
    odd = 0
L = [list(map(int, input().split())) for _ in range(N)]

L.sort()
A = [L[i][0] for i in range(N)]
if odd:
    minres = A[(N - 1) // 2]
else:
    minres = A[(N - 2) // 2] + A[N // 2]

L.sort(key=lambda x: x[1])
B = [L[i][1] for i in range(N)]
if odd:
    maxres = B[(N - 1) // 2]
else:
    maxres = B[(N - 2) // 2] + B[N // 2]

print(maxres - minres + 1)


Measured memory_bytes: 128200
N, K = (raw_input()).split()
N = int(N)
K = int(K)

candles = map(int, raw_input().split())

cumsum_candles = [0]
for i in range(1, len(candles)):
    cumsum_candles.append(candles[i] - candles[0])

zero_idx = 0
for i in range(len(candles)):
    if candles[i] <= 0:
        zero_idx = i

min_time = 10000000000000

low_itr = 0
up_itr = zero_idx

while low_itr <= up_itr and up_itr < len(candles):
    if up_itr-low_itr+1 > K:
        low_itr += 1
    elif up_itr-low_itr+1 < K:
        up_itr += 1
    else :
        time = cumsum_candles[up_itr] - cumsum_candles[low_itr]

        if zero_idx != low_itr or zero_idx != up_itr or K==1:
            min_time = min(min_time, time+abs(candles[up_itr]), time+abs(candles[low_itr]))
        else:
            min_time = min(min_time, time)

        low_itr += 1
        up_itr += 1

print min_time


Measured memory_bytes: 13600