akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
class level {
	int num;
	int size;
	int to_b(const int &n) {
		if (n == 0)
			return 0;
		else
			return (to_b(n / 10) << 1) + (n % 10);
	}
public:
	int test(const int &n) {
		return (((num << (n + 1)) >> size) & 1) - (((num  << n) >> size) & 1);
	}
	level(const int &n = 0, const int &d = 0) :size(d) {
		num = to_b(n);
	};
};
class Lot {
	std::vector<level> levels;
	std::vector<int> down;
	std::vector<int> up;
	void solve() {
		for (auto i = 0; i < down.size() - 1; ++i) {
			down.at(i + 1) = down.at(i) + levels.at(i).test(down.at(i));
		}
	}
	void solve_inv() {
		for (auto i = up.size() - 1; i > 0; --i) {
			up.at(i - 1) = up.at(i) + levels.at(i - 1).test(up.at(i));
		}
	}
public:
	const int choice;
	const int hit;
	Lot(const int &n, const int &m, const int &h, const int &d) :choice(m), hit(h), levels(d), down(d + 1, 0), up(d + 1, 0) {
		for (auto &l : levels) {
			int i;
			std::cin >> i;
			l = level(i, n);
		}
		down.at(0) = m;
		up.at(d) = h;
		solve();
		solve_inv();
	}
	void show() {
		if (down.at(0) == up.at(0)) {
			std::cout << 0 << std::endl;
		}
		else {
			bool flag = true;
			for (auto i = 0; i < down.size() - 1; ++i) {
				if (((down.at(i) - up.at(i)) * (down.at(i) - up.at(i)) == 1) && (down.at(i) == down.at(i + 1)) && (up.at(i) == up.at(i + 1))) {
					std::cout << i + 1 << " " << ((down.at(i) < up.at(i)) ? down.at(i) : up.at(i)) << std::endl;
					i = down.size();
					flag = false;
				}
			}
			if (flag) {
				std::cout << 1 << std::endl;
			}
		}
	}
	void inspect() {
		std::cout << "down" << std::endl;
		for (const auto &d : down) {
			std::cout << d << '\n';
		}
		std::cout << "up" << std::endl;
		for (const auto &u : up) {
			std::cout << u << '\n';
		}
	}
};
int main() {
	int n;
	std::cin >> n;
	while (n != 0) {
		int m, h, d;
		std::cin >> m >> h >> d;
		Lot lot(n, m, h, d);
		lot.show();
		std::cin >> n;
	}
	return 0;
}

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

#define debug(x) cout << #x << ": " << (x) << endl

const int INF = INT_MAX / 3;

int main(int argc, char *argv[]) {
  int n, ma, mb;
  cin >> n >> ma >> mb;

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

  int dp[401][401];
  int res = INF;
  fill_n(&dp[0][0], 401*401, INF);
  dp[0][0] = 0;

  for (int i = 0; i < n; i++) {
    for (int wa = 400; a[i] <= wa; wa--) {
      for (int wb = 400; b[i] <= wb; wb--) {
        dp[wa][wb] = min(dp[wa][wb], dp[wa - a[i]][wb - b[i]] + c[i]);
        if (ma*wb == mb*wa)
          res = min(res, dp[wa][wb]);
      }
    }
  }

  cout << (res == INF ? -1 : res) << endl;

  return 0;
}


Measured memory_bytes: 896
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;

ll a, b, c, n, k, x;
string s;

int main()
{
  cin >> n >> k;
  ll l[n];
  for (ll i = 0; i < n; i++)
  {
    cin >> l[i];
  }
  sort(l, l + n, greater<int>());

  ll ans = 0;
  for (ll i = 0; i < k; i++)
  {
    ans += l[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define f(a, b, c) for(ll a=b; a<c; a++)
#define fo(a, b, c) for(ll a=b; a<=c; a++)

using namespace std;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin>>t;
    // while(t--){
    fo(i, 1, 9){
        ll n = t/i;
        if(n>=1 && n<=9 && (n*i == t)){
            cout<<"Yes"<<endl;
            // cout<<n<<" "<<i<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;


    // }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 200005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n,y;
  scanf("%d%d",&n,&y);
  y /= 1000;
  int a = 0, b = 0, c = y;
  while (y-4 >= n && c >= 5) {
    y -= 4;
    b++; c -= 5;
  }
  while (y-1 >= n && b >= 2) {
    y--;
    a++; b -= 2;
  }
  if (y == n) {
    cout<<a<<" "<<b<<" "<<c<<endl;
  } else {
    cout<<vi(3,-1)<<endl;
  }
  return 0;
}






















Measured memory_bytes: 256
import java.util.Scanner;

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

		int a, b, c;
		for ( int n = stdIn.nextInt(); n-- > 0; System.out.println( a * a + b * b == c * c || b * b + c * c == a * a || c * c + a * a == b * b ? "YES" : "NO" ) ) {
			a = stdIn.nextInt();
			b = stdIn.nextInt();
			c = stdIn.nextInt();
		}
	}
}

Measured memory_bytes: 23396
#include <stdio.h>          // printf(), scanf()

#define MAX_V 15
#define min(a, b) ((a) < (b) ? (a) : (b))

static const int INF = 1000000000;

int d[MAX_V][MAX_V];
int dp[1 << MAX_V][MAX_V];
int V;

int
rec(int S, int v)
{
	int u;

	if (dp[S][v] >= 0)
		return dp[S][v];

	if (S == (1 << V) - 1 && v == 0)
		return dp[S][v] = 0;

	int res = INF;
	for (u = 0; u < V; ++u)
	{
		if (!(S >> u & 1))
		{
			int t = rec(S | 1 << u, u) + d[v][u];
			res = min(res, t);
		}
	}

	return dp[S][v] = res;
}

int
main(int argc, char** argv)
{
	int E;
	int s, t, c;
	int i, j;

	scanf("%d %d", &V, &E);
	for (i = 0; i < V; ++i)
	{
		for (j = 0; j < V; ++j)
		{
			if (i == j)
				d[i][j] = 0;
			else
				d[i][j] = INF;
		}
	}

	for (i = 0; i < E; ++i)
	{
		scanf("%d %d %d", &s, &t, &c);
		d[s][t] = c;
	}

	for (i = 0; i < 1 << V; ++i)
	{
		for (j = 0; j < V; ++j)
			dp[i][j] = -1;
	}

	int res = rec(0, 0);
	if (res == INF)
		res = -1;

	printf("%d\n", res);
	return 0;
}

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

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
struct guide{
  long number;
  string city;
  long score;
};

bool comp(const guide &a,const guide &b){
  if(a.city == b.city){
    return a.score > b.score;
  }
  else{
    return a.city < b.city;
  }
}
  
int main(){
  long n,ii;
  vector<guide> v;
  cin >> n;
  v.resize(n);
  for(ii=0;ii<n;ii++){
    cin >> v[ii].city >> v[ii].score;
    v[ii].number = ii+1;
  }
  sort(v.begin(),v.end(),comp);
  for(ii=0;ii<n;ii++){
    //cout << v[ii].city << v[ii].score << ":";
    cout << v[ii].number << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector

#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}

signed main()
{
   int Q, H, S, D; cin >> Q >> H >> S >> D;
   int N; cin >> N;

   int MIN2 = min(min(8*Q, 4*H), min(2*S, D));
   int MIN1 = min(min(4*Q, 2*H), S);
   if (N % 2 == 0) {
      cout << MIN2 * (N/2) << endl;
   } else {
      cout << MIN2 * (N/2) + MIN1 << endl;
   }
   return 0;
}


Measured memory_bytes: 256
/*
 *  Author : Jun_SH
 *  12/11/2019
 */
#include<bits/stdc++.h>
#pragma GCC optimize(3,"Ofast","inline")
#define int long long
using namespace std;
inline int read(){
    int f=1,x=0;char ch=getchar();
    while(ch<'0'&&ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return f*x;
}
vector<int>v;
const int mod=998244353;
int qp(int n,int k){
    int res=1;
    while(k){
        if(k&1){
            res=res*n%mod;
        }
        k>>=1;
        n=n*n%mod;
    }
    return res;
}
const int maxn=1e5+10;
int a[maxn]={};
main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int ans=1;
    for(int i=1;i<=n;++i){
        int x;
        cin>>x;
        if(i==1&&x!=0)ans=0;
        a[x]++;
    }
    if(a[0]!=1)ans=0;
    int tot=1;
    for(int i=1;a[i];++i){
        tot+=a[i];
        ans=ans*qp(a[i-1],a[i])%mod;
    }
    if(tot!=n)ans=0;
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//ここまでテンプレ
int main(){
	ll N;
	cin>>N;
	vll A,B;
	for(int i=0;i<N;i++){
		ll a;
		cin>>a;
		A.pb(a);
	}
	for(int i=0;i<N;i++){
		ll b;
		cin>>b;
		B.pb(b);
	}
	ll ans=0;
	for(int bit=0;bit<30;bit++){
		ll num=0;
		ll T=1<<bit;
		vll a,b;
		for(int i=0;i<N;i++){
			a.pb(A[i]%(2*T));
			b.pb(B[i]%(2*T));
		}
		sort(a.begin(),a.end());
		sort(b.begin(),b.end());
		for(int i=0;i<N;i++){
			num+=upper_bound(b.begin(),b.end(),2*T-a[i]-1)-lower_bound(b.begin(),b.end(),T-a[i]);
			num+=upper_bound(b.begin(),b.end(),4*T-a[i]-1)-lower_bound(b.begin(),b.end(),3*T-a[i]);
		}
		ans|=(num%2)*(1<<bit);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8404
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

immutable long mod = 10^^9 + 7;
immutable int inf = mod;

void main(){
    int N, W;
    readVars(N, W);

    auto v = new int[](N);
    auto w = new int[](N);

    foreach(i ; 0 .. N){
        readVars(v[i], w[i]);
    }

    auto dp = new int[](W + 1);

    foreach(u ; 1 .. W + 1){
        foreach(i ; 0 .. N){
            if(u - w[i] >= 0){
                dp[u] = max(dp[u], dp[u - w[i]] + v[i]);
            }
        }
    }

    writeln(dp[W]);
}

void readVars(T...)(auto ref T args){
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        throw new Exception("args num < input num");
    }
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> s(N);
  for (int i=0; i<N; i++) {
    cin >> s[i];
  }
  int ans =0;
  sort(s.begin(), s.end());
    
  for (int i=0; i<N; i++) {
    for (int j=i+1; j<N; j++) {
      for (int k=j+1; k<N; k++) {
        if (s[i] < s[j] + s[k] && s[j] < s[k] + s[i] && s[k] < s[i] + s[j]) {
          ans++;
        }
        else break;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String buffer[] = new String[3];
        for (int ct = 0; ct < 3; ct++) {
            buffer[ct] = br.readLine();
        }
        System.out.println(buffer[0].charAt(0) +""+ buffer[1].charAt(1) +""+ buffer[2].charAt(2));
    }
    
}


Measured memory_bytes: 23124
S = input()
N = len(S)

children_list = [0] * N
RL_index_list = []

for i in range(N - 1):
    if S[i] == 'R' and S[i + 1] == 'L':
        RL_index_list.append([i, i + 1])

r, l = RL_index_list[0]
n = 0
for i in range(N):
    if S[i] == 'R':
        if i > l:
            n += 1
            r, l = RL_index_list[n]
        if (l - i) % 2 == 0:
            children_list[l] += 1
        else:
            children_list[r] += 1
    else:
        if (i - r) % 2 == 0:
            children_list[r] += 1
        else:
            children_list[l] += 1

L = [str(x) for x in children_list]
ans = " ".join(L)
print(ans)

Measured memory_bytes: 19248
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const int imax = ~(1 << 31);
const long long linf = 1ll << 61;
const long long lmax = ~(1ll << 63);

#define dump(x) cerr << #x << " : " << x << '\n'
#define MOD(x, y) (((y) + (x) % (y)) % (y))

string s;
int N, K;

int main(int argc, char* argv[])
{
    cin >> s;
    cin >> K;
    N = s.length();
    string list[5];

    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            if (i + j - 1 >= N) continue;
            string t = s.substr(i, j);
            int k;
            for (k = 4; k >= 0; k--) {
                if (list[k].length() == 0) continue;
                if (list[k] == t) {
                    k = 4;
                    break;
                }
                if (list[k] < t) break;
            }
            k++;
            if (k == 5) continue;
            for (int l = 4; l > k; l--) {
                list[l] = list[l - 1];
            }
            list[k] = t;
        }
    }
    cout << list[K - 1] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int z[100002],f[100002];
int main(){
    int n,max1=100001,max2=100001;
    cin>>n;
    int zheng[n/2],fan[n/2];
    for(int i=0;i<n;i++){
        if(i%2==0)cin>>zheng[i/2];
        if(i%2==1)cin>>fan[i/2];
    }
    for(int i=0;i<n/2;i++){
        z[zheng[i]]++;
        f[fan[i]]++;
    }
    for(int i=0;i<=100000;i++){
        if(z[i]>z[max1])max1=i;
        if(f[i]>f[max2])max2=i;
    }
    sort(z,z+100001);
    sort(f,f+100001);
    if(max1==max2)cout<<n-max(z[100000]+f[99999],z[99999]+f[100000])<<endl;
    else cout<<n-(z[100000]+f[100000])<<endl;
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main() {
    int m, d;
    cin >> m >> d;

    int cnt = 0;
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= d; j++) {
            if ((j % 10) >= 2 && (j / 10) >= 2 && (j % 10) * (j / 10) == i) {
                cnt++;
            }
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

use std::cmp::{Ordering, max};

pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (high + low) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();
        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}

#[fastout]
fn main() {
    input! {
    n: usize,
    m: usize,
    k: usize,
    a:[usize; n],
    b:[usize; m]
    }
    let mut a_sum = 0;
    let mut ac = 0;
    let mut cul_b = vec![0; m + 1];
    for i in 0..m {
        cul_b[i + 1] = b[i] + cul_b[i];
    }
    let mut ans = 0;
    while a_sum <= k{
        let b_sum = k - a_sum;
        let bc = cul_b.upper_bound(&b_sum) - 1;
        ans = max(ans, bc + ac);
        if ac == n {break}
        a_sum += a[ac];
        ac += 1;
    }
    println!("{}", ans);
}



Measured memory_bytes: 10892
//#pragma comment(linker, "/STACK:36777216")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <vector>
#include <complex>
#include <ctime>
#include <stack>

//#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector< VI > VVI;
typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define FOR(i, x, y) for(int i = (x); i <= (y); ++i)
#define RFOR(i, y, x) for(int i = (x); i >= (y); --i)
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a)) 
#define CLEAR(x) memset(x, 0, sizeof x);
#define COPY(FROM, TO) memcpy(TO, FROM, sizeof TO);
#define UNIQUE(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())
#define pb push_back
#define mk make_pair
#define sqr(x) ((x)*(x))
#define X first
#define Y second
//typedef tree<int, null_type, less<int>, 
//  rb_tree_tag, tree_order_statistics_node_update> order_set;

const long double PI = acos(-1.0);
const double EPS = 1E-6;
const int INF = 2 * (1e+9) + 1;
const int MAXN = 3 * 100000001;
const int MOD = (1e+9) + 7;


ll n, a, b, t;
string s1, s2;
int main() {
    cin >> s1 >> s2;
    if (s2.substr(0, s1.length()) == s1) {
        cout << "Yes";
    }
    else cout << "No";
    return 0;
}

Measured memory_bytes: 3124
#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() {
  string S;

  cin >> S;
  int N = S.size();
  rep(i, N) {
    if (S[i] != S[N-1-i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  int m = (N-1)/2;
  rep(i, (N-1)/2) {
    if (S[i] != S[m-1-i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  m = (N+3)/2 -1;
  for(int i=m; i<N; ++i) {
    if (S[i] != S[N-1-(i-m)]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
A, B, C = list(map(int,input().split()))
sum_l = A + B + C
max_l = max(A, B, C)

dif = 3*max_l - sum_l
if dif % 2 == 0:
    print(dif // 2)
else:
    print((dif // 2) + 2)

Measured memory_bytes: 2940
package main

import "fmt"

func main(){
var s string
  var n int =0
  fmt.Scanf("%s",&s)
  for _,v :=range s{
    if string(v)=="+" {
    n=n+1
    } else {
    n=n-1
    }
  }
  fmt.Println(n)
  
}

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

int main() {
    int a, b;
    char op;

    int ans;

    while (true) {
        cin >> a >> op >> b;

        if (op == '?') {
            break;
        }

        switch (op) {
            case '+':
                ans = a + b;
                break;
            case '-':
                ans = a - b;
                break;
            case '*':
                ans = a * b;
                break;
            case '/':
                ans = a / b;
                break;
            default:
                break;
        }

        cout << ans << endl;
    }


    return 0;
}


Measured memory_bytes: 3088
import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
# inputb = input().split()

a = int(inputa[0])
b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

if b % a == 0:
    print(a+b)
else:
    print(b-a)


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

int main() {
  string S;
  cin >> S;
  int ans = 1000;
  for(int i = 0;i<S.size()-2;i++) {
    ans = min(ans, abs(753-(S[i]-'0') * 100 - (S[i+1]-'0') * 10 - (S[i+2]-'0')));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool OnBorder(int x, int y, int rows, int cols)
{
    return x == 0 || y == 0 || x == rows || y == cols;
}

int main()
{
    int rows, cols;
    cin >> rows >> cols;

    for (int i = 0; i <= rows + 1; i += 1) {
        for (int j = 0; j <= cols + 1; j += 1) {
            if (OnBorder(i, j, rows + 1, cols + 1)) {
                cout << "#";
            } else {
                char pixel;
                cin >> pixel;
                cout << pixel;
            }
        }
        cout << "\n";
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  each(x,vec) is >> x;
  return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  rep(i,vec.size()) {
    if (i) os << " ";
    os << vec[i];
  }
  return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
  rep(i,vec.size()) {
    if (i) os << endl;
    os << vec[i];
  }
  return os;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b, c; cin >> a >> b >> c;
  vector<ll> kh;
  kh.pb(max({a, b, c}));
  kh.pb(kh.back()+1);
  vector<ll> v{a, b, c};
  ll ans = linf;
  each(x, kh) {
    ll y = 0, cnt = 0;
    rep(i, 3) {
      y += (x - v[i]) / 2;
      cnt += (x - v[i]) % 2;
    }
    if (cnt == 2) ++y;
    if (cnt == 1 || cnt == 3) continue;
    chmin(ans, y);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	S := nextInt()
	W := nextInt()

	if S <= W {
		fmt.Print("unsafe")
	} else {
		fmt.Print("safe")
	}
}


Measured memory_bytes: 1760
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
int a[10];
LL ans;
int main()
{
	for(int i=1;i<=7;i++)
		scanf("%d",&a[i]);
	ans=a[2];
	if(!a[1]||!a[4]||!a[5]) printf("%lld\n",ans+a[1]/2*2+a[4]/2*2+a[5]/2*2);
	else if(a[1]%2==a[4]%2&&a[4]%2==a[5]%2) printf("%lld\n",ans+a[1]+a[4]+a[5]);
	else printf("%lld\n",ans+a[1]+a[4]+a[5]-1);
}

Measured memory_bytes: 128
N = int(input())
dic = [[0,0] for i in range(N)]
for i in range(N):
    A = input().split(" ")
    dic[i] = A

dic_s = sorted(dic,key=lambda x: int(x[1]))

t = 0
ans = "Yes"
for i in range(N):
    
    t += int(dic_s[i][0])
    if (t > int(dic_s[i][1])):
        ans = "No"
        break

print(ans)





Measured memory_bytes: 73996
a, b, c = map(int, input().split())
pat = [
    int(str(a) + str(b)) + c,
    int(str(b) + str(a)) + c,
    a + int(str(b) + str(c)),
    a + int(str(c) + str(b)),
    b + int(str(a) + str(c)),
    b + int(str(c) + str(a))
]
print(max(pat))


Measured memory_bytes: 3060
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto N = RD;
	auto K = RD;
	auto a = new bool[](N);
	foreach (i; 0..K)
	{
		auto d = RD;
		auto A = RDA(-1);
		foreach (e; A)
		{
			a[e] = true;
		}
	}

	long ans;
	foreach (e; a)
	{
		if (!e)
			++ans;
	}

	writeln(ans);
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 2976
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin>>a;
  if("SUN"==a){
    cout<<7<<endl;
  }
    else if("MON"==a){
      cout<<6<<endl;
    }
  else if("TUE"==a){
    cout<<5<<endl;
  }
    else if("WED"==a){
      cout<<4<<endl;
    }
  else if("THU"==a){
    cout<<3<<endl;
  }
  else if("FRI"==a){
    cout<<2<<endl;
  }
  else if("SAT"==a){
cout<<1<<endl;
  }
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const double pi = acos(-1.0);
int a,b,x;

double getv(const double d)
{
    const double half = atan(1.0*b/a);
    const double r = pi*d/180;
    double ans = -inf;
    if (r > half) {
        const double h = b/tan(r);
        ans = a*b*h/2;
    }
    else {
        const double h = a*tan(r);
        ans = a*a*b - a*a*h/2;
    }
    assert(ans != -inf);
    return ans;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    while (cin >> a >> b >> x) {
        double lo = 0, hi = 90;
        FOR(i,0,100) {
            const double mid = (lo+hi)/2;
            const double v = getv(mid);
            if (v > x)
                lo = mid;
            else
                hi = mid;
        }
        cout.precision(10);
        cout << fixed << hi << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
#define MAX 1121
using namespace std;
typedef pair<int,int> P;
bool isntprime[MAX+1];
vector<int> prime;
int dp[MAX+1][16];

int main()
{

  isntprime[0] = isntprime[1] = true;
  int j;
  for(int i=2;i<=MAX;i++)if(!isntprime[i])for(prime.push_back(i),j=2*i;j<=1120;j+=i)isntprime[j] = true;
  int psize = prime.size();

  rep(i,MAX)rep(k,16)dp[i][k]=0;
  dp[0][0] = 1;

  rep(i,psize)
    {
      for(int j=14;j>=0;j--)
	{
	  rep(k,1121)
	    {
	      if(dp[k][j] == 0)continue;
	      if(k+prime[i] > 1120)continue;
	      dp[k+prime[i]][j+1] += dp[k][j];
	    }
	}
    }

  int n,k;
  while(cin >> n >> k,n|k)
    cout << dp[n][k] << endl;
    
  return 0;
}

Measured memory_bytes: 1284
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
LL h, w, n, m, ans[12] = {}, d[100] = {}, a[10][10] = {}, f[200][200] = {}, sum = 0;
int flag = 0;
string str;
int main(){
	cin >> n >> m >> h;
	cin >> str;
	if (n * m < h)sum = n*m;
	else sum = h;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var (
		n, q int
		s    string
	)
	fmt.Scan(&n, &q, &s)
	acc := make([]int, len(s))
	for i := 1; i < len(s); i++ {
		acc[i] = acc[i-1]
		if s[i-1] == 'A' && s[i] == 'C' {
			acc[i]++
		}
	}
	l := make([]int, q)
	r := make([]int, q)
	for i := 0; i < q; i++ {
		fmt.Scan(&l[i], &r[i])
	}
	for i := 0; i < q; i++ {
		fmt.Println(acc[r[i]-1] - acc[l[i]-1])
	}
}

Measured memory_bytes: 7552
#include <stdio.h>
#define N 100
#define NIL -1
#define INF 2000000000
int main(){
  int n;
  int pi[N];
  int d[N];
  int a,b,k,l,i,j,u,v,min=INF,count=0;
  int G[N][N];
  int color[N];
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      G[i][j] = INF;
    }
  }
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&a,&b);
    for(j=0;j<b;j++){
      scanf("%d%d",&k,&l);
      G[a][k] = l;
    }
  }
  
  for(u=0;u<n;u++){
    d[u] = INF;
    pi[u] = NIL;
    color[u] = 0;
  }

  d[0] = 0;
  
  while(1){
    min = INF;
    u = -1;
    for(i=0;i<n;i++){
      if((color[i] != 1) && (d[i] < min)){
        min = d[i];
        u = i;
      }
    }
    
    if(u == NIL){
      break;
    }
    
    color[u] = 1;
    
    for(v=0;v<n;v++){
      if((G[u][v] != -1) && (color[v] != 1) && (d[u] + G[u][v] < d[v])){
	pi[v] = u;
	d[v] = d[u] + G[u][v];
      }
    }
  }
  
  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }
  
  
  return 0;
}



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

using namespace std;

#define REP(i, N) for (int i = 0; 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 < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

int dp[201][201];
int gcd(int a,int b)
{
  if(a<b){
    int tmp=b;
    b=a;
    a=tmp;
  }
	if (a%b==0)
	{
		return(b);
    }
	else
	{
		return(gcd(b,a%b));
    }
}


int main(){
  int n;
  cin>>n;
  ll sum=0;
  memset(dp,-1,sizeof(dp));
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      for(int k=1;k<=n;k++){
        int tmp;
        if(dp[i][j]>=0){
          tmp=dp[i][j];
        }else{
          tmp=gcd(i,j);
          dp[i][j]=tmp;
          dp[j][i]=tmp;
        }

        int tmp2;
        if(dp[tmp][k]>=0){
          tmp2=dp[tmp][k];
        }else{
          tmp2=gcd(tmp,k);
          dp[tmp][k]=tmp2;
          dp[k][tmp]=tmp2;
        }
        //cout<<tmp<<" "<<tmp2<<endl;
        sum+=tmp2;
      }
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3792
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <cctype>
#include <algorithm>
using namespace std;

bool isdigit(char c){
	if(c>='0' && c<='9') return true;
	return false;
}

int main(){
	int num=0;
	double p,q;
	stack<double> st;
	string s;
	int sign=1;
	while(getline(cin,s)){
		s = s + " ";
		for(int i=0;i<s.length();++i){
			if(isdigit(s[i])){
				num*=10;
				num+=s[i]-'0';
			} else if(s[i]=='-' && isdigit(s[i+1])){
				sign=-1;
			} else if(s[i]==' ' && isdigit(s[i-1])){
				num=num*sign;
				st.push(num);
				num=0;
				sign=1;
			} else if (s[i]=='+' || s[i]=='-' || s[i]=='*' || s[i]=='/'){
				p=st.top();
				st.pop();
				q=st.top();
				st.pop();
				if(s[i]=='+') st.push(p+q);
				if(s[i]=='-') st.push(q-p);
				if(s[i]=='*') st.push(p*q);
				if(s[i]=='/') st.push(q/p);
				}
				
			}
		cout << fixed << setprecision(9) << st.top() << endl;
		st.pop();
	}
	return 0; 
}

Measured memory_bytes: 1256
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

const long long int mo = 1e9 + 7;
int main(){
    long long int ans = 0, sum = 0;
    long long int a;
    int n; scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a);
        ans = (ans + sum * a % mo) % mo;
        sum = (sum + a) % mo;
    }
    printf("%lld", ans % mo);
    return 0;
}

Measured memory_bytes: 3820
#include <string>
#include <map>
#include <iostream>
#include <algorithm>
#include <complex>
#include <cstring>

using namespace std;

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define X real()
#define Y imag()

// #define DEBUG

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

typedef complex<int> Pos;

int dp[2][2][2001][2001];

int N, K;
string S;

const int INF = 1e9;

/*
void dfs(int n, int k, int pos, bool dir_x, bool plus)
{
    cerr << n << " " << k << " " <<  pos << endl;

    if (~dp[dir_x][plus][n][k]) return dp[dir_x][plus][n][k];
    if (n == N) return dp[dir_x][plus][n][k] = pos;

    int diff;
    if (dir_x) {
        if (S[n] == 'L' || S[n] == 'R') {
            diff = (S[n] == 'R' ? 1 : -1);
        } else {
            diff = 0;
        }
    } else {
        if (S[n] == 'D' || S[n] == 'U') {
            diff = (S[n] == 'U' ? 1 : -1);
        } else {
            diff = 0;
        }
    }

    int mirror = (k%2 == 0 ? 1 : -1);
    int res = dfs(n+1, k, pos + (mirror * diff), dir_x, plus);
    if (k < K) {
        if (plus) res = max(res, dfs(n+1, k+1, pos + (mirror * diff * -1), dir_x, plus));
        else      res = min(res, dfs(n+1, k+1, pos + (mirror * diff * -1), dir_x, plus));
    }

    return dp[dir_x][plus][n][k] = res;
}
*/

int get_diff(char dir, bool dir_x)
{
    int diff;
    if (dir_x) {
        if (dir == 'L' || dir == 'R') {
            diff = (dir == 'R' ? 1 : -1);
        } else {
            diff = 0;
        }
    } else {
        if (dir == 'D' || dir == 'U') {
            diff = (dir == 'U' ? 1 : -1);
        } else {
            diff = 0;
        }
    }
    return diff;
}


int main()
{
    cin >> S >> K;    
    N = S.size();

    rep(dir_x, 2) rep(n, N+1) rep(k, K+1) dp[dir_x][0][n][k] = INF;
    rep(dir_x, 2) rep(n, N+1) rep(k, K+1) dp[dir_x][1][n][k] = -INF;
    rep(dir_x, 2) rep(plus, 2) rep(k, K+1) dp[dir_x][plus][0][k] = 0;
    

    rep(dir_x, 2) rep(plus, 2) {
        rep(n, N) rep(k, K+1) {
            int diff = get_diff(S[n], dir_x);
            int mirror = (k%2 == 0 ? 1 : -1);
            {
                int npos = dp[dir_x][plus][n][k] + mirror * diff;

                if (plus) chmax(dp[dir_x][plus][n+1][k], npos);
                else      chmin(dp[dir_x][plus][n+1][k], npos);
            }
            if (k < K) {
                int npos = dp[dir_x][plus][n][k] + mirror * diff * -1;
                if (plus) chmax(dp[dir_x][plus][n+1][k+1], npos);
                else      chmin(dp[dir_x][plus][n+1][k+1], npos);
            }
        }
    }

    int dp_abs[2][2001] = {};
    rep(k, K+1) {
        rep(dir_x, 2) {
            int mx = max(abs(dp[dir_x][0][N][k]), abs(dp[dir_x][1][N][k]));
            dp_abs[dir_x][k] = max(dp_abs[dir_x][k], mx);
        }
    }

    int ans = 0;
    rep(kx, K+1) {
        rep(ky, K+1) {
            if (kx + ky <= K) {
                ans = max(ans, dp_abs[0][ky] + dp_abs[1][kx]);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 65736
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (ll i = (ll)(a); i<(ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL <class T = ll> inline T IN() { T x; cin >> x; return x; }
TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
void bOUT(bool c, string s, string t) { OUT(c ? s : t); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }
TPL<TNM T> vector<T> make_v(size_t a) { return vector<T>(a); }
TPL<TNM T, TNM... Ts> auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }

int main(void) {
	string S;
	int K;
	cin >> S >> K;
	set<string> st;
	REP(i, S.size()) {
		FOR(j, 1, K + 1) {
			st.insert(S.substr(i, j));
		}
	}
	auto it = st.begin();
	REP(i, K - 1) {
		it++;
	}
	cout << *it << endl;
	return 0;
}

Measured memory_bytes: 1664
A,B=[int(_) for _ in input().split()]
def fxor(a,b):
    return a^b

def fxorA2B(a,b,iD):
    def calcFD(g,b):
        return (g -1) //2 % 2 if b else g//2 % 2
    if a < b:
        if a == 2**iD :
            sB = bin(b)[2:][::-1]
            i2 = 2**iD -1
            bB = (b - i2)%2
            iC = 0
            for i in range(iD+1):
                iB = int(sB[i])
                if i == 0 and calcFD(b-i2,bB):
                    iC += 1
                elif iB and bB:
                    iC += 2**i
        else:
            a -= 1
            sA = bin(a)[2:][::-1]
            sB = bin(b)[2:][::-1]
            i2 = 2**iD -1
            bA = (a - i2)%2
            bB = (b - i2)%2
            iC = 0
            for i in range(iD+1):
                iA = int(sA[i])
                iB = int(sB[i])
                if i == 0 and calcFD(a-i2,bA) ^ calcFD(b-i2,bB):
                    iC += 1
                elif (iA and bA) ^ (iB and bB):
                    iC += 2**i
        return iC
    else:
        return a
def lenbin(X):
    return len(bin(X)) - 3
iA = lenbin(A)
iB = lenbin(B)
if iA == iB:
    print(fxorA2B(A,B,iA))
else:
    if iA == 0 :
        print(fxorA2B(2**iB,B,iB))
    else:
        print(fxorA2B(A,(2**(iA+1) - 1),iA)^fxorA2B(2**iB,B,iB))


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define int long long int
struct item{
    int wt;
    int val;
};
int solve(vector<item> a,int n,int W)
{
    int dp[n+1][W+1];
    for(int w=0;w<=W;w++)dp[1][w]=0;
    dp[1][a[1].wt]=a[1].val;
    for(int i=2;i<=n;i++)
    {
        for(int w=0;w<=W;w++)
        {
            dp[i][w]=dp[i-1][w];
            if(a[i].wt>w)
                continue;
            dp[i][w]=max(dp[i][w],a[i].val+dp[i-1][w-a[i].wt]);
        }
    }
    return *max_element(dp[n],dp[n]+1+W);
}
main()
{
    int n,W;
    cin>>n>>W;
    vector<item> a(n+1);
    for(int i=1;i<=n;i++){cin>>a[i].wt>>a[i].val;}
    cout<<solve(a,n,W);
}


Measured memory_bytes: 81664
import sys
input = sys.stdin.readline

N, M, L = map(int, input().split())

distance = [[float('inf')]*N for _ in range(N)]
for i in range(N):
    distance[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    distance[a-1][b-1] = c
    distance[b-1][a-1] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            distance[i][j] = min(distance[i][j], distance[i][k]+distance[k][j])

for i in range(N):
    for j in range(N):
        if i == j:
            distance[i][j] = 0
        elif distance[i][j] <= L:
            distance[i][j] = 1
        else:
            distance[i][j] = float('inf')

for k in range(N):
    for i in range(N):
        for j in range(N):
            distance[i][j] = min(distance[i][j], distance[i][k]+distance[k][j])

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    ans = distance[s-1][t-1]-1
    if ans is float('inf'):
        ans = -1
    print(ans)


Measured memory_bytes: 128524
#include<bits/stdc++.h>
using namespace std;
static const long long MOD=1000000007LL;
int n;
char s[100005];
uint64_t dp[100005][13];

uint64_t solve(){
    int i,j,ki;
    uint64_t res=0;
    scanf("%s",s);
    n=strlen(s);
    dp[0][0]=1;
    for(i=0;i<n;i++){
        int c;
        if(s[i]=='?')c=-1;
        else c=s[i]-'0';
        for(j=0;j<10;j++){
            if(c!=-1&&c!=j)continue;
            for(ki=0;ki<13;ki++){
                dp[i+1][(ki*10+j)%13]+=dp[i][ki];

            }
        }
        for(j=0;j<13;j++)dp[i+1][j]%=MOD;
    }
    res=dp[n][5];
    printf("%llu\n",res);
    return 0;
}

int main(){
    solve();
}

Measured memory_bytes: 10496