akhauriyash/Code-Regression huggingface dataset:
def get_next_int():
    return int(float(input()))
def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])

def main():
    h, w, d = get_next_ints()
    values = {}
    for i in range(h):
        line_data = get_next_ints()
        for j, a in enumerate(line_data):
            values[a] = (i, j)
    from collections import defaultdict
    distances = defaultdict(int)
    
    for a in range(1,h * w + 1):
        i, j = values[a]
        prev = a - d
        if prev in values:
            prev_i, prev_j = values[prev]
            distances[a] = abs(prev_i - i) + abs(prev_j - j) + distances[prev]
        else:
            distances[a] = 0
    q = get_next_int()
    for k in range(q):
        r, l = get_next_ints()
        print(distances[l] - distances[r] )
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 36312
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int INT_MAX_SQRT = sqrt(INT_MAX);
int pwi(int x, int p) {
    if (p == 0) return 1;
    if (p == 1) return x;
    int tmp = pwi(x, p / 2);
    if (tmp > INT_MAX_SQRT) return 0;  // overflow
    if (p % 2 == 0)
        return tmp * tmp;
    else
        return tmp * tmp * x;
}

long LONG_MAX_SQRT = sqrt(LONG_MAX);
long pwl(long x, long p) {
    if (p == 0) return 1;
    if (p == 1) return x;
    long tmp = pwl(x, p / 2);
    if (tmp > LONG_MAX_SQRT) return 0;  // overflow
    if (p % 2 == 0)
        return tmp * tmp;
    else
        return tmp * tmp * x;
}

using P = pair<long, int>;

int main() {
    int N;
    long res = 1;
    cin >> N;
    long MAX = pwl(10, 18);
    for (int n = 0; n < N; n++) {
        long A;
        cin >> A;
        if (A == 0) {
            res = 0;
        } else if (MAX * 1.1 / res < A || res < 0) {
            res = -1;
        } else {
            res *= A;
        }
    }
    if (MAX < res || res < 0)
        cout << -1 << endl;
    else
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
ll A1,A2,x,ans,X;
bool check(ll a,ll b) {
	for(int i=41; ~i; i--) {
		int ai=(a>>i)&1;
		int bi=(b>>i)&1;
		if(ai==1&&bi==1) return false;
	}
	return true;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin >> N;
	cin>>A1>>A2;
	ll S = A1 + A2;
	for(int i=3; i<=N; i++) cin>>x,X^=x;
	ll D=(S-X)>>1;
	if(((S-X)&1)||D<0||D>A1||!check(D,X))  cout<<-1,exit(0);
	ans=D;
	for(int i=41; ~i; i--) {
		bool Xi=(X>>i)&1;
		if(Xi&&((ans|(1ll<<i))<=A1))
			ans|=1ll<<i;
	}
	cout<<(ans? A1-ans:-1);
	return 0;
}

Measured memory_bytes: 3636
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(false);cin.tie(nullptr);
cout << fixed << setprecision(10);
    int n,m;
    cin>>n>>m;
    dsu uf(n);
    int x,y;
    rep(i,m){
        cin>>x>>y;
        x --;
        y --;
        uf.merge(x,y);
    }
    
    set<int> z;
    rep(i,n){
        z.insert(uf.leader(i));
    }
    int ans=z.size()-1;
    cout<<ans<<endl;
}/*
./problem.exe
*/

Measured memory_bytes: 7672
N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
for left in range(N + 1):
    for right in range(N + 1):
        if left + right > N or left + right > K:
            continue
        L = V[:left]
        R = V[::-1][:right]

        A = L + R
        A.sort(reverse=True)
        k = K - (left + right)
        while k > 0 and A and A[-1] < 0:
            A.pop()
            k -= 1
        ans = max(ans, sum(A))
print(ans)


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

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


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int H, W, K;
	cin >> H >> W >> K;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	vector<vector<char>> Map(H, vector<char>(W));
	for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> Map[i][j];
	queue<vector<int>> Q;
	Q.push({ y1 - 1,x1 - 1,0,0 });
	while (!Q.empty()) {
		int x = Q.front()[0];
		int y = Q.front()[1];
		int d = Q.front()[2];
		int npd = Q.front()[3];
		Q.pop();
		if (x == y2 - 1 && y == x2 - 1) {
			cout << d << endl;
			return 0;
		}

		int nx, ny, pd;
		vector<vector<int>> subs;
		if (npd != 1 && abs(npd) != 2) {
			nx = x - 1, ny = y, pd = 1;
			subs = {};
			while (nx >= 0 && abs(nx - x) <= K && Map[ny][nx] != '@') {
				if (abs(nx - x) == K) pd = -1;
				if (Map[ny][nx] == '.') {
					subs.push_back({ nx,ny,d + 1,pd });
					Map[ny][nx] = 'x';
				}
					nx--;
			}
			for (int i = subs.size() - 1; i >= 0; i--) Q.push(subs[i]);
		}
		if (npd != 2 && abs(npd) != 1) {
			nx = x + 1, ny = y, pd = 2;
			subs = {};
			while (nx < W && abs(nx - x) <= K && Map[ny][nx] != '@') {
				if (abs(nx - x) == K) pd = -2;
				if (Map[ny][nx] == '.') {
					subs.push_back({ nx,ny,d + 1,pd });
					Map[ny][nx] = 'x';
				}

				nx++;
			}
			for (int i = subs.size() - 1; i >= 0; i--) Q.push(subs[i]);
		}
		if (npd != 3 && abs(npd) != 4) {
			nx = x, ny = y - 1, pd = 3;
			subs = {};
			while (ny >= 0 && abs(ny - y) <= K && Map[ny][nx] != '@') {
				if (abs(ny - y) == K) pd = -3;
				if (Map[ny][nx] == '.') {
					subs.push_back({ nx,ny,d + 1 ,pd });
					Map[ny][nx] = 'x';
				}
				ny--;
			}
			for (int i = subs.size() - 1; i >= 0; i--) Q.push(subs[i]);
		}
		if (npd != 4 && abs(npd) != 3) {
			nx = x, ny = y + 1, pd = 4;
			subs = {};
			while (ny < H && abs(ny - y) <= K && Map[ny][nx] != '@') {
				if (abs(ny - y) == K) pd = -4;
				if (Map[ny][nx] == '.') {
					subs.push_back({ nx,ny,d + 1,pd });
					Map[ny][nx] = 'x';
				}
				ny++;
			}
			for (int i = subs.size() - 1; i >= 0; i--) Q.push(subs[i]);
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 11152
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>

using namespace std;

//a = s1.size();
//vector<string> s1;
//string s2 = accumulate( s1.begin(), s1.end(), string() );

int main()
{
  int a = 0 , b = 0, c = 0, d = 0, e = 0, f = 0;
  int i = 0, j = 0;
  double d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0;
  int a1[256], a2[512], a3[1024];
  char s1[200000], s2[200000], s3[200000];
  
  cin >> s1 >> s2;
  
  if(s1[0] == s2[0]){
    a++;
  }
  if(s1[1] == s2[1]){
    a++;
  }
  if(s1[2] == s2[2]){
    a++;
  }
  cout << a << endl;
}
  


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
void pkuassert(bool t){t=1/t;};

int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

int n,m;

void solve(){
  vector<PI> in(n);
  rep(i,n) cin >> in[i].S >> in[i].F;
  sort(ALL(in));
  reverse(ALL(in));
  ll ans=0;
  FOR(it,in){
    int le=min(it->S,m);
    it->S -= le;
    m -= le;
    ans += it->S*it->F;
  }
  cout << ans << endl;
}

int main(int argc, char *argv[])
{
  while(cin >> n >> m && n|m) solve();
  return 0;
}

Measured memory_bytes: 1272
import java.util.*;

public class Main {
    public static void main(String[] args) {
        int ans=0;
        int bool = 1;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] nums = new Integer[n];
        for(int i=0;i<n;i++){
            nums[i] = sc.nextInt();
        }
        Arrays.sort(nums, Collections.reverseOrder());
        for (int num:nums){
            ans += num*bool;
            bool=(-bool);
        }
        System.out.println(ans);
    }
}

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

void print_ans(bool flag){
    if(flag){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }   
}

int main(){
    string s;
    cin >> s;
    print_ans(s[0] == s[2]);
    return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
int main()
{
	long n,a[10000],min=1000000,max=-1000000,sum=0;
	scanf("%ld",&n);
	for(int i=0;i<n;i++)
		scanf("%ld",&a[i]);
	for(int i=0;i<n;i++){
		if(min>a[i])
			min=a[i];
		if(max<a[i])
			max=a[i];
		sum=sum+a[i];
	}
	printf("%ld %ld %ld\n",min,max,sum);
	return 0;
}

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

const ll INF = 1LL << 60;


int main() {
    long long K;
    scanf("%lld",&K);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);

    for (ll i = A; i <= B; i++) {
        if (i % K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}


Measured memory_bytes: 3656
#include <iostream>

using namespace std;

int main() {
	int n;
	while(1) {
		cin >> n;
		if (!n) break;
		int maxsum = -1000000;
		int sum = 0;
		for (int i = 0; i < n; i++) {
			int a;
			cin >> a;
			sum += a;
			if (sum > maxsum) maxsum = sum;
			if (sum < 0) sum = 0;
		}
		cout << maxsum << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PA;
typedef priority_queue<PA, vector<PA> > PQ;
typedef vector<int> VE;
#define int long long
#define INF 1000000009
#define INFL 1000000000000000018
#define mod 1000000007
#define pb push_back
#define MAXN 100005

int n, a, b, c;
string s;

signed main()
{
    cin >> s;
    n = (int)s.size();
    for(int i = 0; i < n; i++){
        if(s[i] == 'C' && i > 1 && i < n - 1){
            a++;
        }
        else if(i == 0 && s[i] == 'A'){
            b++;
        }
        else if('A' <= s[i] && s[i] <= 'Z'){
            c++;
        }
    }
    if(a == 1 && b == 1 && c == 0){
        printf("AC\n");
    }
    else{
        printf("WA\n");
    }


    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	loop:
	for sc.Scan() {
		s := sc.Text()
		arr := strings.Split(s, " ")
		a, _ := strconv.Atoi(arr[0])
		op := arr[1]
		b, _ := strconv.Atoi(arr[2])
		switch op {
		case "+":
			fmt.Println(a + b)
		case "-":
			fmt.Println(a - b)
		case "*":
			fmt.Println(a * b)
		case "/":
			fmt.Println(a / b)
		default:
			break loop
		}
	}
}



Measured memory_bytes: 1092
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

ll mod = 1e9+7;
const double error = 1e-7;
const double PI = acos(-1); //const ld PI = acosl(-1)

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

#define debug(x) cerr<<#x<<" = "<<(x)<<"\n"
#define hoise cerr<<"hoise\n"
#define tham getchar()
mt19937_64 rng((unsigned int) chrono::system_clock::now().time_since_epoch().count());

inline ll MOD(ll x, ll m = mod)
{
    ll y = x % m;
    return (y >= 0) ? y: y+m;
}

const int inf = 1e8+5;
const ll infl = 1e15;
const int nmax = 2e6+5;
///====================== template =========================

int LIS(vector<int> a, int n) {
	vector<int> lis;
	for(int i=0; i<n; ++i) {
		vector<int>::iterator it = upper_bound(lis.begin(), lis.end(), a[i]);
		if(it == lis.end()) lis.push_back(a[i]);
		else *it = a[i];
	}
	return (int) lis.size();
}

int main(){
    FASTIO;
    int n;
    cin>>n;
    vector<int> input(n);
    for(int i = 0; i<n; i++){
        cin>>input[i];
    }

    reverse(input.begin(), input.end());
    int res = LIS(input, (int) input.size());
    cout << res << "\n";

    return 0;
}


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

using namespace std;

typedef long long int ll;

template<class T> inline bool chmax(T& a,T b){ if(a<b){ a=b; return true;} return false; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){ a=b; return true;} return false; }

typedef pair<int,int> pair;

//
int n;
vector<int> p;
vector<int> q;

int stair(int num){
    return (num==0) ? 1 : num*stair(num-1); 
}

int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        int m; cin >> m;
        p.emplace_back(m);
    }
    for(int i=0;i<n;i++){
        int m; cin >> m;
        q.emplace_back(m);
    }

    if(p==q){
        puts("0");
        return 0;
    }
   

    //
    int a=0,b=0;
    for(int i=0;i<n-1;i++){
        int P=p[i]-1;
        int Q=q[i]-1;
        for(int j=i+1;j<n;j++){
            if(p[j]>p[i])
                p[j]--;
            if(q[j]>q[i])
                q[j]--;
        }
        int st=stair(n-i-1);
        a+=P*st;
        b+=Q*st;
    }

    a++;b++;
    //printf("(a,b)=(%d,%d)\n",a,b);
    cout << abs(a-b) << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)


int main() {
	int X;
	cin >> X;
	int tmp = 600;
	int ans = 8;
	while (tmp<=X) {
		ans--;
		tmp += 200;
	}
	cout << ans;
}
	



Measured memory_bytes: 3628
from statistics import median

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0] * N

    for i in range(N):
        B[i] = A[i] - i - 1

    b = int(median(B))
    sumB = 0
    for i in range(N):
        sumB += abs(B[i] - b)

    print(sumB)


main()

Measured memory_bytes: 27244
n=int(input())
a=list(map(int,input().split()))
from itertools import accumulate
b=[0]+list(accumulate(a))
l=0
r=2
ans=10**18
for i in range(1,n-1):
    while b[i]-b[l]>b[l+1]:
        l+=1
    while b[-1]-b[r]>b[1+r]-b[i]:
        r+=1
    p=b[l]
    q=b[i]-b[l]
    rr=b[r]-b[i]
    s=b[n]-b[r]
    ans=min(ans,abs(max(p,q,rr,s)-min(p,q,rr,s)))
    
print(ans)

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

typedef long long ll;

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


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

    int a, b; cin >> a >> b;
    cout << a*b-(a+b-1) << '\n';
    return 0;
}

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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("fibsubseq.in","r",stdin)
#define write()         freopen("fibsubseq.out","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long int
#define endll           printf("\n")
#define pf              printf
#define pi              acos(-1.0)
#define eps             1e-10
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())

bool Check(unsigned int  N,int pos){return (bool)(N & (1LL<<pos));}
ll  Set(unsigned int N,int pos){    return N=N | (1LL<<pos);}
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define mod  1000000007
#define mod1 1000000009
#define var    int ii,i,j,k,z=0,c=0,t,x,y,l,r,mid
//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};

bool chk(int x,int pos){return (bool)(x&(1<<pos));}
int Set(int x,int pos){return x=x|(1<<pos);}
int clr(int x,int pos){return x=x&~(1<<pos);}

ll n,m,dp[100005][2],p;
vector<ll > v[100005];

ll fn(ll node,ll p,ll clr)
{
    ll &z=dp[node][clr];
    if(z!=-1)return z;
    z=1;
    for(ll i=0;i<v[node].size();i++)
    {
        if(v[node][i]!=p)
        {
            ll x=0;
            x+=fn(v[node][i],node,0);
            if(clr==0)x+=fn(v[node][i],node,1);
            z*=x;
            if(z>mod)z%=mod;
        }
    }
    return z;
}

int main()
{
    ll var;
    sfl(n);
    mem(dp,-1);
    for(i=1;i<n;i++)
    {
        sfl(x);sfl(y);
        v[x].pb(y);
        v[y].pb(x);
    }
    z=fn(1,0,0);
    z+=fn(1,0,1);z%=mod;
    cout<<z<<endl;
}


Measured memory_bytes: 15616
H, W=map(int, input().split())
m=[[-1 for i in range(W+2)]]
mm=[[-1]+[0 for i in range(W)]+[-1] for j in range(H)]
m=m+mm+m

for i in range(1, H+1):
  s=input()
  for j in range(1, W+1):
    if s[j-1]=='#':
      m[i][j]=1
      
out='Yes'
for i in range(1, H+1):
  for j in range(1, W+1):
    if m[i][j]==1:
      if m[i-1][j]<1 and m[i+1][j]<1 and m[i][j-1]<1 and m[i][j+1]<1:
        out='No'
        
print(out)

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

using namespace std;

int main(){
    int N,sumE=0,sumW=0,ans=999999;
    string S;
    cin>>N>>S;
    int West[N];
    int East[N];
    for(int i=0;i<N;i++){
        if(S[i]=='E'){
            sumE++;
            East[i]=sumE;
            West[i]=sumW;
        }else{
            sumW++;
            West[i]=sumW;
            East[i]=sumE;
        }
    }
    for(int i=0;i<N;i++){
        int sum=West[i]+East[N-1]-East[i];
        if(S[i]=='W')sum--;
        if(sum<ans)ans=sum;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dbg(x) cerr << #x << " : " << x << endl;
const ll mod=1e9+7;
int main(){
    int m,d;
    cin >> m >> d;
    int ans=0;
    for(int i=1;i<=m;i++){
        for(int j=10;j<=d;j++){
            if(j/10>=2 and j%10>=2 and j/10*(j%10)==i) {dbg(i);dbg(j);ans++;}
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int min(int a,int b){
	if(a<b) return a;
	else return b;
}

int main(void) {
	int p,q,r;
	scanf("%d%d%d",&p,&q,&r);
	printf("%d",min(r+p,min(p+q,q+r)));
	return 0;
}

Measured memory_bytes: 128
from bisect import bisect_right
from collections import defaultdict

N, K = map(int, input().split())
As = list(map(int, input().split()))

indices_of_elem = defaultdict(list)
for i, A in enumerate(As):
    indices_of_elem[A].append(i)

empty_index = [0]
while True:
    cur_index = empty_index[-1]
    look_for_elem = As[cur_index%N]
    index_of_indices = bisect_right(indices_of_elem[look_for_elem], cur_index%N)
    if len(indices_of_elem[look_for_elem]) ==  index_of_indices:
        pair_end_index = (cur_index // N) * N + indices_of_elem[look_for_elem][0] + N
    else:
        pair_end_index = (cur_index // N) * N + indices_of_elem[look_for_elem][index_of_indices]

    new_index = pair_end_index + 1
    empty_index.append(new_index)
    if new_index % N == 0:
        break
loop = new_index // N

#print(loop, empty_index)

K %= loop

if K == 0:
    exit()
else:
    start = empty_index[bisect_right(empty_index, K * N) - 1] % N
    tmp_ans = As[start:]

#print(tmp_ans)

index_for_tmp_ans = dict()
split = []
for i, elem in enumerate(tmp_ans):
    if elem in index_for_tmp_ans:
        split.append((index_for_tmp_ans[elem], i))
        while True:
            k, v = index_for_tmp_ans.popitem()
            if k == elem:
                break
    else:
        index_for_tmp_ans[elem] = i

for start, end in split:
    tmp_ans[start:end+1] = [-1] * (end - start + 1)

for ans in tmp_ans:
    if ans != -1:
        print(ans, end = ' ')
        


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

int merge(int a[], int n)
{
    int l[n / 2 + 1];
    int r[n - n / 2 + 1];

    for (int i = 0; i < n / 2; i++)
        l[i] = a[i];
    l[n / 2] = 1145141919;
    for (int i = 0; i < n - n / 2; i++)
        r[i] = a[n / 2 + i];
    r[n - n / 2] = 1145141919;

    int i = 0, j = 0;
    for (int k = 0; k < n; k++)
    {
        if (l[i] <= r[j])
        {
            a[k] = l[i];
            i++;
        }
        else
        {
            a[k] = r[j];
            j++;
        }
    }

    return n;
}

int mergeSort(int a[], int n)
{
    int cnt = 0;
    if (n > 1)
    {
        cnt += mergeSort(a, n / 2);
        cnt += mergeSort(a + n / 2, n - n / 2);
        cnt += merge(a, n);
    }
    return cnt;
}

int main(void)
{
    int n;
    cin >> n;
    int s[n];
    for (int i = 0; i < n; i++)
        scanf("%d", &s[i]);
    int cnt = mergeSort(s, n);
    for (int i = 0; i < n; i++)
    {
        printf("%d", s[i]);
        if (i != n - 1)
            printf(" ");
    }
    printf("\n");
    printf("%d\n", cnt);
}


Measured memory_bytes: 7092
# Problem - 素数

import math

def is_prime(x):
    if x==2:
        return True

    if x<2 or x%2==0:
        return False

    i = 3
    while i<=math.sqrt(x):
        if x%i==0:
            return False
        i += 2

    return True

# input
N = int(input())

# initialization
ans = 0
for i in range(N):
    num = int(input())
    if is_prime(num):
        ans += 1

# output
print(ans)



Measured memory_bytes: 5672
#include<stdio.h>
int main(void)
{
    int i, j, k, n, b, f, r, v;
    int count[4][3][10] = {0};
    scanf("%d", &n);

    for (i = 0; i < n; i++) 
    {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        count[b - 1][f - 1][r - 1] = count[b - 1][f - 1][r - 1] + v;
    }

    for (i = 0; i < 4; i++) 
    {
        for (j = 0; j < 3; j++) 
        {
            for (k = 0; k < 10; k++) 
            {
                printf(" %d", count[i][j][k]);
            }
            printf("\n");
        }

        if (i != 3)
            printf("####################\n");

    }
    return 0;
}


Measured memory_bytes: 2068
#include "bits/stdc++.h"

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

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

int factr(int n) {
  int x = 1;
  REP(i, 2, n) x *= i;
  return x;
}

void Main() {
  int n;
  cin >> n;
  ll P = 1;
  {
    vector<bool> S(n, false);
    rep(i, n) {
      int p;
      cin >> p;
      int x = 0;
      rep(i, p - 1) if (!S[i]) x++;
      P += x * factr(n - i);
      S[p - 1] = true;
    }
  }
  ll Q = 1;
  {
    vector<bool> S(n, false);
    rep(i, n) {
      int p;
      cin >> p;
      int x = 0;
      rep(i, p - 1) if (!S[i]) x++;
      Q += x * factr(n - i);
      S[p - 1] = true;
    }
  }
  cout << abs(P - Q) << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
	int n, m, a[50], b[50], c[50], d[50];
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> c[i] >> d[i];
	}
	long long int min = 1e9, yan, ans = 0, x, y;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			x = a[i] - c[j];
			if (x < 0) {
				x = -x;
			}
			y = b[i] - d[j];
			if (y < 0) {
				y = -y;
			}
			yan = x+y;
			if (yan < min) {
				min = yan;
				ans = j + 1;
			}
		}
		cout << ans << endl;
		min = 1e9;	
	}
	return 0;
}

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

#define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (stderr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int INF = 1e9, MOD = INF + 7;

/////////////////////////////////////////////////////////////////////

const int N = 1e5 + 20;

int dp[N];
vi g[N];

int f(int v) {
	if (dp[v] != -1) return dp[v];
	dp[v] = 0;
	for(int u : g[v]) dp[v] = max(dp[v], f(u) + 1);
	return dp[v];
}

int32_t main(){

    sync;

    int n, m; cin >> n >> m;
    for(int i = 0; i < m; i++) {
    	int v, u; cin >> v >> u;
    	g[v].push_back(u);
    }

    for(int i = 1; i <= n; i++) dp[i] = -1;

    int ans = 0;
    for(int i = 1; i <= n; i++) ans = max(ans, f(i));
    cout << ans << endl;

    return 0;
}

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

int par[100010];
long long tot[100010];

stack <pair <int, int>> s;
stack <pair <int, long long>> t;

int root(int x) {
	if(x == par[x]) return par[x];
	int val = root(par[x]);
	s.emplace(x, par[x]);
	return par[x] = val;
}

void join(int x, int y) {
	x = root(x);
	y = root(y);
	if(x != y) {
		s.emplace(x, par[x]);
		t.emplace(y, tot[y]);
		par[x] = y;
		tot[y] += tot[x];
	}
}

int c[100010];
int l[100010], r[100010], w[100010];
int ans;
int n, m;

bool cmp(int p, int q) {
	return w[p] < w[q];
}
void solve() {
	for(int i = 1; i <= n; i++) {
		par[i] = i;
		tot[i] = c[i];
	}
	vector <int> can;
	for(int i = 1; i <= m; i++) {
		can.emplace_back(i);
	}
	sort(can.begin(), can.end(), cmp);

	stack <int> tm1, tm2;
	for(auto i : can) {
		tm1.push(s.size());
		tm2.push(t.size());
		join(l[i], r[i]);
	}
	reverse(can.begin(), can.end());
	for(auto i : can) {
		if(tot[root(l[i])] < w[i]) {
			while(s.size() > tm1.top()) {
				par[s.top().first] = s.top().second;
				s.pop();
			}
			while(t.size() > tm2.top()) {
				tot[t.top().first] = t.top().second;
				t.pop();
			}
			++ans;
		} else {
			while(s.size() > tm1.top()) {
				s.pop();
			}
			while(t.size() > tm2.top()) {
				t.pop();
			}
		}
		tm1.pop();
		tm2.pop();
	}
}

int main(int argc, char const *argv[])
{
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &c[i]);
	}
	for(int i = 1; i <= m; i++) {
		scanf("%d %d %d", &l[i], &r[i], &w[i]);
	}
	solve();
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 9084
#define _USE_MATH_DEFINES  // M_PI等のフラグ

#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <list>

#define MOD 1000000007
#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))

using namespace std;


void solve(){
    int N;
    cin >> N;
    vector<int> Ds(N);
    for (int i=0; i<N; i++)
    {
        cin >> Ds.at(i);
    }

    sort(Ds.begin(), Ds.end());
    reverse(Ds.begin(), Ds.end());

    int ans = 1;
    int pre_d = Ds.at(0);
    for (int i=1; i<N; i++)
    {
        if (Ds.at(i) < pre_d)
        {
            ans ++;
            pre_d = Ds.at(i);
        }
    }

    cout << ans << endl;
}

int main(int argc, char const *argv[]){
    solve();
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    int64_t num[10][10] = {};
    for(int i=1; i<=N; i++){
        string s = to_string(i);
        num[s[0]-'0'][s.back()-'0']++;
    }
    int64_t ans = 0;
    for(int a=1; a<=9; a++) for(int b=1; b<=9; b++) ans += num[a][b] * num[b][a];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	long long a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	if(c-a-b<0){
		printf("No\n");return 0;
	}
	if(4*a*b<(c-a-b)*(c-a-b)){
		printf("Yes\n");
	}else printf("No\n");
}

Measured memory_bytes: 128
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}

ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


string Toupper(string s){
  string ans="";
  rep(i,s.size()){
    if('a'<=s[i] && s[i]<='z') ans+=(char)s[i]-32;
    else ans+=s[i];
  }
  return ans;
}
string Tolower(string s){
  string ans="";
  rep(i,s.size()){
    if('A'<=s[i] && s[i]<='Z') ans+=(char)s[i]+32;
    else ans+=s[i];
  }
  return ans;
}


const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*bool cmp(pint a, pint b) { return a.second < b.second; }*/

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll w,h,x,y;
  cin>>w>>h>>x>>y;
  cout<<setprecision(10)<<(double)w*h/2<<' ';
  if((double)w/2==(double)x && (double)h/2==(double)y) cout<<1<<endl;
  else cout<<0<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2050;

char s[3];
int n,m,a[N<<1],t[N<<1],pl[2][N],f[N][N],del[2][N][N];

main() {
	cin>>n; m=n; n*=2; 
	for (int i=1;i<=n;i++) {
		scanf("%s",s);
		t[i]=(s[0]=='B');
		scanf("%lld",&a[i]);
		pl[t[i]][a[i]]=i;
	}
	for (int i=1;i<=n;i++) {
		int cnt=0;
		for (int j=i+1;j<=n;j++) {
			if (t[i]==t[j]) cnt+=(a[i]>a[j]);
			else if (t[i]==0) del[t[i]][a[i]-1][a[j]]++;
			else del[t[i]][a[j]][a[i]-1]++;
		}
		if (t[i]==0) {
			for (int j=1;j<=m;j++) del[t[i]][a[i]-1][j]+=del[t[i]][a[i]-1][j-1];
			for (int j=0;j<=m;j++) del[t[i]][a[i]-1][j]+=cnt;
		}
		if (t[i]==1) {
			for (int j=1;j<=m;j++) del[t[i]][j][a[i]-1]+=del[t[i]][j-1][a[i]-1];
			for (int j=0;j<=m;j++) del[t[i]][j][a[i]-1]+=cnt;			
		}
	}
	memset(f,0x3f,sizeof(f));
	f[0][0]=0;
	for (int i=0;i<=m;i++)
		for (int j=0;j<=m;j++) {
			f[i+1][j]=min(f[i+1][j],f[i][j]+pl[0][i+1]-i-j-1+(del[0][i][j]));
			f[i][j+1]=min(f[i][j+1],f[i][j]+pl[1][j+1]-i-j-1+(del[1][i][j]));
		}
//	for (int i=0;i<=m;i++) {
//		for (int j=0;j<=m;j++) cout<<f[i][j]<<' ';
//		cout<<endl;
// 	}
	cout<<f[m][m];
}

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

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

	int n , m , k ; 
	cin >> n >> m >> k  ;
	vector<int> a(n+1) , b(m +1) ; 
	for(int i = 1; i <= n ; ++i)
		cin >> a[i] ; 
	for(int i = 1 ; i <= m ; ++i)
		cin >> b[i] ; 

	for(int i = 0 ; i < n   ; ++i)
	{
		a[i+1] += a[i] ; 
	}
	for(int i = 0 ; i < m ; ++i)
	{
		b[i +1] += b[i] ; 
	}
	int ans = 0 ; 
	for(int i = 0 ; i <= n ; ++i)
	{
		if(a[i] > k )
			break ;
		int rem = k- a[i] ; 
		auto it = lower_bound(b.begin() , b.end() , rem +1 ) ; 
		int idx = 0 ;
		if(it != b.begin()) 
		{
			--it ; 
			idx = it - b.begin() ; 
		}
		ans = max( ans ,idx + i  ); 

	}
	cout << ans ;

}    


















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

typedef long long ll;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second

struct unionf{
  vector<int> data;
  unionf(int size):data(size,-1){}
  bool unions(int x, int y){
    x = root(x);y = root(y);
    if(x != y){
      if(data[y] < data[x]) swap(x,y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool finds(int x, int y){
    return root(x) == root(y);
  }
  int root(int x){
    return data[x] < 0 ? x:data[x] = root(data[x]);
  }
  int find(int x){
    return -data[x];
  }
};

int main(){
  vector<pii> v;
  ll n;
  int m,a,b;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v.pb(mp(a,b));
  }
  reverse(v.begin(),v.end());
  unionf uni(n+10);
  ll out = n * (n-1)/2;
  vector<ll> ret;
  for (int i = 0; i < m; i++) {
    ret.pb(out);
    a = v[i].fi;
    b = v[i].se;
    if(uni.finds(a,b)) continue;
  out -= (ll)uni.find(uni.root(a)) * uni.find(uni.root(b));
  uni.unions(a,b);
  }
  reverse(ret.begin(),ret.end());
  for(int i = 0; i < m; ++i) cout << ret[i] << endl;
  return 0;
}


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

signed main(){
	int n;scanf("%lld",&n);
	int Max=INT_MIN,Min=INT_MAX,sum=0;
	rep(i,n){
		int a;scanf("%lld",&a);
		Min=min(Min,a);Max=max(Max,a);sum+=a;
	}
	printf("%lld %lld %lld\n",Min,Max,sum);
}

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

typedef long long ll;
const int  N = 120;
int a[N];
int n, m;
int main(){
    //freopen("in.txt","r",stdin);
    cin>>n>>m;
    int sum = 0;
    for(int i=0; i<n; i++){
        cin>>a[i];
        sum += a[i];
    }
    int cnt = 0;
    for(int i=0; i<n; i++){
        if(4*m*a[i] >= sum) cnt ++;
    }
    if(cnt >= m) puts("Yes");
    else puts("No");
    return 0;
}


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

public class Main{


	
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		
		int n = Integer.parseInt(br.readLine());
		
		int arr[] = new int [n];
		
		StringTokenizer st1 = new StringTokenizer(br.readLine());
		
		for(int i = 0 ; i < n ; i++)
		{
			arr[i] = Integer.parseInt(st1.nextToken());
		}
		
	
		
		int max = 0;
		int prev = 0;
		
		for(int i = n-2; i >= 0 ; i--)
		{
			if(arr[i] >= arr[i+1])
			{
				prev = prev + 1;
			}
			else
			{
				prev = 0;
			}
			max = Math.max(max, prev);
		}
		
		
		
		out.println(max);
		
		
		out.flush();
		out.close();
	}
	
	
	


}


Measured memory_bytes: 41940
#include<iostream>
#include<string>
#include<algorithm>

int main() {
  std::string s, t;
  std::cin >> s >> t;
  std::sort(s.begin(), s.end());
  std::sort(t.rbegin(), t.rend());
  if (t>s) {
    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std;
struct Card {
    char suit, value;
};
void trace(int N, Card A[]) {
    for(int i = 0; i < N; i++) {
        if(i >= 1) {
            cout << " ";
        }
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

void swap(Card a[], int n1, int n2) {
    Card temp = a[n1];
    a[n1] = a[n2];
    a[n2] = temp;
}

void bubble_sort(int n, Card a[]) {
    for(int i = 0; i < n; i++) {
        for(int j = n - 1;  i!=j; j--) {
            if(a[j].value < a[j-1].value){
                swap(a, j-1, j);
            }
        }
    }
}

void selection_sort(int n, Card a[]) {
    for(int i =0;i<n;i++){
        int minj=i;
        for(int j=i;j<n;j++){
            if(a[minj].value > a[j].value){
                minj = j;
            }
        }
        swap(a,minj,i);
    }
}

bool is_stable(int n,Card a[], Card a2[]){
    for(int i=0;i<n;i++){
        if(a[i].suit!=a2[i].suit){
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    Card a[n];
    Card a2[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i].suit >> a[i].value;
        a2[i].value = a[i].value;
        a2[i].suit = a[i].suit;
    }

    bubble_sort(n,a);
    trace(n,a);
    cout << "Stable" << endl;
    selection_sort(n,a2);
    trace(n,a2);
    if(is_stable(n,a,a2)){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define N 101
using namespace std;
typedef long long ll;
int n,W;
typedef pair<ll,ll> P;
vector<ll> A[4];
ll w;

unordered_map<ll,ll> dp[101];

ll dfs(int pos,ll cost){
  if(pos == -1) return 0;
  if(dp[pos].count(cost)) return dp[pos][cost];
  ll sumv=0,sumw=cost;
  ll res =  dfs(pos-1,cost);
  for(int i=0;i<A[pos].size();i++){
    sumv+=A[pos][i];
    sumw+=w+pos;
    if(sumw<=W) res=max(res,sumv+dfs(pos-1,sumw));
  }
    return res;
  }

int main(){
  cin>>n>>W;  
  int v;
  cin>>w>>v;
  A[0].push_back(v);

  for(int i=0,a,v;i<n-1;i++){
    cin>>a>>v;
    A[a-w].push_back(v);
  } 
  for(int i=0;i<4;i++)
    sort(A[i].begin(),A[i].end(),greater<ll>());
  
  
  cout<<dfs(3,0)<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string str = Console.ReadLine();
		string ans = "";
		if(str=="A"){
			ans = "T";
		} else if(str=="T"){
			ans = "A";
		} else if(str=="C"){
			ans = "G";
		} else {
			ans = "C";
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 11092
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ull n;cin >> n;
  string s;cin >> s;
  map<char,int> m;
  ull ans = 0;

  ull a=0,b=0,c=0;
  for(ull i = 0;i < n ;i++)
  {
    if(s[i] == 'R') a++;
    else if(s[i] == 'G') b++;
    else c++;
  }

  ans = a * b * c;

  ull dis = 0;
  for(ull i = 0;i < n;i++)
  {
    for(ull j = i + 1;j < n; j++)
    {
      ull k = (j - i) + j;
      if(k >= n) break;
      if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i])
        dis++;
    }
  }

  cout << (ull)(ans - dis) << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 3656