akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		ArrayList<String[]> all = new ArrayList<String[]>();

		String line = "";

		int pat = 0;

		while (true) {
			line = sc.nextLine();
			if (line.equals("-")) {
				break;
			}

			String shuffle = sc.nextLine();
			int shuffle_int = Integer.parseInt(shuffle);

			String[] kari = new String[2 + shuffle_int];
			kari[0] = line;
			kari[1] = shuffle;

			for (int j = 0; j < shuffle_int; j++) {
				kari[2 + j] = sc.nextLine();
			}
			all.add(kari);
			pat++;
		}

		for (int i = 0; i < pat; i++) {
			String[] s = all.get(i);
			String str = s[0];
			int repeat = Integer.parseInt(s[1]);
			for (int j = 0; j < repeat; j++) {
				int sh = Integer.parseInt(s[j + 2]);
				String a = str.substring(0, sh);
				String b = str.substring(sh);
				str = b + a;
			}
			System.out.println(str);
		}

	}

}

Measured memory_bytes: 26224
count = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]


n = int(input())

for i in range(n):
    b, f, r, v = map(int,input().split())
    count[b-1][f-1][r-1] += v




for i in range(4):
    for j in range(3):
        for k in range(10):
            print("",end=" ")
            print("%d"%(count[i][j][k]),end="")
        else:
            print()
    else:
        if i < 3:
            print("####################")





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

int main()
{
    long n, k;
    cin>>n>>k;
    vector<int> a(n), b(n);
    for(int i=0; i<n; ++i) cin>>a[i]>>b[i];

    auto f=[&](int p)->long {
        long res=0;
        long x=(k&~(1<<p))|((1<<p)-1);
        if (x>k) return 0;
        if (p==0) x=k;

        for(int i=0; i<n; ++i) {
            if (a[i]<=x && ((a[i]>>p)|(k>>p))<=(k>>p) && (a[i]&(1<<p))==0)
                res+=b[i];
        }
        return res;
    };

    long res=0;
    for(int i=0; i<31; ++i) {
        res=max(res, f(i));
    }
    cout<<res<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
int N;
ll T;
ll t[200000];
int main() {
	cin >> N >> T;
	rep(i, N){ cin >> t[i];}

    ll ret = 0;
	for(int i = 1; i < N; i++){
		ret += min(T, t[i] - t[i-1]);
	}
	ret += T;
	cout << ret << endl;
}

Measured memory_bytes: 1792
from functools import reduce
from operator import add


def test(array: list, index: int, calc: str, result: list):
    # print("index:{}".format(index))
    # print("calc:{}".format(calc))
    # 配列の最後までチェックしたら終了
    if index == len(array) - 1:
        # print("sum:{}".format(result[0] + sum(calc + array[index])))
        result[0] += sum(calc + array[index])
        return
    test(array, index + 1, calc + array[index], result)
    test(array, index + 1, calc + array[index] + "+", result)


def sum(calc: str):
    nums = [int(item) for item in calc.split("+")]
    return reduce(add, nums)


array = list(input())
result = [0]
test(array, 0, "", result)
print(result[0])


Measured memory_bytes: 3572
import itertools
N,M,R = map(int,input().split())
r = list(map(int,input().split()))
INF = float('inf')
d = [[INF for i in range(N)] for i in range(N)]
for i in range(M):
    a,b,c = map(int,input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c
for i in range(N):
    d[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j],d[i][k]+d[k][j])
ans = INF
for l in list(itertools.permutations(r)):
    tmp = 0
    for i in range(R-1):
        tmp += d[l[i]-1][l[i+1]-1]
    ans = min(tmp,ans)
print(ans)


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

int main()
{
	int i,j,k,n,l,m;
	string str1,str2;
	string str3;
	cin>>n;
	cin>>str1>>str2;
	for(i=0,j=0;i<n;i++)
	{
		str3[j++]=str1[i];
		str3[j++]=str2[i];
		
	}
	for(i=0;i<n+n;i++)
	{
		cout<<str3[i];
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

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


Measured memory_bytes: 3084
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const ll N = 2e5 + 5, mod = 1e9 + 7;
int n, u, v, ans, sz[N];
vector<int>adj[N];
ll sub(int a, int b){
    return (((a - b) % mod) + mod) % mod;
}
int add(int a, int b){
    return (a + b) % mod;
}
int mul(int a, int b){
    return (1ll * a * b) % mod;
}
ll fp(ll b, ll p){
    if(!p) return 1;
    ll res = fp(b, p / 2);
    res = mul(res, res);
    if(p & 1) res = mul(res, b);
    return res;
}
void dfs(int node, int parent){
    sz[node] = 1;
    for(auto i : adj[node]){
        if(i != parent)
            dfs(i, node);
    }
    sz[parent] += sz[node];
    ans = add(ans, fp(2, n - 1));
    ans = sub(ans, 1);
    for(auto i: adj[node]){
        int x = 0;
        if(i == parent) x = n - sz[node];
        else x = sz[i];
        ans = sub(ans, sub(fp(2, x), 1));
    }
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1; i < n; i++){
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1, 0);
    ans = mul(ans, fp(fp(2, n), mod - 2));
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 30872
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;

using P = std::pair<int, int>;
using ll = long long;
using ld = double;

using bint = boost::multiprecision::cpp_int;


template<typename T, typename U>
std::istream& operator>>(std::istream& in, std::pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

const int MOD = 1e9 + 7;

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    string s;
    cin>>s;
    if(s[s.size()-1]=='s')cout<<s<<"es"<<endl;
    else cout<<s<<"s"<<endl;
}


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

typedef long long int in;


int main() 
{
	in a,b,c,k;
    cin>>a>>b>>c>>k;

    if(a>=k)
    cout<<k;
    else if(a+b>=k)
    cout<<a;
    else if(a+b+c>=k)
    cout<<a-(k-a-b);

	return 0;
}





Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
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);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string bans(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int a,b,c;cin>>a>>b>>c;
  int ans=(a>=c||b>=c||a+b>=c);
  cout << bans(ans) << endl;
  return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)

int partition(int a[], int p, int r){
    int x = a[r];
    int i = p - 1;
    REP(j,p,r){
        if(a[j] <= x){
            i++;
            swap(a[i], a[j]);
        }
    }
    swap(a[i+1], a[r]);
    return i+1;
}
int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n)cin >> a[i];
    int q = partition(a, 0, n-1);
    rep(i,n){
        if(i != q)cout << a[i];
        else printf("[%d]", a[i]);

        if(i < n-1)printf(" ");
        else printf("\n");
    }    
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int A,B;
  cin>>A>>B;
  int ans=max(A*2-1,B*2-1);
  cout<<max(ans,A+B)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	int a,b,c ;
	cin >> a >> b >> c ;
	cout << yorn((a<=c&&c<=b)||(a>=c&&c>=b)) << endl ;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime> 
#define full(a) a.begin(), a.end()

#define sz(x) ((int)(x).size())
#define lli long long int
using namespace std;

int inp() {
    int n; cin >> n;
    return n;
}

void prntv(vector<int> vec) {
    for (auto i : vec)cout << i << " ";
    cout << endl;
}
void solve() {
    int n = inp();
    vector<int> st;
    for (int i = 0; i < n; i++) {
        int a = inp();
        st.push_back(a);
    }
    sort(st.begin(), st.end());
    int count = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (st[i] == st[j] || st[i] == st[k] || st[j] == st[k])continue;
                if (st[i] + st[j] > st[k])count++;
                else break;
            }
        }
    }
    cout << count << endl;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    //int n; cin >> n;
    //while(n--)
        solve();

    return 0;
}

Measured memory_bytes: 3656
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include <random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ");
//#define double long double



template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }

int pa[100010], so[100010];
int num[100010];
int N, M;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> M;
	REP(i, N) {
		int x; cin >> x;
		num[x]++;
	}
	FOR(i, 1, 100001) {
		int cnt_pair = num[i] / 2;
		pa[i % M] += cnt_pair;
		so[i % M] += (num[i] & 1);
	}
	ll ans = 0;
	ans += so[0] / 2;
	ans += pa[0];
	//pe(0); print(ans);
	FOR(i, 1,M) {
		if (i == M - i) {
			ans += so[i] / 2;
			so[i] = (so[i] & 1);
			//pe(i)print(ans);
			continue;
		}
		int sol = min(so[i], so[(M - i)]);
		ans += sol;
		so[i] -= sol;
		so[M - i] -= sol;
		while(so[i]>0) {
			if (so[M - i] > 0) {
				ans++;
				so[M - i]--;
				so[i]--;
			}
			else if (pa[M - i] > 0) {
				ans++;
				pa[M - i]--;
				so[M - i]++;
				so[i]--;
			}
			else break;
		}
		//pe(i)print(ans);
	}
	FOR(i, 1, M) {
		ans += pa[i];
		//pe(i)print(ans);
	}
	print(ans);
}


Measured memory_bytes: 2560
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

process.stdin.on('end', () => {
  const points = [0, 0];
  const result = content
    .trim()
    .split('\n')
    .slice(1)
    .map(line => line.split(' '))
    .reduce((prev, cur) => calc(prev, cur), points);
  console.log(result.join(' '));
});

const calc = ([pointA, pointB], [wordA, wordB]) => {
  if (wordA > wordB) {
    return [pointA + 3, pointB];
  } else if (wordA < wordB) {
    return [pointA, pointB + 3];
  } else {
    return [pointA + 1, pointB + 1];
  }
};


Measured memory_bytes: 19396
def resolve():
    n,k = map(int,input().split())
    per=0
    for i in range(1,n+1):
        cnt = 1
        t = i
        while t<k:
            t = t*2
            cnt = cnt*2
        per = per + 1/n/cnt
    print(per)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 39152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define sc(x) scanf("%d", &x)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ALL(x) x.begin(), x.end()
#define SZ(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define ABS(x) ((x)>=0?(x):(-(x)))
#define fastio ios::sync_with_stdio(0),cin.tie(0)
template<class T>T gcd(T a, T b){return b?gcd(b, a%b):a;}

int main()
{
    int n; sc(n);
    if(!n){
        putchar('0');
        return 0;
    }
    string ans;
    while(n){
        char c;
        if(n%(-2) != 0)c = '1';
        else c = '0';
        ans = c+ans;
        if(n > 0)n /= -2;
        else n = (n-1)/-2;
    }
    cout << ans << endl;
    return 0;
}




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

const ll MOD = 1000000007;
const ll INF = 9999999999;


int main() {
  int n; cin >>n;
  int brick = 0;
  int check = 1;
  for (int i=0; i<n; i++){
    int buf; cin >>buf;
    if (buf == check){
      check++; brick++;
    }
  }
  int ans = -1;

  if (brick != 0){
    ans = n - brick;
  }
  cout <<ans <<endl;

}

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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int a;
  string str;
  cin >> a >> str;

  if(a < 3200) cout << "red" << endl;
  else cout << str << endl;
}


/*





















*/


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    int l = 0;
    int r = 0;
    while(l < n && r < n){
        if(s[l] == s[r]) r++;
        else{
            ans++;
            l = r;
        }
    }
    cout << ans+1;
}
int main(){
    speed;
    int t = 1;
    //cin >> t;
    while(t--) solve();
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>

using namespace std;

int main(){
    char c[101];
    int rez=0, l=0;
    cin>>c;
    l=strlen(c);
    for(int i=0; i<l/2; ++i){
        if(c[i]!=c[l-1-i]) rez++;
    }
    cout<<rez;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef  long long int ll;
typedef long double ld;
#define pb  push_back
#define vll vector<ll>
#define mll map<ll,ll>
const double PI = 2*acos(0.0);
#define gcd(a,b)   __gcd((a),(b))
#define lcm(a,b)   ((a)/(__gcd((a),(b)))*(b))
#define INF         LLONG_MAX
#define ln  INT_MAX
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
using namespace std;
int main(){

    ll n;
    cin>>n;
    if(n==1){cout<<0;}
    else  if(n==0){cout<<1;}
    return 0;}


Measured memory_bytes: 3636
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 305;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
double dp[maxn][maxn][maxn];
int sum[4];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,x;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        sum[x]++;
    }
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n-i;j++)
        {
            for(int k=0;k<=n-i-j;k++)
            {
                if(i==0&&j==0&&k==0) continue;
                if(i>0) dp[i][j][k]+=dp[i-1][j+1][k]*i/(1.0*(i+j+k));
                if(j>0) dp[i][j][k]+=dp[i][j-1][k+1]*j/(1.0*(i+j+k));
                if(k>0) dp[i][j][k]+=dp[i][j][k-1]*k/(1.0*(i+j+k));
                dp[i][j][k]+=1.0*n/(i+j+k);
            }
        }
    }
    printf("%.10f\n",dp[sum[3]][sum[2]][sum[1]]);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 219392
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,add,s,m,ara[3];
    cin>>a>>b;
    add=a+b;
    s=a-b;
    m=a*b;
    ara[0]=add;ara[1]=s;ara[2]=m;
    sort(ara,ara+3);
    cout<<ara[2]<<endl;
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
a = [0 for _ in range(M)]
b = [0 for _ in range(M)]
for i in range(M):
    a[i], b[i] = map(int, input().split())

for j in range(N):
    print(a.count(j + 1) + b.count(j + 1))


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll X, Y;
	cin >> X >> Y;
	for(ll n = 1; ; n++) {
		if(powl(2, n - 1) * X > Y) {
			cout << n - 1 << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }


int main()
{
    int x,t;
    cin>>x>>t;
    cout<<max(x-t,0)<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n, m;
    // cin >> n >> m;
    scanf("%d %d", &n, &m);
    vector<int> ss(n); //cin >> ss;
    for(int i = 0; i < n; i++){
        scanf("%d", &ss[i]);
    }
    vector<int> ts(m); //cin >> ts;
    for(int i = 0; i < m; i++){
        scanf("%d", &ts[i]);
    }
    vector<int> dp[2] = {vector<int>(m + 1, 1), vector<int>(m + 1)};
    // vector<vector<int>> dp(2, vector<int>(m + 1, 1));
    for(int i = 0; i < n; i++){
        int i1 = i & 1, i2 = !i1;
        dp[i2][0] = 1;
        int* num = &dp[i2][0];
        int* num2 = &dp[i1][0];
        for(int j = 0; j < m; j++){
            num++;
            num2++;
            if(ss[i] == ts[j]){
                *num = *(num - 1) + *num2;
                if(*num >= M){
                    *num -= M;
                }
            }else{
                *num = *(num - 1) + *num2 - *(num2 - 1);
                if(*num >= M){
                    *num -= M;
                }else if(*num < 0){
                    *num += M;
                }
            }
        }
        if(i == n - 1){
            cout << *num << '\n';
        }
    }
    // printde(dp);
    // cout << dp[n & 1][m] << '\n';
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int X = sc.nextInt() - 1;
    int Y = sc.nextInt() - 1;
    Map<Integer, Node> map = new HashMap<>();
    for (int i = 0; i < N; i++) {
      map.put(i, new Node(i));
    }
    for (int i = 1; i < N; i++) {
      Node n1 = map.get(i - 1);
      Node n2 = map.get(i);
      n1.adj.add(n2);
      n2.adj.add(n1);
    }
    {
      Node x1 = map.get(X);
      Node y1 = map.get(Y);
      x1.adj.add(y1);
      y1.adj.add(x1);
    }
    int[] ans = new int[N]; // ans for length [0...N-1]
    for (int i = 0; i < N; i++) {
      boolean[] isVisited = new boolean[N];
      Queue<NodeDist> q = new LinkedList<>();
      q.add(new NodeDist(map.get(i), 0));
      while (!q.isEmpty()) {
        NodeDist d = q.poll();
        if (isVisited[d.node.val]) continue;
        isVisited[d.node.val] = true;
        ans[d.dist]++;
        for (Node next : d.node.adj) {
          q.add(new NodeDist(next, d.dist + 1));
        }
      }
    }
    for (int i = 1; i < N; i++) {
      System.out.println(ans[i] / 2);
    }
  }

  static class NodeDist {
    Node node;
    int dist;

    NodeDist(Node n, int d) {
      node = n;
      dist = d;
    }
  }

  static class Node {
    List<Node> adj = new LinkedList<>();
    Integer val;

    Node(Integer i) {
      val = i;
    }
  }
}


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

ll n,a,b;
int main() {
    cin >> n >> a >> b;
    if(a >b || n == 1 && a != b){
        printf("0\n");
    }
    else if(n == 1 && a == b){
        pout(1);
    }
    else{
        printf("%lld\n",(b*(n-1)+a)-(a*(n-1)+b)+1);
    }
    return 0;
}

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

bool isPrime(int n) 
{ 

	if (n <= 1) return false; 
	if (n <= 3) return true; 

	if (n%2 == 0 || n%3 == 0) return false; 
	
	for (int i=5; i*i<=n; i=i+6) 
		if (n%i == 0 || n%(i+2) == 0) 
		return false; 
	
	return true; 
} 

int nextPrime(int N) 
{ 

	// Base case 
	if (N <= 1) 
		return 2; 

	int prime = N; 
	bool found = false; 


	while (!found) { 
		prime++; 

		if (isPrime(prime)) 
			found = true; 
	} 

	return prime; 
} 

int main() 
{ 
	int N; 
  cin>>N;
   
   if(isPrime(N))
   	cout<<N<<'\n';

   else
	cout << nextPrime(N); 

	return 0; 
} 


Measured memory_bytes: 3612
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        LinkedList<Integer> a = new LinkedList<>();

        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }

        LinkedList<Integer> ans = new LinkedList<>();

        for (int i = 0; i < n; i++) {
            debug(i);
            for (int j = n - i; j > 0; j--) if (a.get(j - 1) == j) {
                ans.addFirst(a.remove(j - 1));
                break;
            }
        }
        if (a.size() == 0) {
            for (int x: ans) {
                System.out.println(x);
            }
        } else {
          System.out.println(-1);
        }
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define debug(x) cerr<<#x<<": "<<x<<endl;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)


int main() {
	int N,K;
  	cin>>N>>K;
  	int a[N];
  	rep(i,N) a[i]=0;
  
  	rep(i,K){
     	int d;
      	cin>>d;
      	rep(j,d){
         	int b;
          	cin>>b;
          	a[b-1]++;
        }
    }
  	int count=0;
  	
  	rep(i,N){
     	if(a[i]==0) count++; 
    }
  	
  	cout<<count<<endl;
  
}

Measured memory_bytes: 3588
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

Graph g;
// d[i] := 頂点 i に移動するとき, それ以降に移動する回数の期待値
vector<double> d;
void dfs(int u, int p) {
    double sum = 0;
    int cnt = 0;
    for (int v: g[u]) if (v != p) {
        dfs(v, u);
        sum += d[v] + 1;
        cnt++;
    }
    d[u] = (cnt ? sum / cnt : 0);
}
vector<double> res;
void dfs2(int u, int p, double d_par) {
    double total = 0;
    for (int v: g[u]) total += (v == p ? d_par : d[v]) + 1;
    res[u] = total / g[u].size();
    for (int v: g[u]) if (v != p) {
        double nd_par = (total - (d[v] + 1)) / max(1, (int)g[u].size() - 1);
        dfs2(v, u, nd_par);
    }
}

#include <iomanip>
int main() {
    cout << fixed << setprecision(12);
    int n; cin >> n;
    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v; u--, v--;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    d.resize(n);
    dfs(0, -1);
    res.resize(n);
    dfs2(0, -1, 0);
    for (auto e: res) cout << e << endl;
    return 0;
}

Measured memory_bytes: 18816
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define MOD 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define all(c) (c).begin(),(c).end()
#define ss second
#define MAXX 9000000000000000000
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> > 
#define vvpi vector<vector<pair<int,int> > >
#define Inp(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define Out(a,n,ch) for(int i=0;i<n;i++)cout<<a[i]<<ch;cout<<endl;

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	
	string s;
	cin>>s;
	int n=s.size(),sum=0;
	for(int i=0;i<n;i++)
	{
		sum = (sum+(s[i]-'0'))%9;
	}
	if(sum%9==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N; string s, t; cin >> N >> s >> t;
    for (int i = 0; i < N; i++) {
        string a = s.substr(i, N - i), b = t.substr(0, N - i);
        if (a == b) {
            cout << 2 * i + (N - i) << endl;
            return 0;
        }
    }
    cout << 2 * N << endl;
    return 0;
}


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

#define ll long long
#define f first
#define s second
#define pb push_back

using namespace std;

vector <int> g[(int)2e5];

ll dfs(int v, ll cnt) {
    if (!g[v].size())
        return cnt;
    vector <ll> a;
    for (auto i:g[v]) {
        a.pb(dfs(i, cnt));
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    for (int i = 0; i < a.size(); ++i) {
        a[i] += a.size() - i;
        ans = max(ans, a[i]);
    }
    //cerr << v << ' ' << a[a.size() - 1] << endl;
    return ans;
}

int main() {
    int n;
    cin >> n;
    for (int i = 2,x; i <= n; ++i) {
        scanf("%d", &x);
        g[x].pb(i);
    }
    cout << dfs(1, 0) << endl;
    return 0;
}

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

int main() {
	int a, b, d, r;
	double f;
	cin >> a >> b;
	d = a / b;
	r = a%b;
	f = (double)a / (double)b;
	cout << fixed;
	cout << setprecision(6) << d << " " << r << " " << f << endl;
}


Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define Endl endl
#define int long long
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
bool cmps(pair<int,int>p1,pair<int,int>p2) {
    return p1.ss<p2.ss;
}
int lcm(int a, int b){
    return (a*b)/gcd(a, b);
}

int32_t main() {
    int x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    int cur = x % d;
    int left = x / d;
    if(left > k) {
        cur = x - k*d;
    }
    else if((k-left)%2 == 1)cur = abs(cur-d);
    cout << cur;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<vector<int> > v(n,vector<int>(3));
	for(int i=0;i<n-1;i++)
	cin>>v[i][0]>>v[i][1]>>v[i][2];
	int t;
	for(int i=0;i<n-1;i++){
		t=v[i][1];
		for(int j=i;j<n-2;j++){
			t+=v[j][0];
			t=max(t,v[j+1][1]);
			if(t%v[j+1][2]!=0)
			t+=v[j+1][2]-t%v[j+1][2];
		}
		t+=v[n-2][0];
		cout<<t<<endl;
	}
	cout<<0;
}

Measured memory_bytes: 3624
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type Node struct {
	id, to int
}

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, M := sc.nextInt(), sc.nextInt()
	G := make([][]Node, N)
	for i := 0; i < M; i++ {
		from := sc.nextInt() - 1
		to := sc.nextInt() - 1
		G[from] = append(G[from], Node{i, to})
		G[to] = append(G[to], Node{i, from})
	}
	var dfs func(id, start, to int, done []bool) bool
	dfs = func(id, start, to int, done []bool) bool {
		res := false
		done[to] = true
		for _, node := range G[to] {
			if id != node.id && !done[node.to] {
				if node.to == start {
					done[to] = true
					return true
				} else {
					res = res || dfs(id, start, node.to, done)
				}
			}
		}
		return res
	}
	ans := 0
	ids := make([]bool, M)
	for from, nodes := range G {
		for _, node := range nodes {
			if !ids[node.id] {
				if !dfs(node.id, from, node.to, make([]bool, N)) {
					ans++
				}
				ids[node.id] = true
			}
		}
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


Measured memory_bytes: 640
#include <cstdio>
#include <math.h>

using namespace std;

int main(){
  int n, x;
  scanf("%d", &n);
  for(int i=1; i<n+1; i++) {
    if(i % 3 == 0) {
      printf(" %d", i);
      continue;
    }
    x = i;
    while(x != 0) {
      if(x%10 == 3) {
        printf(" %d", i);
        break;
      }
      x /= 10;
    }
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2748
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    String ans = "No";
    
    if (N % 2 == 0) {
      String s1 = S.substring(0, N/2);
      String s2 = S.substring(N/2, N);
      if (s1.equals(s2))
        ans = "Yes";
    }
    
    System.out.print(ans);
  }
}

Measured memory_bytes: 21716
N = int(input())
W = list(map(int, input().split()))

minw = sum(W)

for t in range(N):
    s1 = sum(W[:t])
    s2 = sum(W[t:])
    diff = abs(s1 - s2)
    minw = min(minw, diff)

print(minw)


Measured memory_bytes: 2940
//#include<iostream>
//using namespace std;
//int main(){
//	int a[7], b[7];
//	for (int i = 0; i < 7; i++)
//		cin >> a[i] >> b[i];
//	for (int i = 0; i < 7; i++)
//		cout << a[i] - b[i] << endl;
//}

//#include<iostream>
//using namespace std;
//int main(){
//	int a, b, c;
//	cin >> a >> b >> c;
//
//	if (a==1&&b==1&&c==0||a==0&&b==0&&c==1)
//		cout << "Open" << endl;
//
//	else
//		cout << "Close" << endl;
//}

//#include<iostream>
//using namespace std;
//int main(){
//	int day;
//	cin >> day;
//	switch (day % 7)
//	{
//	case 0:
//		cout << "thu" << endl;
//		break;
//	case 1:
//		cout << "fri" << endl;
//		break;
//	case 2:
//		cout << "sat" << endl;
//		break;
//	case 3:
//		cout << "sun" << endl;
//		break;
//	case 4:
//		cout << "mon" << endl;
//		break;
//	case 5:
//		cout << "tue" << endl;
//		break;
//	case 6:
//		cout << "wed" << endl;
//		break;
//	}
//}

#include<iostream>
using namespace std;
int main(){
	int n, a[10000];
	bool flag = false;
	int count = 0;

	while (1){
		cin >> n;
		if (n == 0)
			break;

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

			if (a[i] >= 2)
				flag = true;

			else if (a[i] == 0)
				count++;
		}

		if (flag){
			cout << n + 1 - count<< endl;
			flag = false;
		}

		else
			cout << "NA" << endl;

		count = 0;
	}

}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

int mindiff(int H,int W){
  if(W % 3 == 0) return 0;
  int w = W / 3;
  int h = H / 2;
  switch(W % 3){
    case 1:
      switch(H % 2){
        case 0:
          return h;
          break;
        case 1:
          return min(2*h + 1, min(max(w + h + 1, 2*w + 1), max(2*w, 2*h+w+1)));
          break;
      }
      break;
    case 2:
      switch(H % 2){
        case 0:
          return h;
          break;
        case 1:
          return min(H, min(min(max(w + 2*h + 2, 2*w + 2), max(w + h + 1, 2*w + 1)), max(w + 4*h + 2, 2*w)));
          break;
      }
      break;
  }
}

int main(){
  int H, W;
  cin >> H >> W;
  cout << min(mindiff(H,W), mindiff(W,H)) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
	int i, j, k;
	int a, b;

	cin >> a >> b;

	if ((a*b) % 2 == 0) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}







	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for(long i=0; i<(n); i++)

long long chmax(long long a, long long b){
  if(a<b){a=b;}
  return a;
}

int main(){
  long long n,m,k,ans=0;
  std::cin >> n >> m >> k;
  long long a[n],b[m],A[n+1],B[m+1],best=m;
  A[0]=0;B[0]=0;
  rep(i,n){
    std::cin >> a[i];
    A[i+1] = A[i] + a[i];
  }
  rep(i,m){
    std::cin >> b[i];
    B[i+1] = B[i] + b[i];
  }
  
  rep(i,n+1){
    if(A[i] > k){break;}
    for(long j=best; j>=0; j--){
      if(A[i]+B[j] <= k){
        best = j;
        ans = chmax(i+j,ans);
        break;
      }
    }
  }
  
  std::cout << ans << std::endl;
  
  return 0;
}


Measured memory_bytes: 9880
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
int main()
{
    int N, tmp;
    cin >> N;
    vector<int> res(N+1);
        for(int x = 1; x <= sqrt(N); ++x)
        {
            for(int y = 1; y <= sqrt(N); ++y)
            {
                for(int z = 1; z <= sqrt(N); ++z)
                {
                    tmp = x*x + y*y + z*z + x*y + y*z + z*x;
                    if(tmp <= N)
                    res[tmp]++;
                }
            }
        }
    for(int i = 1; i <= N; ++i)
    {
        cout << res[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 3460
#include<iostream>
#include <iterator>
#include <vector>
#include <climits>
#include <queue>
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; }
using namespace std;
typedef long long ll;
const ll INF = 1ll << 60;
ll dp[100001];
int h[100001];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    for(int i = 0; i < 100001; i++) dp[i] = INF;
    int N;
    cin >> N;
    for(int i = 0; i < N; i++) cin >> h[i];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    for(int i = 2; i < N; i++){
        chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
        chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
    }

    cout << dp[N - 1] << endl;
    return 0;
}

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

int main() {
	ll nn,kk;
	ll tmp,res;
	
	cin >> nn >> kk ;
	vector<ll> pp(nn);
	rep(i,nn) cin >> pp[i];
	
	tmp = 0;
	rep(i,kk) tmp += pp[i];
	
	res = tmp;
	for(int i=kk;i<nn;i++){
		tmp = pp[i]+tmp-pp[i-kk];
		res = max(tmp ,res);
	}
	//cout << (double)(res + kk)/2.0 << endl; 
	printf("%.10f\n",(double)(res + kk)/2.0);
	
	return 0;
}

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

public class AtCoder
{
  public static void Main()
  {
    var nk = Console.ReadLine().Trim().Split().ToArray();
    var n = int.Parse(nk[0]);
    var k = long.Parse(nk[1]);

    var a = Console.ReadLine().Trim().Split().Select(e => int.Parse(e)).ToArray();

    var s = new List<long>();
    var ord = Enumerable.Repeat(-1, n+1).ToArray();
    int c = 1;
    int l = 0;
    {
      int v = 1;
      while (ord[v] == -1) {
        ord[v] = s.Count();
        s.Add(v);
        v = a[v-1];
      }
      c = s.Count() - ord[v];
      l = ord[v];
    }

    if (k < l) {
      Console.WriteLine(s[(int)k]);
    }
    else
    {
      k -= l;
      k %= c;
      Console.WriteLine(s[l+(int)k]);
    }
  }
}

Measured memory_bytes: 47372
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;


int main(){
  int a;
  cin >> a;
  if(a<=999){cout << "ABC" << endl;}else{cout << "ABD" << endl;}
}

Measured memory_bytes: 3552
n,m = map(int,input().split())
L = []
R = []
for i in range(m):
	l,r = map(int,input().split())
	L.append(l)
	R.append(r)

l = L[0]
r = R[0]
cnt = 0
for i in range(max(L),min(R)+1) :
	if 0<=i<=r :
		cnt += 1
print(cnt)

Measured memory_bytes: 11136
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){

    int n;
    cin >> n;
    int k;
    cin >> k;
    vector<int> a(n);
    int out = 0;

    while(n >= k){
        ++out;
        --n;
    }

    cout << out << endl;

    return 0;
}

Measured memory_bytes: 256
H, W, K = list(map(int, input().split()))

S=[1, 1]
for i in range(W-1):
    S.append(S[-1]+S[-2])

dp = [0]*W
dp[0] = 1
for h in range(H):
    dp_new=[0]*W
    for w in range(W):
        dp_new[w] = S[w]*S[W-1-w]*dp[w]
	
    for w in range(W-1):
        dp_new[w  ] += S[w]*S[W-2-w]*dp[w+1]
        dp_new[w+1] += S[w]*S[W-2-w]*dp[w  ]

    dp = [d%1000000007 for d in dp_new]

print(dp[K-1])

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

typedef long long LL;
typedef unsigned long long ULL;

#define debug printf("fuck %d\n", __LINE__);

inline LL read() {
	LL res = 0, bo = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') bo = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		res = (res << 1) + (res << 3) + ch - '0';
		ch = getchar();
	}
	return bo * res;
}

template <typename T>
void read(T &x) {
	x = read();
}

template <typename T, typename... Argv>
void read(T &a, Argv &... argv) {
	read(a);
	read(argv...);
}

typedef long long LL;
const int N = 41;

int n, A[N][N];
LL f[N][N][N], g[N][N][N], Ans;

int main() {
	n = read() << 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			scanf("%1d", &A[i][j]);
	for (int i = 1; i < n; ++i) {
		f[i][i][i] = 1;
		for (int j = i + 1; j < n; ++j) g[i][i][j] = A[j][i];
	}
	for (int z = 3; z < n; z += 2)
		for (int i = 1; i <= n - z; ++i) {
			int j = i + z - 1;
			for (int p = i; p < j; p += 2)
				for (int q = j; q > p; q -= 2) {
					LL sum = 0;
					for (int k = q; k <= j; ++k) sum += g[i][p][k] * f[q][j][k];
					for (int k = p + 1; k < q; ++k) f[i][j][k] += sum * f[p + 1][q - 1][k];
				}
			for (int w = i; w <= j; ++w)
				for (int k = j + 1; k < n; ++k)
					g[i][j][k] += f[i][j][w] * A[k][w];
		}
	for (int i = 1; i < n; ++i) if (A[n][i]) Ans += f[1][n - 1][i];
	printf("%lld\n", Ans);
	return 0;
}


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

int main(){
    string str;
    cin >> str;
    for(int i = 0; i < str.size(); i++){
        if(i == 3){
            cout << "8";
        } else {
            cout << str[i];
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    A = inputs[0]
    B = inputs[1]
    if A == B:
        return 'EQUAL'
    if A > B:
        return 'GREATER'
    return 'LESS'


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(int_inputs(2))
    print(ret)


Measured memory_bytes: 38384