akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	int w;
	cin >> w;
	vector<int> a(w);
	REP(i, w)cin >> a[i];

	int now = 0;
	vector<int> cap(w);
	REP(i, w) {
		now--;
		if (a[i] == 0)now = INF;
		else if (a[i] < 0) {
			now = min(now, -a[i]);
		}
		cap[i] = now;
	}

	now = 0;
	for (int i = w - 1; i >= 0; i--) {
		now--;
		if (a[i] == 0)now = INF;
		else if (a[i] < 0) {
			now = min(now, -a[i]);
		}
		cap[i] = max(cap[i], now);
	}
	REP(i, w)cap[i] = max(cap[i], 0);

	ll res = 0;
	REP(i, w)if (a[i] > 0) {
		res += min(a[i], cap[i]);
	}
	cout << res << endl;

	return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
typedef long long ll;
using namespace std;
 
int main(){
    int N; cin >> N;
    string S; cin >> S;
    int ans=0;
    
    for (int i=0; i<S.size(); i++){
        while(1){
            if (S[i]==S[i+1]) i++;
            else {
                ans++;
                break;
            }
        }
    }
    cout << ans;
    
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
  while (true) {
    int n;

    cin >> n;
    if (n == 0)
      break;

    vector<pair<char,char>> vec;
    for (int i = 0; i < n; ++i) {
      char a, b;
      cin >> a >> b;
      vec.push_back(make_pair(a, b));
    }

    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
      char c;
      cin >> c;
      for (auto itr = vec.begin(); itr != vec.end(); ++itr) {
        if (itr->first != c)
          continue;
        c = itr->second;
        break;
      }
      cout << c;
    }
    cout << endl;
  }
}


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

int main() {
	char c;
    cin >> c;
  	string s = "abcdefghijklmnopqrstuvwxyz";
  	for(int i = 0; i < 26; i++){
      if(c == s.at(i)){
        cout << s.at(i+1) << endl;
        break;
      }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep_start(a,i,n) for(ll i=a;i<=n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define rev1(i,n) for(ll i=n;i>0;i--)
#define sz(a) int((a).size())
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i+=c.begin; i!=c.end(); i++)
#define present(c,x) (c.find(x)!=c.end())
#define cpresent(c,x) (find(all(c),x)!=c.end())
#define pb push_back
#define F first
#define S second
#define INF INT_MAX
#define mod 1000000007
#define print1(a) cout<<a<<"\n";
#define print2(a,b) cout<<a<<" "<<b<<"\n";
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define mt make_tuple
#define eb emplace_back

typedef unsigned long long int ll;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef tuple<int,int,int> State;

void solve(){
    int n,m,a,b,c=0;cin>>n>>m;
    vi val(n+1);
    rep1(i,n) cin>>val[i];
    vi G[n+1];
    rep(i,m){
        cin>>a>>b;
        G[a].pb(b);
        G[b].pb(a);
    }
    rep1(i,n){
        int tmp=val[i];
        bool check=1;
        for(auto x:G[i]) if(val[x]>=tmp) check=0;
        if(check) c++;
    }
    cout<<c;
}

signed main() {
    // your code goes here
    IOS
    ll t=1;
    //cin>>t;
    rep1(i,t){
        solve(); 
    }
    return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

struct WeightedEdge {
  const int from, to;
  const int64 weight;
  WeightedEdge(int from, int to, int64 weight) : from(from), to(to), weight(weight) {}
};

constexpr int MAX_COIN = 2500;

tuple<vector<int64>, vector<int>>
ShortestPath(vector<vector<WeightedEdge>>& graph, int s) {
  int n = graph.size();
  vector<int64> distances(n, INT64_MAX);
  vector<int> parents(n, -1);
  struct State {
    int v, parent;
    int64 weight;
  };
  auto compare_state = [](State s1, State s2) {
    return s1.weight > s2.weight;
  };
  priority_queue<State, vector<State>, decltype(compare_state)>
      pq(compare_state);

  pq.push(State({s, -1, 0}));
  vector<int> visited(n);
  while(!pq.empty()) {
    State s = pq.top();
    pq.pop();
    if (visited[s.v]) continue;
    visited[s.v] = true;
    distances[s.v] = s.weight;
    parents[s.v] = s.parent;
    for (const auto& e : graph[s.v]) {
      if (visited[e.to]) continue;
      State next = State({e.to, s.v, s.weight + e.weight});
      pq.push(next);
    }
  }
  return make_tuple(distances, parents);
}

template<class T> inline bool UpdateMin(T& a, T b) {
  if (a > b) { a = b; return 1; } return 0;
}

template<class T> inline bool UpdateMax(T& a, T b) {
  if (a < b) { a = b; return 1; } return 0;
}

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

  int n, m;
  int s;
  cin >> n >> m >> s;
  s = min(s, MAX_COIN);

  vector<tuple<int, int, int, int64>> edges;
  for (int i = 0; i < m; i++) {
    int v1, v2, c;
    int64 t;
    cin >> v1 >> v2 >> c >> t;
    v1--;
    v2--;
    edges.push_back({v1, v2, c, t});
  }

  vector<tuple<int, int64>> cities;
  for (int i = 0; i < n; i++) {
    int c;
    int64 t;
    cin >> c >> t;
    cities.push_back({c, t});
  }

  auto encode_fn = [&](int v, int c) {
    return v * (MAX_COIN + 1) + c;
  };

  vector<vector<WeightedEdge>> graph(n * (MAX_COIN + 1));
  for (const auto& edge : edges) {
    auto [v1, v2, c, t] = edge;
    for (int k = 0; k <= MAX_COIN; k++) {
      if (k >= c) {
        graph[encode_fn(v1, k)].push_back({encode_fn(v1, k), encode_fn(v2, k - c), t});
        graph[encode_fn(v2, k)].push_back({encode_fn(v2, k), encode_fn(v1, k - c), t});
      }
    }
  }
  for (int v = 0; v < n; v++) {
    auto [c, t] = cities[v];
    for (int k = 0; k < MAX_COIN; k++) {
      graph[encode_fn(v, k)].push_back({encode_fn(v, k), encode_fn(v, min(k + c, MAX_COIN)), t});
    }
  }

  vector<int64> distances;
  tie(distances, ignore) = ShortestPath(graph, encode_fn(0, s));
  for (int v = 1; v < n; v++) {
    int64 cost = INT64_MAX;
    for (int c = 0; c <= MAX_COIN; c++) {
      UpdateMin(cost, distances[encode_fn(v, c)]);
    }
    cout << cost << endl;
  }
}



Measured memory_bytes: 26868
#include <stdio.h>
#include <vector>
#include <string>
#include <iostream>
#include <tuple>

std::string trim(const std::string& str)
{
    size_t first = str.find_first_not_of(' ');
    if (std::string::npos == first)
    {
        return str;
    }
    size_t last = str.find_last_not_of(' ');
    return str.substr(first, (last - first + 1));
}

using CheckList = std::vector<std::tuple<std::string, bool>>;
void find(CheckList& checkList, const std::string& card){
    for(auto &each: checkList){
        if(std::get<0>(each) == card) {
            std::get<1>(each) = true;
            return;
        }
    }
}

int main(int argc, char* argv[]){
    std::vector<std::tuple<std::string, bool>> checkList;
    for (auto type: { "S", "H", "C", "D" }){
        for(int num = 1; num <= 13; ++num){
        // for(int num = 1; num <= 3; ++num){
            checkList.push_back(std::make_tuple(
                std::string(type) + " " + std::to_string(num),
                false
            ));
        }
    }
    std::string numString;
    std::getline(std::cin, numString);
    int n = std::atoi(trim(numString).c_str());

    for (int i = 0; i < n; i++) {
        std::string buffer;
        std::getline(std::cin, buffer);
        find(checkList, trim(buffer));
    }

    for(auto each: checkList){
        if(!std::get<1>(each)){
            printf("%s\n", std::get<0>(each).c_str());
        }
    }
}


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

int main()
{
  int A, B;
  cin >> A >> B;

  if(B%A==0) cout << A+B << endl;
  else cout << B-A << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  int a[12][12];
  rep(i,n) {
    cin >> c[i];
    rep(j,m) cin >> a[i][j];
  }

  int ans = INF;
  rep(s,1<<n) {
    int cost = 0;
    vector<int> d(m);
    rep(i,n) {
      if (s >> i & 1) {
        cost += c[i];
        rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(i,m) if (d[i] < x) ok = false;
    if (ok) ans = min(ans, cost);
  }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(){
	int r,c,a[101][101],b[101]={0},d=0,all=0;
	cin>>r>>c;
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cin>>a[i][j];
			all+=a[i][j];
		}
	}
	for(int i=0;i<c;i++){
		for(int j=0;j<r;j++){
			b[i]+=a[j][i];
		}
	}
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cout<<a[i][j]<<" ";
			d+=a[i][j];
		}
		cout<<d<<endl;
		d=0;
	}
	for(int i=0;i<c;i++){
		cout<<b[i]<<" ";
	}
	cout<<all<<endl;


	return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int a1, a2, a3; cin >> a1 >> a2 >> a3;
  int sum = a1+a2+a3;
  if(sum >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
arr = []
for i in range(n):
    arr.append(int(input()))

d = set()

step = 0
now = 0
flag = False
while True:
    step += 1
    nex = arr[now]
    nex -= 1
    # print(nex)
    if nex == 1:
        flag = True
        break

    if nex not in d:
        d.add(nex)
        now = nex
        continue
    else:
        break

if flag:
    print(step)
else:
    print(-1)









Measured memory_bytes: 16032
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    vector<int > num(5);

    int tmp_min_rest = 9;
    int tmp_min_index = 0;
    for ( int i = 0; i < 5; i++ ) {
        cin >> num[i];
        if ( num[i] % 10 == 0 ) {
            continue;
        }
        if ( num[i] % 10 < tmp_min_rest ) {
            tmp_min_rest = num[i] % 10;
            tmp_min_index = i;
        }
    }

    int cnt = 0;
    for ( int i = 0; i < 5; i++ ) {
        if ( i == tmp_min_index | num[i] % 10 == 0 ) {
            cnt += num[i];
        }
        else {
            cnt += (num[i] - num[i] % 10 + 10 );
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
if !ENV['RUBY_THREAD_VM_STACK_SIZE']
  require 'rubygems';RUBY=Gem.ruby
  exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},RUBY,$0) #100MB
end

V = 100_005 # 頂点の最大数+a

n = gets.to_i
to = Array.new(V*2){ [] }
seen = Array.new(V*2, false)
cnt = Array.new(2,0)

n.times do
  x,y = gets.split.map(&:to_i)
  y += V
  to[x] << y
  to[y] << x
end

dfs = -> v do
  return if seen[v]
  seen[v] = true
  cnt[v/V] += 1
  to[v].each do |nv|
    dfs[nv]
  end
end

ans = 0
(V*2).times do |i|
  cnt.fill(0)
  dfs[i]
  ans += cnt[0] * cnt[1]
end
ans -= n
puts ans


Measured memory_bytes: 275272
import java.util.*;
    class Main
    {
      public static void main(String args[])
      {
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        
        String s1=new String();
        String s2=new String();
        
        for(int i=0; i<a;i++){
          s1+=b;
        }
        for(int i=0;i<b;i++){
          s2+=a;
        }
    	if(s1.compareTo(s2)<1)	System.out.println(s1);
    	else	System.out.println(s2);
      }
    }

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

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

  int a(0), b(0), c(0);
  for (int i = 0; i < s.length(); i++) {
    switch (s.at(i)) {
      case 'a':
        a++;
        break;
      case 'b':
        b++;
        break;
      case 'c':
        c++;
        break;
      default:
        break;
    }
  }

  if (abs(a - b) > 1 || abs(a - c) > 1 || abs(b - c) > 1) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
}


Measured memory_bytes: 3572
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            var max = 0L;
            var result = 0L;
            foreach (int a in A)
            {
                if (max < a) max = a;
                else result += max - a;
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 46276
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;

void chmax(string& s1, string& s2) {
    if (s1.size() > s2.size()) return; 
    else if (s1.size() < s2.size()) {
        s1 = s2;
        return;
    }
    else {
        for (int i = 0; i < s1.size(); i++) {
            if (s1[i] > s2[i]) {
                s1 = s2;
                return;
            }
            else if (s1[i] < s2[i]) return;
        }
    }
}

bool is_palindrome(string s) {
    int n = s.size();
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[n - i - 1]) return false;
    }
    return true;
}

int dh[3] = {-1, 0, 1}, dw[3] = {-1, 0, 1};

void solve(int h, int w) {
    vector<string> grid(h);
    for (int i = 0; i < h; i++) {
        cin >> grid[i];
    }
    vector<string> s;
    map<string, int> cnt;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int k = 0; k < 3; k++) {
                for (int l = 0; l < 3; l++) {
                    if (k == 1 && l == 1) continue;
                    int now_h = i, now_w = j;
                    string now_s;
                    do {
                        now_s.push_back(grid[now_h][now_w]);
                        s.push_back(now_s);
                        cnt[now_s]++;
                        now_h = (now_h + dh[k] + h) % h;
                        now_w = (now_w + dw[l] + w) % w;
                    } while (now_h != i || now_w != j);
                }
            }
        }
    }
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    string ans = "";
    for (int i = 0; i < s.size(); i++) {
        if (s[i].size() == 1) continue;
        if (cnt[s[i]] < 2 && !is_palindrome(s[i])) continue;
        chmax(ans, s[i]);
    }
    if (ans == "") cout << 0 << endl;
    else cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    while (true) {
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        solve(H, W);
    }
    return 0;
}


Measured memory_bytes: 39796
#include <bits/stdc++.h>
#define maxi 300005
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define ll long long
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define TRACE
#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#else
#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)
#endif
#define gc getchar
#define REP(i,j,n)               for( i=j;i<n;i++)
#define PER(i,j,n)               for( i=n-1;i>=j;i--)
ll mpow(ll a, ll n,ll mod){
	ll ret=1;ll b=a;
	while(n) {
		if(n&1)
			ret=(ret*b)%mod;
		b=(b*b)%mod;
		n>>=1;
	}
	return (ll)ret;
}
ll gcd(ll a, ll b)
{
    if (a == 0 || b == 0)
       return 0;
    if (a == b)
        return a;
    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}
inline void read(int &x){
	x=0;
	register char c=gc();
	for(;c<'0' || c>'9';c=gc());
	for(;c>='0' && c<='9';c=gc())
		x=(x<<3)+(x<<1)+(c-'0');
}
inline void write(int x){
	register char buffor[35];
	register int i=0;
	do{
		buffor[i++]=(x%10)+'0';
		x/=10;
	} while(x);
	i--;
	while(i>=0) putchar(buffor[i--]);
	putchar('\n');
}
inline int in() { int x; read(x); return x; }
void solve();
int dbg=1;
using namespace std;
int main(){
	int t=1;
	//read(t);
	for(int i=0;i<t;i++){
		//printf("Case #%d:\n",i);
		solve();
	}
	return 0;
}
void solve() {
	ll n,i,j,k,c=0;
	cin>>n;
	vector<pair<ll,ll> > v(n);
	REP(i,0,n)
		cin>>v[i].s>>v[i].f;
	sort(v.begin(), v.end());
	REP(i,0,n){
		c+=v[i].s;
		if(c>v[i].f){
			cout<<"No\n";
			return;
		}
	}
	cout<<"Yes\n";
}



Measured memory_bytes: 3328
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;

fn main() {
    input! {
        N: usize,
        Q: usize,
        tmpABs: [(usize, usize); N-1],
        tmpPXs: [(usize, i64); Q],
    }
    let ABs: Vec<(usize, usize)> = tmpABs.iter().map(|&(a, b)| (a - 1, b - 1)).collect();
    let PXs: Vec<(usize, i64)> = tmpPXs.iter().map(|&(p, x)| (p - 1, x)).collect();

    let mut neibours_list: Vec<Vec<usize>> = vec![Vec::new(); N];
    for &(a, b) in ABs.iter() {
        neibours_list[a].push(b);
        neibours_list[b].push(a);
    }

    let mut children_list: Vec<Vec<usize>> = vec![Vec::new(); N];

    // 根であるノード0からの有向グラフとして扱う
    // 幅優先探索
    // もう見たノード
    let mut checked_set: HashSet<usize> = HashSet::new();
    checked_set.insert(0);
    let mut q: VecDeque<usize> = VecDeque::new();
    for &neibour in neibours_list[0].iter() {
        if !checked_set.contains(&neibour) {
            children_list[0].push(neibour);
            q.push_back(neibour);
        }
    }

    while !q.is_empty() {
        let node = q.pop_front().unwrap();
        checked_set.insert(node);

        for &neibour in neibours_list[node].iter() {
            if !checked_set.contains(&neibour) {
                children_list[node].push(neibour);
                q.push_back(neibour);
            }
        }
    }

    //最後に解決すればよろしい
    let mut Points = vec![0i64; N];
    for &(p, x) in PXs.iter() {
        Points[p] += x;
    }

    // 親ノードから順に解決、ポイントを子に伝搬させていく
    // qは空になっているはずなので再利用しちゃう
    q.push_back(0);

    while !q.is_empty() {
        let node = q.pop_front().unwrap();
        let p = Points[node];

        for &child in children_list[node].iter() {
            Points[child] += p;
            q.push_back(child);
        }
    }

    for i in 0..N {
        print!("{} ", Points[i]);
    }
    println!("");
}


Measured memory_bytes: 45460
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
x,y = Line(N,2)

ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)

print(2*ans/N)

Measured memory_bytes: 38484
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    if (n < 1000) {
        cout << "ABC" << endl;
    } else {
        cout << "ABD" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
/*input
3 5
...#.
.#.#.
.#...




*/

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

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j;
	ll h,w;
	cin>>h>>w;
	ll a[h][w];
	char c;
	rep(i,0,h){
		rep(j,0,w){
			cin>>c;
			if(c=='.'){
				a[i][j]=1;
			}else
				a[i][j]=0;
		}
	}
	ll x,y,x1,y1,k,k1,ans=0;
	ll vis[h][w];
	list<pair<pll,ll>> queue;
	rep(x,0,h){
		rep(y,0,w){
			rep(x1,0,h){
				rep(y1,0,w){

					if(a[x][y]&&a[x1][y1]){
						rep(i,0,h)
							rep(j,0,w)
								vis[i][j]=0;

						vis[x][y]=1;
						queue.clear();
						queue.pb(mp(mp(x,y),0));
						while(!queue.empty()){
							pair<pll,ll> z1=queue.front();
							pll z=z1.F;
							ll z2=z1.S;
							queue.pop_front();
							if(z.F==x1&&z.S==y1){
								ans=max(ans,z2);
								break;
							}
							k=z.F,k1=z.S;
							if(k<h-1&&!vis[k+1][k1]&&a[k+1][k1]){
								queue.pb(mp(mp(k+1,k1),z2+1));
								vis[k+1][k1]=1;
							}if(k>0&&!vis[k-1][k1]&&a[k-1][k1]){
								queue.pb(mp(mp(k-1,k1),z2+1));
								vis[k-1][k1]=1;
							}if(k1>0&&!vis[k][k1-1]&&a[k][k1-1]){
								queue.pb(mp(mp(k,k1-1),z2+1));
								vis[k][k1-1]=1;
							}if(k1<w-1&&!vis[k][k1+1]&&a[k][k1+1]){
								queue.pb(mp(mp(k,k1+1),z2+1));
								vis[k][k1+1]=1;
							}

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




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node { int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print(int u){
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";

    if ( T[u].p == NIL ) cout << "root, ";
    else if ( T[u].l == NIL ) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";

    for( i = 0, c = T[u].l; c != NIL; i++, c = T[c].r ){
        if (i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

// 再帰的に深さを求める
int rec(int u, int p) {
    D[u] = p;
    if ( T[u].r != NIL ) rec(T[u].r, p);
    if ( T[u].l != NIL ) rec(T[u].l, p + 1);
}

int main(){
    int i, j, d, v, c, l, r;
    cin >> n;
    for ( i = 0; i < n; i++ ) T[i].p = T[i].l = T[i].r = NIL;

    for ( i = 0; i < n; i++ ) {
        cin >> v >> d;
        for( j = 0; j < d; j++){
            cin >> c;
            if ( j == 0 ) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for ( i = 0; i < n; i++ ){
        if (T[i].p == NIL) r = i;
    }

    rec(r, 0);

    for( i = 0; i < n; i++) print(i);

    return 0;
}


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

using namespace std;
typedef pair<int,int> ii;
vector<ii> ans;
int n,k,mx=0;
int main()
{
    cin >> n >> k;
    for (int i=1;i<=n-2;i++) mx+=i;
    if (k>mx)
    {
        cout << "-1";
        return 0;
    }
    if (1)
    {
        for (int i=2;i<=n;i++) ans.push_back(ii(1,i));
        int d=mx-k;
        for (int i=2;i<n;i++)
            for (int j=i+1;j<=n;j++)
            {
                if (d==0)
                {
                    cout << ans.size() << "\n";
                    for (ii v:ans) cout << v.first << " " << v.second << "\n";
                    return 0;
                }
                ans.push_back(ii(i,j));
                d--;
            }
        cout << ans.size() << "\n";
        for (ii v:ans) cout << v.first << " " << v.second << "\n";
        return 0;
    }
}

Measured memory_bytes: 384
/*
    Ankit Singhal
 */
#define ll long long int
#include <bits/stdc++.h>
//#include <fstream>
using namespace std;
 
#define         ff               first
#define         ss               second
#define         mp               make_pair
#define         pb               push_back
#define         pf               push_front
#define         vi               vector<ll>
#define         pii              pair<ll,ll>
#define         qi               queue<ll>
#define         mem(a,b)         memset(a,b,sizeof(a))
#define         print(a)         cout<<a<<'\n'
#define         sorted(arr)      sort(arr.begin(),arr.end())
#define         gcd(a,b)         gcd((a),(b))
#define         lcm(a,b)         ((a)*(b))/gcd((a),(b))
#define         all(v)           v.begin(),v.end()
#define         read(a)          scanf("%d", &a)
#define         f(a,n)           for(ll i=a;i<n;i++)
#define         in2(n,m,arr)     for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cin>>arr[i][j];}
#define         debug(a)         cerr<<a<<" ";
#define         debug1(a)        cerr<<a<<'\n'
 
/*typedef tree<int, null_type, less<int>, rb_tree_tag , tree_order_statistics_node_update> Set;*/


const unsigned ll mod= (ll)1e9 + 7 ;
const ll inf = (ll)1e15 + 42;
const ll N = (ll)1e6 + 2;
 
ll power ( ll x , unsigned ll y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}
 
/*struct node{
    ll x , y , z;
};
vector<set<ll>> tree;
vector<ll> ar , ans;
set<ll> s;
ll get(ll x)
{
    if(x == ar[x])
        return x;
    return ar[x] = get(ar[x]);
}
void merge(ll a ,ll b)
{
    a = get(a);
    b = get(b);
    if(a == b)
        return;
    ar[b] = ar[a];
    //ans[a] += ans[b];
 }

ll sev[1000001];


void seive()
{
    for(ll i = 2 ; i <= 1000000 ; i ++)
    {
        if(!sev[i])
        {
            for(ll j = i ; j <= 1000000 ; j += i)
            {
                if(!sev[j])
                    sev[j] = i;
            }
        }
    }
}
*/

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t ;
    t = 1;
    //cin >> t;
    while(t --)
    {
        ll n;
        cin >> n;
        ll arr[n];
        ll col[3];
        mem(col , 0);
        ll ans = 1;
        for(ll i = 0 ;i < n; i ++)
        {
            cin >> arr[i];
            ll ind = 0 , count = 0 ;
            if(col[0] == arr[i])
                ind = 0 , count ++;
            if(col[1] == arr[i])
                ind = 1 , count ++;
            if(col[2] == arr[i])
                ind = 2 , count ++;
            
            col[ind] ++;
            ans *= count;
            ans %= mod;
                
        }
        print(ans);
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
    
}
 


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });

            var N = ReadLine();
            var S = ReadLine();
            var x = 0L;
            var ans = 0L;
            foreach (var c in S)
                if (c == 'I')
                {
                    ++x;
                    ans = Max(ans, x);
                }
                else
                    --x;
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

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

int main() {
	string s;
	cin >> s;
	int n = s.size();

	int ans = 999;
	for (int i = 0; i < n - 2; i++) {
		int x = stoi(s.substr(i, 3));
		ans = min(ans, abs(x - 753));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
P = list(map(int,input().split()))
V = [1,2,4,8]

n = 4*int(input())



VP = []
bv, bp = 0,1
for v,p in zip(V,P):
  if bv*p < v*bp:
    VP.append((v,p))
    bv,bp = v,p

result = 0
for v,p in reversed(VP):
  result += (n//v)*p
  n %= v

print(result)

Measured memory_bytes: 3064
// AOJ 1502: War
// 2017.11.17 bal4u@uu

#include <stdio.h>

int h[126];

int main()
{
	int n, i, k, v, s;
	long long ans;

	scanf("%d", &n);
	for (ans = 1, i = 0; i < n; i++) {
		scanf("%d", &v);
		if (v <= 125) h[v]++;
		ans += v;
	}

	for (s = 0, k = 4, i = 1; i <= 125; i++, k += 4) {
		s += h[i-1];
		if (n > s+k) ans -= n-(s+k);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1844
from collections import deque
n = int(input())
adj = [ [] for _ in range(n+1) ]
for _ in range(n):
  lst = list(map(int,input().split()))
  if lst[1] > 0:
    adj[lst[0]] = lst[2:]

q = deque([1])
dist = [-1] * (n+1)
dist[1] = 0

q = deque([1])
while q:
  node = q.popleft()

  for nei in adj[node]:
    if dist[nei] != -1: continue
    dist[nei] = dist[node] + 1
    q.append(nei)

for i,s in enumerate(dist):
  if i==0: continue
  print(i, s)




Measured memory_bytes: 6036
//============================================================================
// Name        : dpl_1b.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n, W, v[100], w[100], dp[10001];
	cin >> n >> W;
	for(int i = 0;i < n;i++){
		cin >> v[i] >> w[i];
	}
	fill(dp,dp + 10001,-1);
	dp[0] = 0;
	for(int i = 0;i < n;i++){
		for(int j = W;j >= 0;j--){
			if(j - w[i] >= 0 && dp[j - w[i]] != -1 && (dp[j] == -1 || dp[j] < dp[j - w[i]] + v[i])){
				dp[j] = dp[j - w[i]] + v[i];
			}
		}
	}
	int ans = 0;
	for(int i = 0;i <= W;i++){
		ans = max(ans,dp[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int n;
    cin >> n;

    deque<int> h;
    int num;
    for (int i = 0; i < n; i++)
    {
        cin >> num;
        h.push_back(num);
    }

    int cnt = 0;
    int temp;
    int mx = 0;
    int i = 0;
    while (h.size() > 1)
    {
        temp = h.front();
        h.pop_front();

        if (temp >= h[i])
        {
            // printf("temp: %d h[i]: %d\n", temp, h[i]);
            cnt++;
            mx = max(mx, cnt);
        }
        else
        {
            cnt = 0;
        }
        i = 0;
    }
    int ans = mx;
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 640
import java.io.PrintWriter;
import java.util.Scanner;

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

		int N = Integer.parseInt(stdin.next());
		int Nlist[] = new int[N];
		int list[] = new int[N];
		int p[] = new int[N];
		int cnt = 0;

		for(int i=0;i<N;i++) {
			p[i] = Integer.parseInt(stdin.next());
			list[i] = i+1;
		}
		
		for(int i=0;i<N;i++) {
			if(list[i] != p[i]) {
				cnt += 1;
			}
		}
		
		if(cnt > 2) {
			out.print("NO");
		}
		else {
			out.print("YES");
		}

		out.flush();
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;cin >> a >> b >> c;
	cout << c/a*b << endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define forin(i,array) for(auto& x:array)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mod 1000000007
#define inf 10000000000000


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

int ans,n;

void func(ll x,int counter){
    if(x>n)return;
    if(counter==7)ans++;
    func(x*10+3,counter|4);
    func(x*10+5,counter|2);
    func(x*10+7,counter|1);
}



int main(){
    cin>>n;
    func(0,0);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
c = []
s = []
f = []
for _ in range(n-1):
	INPUT = list(map(int, input().split()))
	c.append(INPUT[0])
	s.append(INPUT[1])
	f.append(INPUT[2])

for i in range(n):
	if i == n-1:
		print(0)
	else:
		cc = c[i:]
		ss = s[i:]
		ff = f[i:]
		ans = cc[0] + ss[0]
		for j in range(n-2-i):
			if ans <= ss[j+1]:
				ans = cc[j+1] + ss[j+1]
			else:
				start = (((ans - ss[j+1] + ff[j+1] - 1) // ff[j+1]) * ff[j+1]) + ss[j+1]
				ans = start + cc[j+1]

		print(ans)

Measured memory_bytes: 3572
a=sorted(list(input()))
b=[]
c=[]
d=0
if len(a)%2==0:
    for i in range(len(a)//2):
        b.append(a[2*i])
        c.append(a[2*i+1])
    for j in range(len(b)):
        if b[j]==c[j]:
            d+=1
    if d==len(a)//2:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N,X;
  cin >> N >> X;
  int d=0;
  int l;
  for(int i=0;i<N;i++){
    cin >> l;
    d = d+l;
    if(i==N-1){
      if(d<=X){
      cout << N+1 << endl;
        break;
      }
    }
    if(d<=X){
      continue;
    }
    if(d > X){
      cout << i+1 << endl;
      break;
    }
  }
  
  
}


Measured memory_bytes: 256
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
A = input()
B = input()
C = input()

ans = 0
for i in range(N):
    if A[i] == B[i] == C[i]:
        continue
    if A[i] == B[i] or B[i] == C[i] or C[i] == A[i]:
        ans += 1
    else:
        ans += 2
print(ans)



Measured memory_bytes: 38384
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)

ll encode(pair<ll, ll> p) {
	return (p.first << 32) | p.second;
}

pair<ll,ll> decode(ll p) {
	ll a = p >> 32;
	ll b = p & ((1 << 32) - 1);
	return {a, b};
}

int main() {
	using P = pair<ll, ll>;
	ll H, W, N;
	cin >> H >> W >> N;
	vector<P> points(N);
	rep(i,0,N) {
		ll a, b;
		cin >> a >> b;
		a--;
		b--;
		points[i] = {b, a};
	}
	unordered_map<ll, bool> marked;
	rep(i,0,N) {
		marked[encode(points[i])] = true;
	}
	unordered_map<ll, ll> ans;
	unordered_map<ll, bool> checked;
	for (auto p : points) {
		for (ll vec_x : {-1, 0, 1}) {
			for (ll vec_y : {-1, 0, 1}) {
				P q = {p.first + vec_x, p.second + vec_y};
				if (!(0 <= q.first-1 && q.first+1 < W &&
					0 <= q.second-1 && q.second+1 < H)) {
					continue;
				}
				if (checked[encode(q)]) {
					continue;
				}
				checked[encode(q)] = true;
				ll cnt = 0;
				for (ll x : {-1, 0, 1}) {
					for (ll y : {-1, 0, 1}) {
						P r = {q.first + x, q.second + y};
						if (marked[encode(r)]) {
							cnt++;
						}
					}
				}
				ans[cnt]++;
			}
		}
	}
	ll pos_sum = 0;
	rep(i,1,10) {
		pos_sum += ans[i];
	}
	ans[0] = (W-2)*(H-2) - pos_sum;
	rep(i,0,10) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 199748
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REP1(i,n) for(int i=1;i<=(int)(n);i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)

int main(){
  char i;
  cin >> i;
  if(i<=90)cout << 'A' << endl;
  else cout << 'a' << endl;
}

Measured memory_bytes: 3628
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (h, w) = get!(usize, usize);
    let mut v = vec![vec!['.'; w + 2]; h + 2];
    for i in 0..h {
        let tmp: Vec<char> = get!(String).chars().collect();
        for j in 0..tmp.len() {
            if tmp[j] == '#' {
                v[i + 1][j + 1] = '#';
            }
        }
    }
    let di: [i32; 4] = [-1, 0, 1, 0];
    let dj: [i32; 4] = [0, 1, 0, -1];
    for i in 1..h + 1 {
        for j in 1..w + 1 {
            if v[i][j] == '#' {
                let mut flag = false;
                for k in 0..4 {
                    if v[(i as i32 + di[k]) as usize][(j as i32 + dj[k]) as usize] == '#' {
                        flag = true;
                    }
                }
                if !flag {
                    println!("No");
                    return;
                }
            }
        }
    }
    println!("Yes");
}


Measured memory_bytes: 4352
using System;

class Atcoder59
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int x = int.Parse(input[0]);
        int a = int.Parse(input[1]);
        int b = int.Parse(input[2]);

        int da = Math.Abs(x - a);
        int db = Math.Abs(x - b);

        if (da > db)
            Console.WriteLine("B");
        else
            Console.WriteLine("A");
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  (B) <= (A) && (A) <= (C)
#define AIN(A, B, C) assert(IN(A, B, C))
ll ar[200004];
ll b[200005];
void solve(){
       ll n,m,k;
       cin>>n>>m>>k;
       
       f(i,0,n)cin>>ar[i];
       f(i,1,n)ar[i]+=ar[i-1];
       
       f(i,0,m)cin>>b[i];
       f(i,1,m)b[i]+=b[i-1];
       
       ll sum=0;
       ll ans=0;
       
       f(i,0,n){
       	sum=ar[i];
       	ll h=m-1;
       	if(sum<=k)
       	ans=max(ans,0LL+i+1);
       	ll l=0;
       	while(l+1<h){
       	  ll mm=(l+h)/2;	
       	  if(sum+b[mm]<=k){
       	  	ans=max(ans,i+1+mm+1);
       	  	l=mm;
       	  }
       	  else{
       	    h=mm-1;
       	  }
       	  // cout<<i<<" "<<l<<" "<<h<<"\n";  	   	
       	}
        //cout<<i<<" "<<ans<<"\n";
       	if(sum+b[l]<=k)ans=max(ans,0LL+i+1+l+1);
       	if(sum+b[h]<=k)ans=max(ans,0LL+i+1+h+1);
       	//cout<<i<<" "<<ans<<"\n";
       }
        f(i,0,m){
       	sum=b[i];
       	ll h=n-1;
       	if(sum<=k)
       	ans=max(ans,0LL+i+1);
       	ll l=0;
       	while(l+1<h){
       	  ll mm=(l+h)/2;	
       	  if(sum+ar[mm]<=k){
       	  	ans=max(ans,i+1+mm+1);
       	  	l=mm;
       	  }
       	  else{
       	    h=mm-1;
       	  }
       	  // cout<<i<<" "<<l<<" "<<h<<"\n";  	   	
       	}
        //cout<<i<<" "<<ans<<"\n";
       	if(sum+ar[l]<=k)ans=max(ans,0LL+i+1+l+1);
       	if(sum+ar[h]<=k)ans=max(ans,0LL+i+1+h+1);
       	//cout<<i<<" "<<ans<<"\n";
       }
       cout<<ans;
}
int main() {
    ios;
	int t=1;
	//cin>>t;
	while(t--)solve();
 
    
}


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

bool comp(int i, int N, int p[]) {
    int ans=0;
    for(int n = 0; n < N; n++){
        if (i == p[n]) ans = 1;
    }
    if (ans==0) return true;
    return false;
}

int main() {
    int X, N, p[101] = {0};
    cin >> X >> N;
    int min = 1000, ans=0;
    if (N == 0){
        cout << X << endl;
        return 0;
    }
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < 102; i++) {
        bool c = comp(i, N, p);
        if (c && abs(X-i) < min) {
            min = abs(X-i);
            ans = i;
        }
        else if (c && abs(X-i) == min && i < ans) {
            ans = i;
        }
        
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int a, cnt[3];
double p[301][301][301], DP[301][301][301], N;

int main() {
	cin >> N;
	for (int i = 0; i != N; ++i) {
		cin >> a;
		++cnt[a - 1];
	}
	p[cnt[0]][cnt[1]][cnt[2]] = 1;
	for (int i = 300; i != -1; --i) {
		for (int j = 300; j != -1; --j) {
			for (int k = 300; k != -1; --k) {
				if (p[k][j][i]) {
					if (i)
						p[k][j + 1][i - 1] += p[k][j][i] * i / (i + j + k);
					if (j)
						p[k + 1][j - 1][i] += p[k][j][i] * j / (i + j + k);
					if (k)
						p[k - 1][j][i] += p[k][j][i] * k / (i + j + k);
				}
			}
		}
	}
	for (int i = 300; i != -1; --i) {
		for (int j = 300; j != -1; --j) {
			for (int k = 300; k != -1; --k) {
				if (p[k][j][i]) {
					if (i)
						DP[k][j + 1][i - 1] += (DP[k][j][i] + N / (i + j + k)) * p[k][j][i] * i / (i + j + k) / p[k][j + 1][i - 1];
					if (j)
						DP[k + 1][j - 1][i] += (DP[k][j][i] + N / (i + j + k)) * p[k][j][i] * j / (i + j + k) / p[k + 1][j - 1][i];
					if (k)
						DP[k - 1][j][i] += (DP[k][j][i] + N / (i + j + k)) * p[k][j][i] * k / (i + j + k) / p[k - 1][j][i];
				}
			}
		}
	}
	printf("%.10f", DP[0][0][0]);
	return 0;
}

Measured memory_bytes: 426240
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

char s[1010];
int main(){
	int n;
	scanf("%d %s",&n,s);
	if(n%2){
		puts("No");
		return 0;
	}
	rep(i,0,n/2)if(s[i]!=s[n/2+i]){
		puts("No");
		return 0;
	}
	puts("Yes");
}

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

void BFS(vector<vector<long long> >& Graph, long long start, vector<long long>& reach, vector<bool>& Flag) {
	queue<long long>Q;
	Q.push(start);
	Flag.at(start) = true;
	reach.at(start) = 0;
	while (!Q.empty()) {
		long long v = Q.front(); Q.pop();
		for (long long i = 0; i < Graph[v].size(); i++) {
		    long long to = Graph[v].at(i);
			if (!Flag.at(to - 1)) {
				reach.at(to - 1) = reach.at(v) + 1;
				Flag.at(to - 1) = true;
				Q.push(to - 1);
			}
		}
	}
}
int main() {
	long long N; cin >> N;
	vector<vector<long long> >Graph(N);
	for (long long i = 0; i < N; i++) {
		long long virtex, num;
		cin >> virtex >> num;
		for (long long j = 0; j < num; j++) {
			long long to; cin >> to;
			Graph.at(virtex - 1).push_back(to);
		}
	}
	vector<long long>reach(N, -1);
	vector<bool>Flag(N, false);
	BFS(Graph, 0, reach, Flag);
	for (long long i = 0; i < N; i++) {
		cout << i + 1 << ' ' << reach.at(i) << endl;
	}
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s,sub,x,y;
	cin>>s;
	for(int i=2;i<s.size();i+=2){
		sub=s.substr(0,s.size()-i);
		x=sub.substr(0,sub.size()/2);
		y=sub.substr(sub.size()/2,sub.size()/2);
		if(x==y){
			cout<<sub.size()<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int n;
    scanf("%d",&n);

    char s[n];
    scanf("%s",s);

    int a[26];
    int b[26];

    int count=0;
    int max=0;
    for(int i=0; i<n-1; i++){
      for(int p=0; p<26; p++){
          a[p] = 0;
          b[p] = 0;
      }
      for(int j=0; j<i+1; j++){
        a[s[j]-'a']++;
      }
      for(int k=i+1; k<n; k++){
        b[s[k]-'a']++;
      }
      for(int l=0; l<26; l++){
        if((a[l]!= 0)&&(b[l]!=0)){
          count++;
        }
      }
      if(count>max){
        max=count;
      }
      count = 0;
    }

    printf("%d",max);
    return 0;

}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    val n = getInt()
    val m = IntArray(10001) { 0 }

    fun cal(a: Int, b: Int, c: Int) : Int {
        return a * a + b * b + c * c + a * b + b * c + c * a
    }

    (1..100).forEach { a ->
        (1..100).forEach { b ->
            (1..100).forEach { c ->
                val k = cal(a, b, c)
                if (k <= 10000) {
                    m[k]++
                }
            }
        }
    }

    (1..n).forEach {
        println(m[it])
    }
}

fun getInt() = readLine()!!.toInt()

Measured memory_bytes: 38372