akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000007;
#define PI 3.1415926535
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
bool seen[100000];
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする
 
    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}
 
//dpTable
ll dp[55][2];
int main(){
    int N,P;
    cin >> N >> P;
    vector<int> A(N);
    rep(i,N) cin >> A.at(i);
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        if (A.at(i - 1) % 2 == 0) {
            dp[i][0] = dp[i - 1][0] * 2;
            dp[i][1] = dp[i - 1][1] * 2;
        }
        else {
            dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
            dp[i][1] = dp[i - 1][0] + dp[i - 1][1];
        }
    }
    cout << dp[N][P] << endl;
    return 0;
}

Measured memory_bytes: 3612
#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 <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;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

ll N, M;
vector<ll> x(100010);
vector<ll> y(100010);

int main(){
  cin >> N >> M;
  rep(i, N) cin >> x[i];
  rep(i, M) cin >> y[i];
  vector<ll> X(N-1), Y(M-1);
  rep(i, N-1) X[i] = x[i+1] - x[i];
  rep(i, M-1) Y[i] = y[i+1] - y[i];

  rep(i, N-1){
    X[i] %= MOD;
    X[i] *= (i+1) * (N-i-1) % MOD;
    X[i] %= MOD;
  }
  rep(i, M-1) Y[i] %= MOD;
  ll W = 0;
  rep(i, N-1){
    W += X[i];
    W %= MOD;
  }

  ll ans = 0;
  rep(i, M-1){
    ans += Y[i] * W % MOD * (i+1) % MOD * (M-1-i) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;

}


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

int main() {
	int N, a, b = 0, c = 0;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> a;
		if (0 == a % 4) ++b;
		else if (0 == a % 2) ++c;
	}
	if (N / 2 - b > c / 2) cout << "No";
	else cout << "Yes";
}

Measured memory_bytes: 256
import collections
N,P = list(map(int,input().split()))
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
a = sorted(collections.Counter(prime_factorize(P)).most_common(),key=lambda x: -x[0])
tmp = 1
for i in range(len(a)):
    if a[i][1] >= N:
        tmp *= a[i][0]**(a[i][1]//N)
print(tmp)

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

int n;
map<string, int> cnt;

int main(){
    ios_base::sync_with_stdio(0);
    //freopen("input.txt","r",stdin);

    cin>>n;
    int theMax = 0;
    for(int i=0;i<n;i++){
        string s;cin>>s;
        cnt[s]++;
        theMax = max(theMax,cnt[s]);
    }
    vector<string> res;
    for(auto const& x : cnt)
    {
        if(x.second==theMax)res.push_back(x.first);
    }
    sort(res.begin(),res.end());
    for(string s : res)cout<<s<<"\n";
}


Measured memory_bytes: 26096
from itertools import permutations
from heapq import heappop,heappush
def dijkstra(n,s,adj):
	dis = [float("inf") for i in range(n+1)]
	dis[s],q = 0,[[0,s]]
	while q:
		num2,num = heappop(q)
		for i,j in adj[num]:
			if dis[i]>num2+j:
				dis[i] = num2+j
				heappush(q,[dis[i],i])
	return dis
n,m,r = (int(i) for i in input().split())
rlist = [int(i) for i in input().split()]
x = [[int(i) for i in input().split()] for i in range(m)]
road,y,ans = [[] for i in range(n+1)],[[] for i in range(n+1)],float("inf")
for i,j,k in x:
	road[i].append([j,k])
	road[j].append([i,k])
for i in rlist: y[i] = dijkstra(n,i,road)
for i in permutations(rlist,r):
	num = 0
	for j in range(r-1): num+=y[i[j]][i[j+1]]
	ans = min(num,ans)
print(ans)

Measured memory_bytes: 10324
#include "bits/stdc++.h"
using namespace std;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
using pii=pair<int, int>;


string Cipher(string& s, int& idx);
string String(string& s, int& idx);
char Letter(string& s, int& idx);

string Cipher(string& s, int& idx) {
	string ret;
	while (1) {
		if (idx == s.size() || s[idx] == ']') {
			break;
		}
		ret += String(s, idx);
	}
 	return ret;
}
string String(string& s, int& idx) {
	if (s[idx] == '[') {
		idx++;
		string tmp = Cipher(s, idx);
		idx++;
		reverse(tmp.begin(), tmp.end());
		return tmp;
	}
	else {
		return string(1, Letter(s, idx));
	}
}

char Letter(string& s, int& idx) {
	int d = 0;
	while (1) {
		if (s[idx] == '+') {
			d++;
			idx++;
		}
		else if (s[idx] == '-') {
			d--;
			idx++;
		}
		else {
			int x = s[idx] - 'A';
			if (s[idx] == '?') {
				x = 'A';
			}
			else {
				x = (x + d % 26 + 26) % 26 + 'A';
			}
			idx++;
			return x;
		}
	}
}

string solve(string s) {
	int i = 0;
	return Cipher(s, i);
}
signed main() {
	while (1) {
		string s;
		cin >> s;
		if (s == ".") break;
		cout << solve(s) << endl;
	}
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; ll k; 
    cin >> n >> k;
    vector<ll> a(n);
    vector<ll> f(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];
    sort(RALL(f));
    sort(RALL(a));
    ll ng = -1;
    ll ok = f[0]*a[0];
    reverse(ALL(f));
    while(ok - ng > 1){
        ll mid = (ok + ng) / 2;
        ll goal = 0;
        rep(i,n){
            goal += max(0LL, a[i] - mid / f[i]);
        }
        if(goal <= k) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

struct UFTree {
    static const int MAX_N = 1e6;
    int p[MAX_N], r[MAX_N];

    UFTree(int n) : p(), r() {
        for(int i = 0; i < n; ++i) {
            p[i] = i;
            r[i] = 0;
        }
    }

    int root(int x) {
        return p[x] == x ? x : (p[x] = root(p[x]));
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y) return;

        if(r[x] < r[y]) {
            p[x] = y;
        } else {
            p[y] = x;
            if(r[x] == r[y]) r[x]++;
        }
    }
};

int n, m;
string s;

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

    V<P<int, Pii>> edges(m);
    REP(i, m) {
        int x, y, c;
        cin >> x >> y >> c;
        edges[i] = {c, {x, y}};
    }

    sort(ALL(edges));

    UFTree t = UFTree(n);

    int res = 0;
    FOR(i, edges) {
        int c = i->first;
        int x = i->second.first, y = i->second.second;
        if (t.same(x, y)) continue;
        t.unite(x, y);
        res += c;
    }
    std::cout << res << '\n';

    return 0;
}



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

using ll = long long;
const ll inf = 1e18;
const int  N = 1e5 + 10;

ll n, W;
int main(int argc, char const *argv[]){
	
	cin >> n >> W;
	std::vector<ll> dp(W + 1, 0);
	for (int i = 0; i < n; ++i){
		ll weight, value;
		cin >> weight >> value;
		for (int i = W; i >= weight; --i){
			dp[i] = max(dp[i], dp[i - weight] + value);
		}

	}
	ll mx = 0;
	for (int i = 0; i <= W; ++i){
		mx = max(dp[i], mx);
	}
	cout << mx;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	for (int i = 0; i + 2 < N; ++i) {
		if (a[i] == b[i] && a[i+1] == b[i+1] && a[i+2] == b[i+2]) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";

	return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#define MAX 1000000000000000000LL

using namespace std;
int main(){
    string  a,b;
    cin>>a>>b;
    if(a.length()==b.length()){
        for(int i=0; i<a.length(); i++){
            cout<<a[i]<<b[i];
        }
        cout<<endl;
    }
    else {
        for(int i=0; i<a.length()-1; i++){
            cout<<a[i]<<b[i];
        }
        cout<<a[a.length()-1]<<endl;
    }
    return 0;
}


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

int main(){
    //input
    long long N, W;
    cin >> N >> W;
    long long i, j;
    long long v[N+1], w[N+1];
    for(i = 1; i <= N; i++){
        cin >> v[i] >> w[i];
    }

    //calc
    long long dp[N+1][W+1];
    for(i = 0; i <= N; i++){
        dp[i][0] = 0;
    }
    for(j = 0; j <= W; j++){
        dp[0][j] = 0;
    }
    for(i = 1; i <= N; i++){
        for(j = 1; j <= W; j++){
            if(j < w[i]){
                dp[i][j] = dp[i-1][j];
            }else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-w[i]] + v[i]);
            }
        }
    }

    //answer
    cout << dp[N][W] << endl;
    return 0;
}


Measured memory_bytes: 10984
#include<stdio.h>


float round(float x){
	if(x >= 0){
		x = (int)(x*1000.0 + 0.5);
		x = x/1000.0;
	}else if(x < 0){
		x = (int)(x*1000.0 - 0.5);
		x = x/1000.0;
	}
	return x;
}


int main(){
	float a, b, c, d, e, f;

	while(scanf("%f %f %f %f %f %f", &a, &b, &c, &d, &e, &f) != EOF){
		float r = b*d - a*e;
		float x = (b*f - c*e)/r;
		float y = (c*d - a*f)/r;
		//printf("%f %f\n", x, y);
		printf("%0.3f %0.3f\n", round(x), round(y));
	}

	return 0;
}

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

void solve()
{
    int A[3][3];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> A[i][j];
        }
    }
    int c, k;
    cin >> c;
    for (int i = 0; i < c; i++)
    {
        cin >> k;
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (A[i][j] == k)
                {
                    A[i][j] = 0;
                }
            }
        }
    }
    if (A[0][0] == A[0][1] && A[0][2] == A[0][0])
        cout << "Yes";
    else if (A[1][0] == A[1][1] && A[1][2] == A[1][0])
        cout << "Yes";
    else if (A[2][0] == A[2][1] && A[2][2] == A[2][0])
        cout << "Yes";
    else if ((A[0][0] == A[1][0] && A[2][0] == A[1][0]))
        cout << "Yes";
    else if ((A[0][1] == A[1][1] && A[2][1] == A[1][1]))
        cout << "Yes";
    else if ((A[0][2] == A[1][2] && A[2][2] == A[1][2]))
        cout << "Yes";
    else if (A[0][0] == A[1][1] && A[0][0] == A[2][2])
        cout << "Yes";
    else if (A[0][2] == A[1][1] && A[1][1] == A[2][0])
        cout << "Yes";
    else
        cout << "No";
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int gcd(int a,int b){
  if(b == 0) return a;
  return gcd(b,a%b);
}

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(c%gcd(a,b) == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/aising2019/tasks/aising2019_b
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};


int main(){
    int N,A,B;
    cin>>N>>A>>B;
    int cnt[3]={};
    for(int i:range(N)){
        int p;cin>>p;
        if(p<=A){
            cnt[0]++;
        }
        else if(p<=B){
            cnt[1]++;
        }
        else{
            cnt[2]++;
        }
    }
        cout<<*min_element(cnt,cnt+3)<<endl;

    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
sys.setrecursionlimit(10**7)
inf=float("inf")

def BFS(x,y):
    color=[["white" for _ in range(w+2)] for _ in range(h+2)]
    D=[[inf for _ in range(w+2)] for _ in range(h+2)]

    color[x][y]="gray"
    D[x][y]=0
    queue=deque([[x,y]])
    while len(queue)!=0:
        a,b=queue.popleft()
        for c,d in ((1,0),(0,1),(-1,0),(0,-1)):
            X,Y=a+c,b+d
            if S[X][Y]=="." and color[X][Y]=="white":
                color[X][Y]="gray"
                D[X][Y]=D[a][b]+1
                queue.append([X,Y])
        color[a][b]="black"

    return D


h,w=map(int,input().split())
S=[["#"]+list(input())+["#"] for _ in range(h)]
S.insert(0,["#"]*(w+2))
S.append(["#"]*(w+2))
D=BFS(1,1)

black=0
for i in range(1,h+1):
    black +=S[i][1:w+1].count("#")
print(h*w-(black+D[h][w]+1) if D[h][w]!=inf else -1)

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

anss = [0] * (N+1)
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            a = x*x + y*y + z*z + x*y + y*z + z*x
            if a <= N:
                anss[a] += 1

print('\n'.join(map(str, anss[1:])))


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; cin >> n;
	int mx = 0;
	while (mx * (mx + 1) / 2 < n) mx++;
	int ex = mx * (mx + 1) / 2 - n;
	rep(i, 1, mx + 1) if (i != ex) cout << i << endl;
}


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

using namespace std;

int n, x, d, ans;

int main() {
    scanf("%d%d", &n, &x); ans = 1;
    for (int i = 1; i <= n; i++) {
        int l; scanf("%d", &l);
        if ((d += l) <= x) ans++;
    }
    printf("%d\n", ans);
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli calc(lli now){
	if(now==1)return 1;
	else return 1+2*calc(now/2);
}

signed main(){

	lli h;
	cin>>h;

	cout<<calc(h)<<endl;

	return 0;
}

Measured memory_bytes: 256
import math
import copy
import fractions
import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, m = map(int, input().split())

broken = getSomeInputInt(m)

mod = 1000000007

dp = np.zeros(n+1)
dp[0] = 1

brokenArray = np.ones(n+1)
for i in range(len(broken)):
    brokenArray[broken[i]] = 0


for i in range(n+1):
    if brokenArray[i] == 1 and i+1 < n+1:
        dp[i+1] += dp[i]
        dp[i+1] %= mod

    if brokenArray[i] == 1 and i+2 < n+1:
        dp[i + 2] += dp[i]
        dp[i + 2] %= mod

print(int(dp[n]))




Measured memory_bytes: 18156
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

ll dp[100005][13];

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

  dp[0][0] = 1;


  
  for(int i = 0; i < s.size(); i++) {
    for(int j = 0; j < 13; j++) {
      if(s[i] == '?') {
      for(int k = 0; k < 10; k++) {

       dp[i+1][(j * 10 + k) % 13] += dp[i][j];
	dp[i+1][(j * 10 + k) % 13] %= mod;
      }
      }
      else {
	int n = s[i] - '0';
	dp[i+1][(j * 10 + n) % 13] += dp[i][j];
	dp[i+1][(j * 10 + n) % 13] %= mod;
      }
    }
  }

  /*  for(int j = 0; j < s.size(); j++) {
  for(int i = 0; i < 13; i++) {
    cout <<"dp["<<j<<"]["<<i<<"] = "<< dp[j][i] << endl;
  }
  }*/

  cout << dp[s.size()][5] % mod << endl;
}

  

  
  


Measured memory_bytes: 10624
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>

using namespace std;
// for loop
#define F(i, L, R) for(int i = L; i < R; i++)
#define FE(i, L, R) for(int i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(int i = L; i > R; i--)
#define FRE(i, L, R) for(int i = L; i >= R; i--)

// data types
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

int main() {
    string str;
    int n;
    cin >> str;
    cin >> n;
    string op;
    int a,b;
    string p;
    F(i, 0, n){
        cin >> op;
        cin >> a >> b;
        if(op == "print"){
            cout << str.substr(a, b-a+1) << endl;
            continue;
        }
        if(op == "reverse"){
            reverse(str.begin()+a, str.begin()+b+1);
            continue;
        }
        if(op == "replace"){
            cin >> p;
            str = str.replace(a, b-a+1, p);
            continue;
        }
    }
}



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

int main() {
    int N; cin >> N;
    vector<vector<pair<int, bool>>> T(N);
    for(int i = 0; i < N; ++i) {
        int A; cin >> A;
        while(A--) {
            int x, y;
            cin >> x >> y;
            T[i].emplace_back(x - 1, y);
        }
    }
    auto rec = [&](auto &&rec, int d, int mask, int hmask, int umask) -> int {
        if(d == N) {
            for(int i = 0; i < N; ++i) {
                if((hmask & (1 << i)) && !(mask & (1 << i))) return 0;
                if((umask & (1 << i)) && (mask & (1 << i))) return 0;
            }
            return __builtin_popcount(mask);
        }
        int res = rec(rec, d + 1, mask, hmask, umask);
        mask |= (1 << d);
        for(auto &t : T[d]) {
            int m = t.first;
            if(t.second) hmask |= (1 << m);
            else umask |= (1 << m);
        }
        return max(res, rec(rec, d + 1, mask, hmask, umask));
    };
    cout << rec(rec, 0, 0, 0, 0) << '\n';
    return 0;
}


Measured memory_bytes: 256
production = True

import sys, math, collections

def input(input_format = 0, multi = 0):

    if multi > 0: return [input(input_format) for i in range(multi)]
    else:
        next_line = sys.stdin.readline()[:-1]

        if input_format >= 10:
            use_list = False
            input_format = int(str(input_format)[-1])
        else: use_list = True

        if input_format == 0: formatted_input = [next_line]
        elif input_format == 1: formatted_input = list(map(int, next_line.split()))
        elif input_format == 2: formatted_input = list(map(float, next_line.split()))
        elif input_format == 3: formatted_input = list(next_line)
        elif input_format == 4: formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
        elif input_format == 5: formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
        elif input_format == 6: formatted_input = next_line.split()
        else: formatted_input = [next_line]

        return formatted_input if use_list else formatted_input[0]


def out(output_line, output_format = 0, newline = True):

    formatted_output = ""

    if output_format == 0: formatted_output = str(output_line)
    elif output_format == 1: formatted_output = " ".join(map(str, output_line))
    elif output_format == 2: formatted_output = "\n".join(map(str, output_line))

    print(formatted_output, end = "\n" if newline else "")


def log(*args):
    if not production:
        print("$$$", end = "")
        print(*args)

enum = enumerate

#
#   >>>>>>>>>>>>>>> START OF SOLUTION <<<<<<<<<<<<<<
#


def solve():

    n = input(11)
    a = n + n ** 2 + n ** 3

    out(a)

    return


#for i in range(input(11)): solve()
solve()

#
#   >>>>>>>>>>>>>>>> END OF SOLUTION <<<<<<<<<<<<<<<
#


Measured memory_bytes: 65388
#include<cstdio> 
typedef long long ll;
const ll mo=1000000007;
const int N=100010;
ll f[N];
int i,n,m;
int main(){
	scanf("%d%d",&n,&m);
	if(n<m){
		int t=n;
		n=m;
		m=t;
	}
	if(n-m>1)return puts("0"),0;
	f[0]=1;
	for(i=1;i<=n;++i)f[i]=f[i-1]*i%mo;
	printf("%lld\n",f[n]*f[m]*(n==m?2ll:1ll)%mo);
	return 0;
}

Measured memory_bytes: 896
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
h = LIST()

print(len([x for x in h if x >= K]))


Measured memory_bytes: 12672
#include "bits/stdc++.h"
using namespace std;

#define OUT(x)  cerr << #x << " = " << x << endl;
#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define piii    pair<int, pair<int, int>>

int main() {
        string s;
        cin >> s;
        vector<int> cnt(s.size(), 0);
        for (int i = 0; i < s.size(); i ++) {
                cnt[s[i] - 'a'] ++;
        }
        int ans;
        bool found = false;
        for (int i = 0; i < 26; i ++) {
                if (!cnt[i]) { 
                        ans = i;
                        found = true;
                        break;
                }
        }
        char res = 'a' + ans;
        if (!found) cout << "None" << endl;
        else cout << res << endl;
        return 0;
}


Measured memory_bytes: 896
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():

    A,B,C,D=map(int,input().split())
    val=len(set(range(A,B+1)) & set(range(C,D+1)))
    print(val-1 if val>0 else 0)

resolve()

Measured memory_bytes: 38384
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
  int a[20];
  int b[20];
  int N,M,C;
  cin >>N>>M>>C;
  REP(i,M){
    cin>>b[i];
  }
  int ans=0;
  REP(i,N){
    REP(j,M){
      cin>>a[j];
    }
    int v=C;
    REP(j,M){
      v += a[j]*b[j];
    }
    if(v>0)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
$s=gets.chomp

# 再帰解法
def solve(decided, left, i)
    if i==$s.length
        return decided + left
    end
    # +を手前に入れる
    ret1 = solve(decided+left, $s[i].to_i, i+1)
    # 入れない
    ret2 = solve(decided, left*10 + $s[i].to_i, i+1)
    return ret1 + ret2
end

# C++の時は一番最初に+を入れるか入れないかを処理していたので最後に2で割りました。
# こっちはi=1から呼ぶことでそれを回避します。
puts solve(0, $s[0].to_i, 1)

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

int po3(int e){
    int ret = 1;
    for(int i = 0; i<e; i++){
        ret *= 3;
    }

    return ret;
}

int conjug(int x){
    int mult = 1;
    int ret = 0;

    while(x){
        int t = x % 3;
        if(t == 1) ret += mult * 2;
        if(t == 2) ret += mult;

        x /= 3;
        mult *= 3;
    }

    return ret;
}

struct EndingSet{
    int ending;
    vector<int> nums;
};

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

    string T;
    cin >> T;

    int e = po3((n + 1) / 2);
    int b = po3(n) / e;

    EndingSet a[e];
    int con[b*e];
    for(int i = 0; i<b*e; i++){
        con[i] = conjug(i);
    }
    for(int i = 0; i<e; i++){
        a[i].ending = i;
        for(int j = 0; j<b; j++){
            a[i].nums.push_back(i + j*e);
        }
    }

    int beg[b], ids[b*e], ans[b*e];
    for(int i = 0; i<b; i++){
        beg[i] = i;
    }

    for(int i = 0; i<b*e; i++){
        ids[i] = i / e;
    }

    for(int i = 0; i<T.size(); i++){
        if(T[i] == 'S'){
            for(int j = 0; j<e; j++){
                a[j].ending = con[a[j].ending];
            }

            for(int j = 0; j<b; j++){
                beg[j] = con[beg[j]];
            }
        }

        if(T[i] == 'R'){
            int pos;
            for(int j = 0; j<e; j++){
                if(a[j].ending == e - 1) pos = j;
            }

            int inv[b];
            for(int i = 0; i<b; i++){
                inv[beg[i]] = i;
            }

            for(int x: a[pos].nums){
                if(beg[ids[x]] < b - 1) ids[x] = inv[beg[ids[x]] + 1];
                else ids[x] = inv[0];
            }

            for(int j = 0; j<e; j++){
                if(a[j].ending < e - 1) a[j].ending++;
                else a[j].ending = 0;
            }
        }


    }

    int inv[b*e];

        for(int j = 0; j<e; j++){
            int x = a[j].ending;

            for(int y: a[j].nums){
                ans[x + beg[ids[y]] * e] = y;
                inv[y] = x + beg[ids[y]] * e;
            }
        }

        for(int j = 0; j<b*e; j++){
            cout << inv[j] << " ";
        }

        cout << endl;

    /*
    for(int i = 0; i<e; i++){
        int x = a[i].ending;

        for(int y: a[i].nums){
            ans[y] = x;
        }
    }

    for(int i = 0; i<b*e; i++){
        ans[i] += beg[ids[i]] * e;
    }

    for(int i = 0; i<b*e; i++){
        cout << ans[i] << " ";
    }
    */


}


Measured memory_bytes: 15420
#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() {
    int N;
    cin >> N;
    string S;
    vector<int> cnt(4,0);
    vector<string> ans = {"AC", "WA", "TLE", "RE"};
    rep(i,N) {
        cin >> S;
        rep(j,4) {
            if (S == ans.at(j)) ++cnt.at(j);
        }
    }
    rep(i,4) {
        cout << ans.at(i) << " " << "x" << " " << cnt.at(i) << endl;
    }
}


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

using namespace std;
typedef long long ll;

int dfs(int x, vector<vector<int>> &g, vector<int> &vis) {
    int c = 1;
    for (int i : g[x]) {
        if (!vis[i]) {
            vis[i] = 1;
            c += dfs(i, g, vis);
        }
    }
    return c;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m; cin >> n >> m;
    vector<vector<int>> g(n + 1);
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int> vis(n + 1);
    int r = 0;
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            vis[i] = 1;
            r = max(r, dfs(i, g, vis));
        }
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 24288
#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define uii             unordered_map<int,int>
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
void S_K_S()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int32_t main()
{
	S_K_S();
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	int dp[n];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++){
		int x=abs(a[i]-a[i-1]);
		int y=abs(a[i]-a[i-2]);
		// cout<<dp[i-1]+x<<" "<<dp[i-2]+y<<endl; 
		dp[i]=min(dp[i-1]+x,dp[i-2]+y);
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 5028
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=2e5;
const int INF=1e9;
vector<int> g[size];
int calc[size]={};int ans[size]={};
int sum=0;
void dfs(int n,int v){
	sum+=calc[v];ans[v]+=sum;
	for(int u:g[v]){
		if(u==n) continue;
		dfs(v,u);
	}sum-=calc[v];
	return;
}
int main(){
	int N,Q;cin>>N>>Q;
	int a,b;
	rep(i,0,N-1){
		cin>>a>>b;a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}int p,x;
	rep(i,0,Q){ cin>>p>>x;calc[p-1]+=x; }
	dfs(-1,0);
	print(ans,N);
}

Measured memory_bytes: 24064
#include<cstdio>
using namespace std;
int main()
{
	int a,b,c,temp;
	scanf("%d %d %d",&a,&b,&c);
	temp = c - a;
	if(temp >= 0)
	{
		if(temp < b)
			printf("YES\n");
			else
				printf("NO\n");
	}
	else
		printf("NO\n");
		return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<map>
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<time.h>
#include<limits.h>
#include<unordered_map>
#include<set>
#include<queue>
#include <iomanip>
using namespace std;
#define inf LLONG_MAX
const int N = 2e5 + 7;
#define int long long
void solve() {
    int a; cin >> a;
    cout << a + pow(a, 2) + pow(a,3);
}

int32_t main() {
        solve();
    
}


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

int main()
{
  string s;
  cin >> s;
  if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323;
typedef long long ll;
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    //cout<<sqrt(a)<<" "<<sqrt(b)<<" "<<sqrt(c)<<endl;
    //cout<<sqrt(a)+sqrt(b)<< " "<<sqrt(c)<<endl;
    if(a+b>c) {
        printf("No");
    }
    else {
        if((4*a*b)<(a*a+b*b+c*c-2*a*c+2*a*b-2*b*c)) printf("Yes");
        else printf("No");
    }

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

void sub_main(istream &cin) {
    string s;
    cin >> s;
    if(!cin) return;
    int l, r;
    l = 0; r = s.size() - 1;
    ll ans = 0;
    while(l < r){
        if(s[l] == s[r]){
            l++; r--;
        }
        else if(s[l] == 'x'){
            l++; ans++;
        }
        else if(s[r] == 'x'){
            r--; ans++;
        }
        else { cout << -1 << endl; return;}
    }
    
    cout << ans << endl;

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test_3.txt";
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#\n";
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;
const long INF = 2000000000;

int main() {
  int n,a[300000];
  cin >> n;
  int ma = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    ma = max(ma, a[i]);
  }

  bool flag = 0;
  int cnt = 0;
  for(int i = 0; i < n; i++)
    if(a[i] == ma) cnt++;

  if(cnt > 1) flag = 1;
  
  int second = 0;
  for(int i = 0; i < n; i++) 
    if(second < a[i] & a[i] < ma) second = a[i];
  
  for(int i = 0; i < n; i++) {
    if(a[i] != ma || flag) 
      cout << ma << endl;
    else 
      cout << second << endl;
  }
}

Measured memory_bytes: 4420
#include<stdio.h>
#define N 2000001
void CountingSort(int);
int A[N], B[N], n;

void CountingSort(int k){
  int C[k + 1], i, j;

  for(i=0;i<=k;i++){
    C[i] = 0;
  }
  
  /* C[i] に i の出現数を記録する */
  for(j=1;j<=n;j++){
    C[A[j]]++;
  }

  /* C[i] に i 以下の数の出現数を記録する*/
  for(i=1;i<=k;i++){
    C[i] = C[i] + C[i-1];
  }
  
  for(j=n;j>=1;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
}


int main(){
  int i, k = 0;

  scanf("%d", &n);
  for(i = 1; i <= n; i++){
    scanf("%d", &A[i]);
    if(k < A[i]) k = A[i];
  }
  
  CountingSort(k + 1);

  for(i = 1; i <= n; i++){
    printf("%d", B[i]);
    if(i < n)printf(" ");
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 17480
#define _GLIBCXX_DEBUG
#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 = 1; i < (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

bool is_prime(ll num){
    if(num < 2) return false;
    else if(num == 2) return true;
    else if(num%2 == 0) return false;

    for(ll i = 3; i <= (ll)sqrt(num); i += 2){
        if(num % i == 0) return false;
    }

    return true;
}

int main() {
    int x; cin >> x;
    for(int i = x;;i++){
        if(is_prime(i)){
            dunk(i);
            return 0;
        }
    }
    return 0;
}

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

int main(void)
{
	bool judge = true;
	long long int n, h[100010], max = 0;
	cin >> n;
	for (int i = 0; i < n; i++) { cin >> h[i]; }
	max = h[0];
	for (int i = 1; i < n; i++)
	{
		if (max - 1 > h[i]){judge = false; break;}
		else if (h[i] > max) { max = h[i]; }
	}
	if (judge) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
string solve(string a, string b) {
    
    int n=a.length(),m=b.length();
    int dp[n+1][m+1];
    for(int i=0;i<=n;i++)
    {
        dp[i][0]=0;
    }
    for(int i=0;i<=m;i++)
    {
        dp[0][i]=0;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i-1]==b[j-1])
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else
            {
                dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
            }
        }
    }
    
   /* for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            cout<<dp[i][j]<<" ";

        }
        cout<<endl;
    }*/
    string answer="";
    ll i=n,j=m;
    while(i>0&&j>0)
    {
        if(a[i-1]==b[j-1])
        {
            answer.pb(a[i-1]);
            i--,j--;
        }
        else if(dp[i][j-1]>dp[i-1][j])
        {
            j--;
        }
        else
        {
            i--;
        }
    }
   // cerr<<"answer "<<answer<<endl;
    reverse(answer.begin(),answer.end());
    return answer;
}

int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
        

fast();
//ll t;cin>>t;while(t--)
{
    string s,t;
    cin>>s>>t;
    cout<<solve(s,t)<<endl;
}
return 0;
}

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


using namespace std;
using ll = long long;

const int INF = 1e9;
int N, A, B, C; 
vector<int> v;

int dfs (int a, int b, int c, int i) {
    if (i == N)
        return (min({a, b, c}) > 0 ? abs(A-a) + abs(B-b) + abs(C-c) - 30: INF);

    int res_1 = dfs(a, b, c, i+1);
    int res_2 = dfs(a+v[i], b , c, i+1) + 10;
    int res_3 = dfs(a, b+v[i], c, i+1) + 10;
    int res_4 = dfs(a, b, c+v[i], i+1) + 10;

    return min({res_1, res_2, res_3, res_4});
}

int main () {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    cin >> N >> A >> B >> C;
    v.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> v[i];
    
    cout << dfs(0, 0, 0, 0) << '\n';


    return 0;
}





Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e9
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

int main(){

    ll n,t,a;
    cin >> n >> t >> a;

    double mini = 1e18;
    ll ans;
    REP(i,n){
        ll h;
        cin >> h;
        double tmp = t-0.006*h;
        if(abs(tmp-a) < mini){
            ans = i+1;
            mini = abs(tmp-a);
        }
    }
    cout << ans << endl;
  
    return 0;
}

Measured memory_bytes: 384
mod = 10**9+7

N = int(input())
A = list(map(int, input().split()))

s = 0
for i in range(N):
    s += A[i]
ans = 0
for i in range(N):
    ans += (A[i]*(s-A[i]))%mod
    s -= A[i]
    ans = ans % mod

print(ans)



Measured memory_bytes: 94196
import java.util.Map.Entry;
import java.lang.reflect.Method;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.ArrayList;

//import org.w3c.dom.css.Counter;


public class Main {
	public static void main(String[] args)throws Exception{
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
        String T = sc.next();
        String hoge;
        int ans =999999;
		for(int i=0;i<S.length()-T.length()+1;i++){
			hoge=S.substring(i,i+T.length());
			int tmp=0;
			for(int i2=0;i2<T.length();i2++){
				if(T.charAt(i2)!=hoge.charAt(i2)){
                    tmp++;
                }
			}
			if(ans>tmp){ans=tmp;}
		}
        System.out.println(ans);
    }

}

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

const int MAX_N =510000;

int par[MAX_N];
int depth[MAX_N];
int pos[MAX_N]; //親との差

void init(int n){
    for(int i=0; i<n; i++){
        par[i]=i;
        depth[i]=0;
//        pos[i]=0;
    }
}

int find(int x){
    if(par[x]==x) return x;
    int r = find(par[x]);
    pos[x] +=pos[par[x]];
    return par[x]=r;
}

int weight (int x){
    find(x);
    return pos[x];
}

bool unite(int x, int y, int d){
    d = d + weight(y) - weight(x);
    x = find(x); y = find(y);
    if(x==y){
        if(d==0) return true;
        else return false;
    }
    if(depth[x]<depth[y]) {par[x]=y; pos[x]=d; return true;}
    if(depth[x]>depth[y]) {par[y]=x; pos[y]=-d; return true;}
    par[y]=x; pos[y]=-d;
    depth[x]++;
    return true;
}

bool same(int x,int y){
    return find(x)==find(y);
}

int main(){
    int N; cin >> N;
    int M; cin >> M;
    bool flag=true;
    init(N);
    for(int i=0; i<M; i++){
        int l, r, d; cin >> l >> r >> d; l--; r--;
        if(!unite(l,r,d)){
            flag = false;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 3072
n=int(input())
a=[int(i) for i in input().split()]
a.append(0)
x,y=1000,0
for i in range(n):
    if a[i]>=a[i+1]:
        x+=y*a[i]
        y=0
    else:
        y+=x//a[i]
        x=x%a[i]
print(x)

Measured memory_bytes: 61732
N = int(input())
S = []
for i in range(N):
    S.append(input())



www = "YYY"
for i in range(N-1):
    if S[i][-1] != S[i+1][0]:
        www = "fuck"

qqq = "ZZZ"
S.sort()
for i in range(N-1):
    if S[i] == S[i+1]:
        qqq = "bich"

if www == "YYY" and qqq == "ZZZ":
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
;; C - Traveling Salesman around Lake

(defun solve (k n a)
  "n軒すべての家を訪ねるための最短移動距離.
   円周長k. 基準点からの距離a[i]. aは昇順に整列済"
  (let* ((pre (- (car (last a)) k)) ; a[-1] - k
         (maxsep (reduce #'max (mapcar #'- a (cons pre a)))))
    (- k maxsep)))

(defun main ()
  (let* ((k (read))
         (n (read))
         (a (loop repeat n collect (read))))
    (princ (solve k n a))))

(main)


Measured memory_bytes: 66152
N, L = list(map(int, input().split()))
taste = [L+i-1 for i in range(1, N+1)]
abs_taste = list(map(lambda x: abs(x), taste))
argmin = abs_taste.index(min(abs_taste))
cnt = 0
x = sum([taste[n] for n in range(N) if n != argmin])
print(x)

Measured memory_bytes: 3060