akhauriyash/Code-Regression huggingface dataset:
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

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

func main() {
	defer stdout.Flush()
	N := readInt()
	K := readInt()
	mx := make(map[int]bool)
	my := make(map[int]bool)
	m := make(map[int]map[int]int)
	for i := 0; i < N; i++ {
		x := readInt()
		y := readInt()

		mx[x] = true
		my[y] = true

		m2, ok := m[x]
		if !ok {
			m2 = make(map[int]int)
			m[x] = m2
		}
		m2[y]++
	}

	xs := make([]int, 0, N)
	for x := range mx {
		xs = append(xs, x)
	}
	ys := make([]int, 0, N)
	for y := range my {
		ys = append(ys, y)
	}

	sort.Ints(xs)
	sort.Ints(ys)

	s := make([][]int, len(xs)+1)
	for i := range s {
		s[i] = make([]int, len(ys)+1)
	}

	for i := 1; i <= len(xs); i++ {
		for j := 1; j <= len(ys); j++ {
			x := xs[i-1]
			y := ys[j-1]
			s[i][j] = s[i][j-1] + m[x][y]
		}
	}

	for i := 1; i <= len(xs); i++ {
		for j := 1; j <= len(ys); j++ {
			s[i][j] += s[i-1][j]
		}
	}

	sum := func(i, j, k, l int) int {
		return s[k][l] - s[i][l] - s[k][j] + s[i][j]
	}

	inf := int64(1000000001)
	ans := 2 * inf * 2 * inf

	for i := 0; i+2 <= len(xs); i++ {
		for ie := i + 2; ie <= len(xs); ie++ {
			for j := 0; j+2 <= len(ys); j++ {
				for je := j + 2; je <= len(ys); je++ {
					if sum(i, j, ie, je) < K {
						continue
					}
					x := xs[i]
					xe := xs[ie-1]
					y := ys[j]
					ye := ys[je-1]
					ans = min(ans, int64(xe-x)*int64(ye-y))
				}
			}
		}
	}

	println(ans)
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fastio 	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long int
using namespace std;

int mod = 1e9 + 7;
int arr[100];
int dp[100][100005];


// Hard to do this recursively so iterative dp with prefix sum is preferred
// dp[x][y] - x is childrens, y is candies, val at dp[x][y] is no of ways
// dp[first][0] - ways to distribute 0 candies is 1
// dp[x][y] = dp[x - 1][y] if we gave 0 candies to current child otherwise
//			  dp[x - 1][y - 1] if we gave 1 candy to current child
// dp[x][y] = prefix_sum[y] - prefix_sum[y - arr[x] - 1]
// dp[last][k] is our number of ways

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio;

	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> arr[i];

	for (int i = 0; i <= arr[0]; i++)
		dp[0][i] = 1;

	for (int i = 1; i < n; i++) {
		// prefix sum
		vector<int> prefix(k + 1);
		prefix[0] = dp[i - 1][0];
		for (int j = 1; j <= k; j++)
			prefix[j] = (prefix[j - 1] + dp[i - 1][j]) % mod;
		for (int j = 0; j <= k; j++) {
			if (j > arr[i])
				dp[i][j] = (prefix[j] + mod - prefix[j - arr[i] - 1]) % mod;
			else
				dp[i][j] = prefix[j];
		}
	}
	cout << dp[n - 1][k];
}

Measured memory_bytes: 82412
n = int(input())
A = list(map(int,input().split()))
Su = [0 for i in range(n)]
Su[0] = A[0]
Su[1] = A[1]

for i in range(2,n):
    Su[i] = Su[i-2] + A[i]
#print(Su)
als = (Su[n-2]+Su[n-1])//2
for i in range(n):
    if i%2 == 0:
        ps = Su[n-2]-(Su[i-1] if i>0 else 0)+(Su[i-2] if i>0 else 0)
    else:
        ps = Su[n-1]-Su[i-1]+(Su[i-2] if i>1 else 0)
    print((als-ps)*2)

Measured memory_bytes: 14400
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <complex>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

#define at(y, x) field[y + 201][x + 201]

int N;
int n[201], d[201];
int field[402][402];
void solve() {
    vector<complex<int>> pos;
    memset(field, -1, sizeof(field));
    at(0, 0) = 0;
    pos.emplace_back(0, 0);
    rep(i, N - 1) {
        auto p = pos[n[i]] + complex<int>(dy[d[i]], dx[d[i]]);
        at(p.real(), p.imag()) = 0;
        pos.push_back(p);
    }
    int wmin, wmax;
    int hmin, hmax;
    wmin = hmin = INF;
    wmax = hmax = -INF;
    /*
    for (int i = -10; i <= 10; i++) {
        for (int j = -10; j <= 10; j++) {
            cout << at(i, j) << " ";
        }
        cout << endl;
    }
    */
    rep(i, 402) rep(j, 402) {
        if (field[i][j] == 0) {
            wmin = min(wmin, j);
            wmax = max(wmax, j);
            hmin = min(hmin, i);
            hmax = max(hmax, i);
        }
    }
    // cout << hmin << ", " << hmax << endl;
    // cout << wmin << ", " << wmax << endl;
    cout << wmax - wmin + 1 << " " << hmax - hmin + 1 << endl;
}
int main() {
    while (cin >> N, N) {
        rep(i, N - 1) cin >> n[i] >> d[i];
        solve();
    }
    return 0;
}

Measured memory_bytes: 3736
import bisect as bs

def main():
    with open(0) as f:
        N = int(f.readline())
        A = sorted(list(map(int, f.readline().split())))
        B = list(map(int, f.readline().split()))
        C = sorted(list(map(int, f.readline().split())))

    ans = 0
    for b in B:
        ans += bs.bisect_left(A, b) * (N-bs.bisect_right(C, b))
    print(ans)

main()

Measured memory_bytes: 29056
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;
static const int INF = 1000000;

/*
  ------  -----
--- -----
 ----
最初は、区間の始点があればflagを１にし、flagが1でかつ終点があればans++とし、flag=0としていた
しかし、これだと前の区間が残ったまま次の新しい区間が追加されると、
すでに分断されたはずの区間が終点となった時にもカウントされるためWAとなった

次に、終端を迎えたものが一つでもあった際に、今ある全ての区間を0にして、新たに区間を追加していく実装にした所、ACとなった
この実装では終端の最小値のみを記録しておけば良い

*/

int ans;
int N, M;
pair<int, int> pr[100005];

int main(void) {
    scanf("%d %d", &N, &M);
    rep(i, 0, M) {
        int a, b;
        scanf("%d %d", &a, &b);
        pr[i] = mp(a, b);
    }
    sort(pr, pr+M);
    int mint = INF;
    for (int i=0; i<M; i++) {
        if (pr[i].first<mint) mint = min(mint, pr[i].second);
        else {
            ans++;
            mint = pr[i].second;
        }
    }
    if (mint!=INF) ans++;

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

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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; }

int main() {
    string s; cin >> s;
    ll n = s.size();
    vector<ll> cnt(26, 0);
    rep(i, n) cnt[s[i]-'a']++;

    ll ans = n * (n-1) / 2;
    rep(i, 26) {
        if (cnt[i] >= 2) {
            ans -= cnt[i] * (cnt[i] - 1) / 2;
        }
    }
    cout << ans + 1 << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long int ll;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main() {
  int k, n;
  cin >> k >> n;
  vector<int> v(n);
  int maxN = 0;
  rep (i, n) {
    cin >> v[i];
  }
  int before = v[0];
  for (int i = 1; i < n; i++) {
    maxN = max(maxN, v[i] - before);
    before = v[i];
  }
  maxN = max(maxN, v[0] + k - v[n - 1]);
  // P(maxN);
  P(k - maxN);
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#include <iostream>
#include<string>
#include<vector>
#include <algorithm>
#define REP(a,b) for (int i = a; i <= (b); i++)
using namespace std;
int main() {
int a;
  cin>>a;
  cout<<48-a;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target ("avx")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

/*
struct Mo {
    using ADD = function< void(int) >;
    using DEL = function< void(int) >;
    using REM = function< void(int) >;

    int width;
    vector< int > left, right, order;
    vector< bool > v;

    Mo(int N, int Q) : width((int)sqrt(N)), order(Q), v(N) {
        iota(begin(order), end(order), 0);
    }

    void add(int l, int r) { // [l, r) 
        left.emplace_back(l);
        right.emplace_back(r);
    }

    int run(const ADD& add, const DEL& del, const REM& rem) {
        assert(left.size() == order.size());
        sort(begin(order), end(order), [&](int a, int b) {
            int ablock = left[a] / width, bblock = left[b] / width;
            if (ablock != bblock) return ablock < bblock;
            if (ablock & 1) return right[a] < right[b];
            return right[a] > right[b];
            });
        int nl = 0, nr = 0;
        auto push = [&](int idx) {
            v[idx].flip();
            if (v[idx]) add(idx);
            else del(idx);
        };
        for (auto idx : order) {
            while (nl > left[idx]) push(--nl);
            while (nr < right[idx]) push(nr++);
            while (nl < left[idx]) push(nl++);
            while (nr > right[idx]) push(--nr);
            rem(idx);
        }
        return 0;
    }
};
int main() {
    int N, Q;
    cin >> N;
    cin >> Q;

    vector< int > A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector< int > f(1000001);
    Mo mo(N, Q);
    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        mo.add(--l, r);
    }
    int ret = 0;
    auto add = [&](int idx) { if (f[A[idx]]++ == 0) ret++; };
    auto del = [&](int idx) { if (f[A[idx]]-- == 1) --ret; };
    vector< int > ans(Q);
    auto rem = [&](int idx) { ans[idx] = ret; };
    mo.run(add, del, rem);
    for (int i = 0; i < Q; i++) {
        cout << ans[i] << "\n";
    }
}
*/


ll N, K;
vector<ll> A;

bool isOK(ll m) {
    ll a = 0;
    for (int i = 0; i < N; i++)a += (A[i]+m-1)/m - 1 ;
    return a <= K;
}

int main() {
    cin >> N >> K;
    A = vector<ll>(N);
    for (int i = 0; i < N; i++)cin >> A[i];
    if (K == 0) {
        cout << *max_element(A.begin(), A.end()) << endl;
        return 0;
    }

    ll left = 0; //「index = 0」が条件を満たすこともあるので、初期値は -1
    ll right = INF_LL/4; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    // どんな二分探索でもここの書き方を変えずにできる！ 
    while (right - left > 1) {
        ll mid = left + (right - left) / 2;
        if (isOK(mid)) right = mid;
        else left = mid;
    }

    cout << right << endl;
}



Measured memory_bytes: 4720
import numpy as np
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
A = np.array(A)
all_max = np.max(A)
max_ind = np.argmax(A)
max_remove = np.ones(N, dtype=bool)
max_remove[max_ind] = False
second_max = np.max(A[max_remove])
# print(all_max)
# print(second_max)
for n in range(N):
    if n == max_ind:
        print(second_max)
    else:
        print(all_max)

Measured memory_bytes: 21840
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    rep(i, n) cin >> x[i];

    ll ans = 0;
    for(int i = 1; i < n; i++){
        if((x[i] - x[i - 1]) * a < b) ans += (x[i] - x[i - 1]) * a;
        else ans += b;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define eps 1e-7
#define PI acos(-1)
#define de(x) cout<<#x<<'='<<x<<" , "
#define dee(x) cout<<#x<<'='<<x<<endl
#define sz(x) x.size()
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define mset(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int MAXN=155;
int item[MAXN];

int N,K;
LL gcd(LL a,LL b){ return b?gcd(b,a%b):a; }

int main(){
    cin>>N>>K;
    rep(i,0,N) cin>>item[i];
    sort(item,item+N);
    LL ans=0;
    int p1=0,p2=K;
    rep(i,0,N){
        if(item[i]<K-item[i])  ans+=2*item[i];
        else ans+=2*(K-item[i]),p2=item[i];
    }
    cout<<ans<<endl;
}



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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

llint pow2mod(llint n) {
    llint ans = 1;
    for(int in=0;in<n;in++) {
        ans *= 2;
        ans  %= MOD;
    }
    return ans;
}

int main(void) {
    llint n;
    cin >> n;

    vector<llint> a(n);
    llint atmp;
        for(int in=0;in<n;in++) {
            cin >> atmp;
            a.at(atmp)++;
        }
    if(n%2==0) {
        for(int in=0;in<n;in++) {
            if(in%2==1&&a.at(in)!=2) {
                cout << 0 << endl;
                return 0;
            }
            if(in%2==0&&a.at(in)!=0) {
                cout << 0 << endl;
                return 0;
            }
        }
        cout << pow2mod(n/2) << endl;
    }
    else {
        if(a.at(0)!=1) {
            cout << 0 << endl;
            return 0;
        }
        for(int in=0;in<n;in++) {
            if(in%2==1&&a.at(in)!=0) {
                cout << 0 << endl;
                return 0;
            }
            if(in!=0&&in%2==0&&a.at(in)!=2) {
                cout << 0 << endl;
                return 0;
            }
        }
        cout << pow2mod((n-1)/2) << endl;
    }
    return 0;
}


Measured memory_bytes: 3996
MOD = 10**9 + 7
m = 10**5 + 100
fac = [0] * m
finv = [0] * m
inv = [0] * m


def COMBinitialize(m):
    fac[0] = 1
    finv[0] = 1
    if m > 1:
        fac[1] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2, m):
            fac[i] = fac[i-1] * i % MOD
            inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
            finv[i] = finv[i - 1] * inv[i] % MOD


def COMB(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


COMBinitialize(m)


def main():
    K, M = (int(i) for i in input().split())

    def prime_factorize(n):
        res = []
        for i in range(2, n+1):
            if i*i > n:
                break
            if n % i != 0:
                continue
            ex = 0
            while n % i == 0:
                ex += 1
                n //= i
            res.append((i, ex))
        if n != 1:
            res.append((n, 1))
        return res

    pf = prime_factorize(M)

    ans = 1

    for _, n in pf:
        ans *= COMB(n+K-1, n)
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()


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

int main () {
	int n,i,c,b=0,j,minj;
	cin >> n;
	int a[n];
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	for(i=0;i<n;i++){
		minj=i;
		for(j=i;j<n;j++){
			if (a[j]<a[minj]){
				minj=j;
			}
		}
		if(i==minj) b--;
		c=a[i];
		a[i]=a[minj];
		a[minj]=c;
		b++;
	}
	for(i=0;i<n;i++){
		if(i!=n-1) cout << a[i] << " ";
		else cout << a[i] << endl;
	}
	cout << b << endl;
}

Measured memory_bytes: 1160
A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())
c='YES'
if A<B:
    A+=V*T
    B+=W*T
    if A<B:
        c='NO'
else:
    A-=V*T
    B-=W*T
    if A>B:
        c='NO'
print(c)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n)(for i=0;i<n;++i);
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
const double PI = 3.14159265358979323846;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] % 2 == 0) {
      if (a[i] % 3 != 0 && a[i] % 5 != 0) {
        cout << "DENIED";
        return 0;
      }
    }
  }
  cout << "APPROVED";
}

Measured memory_bytes: 256
# include <cctype>
# include <cstdio>

# define debug(...) fprintf ( stderr, __VA_ARGS__ )
# define LocalJudge( PN ) freopen ( PN ".in", "r", stdin ) ;	freopen ( PN ".out", "w", stdout )


struct IO{
	char buf [1 << 20 | 1], *ss, *tt ;
	IO ( ) : ss ( 0 ), tt ( 0 )	{	}
	# define pick( ) ( ( ss == tt ) ? ( tt = buf + fread ( ss = buf, 1, 1 << 20 | 1, stdin ) ), ( ( ss == tt ) ? -1 : *ss ++ ) : *ss ++ ) 
	inline operator int ( )  {
		register int x, c;
		while ( ( c = pick ( ) ) > '9' || c < '0' ) ;
		for ( x = -48 + c ; isdigit ( c = pick ( ) ) ; x = x * 10 + c - 48 ) ;
		return x ;
	}
	inline char gc ( )  {
		register char c ;
		while ( ( c = pick ( ) ) == ' ' || c == '\n' ) ;
		return c ;
	} 
} it ;

const int N = 2345 ;

int map [N] [N], sum [N] [N], sum_dwn [N] [N], sum_side [N] [N] ;

/*
inline int SUM ( int sum [] [N], int xa, int ya, int xb, int yb )  {
	return sum [xb] [yb] - sum [xb] [ya - 1] - sum [xa - 1] [yb] + sum [xa - 1] [ya - 1] ;	
}*/

# define SUM( ZJC, xa, ya, xb, yb )  ( ZJC [xb] [yb] - ZJC [xb] [ya - 1] - ZJC [xa - 1] [yb] + ZJC [xa - 1] [ya - 1] )

int main ( )  {
	int n ( it ), m ( it ) ; register int q ( it ) ;
	for ( register int i = 1 ; i <= n ; ++ i )
		for ( register int j = 1 ; j <= m ; ++ j )  {
			map [i] [j] = ( it.gc ( ) == '1' ) ;
		}
	for ( register int i = 1 ; i <= n ; ++ i )
		for ( register int j = 1 ; j <= m ; ++ j )  {
			sum [i] [j] = map [i] [j] + sum [i - 1] [j] + sum [i] [j - 1] - sum [i - 1] [j - 1] ;
		}
	for ( register int i = 1 ; i <= n ; ++ i )
		for ( register int j = 1 ; j <= m ; ++ j )  {
			sum_dwn [i] [j] = ( map [i + 1] [j] & map [i] [j] ) ;
			sum_dwn [i] [j] += sum_dwn [i - 1] [j] + sum_dwn [i] [j - 1] - sum_dwn [i - 1] [j - 1] ;
		}

	for ( register int i = 1 ; i <= n ; ++ i )
		for ( register int j = 1 ; j <= m ; ++ j )  {
			sum_side [i] [j] = ( map [i] [j + 1] & map [i] [j] ) ;
			sum_side [i] [j] += sum_side [i - 1] [j] + sum_side [i] [j - 1] - sum_side [i - 1] [j - 1] ;
		}
	
	register int xa, ya, xb, yb ;
	while ( q -- )  {
		xa = it, ya = it, xb = it, yb = it ;
		printf ( "%d\n", SUM ( sum, xa, ya, xb, yb ) - SUM ( sum_dwn, xa, ya, xb - 1, yb ) - SUM ( sum_side, xa, ya, xb, yb - 1 ) ) ;
	}
}


Measured memory_bytes: 84608
#include<bits/stdc++.h>
#define ll long long
ll fast_int()
{
	ll x;
	scanf("%lld",&x);
	return x;
}
void fast_out(ll x)
{
	printf("%lld",x);
}
using namespace std;
int main()
{
ll x;
x=fast_int();
ll res=1000*(x/500)+((x%500)/5)*5;
fast_out(res);
}

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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL N, L, T; cin >> N >> L >> T;
  VL xs(N), ds(N);
  vector<bool> cnt(2);
  REP(i,N){
	cin >> xs[i] >> ds[i];
	cnt[ds[i]-1] = true;
  }
  if(!cnt[1]){
	REP(i,N){
	  cout << (xs[i] + T) % L << endl;
	}
	return 0;
  }
  else if(!cnt[0]){
	REP(i,N){
	  cout << (xs[i] - T%L + L) % L << endl;
	}
	return 0;
  }

  LL id = 0;
  if(ds[0] == 1){
	FOR(i,1,N){
	  if(ds[i] == 2 && xs[i]-xs[0] <= 2*T)
		(id += (2*T - (xs[i] - xs[0])) / L + 1) %= N;
	}
  }
  else{
	FOR(i,1,N){
	  if(ds[i] == 1 && xs[0] + L - xs[i] <= 2*T)
		(id += N - (2*T - (xs[0] + L - xs[i])) / L % N + N-1) %= N;
	}
  }

  VL ps(N);
  REP(i,N) ps[i] = (xs[i] + L + T%L * (ds[i]==1?1:-1)) % L;

  LL x0 = ps[0];
  SORT(ps);

  int i0 = lower_bound(ALL(ps), x0) - begin(ps);
  //cout<<x0<<","<<i0<<","<<id<<endl;
  if(i0+1<N&&ps[i0] == ps[i0+1] && ds[0] == 1)
	((--id)+=N)%=N;
  VL ans(N);
  REP(i,N) ans[(i+id)%N] = ps[(i+i0)%N];
  
  for(auto a: ans)
	cout << a << endl;

  return 0;
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.Stream;
import java.util.Arrays;
public class Main {
  public static void main (String args[]) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] colorArray = br.readLine().split(" ");
    String[] cntArray = br.readLine().split(" ");
    int[] icntArray = Stream.of(cntArray).mapToInt(Integer::parseInt).toArray();
    String rmColor = br.readLine();
    if(colorArray[0].equals(rmColor)){
      icntArray[0]--;
    }else if(colorArray[1].equals(rmColor)){
      icntArray[1]--;
    }
    System.out.print(icntArray[0] + " " + icntArray[1]);
  }
}

Measured memory_bytes: 29008
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int x, y;
	cin >> x >> y;
	int a[12] = { 1,3,1,2,1,2,1,1,2,1,2,1 };

	if (a[x - 1] == a[y - 1])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
} 

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

int a[200002];


int main(void)
{
	int N;
	cin >> N;
	for (int i = 0; i < 200002; i++) a[i] = 0;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int in;
		cin >> in;
		if (in >= 200002) ans++;
		else a[in]++;
	}


	for (int i = 1; i < 200002; i++) {
		if (a[i] < i) ans += a[i];
		else ans += a[i]-i;
	}

	if (ans > N) ans = N;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL

struct node {
  int key;
  struct node *right;
  struct node *left;
  struct node *parent;
};
typedef struct node * Node;
Node root;
void Insert(int );
void inorder(Node );
void preorder(Node );
Node search(Node, int);
Node treeSuccessor(Node );
void treeDelete(Node );
Node treeMinimum(Node);
int main()
{
  int i,j,k,yflag=0,nflag=0,x;
  char c[10];
  Node a;
  scanf("%d",&k);

  for(i=0;i<k;i++)
    {
      scanf("%s",&c[0]);
      if(c[0]=='f')
        {
          scanf("%d",&j);
          a=search(root,j);
          if(a!=NIL) printf("yes\n");
          else printf("no\n");
        }
      if(c[0]=='i')
        {
          scanf("%d",&j);
          Insert(j);
        }
else if(c[0]=='p')
        {
          inorder(root);
          printf("\n");
          preorder(root);
          printf("\n");
        }
else if(c[0]=='d')
        {
          scanf("%d",&x);
          treeDelete(search(root,x));
        }

    }
  return 0;
}

void Insert(int p)
{
  Node x=root;
  Node y=NIL;
  Node z;

  z=(Node )malloc(sizeof(struct node));
  z->key=p;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL)
    {
      y=x;
      if(z->key < x->key) x=x->left;
      else x=x->right;

z->parent=y;
    }
  if(y==NIL) root=z;
  else if(z->key < y->key) y->left=z;
  else  y->right=z;
}

void inorder(Node x)
{
  if(x==NIL) return;
  inorder(x->left);
  printf(" %d",x->key);
  inorder(x->right);
}

void preorder(Node x)
{
  if(x==NIL) return;
  printf(" %d",x->key);
  preorder(x->left);
  preorder(x->right);
}
Node search(Node u,int k)
{
  while(u!=NIL && k!=u->key)
    {
      if(k < u->key) u=u->left;
      else u=u->right;
    }
  return u;
}

Node treeSuccessor(Node x)
{
  Node y;
  if(x->right!=NIL) return treeMinimum(x->right);
  y=x->parent;
  while(y!=NIL&&x==y->right)
    {
      x=y;
      y=y->parent;
    }
  return y;
}
void treeDelete(Node z)
{
  Node y,x;

  if(z->left==NIL||z->right==NIL) y=z;
  else y=treeSuccessor(z);
  if(y->left!=NIL)  x=y->left;
  else  x=y->right;

  if(x!=NIL)  x->parent=y->parent;
  if(y->parent==NIL) root=x;
  else
    {
      if(y==y->parent->left)  y->parent->left=x;
      else y->parent->right=x;
    }
  if(y!=z)  z->key=y->key;

  free(y);
}

Node treeMinimum(Node x)
{
  while(x->left!=NIL) x=x->left;
  return x;
}

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

using namespace std;

const int MOD = 1e9 + 7;

int n,m,i,j,x[100005],y[100005],a[100005],b[100005];

int main(){
	scanf("%d%d", &n, &m);
	
	for(i = 0; i < n; i++)
	scanf("%d", &x[i]);
	
	for(i = 0; i < m; i++)
	scanf("%d", &y[i]);
	
	for(i = 0; i < m - 1; i++)
	a[i] = y[i + 1] - y[i];
	
	int cnt = 0;
	int tot = 0;
	long long pre = 0;
	long long sum = 0;
	
	for(i = 0; i < m - 1; i++){
		cnt++;
		pre = pre + (long long)cnt * a[i];
		sum = (sum + pre) % MOD;
	}
	
	
	for(i = 0; i < n - 1; i++)
	b[i] = x[i + 1] - x[i];
	
	long long res = 0;
	pre = 0;
	cnt = 0;
	
	for(i = 0; i < n - 1; i++){
		cnt++;
		pre = (pre + ((sum * cnt) % MOD * b[i])) % MOD;
		res = (res + pre) % MOD;
	}
	
	printf("%lld\n", res);
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define MAXN 1000009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;

using namespace std;

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

template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int n;
int a[MAXN];
int main()
{
    //~ freopen("file.in", "r", stdin);
    cin >> n;
	string s;
	cin >> s;
	s = "0"+s;
	for(int i = 1; i <= n; i ++)
		a[i] = a[i - 1] + (s[i] == 'W' ? 1 : 0);
	int mx = INF, l, r;
	for(int i = 1; i <= n; i ++){
		l = a[i - 1], r = (n - i) - (a[n] - a[i]);
		umin(mx, l + r);
	}
	printf("%d\n",mx);
}




Measured memory_bytes: 1888
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	long long n,m;
	cin>>n>>m;
	priority_queue<long long> q;
	for(long long i=0;i<n;i++){
		long long tmp;
		cin>>tmp;
		q.push(tmp);
	}
	
	for(long long i=0;i<m;i++){
		long long top=q.top();
		q.pop();
		top/=2;
		q.push(top);
	}
	long long money=0;
	while(!(q.empty())){
		long long kane=q.top();
		q.pop();
		money+=kane;
	}
	cout<<money<<endl;
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>

typedef long long Long;

int main()
{
    int n;
    Long price[80];
    scanf("%d", &n);

    for (int i = 0; i < n; ++i)
        scanf("%lld", price+i);
    
    bool isIncreasing = price[0] <= price[1];
    Long currMoney = 1000;
    Long currStocks = 0;

    if (isIncreasing)
    {
        currStocks += currMoney / price[0];
        currMoney -= (currMoney / price[0]) * price[0];
    }

    for (int i = 1; i < n-1; ++i)
    {
        if (isIncreasing)
        {
            if (price[i] > price[i+1])
            {
                currMoney += currStocks * price[i];
                currStocks = 0;
                isIncreasing = false;
            }
        }
        else
        {
            if (price[i] <= price[i+1])
            {
                currStocks += currMoney / price[i];
                currMoney -= (currMoney / price[i]) * price[i];
                isIncreasing = true;
            }
        }
    }

    currMoney += currStocks * price[n-1];
    printf("%lld", currMoney);

    return 0;
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
string s,t;
int f(string st,int p){
    for(int i = 0; i < st.size(); i++){
        if(st[i] != '?' && st[i] != t[i])
            return 0;
    }
    return 1;
}
int main(){
    cin>>s>>t;
    string out;
    int p=-1;
    for(int i = 0;i<s.size()-t.size()+1;i++){
        if(f(s.substr(i,t.size()),i)){
            p=i;
        }
    }
    if(p==-1){
        cout<<"UNRESTORABLE";
        return 0;
    }
    for(int i = 0; i < t.size(); i++){
        s[p+i]=t[i];
    }
    for(int i = 0; i < s.size(); i++){
        if(s[i]=='?')
            cout<<'a';
        else
            cout<<s[i];
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_limit=(n); i<i##_limit; ++i)
#define FOR(i, a, b) for (int i=(a), i##_limit=(b); i<i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;

int main()
{
    int P, Q, R; 
    cin >> P >> Q >> R;

    cout << min(min(P+Q, Q+R), R+P) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <climits>

using namespace std;

typedef long long ll;
typedef vector<int> ivec;
typedef pair<int, int> ipair;

int N;
int a[100], b[100], c[100], d[100];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
    for (int i = 0; i < N; i++) cin >> c[i] >> d[i];

    vector<ipair> v1(N);
    vector<ipair> v2(N);

    for (int i = 0; i < N; i++) {
        v1[i] = make_pair(a[i], b[i]);
        v2[i] = make_pair(c[i], d[i]);
    }

    sort(v1.begin(), v1.end(), [](auto &left, auto &right) { return left.second > right.second; });
    sort(v2.begin(), v2.end());

    bool s[100];
    int count = 0;
    for (int i = 0; i < N; i++) s[i] = true;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (s[j] && v1[i].first < v2[j].first && v1[i].second < v2[j].second) {
                s[j] = false;
                count++;
                break;
            }
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN = 100;
const int MAXGN = MAXN + 2;
const int MAXGM = MAXN + MAXN*MAXN;


typedef struct G {
	int n, m;
	int ghead[MAXGN], gto[2 * MAXGM], gnxt[2 * MAXGM]; ll gcap[2 * MAXGM];

	void init(int _n) { n = _n; m = 0; REP(i, n) ghead[i] = -1; }
	void addedge(int a,int b,ll cap) { 
		gnxt[m] = ghead[a], ghead[a] = m, gto[m] = b, gcap[m] = cap, ++m;
		gnxt[m] = ghead[b], ghead[b] = m, gto[m] = a, gcap[m] = 0, ++m;
	}

	ll flow[MAXGN]; int back[MAXGN]; int q[MAXGN], qhead, qtail;
	void upd(int to, ll f, int b) { assert(flow[to] == 0 && f > 0); flow[to] = f; back[to] = b; q[qhead++] = to; }
	ll maxflow(int s, int t) {
		ll ret = 0;
		while (true) {
			REP(i, n) flow[i] = 0, back[i] = -2; qhead = qtail = 0;
			upd(s, LLONG_MAX, -1);
			while (qtail < qhead) {
				int at = q[qtail++];
				for (int x = ghead[at]; x != -1; x = gnxt[x]) {
					int to = gto[x]; if (gcap[x] == 0 || flow[to] > 0) continue;
					upd(to, min(flow[at], gcap[x]), x ^ 1);
				}
			}
			if (flow[t] == 0) return ret;
			ret += flow[t];
			for (int x = t; x != s; x = gto[back[x]]) {
				gcap[back[x]] += flow[t];
				gcap[back[x] ^ 1] -= flow[t];
			}
		}
	}
} G;

int n;
int a[MAXN+1];
G g;


void run() {
	scanf("%d", &n); FORE(i, 1, n) scanf("%d", &a[i]);
	int s = 0, t = n + 1; ll sum = 0; g.init(n + 2);
	FORE(i, 1, n) if (a[i] >= 0) g.addedge(i, t, a[i]), sum += a[i]; else g.addedge(s, i, -a[i]);
	FORE(i, 1, n) if (a[i] < 0) for (int j = i + i; j <= n; j += i) if (a[j] >= 0) g.addedge(i, j, LLONG_MAX);
	ll ret = sum - g.maxflow(s, t);
	printf("%lld\n", ret);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
int f[1005][1005][2],aux[1005][2],a[1005],n,tot;
int fac[1005],inv[1005],p2[1005];
int add(int a,int b){a+=b; return a>=mod?a-mod:a;}
void Inc(int &a,int b){a=add(a,b);}
int ksm(int a,int b)
{
	int s=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1) s=1ll*s*a%mod;
	return s;
}
int C(int n,int m){return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}
void Solve(int p,int l,int r,int lim)
{
	int mval=1e9,mpos;
	if(l==r) f[p][0][1]=f[p][1][0]=1,mval=a[l],mpos=l;
	else
	{
		for(int i=l;i<=r;i++) if(mval>a[i]) mval=a[i],mpos=i;
		if(mpos==l||mpos==r)
		{
			int id=++tot;
			Solve(id,l+(mpos==l),r-(mpos==r),mval);
			for(int ty=0;ty<2;ty++)
				for(int i=(!ty);i<=r-l+1;i++)
					f[p][i][ty]=f[id][i-!(ty)][ty];
		}
		else
		{
			int ls=++tot,rs=++tot;
			Solve(ls,l,mpos-1,mval),Solve(rs,mpos+1,r,mval);
			for(int i=0;i<=mpos-l;i++)
				for(int j=0;j<=r-mpos;j++)
					for(int ty=0;ty<2;ty++)
						Inc(f[p][i+j+!(ty)][ty],1ll*f[ls][i][ty]*f[rs][j][ty]%mod);
		}
	}
	int L=r-l+1;
	for(int t=mval-1;t>=lim;t--)
	{
		for(int i=0;i<=L;i++)
		{
			Inc(aux[i][0],f[p][i][0]);
			Inc(aux[i][1],f[p][i][0]);
			for(int j=0;j<=i;j++)
			{
				Inc(aux[j][1],1ll*f[p][i][1]*C(i,i-j)%mod*(p2[L-i]-(i==j))%mod);
				Inc(aux[j][0],1ll*f[p][i][0]*C(i,i-j)%mod*(p2[L-i]-(i==j))%mod);
			}
		}
		for(int i=0;i<=L;i++) f[p][i][0]=aux[i][0],f[p][i][1]=aux[i][1],aux[i][0]=aux[i][1]=0;
	}
}
void Pre()
{
	fac[0]=p2[0]=1;
	for(int i=1;i<=1000;i++) fac[i]=1ll*fac[i-1]*i%mod,p2[i]=add(p2[i-1],p2[i-1]);
	inv[1000]=ksm(fac[1000],mod-2);
	for(int i=999;i>=0;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod;
}
int main()
{
	Pre();
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	Solve(++tot,1,n,0);
	printf("%d\n",f[1][0][1]);
	return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
typedef long long int ll;
typedef unsigned long long ull;
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;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

int main(){
    while(1){

        int n;
        cin >> n;
        if(n == 0)break;

        vector<int>a(n);
        int cnt = 0;
        for(int i = 0; i < n; i++){
            cin >> a[i];
            cnt += a[i];
        }

        double ave = (double)cnt/n;

        double bunsan = 0;

        for(int i = 0; i < n; i++){
            bunsan += (ave - a[i])*(ave - a[i]);
        }

        double ans = sqrt(bunsan/n);

        printf("%.8lf\n",ans);

    }
    


}


Measured memory_bytes: 3220
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	int n;
	string s, t;
	cin >> n >> s >> t;
	int cnt = 0;
	for (int i = 0;i < n; i++) {
		if (s[i] != t[cnt]) {
			cnt = 0;
		}
		if (s[i] == t[cnt]) {
			cnt++;
		}

	}

	
	cout <<( 2 * n - cnt) << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()
#define MP make_pair

int main() {
	ll n,s[1100] = {}, ans = 1;
	cin >> n;
	FOR(i, 2, n + 1) {
		int b = i;
		FOR(j, 2, n + 1) {
			REP(k, INF) {
				if (b % j == 0) {
					b /= j;
					s[j]++;
				}
				else break;
			}
		}
	}
	REP(i, 1100) {
		if (s[i] > 0) ans *= s[i] + 1;
		if (ans > 1000000007) ans %= 1000000007;
	}
	cout << ans << endl;
}

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

int main(){
  int nin;
  while(1){ 
    scanf("%d",&nin);
    if(!nin)break;

    long long int human[4002]={0};
    long long int no[4002],tanka,kazu,outflag=0;
    
    for(int i=0;i<nin;i++){
      scanf("%d %d %d",&no[i],&tanka,&kazu);
      human[no[i]]+=tanka*kazu;
    }
    
    for(int i=0;i<nin;i++){
      if(human[no[i]]>=1000000 && human[no[i]]!=-1){
	printf("%d\n",no[i]);
	human[no[i]]=-1;
	outflag=1;
      }
    }
    
    if(outflag==0)printf("NA\n");
    
  }
}

Measured memory_bytes: 1244
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> vt;
int n, m, k;
void dfs(int x, int depth) {
	if (depth == k + 1)return;
	if(x-m>=k-depth){
		for (int i = x - m + 1; i <= x; i++)
			vt.push_back(i);
		dfs(x - m, depth + 1);
	}
	else if (x == k - depth + 1) {
		vt.push_back(x);
		dfs(x - 1, depth + 1);
	}
	else {
		int xx = k - depth;
		for (int i = xx + 1; i <= x; i++)
			vt.push_back(i);
		dfs(xx, depth + 1);
	}

}
int main()
{
	scanf("%d %d %d", &n, &m, &k);
	int ch = n / m;
	if (n%m)ch++;
	if (n+1 < m + k) {
		puts("-1");
		return 0;
	}
	if (k < ch) {
		puts("-1");
		return 0;
	}
	dfs(n, 1);
	for (int i = 0; i < vt.size(); i++)
		printf("%d ", vt[i]);
}	

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

int main() {
  int N;
  cin >> N;
  int sum=0;
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    if(a%2==1)sum++;
  }
  if(sum%2==0) cout << "YES";
  else cout << "NO";
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a,b,c,d,p,x,y,ans;
  scanf("%d %d %d %d %d",&a,&b,&c,&d,&p);
  x = a * p;
  if(p > c){
    y = (p -c) * d + b;
  }else{
    y = b;
  }
  if(x > y){
    ans = y;
  }else{
    ans = x;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 596
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

var H int
var W int
var Ch int
var Cw int
var Dh int
var Dw int
var S [][]byte
var m [][]int

func main() {
	H = nextInt()
	W = nextInt()
	Ch = nextInt() - 1
	Cw = nextInt() - 1
	Dh = nextInt() - 1
	Dw = nextInt() - 1

	S = make([][]byte, H)
	m = make([][]int, H)

	max := H*W + 1
	for i := 0; i < H; i++ {
		S[i] = nextBytes()
		m[i] = make([]int, W)

		for j := 0; j < W; j++ {
			m[i][j] = max
		}
	}
	m[Ch][Cw] = 0

	queue := make(PriorityQueue, 0)
	queue = append(queue, &P{Ch, Cw, 0})
	dir := []P{
		P{-1, 0, 0},
		P{+1, 0, 0},
		P{0, -1, 0},
		P{0, +1, 0},
	}

	for queue.Len() > 0 {
		p := heap.Pop(&queue).(*P)

		if p.h == Dh && p.w == Dw {
			break
		}
		// A type
		for i := 0; i < len(dir); i++ {
			d := dir[i]
			n := P{p.h + d.h, p.w + d.w, p.c}
			if out(n) {
				continue
			}
			if m[n.h][n.w] <= n.c {
				continue
			}
			m[n.h][n.w] = n.c
			heap.Push(&queue, &n)
		}

		// B type
		for h := -2; h <= +2; h++ {
			for w := -2; w <= +2; w++ {
				if h == 0 && w == 0 {
					continue
				}

				n := P{p.h + h, p.w + w, p.c + 1}
				if out(n) {
					continue
				}
				if m[n.h][n.w] <= n.c {
					continue
				}
				m[n.h][n.w] = n.c
				heap.Push(&queue, &n)
			}
		}
	}

	if m[Dh][Dw] == max {
		fmt.Println(-1)
	} else {
		fmt.Println(m[Dh][Dw])
	}
}

func out(p P) bool {
	return p.h < 0 || p.w < 0 || p.h >= H || p.w >= W || S[p.h][p.w] == '#'
}

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

type PriorityQueue []*P

func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
	pi := pq[i]
	pj := pq[j]

	if pi.c != pj.c {
		return pi.c < pj.c
	}
	di := abs(pi.h-Dh) + abs(pi.w-Dw)
	dj := abs(pj.h-Dh) + abs(pj.w-Dw)
	return di < dj
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	item := x.(*P)
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil // メモリリークを避ける
	*pq = old[0 : n-1]
	return item
}

type P struct {
	h int
	w int
	c int
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}

func debug(args ...interface{}) {
	fmt.Fprintln(os.Stderr, args)
}


Measured memory_bytes: 39564
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int m, k; cin >> m >> k;
  if (m < 3) {
    V<> a;
    for (int i = 0; i < 1 << m; ++i) {
      a.push_back(i);
      a.push_back(i);
    }
    int n = a.size();
    do {
      V<> c(n + 1);
      for (int i = 0; i < n; ++i) c[i + 1] = c[i] ^ a[i];
      bool ok = true;
      for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) if (a[i] == a[j]) {
        if ((c[j + 1] ^ c[i]) != k) ok = false;
      }
      if (ok) {
        for (int i = 0; i < n; ++i) cout << a[i] << " \n"[!(n + ~i)];
        return 0;
      }
    } while (next_permutation(begin(a), end(a)));
    cout << -1 << '\n';
  } else {
    if (k >= 1 << m) return cout << -1 << '\n', 0;
    V<> a;
    a.push_back(k);
    for (int i = 0; i < 1 << m; ++i) if (i != k) a.push_back(i);
    a.push_back(k);
    for (int i = (1 << m) - 1; i >= 0; --i) if (i != k) a.push_back(i);
    int n = a.size();
    for (int i = 0; i < n; ++i) cout << a[i] << " \n"[!(n + ~i)];
  }
}

Measured memory_bytes: 2932
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		Main app = new Main();
		String s[];
		
		int n, res;
		while(true){
			if((n = Integer.valueOf(reader.readLine())) == 0) break;
			
			s = reader.readLine().split(" ");
			res = 0;
			for(int i = 1; i < n; i += 2){
				res += app.check(s[i], s[i - 1]);
			}
			System.out.println(res);
		}
		reader.close();
	}
	public int check(String x, String y){
		char l[] = x.toCharArray();
		char r[] = y.toCharArray();
		
		if(l[0] == r[0]){
			return 0;
		}else return 1;
	}
}

Measured memory_bytes: 26760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll K;
    //string S;
    cin >> K;
    //ll cur = 7;
    ll cnt = 1;
    vector<ll> v(K+1);
    ll r = 7 % K;
    while(r != 0){
        if(v[r] > 0){
            cout << -1 << endl;
            return 0;
        }
        v[r]++;
        r *= 10;
        r += 7;
        r %= K;
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 11172
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <map>
using namespace std;

int main() {
  int64_t N, x, S, ans;
  cin >> N >> x;
  S=0;
  ans=0;
  vector<int64_t> a(N);
  for (int64_t i=0; i<N; i++) {
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  for (int j=0; j<N; j++) {
    S=S+a[j];
    if (S<=x) {
      ans=ans+1;
    }
  }
  if (S<x) {
    cout << ans-1 << endl;
  }
  else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 3616