akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll pair<ll,ll>
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 200005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
     ll h1,s1,h2,s2;
     cin >> h1 >> s1 >> h2 >> s2;
     ll turn = 0;
     while(h1>0 && h2>0)
     {
          if(turn==0)
          {
               h2 -= s1;
          }
          else
          {
               h1 -= s2;
          }
          turn ^= 1;
     }
     if(h1<=0)
     {
          cout<<"No";
     }
     else
     {
          cout<<"Yes";
     }
}

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

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

int main() { 
    int n, i = 0, a = 0;
    cin >> n;
    while(a < n) {
      i++;
      a += i;
    }
    for(int j = 1; j <= i; ++j) {
      if(j != a-n) {
        cout << j << '\n'; 
      }
    }
}


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

int main()
{
    int N,L;
    cin >> N >> L;
    vector<string> s;
    s.resize(N);
    rep(i,N)cin >> s[i];
    sort(s.begin(),s.end());
    rep(i,N){
        cout << s[i];
    }cout << endl;

}

Measured memory_bytes: 256
rr = raw_input
rrm = lambda: map(int, rr().split())

from collections import deque
def solve(N, A):
    S = sum(A)
    A.sort()
    A = deque(A)
    moves = []

    if A[0] > 0: # all pos, ans is S - A[0]
        ans = S - A[0]
        x = A.popleft()
        while len(A) >= 2:
            y = A.popleft()
            moves.append([x,y])
            x = x-y
        moves.append([A.pop(), x])
    elif A[-1] < 0:  # all neg, ans is -S + A[-1]
        ans = A[-1] - S
        x = A.pop()
        while A:
            y = A.pop()
            moves.append([x,y])
            x-=y
    else:
        pos = A.pop()
        neg = A.popleft()
        # neg soaks all pos
        while A and A[-1] >= 0:
            x = A.pop()
            moves.append([neg, x])
            neg -= x
        while A and A[0] <= 0:
            x = A.pop()
            moves.append([pos, x])
            pos -= x
        moves.append([pos, neg])
    return moves

N = int(rr())
A = rrm()
moves = solve(N, A)
ans = moves[-1][0] - moves[-1][1]
print ans
for row in moves:
    print " ".join(map(str, row))
    


Measured memory_bytes: 57056
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#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
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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

int n,m,a,b,c,d[100005] = {};
string s,t;

int main(){

    rep(i,0,3)cin >> d[i];
    sort(d,d+3);
    P(d[0] + d[1]);
	
	return  0;
}

Measured memory_bytes: 256
import math
import itertools

N = int(input())
town = [0]*N

for i in range(N):
    town[i] = [int(i) for i in input().split()]
    
k = math.factorial(N)

zenbu = list(itertools.permutations(town))

kyori = 0

for i in zenbu:
    for j in range(N-1):
        kyori += math.sqrt((i[j][1]-i[j+1][1])**2 + (i[j][0]-i[j+1][0])**2)

print(kyori/k)

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100],b[100];
int main()
{
    int n,ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];

    }
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
        if(a[i]>b[i])
        {
            ans+=(a[i]-b[i]);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input())

x=N

import math
xr=math.ceil(math.sqrt(x))

LIST=[]
for i in range(1,xr+1):
    if x%i==0:
        LIST.append(i)
        LIST.append(x//i)

ANS=1<<60

for l in LIST:
    ANS=min(ANS,l-1+N//l-1)

print(ANS)


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

int p[20] = {1};
int used[1<<20] = {};
vector<int> v;
int M,K;
int main(){
    cin >> M >> K;
    for(int i=1;i<=M+1;i++) p[i] = 2*p[i-1];
    if(K==0){
        for(int i=0;i<p[M];i++){
            cout << i << " " << i << " ";
        }
        cout << endl;
        return 0;
    }
    if((M==1 && K==1) || p[M]<=K){
        cout << -1 << endl;
        return 0;
    }
    deque<int> ans;
    ans.push_front(K);
    used[K] = 1;
    for(auto x:v){
        ans.push_front(x);
    }
    for(int i=0;i<p[M];i++){
        if(used[i]==1) continue;
        ans.push_front(i);
        ans.push_back(i);
    }
    ans.push_back(K);
    for(auto x:ans) cout << x << " ";
    cout << endl;
}

Measured memory_bytes: 2944
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApp16
{
     class Program
    {
        public static void Main()
        {
            while (true)
            {
                string a = Console.ReadLine();
                if (a == null) break;
                decimal[] b= a.Split().Select(decimal.Parse).ToArray();//1 2 3 4 5 6
                decimal[] c = {b[1]*b[3]/b[0],b[2]*b[3]/b[0]};//8 12
                decimal d =( b[5] - c[1]) / (b[4] - c[0]);//-6 -3
                decimal e = (b[2] - d*b[1]) / b[0];//3 2
                Console.WriteLine("{0,0:F3} {1,1:F3}",e,d);
            }
        }
    }
}


Measured memory_bytes: 16460
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
#define ll long long
#define LL ll
#define mem(arry,x) memset(arry,x,sizeof(arry))
const int maxn=1e2+10;
const int INF=0x3f3f3f3f;
string s1[maxn],s2[maxn];
int main()
{
    int n,m;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    int res=0;
    for(int i=1;i<=n;i++) cin>>s1[i];
    cin>>m;
    for(int i=1;i<=m;i++) cin>>s2[i];
    for(int i=1;i<=n;i++){
        int mark=0;
        for(int j=1;j<=n;j++){
            if(s1[i]==s1[j]) mark++;
        }
        for(int j=1;j<=m;j++){
            if(s1[i]==s2[j]) mark--;
        }
        res=max(res,mark);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
//Compiler optimization
#pragma GCC optimize("Ofast")

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

//typedef
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<vl> mat;

//macro
#define reverse(a) reverse(a.begin(),a.end())
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define each(x, v) for (auto &x : v)

//abbreviation
#define pb push_back
#define elif else if
#define mp make_pair
#define endl '\n'

//debug
#define debug(x) cerr << #x << ": " << x << endl
#define v_debug(v) cerr << #v << endl;fr(i,v.size()) cerr << i << ": " << v[i] << endl

//const
const  ll INF = 1e18;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(20);
    ll n;cin >> n;
    vl a(n);
    ll q = 0;
    fr(i,n){
        cin >> a[i];
        q ^= a[i];
    }
    ll ans;
    fr(i,n){
        ans = q^a[i];
        cout << ans;
        if(i<n-1)cout << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 4784
#include <cstdio>
#include <limits>
#include <vector>
#define rep(i,a) for(int i=0;i<(a);++i)

const int INF = std::numeric_limits<int>::max()>>2;

struct edge
{
  int s, t, d; // ?§?????????????????????????

  edge( int s, int t, int d )
  : s(s), t(t), d(d)
  {}
};

int V, E, r;
std::vector<edge> es;
std::vector<int> d;

int main()
{
  scanf( "%d%d%d", &V, &E, &r );
  rep( i, E )
  {
    int s, t, dist;
    scanf( "%d%d%d", &s, &t, &dist );
    es.push_back( edge( s, t, dist ) );
  }

  d.resize( V, INF );
  d[r] = 0;

  bool upd = true;
  bool fl = false;
  int cnt = 0;
  while( upd )
  {
    upd = false;
    ++cnt;

    if( cnt > V )
      break;

    rep( i, E )
    {
      edge &e = es[i];
      if( d[e.s] != INF && d[e.t] > d[e.s]+e.d )
      {
        d[e.t] = d[e.s]+e.d;
        upd = true;

        if( cnt == V )
        {
          puts( "NEGATIVE CYCLE" );
          fl = true;

          break;
        }
      }
    }
  }

  if( !fl ) rep( i, V )
  {
    if( d[i] == INF )
      puts( "INF" );
    else
      printf( "%d\n", d[i] );
  }

  return 0;
}

Measured memory_bytes: 2760
%:pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;

int n, ans, a[N];
map<int, int> g;

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d", a + i), g[a[i]] = i;
	sort(a + 1, a + 1 + n);
	for(int i = 1; i <= n; ++i)
		if(abs(i - g[a[i]]) & 1)
			++ans;
	assert(ans % 2 == 0);
	cout << ans / 2 << '\n';
	return 0;
}


Measured memory_bytes: 5376
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    a=parseMap(split(readline()))
    ans=[0 for i in 1:n]
    for i in a
        ans[i]+=1
    end
    println(join(ans,"\n"))
end
main()

Measured memory_bytes: 203928
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(void){
	int a,v,b,w,t;
	cin >> a >> v >> b >> w >> t;
	int difSpeed = v-w;
	int dis = abs(a-b);
	if(difSpeed>0&&(double)dis/difSpeed<=(double)t){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
using namespace std;

int n;
int parts = 3;
int len[3];
long long mod = 1000000000 + 7;
long long dp[1<<18];
long long nextDP[1<<18];
int isLast[18];
int belongTo[18];
int go[18][11];
int trans[1<<18][18];

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	cin >> n >> len[0] >> len[1] >> len[2];
	memset(dp, 0, sizeof(dp));
	int total = len[0] + len[1] + len[2];
	isLast[0] = 1;
	belongTo[0] = -1;
	int w = 0;
	for(int i = 0; i < 3; i++)
	{
		for(int j = 0; j < len[i]; j++)
		{
			w ++;
			isLast[w] = false;
			belongTo[w] = i;
		}
		isLast[w] = true;
	}
	for(int i = 0; i <= total; i++)
		for(int j = 1; j <= 10; j++)
		{
			if(i + j > total) go[i][j] = 0;
			else
			{

				if((isLast[i] == false && belongTo[i] != belongTo[i+j]) || (belongTo[i+j] > belongTo[i] + 1)) go[i][j] = 0;
				else go[i][j] = (1<<(i+j));
			}
		}
	for(int i = 0; i < (1<<18); i++)
		for(int j = 1; j <= 10; j++)
		{
			int nextState = 0;
			for(int k = 0; k <= total; k++)
				if((i & (1<<k)) > 0)
					nextState |= go[k][j];

			if((i & (1<<total)) > 0)
				nextState |= (1<<total);
			trans[i][j] = nextState;
		}


	dp[1] = 1;

	for(int i = 1; i <= n; i++)
	{
		memset(nextDP, 0, sizeof(nextDP));
		for(int j = 0; j < (1<<18); j++)
			for(int k = 1; k <= 10; k++)
			{
				nextDP[trans[j|1][k]] += dp[j];
				nextDP[trans[j|1][k]] %= mod;
			}
		for(int j = 0; j < (1<<18); j++)
			dp[j] = nextDP[j];
	}
	long long ret = 0;
	for(int j = 0; j < (1<<18); j++)
		if((j & (1<<total)) > 0)
		{
			ret += dp[j];
			ret %= mod;
		}
	cout << ret << endl;




	

	
	return 0;
}


Measured memory_bytes: 22784
def main():
    import sys
    input = sys.stdin.readline

    n = int(input())

    l1 = l2 = l3 = 0
    for i in map(int,input().split()):
        if i == 1:
            l1 += 1
        elif i == 2:
            l2 += 1
        else:
            l3 += 1

    a = l2+l3
    dp = [[[0.0]*(l3+1) for i in range(a+1)] for j in range(n+1)]

    for i in range(1,n+1):
        for j in range(min(i,a)+1):
            for k in range(min(j,l3)+1):
                s = i-j
                t = j-k
                count = n/(s+t+k)
                if s > 0:
                    count += dp[s-1][t][k]*(s/(s+t+k))     
                if t > 0 :
                    count += dp[s+1][t-1][k]*(t/(s+t+k))
                if k > 0 :
                    count += dp[s][t+1][k-1]*(k/(s+t+k))

                dp[s][t][k] = count

    print(dp[l1][l2][l3])
if __name__ == "__main__":
    main()



Measured memory_bytes: 254344
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
typedef unsigned long long ull;
const ull INF = 1e18;
using namespace std;

int main(){
    char c;
    cin>>c;
    if(c>='a' && c<='z'){
        cout<<"a"<<endl;
    }else {
        cout<<"A"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3584
N = int(input())
a = sorted([int(c) for c in input().split()])
#2回の変わり目を記憶
c1,c2,c3 = [0,0,0]
ma = 1
for i in range(N):
    if i > 0:
        if a[i]==a[i-1]+1:
            c1 = c2 
            c2 = c3
            c3 = i
        elif a[i]!=a[i-1]:
            c1,c2,c3=[i,i,i]
    if ma < i - c1+1:
        ma = i - c1+1

print(ma)

Measured memory_bytes: 20044
#include<stdio.h>
main(){
  int a[3],tyo=0,hi=0,i,j,temp;
  while(scanf("%d,%d,%d",&a[0],&a[1],&a[2])!=EOF){
    if(a[0]!=a[1]  && a[0]*a[0]+a[1]*a[1]==a[2]*a[2])
      tyo++;

    if(a[0]==a[1])
      hi++;
  }
    printf("%d\n%d\n",tyo,hi);
    return 0;
}

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

int main() {
	int N, M, a, b, c, d, f, x, y, Z, w, j;
	w = 0;
	j = 0;
	cin >> N;
	int*h = new int[N];
	int*m = new int[N];
	for (a = 0; a < N; a++) {
		cin >> h[a] >> m[a];
	}
	cin >> M;
	int*k = new int[M];
	int*g = new int[M];
	for (b = 0; b < M; b++) {
		cin >> k[b] >> g[b];
	}
	Z = N + M;
	int*q = new int[Z];
	int*r = new int[Z];
	for (a = 0; a < N; a++) {
		q[a] = h[a];
		r[a] = m[a];
	}
	for (b = 0; b < M; b++) {
		q[b + N] = k[b];
		r[b + N] = g[b];
	}
	for (c = 0; c < Z; c++) {
		for (d = c + 1; d < Z ; d++) {
			if (q[c] > q[d]) {
				x = q[c];
				q[c] = q[d];
				q[d] = x;
				y = r[c];
				r[c] = r[d];
				r[d] = y;
			}
			else if (q[c]==q[d]) {
				if (r[c] > r[d]) {
					x = q[c];
					q[c] = q[d];
					q[d] = x;
					y = r[c];
					r[c] = r[d];
					r[d] = y;
				}
			}
		}
	}
	for (c = 0; c < Z; c++) {
		for (d = c + 1; d < Z - w; d++) {
			if (q[c] == q[d] && r[c] == r[d]) {
				for (f = d; f < Z - w; f++) {
					q[f] = q[f + 1];
					r[f] = r[f + 1];
				}
				w = w + 1;
			}
		}
	}
	for (c = 0; c < Z - w; c++) {
		cout << q[c] << ":";
		if (r[c] < 10) {
			cout << 0;
		}
		cout << r[c];
		if (c < Z - w - 1) {
			cout << " ";
		}
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 1188
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_d)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

require "bigdecimal"
require "bigdecimal/util"

a, b = input_a

puts (a * b).floor


Measured memory_bytes: 14540
/*
    Author : DemonStar
*/

#pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native")

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define ll long long
#define pi pair<int, int>
#define pl pair<long long, long long>
#define pld pair<long double, long double>
#define endl '\n'
#define loop(i, n) for (ll i = 0; i < n; i++)
#define rep(i, begin, end) for (__typeof(begin) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(x) x.begin(), x.end()
#define vl vector<ll>
#define vi vector<int>
#define ml map<ll, ll>
#define vpl vector<pair<ll, ll>>
const ll mod = 1e9 + 7;

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t)
{
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t)
{
    for (auto &i : t)
        os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (T &t : v)
        is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v)
{
    for (pair<T1, T2> &t : v)
        is >> t.first >> t.second;
    return is;
}

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    cin >> s;
    vector<vl> dp(h, vl(w, 0));
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (!i and !j)
                dp[i][j] = (s[i][j] == '.');
            else if (!i)
                dp[i][j] = (s[i][j] == '.') * dp[i][j - 1];
            else if (!j)
                dp[i][j] = (s[i][j] == '.') * dp[i - 1][j];
            else if (s[i][j] == '.')
                (dp[i][j] += dp[i - 1][j] + dp[i][j - 1]) %= mod;
        }
    }
    cout << dp[h - 1][w - 1] << endl;
#ifdef LOCAL
    cerr
        << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif

    return 0;
}

Measured memory_bytes: 9216
def resolve():
    N, X, Y = list(map(int, input().split()))
    X -= 1
    Y -= 1
    dists = [[0 for _ in range(N)] for __ in range(N)]
    for i in range(N):
        for j in range(i+1, N):
            dists[i][j] = min(j-i, abs(X-i)+abs(Y-j)+1)
    counts = [0 for _ in range(N)]
    for i in range(N):
        for j in range(i+1, N):
            counts[dists[i][j]] += 1
    for i in range(1, N):
        print(counts[i])


if '__main__' == __name__:
    resolve()

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
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;}
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    int r = 0;
    int s;
    int a, b;
    REP(i, n) {
        cin >> a >> b;
        if (r < a) {
            r = a;
            s = b;
        }
    }
    cout << r + s << endl;
}


Measured memory_bytes: 768
from collections import defaultdict

N, M = map(int, input().split())
H = map(int, input().split())
H_dict = dict(zip(range(1, N + 1), H))
roads = defaultdict(list)
good_count = 0

for _ in range(M):
    A, B = map(int, input().split())
    roads[A].append(B)
    roads[B].append(A)

for i in range(1, N + 1):
    observatorys = roads.get(i)
    if not observatorys:
        good_count += 1
        continue
    most_observatorys = max(observatorys, key=lambda x: H_dict[x])
    if H_dict[i] > H_dict[most_observatorys]:
        good_count += 1
    continue

print(good_count)


Measured memory_bytes: 47912
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a+b>c+d)
    {
        printf("Left\n");
    }
    else if(a+b<c+d)
    {
        printf("Right\n");
    }
    else
        printf("Balanced\n");

    return 0;
}


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

int main(){
    int i;
    cin >> i;
    int x = i / 100;
    int y = i % 100 / 10;
    int z = i % 100 % 10;
    if (x == 7 || y == 7 || z == 7) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3624
class Combination:
    def __init__(self, n_max, mod=10**9+7):
        # O(n_max + log(mod))
        self.mod = mod
        f = 1
        self.fac = fac = [f]
        for i in range(1, n_max+1):
            f = f * i % mod
            fac.append(f)
        f = pow(f, mod-2, mod)
        self.facinv = facinv = [f]
        for i in range(n_max, 0, -1):
            f = f * i % mod
            facinv.append(f)
        facinv.reverse()

    def __call__(self, n, r):  # self.C と同じ
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def C(self, n, r):
        if not 0 <= r <= n: return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def P(self, n, r):
        if not 0 <= r <= n: return 0
        return self.fac[n] * self.facinv[n-r] % self.mod

    def H(self, n, r):
        if (n == 0 and r > 0) or r < 0: return 0
        return self.fac[n+r-1] * self.facinv[r] % self.mod * self.facinv[n-1] % self.mod

    def rising_factorial(self, n, r):  # 上昇階乗冪 n * (n+1) * ... * (n+r-1)
        return self.fac[n+r-1] * self.facinv[n-1] % self.mod

    def stirling_first(self, n, k):  # 第 1 種スターリング数  lru_cache を使うと O(nk)  # n 要素を k 個の巡回列に分割する場合の数
        if n == k: return 1
        if k == 0: return 0
        return (self.stirling_first(n-1, k-1) + (n-1)*self.stirling_first(n-1, k)) % self.mod

    def stirling_second(self, n, k):  # 第 2 種スターリング数 O(k + log(n))  # n 要素を区別のない k グループに分割する場合の数
        if n == k: return 1  # n==k==0 のときのため
        return self.facinv[k] * sum((-1)**(k-m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k+1)) % self.mod

    def balls_and_boxes_3(self, n, k):  # n 要素を区別のある k グループに分割する場合の数  O(k + log(n))
        return sum((-1)**(k-m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k+1)) % self.mod

    def bernoulli(self, n):  # ベルヌーイ数  lru_cache を使うと O(n**2 * log(mod))
        if n == 0: return 1
        if n % 2 and n >= 3: return 0  # 高速化
        return (- pow(n+1, self.mod-2, self.mod) * sum(self.C(n+1, k) * self.bernoulli(k) % self.mod for k in range(n))) % self.mod

    def faulhaber(self, k, n):  # べき乗和 0^k + 1^k + ... + (n-1)^k
        # bernoulli に lru_cache を使うと O(k**2 * log(mod))  bernoulli が計算済みなら O(k * log(mod))
        return pow(k+1, self.mod-2, self.mod) * sum(self.C(k+1, j) * self.bernoulli(j) % self.mod * pow(n, k-j+1, self.mod) % self.mod for j in range(k+1)) % self.mod

    def lah(self, n, k):  # n 要素を k 個の空でない順序付き集合に分割する場合の数  O(1)
        return self.C(n-1, k-1) * self.fac[n] % self.mod * self.facinv[k] % self.mod

    def bell(self, n, k):  # n 要素を k 個以下に分割する場合の数  O(k**2 + k*log(mod))
        return sum(self.stirling_second(n, j) for j in range(1, k+1)) % self.mod

mod = 10**9+7
comb = Combination(2000)
n, k = map(int, input().split())
print(comb.bell(n, k))



Measured memory_bytes: 5776
#include <iostream>
#include <vector>
#include <algorithm>

using vi = std::vector<int64_t>;

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

    int n; std::cin >> n;
    vi v(n);
    for (auto &a : v) std::cin >> a;
    for (auto it = std::next(v.begin()); it != v.end(); ++it) *it += *std::prev(it);
    vi results;
    for (int s = 0; s < 2; s++) {
        int64_t shift = 0, total = 0;
        for (int i = 0; i < n; i++) {
            auto a = v[i] + shift;
            if ((i % 2) == s) {
                if (a <= 0) {
                    auto diff = -a + 1;
                    shift += diff;
                    total += diff;
                }
            } else {
                if (a >= 0) {
                    auto diff = a + 1;
                    shift -= diff;
                    total += diff;
                }
            }
        }
        results.push_back(total);
    }
    std::cout << *min_element(results.begin(), results.end()) << std::endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <stack>

int main(){
	std::stack<int> rail;
	
	int x;
	while(std::cin >> x){
		//car exit
		if(x == 0){
			std::cout << rail.top() << std::endl;
			rail.pop();
		}
		//car enter
		else{
			rail.push(x);
		}
	}
	
}

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

using namespace std;

int main()
{
 int x,y;
 cin>>x>>y;
 if((y>=(2*x))&&(y<=(4*x))&&(y%2==0))
 {
     cout<<"Yes";
 }
 else
 {
     cout<<"No";
 }

    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;

int main() {
  int a, b;
  double degree;
  cin >> a >> b >> degree;
  double rad = M_PI*(degree/180);
  double s = a*b*sin(rad)/2;
  printf("%.5lf\n", s);
  double c = a*a + b*b - 2*a*b*cos(rad);
  c = sqrt(c);
  printf("%.5lf\n", a+b+c);
  printf("%.5lf\n", s*2/a);
  return 0;
}



Measured memory_bytes: 3412
n = int(input())
table = [-1] * (n + 1)
table[0] = 2
table[1] = 1
def lucas(i):
    if table[i] != -1:
        return table[i]
    ret = lucas(i-1) + lucas(i-2)
    table[i] = ret
    return ret
print(lucas(n))

Measured memory_bytes: 3060
n, m = map(int, input().split())
ab = sorted(tuple(map(int, input().split())) for _ in range(m))
s = n + 1
ret = 0
for a, b in ab:
    if s <= a:
        ret += 1
        s = n + 1
    s = min(s, b)
if s != n + 1:
    ret += 1
print(ret)


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

namespace {
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define len(x) (int)((x).size())
#define X first
#define Y second

#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
  
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;

ll expmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
template<typename T> T sqr(const T& x) { return x*x; }
ll flog(const ll x) { return 63 - __builtin_clzll(x); }
template<typename T> void sort(T& t) { sort(all(t)); }
template<typename T> void undupe(vector<T>& v) { sort(v); v.erase(unique(all(v)), v.end()); }

struct _IOS { _IOS() { ios::sync_with_stdio(0); cin.tie(0); } } _IOS;
}

const ll MOD = 1000000009LL;
const ll INF = 1e15;
const double EPS = 1e-8;

bool solve(int k1, int k2, int size) {
  if (k2 == 1) return false;
  
  int atleast = k1 + 1;
  int atmost = k1 + k2 / 2;
  
  if (size < atleast || size > atmost) return false;
  
  return true;
}

int main() {
	int N;
	cin >> N;
	
	vi a(N);
	for (auto& x : a) cin >> x;
	
	map<int,int> cnt;
	for (int x : a) cnt[x]++;
	
	if (cnt.size() > 2) cout << "No" << endl;
	else if (cnt.size() == 1) {
	  int k = cnt.begin()->X;
	  bool works = (k == N - 1 || N/k > 1);
	  cout << (works ? "Yes" : "No") << endl;
	} else {
	  vector<pii> y;
	  for (auto p : cnt) y.push_back(p);
	  sort(y);
	  if (y[1].X - y[0].X != 1) cout << "No" << endl;
	  else {
	    bool works = solve(y[0].Y, y[1].Y, y[1].X);
	    cout << (works ? "Yes" : "No") << endl;
	  }
	}
}

Measured memory_bytes: 5376
N = int(input())
A = [int(i) for i in input().split()]

cnt = 0
cnt2 = 0
for i in range(N):
    if A[i] % 4 == 0:
        cnt += 1
    elif A[i] % 2 == 0:
        cnt2 += 1
    
ans = 'No'
if cnt2 % 2 == 0:
    if cnt >= (N - cnt2) // 2:
        ans = 'Yes'
else:
    if cnt >= (N - cnt2 + 1) // 2:
        ans = 'Yes'
        
print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	long long a, b, x;
	cin >> a >> b >> x;
	cout << (b / x) - ((a + x - 1) / x) + 1 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        new Program().Solve();
    }

    void Solve()
    {
        Scanner cin = new Scanner();
        int N = cin.NextInt();
        long[] A = cin.ArrayLong(N);
        long[] gcd = new long[N+2]; // gcd[i] is gcd with removing i-th number 
        long[] L = new long[N+2];
        long[] R = new long[N+2];

        L[0] = A[0];
        R[N - 1] = A[N-1];

        for (int i = 0; i < N-1; ++i)
        {   
            L[i+1] = CalcGCD(L[i], A[i+1]);
        }
        for (int i = N - 2; 0 <= i; --i)
        {   
            R[i] = CalcGCD(R[i+1], A[i]);
        }

        long ans = Math.Max(L[N - 2], R[1]);
        for (int i = 1; i < N - 1; ++i)
        {
            long tmp = CalcGCD(L[i-1], R[i + 1])/*without i-th*/;

            //long tmp = Math.Max(
            //    CalcGCD(L[i], R[i + 1])/*without i-th*/,
            //    CalcGCD(L[i], R[i])/*with i-th*/);
            ans = ans <= tmp ? tmp : ans;
        }

        Console.WriteLine(ans);
    }

    private long CalcGCD(long a, long b)
    {
        if (b == 0)
        {
            return a;
        }
        if (a == 0)
        {
            return b;
        }
        if (a < b)
        {
            long residual = b % a;
            return CalcGCD(a, residual);
        }
        else
        {
            long residual = a % b;
            return CalcGCD(b, residual);
        }
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string Next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextInt() + add;
        }
        return Array;
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextLong() + add;
        }
        return Array;
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 29916
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    vector<int> v(3);
    REP(i,3) cin >> v[i];
    int sum = accumulate(ALL(v),0);
    int mx = *max_element(ALL(v));
    bool b = sum - mx == mx;
    ATYN(b);

    return 0;
}

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

map<pair<int, int>, int> Map;
int N, X[59], Y[59], maxn;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> X[i] >> Y[i];
	}
	for (int i = 1; i <= N; i++) {
		for (int j = i + 1; j <= N; j++) {
			Map[make_pair(X[j] - X[i], Y[j] - Y[i])]++; maxn = max(maxn, Map[make_pair(X[j] - X[i], Y[j] - Y[i])]);
			Map[make_pair(X[i] - X[j], Y[i] - Y[j])]++; maxn = max(maxn, Map[make_pair(X[i] - X[j], Y[i] - Y[j])]);
		}
	}
	cout << N - maxn << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

void out(int n, int* a);

int main() {
	int n;
	int a[100];
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
	}
	// Selection Sort
	int count = 0;
	for (int i = 0; i < n; i++) {
		int minj = i;
		for (int j = i; j < n; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		if (i != minj) {
			int aa = a[minj];
			a[minj] = a[i];
			a[i] = aa;
			count++;
		}
	}
	out(n, a);
	std::cout << count << std::endl;
	return 0;
}

void out(int n, int* a) {
	std::cout << a[0];
	for (int i = 1; i < n; i++) {
		std::cout << " " << a[i];
	}
	std::cout << std::endl;
}

Measured memory_bytes: 3048
#include<bits/stdc++.h>
using namespace std;
 long long tr[1000001]={0};
 void update(long long up,long long h,int idx,int s,int e){
   if(s>e)
   return;
   //cout<<s<<" "<<e<<" "<<idx<<" "<<h<<"\n";
   if(s==e){
      tr[idx]=up;
     //  cout<<s<<" "<<e<<" "<<idx<<" "<<h<<" leaf\n";
      return;
   }

   int mid=(s+e)/2;
   if(mid >= h){
     update(up,h,2*idx,s,mid);
   }else{
   update(up,h,2*idx+1,mid+1,e);
   }
   tr[idx]=max(tr[2*idx],tr[2*idx+1]);

 }
 long long getMx(int x,int idx,int s,int e){
        if(s>e || x<s){
        return INT_MIN;
        }

        if(e<=x)
        return tr[idx];
        int mid=(s+e)/2;

        long long m1=getMx(x,2*idx,s,mid);
        long long m2=getMx(x,2*idx+1,mid+1,e);
        return max(m1,m2);

 }
int main(){

long long n,m=0;
cin>>n;
long long h[n],a[n];
for(int i=0;i<n;i++)
  {cin>>h[i];
    m=max(m,h[i]);
  }
for(int i=0;i<n;i++)
 cin>>a[i];


 long long ans=0;
 for(int i=0;i<n;i++){

    long long  mx=getMx(h[i]-1,1,0,m);
  //cout<<h[i]-1<<" "<<mx<<" "<<a[i]<<"\n";
    ans=max(ans,mx+a[i]);
    update(mx+a[i],h[i],1,0,m);
 }

cout<<ans<<"\n";

}


Measured memory_bytes: 9472
import sys


N, M = map(int, input().split())
S = [list(map(int, x.split())) for x in sys.stdin.readlines()]

S.sort(key=lambda x: x[0])

amount = 0

for a, b in S:
    num = min(M, b)
    amount += a * num
    M -= num
    if M == 0:
        break

print(amount)


Measured memory_bytes: 35304
#include <iostream>
#include <cmath>
#include <iomanip>

int main()
{
    double a, b, c, C;

    std::cin >> a >> b >> C;

    double S, L, h;

    h = b * sin(M_PI * C / 180);

    S = a * h / 2;

    c = sqrt(pow(a,2) + pow(b,2) - 2*a*b*cos(M_PI * C / 180));

    L = a + b + c;

    std::cout << std::fixed << std::setprecision(5) << S << std::endl;
    std::cout << std::fixed << std::setprecision(5) << L << std::endl;
    std::cout << std::fixed << std::setprecision(5) << h << std::endl;
}


Measured memory_bytes: 3456
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){ cin >> a[i]; }
  ll ans = 1;
  ll q = 1e18;
  sort(a.begin(),a.end());
  if(a[0]==0){ cout << 0 << endl; return 0; }
  rep(i,n){
    if(a[i]>longinf/ans){ ans=-1; break; }
    ans *= a[i];
  }
  if(ans>q){ ans=-1; }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3988
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<queue>

using namespace std;

priority_queue<long long>Q;

void leftpush(int i, int N,long long v[]){//i回左から取ってくる

for(int l=0;l<N && l<i ;l++){

    Q.push(-v[l]);
}
}

void rightpush(int k, int N,long long v[]){//k回右から取ってくる

for(int l=N-1;l>=0 && N-l<=k ;l--){

    Q.push(-v[l]);
}


}
int main(){


int N,K;
cin >> N >> K;
long long v[N];


for(int i=0;i<N;i++){
cin >> v[i];
}
long long value=0;
long long total;
int s;
long long t=1;
int limit=min(N,K);
for(int i=0;i<=limit;i++){




    for(int k=0;k+i<=limit;k++){
        total=0;
        t=1;
        leftpush(i,N,v);
        rightpush(k,N,v);
    
        s=K-i-k;
        
        while(t>0 && s>0 &&!Q.empty()){
            t=Q.top();
            if(t>0){//保持している最小値が負なら捨てる
                Q.pop();
            }
            s--;
        }

        while(!Q.empty()){

            total-=Q.top();
            Q.pop();
        }
        
        value=max(value,total);
    }
}
cout <<value<<endl;
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    if (v.size() > 0) {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main() {
    ll n,m,k;
    cin >> n >> m >> k;
    vll a(n), b(m);
    cin>>a;
    cin >> b;
    FOR(i, 1, n) { a[i] += a[i - 1]; }
    FOR(i, 1, m) { b[i] += b[i - 1]; }
    ll ans = 0;
    REP(i, n + 1) {
        ll now = (i == 0 ? k : k - a[i-1]), tmp = i;
        if (now < 0) continue;
        auto ite = upper_bound(b.begin(), b.end(), now);
        tmp += ite - b.begin();
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int h, w, c[10][10], a[200][200];

int main() {
	cin >> h >> w;
	inc(i, 10) {
	inc(j, 10) {
		cin >> c[i][j];
	}
	}
	inc(i, h) {
	inc(j, w) {
		cin >> a[i][j];
	}
	}
	
	inc(k, 10) {
	inc(i, 10) {
	inc(j, 10) {
		setmin(c[i][j], c[i][k] + c[k][j]);
	}
	}
	}
	LL ans = 0;
	inc(i, h) {
	inc(j, w) {
		if(a[i][j] == -1) { continue; }
		ans += c[a[i][j]][1];
	}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int a[21],b[21],c[20];
    int i;
    for(i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(i=1;i<=n;i++){
        scanf("%d",&b[i]);
    } 
    for(i=1;i<n;i++){
        scanf("%d",&c[i]);
    }
    int sati = 0;
    for(i=1;i<=n;i++){
        sati += b[i];
        if(i!=1 && a[i]-a[i-1]==1){
            sati += c[a[i-1]];
        }
    }
    printf("%d\n",sati);
    return 0;
}

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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    int t = min(a,b);
      int diviser_counter = 0;
      int result = 0;
      for (int i = t; 1<=i; i=i-1) {
        if ((a%i==0)&&(b%i==0)) {
          diviser_counter++;
          result = i;
        }
        if (diviser_counter == k) {
          break;
        }
      }
      cout << result << endl;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
//const int mod = 17; //(int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >> s;

	bool ok=true;
	if(s[0] !='A') ok=false;
	int cct=0;
	rep2(i, 1, sz(s)){
		if(!((s[i] >='a' && s[i]<='z') || s[i]=='C')) ok=false;
		if(s[i]=='C') cct++;
		if(s[i]=='C' && i<2) ok=false;
		if(s[i]=='C' && i>sz(s)-2) ok=false;
	}
	puts(ok&&cct==1? "AC": "WA");
	return 0;
}


Measured memory_bytes: 256
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O25")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << x << "\n")
using ll = uint16_t; using ld = long double; using namespace std;

#ifndef __GNUC__
string text =
R"X(
8
7 3 5 4 2 1 6 8
3 8 2 5 4 6 7 1
)X";
stringstream iss{text};
#endif

class CountOrder
{
	ll N{0};
	vector<ll> p, q;
	void inp( ) {
		iss >> N; p.resize(N); q.resize(N);
		rep(n, N) { iss >> p[n]; }
		rep(n, N) { iss >> q[n]; }
		//for_each(begin(p), end(p), [](auto x) { cout << x << "\n"; });
	}
	void change( ) {
		long long sa{0};
		if (p > q) swap(p, q);
		do {
			if (p == q) break;
			++sa;
		} while (next_permutation(begin(p), end(p)));
		p(sa);
	}
public:
	void procedures( ) {
		inp( );
		change( );
	}
};
//https://atcoder.jp/contests/abc145/tasks/abc145_c
int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	class CountOrder a; a.procedures( );
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
int main()
{
    ll n; 
    cin >> n;
    ll a[n]; 
    for(int i=0;i<n;i++) 
      cin >>a[i];
    for(int i=0;i<n;i++) {
        if (a[i] == 0) {
            cout << 0 << endl;
             return 0;
        }
    }
    ld L = 0;
    for(int i=0;i<n;i++) {
        L += log10(a[i]);
    }
    if (L > 18.1) {
        cout << -1 << endl;
         return 0;
    }
    ll prod = 1; 
    for(int i=0;i<n;i++)
      prod*= a[i];
    if (prod > 1000000000000000000) {
      prod=-1;
       
    }
    cout << prod<<endl;
  
  return 0;
}

	

Measured memory_bytes: 4632
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
#include <iomanip>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  //cout<<fixed<<setprecision(10);
  ll n,m,ans=0;
  cin>>n>>m;
  ll p;
  string s;
  vector<ll>v(n,0);
  ll a=0,b=0;
  for(ll i=0;i<m;i++){
    cin>>p>>s;
    if(s=="AC"&&v[p-1]>=0){
      a++;
      b+=v[p-1];
      v[p-1]=-1;
    }
    else if(v[p-1]>=0)v[p-1]++;
  }
  cout<<a<<" "<<b<<endl;
}


Measured memory_bytes: 1024