akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;
typedef long long LL;

const int MOD = 1e9+7;

vector<vector<int>> dir = {{-1,0},{0,-1},{0,1},{1,0}};

// vector<vector<int>> bfs2(vector<string> &table,int sx,int sy){
//     int m = table.size();
//     int n = table[0].size();
//     auto maze = table;
//     maze[sx][sy] = '#';
//     deque<pair<int,int>> que;
//     que.push_back({sx,sy});
//     vector<vector<int>> re;
//     while(!que.empty()){
//         int tm = que.size();
//         re.clear();
//         while(tm--){
//             auto p = que.front();
//             que.pop_front();
//             int x = p.first;
//             int y = p.second;
//             re.push_back({x,y});
//             for(int i = 0;i<4;i++){
//                 int tx = x+dir[i][0];
//                 int ty=  y+dir[i][1];
//                 if(tx<0||ty<0||tx>=m||ty>=n||maze[tx][ty]=='#')continue;
//                 maze[tx][ty] = '#';
//                 que.push_back({tx,ty});
//             }
//         }
//     }
//     return re;
// }

int bfs(vector<string> &table,int sx,int sy){
    int cnt = 0;
    int m = table.size();
    int n = table[0].size();
    auto maze = table;
    maze[sx][sy] = '#';
    deque<pair<int,int>> que;
    que.push_back({sx,sy});
    while(!que.empty()){
        int tm = que.size();
        while(tm--){
            auto p = que.front();
            que.pop_front();
            int x = p.first;
            int y = p.second;
            for(int i = 0;i<4;i++){
                int tx = x+dir[i][0];
                int ty=  y+dir[i][1];
                if(tx<0||ty<0||tx>=m||ty>=n||maze[tx][ty]=='#')continue;
                maze[tx][ty] = '#';
                que.push_back({tx,ty});
            }
        }
        cnt++;
    }
    return cnt-1;
}
void solve(){
    int m,n;
    cin>>m>>n;
    vector<string> table(m);
    for(int i = 0;i<m;i++){
        cin>>table[i];
    }
    vector<vector<int>> starts;

    for(int i =0;i<m;i++){
        for(int j = 0;j<n;j++){
            if(table[i][j]=='#') continue;
            starts.push_back({i,j});
        }
    }
    int ans = 0;
    for(auto item:starts){
        ans = max(ans,bfs(table,item[0],item[1]));
    }
    cout<<ans<<endl;
}

int main(){
    int T = 1;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
 
ll MOD = 1000000007;
ll INF =1<<29;
 
int main(){
     int n;
     cin >> n;
     vector<int> a(n);
     rep(i,n) cin >> a[i];
     set<int>s;
     rep(i,n) s.insert(a[i]);
     if(n==s.size()) cout << "YES" <<endl;
     else cout << "NO" <<endl;
}

Measured memory_bytes: 10368
#include <cstdio>
#include <algorithm>
using namespace std;
long long rec(long long i) {
	if (i == 0) return 0;
	return 2 * rec(i / 2) + 1;
}
int main() {
	long long H;
	scanf("%lld", &H);
	printf("%lld", rec(H));
	return 0;
}

Measured memory_bytes: 128
fn main() {                                                                                                                                                                                                                                      let scan = std::io::stdin();                                                                                                                                                                                                                                                                                                                                                                                                                                                              let mut line = String::new();                                                                                                                                                                                                                                                                                                                                                                                                                                                             let _ = scan.read_line(&mut line);                                                                                                                                                                                                           let vec: Vec<&str> = line.split_whitespace().collect();                                                                                                                                                                                                                                                                                                                                                                                                                                   let r: f64 = vec[0].parse().unwrap_or(0.0);                                                                                                                                                                                                  println!("{} {}", &r * &r * std::f64::consts::PI, &r * 2 as f64 * std::f64::consts::PI);                                                                                                                                                 }


Measured memory_bytes: 5068
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

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

  int ans[105][105];
  rep(i, 105) {
    rep(j, 105) {
      ans[i][j] = INT_MAX/4;
    }
  }

  vector<pair<P, int>> vec;

  rep(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    ans[a][b] = c;
    ans[b][a] = c;
    vec.push_back(make_pair(P(a,b),c));
  }

  for(int k=1; k<=N; k++) {
    for(int i=1; i<=N; i++) {
      for(int j=1; j<=N; j++) {
        ans[i][j] = min(ans[i][k] + ans[k][j], ans[i][j]);
      }
    }
  }

  int sum = 0;
  rep(i, M) {
    int a = vec.at(i).first.first;
    int b = vec.at(i).first.second;
    int c = vec.at(i).second;
    if (ans[a][b] < c) {
      sum++;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
import java.io.*;

class Main {
    public static void main(String args[]) {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	try {
	    while (true) {
		int n = Integer.parseInt(br.readLine());
		if (n==0) break;
		int a[] = new int[n];
		for (int i=0;i<n;i++)
		    a[i] = Integer.parseInt(br.readLine());
		int max = a[0];
		for (int i=0;i<n;i++) {
		    int d = 0;
		    for (int j=i;j<n;j++) {
			d += a[j];
			if (d>max) max = d;
		    }
		}
		System.out.println(max);
	    }
	} catch (Exception e) {
	    e.printStackTrace();
	}
    } 
}

Measured memory_bytes: 22068
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007
#define ll long long
#define int long long 
# define INF 2e5 + 5
#define ar array
# define fr first
# define sc second
#define wt(x) int x;cin>>x;while(x--)
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
//#define cerr if(false)cerr
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> pbds;

void  c_p_c(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
 
#ifndef ONLINE_JUDGE
  freopen("input1.txt","r",stdin);
  freopen("output1.txt","w",stdout);
#endif
 }
 
int power(int a,int b,int mod){
    a=a%mod;
    if(a==0){
        return 1;
    }
    int res=1;
    while(b){
        if(b&1){
            res=(res*a)%mod;
        }
        b>>=1;
        a=(a*a)%mod;
    }
    return res;
 }
 
int  MMI(int p){
    return power(p,MOD-2,MOD);
}

int32_t main()
{
    
    c_p_c();
   int n;
   cin>>n;
   vector<int> ans(n + 1, 0);
  for(int x = 1; x <= 100; x++)
  {
    for(int y = 1; y <= 100; y++)
    {
      for(int z = 1; z <= 100; z++)
      {
        int cur = x * x + y * y + z * z + x * y + y * z + z * x;
        if(cur <= n)
          ans[cur]++;
      }
    }
  }
  for(int i = 1; i <= n; i++)
    cout << ans[i] << endl;
    




    return 0;


             
    
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n(s.size());
    vector<vector<int>> count(n+1, vector<int>(4, 0));
    for (int i = 1; i <= n; ++i) {
        for (int length = 1; length <= 3 && i - length >= 0; ++length) {
            int best = 0;
            // take the string s[i-length], ..., s[i-1].
            for (int prev_length = 1; prev_length <= 3; ++prev_length) {
                if (prev_length != length || i - 2*length < 0 || s.substr(i - 2*length, length) != s.substr(i - length, length)) {
                    best = max(best, 1 + count[i-length][prev_length]);
                }
            }
            count[i][length] = best;
        }
    }
    int answer = max(max(count[n][1], count[n][2]), count[n][3]);
    cout << answer << endl;
    return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;

int main() {
	double a, b, h, m;
	cin >> a >> b >> h >> m;
	double deg = abs((M_PI * (h + m / 60) / 6) - (M_PI * m / 30));
	double res = a*a + b*b - 2 * a*b*cos(deg);
	res = sqrt(res);
	printf("%.16f\n", res);
	return(0);
}

Measured memory_bytes: 4212
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int h,w,s;
int f[64][64];
pair<int,int> memo[33][33][33][33];
pair<int,int> merge(pair<int,int> a,pair<int,int> b)
{
  return make_pair(a.first+b.first,min(a.second,b.second));
}
pair<int,int> solve(int u,int l,int b,int r)
{
  if(memo[u][l][b][r].first!=-1) return memo[u][l][b][r];
  pair<int,int> answer=make_pair(0,f[b][r]-f[u][r]-f[b][l]+f[u][l]);
  if(answer.second>=s){
    answer.first=1;
    answer.second-=s;
  }
  FOR(i,u+1,b) answer=max(answer,merge(solve(u,l,i,r),solve(i,l,b,r)));
  FOR(i,l+1,r) answer=max(answer,merge(solve(u,l,b,i),solve(u,i,b,r)));
  return memo[u][l][b][r]=answer;
}
int main(void)
{
  for(;;){
    cin >> h >> w >> s;
    if(!h) return 0;
    REP(i,64) REP(j,64) f[i][j]=0;
    REP(i,h) REP(j,w) cin >> f[i+1][j+1];
    REP(i,h+1) REP(j,w) f[i][j+1]+=f[i][j];
    REP(i,h) REP(j,w+1) f[i+1][j]+=f[i][j];
    s=f[h][w]-s;
    REP(i,33) REP(j,33) REP(k,33) REP(l,33) memo[i][j][k][l].first=-1;
    int g,p;
    tie(g,p)=solve(0,0,h,w);
    cout << g << ' ' << p << endl;
    
  }
}

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

using namespace std;

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

vector<int> g[N];
long long ans = 1;

void dfs(int u, int k, int p, int nao, int depth) {
  //cerr << u << " " << k << " " << depth << endl;
  ans *= (long long)k;
  ans %= MOD;
  int nK = k - 1 + nao;
  if (depth >= 2) nK++;
  int bad = 0;
  for (auto v : g[u]) if (v != p) {
    dfs(v, nK - bad, u, bad, depth + 1);
    bad++;
  }
}

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int start = 1;
  for (int i = 1; i <= n; i++) {
    if (g[i].size() == 1) {
      start = i;
      break;
    }
  }
  dfs(start, k, 0, 0, 0);
  cout << ans;
  return 0;
}


Measured memory_bytes: 13568
n, m, x, y = [int(item) for item in input().split()]

xs = sorted([int(item) for item in input().split()] + [x])
ys = sorted([int(item) for item in input().split()] + [y])

if xs[-1] < ys[0]:
  print("No War")
else:
  print("War")

Measured memory_bytes: 3060
def main():
    N, D = map(int, input().split(" "))
    xy = []
    for i in range(N):
        xy.append(list(map(int, input().split(" "))))
    D2 = D **2
    cnt = 0
    for i in range(N):
        if xy[i][0] **2 + xy[i][1] **2 > D2:
            continue
        cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()

Measured memory_bytes: 45308
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#include<string>
#include<cmath>
#include<tuple>
#include<algorithm>
#define INF 1111111111
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> tup;
typedef long long ll;
vector<int> vec(100100);
vector<int> passed(100100);
vector<int> dx = {-1,1};

int main() {
  int n;
  cin >> n;
  cout << n*n*n << endl;
}

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

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

	return 0;
}

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

const int mod = 1e9+7;
int main() {
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  int n,m;
  cin>>n>>m;
  char s[n][m];
  int a[n][m];
  for(int i=0;i<n;i++) {
    for(int j=0;j<m;j++) {
      cin>>s[i][j];
    }
  }
  for(int i=0;i<n;i++) {
    for(int j=0;j<m;j++) {
      a[i][j] = 1000000000;
      if(i+j==0)
        a[i][j] = (s[i][j]=='#');
      else {
        if(i > 0)
          a[i][j] = min(a[i][j],a[i-1][j]+((s[i-1][j]=='.')&&(s[i][j]=='#')));
        if(j > 0)
          a[i][j] = min(a[i][j],a[i][j-1]+((s[i][j-1]=='.')&&(s[i][j]=='#')));
      }
    }
  }
  cout<<a[n-1][m-1];
  cout<<"\n";
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var X int
	fmt.Scan(&X)
	for !isPrime(X) {
		X++
	}
	fmt.Println(X)
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int buf[n+1];
  buf[0]=0;
  int bufsh[n+1];
  bufsh[0]=0;
  int i,k;
  for(i=1;i<=n;i++){
    scanf("%d",&k);
    buf[i]=k;
    bufsh[k]=i;
  }
  for(i=1;i<=n;i++){
    printf("%d ",bufsh[i]);
  }
  return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>

int main(){
  int H,W,i,k;

  while(1){
    scanf("%d %d",&H,&W);
    if(H==0 && W==0){break;}
    else{
      for(i=0; i<H; i++){
	for(k=0; k<W; k++){
	  printf("#");
	}
	printf("\n");
      }
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 572
import java.util.Scanner;

/**
 * コンソールテスト用Main クラス
 *
 */
public class Main {

	/* コンストラクタ */
	Main() {
	//何もしない
	}

	/**
	 * 提出
	 *
	 */

	public static void main(String args[]) {
		Scanner scanner= new Scanner(System.in);
		String a = " ";
		boolean hanntei = false;


		a = scanner.next();
		hanntei = a.matches("[a-z]");


		/* hanntei の値がtrueの場合、小文字 */
		if (hanntei == true) {
			System.out.println("a") ;
		/* それ以外(hanntei の値がfalseの場合、大文字)*/
		} else {
			System.out.println("A") ;
		}
	}
}


Measured memory_bytes: 26668
#include<bits/stdc++.h>
using namespace std;
#define debug(x)        cout<<#x<<" :"<<x<<endl;
#define ff              first
#define ar              array
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define f(i,n)          for(int i=0;i<n;i++)
#define MOD             1000000007
#define pi              3.14159265
#define umii            unordered_map<int,int>
#define umci            unordered_map<char,int>
#define umsi            unordered_map<string,int>

void k_007()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("ip1.txt", "r", stdin);
	freopen("op1.txt", "w", stdout);
#endif
}
bool sortbysec(const pair<int, int> &a,
               const pair<int, int> &b);
int gcd(int a, int b) ;
int prime(int n);
int power(int x, int y);
int lcm(int a, int b);
int32_t main()
{
	k_007();
	char c;
	cin>>c;
	if(c >= 'a' && c <= 'z')
	{
		cout<<"a"<<endl;
	}
	else
	{
		cout<<"A"<<endl;
	}
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
	return (a.second < b.second);
}
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int prime(int n) {
	int flag = 1;
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) {flag = 0; break;}
	}
	return flag;
}
int power(int x, int y)
{
	if (y == 0)
		return 1;
	else if (y % 2 == 0)
		return ((power(x, y / 2) % MOD) * ( power(x, y / 2) % MOD)) % MOD;
	else
		return ((x % MOD) * (power(x, y / 2) % MOD) * (power(x, y / 2) % MOD)) % MOD;
}
int lcm(int a, int b)
{
	return (a * b) / gcd(a, b);
}

Measured memory_bytes: 3560
#include<stdio.h>
 
int main(void){

  int W,H,x,y,r;
 
  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  if((x-r>=0) && (x+r<=W) && (y-r>=0) && (y+r<=H)) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmin (T& a, T b) {if (a > b) {a = b; return true;} return false;}

const long long INF = 1LL << 60;

const int MAX_N = 110;
const int MAX_V = 110000;

int N;
long long W, weight[MAX_N], value[MAX_N];
long long dp[MAX_N][MAX_V];

int main() {
	cin >> N >> W;
	rep(i, N) cin >> weight[i] >> value[i];
	rep(i, MAX_N) rep(j, MAX_V) dp[i][j] = INF;
	dp[0][0] = 0;

	rep(i, N) {
		rep(sum_v, MAX_V) {
			if (sum_v - value[i] >= 0) chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
			chmin(dp[i+1][sum_v], dp[i][sum_v]);
			// cout << dp[i][sum_v] << ", ";
		}
		// cout << endl;
	}

	long long res = 0;
	rep(sum_v, MAX_V) {
		if (dp[N][sum_v] <= W) res = sum_v;
	}
	cout << res << endl;

}

Measured memory_bytes: 98168
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n;cin >> n;
    for(int i = 1;i <= n;i++){
        //f[i]
        bool found = false;
        int ans = 0;
        for(int x = 1;x*x <=i;x++){
            for(int y = x;y*y <= i;y++){
                for(int z = y;z*z <= i;z++){
                    //trace(x,y,z,i);
                    if(x*x + y*y + z*z + x*y + y*z + z*x > i)continue;
                    else if(x*x + y*y + z*z + x*y + y*z + z*x == i){
                        if(x == y && y == z)ans++;
                        else if(x == y || y == z){
                            ans += 3;
                        }
                        else ans += 6;
                        
                        

                        
                    }
                    
                }
            
                
            }
            
            

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


Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;



bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<pair<ll, ll>> x;
    rep(i, n){
        ll a, b; cin >> a >> b;
        x.pb(mp(a, b));
    }
    sort(all(x), compare_by_b);
    ll now = 0;
    rep(i, n){
        now += x[i].first;
        //cout << now << " " << x[i].first << " " << x[i].second << endl;
        if(now > x[i].second){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes";
    cout << endl;
    return 0;
}


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

int main()
{
  int a, b, c, x, y;
  ll ans=0;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a,0);
  vector<ll> q(b,0);
  vector<ll> r(c,0);
  vector<ll> pqr(x + y + c,0);
  REP(i, a)
  {
    cin >> p.at(i);
  }
  REP(i, b)
  {
    cin >> q.at(i);
  }
  REP(i, c)
  {
    cin >> r.at(i);
  }
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());
  sort(q.begin(), q.end());
  reverse(q.begin(), q.end());

  REP(i, x)
  {
    pqr.at(i) = p.at(i);
  }
  REP(i, y)
  {
    pqr.at(x + i) = q.at(i);
  }
  REP(i, c)
  {
    pqr.at(x + y + i) = r.at(i);
  }
  sort(pqr.begin(), pqr.end());
  reverse(pqr.begin(), pqr.end());

  REP(i, x + y)
  {
    ans += pqr.at(i);
   // cout << pqr.at(i) << "\n";
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 4736
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
int mod=1000000007;
typedef long long ll;
using namespace std;

int main(){
	int n;
	ll a,b;
	cin>>n>>a>>b;
	lol(i,n-1){
		ll p,q;
		cin>>p>>q;
		ll tmp=a/p+(a%p>0);
		tmp=max(tmp,b/q+(b%q>0));
		a=p*tmp;
		b=q*tmp;
	}
	cout<<a+b<<endl;
	return 0;
}


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

string divide[4]={"dream","dreamer","erase","eraser"};

int main(){
    string s;
    cin>>s;
    
    reverse(s.begin(), s.end());
    for (int i = 0; i < 4; ++i){
    reverse(divide[i].begin(), divide[i].end());
    }
    
    bool can = true;
    for(int i=0;i<s.size();){
        bool can2 = false;
        for (int j=0;j<4;j++){
            string d =divide [j];
            if (s.substr(i,d.size())==d){
                can2 = true;
                i+=d.size();
            }
        }
            if (!can2){
                can = false;
                break;
        }
    }
    
    if (can){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 512
N, M = map(int, input().split())
starts = []
goals = []
for _ in range(M):
    s, g = map(int, input().split())
    if s == 1:
        starts.append(g)
    elif g == N:
        goals.append(s)

ans = set(starts) & set(goals)

if len(ans) >= 1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 21836
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> State;
const int INF = 1e+8;
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};

// デバッグ出力
void debug(const vector<string>& m){
	cout << "[debug]" << endl;
	for(int y=0 ; y < m.size() ; y++ )
		cout << m[y] << endl;
}

// 幅と高さ
int w, h;

// ゴールの位置を調べる
P search_goal(vector<string>& m){
	int gx, gy;
	for(int y = 0 ; y < h ; y++ ){
		for(int x = 0 ; x < w ; x++ ){
			if( m[y][x] == '&' ){
				m[y][x] = '.';
				gx = x;
				gy = y;
				break;
			}
		}
	}
	return P(gx,gy);
}

int solve(vector<string>& m){	
	// n := ノード数
	int n = w * h; 
	// d[y][x] := (x,y) への最小コスト, まだ確定していないときはINF
	int d[110][110];
	// used[y][x] := (x,y) が探索済みかどうか
	bool used[110][110];
	// 初期化
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			d[y][x] = INF;
			used[y][x] = false;
		}
	}
	
	// ゴールの位置を調べる
	P gp = search_goal( m );
	int gx = gp.first;
	int gy = gp.second;
	
	// (x,y)=(0,0) を始点として探索する
	priority_queue< State , vector<State> , greater<State> > q;
	q.push( State( 0 , P(0,0) ) );
	d[0][0] = 0;
	
	int result = INF;
	while( !q.empty() ){
		// コストの小さい座標から順に出てくる
		int cost = q.top().first;
		int x = q.top().second.first;
		int y = q.top().second.second;
		q.pop();
		// 座標 (x,y) を確定ノードにする
		used[y][x] = true;
		
		// ゴールのとき
		if( x == gx && y == gy ){
			result = min( result , cost );
		}
		
		for(int i=0 ; i < 4 ; i++ ){
			int mx = x + dx[i];
			int my = y + dy[i];
			
			if( mx < 0 || my < 0 || mx >= w || my >= h || used[my][mx] ) continue;
			
			int next_cost = cost;
			if( m[y][x] == '.' && m[my][mx] == '#' ){
				next_cost++;
			}
			if( next_cost < d[my][mx] ){
				d[my][mx] = next_cost;
				State next( next_cost , P(mx,my) );
				q.push( next );
			}
		}
	}
	// debug
	// debug( m );
	/* for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			if( d[y][x] == INF ){
				cout << "?";
			}else{
				cout << d[y][x];
			}
		}
		cout << endl;
	}*/
	return result;
}

int main(){
	while( cin >> w >> h , w || h ){
		vector<string> m(h+2);
		string t;
		for(int i=0 ; i < w+2 ; i++ ){
			t.push_back('.');
		}
		m[0] = m[h+1] = t;
		
		for(int y = 1 ; y <= h ; y++ ){
			string s, s_;
			cin >> s;
			s_ = "." + s + ".";
			m[y] = s_;
		}
		w += 2;
		h += 2;
		cout << solve( m ) << endl;
		//debug2();
		//int ans = d[gy][gx];
		//cout << ans << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define vi vector<int>
#define ll long long
#define pb push_back
#define ii pair<int, int>
#define qi queue<int>
#define si stack<int>
#define mii map<int, int>
#define msi map<string, int>
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
using namespace std;

const int MAX = 1e5+5;
const int mod = 1e9+7;

vi adj[MAX];
int ind[MAX] = {}, dist[MAX] = {};
bool visited[MAX] = {};

void dfs(int u) {
	assert(!visited[u]);
	visited[u] = 1;

	//cout << u << '\n';
	for (int v : adj[u]) {
		dist[v] = max(dist[v], dist[u]+1);
		--ind[v];
		if (ind[v] == 0)
			dfs(v);
	}
}

int main(int argc, char** argv) {
	int n, m, u, v;
	scanf("%d %d", &n, &m);

	while (m--) {
		scanf("%d %d", &u, &v);
		adj[u].pb(v);
		ind[v]++;
	}

	for (int i = 1; i <= n; i++) {
		//cout << ind[v] << '\n';
		if (!visited[i] && ind[i] == 0) {
			//cout << i << '\n';
			dfs(i);
		}
	}

	int ans = 0;

	//for (int i = 1; i <= n; i++)
		//cout << dist[i] << ' ';
	//cout << '\n';

	for (int i = 1; i <= n; i++)
		ans = max(ans, dist[i]);

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

	return 0;
}








Measured memory_bytes: 9728
#include<iostream>
using namespace std;
int main() {
    int k, a, b; cin >> k >> a >> b;
    long long ans = 1;
    if (b - a <= 1) {
        ans += k;
        cout << ans << endl;
        return 0;
    }
    long long en = 0;
    for (int i = 0; i < k; ++i) {
        if (en) {
            en--;
            ans += b;
        } else if (ans >= a && i < k - 1) {
            ans -= a;
            en++;
        } else {
            ans++;
        }
        //cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)

ll M = 1e9 + 7;
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll max3(ll a,ll b,ll c){ return max( max(a,b),c ); }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}
const int N = 1e5 + 5;
vector <int> adj[N];
bool vis[N];
int ans[N];
void bfs(int u)
{
    vis[u] = 1;
    queue <int> q; 
    q.push(u);
    while(!q.empty())
    {
        int v = q.front();
        q.pop();
        for(auto it:adj[v])
        {
            if(vis[it]) continue;
            ans[it] = v; vis[it] = 1;
            //cout<<it<<' '<<v<<endl;
            q.push(it);
        }
    }
}


int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int n,m; cin>>n>>m;
	for(int i=0;i<m;i++)
	{
	    int u,v; cin>>u>>v;
	    adj[u].pb(v);
	    adj[v].pb(u);
	}
	//for(int i=1;i<=n;i++){ for(auto it:adj[i]) cout<<it<<' '; cout<<endl; }
	bfs(1);
	for(int i=2;i<=n;i++) if(ans[i]==0){ cout<<"No"; return 0; }
	cout<<"Yes\n";
	for(int i=2;i<=n;i++) cout<<ans[i]<<'\n';
	
	
	return 0;
}


Measured memory_bytes: 10712
<?php
/*
	AOJ 2109
	title:Ancient Expression
	@kankichi573
*/
$operators=array();

function remove_paren($expr)
{
  $len = strlen($expr)-1;

  if(substr($expr,0,1)!="(" || substr($expr,$len,1) != ")")
    return($expr);
  
  $level=1;$flag=0;
  for($i=0;$i<$len;$i++)
    {
      if(substr($expr,$i,1)=="(")
	$level++;
      if(substr($expr,$i,1) == ")")
	{
	  $level--;
	  if($level==1)
	    $flag =-1;
	}
    }
  if($flag)
    return($expr);
  else
    return(remove_paren(substr($expr,1,$len-1)));
}
function set_paren($expr)
{
  if(strlen($expr)==1)
    return($expr);
  return("(".remove_paren($expr).")");
}

function solve($expr,$prio)
{
  global $operators,$assoc,$gr;

  //fprintf(STDOUT,"exp=%s\n",$expr);

  $expr=remove_paren($expr);
  $len=strlen($expr);

  if($len==1)
    return($expr);

  if($assoc[$prio]=='L')
    {
      $start=$len-1;
      $stop=0;
      $step=-1;
    }
  else	
    {
      $start=0;
      $stop=$len-1;;
      $step=1;
    }	
  $level=0;
  for($i=$start;;$i+=$step)
    {
      if(strchr($operators[$prio],substr($expr,$i,1)) && $level==0)
	{
	  $op1=set_paren(solve(substr($expr,0,$i),0));
	  $opr=substr($expr,$i,1);
	  $op2=set_paren(solve(substr($expr,$i+1),0));
	  return($op1.$opr.$op2);
	}
      if(substr($expr,$i,1)=="(")
	$level++;	
	  if(substr($expr,$i,1)==")")
	    $level--;	
      if($i==$stop)
	break;
    }
  //not find prio=$prio operator
 return(solve($expr,$prio+1));
    
}
//MAIN ROUTINE



fscanf(STDIN,"%d",$n);
for($i=0;$i<$n;$i++)
{
  $assoc=array();
  $operators=array();
  fscanf(STDIN,"%d",$gr);

  for($j=0;$j<$gr;$j++)
    {
      $input=fgets(STDIN);
      $ac=strtok($input," \n\t");
      $assoc[$j]=$ac;
      $cnt=strtok(" \n\t");

      for($k=0;$k<$cnt;$k++)
	{
	  $op=strtok(" \n\t");
	  if($k==0)
	    $operators[$j]=$op;
	  else
	    $operators[$j]=$operators[$j].$op;
	}
    }
  fscanf(STDIN,"%d",$nq);
  for($j=0;$j<$nq;$j++)
    {
      fscanf(STDIN,"%s",$expr);
      $expr2=set_paren(solve($expr,0));
      fprintf(STDOUT,"%s\n",$expr2);
    }
  if($i<$n-1)
    fprintf(STDOUT,"\n");
}
return(0);
?>

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

int main() {
    string s;
    cin >> s;
    for(int i = 0; i < s.length(); i++) {
        if(i % 2 && s[i] != 'i' || i % 2 == 0 && s[i] != 'h') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << (s.length() % 2 ? "No" : "Yes") << endl;
    return 0;
}


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

int main(){
  string S; cin>>S;
  string y = S.substr(0,4);
  string m = S.substr(5,2);
  string d = S.substr(8,2);
  int yy = stoi(y);
  int mm = stoi(m);
  int dd = stoi(d);
  if(mm <= 4) cout<<"Heisei"<<endl;
  else cout<<"TBD"<<endl;
  return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int,x)

parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    mod = 10^9 + 7
    N, M = readline() |> split |> parseMap
    S = readline() |> split |> parseMap
    T = readline() |> split |> parseMap
    DP = [[1 for j in 1:N+1] for i in 1:M+1]
    for i in 1:M
        for j in 1:N
            if T[i]==S[j]
                DP[i+1][j+1] = (DP[i+1][j]+DP[i][j+1])%mod
            else
                DP[i+1][j+1] = (mod + DP[i+1][j]+DP[i][j+1]-DP[i][j])%mod
            end
        end
    end
    println(DP[M+1][N+1])
end

main()


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

struct UnionFind{
    vector<ll> link;
    UnionFind(ll n):link(n,-1){}
    ll find(ll v){
        if(link[v]<0) return v;
        else return link[v]=find(link[v]);
    }
    bool unite(ll v,ll w){
        v=find(v),w=find(w);
        if(v==w) return 0;
        if(link[v]>link[w]) swap(v,w);
        link[v]+=link[w];
        link[w]=v;
        return 1;
    }
    bool same(ll v,ll w){
        return find(v)==find(w);
    }
};

int main(){
    ll n,m;
    cin>>n>>m;
    UnionFind uf(n);
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        a--,b--;
        uf.unite(a,b);
    }
    ll ans=0;
    rep(i,n) ans=max(ans,-uf.link[uf.find(i)]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4764
import java.math.BigDecimal;
import java.util.Scanner;

/**
 * TITLE : Maximum Volume
 * URL : https://atcoder.jp/contests/abc159/tasks/abc159_c
 */
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        double L = sc.nextDouble();
        sc.close();
        double x = L / 3;
        double y = L / 3;
        double z = L - x - y;
        BigDecimal a = new BigDecimal(String.valueOf(x));
        BigDecimal b = new BigDecimal(String.valueOf(y));
        BigDecimal c = new BigDecimal(String.valueOf(z));
        System.out.println(a.multiply(b).multiply(c));
    }
}

Measured memory_bytes: 24660
# coding:utf-8

import sys
import bisect
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


a, b, q = LI()
A = [-INF] + [II() for _ in range(a)] + [INF]
B = [-INF] + [II() for _ in range(b)] + [INF]

for _ in range(q):
    x = II()
    ans = INF
    x_a = bisect.bisect_left(A, x)
    for k in [-1, 0]:
        tmp = abs(x - A[x_a + k])
        x_b = bisect.bisect_left(B, A[x_a + k])
        tmp += min(abs(B[x_b] - A[x_a + k]), abs(B[x_b - 1] - A[x_a + k]))
        ans = min(ans, tmp)

    x_b = bisect.bisect_left(B, x)
    for k in [-1, 0]:
        tmp = abs(x - B[x_b + k])
        x_a = bisect.bisect_left(A, B[x_b + k])
        tmp += min(abs(A[x_a] - B[x_b + k]), abs(A[x_a - 1] - B[x_b + k]))
        ans = min(ans, tmp)

    print(ans)


Measured memory_bytes: 82012
using System;
using System.Linq;

namespace ConsoleApp {

    class Program {
        static void Main(string[] args) {
            var num = int.Parse(Console.ReadLine());
            var numList = Console.ReadLine().Trim().Split().Select(s => int.Parse(s)).ToArray();

            var min = int.MaxValue;
            var max = int.MinValue;

            foreach (var n in numList) {
                min = Math.Min(n, min);
                max = Math.Max(n, max);
            }

            Console.WriteLine(max - min);
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <vector>
using namespace std;
int main(){
    vector<int> antenna(5);
    for(auto i = antenna.begin(); i < antenna.end(); i++){
        cin >> *i;
    }
    int k;
    cin >> k;
    for(auto i = antenna.begin(); i < antenna.end(); i++){
        for(auto j = antenna.begin() + distance(antenna.begin(), i) + 1; j < antenna.end(); j++){
            if(abs(*i - *j) > k){
            cout << ":(" << endl;
            return 0;
        }
        }
    }
    cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1; rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int a[LIMIT2]={0};
ll b[LIMIT2]={0};
int tmp(const void *p,const void *q){
  int n = a[*(int *)p]-a[*(int *)q];
  if(n!=0) return n;
  
  if(b[*(int *)p]-b[*(int *)q]==0) return 0;
  else if(b[*(int *)p]-b[*(int *)q]>0) return 1;
  else return -1;
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,tmp2=0;
  int c[LIMIT1]={0};
  char s[LIMIT1];
  
  scanf("%lld %lld",&n,&m);
  rep(i,m){
    scanf("%d %lld",&a[i],&b[i]);
  }
  rep(i,m) c[i] = i;
  qsort(c,m,sizeof(int),tmp);
  tmp2=1;
  rep(i,m){
    //printf("%lld ",b[c[i]]);
    b[c[i]] = tmp2;
    if(i<m-1 && a[c[i]]!=a[c[i+1]]){
      tmp2=1;
    }else{
      tmp2++;
    }
  }
  rep(i,m){
    printf("%06d%06lld\n",a[i],b[i]);
  }
  
  return 0;
}



Measured memory_bytes: 5240
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  unordered_set<char> chars;
  for (char c : s){
    chars.insert(c);
  }
  cout << (chars.size() == s.size() ? "yes" : "no") << endl;
}

Measured memory_bytes: 256
N,M,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

A = [0]
B = [0]

for i in range(N):
    A.append(A[i]+a[i])

for i in range(M):
    B.append(B[i]+b[i])
ans = 0

p = M
for i in range(0,N+1):
    if A[i] > K:
        break
    while B[p] > K - A[i]:
        p -= 1
    ans = max(ans,i+p)

print(ans)

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int h, w, k; cin >> h >> w >> k;
	vector<int> emp, nemp;
	vector<string> S;
	vector<vector<int>> ret(h, vector<int>(w, 0));
	int cnt=1;
	for (int i=0; i<h; i++) {
		string s; cin >> s;
		S.push_back(s);
		bool empty = true;
		for (int j=0; j<w; j++) {
			if (s[j]=='#') {
				empty = false;
				break;
			}
		}

		if (empty) {
			emp.push_back(i);
			continue;
		} else {
			nemp.push_back(i);
		}

		int lichi = 0;
		for (int j=0; j<w; j++) {
			ret[i][j] = cnt;
			if (s[j]=='#') {
				lichi = j;
				cnt++;
			} else if (s[j=='.'] && j==w-1) {
				cnt--;
				for (int k=w-1; k>lichi; k--) {
					ret[i][k] = cnt;
				}
				cnt++;
			}
		}
	}
	int last = nemp[nemp.size()-1];
	for (int i=0; i<emp.size(); i++) {
		int now = emp[i];
		int t;
		if (now > last) {
			t = last;
		} else {
			auto itr = lower_bound(nemp.begin(), nemp.end(), now);
			t = *itr;
		}
		for (int j=0; j<w; j++) ret[now][j] = ret[t][j];
	}

	for (int i=0; i<h; i++) {
		for (int j=0; j<w; j++) {
			cout << ret[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define int long long
#define FASTIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
    FASTIO;
    int n;
    cin>>n;
    int arr[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    sort(arr+1,arr+n+1);
    int cnt=0;
    for(int i=1;i<=n-2;i++)
    {
        for(int j=i+1;j<=n-1;j++)
        {
            if(arr[i]!=arr[j])
            {
                for(int k=j+1;k<=n;k++)
                {
                    if(arr[i]!=arr[k] && arr[j]!=arr[k])
                    {
                        if(arr[i]+arr[j]>arr[k])
                            cnt++;
                    }
                }
            }
        }
    }
    cout<<cnt;
    return 0;
}



Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define for1(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define endl '\n'
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    string s;
    cin >> s;
    rep(i, 4) {
        cout << s[i];
    }
    cout << ' ';
    for1(i, 4, 12) {
        cout << s[i];
    }
    cout << endl;
	return 0;
}

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

class Progaram
{
    static void Main(String[] args)
    {
        var x = Int32.Parse(Console.ReadLine());
        var expo = new Boolean[x + 1];

        expo[1] = true;
        for (var b = 2; x >= b; b++)
        {
            var v = b * b;
            while (v <= x)
            {
                expo[v] = true;
                v *= b;
            }
        }
        for (var i = x; i >= 1; i--)
            if (expo[i])
            {
                Console.WriteLine(i);
                return;
            }
    }
}

Measured memory_bytes: 13140
S = input()

cnt = [0,0,0,0]

for i in range(4):
  
  for j in range(4):
    if S[i] == S[j]:
      cnt[i] += 1
      
    else:
      pass

if cnt[0] == cnt[1] == cnt[2] == cnt[3] == 2:
  print("Yes")
  
else:
  print("No")
    

Measured memory_bytes: 2940
N, M = map(int, input().split())
H = list(map(int, input().split())) 
A = [0]*M
B = [0]*M

for i in range(M):
    A[i], B[i] = map(int, input().split())
    A[i] -= 1
    B[i] -= 1

lis = [0]*N

for i in range(M):
    if H[A[i]] >= H[B[i]]:
        lis[B[i]] = -1
    if H[A[i]] <= H[B[i]]:
        lis[A[i]] = -1
    

print(lis.count(0))

Measured memory_bytes: 21692
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()

score = {"s":R, "p":S, "r":P}

ans = 0
for i in range(K):
    j = i
    tmp = ""
    while j <N:
        if tmp != T[j]:
            ans += score[T[j]]
            tmp = T[j]
        else:
            tmp = ""
        j += K

print(ans)



Measured memory_bytes: 3316
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int max = A + B;

        max = Math.max(max, A - B);
        max = Math.max(max, A * B);

        System.out.println(max);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>

const int MAXN = 1000;

int a[MAXN];

int main() {
  int n, k;
  std::cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    std::cin >> a[i];
  }
  std::sort(a, a + n);
  int sum = 0;
  for (int i = 0; i < k; ++i) {
    sum += a[i];
  }
  std::cout << sum << std::endl;
  return 0;
}


Measured memory_bytes: 3648
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.regex.Pattern;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			String line = scanner.next();
			if (line.equals("0"))
				break;
			Pattern pattern = Pattern.compile("^r+$|^g+$|^b+$");
			Deque<String> deque = new ArrayDeque<String>();
			Set<String> set = new HashSet<String>();
			deque.offer(line);
			boolean flag = false;
			int step = 0;
			loop: while (!deque.isEmpty()) {
				int size = deque.size();
				for (int i = 0; i < size; i++) {
					String tmp = deque.pop();
					if (pattern.matcher(tmp).find()) {
						flag = true;
						break loop;
					}
					if (!set.contains(tmp)) {
						set.add(tmp);
						char[] chs = tmp.toCharArray();
						for (int j = 0; j < chs.length - 1; j++) {
							char l = chs[j];
							char r = chs[j + 1];
							if (l != r) {
								char[] tmpchs = Arrays.copyOf(chs, chs.length);
								if (l != 'r' && r != 'r')
									tmpchs[j] = tmpchs[j + 1] = 'r';
								else if (l != 'g' && r != 'g')
									tmpchs[j] = tmpchs[j + 1] = 'g';
								else {
									tmpchs[j] = tmpchs[j + 1] = 'b';
								}
								deque.offer(String.valueOf(tmpchs));
							}
						}
					}
					
				}
				step++;
			}
			System.out.println(flag ? step : "NA");
		}
	}
}

Measured memory_bytes: 94140