akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
import string

def main():
    S = list(input())
    T = list(input())
    accept = False
    for i in reversed(range(len(S)-len(T)+1)):
        match = True
        for j,s in enumerate(S[i:i+len(T)]):
            if s != T[j] and s != '?':
                match = False
                break
        if match:
            S[i:i+len(T)] = T
            accept = True
            break
    if accept:
        print(''.join(S).replace('?','a'))
    else:
        print('UNRESTORABLE')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+5;
bool dp[maxn][4];
char buff[maxn];
string x[]={"dream","dreamer","erase","eraser"};
int main() {
	cin>>(buff+1);
	int len=strlen(buff+1);    
    for(int i=0;i<4;i++) dp[0][i]=1;
    for(int i=1;i<=len;i++) {
    	for(int j=0;j<4;j++) {
    		if(i>=x[j].length()) {
    			bool ok1=1,ok2=0;
    			for(int k=0;k<x[j].length();k++) {
    				if(buff[i-x[j].length()+1+k]!=x[j][k]) {ok1=0;break;}
    			}
    			for(int k=0;k<4;k++) if(dp[i-x[j].length()][k]) {ok2=1;break;}
    			if(ok1&&ok2) dp[i][j]=1;
    		}
    	}
    }
    for(int k=0;k<4;k++) if(dp[len][k]) return 0*puts("YES");
	puts("NO");
    return 0;
}

Measured memory_bytes: 4096
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

int main(){

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

    cin >> N;

    ll ans=0;
    for( ll ni = 1 ; ni <=N ; ni++ ){
        stmp = to_string(ni);
        ans += (stmp.size()%2);
    }
    cout << ans << endl;
    

}

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

using namespace std;

int main() {

	int n, m;
	cin >> n >> m;

	vector<map<int, int>> py(n+1);
	vector<vector<int>> numm(m + 1, vector<int>(2));
	int tmp1, tmp2;
	for (int i = 1; i <= m; i++) {
		cin >> tmp1 >> tmp2;
		py[tmp1][tmp2]=0;
		numm[i][0] = tmp1;
		numm[i][1] = tmp2;
	}

	for (int i = 1; i <= n; i++) {
		int counter = 1;
		for (auto itr = py[i].begin(); itr != py[i].end(); itr++) {
			itr->second = counter;
			counter++;
		}
	}

	for (int i = 1; i <= m; i++) {
		cout << std::setfill('0') << std::right << std::setw(6) << numm[i][0] 
			<< std::setfill('0') << std::right << std::setw(6) << py[numm[i][0]][numm[i][1]] << endl;
	}
	return 0;
}

Measured memory_bytes: 16384
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;

const int MAX_N = 200000;
int N, K;
int A[MAX_N];

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

  cin >> N >> K;
  rep(i, N) cin >> A[i];

  sort(A, A+N);
  vector<Pii> vp;
  int count = 1;
  for (int i = 0; i < N; ++i) {
    if (i+1 == N) {
      vp.push_back(Pii(count, A[i]));
      continue;
    }
    if (A[i] == A[i+1]) ++count;
    else {
      vp.push_back(Pii(count, A[i]));
      count = 1;
    }
  }

  sort(all(vp));
  int ans = 0, size = vp.size();
  for (int i = 0; i < vp.size(); ++i) {
    if (size <= K) break;
    ans += vp[i].fi;
    --size;
  }

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


Measured memory_bytes: 3188
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	ans := -1
	c := 0
	for i := 0; i < n; {
		c++
		t := a[i]
		a[i] = -1

		if t == 2 {
			ans = c
			break
		} else if t == -1 {
			break
		}
		i = t - 1
	}
	fmt.Println(ans)
}


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

using namespace std;

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

	int sum = 0;
	int i;
	for (i = 1;sum < X;i++) {
		sum = sum + i;
		if (sum == X) {
			cout << i << endl;
			break;
		}
	}
	if (sum != X) {
		cout << i-1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The Value Of " << #val << " is : " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 3e5+5;
ll n, pref[nax];
string s;
	
int main(){
	IOS
	cin >> n >> s;
	if(s[0]=='W') pref[0]=1;
	else pref[0]=0;
	for(int i=1;i<n;i++){
		pref[i]=pref[i-1];
		if(s[i]=='W'){
			pref[i]++;
		}
	}
	ll mins=inf;
	mins=min(mins, (n-1)-(pref[n-1]-pref[0]));
	for(int i=1;i<n;i++){
		ll ans=pref[i-1];
		ans+=(n-1)-i-(pref[n-1]-pref[i]);
		mins=min(mins, ans);
	}
	cout << mins << '\n';
}


Measured memory_bytes: 6100
#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#define rep(i,n) for(int i=0; i <(n); i++)

int main(){
  char s;
  scanf("%c",&s);
  if(s>='a'&&s<='z'){
    printf("a\n");
  }else{
    printf("A\n");
  }
  return 0;
}


Measured memory_bytes: 1600
#C問題
W,H,N = map(int,input().split())
XY = [list(map(int,input().split())) for i in range(N)]

ans = 0
for i in range(N):
    if i == 0:
        sx,sy = XY[0]
    else:
        gx,gy = XY[i]
        dx = gx-sx
        dy = gy-sy
        if dx*dy >= 0:
            ans+=max(abs(dx),abs(dy))
        else:
            ans+=(abs(dx)+abs(dy))
        sx,sy = gx,gy
        
print(ans)




Measured memory_bytes: 5716
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static void Main(string[] args)
    {
        var n = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        n = n.OrderBy(x => x).ToArray();
        var sum = 0;
        var k1 = n[2] - n[1];
        n[0]++;
        n[1]++;
        var sa = n[1] - n[0];
        var m = sa / 2;
        var d = sa % 2;
        if (d == 1)
        {
            sum += 2;
        }
        sum += k1 + m;
        Console.WriteLine(sum);
    }
}


Measured memory_bytes: 13396
# https://atcoder.jp/contests/abc157/tasks/abc157_d
# https://www.planeta.tokyo/entry/6193/

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M, K = map(int, input().split())
uf = UnionFind(N)
dir_or_blk = [[] for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    dir_or_blk[a].append(b)
    dir_or_blk[b].append(a)
    uf.union(a, b)

for _ in range(K):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if uf.same(c, d):
        dir_or_blk[c].append(d)
        dir_or_blk[d].append(c)

for i in range(N):
    ans = uf.size(i)-len(dir_or_blk[i])-1
    print(ans, end=" ")


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

int main()
{
	for (int i = 1; i <= 9; i++)
	{
		for (int j = 1; j <= 9; j++)
		{
			cout << i << 'x' << j << '=' << i * j << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3008
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	LL n,k;
	cin>>n>>k;
	vl a(n);
	vl b(n);
	FOR(i,0,n){
		cin>>a[i];
		a[i]=(a[i]+k-1)%k;
	}
	map<LL,LL> mp;
	mp[0]=1;
	LL ans=0,nw=0;
	FOR(i,0,n){
		nw+=a[i];
		nw=nw%k;
		b[i]=nw;
		if(i==k-1)mp[0]--;
		if(i>=k){
			mp[b[i-k]]--;
		}
		ans+=mp[nw];
		mp[nw]++;
	}

	cout<<ans<<endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define fup(i,a,b) for(int i=a;i<=b;++i)
#define fdw(i,a,b) for(int i=a;i>=b;--i)
#define sync ios::sync_with_stdio(false);cin.tie(0)
#define cl(a) memset(a,0,sizeof(a))
#define gcd __gcd
#define fi first
#define se second
#define pb push_back
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
//ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//ll ksm(ll a,ll b,ll mod){ll res=1;a%=mod;for(;b;b>>=1){if(b&1) res=res*a%mod;a=a*a%mod;}return res;}
//ll oula(ll n){ ll res=n;for(ll i=2;i*i<=n;i++){if(n%i==0){ res=res-res/i;while(n%i==0) n/=i;}}if(n>1) res=res-res/n;return res;}
//bool MRT(ll x){if(x==2)return true;fup(i,1,50){ll now=rand()%(x-2)+2;if(ksm(now,x-1,x)!=1)return false;}return true;}
//void shai(int n)fup(i,2,n){if(isprime[i]){v.push_back(i);for(int j=2*i;j<=10000;j+=i)isprime[j]=0;}}//"埃氏筛筛选素数"
const int mod=998244353;
const int inf=0x3f3f3f3f;
const double eps=1e-7;
const int N=1e3+10;
int main()
{
    
    sync;
    int a[33]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin>>k;
    cout<<a[k-1]<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int noticeNum = scan.nextInt();
		int building1[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
		int building2[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
		int building3[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
		int building4[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
		while (noticeNum > 0) {
			int building = scan.nextInt();
			int floor = scan.nextInt();
			int room = scan.nextInt();
			int number = scan.nextInt();
			room = room + (10 * floor - 10) - 1;
			if (building == 1) {
				building1[room] += number;
			}
			if (building == 2) {
				building2[room] += number;
			}
			if (building == 3) {
				building3[room] += number;
			}
			if (building == 4) {
				building4[room] += number;
			}
			noticeNum--;
		}
		for (int i = 0; i < 15; i++) {
			for (int j = 0; j < 10; j++) {
				if (i == 3 || i == 7 || i == 11) {
					System.out.print("##");
				} else if (i < 3) {
					System.out.print(" " + building1[j + (10 * i)]);
				} else if (i > 3 && i < 7) {
					System.out.print(" " + building2[j + (10 * i -40)]);
				} else if (i > 7 && i < 11) {
					System.out.print(" " + building3[j + (10 * i -80)]);
				}else if (i > 11) {
					System.out.print(" " + building4[j + (10 * i -120)]);
			}
		}System.out.println("");
	}
}
}


Measured memory_bytes: 30256
n, k = list(map(int, input().split()))
a = list( map(int, input().split())) 

MOD = 10**9 + 7

ansR = 0
ansL = 0

for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                ansL += 1
            if i < j:
                ansR += 1

ans = ansR*(k+1)*k//2%MOD + ansL*(k-1)*k//2%MOD

print(int(ans%MOD))

Measured memory_bytes: 3188
#include <stdio.h>
#include <string.h>
 
int main()
{
	long a[5] = {0,0,0,0,0};
	char s[11];
	int N;
	scanf("%d", &N);
	int k;
	for(k = 1; k <= N; k++)
	{
		scanf("%s", s);
		if(s[0] == 'M')  a[0]++;
		if(s[0] == 'A')  a[1]++;
		if(s[0] == 'R')  a[2]++;
		if(s[0] == 'C')  a[3]++;
		if(s[0] == 'H')  a[4]++;
	}
	long long int O = 0;
	int p, t, r;
	for(p=0; p<=2; p++)
	 {for(t=p+1; t<=3; t++)
	   {for(r=t+1; r<=4; r++)
        {O += a[p]*a[t]*a[r];
	}}}
	printf("%lld", O);
}


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

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k <= a){
        cout << k << endl;
    }else if(a < k && k <= a+b){
        cout << a << endl;
    }else{
        cout << a-(k-a-b) << endl;
    }
}

Measured memory_bytes: 3636
n = int(input())
from collections import defaultdict
d = defaultdict(list)
X = []
xl = [tuple(map(int,input().split())) for i in range(n)]
for x,l in xl:
    d[x].append(x-l)
    d[x].append(x+l)
    X.append(x)

X.sort()


n_remove = 0


for i in range(1,n):
    x_1 = X[i-1]
    x_2 = X[i]
    min_1 , max_1 = d[x_1]
    min_2 , max_2 = d[x_2]

    if max_1 > min_2:
        n_remove += 1
        if max_2 >= max_1:
            d[x_2] = d[x_1]
            X[i] = X[i-1]


ans = n - n_remove
print(ans)


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

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll max0 = LLONG_MIN;
    ll max1 = LLONG_MIN;

    for(ll i=0;i<N;i++){
        cin >> A[i];
        if(max0<A[i]){
            max1 = max0;
            max0 = A[i];
        }else if(max1<A[i]){
            max1 = A[i];
        }
    }


    for(ll i=0;i<N;++i){
        if(A[i]==max0){
            cout << max1 << endl;
        }else{
            cout << max0 << endl;
        }
    }
    return 0;
}

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

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    int A[N], B[M];
    double atime = 0, btime = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    for(int i = 0; i < M; i++){
        cin >> B[i];
        btime += B[i];
    }

    int best = M, ans = 0, tmp = M;

    for(int i = 0; i < N + 1; i++){
        for(int j = best; j > 0; j--){
            if(btime <= K - atime){break;}
            tmp -= 1;
            btime -= B[tmp];
        }
        best = tmp;

        if(ans < i + best){
            ans = i + best;
        }
        atime += A[i];
        if(atime > K){break;}
        
    }

    cout << ans << endl;
}

Measured memory_bytes: 5184
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N , X = map(int, input().split())
x = list(map(int, input().split()))
d = []

for i in range(N):
    d.append(abs(x[i] - X))

ans = gcd_list(d)
print(ans)

Measured memory_bytes: 16280
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

  LL N;
  cin >> N;
  vector<LL> v(N);
  REP(i,N){
    cin >> v[i];
  }

  vector<LL> ans(N,-1);

  REP(i,N){
    REP(k,v.size()){
      LL j = v.size() - k-1;
      if (j + 1 == v[j])
      {
        ans[N - 1 - i] = v[j];
        v.erase(v.begin() + j);
        break;
      }
    }
  }

  REP(i,N){
    if(ans[i]==-1){
      cout<<-1<<endl;
      return 0;
    }
  }

  REP(i,N){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 888
import java.util.Scanner;
//なんかよくわからないやつ
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      //入力のやつ
		int X = sc.nextInt();
      //鉄道運賃
		int Y = sc.nextInt();
      //バス運賃
		System.out.println(X + Y / 2);
      //合計運賃を計算して入力
	}
}

Measured memory_bytes: 21844
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b;
  cin >> a >> b;
  cout << (a - 1) + (b >= a) << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3652
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    String S = sc.next();
    String T = sc.next();
    for(int i = 0; i < n; i++){
      System.out.print(S.charAt(i)+""+T.charAt(i));
    }
    System.out.println();
  }
}

Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int h, w, K;
    cin >> h >> w >> K;

    char c[10][10];

    for (int i = 0; i < h; i++) {
        cin >> c[i];
    }

    int r = 0;
    int l = 1 << (h + w);
    for (int k = 0; k < l; k++) {
        int t = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if ((k >> i & 1) || (k >> (j + h) & 1)) continue;
                if (c[i][j] == '#') t++;
            }
        }
        if (t == K) r++;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<string>
#include<vector>
#include<iostream>

using namespace std;

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

	for (int i = 0; i < s.length(); i++)
	{
		if (i % 2 == 0)
			printf("%c", s[i]);
	}
	printf("\n");
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  string s; cin >> s;
  ll cnt = 0;
  ll cntb = 0;
  RFOR(i, SZ(s)-1, 0) {
    if(s[i] == 'B') {
      cnt += SZ(s) - 1 - i - cntb;
      cntb++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 644
void main() {
	auto N = ri;
	int[string] count;
	foreach(_; 0..N) {
		count[rs]++;
	}
	auto M = ri;
	foreach(_; 0..M) {
		count[rs]--;
	}
	count.values.reduce!max.max(0).writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m, num[26];
char str[110];
int main(void) {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    while(cin >> n >> m) {
        memset(num , 0, 26 << 2);
        for(int i = 0; i < n; ++i) {
            cin >> str;
            for(int j = 0; j < m; ++j)
                num[str[j] - 'a']++;
        }
        int c4 = (n >> 1) * (m >> 1);
        int c2 = (n & 1) * (m >> 1) + (m & 1) * (n >> 1);
        int c1 = (n & 1) * (m & 1);
        for(int i = 0; c4 && i < 26;) {
            if(num[i] >= 4) { c4--, num[i] -= 4; }
            else ++i;
        }
        for(int i = 0; c2 && i < 26;) {
            if(num[i] >= 2) { c2--, num[i] -= 2; }
            else ++i;
        }
        for(int i = 0; c1 && i < 26;) {
            if(num[i] >= 1) { c1--, num[i] -= 1; }
            else ++i;
        }
        puts(c1 + c2 + c4 ? "No" : "Yes");
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll n;cin>>n;
  vector<ll> A(n), B(n);
  ll sumA = 0;
  rep(i,n){
    cin>>A[i];
    sumA += A[i];
    if(i == 0) continue;
    B[i-1] = A[i] - A[i-1];
  }
  B[n-1] = A[0] - A[n-1];

  sort(all(B));
  ll maxB = B[n-1];
  ll count = 0;
  rep(i,n){
    if((maxB - B[i]) % n != 0){
      cout<<"NO"<<endl;
      return 0;
    }
    count += (maxB - B[i]) / n;
  }
  ll remain = sumA - n * (n+1) / 2 * count;
  if(remain < 0){
    cout<<"NO"<<endl;
    return 0;
  }
  if(remain % (n * (n+1) / 2 * n) != 0){
    cout<<"NO"<<endl;
    return 0;
  }
  cout<<"YES"<<endl;
  return 0;
}

Measured memory_bytes: 1792
//Kenken Race

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a) vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,string> p;
using g = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n,a,b,c,d;cin>>n>>a>>b>>c>>d;
    string s;cin>>s;
    a--;b--;c--;d--;
    bool flag=true;
    if(c>d){
        rep(i,a+1,c+1){
            if(s[i]=='#'&&s[i-1]=='#')flag=false;
        }
        if(!flag){cout<<"No"<<nnn;return 0;}
        bool miti = false;
        rep(i,b,d+1){
            if(s[i]=='.'&&s[i-1]=='.'&&s[i+1]=='.')miti=true;
        }
        if(!miti){cout<<"No"<<nnn;return 0;}
    }else{
        rep(i,a+1,d+1){
            if(s[i]=='#'&&s[i-1]=='#')flag=false;
            if(!flag){cout<<"No"<<nnn;return 0;}
        }
    }
    cout<<"Yes"<<nnn;
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>

const int MOD = 1e9+7;
const int MAXN = 1e5+5;
int f[MAXN][2];
std::vector<int> son[MAXN];
int v[MAXN];

void dp(int k, int fat) {
	if (son[k].size() == 1 && son[k][0] == fat) {
		f[k][0] = 1;
		f[k][1] = 1;
		return;
	}
	long long x = 1;
	long long y = 1;
	for (int i = 0; i < son[k].size(); ++i) {
		int to = son[k][i];
		if (to == fat)
			continue;
		dp(to, k);
		x = (x * (f[to][0]+f[to][1]) % MOD) % MOD;
		y = y * f[to][0] % MOD;
	}
	f[k][0] = x;
	f[k][1] = y;
}

int main() {
	int n;
	std::cin>>n;
	memset(v, 0, sizeof(v));
	for (int i = 1; i <= n-1; ++i) {
		int pi,pj;
		std::cin>>pi;
		std::cin>>pj;
		son[pi].push_back(pj);
		son[pj].push_back(pi);
		v[pj] = 1;
	}
	int root;
	for (int i = 1; i <=n; ++i) {
		if (!v[i]) {
			root = i;
			break;
		}
	}
	dp(root, -1);
	printf("%d\n", (f[root][0] + f[root][1])%MOD);
	return 0;
}



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

int main(){
    ll N, A ,B;
    cin >> A >> B >> N;
    ll ans = 0;
    ll x;
    if(N < B){
        x = N;
    }else{
        x = B - 1;
    }
    while(1){
        ans = max(ans, ll(floor(A * x / B) - A * floor(x / B)));
        if(floor(A * x / B) != floor(A * (x- 1) / B)){
            break;
        }
        x--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

string s;
Int k;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> s >> k;
	Int ans = 0;
	if(s.front() == s.back()){
		Int a = 0, b = s.size()-1;
		while(a < (Int)s.size() && s[a] == s.front()) ++a;
		while(b >= 0 && s[b] == s.front()) --b;
		for(Int i=a; i<=b; ++i){
			Int j=0;
			while(i+j<=b && s[i+j] == s[i]) ++j;
			ans += j/2;
			i += j-1;
		}
		ans *= k;
		if(a == (Int)s.size()){
			ans = a * k / 2;
		}else{
			ans += ((a+s.size()-1-b)/2) * (k-1);
			ans += a/2 + (s.size()-1-b)/2;
		}
	}else{
		for(size_t i=0; i<s.size(); ++i){
			size_t j=0;
			while(i+j<s.size() && s[i+j] == s[i]) ++j;
			ans += j/2;
			i += j-1;
		}
		ans *= k;
	}
	cout << ans << "\n";
}

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




int main()
{
	ll n;
	cin>>n;
	ll v[n];
long double x[n],y[n];
	long double sum=0.0000000;
	ll f=0;
	for(ll i=0;i<n;i++)cin>>x[i]>>y[i],v[i]=i;
	bool flag=true;
	while(flag)
	{	f++;
		for(ll i=0;i<n-1;i++)
		{
			 long double dx = x[v[i + 1]] - x[v[i]];
            long double dy = y[v[i + 1]] - y[v[i]];
			sum+=sqrt(dx*dx+dy*dy);
			
		}
		flag=next_permutation(v,v+n);
	}

cout<<setprecision(12)<<sum/f;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//解説解答例
bool is_prime(int x){
  if(x<=1) return false;
  for(int i=2;i*i<=x;i++)
  if(x%i==0) return false;
  return true;
}

signed main(){
  int x;
  cin>>x;
  int p=x;
  while(!is_prime(p)) p++;
  cout<<p<<endl;
  return 0;
}

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

int main(){
  int a;
  int b;
  int c;
  int d;
  
  cin >> a >> b >> c >> d ;
  
  if(a+b<c+d){
    cout << "Right" << endl;
  }
  if (a+b==c+d){
    cout << "Balanced" << endl;
  }
  if (a+b>c+d){
    cout << "Left" << endl;
  }
}


Measured memory_bytes: 256
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<string>
#include<map>
#include<list>

using namespace std;

using llint = long long int ;
using ullint = unsigned long long int;


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

    llint n,k;
    cin >> n >> k;

    vector<llint> x(n),y(n);

    for(int i=0; i<n; i++){
        cin >> x[i];
    }
    for(int i=0; i<n; i++){
        cin >> y[i];
    }
    llint count, a, b;
    sort(x.begin(), x.end());
    sort(y.rbegin(), y.rend());
  
    llint l, r;
    l = 0;
    r = 10e12;

    while(l < r){
        llint c = (l + r) / 2;

        bool upper = [&]{
            llint sum = 0;
            
            //
            for(llint i=0; i<n; i++){
                sum += max(x[i]-c/y[i], 0ll);
            }

            return sum > k;
        }();

        if(upper){
            l = c + 1;
        }else{
            r = c;
        }
    }

    llint ans = r;

    cout << ans << endl;

}

Measured memory_bytes: 3456
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  string A,B,S="NO";
  cin>>A>>B;
  reverse(B.begin(),B.end());
  if(A==B) S="YES";
  cout<<S;
return 0;}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;


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

int x[5];
for(int i=0;i<5;i++){
    cin>>x[i];
    if(x[i]==0)cout<<i+1;
}

return 0;

}


Measured memory_bytes: 3652
import collections

n=int(input())

A=list(map(int,input().split()))
        
X=collections.Counter(A)

ans=1
cnt_1=0
cnt_2=0

for k,v in sorted(X.items(),key=lambda x:x[0],reverse=True):
    if v>=2:
        cnt_1+=1
        ans*=k
        if cnt_1==2:
            break
        if v>=4:
            ans*=k
            break
    else:
        cnt_2+=1
        if cnt_2==n or cnt_2==n-2 or cnt_2==n-3:
            ans=0
            break
print(ans)

Measured memory_bytes: 22436
// 提出がうまくいかないので、他ユーザーの解答でためしてみる
'use strict'
const main = (input) => {
    input = input.split('\n')
    let temp = input[0].split(' ').map(i => parseInt(i))
    const N = temp[0]
    const M = temp[1]
    temp = input.slice(1, M + 1)
    let arr = []
    let aMap = new Map
    temp.forEach((v) => {
        let tmp = v.split(' ').map(i => parseInt(i))
        aMap.set(tmp[1], 0)
        if(arr[tmp[0]] === undefined){
            arr[tmp[0]] = []
        }
        arr[tmp[0]].push(tmp[1])
    })
  
    arr.forEach((v, i) => {
        v.sort((a, b) => a - b)
        v.forEach((num, j) => {
            let def = ('000000' + i.toString(10)).slice(-6) + ('000000' + (j + 1).toString(10)).slice(-6)
            aMap.set(num, def)
        })
    })
    aMap.forEach(val => console.log(val))
}
  
main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 78344
#include <stdio.h>
#define REP(i,n,m) for(i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)
int main(){
	
	int i,j,n,m,sai;
	int a[1000],up[1000],down[1000];
	int h=0,k=0,maxup,maxdown;
	
	scanf("%d",&n);
	rep(i,n){ 
	scanf("%d",&m);
	rep(j,m){
	scanf("%d",&a[j]);
	}
		rep(j,m-1){
			sai = a[j+1] - a[j];
			if(sai>0){
			if(k==0){
				maxup = sai;
			}else{
				if(sai>maxup){
					maxup = sai;
				}
			}
			k++;
			}else if(sai<0){
				if(h==0){
					maxdown = sai;
				}else{
					if(sai<maxdown){
						maxdown = sai;
					}
				}
				h++;
			}
		}
		
		printf("%d %d\n",maxup,-1*maxdown);
		maxup=0,maxdown=0;
		k=0,h=0;
	}
}

Measured memory_bytes: 1028
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())
from collections import Counter
c = Counter(S)

if (c['N']==0 and c['S']!=0) or (c['N']!=0 and c['S']==0) or (c['E']==0 and c['W']!=0) or (c['E']!=0 and c['W']==0):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 64220
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll inf=1ll<<60;
int main(){
    ll n,k;
    cin>>k>>n;
    ll x[k];
    for(ll &i:x) cin>>i;
    bool dp[n+1]={};
    for(ll i=0;i<=n;i++){
        for(ll j:x){
            if(i-j>=0) dp[i]=max(dp[i],!dp[i-j]);
        }
    }
    cout<<(dp[n]?"First":"Second");
}


Measured memory_bytes: 3716
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

constexpr ll MAX_N = 1e5;

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

    ll N, K;
    cin >> N >> K;

    ll ans = 0;

    for (ll b = K + 1; b <= N; b++) {
        ans += N / b * (b - K);
        if (K == 0) {
            ans--;
        }
        ll mod = N % b;
        if (mod >= K) {
            ans += mod - K + 1;
        }
    }

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



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

int main() {
	int N, MAX = 0, SMAX = 0;
	static int A[200000];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) {
		if (MAX < A[i]) {
			SMAX = MAX;
			MAX = A[i];
		}
		else if (SMAX < A[i]) SMAX = A[i];
	}
	for (int i = 0; i < N; i++) {
		if (A[i] == MAX) cout << SMAX << endl;
		else cout << MAX << endl;
	}
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
long long a[100][2],dp[105][maxn];
int main()
{
	int n,w;
	cin>>n>>w;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld %lld",&a[i][0],&a[i][1]);
	}
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=w;j++)
			dp[i][j]=0;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(a[i][0]>j)
			{
				dp[i][j]=dp[i-1][j];
			}
			else
			{
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i][0]]+a[i][1]);
			}
		}
	}
	cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 80128
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let A: Vec<Vec<i64>> = {
        let mut A = vec![];
        for _ in 0..2 {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            A.push(
                line.split_whitespace()
                    .map(|x| x.parse().unwrap())
                    .collect()
            );
        }
        A
    };

    let (_, ans) = (1..N).fold(
        (A[0][0], A[0][0] + A[1][0]),
        |(u, d), i| (u + A[0][i], std::cmp::max(u + A[0][i], d) + A[1][i])
    );

    println!("{}", ans);
}

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

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> H(N);
    for (ll i = 0; i < N; i++)
    {
        cin >> H[i];
    }
    sort(H.begin(), H.end(), greater<ll>());
    ll sum = 0;
    for (ll i = K; i < N; i++)
    {
        sum += H[i];
    }
    cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1792
/*_BELIEVE_*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,M=1e9+7;

vector<int> a[30];

void solve()
{
    string s,t;
    cin>>s>>t;
    
    int n=s.length();
    int m=t.length();
    
    for(int i=0;i<n;++i)
        a[s[i]-'a'].pb(i+1);
    
    int cur=0,x,pos;
    int ans=0;
    for(int i=0;i<m;++i)
    {
        x=t[i]-'a';
        
        pos=upper_bound(all(a[x]),cur)-a[x].begin();
        
        if(pos==a[x].size())
        {
            pos=upper_bound(all(a[x]),-1ll)-a[x].begin();
            
            if(pos==a[x].size())
            {
                cout<<-1;
                return;
            }
            
            ans+=n-cur+a[x][pos];
            cur=a[x][pos];
        }
        else
        {
            ans+=a[x][pos]-cur;
            cur=a[x][pos];
        }
        
        //cout<<cur<<" "<<ans<<"\n";
    }
    
    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 1736
from collections import deque

H, W = map(int, input().split())
ss = ['#' + input() + '#' for i in range(H)]
ss = ['#' * (W + 2)] + ss + ['#' * (W + 2)]

numWhite = sum(map(lambda s: s.count('.'), ss))

dij = [(0, -1), (0, 1), (-1, 0), (1, 0)]

dist = [[float('inf')] * (W + 2) for i in range(H + 2)]
dist[1][1] = 1

Q = deque()
Q.append((1, 1))
while Q:
    i, j = Q.popleft()

    for di, dj in dij:
        if ss[i + di][j + dj] == '#': continue
        if dist[i + di][j + dj] == float('inf'):
            dist[i + di][j + dj] = dist[i][j] + 1
            Q.append((i + di, j + dj))

if dist[H][W] == float('inf'):
    print(-1)
else:
    print(numWhite - dist[H][W])


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,b,z,x,y;
	cin>>n>>b;
	for( x=0;x<=b/10000;x++){
		for( y=0;y<=b/5000;y++){
			z=n-x-y;
			if(z>=0&&x+y+z==n&&x*10000+y*5000+z*1000==b){
				cout<<x<<" "<<y<<" "<<z;
				return 0;	
		}
		}
	}
	cout<<"-1 -1 -1"<<endl;
	return 0;
} 

Measured memory_bytes: 384
def main():
    s = input()
    t = input()

    len_s = len(s)
    len_t = len(t)

    DP = [[0] * (len_t + 1) for _ in range(len_s + 1)]

    for i in range(len_s):
        for j in range(len_t):
            if s[i] == t[j]:
                DP[i + 1][j + 1] = DP[i][j] + 1
            else:
                DP[i + 1][j + 1] = max(DP[i + 1][j], DP[i][j + 1])

    ans = ""
    i = len_s
    j = len_t
    while DP[i][j]:
        if DP[i - 1][j] < DP[i][j] and DP[i][j - 1] < DP[i][j]:
            ans += s[i - 1]
            i -= 1
            j -= 1
        else:
            if DP[i - 1][j] ==  DP[i][j]:
                i -= 1
            if DP[i][j - 1] == DP[i][j]:
                j -= 1

    print(ans[::-1])


if __name__ == '__main__':
    main()

exit()


Measured memory_bytes: 144612
#include <stdio.h>

int main(){
	int i,pa,pb,tpa,tpb,count;
	while(1){
		tpa = 0;
		tpb = 0;
		scanf("%d",&count);
		if (count == 0) break;
		for(i=0;i<count;i++){
			scanf("%d %d",&pa,&pb);
			if(pa == pb) {
				tpa += pa;
				tpb += pb;
			}
			else if(pa > pb) tpa += (pa+pb);
			else tpb += (pa+pb);
		}
		printf("%d %d\n",tpa,tpb);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;
typedef long long ll;
int H, W;
int MOD = 1e9 + 7;
char a[1001][1001];
ll dp[1001][1001];

int main() {
   cin >> H >> W;
   for (int h = 0; h < H; h++) {
      for (int w = 0; w < W; w++) {
         cin >> a[h][w];
      }
   }

   dp[0][0] = 1;
   for (int h = 1; h < H; h++) {
      if (a[h][0] == '.') dp[h][0] = dp[h - 1][0];
      else dp[h][0] = 0;
   }
   for (int w = 1; w < W; w++) {
      if (a[0][w] == '.') dp[0][w] = dp[0][w - 1];
      else dp[0][w] = 0;
   }
   for (int h = 1; h < H; h++) {
      for (int w = 1; w < W; w++) {
         dp[h][w] = 0;
         if (a[h][w] == '#') continue;
         if (a[h - 1][w] == '.') {
            dp[h][w] += dp[h - 1][w];
            dp[h][w] %= MOD;
         }
         if (a[h][w - 1] == '.') {
            dp[h][w] += dp[h][w - 1];
            dp[h][w] %= MOD;
         }
      }
   }
   cout << dp[H - 1][W - 1] << endl;
   return 0;
}


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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
  string s;
  cin >> s;
  int n=s.size();
  int ans=1000000000;
  for(int i=0;i<n-2;i++){
    string t=s.substr(i,3);
    int x=atoi(t.c_str());
    ans=min(abs(753-x),ans);
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
import sys
import time
sys.setrecursionlimit(20000)

def find(tree,x):
    (idx,weight) = tree[x]
    if(idx== -1):
        return x
    else:
        root_idx = find(tree,idx)
        tree[x] = (root_idx, tree[x][1] + tree[idx][1])
        return root_idx

def relate(tree,x,y,z):
    x_root_idx = find(tree,x)
    y_root_idx = find(tree,y)
    if(x_root_idx == y_root_idx):
        return False
    
    if (tree_rank[y_root_idx] < tree_rank[x_root_idx]):
        tree[y_root_idx] = (x_root_idx, z+tree[x][1]-tree[y][1])
    else:
        tree[x_root_idx] = (y_root_idx, -z-tree[x][1]+tree[y][1])
        if(tree_rank[x_root_idx]==tree_rank[y_root_idx]):
            tree_rank[y_root_idx] = tree_rank[y_root_idx] + 1
    #tree[x_root_idx] = (y_root_idx,z-tree[x_root_idx][1]+tree[y_root_idx][1])

def diff(tree,x,y):
    x_idx = find(tree,x)
    y_idx = find(tree,y)
    if not(x_idx == y_idx):
        return "?"
    return tree[y][1] - tree[x][1]

if __name__ == '__main__':
    N,query_num = map(int, input().split())
    weighted_union_find_tree = [(-1,0) for _ in range(N)]
    tree_rank = [0]*N
    for i in range(query_num):
        query = list(map(int,input().split()))
        if(query[0]==0):
            relate(weighted_union_find_tree,query[1],query[2],query[3])
            #print(weighted_union_find_tree)
            #print(tree_rank)
        elif(query[0]==1):
            res = diff(weighted_union_find_tree,query[1],query[2])
            print(res)




Measured memory_bytes: 16804
#include <stdio.h>
int main() {
  int a,b,c,dd,e,k;
  scanf("%d %d %d %d %d %d",&a,&b,&c,&dd,&e,&k);
  if (e - a > k) {
    printf(":(\n");
  } else {
    printf("Yay!\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
 
using namespace std;
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,k;
    double p[200005];
    cin>>n>>k;
    reps(i,n){
      cin>>p[i];
      p[i] = SUM(p[i])/p[i];
    }

    p[0] = 0;
    reps(i,n){
      p[i] += p[i-1];
    }

    double maxv = 0;
    for(int i = k;i <= n ; i ++ ){
      maxv = max(maxv,p[i]-p[i-k]);
    }

    cout<<SYOU(7)<<maxv<<'\n';
    return 0;
}



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

using namespace std;

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    long long ans = 0;
    for(int i = 1; i <= n; i++) {
        long long y = floor(n / i);
        ans += ((i * y * (y + 1)) / 2);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3620