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

int main() {
  int Q; cin >> Q;
  while(Q--) {
    int N; cin >> N;
    int res = 0;
    set<int> s;
    while(N >= 10) {
      string n;
      {
        stringstream ss; ss << N;
        n = ss.str();
      }
      int maxi = -1;
      for(int i = 1; i < n.size(); ++i) {
        string a = n.substr(0, i);
        string b = n.substr(i);
        int x = atoi(a.c_str()) * atoi(b.c_str());
        maxi = max(maxi, x);
      }
      N = maxi;
      if(s.count(N)) {
        res = -1; break;
      }
      s.insert(N);
      ++res;
    }
    cout << res << endl;
  }
  return 0;
}

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

using namespace std;

#define int long long

const int MOD = 1e9 + 7;

int add(int a, int b) {
	return (a + b) % MOD;
}

int mul(int a, int b) {
	return (a * b) % MOD;
}

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

    int N, K;

    cin >> N >> K;

    int r;

    r = N%K;

    cout << min(K-r, r) << endl;

    return 0;
}


Measured memory_bytes: 384
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

def binarySearch(A, key, n):
    left = 0
    right = n
    while left < right:
        mid = (left + right) // 2
        if A[mid] == key:
            return 1
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return 0

C = 0
for t in T:
    if binarySearch(S, t, n):
        C += 1
print(C)


Measured memory_bytes: 16712
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
 
using namespace std;
 
const int MAXN=100010;
char s[MAXN];
 
int main()
{
	scanf("%s",s+1);
	int len=strlen(s+1);
	int ans=0;
	int start=1,end=len;
	while (start<end)
	{
		if (s[start]==s[end])
		{
			start++;
			end--;
		}
		else if (s[start]=='x')
		{
			ans++;
			start++;
		}
		else if (s[end]=='x')
		{
			ans++;
			end--;
		}
		else 
		{
			cout<<-1;
			return 0;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
long long dp[60][60][2600];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	dp[0][0][0]=1;
	for(int i=0;i<a;i++){
		for(int j=0;j<=i;j++){
			for(int k=0;k<=b;k++){
				if(!dp[i][j][k])continue;
				if(j&&k+j*2<=b){
					dp[i+1][j][k+j*2]=(dp[i+1][j][k+j*2]+dp[i][j][k]*(2*j))%mod;
				}
				dp[i+1][j][k+j*2]=(dp[i+1][j][k+j*2]+dp[i][j][k])%mod;
				if(j&&k+(j-1)*2<=b){
					dp[i+1][j-1][k+j*2-2]=(dp[i+1][j-1][k+j*2-2]+dp[i][j][k]*(j)*(j))%mod;
				}
				if(k+(j+1)*2<=b){
					dp[i+1][j+1][k+j*2+2]=(dp[i+1][j+1][k+j*2+2]+dp[i][j][k])%mod;
				}
			}
		}
	}
	printf("%lld\n",dp[a][0][b]);
}

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

int solve(vector<int> s) {
	int n = s.size();
	int ans = 0;
	for(int i = 0; i < n; ++i) if(((i) & (n - 1)) == (i)) {
		ans ^= s[i];
	}
	return ans;
}

int main() {
	int n; cin >> n;
	string s;
	cin >> s;
	vector<int> a(n);
	for(int i = 0; i < n; ++i) a[i] = s[i] - '1';
	
	vector<int> odds = a;
	for(int i = 0; i < n; ++i) odds[i] %= 2;
	if(solve(odds) == 0) { // ans = 0 / 2
		bool has1 = false;
		for(int i = 0; i < n; ++i) if(a[i] == 1) has1 = true;
		if(has1) cout << 0 << endl;
		else {
			for(int i = 0; i < n; ++i) a[i] /= 2;
			if(solve(a) == 0) cout << 0 << endl;
			else cout << 2 << endl;
		}
	} else {
		cout << 1 << endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 13060
N,Y = map(int,input().split())

ans = [-1,-1,-1]
for i in range(0,N+1,1):
    for j in range(0,N+1-i,1):
        k = N-i-j
        if i*10000 + 5000*j + 1000*k == Y:
            ans = [i,j,k]
            break

print(ans[0],ans[1],ans[2])


Measured memory_bytes: 66152
moji_list = input()
ADGT = ["A","C","G","T"]

def count(moji_list,i,cnt,ADGT):
  while moji_list[i] in ADGT:
    cnt+=1
    if i+1 == len(moji_list):
      break
    i+=1
    
  return cnt

cnt_list = []
for i in range(len(moji_list)):
  cnt=0
  cnt_list.append(count(moji_list,i,cnt,ADGT))
  
print(max(cnt_list))

Measured memory_bytes: 3064
import heapq

n = int(input())
A = [int(x) for x in input().split()]
A_rev = [-x for x in A[::-1]]

def get_sum_list(A):
  h = []
  result = []
  current_sum = 0
  for i,a in enumerate(A[:2*n]):
    heapq.heappush(h,a)
    current_sum += a
    if i >= n:
      m = heapq.heappop(h)
      current_sum -= m
    if i >= n-1:
      result.append(current_sum)
  return result

from_left = get_sum_list(A)
from_right = get_sum_list(A_rev)

ans = -10**18
for i in range(n+1):
  score = from_left[i] + from_right[n-i]
  if ans < score:
    ans = score
    
print(ans)

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


int main(void){
  string S;
  cin >> S;
  int flag = 0;
  if(S[0] != 'A') cout << "WA";
  
  else{
    for(int i = 1; i < S.length(); i++){
      if(i >= 2 && i <= S.length() - 2
         && S[i] == 'C'){
        if(flag == 0) flag = 1;
        else{
          cout << "WA";
          return 0;
        }
      }
      else if(isupper(S[i])){
        cout << "WA";
        return 0;
      }
    }
    if(flag == 0) cout << "WA";
    else    cout << "AC";
  }
 return 0; 
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a < 0 && b < 0){
    cout << a*b << endl;
    return 0;
  }
  if(a < 0){
    cout << a+b << endl;
  }
  else if(b < 0){
    cout << a-b << endl;
  }
  else{
    cout << max(a+b,a*b) << endl;
  }
}


Measured memory_bytes: 256
import math
tem = input().split()
a = int(tem[0])
b = int(tem[1])
x = int(tem[2])

if x >= a*a*b/2:
    flag = 1
else:
    flag = 0

if flag ==1:
    #print('debug')
    sq = a*a*b - x
    #print(sq)
    x = sq * 2 / (a*a)
    result = math.degrees(math.atan(x/a))
elif flag ==0:
    #print('aaa')
    sq = x
    x = sq * 2 /(a*b)
    result = math.degrees(math.atan(b/x))

print(result)


Measured memory_bytes: 3060
#include <cstdio>
#include <complex>
using namespace std;

typedef complex<double> P;

double dot(P a, P b){
	return real(a) * real(b) + imag(a) * imag(b);
}

int main(){
	P p[3];
	double x, y;
	while(1){
		for(int i = 0; i < 3; ++i){
			if(scanf("%lf,%lf,", &x, &y) == EOF){
				return 0;
			}
			p[i] = P(x, y);
		}
		
		P d = p[0] - p[1];
		P ans = 2.0 * (p[0] - dot(p[0] - p[2], d) / norm(d) * d) - p[2];
		printf("%f %f\n", real(ans), imag(ans));
	}
}

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

const int MAXN = 5e3 + 5;
const int MOD = 1e9 + 7;

int N;
int ways[MAXN];
vector <int> adj[MAXN], ch[MAXN];
int dp[MAXN][MAXN][2], tmp[MAXN][2][2];
int subtree[MAXN];

void load() {
	scanf("%d", &N);
	for (int i = 1; i < N; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
}

inline int add(int x, int y) {
	x += y;
	if (x >= MOD)	
		x -= MOD;
	else if (x < 0)
		x += MOD;
	return x;
}

inline void inc(int &x, int y) {
	x = add(x, y);
}

inline int mul(int x, int y) {
	return (long long)x * y % MOD;
}

int dfs(int x, int p) {
	subtree[x] = 1;
	for (auto it : adj[x])
		if (it != p) {
			subtree[x] += dfs(it, x);
			ch[x].push_back(it);
		}
	return subtree[x];	
}

void init(int c) {
	for (int i = 0; i <= N; i++)
		for (int k = 0; k < 2; k++)
			tmp[i][k][c] = 0;
}

void calc(int x, int p) {
	for (auto it : ch[x])
		calc(it, x);
	
	init(0);
	tmp[0][0][0] = 1;
	
	int pref = 0, c = 0;
	for (auto it : ch[x]) {
		c ^= 1;
		init(c);
		for (int i = 0; i <= pref; i++)
			for (int k = 0; k < 2; k++)
				for (int j = 0; j <= subtree[it]; j++)
					for (int l = 0; l < 2; l++)
						inc(tmp[i + j][(k + l + !j) % 2][c], mul(tmp[i][k][c ^ 1], dp[it][j][l]));
		pref += subtree[it];
	}
	
	for (int i = 0; i < subtree[x]; i++)
		for (int k = 0; k < 2; k++) {
			dp[x][i + 1][k] = tmp[i][k][c];
			if (i % 2)
				inc(dp[x][0][k], mul(dp[x][i + 1][k], ways[i + 1]));
		}
}

int solve() {
	ways[0] = 1;
	for (int i = 2; i <= N; i += 2)
		ways[i] = mul(ways[i - 2], i - 1);
		
	dfs(1, 0);
	calc(1, 0);
	
	return add(dp[1][0][0], -dp[1][0][1]);
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;
}

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

int gcd(int x,int y){return (x%y) ? gcd(y,x%y) : y;}

int main(){
  int n,sum=0;
  cin >> n;
  
  for(int i=1;i<n+1;i++){
    for(int j=1;j<n+1;j++){
      for(int k=1;k<n+1;k++){
        sum+=gcd(i,(gcd(j,k)));
      }
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main() {
  int K, A, B;
  cin >> K >> A >> B;
  int a = 0;
  while(true) {
    if(K * a >= A && K * a <= B) {
      cout << "OK" << endl;
      return 0;
    } else if(K * a > B) {
      cout << "NG" << endl;
      return 0;
    }
    
    a++;
  }
  return 0;
}

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

typedef long long ll;
const int mod = 1e9 + 7;

ll N;
vector<ll> p;

int main() {
    cin >> N;
    p.resize(N);
    rep(i, N) cin >> p[i];

    ll sum = 1;
    ll min_x = p[0], max_x = p[0];
    
    for (ll i = 1; i <= N - 1; i++) {
        if (p[i] <= min_x) sum++;
        min_x = min(min_x, p[i]);
        max_x = max(max_x, p[i]);
    }

    cout << sum << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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やllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------
vector<int> div(int x){
  vector<int> vec;
  for(ll i=1; i*i<=x; i++){
    if(x%i==0){
      vec.push_back(i);
      if(x/i != i) vec.push_back(x/i);
    }
  }
  sort(vec.begin(),vec.end());
  return vec;
}

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  vector<int> vec;
  vec = div(A[0]);
  int ans = 1;
  for(int d: vec){
    int cnt = 0;
    for(int i=1; i<N; i++){
      if(A[i]%d != 0){
        cnt++;
      }
    }
    if(cnt <= 1){
      chmax(ans,d);
    }
  }
  vec = div(A[1]);
  for(int d: vec){
    int cnt = 0;
    for(int i=0; i<N; i++){
      if(A[i]%d != 0){
        cnt++;
      }
    }
    if(cnt <= 1){
      chmax(ans,d);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int n;
int cnt[4];
string str;

int main(){
	memset(cnt, 0, sizeof(cnt));
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		cin >> str;
		if(str == "AC") cnt[0]++;
		else if(str == "WA") cnt[1]++;
		else if(str == "TLE") cnt[2]++;
		else if(str == "RE") cnt[3]++;
	}
	printf("AC x %d\n", cnt[0]);
	printf("WA x %d\n", cnt[1]);
	printf("TLE x %d\n", cnt[2]);
	printf("RE x %d\n", cnt[3]);
	return 0;
}

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

using namespace std;
long long x[10000010], y[10000010];
#define rep(i, n) for (int i = 0; i < (n); i++)
#define lep(j, n) for (int j = 0; j < (n); j++)
#define reps(i, n) for (int i = 1; i < (n); i++)
#define leps(i, n) for (int j = 1; j < (n); j++)
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define int long long
#define gsort(x, n) sort((x), (x) + (n), greater<int>());
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

signed main()
{

   cin.tie(0);
   ios::sync_with_stdio(false);

   int a, b, c;
   cin >> a >> b >> c;
   int n = max(a, b);
   int m = min(a, b);
   cout << max(n, c) - min(m, c) << '\n';
}

Measured memory_bytes: 256
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

def fft_convolve(f, g):
    """
    数列 (多項式) f, g の畳み込みの計算．上下 15 bitずつ分けて計算することで，
    30 bit以下の整数，長さ 250000 程度の数列での計算が正確に行える．
    """
    Lf, Lg = f.shape[-1], g.shape[-1]
    L = Lf + Lg - 1
    fft_len = 1 << L.bit_length()
    fh, fl = f >> 15, f & (1 << 15) - 1
    gh, gl = g >> 15, g & (1 << 15) - 1

    def conv(f, g):
        Ff = np.fft.rfft(f, fft_len)
        Fg = np.fft.rfft(g, fft_len)
        h = np.fft.irfft(Ff * Fg)
        return np.rint(h)[..., :L].astype(np.int64) % MOD

    x = conv(fl, gl)
    z = conv(fh, gh)
    y = conv(fl + fh, gl + gh) - x - z
    return (x + (y << 15) + (z << 30)) % MOD

def coef_of_generating_function(P, Q, N):
    """compute the coefficient [x^N] P/Q of rational power series.

    Parameters
    ----------
    P : np.ndarray
        Numerator.
    Q : np.ndarray
        Denominator
        Q[0] == 1 and len(Q) == len(P) + 1 is assumed.
    N : int
        The coefficient to compute.
    """
    assert Q[0] == 1 and len(Q) == len(P) + 1

    def convolve(f, g):
        return fft_convolve(f, g)

    while N:
        Q1 = np.empty_like(Q)
        Q1[::2] = Q[::2]
        Q1[1::2] = MOD - Q[1::2]
        P = convolve(P, Q1)[N & 1::2]
        Q = convolve(Q, Q1)[::2]
        N >>= 1
    return P[0]

N = int(read())

P = np.array([1, -1, 0], np.int64)
Q = np.array([1, -1, 0, -1], np.int64)

print(coef_of_generating_function(P, Q, N))

Measured memory_bytes: 27292
#include <iostream>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1){
    	int n, x;
    	cin >> n >> x;
    	if(n == 0 && x == 0) break;
    	int ans = 0;
    	for(int i = 1; i <= n; i++){
    		for(int j = i+1; j <= n; j++){
    			int k = x - i - j;
    			if(j+1 <= k && k <= n) ans++;
    		}
    	}
    	cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3152
#include <stdio.h>

int main(void)
{
	int n, x, a[100];
	
	scanf("%d", &n);
	for(x = 0; x < n; x++){
		scanf("%d", &a[x]);
	}
	
	for(x = (n - 1); x >= 0; x--){
		printf("%d", a[x]);
		if(x > 0){
			printf(" ");
		}
	}
	printf("\n");
	
	return(0);
}



Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int h,w;
    cin >> h >> w;
    int a[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }    
    vector<pair<int,int>> ans[2];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(a[i][j]%2 == 1){
                if(i != h-1){
                    if(j+1 < w){
                        a[i][j]--;
                        a[i][j+1]++;
                        ans[0].push_back({i+1,j+1});
                        ans[1].push_back({i+1,j+2});
                    }
                    else{
                        a[i][j]--;
                        a[i+1][j]++;
                        ans[0].push_back({i+1,j+1});
                        ans[1].push_back({i+2,j+1});
                    }
                }
                else {
                    if(j+1 < w){
                        a[i][j]--;
                        a[i][j+1]++;
                        ans[0].push_back({i+1,j+1});
                        ans[1].push_back({i+1,j+2});
                    }
                }
            }
        }
    }
    cout << ans[0].size() << endl;
    for(int i = 0; i < ans[0].size(); i++){
        cout << ans[0][i].first << " " << ans[0][i].second << " ";
        cout << ans[1][i].first << " " << ans[1][i].second << endl;
    }
    return 0;
    
}

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

using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define debug(a) cout << #a << ": " << a << endl;

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;

  vector<ll> A(X);
  rep(i, X) { cin >> A[i]; }
  sort(A.begin(), A.end(), greater<ll>());
  vector<ll> B(X);
  rep(i, Y) { cin >> B[i]; }
  sort(B.begin(), B.end(), greater<ll>());
  vector<ll> C(X);
  rep(i, Z) { cin >> C[i]; }
  sort(C.begin(), C.end(), greater<ll>());

  vector<ll> AB;
  rep(x, X) rep(y, Y) { AB.push_back(A[x] + B[y]); }
  sort(AB.begin(), AB.end(), greater<ll>());
  vector<ll> ABC;
  rep(xy, min(K, (int)AB.size())) rep(z, Z) { ABC.push_back(AB[xy] + C[z]); }
  sort(ABC.begin(), ABC.end(), greater<ll>());

  for (int i = 0; i < (int)ABC.size() && i < K; i++) {
    cout << ABC[i] << endl;
  }
}


Measured memory_bytes: 43368
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}
const long long INFLL = 1LL << 60;
const int INF = 1 << 30;
const double PI = acos(-1);
int main()
{
	ll a;
	double b;
	cin >> a >> b;
	ll ans=a*ll(100.0*b+0.5);
	printf("%lld\n", ans / 100LL);
}


Measured memory_bytes: 3784
#!/usr/bin/python3

import sys
import re
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7

#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]

A, B = [x for x in input().split()]
S = input()

pat = '\d{{{}}}-\d{{{}}}'.format(A, B)
result = re.match(pat, S)

if result:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int main(){
    long int N,K;
    cin >> N >> K;
    long int ans = 0;
    if(K==0)
        ans=N*N;
    else{
        for (int b=K+1;b<=N;b++){
            int rem, quo;
            rem = N % b;
            quo = N / b;
            if (rem >= K)
                ans += (b-K) * quo + (rem-K+1);
            else
                ans += (b-K) * quo;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>

#define num_day 5000000000000000 // 5 x 10^15

char buf[102];
long long K;

int retnum( char c )
{
    return c - '0';
}

int main()
{
    fgets( buf, 102, stdin );
    scanf(" %lld", &K );

    int ans = 1;

    for ( int i=0; i<K ;i++ ) {
        if ( buf[i] < '0' || buf[i] > '9' ) break;

        if ( buf[i] != '1' ) { 
            ans = retnum(buf[i]);
            break;
        }
    }

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


Measured memory_bytes: 128
n=int(input())
a=[]
for i in range(n):
    x=int(input())
    a.append(x)
maxa=a[1]-a[0]
mina=a[0]
for i in range(1,n):
    if a[i]-mina>maxa:
        maxa=a[i]-mina    
    if a[i]<mina:
        mina=a[i]
print(maxa)


Measured memory_bytes: 13584
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime,random
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
VV = inpl()
CC = inpl()

ans = 0
for i in range(N):
    tmp = VV[i] - CC[i]
    if tmp > 0:
        ans += tmp
print(ans)


Measured memory_bytes: 5356
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define inf 1e10
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(int i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define veci vector<int>
#define vecl vector<long long>
#define FORI(a,b,c) for(int a=b;a<c;a++)
#define FORD(a,b,c) for(int a=b;a>c;a--)
#define adj(N) vector<vector<int>> ADJ(N+1)
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

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

	READV(N);
	READV(K);
	if(K==1)
	{
		cout<<0<<endl;
	}
	else
	{
		cout<<N-K<<endl;
	}

	return 0;
}

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

using namespace std;

int main() {

	long long a, b, k;
	cin >> a >> b >> k;

	if (k <= a) {
		cout << a - k << " " << b << endl;
		return 0;
	}
	else if (k <= a + b) {
		cout << 0 << " " << a+b-k << endl;
		return 0;
	}
	else {
		cout << 0 << " " << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  
  
  int a[3];
  int x;
  int i;
  
  for(i = 0; i< 3; i++){
    
    scanf("%d", &a[i]);
    
  }
  
  
    
    x = a[0]+a[1]+a[2];
    
  
  if(x<22){
    
    printf("win");
    
    
  }
  
  else {
    
    printf("bust");
    
    
  }
  
    
    
    
    
    
  return 0;
  
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define mod 1000000007LL
#define PI acosl(-1)

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve()
{
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;
	int mn = min({a, b, c, d, e});
	int mx = max({a, b, c, d, e});
	if (mx - mn > k)
	{
		// can not communicate
		cout << ":(";
	}
	else
	{
		// can communicate
		cout << "Yay!";
	}
}

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

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

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

#define roop(i, n) for(int i = 0;i < n;i++)
#define INF 1000000000

int main(void){

    string s;
    cin >> s;

    string tmp = "";

    int ans = INF;
    for(int i = 0;i < s.length()-2;i++){
        for(int j = 0;j < 3;j++){
            tmp += s[i+j];
        }
        ans = min(ans, abs(atoi(tmp.c_str())-753));
        tmp = "";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        n: usize,
    }

    if n%2==0{
        print!("{}", n/2);
    } else {
        println!("{}", n/2+1);
    }

}

Measured memory_bytes: 4352
import math
n=int(input())
x=[int(input()) for i in range(5)]

m=0
for i in range(5):
    if x[m]>x[i]:
        m=i
if m==0:
    print(5+math.ceil(n/x[0])-1)
else:
    print(5+math.ceil(n/x[m])-1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}
int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    if (b == 1) {
        cout << 0 << endl;
        return 0;
    }

    int ans = 1;
    int now = a;
    while (ans < 30) {
        if (now >= b) {
            cout << ans << endl;
            return 0;
        } else {
            ans++;
            now += a - 1;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	// your code goes here
	int c[30],i;
	int a[30]={0};
	char d[30];
	cin >> d;
	for(i=0;i<strlen(d);i++){
		c[i]=d[i]-'a';
		if(a[c[i]]>0){
			cout << "no" << endl;
			return 0;
		}
		a[c[i]]++;
	}
	cout << "yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define per(i,n) for(long long i = (long long)(n-1);i >= 0;--i)
#define REP(i,s,t) for(long long i=s;i<t;i++)
#define PER(i,s,t) for(long long i=s;i>t;--i)
#define all(x) x.begin(),x.end()
#define sp(n) setprecision(n)
typedef long long ll;
using namespace std;
int main(){
  ll n;
  cin>>n;
  vector<ll> a(100100),b(100100),c(100100);
  rep(i,n){cin>>a[i]>>b[i]>>c[i];}
  vector<vector<ll>> dp(100100,vector<ll>(3));
  dp[0][0]=a[0],dp[0][1]=b[0],dp[0][2]=c[0];//dp[i][j]=iまでで,最後がj
  REP(i,1,n){dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
             dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
             dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);}
  cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}

Measured memory_bytes: 8064
import sys

H, W = map(int, input().split())
S = [list(input()) for i in range(H)]
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]

for i in range(H):
    for j in range(W):
        if(S[i][j]=="."):
            continue
        exist = False
        for k in range(4):
            if(0<=i+dy[k]<H and 0<=j+dx[k]<W and S[i+dy[k]][j+dx[k]]=="#"):
                exist = True
        if(exist==False):
            print("No")
            sys.exit()     
print("Yes")

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int main()
{
	int i,j;
	char s[11],t[11]={};

	scanf("%s",s);

	for(i=0,j=0;s[i]!='\0';i++){
		if(s[i]=='B'){
			j--;
			j=j<0?0:j;
		}
		else
			t[j++]=s[i];
	}
	t[j]='\0';
	puts(t);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>


int maxIndex(int x[]) {
	int max = -10;
	int index = 0;
	for (int i = 0; i < 3;++i) {
		if (x[i] > max) {
			index = i;
			max = x[i];
		}
	}
	return index;
}

int main(){
	int abc[3];
	int k;

	for (int i = 0; i < 3; ++i) {
		scanf("%d", &abc[i]);
	}
	scanf("%d", &k);

	abc[maxIndex(abc)] = abc[maxIndex(abc)] * pow(2, k);

	int sum = 0;
	for (int i = 0; i < 3; ++i) {
		sum += abc[i];
	}

	printf("%d", sum);


	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
priority_queue<int64_t> Que;

int main()
{
  int64_t N, M, a, res = 0;
  cin >> N >> M;
  for (int i = 0; i < N; i++)
  {
    cin >> a;
    Que.push(a);
  }
  for (int i = 0; i < M; i++)
  {
    a = Que.top();
    Que.pop();
    Que.push(a / 2);
  }
  while (!Que.empty())
  {
    res += Que.top();
    Que.pop();
  }
  cout << res << endl;
}


Measured memory_bytes: 1400
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	while(true) {
		ll n, m, r;
		cin>>n>>m;
		if(n == 0 && m == 0) break;
		cin>>r;
		vector<vector<int> > h(m, vector<int>(721, 0));
		REP(i, r) {
			ll t, gomi, man, s;
			cin>>t>>gomi>>man>>s;
			--man;
			t -= 540;
			if(s == 1) {
				h[man][t] += 1;
			} else {
				if(t + 1 <= 720) h[man][t + 1] -= 1;
			}
		}
		REP(i, m) {
			FOR(j, 1, 721) {
				h[i][j] += h[i][j - 1];
			}
		}
		ll q;
		cin>>q;
		REP(i, q) {
			ll ts, te, man;
			cin>>ts>>te>>man;
			--man;
			ts -= 540;
			te -= 540;
			ll ans = 0;
			bool det = false;
			FOR(j, ts, te + 1) {
				if(h[man][j] != 0) {
					++ans;
					det =true;
				} else if(det) {
					det = false;
					--ans;
				}
			}
			if(det) --ans;
			cout<<ans<<endl;
		}
	}
}

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

int main(){
  int n;
  cin >> n;
  if ((n/10)%111 == 0){
    cout << "Yes" << endl;
  }
  else if ((n%1000)%111 == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3624
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,k=map(int,readline().split())
    a=list(map(int,readline().split()))

    s=bin(max(k,max(a)))[2:]
    l=len(s)
    cnt_one=[0]*l

    for i in range(n):
        b=a[i]
        for j in range(l):
            if b&1==1:
                cnt_one[j]+=1
            b>>=1

    cnt_one.reverse()
    k_bin=bin(k)[2:]
    dp=[[-float("inf"),-float("inf")] for _ in range(l+1)]
    dp[0][0]=0
    for i in range(l):
        j=l-i
        score1=cnt_one[i]*2**(j-1)
        score2=(n-cnt_one[i])*2**(j-1)
        if len(k_bin)<j:
            dp[i+1][0]=dp[i][0]+score1
        else:
            if k_bin[len(k_bin)-j]=="1":
                dp[i+1][0]=dp[i][0]+score2
                if cnt_one[i]>=(n+1)//2:  #1の数が半数以上
                    dp[i+1][1]=max(dp[i][0]+score1,dp[i][1]+score1)
                else:  #1の数が半数未満
                    dp[i+1][1]=max(dp[i][0]+score1,dp[i][1]+score2)
            else:
                dp[i+1][0]=dp[i][0]+score1
                if cnt_one[i]>=(n+1)//2:  #1の数が半数以上
                    dp[i+1][1]=dp[i][1]+score1
                else:  #1の数が半数未満
                    dp[i+1][1]=dp[i][1]+score2

    print(max(dp[l][0],dp[l][1]))

if __name__=="__main__":
    main()

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

struct Point {
    double x;
    double y;
};

void koch(int n, Point a, Point b) {
    if (n == 0) return;
    Point s, t, u;
    double th = M_PI * 60.0/180.0;

    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x)*cos(th) - (t.y - s.y)*sin(th) + s.x;
    u.y = (t.x - s.x)*sin(th) + (t.y - s.y)*cos(th) + s.y;

    koch(n-1, a, s);
    printf("%.5f %.5f\n", s.x, s.y);
    koch(n-1, s, u);
    printf("%.5f %.5f\n", u.x, u.y);
    koch(n-1, u, t);
    printf("%.5f %.5f\n", t.x, t.y);
    koch(n-1, t, b);
}

int main(void) {
    int n;
    Point a, b;
    cin >> n;
    a.x = 0; a.y = 0;
    b.x = 100; b.y = 0;

    printf("%.5f %.5f\n", a.x, a.y);
    koch(n, a, b);
    printf("%.5f %.5f\n", b.x, b.y);

    return 0;
}

Measured memory_bytes: 1176
# B
R, G, B = map(int, input().split())
K = int(input())
ans = 'No'

num = 0

while (True):
    if  (num == K):
        break
        
    if (R >= G):
        G *= 2
        num += 1
        
    if (R < G):
        break
    
while (True):
    if  (num == K):
        break
        
    if (G >= B):
        B *= 2
        num += 1
        
    if (G < B):
        break

if (R < G and G < B):
    ans = 'Yes'
    
print(ans)

Measured memory_bytes: 61896
/*
This is code of SuperJ6 for Atcoder.
Don't copy my code during f*kin' contests.

2.71828182845904523536
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <vector>
using namespace std;
#define endl '\n'

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

	string s, t;
	cin >> s >> t;
	
	vector<int> nx[26];
	for(int i = 0; i < s.size(); i++){
		nx[s[i] - 'a'].push_back(i);
	}
	for(int i = 0; i < 26; i++) nx[i].push_back(s.size());
	
	long amt = 0, cur = -1;
	for(int i = 0; i < t.size(); i++){
		int nc = *upper_bound(nx[t[i] - 'a'].begin(), nx[t[i] - 'a'].end(), cur);
		if(nc == s.size()){
			amt += s.size();
			cur = -1;
			nc = *upper_bound(nx[t[i] - 'a'].begin(), nx[t[i] - 'a'].end(), cur);
			if(nc == s.size()){
				cout << -1 << endl;
				return 0;
			}
			cur = nc;
		}else{
			cur = nc;
		}
	}
	
	amt += cur + 1;
	cout << amt << endl;

	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
using namespace std;

int main() {
	int n, k;
	string s;
	cin >> n >> s >> k;
	char key;
	key = s[k - 1];
	REP(i, n) {
		if (s[i] == key) {
			continue;
		}
		else {
			s[i] = '*';
		}
	}
	cout << s << endl;
	return 0;
}

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

int main() {
	int a,b,c;
	cin >> a>>b>>c;
	if(b>c){
		int d;
		d=b;
		b=c;
		c=d;
	}
	if(a>b){
		int e;
		e=a;
		a=b;
		b=e;
	}
	if(b>c){
		int f;
		f=b;
		b=c;
		c=f;
	}
	cout<<a;
	cout<<' ';
	cout<<b;
	cout<<' ';
	cout<<c<<endl;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define tam 1200
#define offset 100000
#define se second
#define fi first
#define forr(i,p,n) for(int i=p;i<n;i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}

int main()
{
    string txt;
    cin>>txt;
    char ant='$';
    int c=0;
    forr(i,0,txt.size())
    {
        if (txt[i]==ant|| ant=='$')
            ant=txt[i];
        else
            ant=txt[i],c++;
    }
    c++;
    cout<<c-1<<endl;
}

Measured memory_bytes: 512
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [n, m] = input[0].split(" ").map((x: string): number => +x);
const a = input[1].split(" ").map((x: string): number => +x);
a.sort((x, y) => y - x);
const sum = a.reduce((prev, curr) => prev + curr, 0);
const threshold = sum / (m * 4);
console.log(a[m - 1] >= threshold ? "Yes" : "No");


Measured memory_bytes: 7500
#include<stdio.h>
int main(void)
{
	int n,m,l,i,d=-1000000000;
	scanf("%d%d",&n,&m);
	for(i=1;i<n;i++)
	{
		scanf("%d",&l);
		if(d<l-m)d=l-m;
		if(l<m)m=l;
	}
	printf("%d\n",d);
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int n,c=0;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    bool f=true;
    for(int j=0;j<i;j++){
      if(a[i]<a[j]) f=false;
    }
    if(f) c++;
  }
  cout<<c;
}


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

public class Main {
  private static InputReader in;
  private static PrintWriter out;

  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out, true);

    int n = in.nextInt();
    String s = in.next(), t = in.next();
    for (int len = n; len <= 2*n; len++) {
      int overlap = 2*n - len;
      if (s.substring(s.length()-overlap).equals(t.substring(0, overlap))) {
        out.println(len);
        out.close();
        System.exit(0);
      }
    }
    
    out.close();
    System.exit(0);
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

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

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

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


}


Measured memory_bytes: 8404
#include<iostream>
using namespace std;
int main()
{
    int point;
    cin >> point;
    if(point>3000 || point<1){
    return 1;
    }
    if(point<1200 && point > 0){
    cout << "ABC";
    }
    if(point>=1200 && point < 3001){
    cout << "ARC";
    }
    return 0;
}

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

vector<int> Odd[100010],Even[100010];
int color[100010];

bool dfs(int v,int c){
  color[v]=c;
  for(int i=0;i<Odd[v].size();i++){
    if(color[Odd[v][i]]==0)dfs(Odd[v][i],-c);
  }
  for(int i=0;i<Even[v].size();i++){
    if(color[Even[v][i]]==0)dfs(Even[v][i],c);
  }
}

int main(){
  int n;
  cin >> n;
  int u[n],v[n],w[n];
  rep(i,n-1){
    cin >> u[i] >> v[i] >> w[i];
    u[i]--,v[i]--;
  }
  rep(i,n-1){
    if(w[i]%2==0){
      Even[u[i]].push_back(v[i]);
      Even[v[i]].push_back(u[i]);
    }
    if(w[i]%2==1){
      Odd[u[i]].push_back(v[i]);
      Odd[v[i]].push_back(u[i]);
    }
  }
  dfs(0,1);
  rep(i,n){
    if(color[i]==1)cout << 1 << endl;
    else cout << 0 << endl;
  }
return 0;}

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

using namespace std;

int a[105];

int main()
{
    int n, i, sum = 1;
    cin >> n;
    for(i=1;i<=n;i++)
    {
        cin >> a[i];
        if(i != 1)
        {
            if(a[i] >= a[i-1])
                sum++;
            else
                a[i] = a[i-1];
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
//template <class Type>
 
 
void Fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
}
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
 
 
ll MOD=1e9 + 7;
ll OO=1e6;  
const int N=1e6 + 2;
ll arr[N];
int dp[N][4];

ll n,m,k,cnt,SU,idx,len,MN,MX,T;
ll l,r,mid;
ll a,b,c,d;


ll power(ll x,ll y,ll p){
	
	ll cnt=1;
	x%=p;
	
	while(y){
		
		if(y&1)
			cnt=(cnt*x)%p;
		
		x=(x*x)%p;
		y>>=1;

	}
	
	return cnt;
	
}


int main(){

	
	cin>>n>>a>>b;
	
	cnt=power(2,n,MOD)-1;
	
	arr[0]=1;
	for(int i=1;i<=max(a,b);++i)
		arr[i]=(arr[i-1]*i)%MOD;
	ll x=1;
	for(int i=n-a+1;i<=n;++i)
		x=(x*i)%MOD;
	
	SU+= (x*power(arr[a],MOD-2,MOD))%MOD;
	
	x=1;
	for(int i=n-b+1;i<=n;++i)
		x=(x*i)%MOD;
	
	SU+=(x*power(arr[b],MOD-2,MOD))%MOD;
	
	SU%=MOD;
	
	
	cnt = ((cnt-SU)%MOD + MOD )%MOD;
	
	cout<<cnt<<endl;
	
	
	
	
	
}
 
 
 
 
 
 
 
 
 
 
 
 


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;

int main() {
    int n;
    string s;
    cin >> s;
    n = SZ(s);
    int cnt0 = 0, cnt1 = 0;
    rep(i, n) {
        if(s[i] == '0') cnt0++;
        else cnt1++;
    }
    cout << min(cnt0, cnt1) * 2 << "\n";
    
}

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

using namespace std;

int main() {
    int a[3][3]{};
    bool a_p[3][3]{false};
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    } 
    int n = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int b = 0;
        cin >> b;
        for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 3; j++) {
                if (a[i][j] == b) a_p[i][j] = true;
            }
        } 
    }
    for(int i = 0; i < 3; i++) {
        if ((a_p[0][i] && a_p[1][i] && a_p[2][i]) || (a_p[i][0] && a_p[i][1] && a_p[i][2])) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if ((a_p[0][0] && a_p[1][1] && a_p[2][2]) || (a_p[0][2] && a_p[1][1] && a_p[2][0])) {
    cout << "Yes" << endl;
    return 0;
    }
    cout << "No" << endl;
    return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll sum = 0;
  rep(i,n) sum += a[i];
  set<ll> candidates;
  for (int i = 1; i*i <= sum; i++) {
    if (sum%i == 0) {
      candidates.insert(i);
      candidates.insert(sum/i);
    }
  }
  ll ans = 1;
  for (ll x : candidates) {
    ll need;
    { // calc need
      vector<ll> r(n);
      rep(i,n) r[i] = a[i]%x;
      sort(r.begin(), r.end());
      ll tot = 0;
      rep(i,n) tot += r[i];
      int l = n-tot/x;
      need = 0;
      rep(i,l) need += r[i];
    }
    if (need <= k) ans = max(ans, x);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int a[2005];
bitset<4000000> dp;
int sum = 0;
int main(){
    scanf("%d",&n);
    dp.reset();
    dp[0] = 1;
    for (int i =0,x;  i < n; i++){
        scanf("%d",&x);
        dp |= dp << x;
        sum += x;
    }
    for (int i = 0; i <= 4000000; i++){
        if (i >= (sum+1)/2 && dp[i]){
            printf("%d\n",i);
            return 0;
        }
    }
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string input;

long long int kansu( long long int x ) {
  vector< long long int > list;
  long long int k = 0;
  while( true ) {
    if ( input[x] == '[' ) {
      list.push_back( kansu(x+1) );
      long long int f = 0;
      while( true ) {
	if ( input[x] == '[' ) f++;
	if ( input[x] == ']' ) {
	  f--;
	  if ( f == 0 ) break;
	}
	x++;
      }
      x++;
      if ( x == input.size() ) break;
    }else if ( input[x] == ']' ) {
      if ( k > 0 ) list.push_back( k / 2 + 1 );
      break;
    }else {
      k = k * 10 + input[x] - '0';
      x++;
    }
  }
  sort( list.begin(), list.end() );
  long long int ans = 0;
  for ( long long int i = 0; i < list.size() / 2 + 1; i++ ) {
    ans += list[i];
  }
  return ans;
}

int main () {

  long long int n;

  cin >> n;

  for ( long long int i = 0; i < n; i++ ) {
    cin >> input;
    cout << kansu( 0 ) << endl;
  }

  return 0;

}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
// using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //////////////////////////////////////
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}


Measured memory_bytes: 3652
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
using namespace std;

int par[120];
int rnk[120];
struct edge { int u, v, cost; };
bool comp(const edge&e1, const edge& e2) {
	return e1.cost < e2.cost;
}

void init(int n) {
	for (int i = 0;i < n;i++) {
		par[i] = i;
		rnk[i] = 0;
	}
}

int find(int a) {
	if (par[a] == a)return a;
	else return par[a] = find(par[a]);
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;

	if (rnk[x] < rnk[y])par[x] = y;
	else {
		par[y] = x;
		if (rnk[x] == rnk[y])rnk[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}
int main() {
	int n, m;
	while (cin >> n >> m, n, m) {
		edge es[1000];
		for (int i = 0;i < m;i++) {
			int a, b, c;
			cin >> a >> b >> c;
			es[i].u = a;
			es[i].v = b;
			es[i].cost = c;
		}
		sort(es, es + m, comp);
		init(n);
		int ans = 0;
		for (int i = 0;i < m;i++) {
			edge e = es[i];
			if (!same(e.u, e.v)) {
				unite(e.u, e.v);
				ans += e.cost;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3012