akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> s(n), t(m);
    for(int i=0;i<n;++i){
        cin >> s[i];
    }
    for(int i=0;i<m;++i){
        cin >> t[i];
    }

    vector<vector<ll>> dp(n+1, vector<ll>(m+1, 1));
    for(int i=1;i<=n;++i) {
        for(int j=1;j<=m;++j) {
            if(s[i-1] == t[j-1]) {
                dp[i][j] =  (dp[i-1][j] + dp[i][j-1] + MOD) % MOD;
            } else {
                dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + MOD) % MOD;
            }
        }
    }

    cout << dp[n][m] << endl;
}


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

int main()
{
    ll n;
    cin >> n;
    vector<ll> va(n), vb(n), vc(n);
    for (ll i = 0; (i < n); ++i) {
        cin >> va[i] >> vb[i] >> vc[i];
    }
    vector<ll> dpa(n, numeric_limits<ll>::min()),
               dpb(n, numeric_limits<ll>::min()),
               dpc(n, numeric_limits<ll>::min());
    dpa[0] = va[0];
    dpb[0] = vb[0];
    dpc[0] = vc[0];
    for (ll i = 1; (i < n); ++i) {
        dpa[i] = va[i] + max(dpb[i-1], dpc[i-1]);
        dpb[i] = vb[i] + max(dpa[i-1], dpc[i-1]);
        dpc[i] = vc[i] + max(dpa[i-1], dpb[i-1]);
    }
    ll result = max(dpa[n-1], dpb[n-1]);
    result = max(result, dpc[n-1]);
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 4992
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        for(int i=1;;i++){
            int a = sc.nextInt();
            if(a == 0) break;
            System.out.printf("Case %d: %d\n", i, a);
            }
    }
}


Measured memory_bytes: 62520
#include<bits/stdc++.h>
using namespace std;
int mod = 1e9+7;


class activity{
public:
    int A;
    int B;
    int C;
};

int vacation(vector<activity>v,int n){

     int dp[n+1][3];
     dp[1][0]=v[1].A;
     dp[1][1]=v[1].B;
     dp[1][2]=v[1].C;

    for(int i=2;i<=n;i++){
      dp[i][0]=(v[i].A + max(dp[i-1][1],dp[i-1][2]))%mod;
      dp[i][1]=(v[i].B + max(dp[i-1][0],dp[i-1][2]))%mod;
      dp[i][2]=(v[i].C + max(dp[i-1][0],dp[i-1][1]))%mod;
    }

    int ans = max(dp[n][0],max(dp[n][1],dp[n][2]));
    return ans % mod;
}



int main(){

     int n;
     cin>>n;
     vector<activity>v(n+1);
     for(int i=1;i<=n;i++){
       cin>>v[i].A;
       cin>>v[i].B;
       cin>>v[i].C;
     }

     cout<<vacation(v,n)<<endl;

     return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n;
  	cin>>n;
  	vector<int> h;
  	for(int i=0; i<n; i++) {
      	int temp;
      	cin>>temp;
      	h.push_back(temp);
    }
  	vector<int> dp(n,0);
  	dp[0] = 0;
  	dp[1] = abs(h[0]-h[1]);
  	for(int i=2; i<n; i++) {
      dp[i] += min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
    }
  		cout<<dp[n-1];
}

Measured memory_bytes: 4068
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN=1e5+10;
ll N,X,M;
set<ll> s;
map<ll,ll> m;
ll Add[MAXN];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>N>>X>>M;
    ll A,i;
    for(A=X,i=1;s.find(A)==s.end();A=A*A%M,i++)
        Add[i]=Add[i-1]+A,s.insert(A),m[A]=i;
    ll Pos=m[A];
    ll T=i-Pos,Sum=Add[i-1]-Add[Pos-1];
    ll Ans=(N-Pos+1)/T*Sum+Add[(N-Pos+1)%T+Pos-1];
    cout<<Ans<<endl;
    return 0;
}

Measured memory_bytes: 9404
let rec fold_n n f a k = if n <= 0 then k a else fold_n (n-1) f (f a) k
let f (a, b) = (b + a/2, a/2)
let _ = Scanf.scanf "%d %d %d" @@ fun a b n ->
  fold_n n f (a, b) @@ fun (x,y) ->
  if n mod 2 = 0 then Printf.printf "%d %d\n" x y
  else Printf.printf "%d %d\n" y x


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

using namespace std;

int main() {

	vector<vector<int>> a(3, vector<int>(3));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a.at(i).at(j);
		}
	}

	int N;
	cin >> N;

	vector<int> b(N);
	for (int i = 0; i < N; i++) {
		cin >> b.at(i);
	}

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < N; k++) {
				if (a.at(i).at(j) == b.at(k)) {
					a.at(i).at(j) = 0;
				}
			}
		}
	}

	string d = "No";

	for (int i = 0; i < 3; i++) {
		if (a.at(i).at(0) == 0 && a.at(i).at(1) == 0 && a.at(i).at(2) == 0) {
			d = "Yes";
		}
		else if (a.at(0).at(i) == 0 && a.at(1).at(i) == 0 && a.at(2).at(i) == 0) {
			d = "Yes";
		}
		else if (a.at(0).at(0) == 0 && a.at(1).at(1) == 0 && a.at(2).at(2) == 0) {
			d = "Yes";
		}
		else if (a.at(0).at(2) == 0 && a.at(1).at(1) == 0 && a.at(2).at(0) == 0) {
			d = "Yes";
		}
		
	}
	cout << d << endl;

	return 0;
}

Measured memory_bytes: 384
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
l = [a,b,c,d,e]
rissoku = min(l)
amari = n % rissoku
syou = n // rissoku
if amari == 0:
    print(syou + 4)
else:
    print(syou + 5)

Measured memory_bytes: 38384
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N;
int t[100001], x[100001], y[100001];

void init()
{
}

void solve()
{
    bool ok = true;
    FOR(i, 1, N+1){
        int dt = t[i] - t[i-1];
        int dx = abs(x[i] - x[i-1]);
        int dy = abs(y[i] - y[i-1]);
        if(dt < dx+dy || ((dx+dy)-dt) % 2 != 0){
            ok = false;
            break;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(i, 1, N+1) cin >> t[i] >> x[i] >> y[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 1408
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		int count=3;
		if(a==b){count--;
			 }if(b==c){count--;
			 }if(a==c){count--;
			 }
		 if(count==0) {
			 count++;
		 }
		System.out.println(count);
	}
}

Measured memory_bytes: 23124
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int g[5][5],p[5];
void AC(){puts("YES");exit(0);}
void WA(){puts("NO");exit(0);}
int main()
{
	for(int i=1;i<=3;++i)
	{
		int u=read(),v=read();
		g[u][v]=g[v][u]=1;
	}
	for(int i=1;i<=4;++i)p[i]=i;
	do
	{
		int now=p[1];bool fl=true;
		for(int i=2;i<=4;++i)
			if(g[p[i-1]][p[i]]);
			else fl=false;
		if(fl)AC();
	}while(next_permutation(&p[1],&p[5]));
	WA();
}


Measured memory_bytes: 256
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        _n: usize,
        s: chars,
        t: chars,
    }
    let ans = s
        .iter()
        .zip(t.iter())
        .map(|(x, y)| format!("{}{}", x, y))
        .collect::<Vec<_>>()
        .join("");
    println!("{}", ans);
}


Measured memory_bytes: 4352
n, k = map(int, input().split(' '))
W = []
for _ in range(n):
    W.append(int(input()))


def is_carry(p):
    i = 0
    for _ in range(k):
        s = 0
        while s + W[i] <= p:
            s += W[i]
            i += 1
            if i == n:
                return True
    return False


def binary_search(left, right):
    while left < right:
        m = (left + right) // 2
        c = is_carry(m)
        if c:
            right = m
        else:
            left = m + 1
    print(left)


left = 0
right = 100_000 * 100_000
binary_search(left, right)



Measured memory_bytes: 9560
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
typedef long long ll;

int dp[1<<20];
vector<string> lex;
int n,p;

int add(int k,int a){
	k+=n-1;
	dp[k]=(dp[k]+a)%p;
	while(k>0){
		k=(k-1)/2;
		dp[k]=(dp[k*2+1]+dp[k*2+2])%p;
	}
}

int query(int a,int b,int k=0,int l=0,int r=n){
	if(r<=a || b<=l)return 0;
	if(a<=l && r<=b)return dp[k];
	int vl=query(a,b,k*2+1,l,(l+r)/2);
	int vr=query(a,b,k*2+2,(l+r)/2,r);
	return (vl+vr)%p;
}

int main(void){
	int a,b;
	while(1){
		scanf("%d%d%d",&a,&b,&p);
		if(a+b+p==0)break;
		lex.clear();
		memset(dp,0,sizeof(dp));
		n=1;
		while(n<=b-a+1)n*=2;
		for(int i=a;i<=b;i++){
			stringstream stream;
			stream << i;
			string s;
			stream >> s;
			lex.push_back(s);
		}
		sort(lex.begin(),lex.end());
		for(int i=0;i<lex.size();i++){
			stringstream stream;
			stream << lex[i];
			int num;
			stream >> num;
			num-=a;
			int plus=query(0,num);
			add(num,(plus+1)%p);
		}
		printf("%d\n",dp[0]);
	}
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

int main(){

    ll N = 0;
    cin >> N;

    ll tmp = N;

    for(ll i = N; i > 0; i--){
        ll tmp = i * 1.08;
        if(tmp == N){
            cout << i << endl;
            return 0;
        }
    }

    cout << ":(" << endl;

}

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

double dist(const std::vector<double>& p, const std::vector<double>& q)
{
  double resultSqared = 0;
  for(int i=0; i<p.size(); i++) { resultSqared += (p[i]-q[i])*(p[i]-q[i]); }
  return std::sqrt(resultSqared);
}


int main()
{
  int n,d;
  std::cin >> n >> d;
  
  std::vector<std::vector<double>> points;
  for(int i=0; i<n; i++)
  {
    std::vector<double> point;
    for(int j=0; j<d; j++) { int x; std::cin >> x; point.push_back(x);}
    points.push_back(point);
  }

  int count = 0;
  for(int i=0; i<points.size(); i++)
  {
    for(int j=i+1; j<points.size(); j++)
    {
      const double thisdist = dist(points[i], points[j]);
      if( thisdist == std::ceil(thisdist) ) { count += 1; }
    }
  }

  std::cout << count;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
  vi N(4); rep(i,4) cin>>N[i];
  sort(all(N)); vi M={1,4,7,9}; bool ans=1;
  rep(i,4){
    if(N[i]!=M[i]) ans=0;
  }
  if(ans) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;
using ll = long long;

int main() {
  int n, W;
  cin >> n >> W;
  vector<int> w(n), v(n);
  int V = 0;
  for (int i = 0; i < n; ++i) {
    cin >> w[i] >> v[i];
    V += v[i];
  }
  vector<ll> dp(V + 1, LLONG_MAX);
  dp[0] = 0;
  for (int i = 0; i < n; ++i) {
    vector<ll> new_dp(V + 1, LLONG_MAX);
    for (int j = 0; j <= V; ++j) {
      new_dp[j] = min(new_dp[j], dp[j]);
      if (j-v[i] >= 0 && dp[j-v[i]] != LLONG_MAX) {
        new_dp[j] = min({new_dp[j], (i > 0 ? dp[j-v[i]]: 0) + w[i]});
      }
    }
    dp = new_dp;
  }

  int ans = 0;
  for (int i = V; i >= 0; --i) {
    if (dp[i] <= W) {
      ans = i;
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}


/* 0-1 knapsack
 *
 * dp[i][j] = max value (first i object, with weight <= j)
 */


Measured memory_bytes: 4760
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill((T*)array, (T*)(array+N), val);
}
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


class ATableTennisTraining {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll n, a, b;
        in >> n >> a >> b;
        ll diff = abs(a - b) - 1;
        ll res;
        if(diff % 2 == 1) res = diff/2 + 1;
        else{
            res = min(a - 1, n - b);
            res += (diff + 2) / 2;
        }
        out << res << endl;
	}
};


int main() {
	ATableTennisTraining solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
const ll N = 3e3+5;
const ll MOD = 998244353;
ll n, s;
ll dp[N][N][4];
ll a[N];
ll compute(ll i, ll left, ll start)
{
    if(left < 0 ) return 0;
    if( left == 0) return dp[i][left][start] = (n-i+1)%MOD;
    if( i == n) return 0;
    if(dp[i][left][start] != -1) return dp[i][left][start];
    ll ans = 0;
    // take
    if(!start)
    {
        ll val = compute(i+1, left-a[i], 1);
        val *= i+1;
        val %= MOD;
        ans += val;
        ans %= MOD;
    }
    else 
    {
        ll val = compute(i+1, left-a[i], 1);
        ans += val;
        ans %= MOD;
    }

    // do not take
    ll val = compute(i+1, left, start);
    ans += val;
    ans %= MOD;
    
    return dp[i][left][start] = ans;

}
int main()
{
    she_told_me_dont_worry
    cin>>n>>s;
    ll i, j, k;
    FOR0(i, n) cin>>a[i];
    FOR0(i, n+2)FOR0(j, s+2)FOR0(k, 3) dp[i][j][k] = -1;
    cout<<compute(0, s, 0)<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 282368
import bisect
S = input()
T = input()
D = [[] for _ in range(26)]
for i in range(26):
  D[i] = [0] * S.count(chr(97 + i))
P = [0] * 26
for i, s in enumerate(S):
  n = ord(s) - 97
  D[n][P[n]] = i + 1
  P[n] += 1
pos = 0
loop = 0
for t in T:
  n = ord(t) - 97
  if D[n] == []:
    print(-1)
    break
  _d = bisect.bisect(D[n], pos)
  _pos = D[n][_d % len(D[n])]
  if _pos <= pos:
    loop += 1
  pos = _pos
else:
  print(len(S) * loop + pos)

Measured memory_bytes: 7284
#include<stdio.h>

int main() {
	int n;
	int i;

	scanf("%d" ,&n);

	for (i = 1; i <= n ;i++) {
		if (i % 3 == 0) {
			printf(" %d" ,i);
		} else if (i % 10 == 3) {
			printf(" %d" ,i);
		} else if ((i % 100) / 10 == 3) {
			printf(" %d", i);
		} else if ((i % 1000) / 100 == 3) {
			printf(" %d", i);
		} else if ((i % 10000) / 1000 == 3) {
			printf(" %d", i);
		}
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	ll n, k; cin >> n >> k;
	VI p(n), c(n); 
	REP(i,n){
		cin >> p[i];
		p[i]--;
	}
	REP(i,n) cin >> c[i];
	ll ans=-INF;
	REP(i,n){
		vector<bool> f(n,0);
		VI sc(n,-INF);
		VI pp(n,0);
		int now=i;
		ll sum=0;
		for(ll j=0;1;j++){
			if(f[now]||j>=k){
				sum+=(sum-sc[now])*(max(0ll,k-j-1)/(j-pp[now]));
				ans=max(ans,sum);
				int lm=(k-j)%(j-pp[now]);
				if(lm==0&&k-j!=0)
					lm=j-pp[now];
				for(int l=0;l<lm;l++){
					sum+=c[now];
					now=p[now];
					ans=max(ans,sum);
				}
				break;
			}
			f[now]=1;
			sc[now]=sum;
			pp[now]=j;
			sum+=c[now];
			now=p[now];
			ans=max(ans,sum);
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
int main() {
const ll INF = 100100100100100100;
int N,M;
cin>>N>>M;
vector<ll> height(N+1),checker(N+1,1);
rep3(i,N){
  cin >> height[i];

}
int A,B;
rep(i,M){
  cin>>A>>B;
  if(height[A]<height[B]){
    checker[A]=0;

  }
  else if(height[A]>height[B]){
    checker[B] =0;
  }
  else{
    checker[A]=checker[B]=0;
  }

}
int count=0;
rep3(i,N){
  if(checker[i]){
    count++;
  }
}
cout<<count<<endl;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  A.at(0)=-1;
  for (int i=1; i<N; i++) {
    cin >> A.at(i);
  }
  
  vector<int> B(N);
  for (int i=0; i<N; i++) {
    B.at(i)=0;
  }
  for (int i=1; i<N; i++) {
    B.at(A.at(i)-1)++;
  }
  
  for (int i=0; i<N; i++) {
    cout << B.at(i) << endl;
  }
}


Measured memory_bytes: 4844
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct pole{
	struct pole* next;
	int y;
} Pole;

Pole* table[5001];

int search(int x,int y)
{
	if(x < 0 || y < 0 || x > 5000 || y > 5000)return 0;
	if(table[x] != NULL)
	{
		Pole* pt = table[x];
		while(pt->next != NULL)
		{
			if(pt->y == y)
				return 1;
			pt = pt->next;
		}
		if(pt->y == y)
			return 1;
	}
	return 0;
}

void delete(int x,int y)
{
	Pole* pt = table[x];
	if(pt->y == y)
	{
		table[x] = NULL;
		return;
	}
	while(1)
	{
		if(pt->next->y == y)
		{
			pt->next = NULL;
			return;
		}
		pt = pt->next;
	}
}

int main()
{
	int** poleList;
	int n;
	int i,j,k,l,m,o;
	while(scanf("%d",&n),n)
	{
		for(i = 0;i <= 5000;i++)
		{
			table[i] = NULL;
		}
		poleList = (int**)malloc(sizeof(int*)*n);
		for(i = 0;i < n;i++)
		{
			int x,y;
			scanf("%d %d",&x,&y);
			poleList[i] = (int*)malloc(sizeof(int)*2);
			poleList[i][0] = x;
			poleList[i][1] = y;
			if(table[x] == NULL)
			{
				table[x] = (Pole*)malloc(sizeof(Pole));
				table[x]->next = NULL;
				table[x]->y = y;
			}
			else
			{
				Pole* tmp = table[x];
				table[x] = (Pole*)malloc(sizeof(Pole));
				table[x]->next = tmp;
				table[x]->y = y;
			}
		}
		int maxsq = 0;
		for(i = 0;i < n;i++)
		{
			for(j = (i+1);j < n;j++)
			{
				double posx[6] = {
					poleList[i][0]+poleList[i][1]-poleList[j][1],
					poleList[j][0]+poleList[i][1]-poleList[j][1],
					poleList[i][0]-poleList[i][1]+poleList[j][1],
					poleList[j][0]-poleList[i][1]+poleList[j][1],
					(poleList[i][0]+poleList[j][0]+poleList[i][1]-poleList[j][1])/2,
					(poleList[i][0]+poleList[j][0]-poleList[i][1]+poleList[j][1])/2
				};
				double posy[6] = {
					poleList[i][1]-poleList[i][0]+poleList[j][0],
					poleList[j][1]-poleList[i][0]+poleList[j][0],
					poleList[i][1]+poleList[i][0]-poleList[j][0],
					poleList[j][1]+poleList[i][0]-poleList[j][0],
					(poleList[i][1]+poleList[j][1]-poleList[i][0]+poleList[j][0])/2,
					(poleList[i][1]+poleList[j][1]+poleList[i][0]-poleList[j][0])/2
				};
				int sq = (poleList[i][0]-poleList[j][0])*(poleList[i][0]-poleList[j][0])
					+(poleList[i][1]-poleList[j][1])*(poleList[i][1]-poleList[j][1]);
				if(search(posx[0],posy[0]) && search(posx[1],posy[1]) || search(posx[2],posy[2]) && search(posx[3],posy[3]))
				{
					if(sq < maxsq)continue;
					else maxsq = sq;
				}
				else if(search(posx[4],posy[4]) && search(posx[5],posy[5]))
				{
					if(sq < maxsq*2)continue;
					else maxsq = sq/2;
				}
			}
			delete(poleList[i][0],poleList[i][1]);
		}
		printf("%d\n",maxsq);
	}
	return 0;
}

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

using namespace std;

typedef long long         ll;
typedef pair <int,int>    ii;
typedef vector <int>      vi;
typedef vector <int,int>  vii;

#define INF 2000000000
#define pb push_back
#define what_is(x) cerr <<#x<<" is "<<x<<endl;

int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
    ll n,p;
    cin>>n>>p;
    ll k=2;
    ll ma=1;
    if(n==1)
    {
        cout<<p;
        return 0;
    }
    ll maxcheck=pow(p,(1.0/(n*1.0)));
    maxcheck+=2;
    while(k<maxcheck)
    {
        ll coun=n;
        ll ans=1;
        while(coun>0)
        {
            if(p%ans!=0||ans>p) break;
            ans*=k;
            coun--;
        }
        if(coun==0&&p%ans==0) ma=max(ma,k);
        k++;
    }
    cout<<ma;
}


Measured memory_bytes: 256
from collections import deque
s = deque(input())
q = int(input())
rev = 1
for i in range(q):
    t = input().split()
    if t[0]=="1":
        rev *= -1
    else :
        if t[1]=='1':
            if rev == 1:
                s.appendleft(t[2])
            else :
                s.append(t[2])
        else :
            if rev == 1:
                s.append(t[2])
            else :
                s.appendleft(t[2])
if rev == 1:
    print(''.join(s))
else :
    print(''.join(reversed(s)))

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

int main() {
  int N;
  cin>>N;
  vector<vector<pair<int,int>>> G(N);
  vector<int> c(N-1);
  vector<int> S(N);
  for(int i=0;i<N-1;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    S.at(a)++,S.at(b)++;
    G.at(a).push_back(make_pair(b,i));
    G.at(b).push_back(make_pair(a,i));
  }
  int Z=0;
  for(int i=0;i<N;i++){
    Z=max(Z,S.at(i));
  }
  cout<<Z<<endl;
  queue<pair<int,int>> q;
  q.push(make_pair(0,-1));
  while(!q.empty()){
    int a,b;
    tie(a,b)=q.front();
    q.pop();
    int t=1;
    for(pair<int,int> x:G.at(a)){
      if(t==b){
        t++;
      }
      int d,e;
      tie(d,e)=x;
      if(c.at(e)==0){
        c.at(e)=t;
        q.push(make_pair(d,t));
        t++;
      }
    }
  }
  for(int i=0;i<N-1;i++){
    cout<<c.at(i)<<endl;
  }
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>

int main(){
    ll X, Y, Z;
    cin >> X >> Y >> Z;
    
    ll ans=0;
    ans=(X-Z)/(Y+Z);
    cout << ans << endl;
    return 0;
}

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

int main(void) {
  ll N, T;
  cin >> N >> T;
  vector<ll> c(N), t(N);
  REP(i, 0, N) cin >> c[i] >> t[i];

  ll ans = 1LL << 60;
  REP(i, 0, N) {
    if (t[i] <= T) {
      ans = min(ans, c[i]);
    }
  }

  if (ans == 1LL << 60) {
    cout << "TLE" << endl;
  } else {
    cout << ans << endl;
  }
}

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

int n;
vector<lint> a;

int main() {
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<lint>());
    lint ans = a[0];
    n -= 2;
    for (int i = 0; i < n / 2; i++) {
        ans += a[i + 1] * 2;
    }
    if (n % 2 != 0) {
        ans += a[n / 2 + 1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4776
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();

            var max = A.Max();
            var check = Enumerable.Repeat(true, max + 1).ToArray();
            var exist = Enumerable.Repeat(false, max + 1).ToArray();
            foreach (var i in Enumerable.Range(0, N))
            {
                if (check[A[i]] == false)
                {
                    continue;
                }

                if (exist[A[i]])
                {
                    check[A[i]] = false;
                    continue;
                }
                else
                {
                    exist[A[i]] = true;
                }

                for (var j = 2 * A[i]; j <= max; j += A[i])
                {
                    check[j] = false;
                }
            }

            Console.WriteLine(A.Count(elem => check[elem]));
        }
    }
}


Measured memory_bytes: 46208
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String s = a.concat(b);
    int num = Integer.parseInt(s);
    for (int i = 1; i <= 400; i++) {
      if (i * i == num) {
        System.out.println("Yes");
        return;
      }
    }
    System.out.println("No");
  }
}

Measured memory_bytes: 21588
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

x = i()
num = (x//11)*11
r = x-num
if r == 0:
    print((x//11)*2)
elif r <= 6:
    print((x//11)*2+1)
else:
    print(((x//11)+1)*2)

Measured memory_bytes: 77320
#include <bits/stdc++.h>
using namespace std;
/************************Contest Template**************************/
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(0);
struct S{
    int a,b; S(){}S(int _a,int _b)
    { a=_a; b=_b; }
    const bool operator<(const S &o) const{
        return a<o.a;}
};
string exm;
inline void exf(void){ cout<<exm<<"\n"; exit(0); }
template <typename T>
inline void showAll(vector<T> &v,string sep=""){
    for(T &here:v) cout<<here<<sep;}
template <typename T>
inline void showAll(T a[],int st,int end,string sep=""){
    for(int i=st ; i<=end ; i++) cout<<a[i]<<sep; }
template <typename T>
inline void showAll(T a[],int x,int y,int z,int w,string p,string q){
    for(int i=x ; i<=y ; i++){for(int j=z ; j<=w ; j++)
        {cout<<a[i][j]<<p;}cout<<q;}}   
template <typename T>
inline vector<int> int_seperation(T N,int d=10){
    vector<int> v; while(N){v.push_back(N%d); N/=d;}
    reverse(v.begin(),v.end()); return v; }
/************************Contest Template**************************/
//const int SIZE=

int main(){
    int t;  scanf("%d",&t);	
	if(t>=30) printf("Yes\n");
  	else printf("No\n");
  	
  	return 0;
}
/*

*/






Measured memory_bytes: 3740
#include <stdio.h>
 
int main()
{   int a,b,i;
    char op;
    for(i=1;i>0;i++){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='+')
        {printf("%d\n",a+b);
        }
        else if(op=='-')
        {printf("%d\n",a-b);
        }
        else if(op=='*')
        {printf("%d\n",a*b);
        }
        else if(op=='/'){
            printf("%d\n",a/b);
        }else if(op=='?') {
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <fstream>
using namespace std;
const int a[] = {0,1,400,800,1200,1600,2000,2400,2800};
const int b[] = {0,399,799,1199,1599,1999,2399,2799,3199};
int n;
const int N = 100;
int f[N];
void nhap()
{
    scanf("%d\n",&n);
}
int vt(int x)
{
    if (x>=3200) {return 9;}
    if (x>=2800) {return 8;}
    if (x>=2400) {return 7;}
    if (x>=2000) {return 6;}
    if (x>=1600) {return 5;}
    if (x>=1200) {return 4;}
    if (x>=800) {return 3;}
    if (x>=400) {return 2;}
    if (x>=1) {return 1;}
}
void taomang()
{
    int vitri;
    for (int i=1; i<=n; i++)
    {
        int x;
        scanf("%d ",&x);
        vitri = vt(x);
        f[vitri]++;
    }
}
void solve()
{
    int res=0;
    for (int i=1; i<=8; i++)
    {
        if (f[i]>0) {res++;}
    }
    printf("%d %d",max(res,1),res+f[9]);
}
int main()
{
    nhap();
    taomang();
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long m,n;
int main()
{
	cin>>m>>n;
	if(n==1&&m==1) {cout<<1;return 0;}
	if(n==1) cout<<m-2;
	else if(m==1) cout<<n-2;
	else cout<<(m-2)*(n-2);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	if (s == "SUN") cout << 7;
	if (s == "MON") cout << 6;
	if (s == "TUE") cout << 5;
	if (s == "WED") cout << 4;
	if (s == "THU") cout << 3;
	if (s == "FRI") cout << 2;
	if (s == "SAT") cout << 1;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
	int prime[56];
	int n;
	prime[0]=2;
	prime[1]=11;
	prime[2]=31;
	prime[3]=41;
	prime[4]=61;
	prime[5]=71;
	prime[6]=101;
	prime[7]=131;
	prime[8]=151;
	prime[9]=181;
	prime[10]=191;
	prime[11]=211;
	prime[12]=241;
	prime[13]=251;
	prime[14]=271;
	prime[15]=281;
	prime[16]=311;
	prime[17]=331;
	prime[18]=401;
	prime[19]=421;
	prime[20]=431;
	prime[21]=461;
	prime[22]=491;
	prime[23]=521;
	prime[24]=541;
	prime[25]=571;
	prime[26]=601;
	prime[27]=631;
	prime[28]=641;
	prime[29]=661;
	prime[30]=691;
	prime[31]=751;
	prime[32]=761;
	prime[33]=811;
	prime[34]=821;
	prime[35]=881;
	prime[36]=911;
	prime[37]=941;
	prime[38]=971;
	prime[39]=991;
	prime[40]=1021;
	prime[41]=1031;
	prime[42]=1051;
	prime[43]=1061;
	prime[44]=1091;
	prime[45]=1151;
	prime[46]=1171;
	prime[47]=1181;
	prime[48]=1201;
	prime[49]=1231;
	prime[50]=1291;
	prime[51]=1321;
	prime[52]=1361;
	prime[53]=1381;
	prime[54]=1471;

	cin >> n;
	
	for(int i=0;i<n-1;i++){
		cout << prime[i] << " ";
	}
	cout << prime[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// ========== debug ==========
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// ===========================

int main() {
  string N;
  ins(N);
  cout << N.substr(0, 3) << endl;

  return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
#define MAX 101

int G[MAX][MAX], d[MAX], f[MAX];

void adjacency_matrices(int n) {
    int i, j, u, m, k;

    for (i=1; i<=n; i++) {
        scanf("%d", &u);
        scanf("%d", &m);
        for (j=1; j<=m; j++) {
            scanf("%d", &k);
            G[u][k] = 1;
        }
    }
}

int depth_first_search(int t, int i, int n) {
    int j;
    bool get;
    d[i] = t;

    for (j=1; j<=n; j++) {
        if (G[i][j]==1 && d[j]==-1) {
            t = depth_first_search(++t, j, n);
        } 
    }

    f[i] = ++t;

    return t;
}

int main() {
    int n, i, j, t;
    t = 0; 

    scanf("%d", &n);
    for (i=1; i<=n; i++) {
        d[i]=f[i]=-1;
        for (j=1; j<=n; j++) {
            G[i][j] = 0;
        }
    }

    adjacency_matrices(n);

    for (i=1; i<=n; i++) {
        if (f[i]==-1) {
            t = depth_first_search(++t, i, n);
        }
    }

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

    return 0;
}


Measured memory_bytes: 2708
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

ll N, res;

int main() {
	cin >> N;
	res = N - 1;
	for (ll i = 1; i*i <= N; i++) {
		if (N%i == 0) {
			res = min(res, i + N / i - 2);
		}
	}
	cout << res << endl;
}

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

typedef long long ll;
typedef pair<int,int> PII;
#define CINSPEED std::ios::sync_with_stdio(false),std::cin.tie(0),std::cout.tie(0)
#define fi first
#define se second
#define pb push_back

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){ return a * b / gcd(a,b);}


const int N = 100010,M = 1000010;
int cmp(int a,int b)
{
    return a > b;
}

void solved()
{
    ll h;
    ll res = 1;
    ll ans = 1;
    ll t;
    cin >> h;
    while(h > 1)
    {
        h /= 2;
        res *= 2;
        ans += res;
    }
    cout << ans;

}

int main()
{
    //CINSPEED;
    solved();
#ifdef LOCAL
    system("pause");
#endif
    return 0;
}

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

typedef pair<long long, long long> P;

void Main() {
  int n, m;
  cin >> n >> m;

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

  sort(ab.begin(), ab.end());
  int i = 0, num = 0;
  long long ans = 0;
  while (num < m) {
    P p = ab[i];
    if (p.second + num < m) {
      ans += p.first * p.second;
      num += p.second;
      i++;
    } else {
      ans += p.first * (m - num);
      num += m - num;
    }
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 1792
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include "bitset"
#include "cmath"
#include "list"
#include "complex"
#include <cassert>
#include "deque"
#include "numeric"
#include <cstdio>

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++) 
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
//#define mp make_pair
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
#define endl '\n'
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;
#define int long long
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

const int sze = 3e5 + 50, oo = 1e18 + 500, mod = 1e9 + 7;
const double eps = 1e-9, PI = 2 * acos(0.0);
vi vertices[sze];
vc visit(sze, false);
vc used(sze, false);
vi arr(sze, 0);
int n, m, k;
int A, B;
int cnt = 0;

int dp[sze][3];

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

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

	int ans = -1;
	for (int i = 0; i < 3; i++) {
		maxi(ans, dp[n][i]);
	}
	
	cout << ans;
	return 0;
}

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

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	if(a <= 0 && 0 <= b)cout << "Zero" << endl;
	else if(a < 0 && (b - a) % 2 == 0)cout << "Negative" << endl;
	else cout << "Positive" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
double inf=1000000000000000000;
struct Cir{
	double x,y,r;
}e[1005];
double a[1005][1005],d[1005];
int n,vis[1005];
double xs,ys,xt,yt;
double min(double x,double y){
	return x<y?x:y;
}
double max(double x,double y){
	return x>y?x:y;
}
double dis(double xa,double ya,double xb,double yb){
	return sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
}
double dij(int n,int S,int T){
	int mini;
    for(int i=1;i<=n;i++) d[i]=inf,vis[i]=0;
    d[S]=0,d[0]=inf+1;
    while(!vis[T]){
    	mini=0;
        for(int i=1;i<=n;i++) if(!vis[i]&&d[mini]>d[i]) mini=i;
        vis[mini]=1;
        for(int i=1;i<=n;i++) if(!vis[i]) d[i]=min(d[i],d[mini]+a[mini][i]);
    }
    return d[mini];
}
int main(){
    scanf("%lf%lf%lf%lf",&xs,&ys,&xt,&yt);
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lf%lf%lf",&e[i].x,&e[i].y,&e[i].r);
    for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++){
          double r1=e[i].r,r2=e[j].r;
          a[i][j]=a[j][i]=max(0.0,dis(e[i].x,e[i].y,e[j].x,e[j].y)-r1-r2); 
    }
    for(int i=1;i<=n;i++){
        a[n+1][i]=a[i][n+1]=max(0.0,dis(xs,ys,e[i].x,e[i].y)-e[i].r);
        a[n+2][i]=a[i][n+2]=max(0.0,dis(xt,yt,e[i].x,e[i].y)-e[i].r);
        a[i][i]=0;
    }
    a[n+1][n+1]=a[n+2][n+2]=0;
    a[n+1][n+2]=a[n+2][n+1]=dis(xs,ys,xt,yt);
    printf("%.10lf\n",dij(n+2,n+1,n+2));
    return 0;
}

Measured memory_bytes: 8192
N = int(input())
A = list(map(int, input().split()))
tmp_money = 1000
tmp_min = A[0]
for i in range(1, N):
    if A[i] <= tmp_min:
        tmp_min = A[i]
    else:
        tmp_kabu = tmp_money // tmp_min
        tmp_money = tmp_money - (tmp_kabu * tmp_min) + tmp_kabu * A[i]
        tmp_min = A[i]
print(tmp_money)        


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

const int32_t MAX_N = 1e5;

int32_t a[MAX_N + 5][3];
int32_t dp[MAX_N + 5][3];

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

	int32_t n;
	std::cin >> n;

	for(int32_t i = 0; i < n; i++) {
		for(int32_t j = 0; j < 3; j++) {
			std::cin >> a[i][j];
		}
	}

	for(int32_t i = n - 1; i >= 0; i--) {
		for(int32_t j = 0; j < 3; j++) {
			for(int32_t p = 0; p < 3; p++) {
				if(p == j) {
					continue;
				}

				dp[i][j] = std::max(dp[i][j], dp[i + 1][p] + a[i][p]);
			}
		}
	}

	int32_t ans = 0;
	for(int32_t i = 0; i < 3; i++) {
		ans = std::max(ans, dp[0][i]);
	}

	std::cout << ans << '\n';
}



Measured memory_bytes: 2560
#include<cstdio>
#include<map>
#include<iostream>

using namespace std;


const int N = 222;



bool SubContain(string s, string g){
	
	map<string, int> memo;
	
	
	for(int dist=1; dist<g.size()-1; dist++){
		
		string t="";
		
		int cnt = 0;
		for(int j=0;j<g.size();j+=dist){
			if(cnt==s.size())break;
			t+= g[j];
			cnt++;
		}
		
		//cout<<"**** " << t<<endl;
		
		memo[t] = 1;
	}
	
	return memo[s]==1;
}

bool Contain(string s, string g){
	
	for(int i=0;i<g.size();i++){
		if(SubContain(s, g.substr(i))) return true;
	}
	
	return false;
}

int main(){
	
	int n;
	string s;
	
	cin>>n>>s;
	
	int ans = 0;
	
	for(int i=0;i<n;i++){
		string g;
		cin>>g;
		
		if(Contain(s,g))ans++;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 1232
n = int(input())
w = list(map(int, input().strip().split()))
def add(x, y):
    return x+y
from functools import reduce
res = reduce(add, w)/2
k = 0
temp = 100
for i in range(n):
    sum1 = w[i]+k
    a = abs((res-sum1))*2
    k = sum1
    if a < temp:
        temp = a
print(int(temp))

Measured memory_bytes: 3572
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define ff               first
#define ss               second
#define pb               push_back
#define all(x)           (x).begin(), (x).end()
#define mem0(x)          memset(x, 0, sizeof (x))
#define mem1(x)          memset(x, -1, sizeof (x))

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<vii> vvii;
typedef vector <ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    int ans = 10000;
    for (int i = 0; i < n-m+1; ++i) {
        int res = 0;
        for (int j = 0; j < m; ++j) {
            if (s[i+j] != t[j]) res++;
        }
        ans = min(ans, res);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3660