akhauriyash/Code-Regression huggingface dataset:
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
//void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll maxn = 100005;
const ll mm = 1e+18;
void solve()
{
    int n;
    cin>>n;
    int a[n+1]={0};
    rep0(i,n-1){
        int x;
        cin>>x;
        a[x]++;
    }
    rep1(i,n) cout<<a[i]<<"\n";
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //srand(time(0));
    //cin>>t;
    for(int _i=1;_i<=t;_i++){
        solve();
        //nx;
    }
    return 0;
}

Measured memory_bytes: 5268
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=1e9+7;



int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();
    
    string s;
    cin>>s;
    ll tot=0;
    for(ll i=0;i<s.size();i++){
        tot+=(s[i]-'0');
    }
    if(tot%9==0)
        cout<<"Yes";
    else
        cout<<"No";



    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	double x[n];
	string u[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> x[i] >> u[i];
	}
	
	double ans = 0;
	for (int i = 0; i < n; ++i)
	{
		if (u[i] == "BTC")
		{
			ans += 380000.0 * x[i];
		}
		else
		{
			ans += x[i];
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;



int solve(){

    int n;
    
    cin >> n;
    
    unsigned long long max,min;
    max = 1; min = 1;
    
    for(int i = 0; i < n; i++){
        
        int now;
        
        cin >> now;
        
        switch (now) {
            default:
                max *= 3;
                if(now % 2 == 0){
                    min *= 2;
                }else{
                    min *= 1;
                }
                
                break;
        }
        
        
        
    }
    
    cout << max - min << endl;
    
    
    return 0;
}



int main() {
    // insert code here...
    //cout << "Hello, World!\n";
    
    solve();
    
    
    //return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

#define FOR(i, b, e) for(int i=(b);i<(e);i++)
#define REP(i, n) FOR(i,0,n)

#define ALL(v) (v).begin(),(v).end()

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

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

int main() {
    int N;
    cin >> N;
    cout << (N + 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
vector<pair<char, int> > Runlen(string S) {
  vector<pair<char, int> > b;
  int N = S.size();
  if (N == 0) return b;
  char cur = S[0];
  int cnt = 0;
  for (int i = 0; i <= N - 1; i++) {
    if (cur != S[i]) {
      b.push_back(make_pair(cur, cnt));
      cnt = 1;
      cur = S[i];
    } else {
      cnt++;
    }
  }
  b.push_back(make_pair(cur, cnt));
  return b;
}
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string S;
  cin >> S;
  print(Runlen(S).size() - 1);
}

Measured memory_bytes: 2628
"use strict";
function I(t,i){this._s=t.split("\n"),this._c=0,this._l=0,this._f=i||Number}I.prototype.a=function(t){var i=this._s[this._l];if(i){var s=i.trim().split(" "),h=s[this._c];return this._c++,s.length===this._c&&(this._c=0,this._l++),t?t(h):this._f(h)}},I.prototype.l=function(t){var i=this._s[this._l];if(i)return this._c=0,this._l++,i.split(" ").map(t||this._f)},module.exports=I;

function main(input) {
  var o = new I(input);

  var n = o.a();
  var k = o.a();
  var s = o.a(String);

  s = s.split("");
  s[k - 1] = s[k - 1].toLowerCase();
  s = s.join("");
  console.log(s);
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 22204
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed _main(){
  int N; cin >> N;
  int ans=0;
  for(int i=1;i<=N;i++){
    if(i%3==0 && i%5==0);
    else if(i%3==0);
    else if(i%5==0);
    else ans+=i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(ll i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    v tele;
    ll N,K;
    cin>>N>>K;
    v A(N);
    rep(i,0,N){
        cin>>A[i];
        A[i]--;
    }
    map<ll,ll> m;
    tele.PB(0);
    m[0] = 1;
    ll i=0;
    ll loop = 0;
    ll fin = 0;
    while(true){
        if(m[A[i]] > 0){
            loop = tele.size()-m[A[i]]+1;
            fin = m[A[i]]-1;
            break;
        }
        else{
            tele.PB(A[i]);
            m[A[i]] = tele.size();
            i = A[i];
        }
    }
    K+=1;
    if(K<=fin){
        cout<<tele[K-1]+1;
    }
    else{
        K-=fin;
        K--;
        K %= loop;
        cout<<tele[fin+K]+1;
    }
    return 0;
}

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

using ll = long long;
using pii = pair<int, int>;

#define     endl               "\n"
#define     fast_io            ios::sync_with_stdio(false); cin.tie(0);
#define     file_io            freopen("input.txt", "r", stdin);   \
                               freopen("output.txt", "w", stdout);
#define     all(x)             begin(x), end(x)
#define     debug(x)           cerr <<"Line "<< __LINE__ <<" : "<< #x " = "<< x <<endl;
 
template<typename T, typename TT>
ostream& operator<<(ostream &os, const pair<T, TT> &t) { return os<<"("<<t.first<<", "<<t.second<<")"; }
template<typename T>
ostream& operator<<(ostream& os, const vector<T> &t) { for(auto& i: t) os<<i<<" "; return os; }
 



int main(int argc, char** argv) {
    fast_io
   
	
	int n;
	cin >> n;
	ll mini = INT_MAX, maxi = INT_MIN, sum = 0;
	ll a;
	for(int i = 0; i < n; ++i) {
	    cin >> a;
	    mini = min(mini, a), maxi = max(maxi, a), sum += a;
	}
	
	cout << mini << " " << maxi << " " << sum << endl;
	
	
	

    return 0;
}























Measured memory_bytes: 3216
#include <iostream>

using namespace std;

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

  for (int i = 0; i < S.size() - 1; i++) {
    if (S[i] == S[i + 1]) {
      cout << "Bad" << endl;
      return 0;
    }
  }

  cout << "Good" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  string str;cin>>str;
  int N = str.size()+1;
  vector<int> vec1 (N,0);
  vector<int> vec2 (N,0);

  for (int i = 0; i < N-1; i++)
  {
    if(str[i] == '<')
    {
      vec1[i+1] = vec1[i]+1;
    }
  }
  
  for (int i = N-2; i >= 0; i--) {
    if(str[i] == '>')
    {
      vec2[i] = vec2[i+1]+1;
    }
  }
  int ANS = 0;
  for (int i = 0; i < N; i++)
  {
    ANS += max(vec1[i],vec2[i]);
  }
  // DEBUG(vec1);
  // DEBUG(vec2);
  cout<<ANS<<endl;
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 8732
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

#define int ll

int h, w, n, k, ans;

int pot[50*50];

int query(int y1, int y2, int x1, int x2)
{
	cout << "? " << y1 << " " << x1 << " " << y2 << " " << x2 << endl;
	int ans;
	cin >> ans;
	return ans;
}

void solve(int y1, int y2, int x1, int x2, int cnt, int split)
{
	if(cnt==0)
		return;

	if(cnt==(y2-y1+1)*(x2-x1+1))
	{
		for(int i = y1; i <= y2; ++i)
		{
			for(int j = x1; j <= x2; ++j)
			{
				ans += pot[i*w+j];
				ans %= k;
			}
		}

		return;
	}

	if(y1!=y2 && split)
	{
		int m = (y1+y2)/2;
		int h = query(y1, m, x1, x2);
		solve(y1, m, x1, x2, h, split^1);
		solve(m+1, y2, x1, x2, cnt-h, split^1);
	}
	else
	{
		int m = (x1+x2)/2;
		int h = query(y1, y2, x1, m);
		solve(y1, y2, x1, m, h, split^1);
		solve(y1, y2, m+1, x2, cnt-h, split^1);
	}
}

int32_t main()
{
	cin >> h >> w >> n >> k;

	pot[0] = 1;

	for(int i = 1; i < 50*50; ++i)
	{
		pot[i] = pot[i-1]*2%k;
	}

	for(int j = 0; j < w; j += 16)
	{
		solve(0, h-1, j, min(j+15, w-1), query(0, w-1, j, min(j+15, w-1)), 1);
	}

	/*for(int i = 0; i < h; i += 5)
	{
		for(int j = 0; j < w; j += 5)
		{
			solve(i, i+4, j, j+4, query(i, i+4, j, j+4), 1);
		}
	}*/

	//solve(0, h-1, 0, w-1, n, 1);

	cout << "! " << ans << endl;
}

Measured memory_bytes: 720
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

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

using namespace std;

int main(){

	int N;

	cin >> N;

	double sum = 0;
	for(int i=0; i<N; i++){
		double x;
		string u;
		cin >> x >> u;
		if(u == "BTC"){
			x *= 380000;
		}
		sum += x;
	}

	cout << sum << endl;

	return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  int ans = 0;
  int count = 1;
  while(1){
    if(count >= b){
      cout << ans << endl;
      return 0;
    }
    else{
      ++ans;
      count += a-1;
    } 
  }
  return 0;
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Control.Monad.ST
import Data.Int
import Data.List
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as B

main=do
  n<-readLn::IO Int
  as<-unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
  --
  let !cs = f n as
  --
  let fr = fi cs 3 n
  let s1 = sss cs n 1 2 fr
  print.minimum.map(\(a,_,_)->a) $ scanl (\(s,fl,fr) i->sol cs n i fl fr) (s1,1,fr) [3..n-2]
--
f n as = V.create $ do
  v<-MV.replicate (n+1) 0 :: ST s (MV.STVector s Int)
  forM_ (zip as [1..]) $ \(a,i) ->
    MV.unsafeRead v (i-1) >>= MV.unsafeWrite v i.(a+)
  return v

ss cs s e = cs V.! e - cs V.! (s-1)

sol cs n i fl fr = (sb, fl', fr')
  where
    sb = sss cs n fl' i fr'
    fl' = fi' cs 1 i (fl-1) (maxBound::Int)
    fr' = fi' cs (i+1) n (fr-1) (maxBound::Int)
--
sss cs n a b c = maximum sl - minimum sl
  where
    sl = [s1,s2,s3,s4]
    s1 = ss cs 1 a
    s2 = ss cs (a+1) b
    s3 = ss cs (b+1) c
    s4 = ss cs (c+1) n

fi cs s e = fi' cs s e s (maxBound::Int)
fi' cs s e i pd
  | pd < pc = i-1
  | i == e = i-1
  | i > e = undefined
  | True = fi' cs s e (i+1) pc
  where
    pc = abs (ri-li)
    li = ss cs s i
    ri = ss cs (i+1) e


Measured memory_bytes: 9212
#include<iostream>
#include<cstdio>
using namespace std;
main(){
  double x1,y1,x2,y2,t_x1,t_y1,t_x2,t_y2;
  while(~scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
	       &x1,&y1,&x2,&y2,&t_x1,&t_y1,&t_x2,&t_y2)){
    if(x1 <= t_x2 && t_x1 <= x2 && y1 <= t_y2 && t_y1 <= y2)
      {   
	puts("YES");
      }/*
    else if(x1 >= t_x1 && x2 <= t_x2 && y1 <= t_y1 && y2 >= t_y2){
	puts("YES");
    }
    else if(x1 <= t_x1 && x2 >= t_x2 && y1 >= t_y1 && y2 <= t_y2){
	puts("YES");
	}*/
    else puts("NO");
  }
}

Measured memory_bytes: 1192
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<pair<ll, ll> > xy(n);
  for (auto &x: xy) cin >> x.first >> x.second;

  for (auto &x: xy) {
    x = pair<ll, ll>(x.first + x.second, x.first - x.second);
  }

  ll x_min = (ll) 9e18;
  ll x_max = (ll) -9e18;
  ll y_min = (ll) 9e18;
  ll y_max = (ll) -9e18;
  for (auto &x: xy) {
    if (x.first < x_min) x_min = x.first;
    if (x.first > x_max) x_max = x.first;
    if (x.second < y_min) y_min = x.second;
    if (x.second > y_max) y_max = x.second;
  }

  cout << max(x_max - x_min, y_max - y_min) << endl;

  return 0;
}


Measured memory_bytes: 6356
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
 
int main()
{
  int H, W, last, count=0;
  char c;
  cin >> H >> W;
  last=H*W;
  vector<char> all(11111,'.'), warp(H,0), weft(W,0);

  rep(i,H)
  {
    rep(j,W)
    {
      cin >> c;
      if(c=='#')
      {
        all.at(i*H+j)='#';
        warp.at(i)=1;
        weft.at(j)=1;
      }
    }
  }
  rep(i,H)
  {
    if(warp.at(i)==0)
      continue;
    rep(j,W)
    {
      if(weft.at(j)==0)
        continue;
      else
        cout<<all.at(i*H+j);
    }
    cout<<endl;
  }
}

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

int main(void)
{
  int n, l;
  cin >> n >> l;
  
  vector<string> s;
  for(int i=0; i<n; i++){
      string tmp;
      cin >> tmp;
      s.push_back(tmp);
  }
  sort(s.begin(), s.end());
  
  for(auto i : s){
   cout << i;
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	vi v(n), c(n);
	rep(i, n)cin >> v[i];
	rep(i, n)cin >> c[i];

	int ans = 0;
	rep(i, 1 << n) {

		int x = 0, y = 0;
		rep(j, n) {
			if ((i >> j) & 1) {
				x += v[j];
				y += c[j];
			}
		}
		ans = max(ans, x - y);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>

using namespace std;
#define endl '\n'
#define pb push_back
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1e9 + 7)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) > "Yes" : "No" ) << endl


typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

void solve() {

	string s = in<string>();;
	ll k = in<ll>(), i;

	for (i = 0; i < k && s[i] != '\0'; i++) {
		if (s[i] != '1') break;
	}
	if (i == k || s[i] == '\0') {
		out(1);
	}
	else {
		out<char>(s[i]);
	}

	return;
}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}
void _main();
int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); return 0;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 

void _main() {
  int N; cin >> N ;
  map<ll,int> mp;
  vl a(N);
  rep(i,N){
    cin >> a[i] ;
    mp[a[i]]++;
  }
  sort(ALL(a));
  reverse(ALL(a));
  int ans = 0;
  rep(i,N){
    if(mp[a[i]]==0) continue;
    ll mask = 1LL;
    while(mask<=a[i]) mask<<=1;
    ll rev = mask - a[i];
    if(a[i]==rev){
      if(mp[a[i]]<2) continue;
      ans++;
      mp[a[i]] -= 2;
    }else{
      if(mp[rev]==0) continue;
      ans++;
      mp[a[i]]--;
      mp[rev]--;
    }
  }
  cout << ans << endl;

}

Measured memory_bytes: 26880
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  if (n == 1) return cout << 1 << '\n', 0;
  V<lint> x(n), y(n);
  set< pair<lint, lint> > se;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
    se.emplace(x[i], y[i]);
  }
  int res = 1e9;
  for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (i != j) {
    lint p = x[i] - x[j], q = y[i] - y[j];
    int curr = 0;
    for (int k = 0; k < n; ++k) {
      curr += !se.count({x[k] - p, y[k] - q});
    }
    res = min(res, curr);
  }
  cout << res << '\n';
}

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

MAP = "0123456789A"
freqs = {}
for i in range(N):
  s = input()

  template = [0 for x in range(26)]
  for j in range(len(s)):
    template[ord(s[j]) - ord("a")] += 1
  freq_str = ""
  for j in range(26):
    freq_str += MAP[template[j]]
  freqs[freq_str] = freqs.get(freq_str, 0) + 1

ans = 0
for key in freqs:
  ans += (freqs[key] * (freqs[key] - 1)) // 2
print(ans)

Measured memory_bytes: 19300
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int n,tmp;cin>>n;
    vector<int> pile(0);
    vector<int> vec(n);for(int i=0;i<n;i++)cin>>vec[i];
    sort(all(vec),greater<int>());
    for(int i=0;i<n-1;i++){
        tmp=vec[i]-vec[i+1];
        if(tmp%2==1){
            pile.pb(i+1);
        }
    }
    if(vec[n-1]%2==1)pile.pb(n);
    int x=0;
    for(int p:pile){
        x^=p;
    }
    if(x==0)cout<<"second"<<endl;
    else cout<<"first"<<endl;
}


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

int main(){
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int a,b,c,s=0;
  for(int i = 0; i <= A; ++i){
    a = 500*i;
    if(a > X) break;
    for(int j = 0; j <= B; ++j){
      b = 100*j;
      if(a + b > X) break;
      for(int k = 0; k <= C; ++k){
        c = 50*k;
        if(a+b+c == X) ++s;
        if(a+b+c > X) break;
      }
    }
  }
  cout << s <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
using p = pair<int, Int>;
const Int INF = 1e18;


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

    rep(i,T.size()) {
        if(T[i] == '?') T[i] = 'D';
    }

    cout << T << endl;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define ll long long 
using namespace std; 
void solve(); 
int main() 
{ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
  
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("error.txt", "w", stderr); 
    freopen("output.txt", "w", stdout); 
#endif 
  
    int t = 1; 
    // cin >> t; 
    while (t--) { 
        solve(); 
    } 
  
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
    return 0; 
} 

void solve() 
{ 
	int x;
    cin >> x ;

    if (x%10 == 2 || x%10 == 4 || x%10 == 5 || x%10 == 7 || x%10 == 9) {
        cout << "hon\n";
    } else if (x%10 == 0 || x%10 == 1 || x%10 == 6 || x%10 == 8) {
        cout << "pon\n";
    } else {
        cout << "bon\n";
    }
}

Measured memory_bytes: 3772
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    cout << n - k + 1 << endl;
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int main() {
	int N, M;
	cin >> N >> M;

	vector<bool> br(N);
	vector<int64_t> v(N);

	for (int i = 0; i < M; i++) {
		int n;
		cin >> n;
		br[n - 1] = 1;
	}

	for (int i = 0; i < N; i++) {
		if (br[i]) continue;
		if (i == 0) v[i] = 1;
		else if (i == 1) v[i] = v[i - 1] + 1;
		else {
			v[i] = v[i - 1] + v[i - 2];
			v[i] %= MOD;
		}
	}

	//for (int i = 0; i < N; i++) cout << v[i] << ' ';
	//cout << endl;

	cout << v[N - 1] << endl;
}

Measured memory_bytes: 4004
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
        var s string
        var list []string
        var a, b int

        if sc.Scan() {
                s = sc.Text()
                list = strings.Split(s, " ")
        }

        a, _ = strconv.Atoi(list[0])
        b, _ = strconv.Atoi(list[1])

        if a < b {
                if a == 1 {
                        fmt.Println("Alice")
                } else {
                        fmt.Println("Bob")
                }
        } else if a == b {
                fmt.Println("Draw")
        } else {
                if b == 1 {
                        fmt.Println("Bob")
                } else {
                        fmt.Println("Alice")
                }
        }

}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int a,b,c,x,y,z,p;
    scanf("%d %d %d",&a,&b,&c);
    if(a>=b&&a>=c)
    {
        x=a;
        if(b>=c)
        {
            y=b;
            p=c;
        }
        else
        {
            y=c;
            p=b;
        }
    }
    else if(b>=a&&b>=c)
    {
        x=b;
        if(a>=c)
        {
            y=a;
            p=c;
        }
        else
        {
            y=c;
            p=a;
        }
    }
    else if(c>=a&&c>=b)
    {
        x=c;
        if(a>=b)
        {
            y=a;
            p=b;
        }
        else
        {
            y=b;
            p=a;
        }
    }
    z=(x*10)+y;
    printf("%d",z+p);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define NMAX    50000
#define MMAX    20
#define MAX     1000000000

int *c;
int memo[MMAX][NMAX + 1];

int min2(int x, int y) {

    return x < y ? x : y;
}

// 0???m?¨????????????????????????£???n??????????????¨??????????????????????°?????????°???
int dp(int m, int n) {
    int rep;

    if( m < 0 ) return MAX;
    if( memo[m][n] < MAX ) return memo[m][n];

    if( n == 0 ) {
        rep = 0;
    } else if( n < c[m] ) {
        rep = dp(m - 1, n);
    } else {
        rep = min2(dp(m - 1, n), dp(m, n - c[m]) + 1);
    }
    
    return memo[m][n] = rep;
}

void insertsort(int *a, int n) {
    int i, j;

    for( i = 1; i < n; i++ ) {
        int tmp = a[i];
        for( j = i; j > 0 && a[j - 1] > tmp; j-- ) {
            a[j] = a[j - 1];
        }
        a[j] = tmp;
    }

    return;
}

int main(void) {
    int n, m;
    int i, j;

    scanf("%d %d", &n, &m);
    c = (int *)malloc(sizeof(int) * m);
    for( i = 0; i < m; i++ ) {
        scanf("%d", c + i);
        for( j = 0; j <= NMAX; j++ ) {
            memo[i][j] = MAX;
        }
    }
    insertsort(c, m);

    printf("%d\n", dp(m - 1, n));

    free(c);

    return 0;
}

Measured memory_bytes: 4612
#include <iostream>
#include <algorithm>
#include <string>
#include <limits.h>
#include <vector>
#include <numeric>

using namespace std;



bool gooddis(long long int n) {

	long long int a = 0;

	while (n >= a * a) {
		if (n == a * a)return true;
		a++;
	}

	return false;
}


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

	vector<int> h(n);

	for (auto& i : h)cin >> i;

	h[0]--;

	for (int i = 1; i < h.size(); i++) {
		if (h[i] > h[i - 1]) {
			h[i]--;
		}
		else if (h[i] < h[i - 1]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;

}




Measured memory_bytes: 640
#include<stdio.h>
#define MAX 100000

int parent(int i){
    return i/2;
}
int left(int i){
    return 2*i;
}
int right(int i){
    return 2*i+1;
}
int main(){
    int H,i,A[MAX+1];

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

    for(i = 1; i <= H; i++){
        printf("node %d: key = %d, ",i,A[i]);
        if(parent(i) >= 1) printf("parent key = %d, ",A[parent(i)]);
        if(left(i) <= H) printf("left key = %d, ",A[left(i)]);
        if(right(i) <= H) printf("right key = %d, ",A[right(i)]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2112
import numpy as np
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

players = list(np.array([K - len(A)] * N))
for a in A:
    players[a-1] += 1
    
for p in players:
    if p > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 21452
#include<stdio.h>

int main(){
  int N, T, c, t, min = 1001;
  
  scanf("%d %d", &N, &T);
  
  for (int i = 0; i < N; i++){
    scanf("%d %d", &c, &t);
    if(min > c && t <= T){
      min = c;
    }
  }
  if(min == 1001){
    printf("TLE\n");
    return 0;
  }
  
  printf("%d\n", min);
  
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
int n;
int h[100];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i=0;i<n;i++) cin>>h[i];
    int ans=0;
    int count=0;
    int hight=0;
    while(count<n){
        bool s=false;
        for(int i=0;i<n;i++){
            if(s==true&&h[i]<hight){
                s=false;
                ans++;
            }
            if(hight==h[i]){
                count++;
            }
            if(h[i]>=hight){
                s=true;
            }
            if(s==true&&i==n-1&&hight>0){
                ans++;
            }
        }
        hight++;
    }
    cout<<ans<<"\n";
}


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

using namespace std;
typedef long long ll;
const ll mod = 998244353;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  vector<vector<ll>> dp(c + 1, vector<ll>(d + 1));
  dp[a][b] = 1;
  for (int i = a + 1; i <= c; ++i)
    dp[i][b] = dp[i - 1][b] * b % mod;
  for (int j = b + 1; j <= d; ++j)
    dp[a][j] = dp[a][j - 1] * a % mod;
  for (int i = a + 1; i <= c; ++i)
    for (int j = b + 1; j <= d; ++j) {
      dp[i][j] = (dp[i - 1][j] * j + dp[i][j - 1] * i -
                  (i - 1) * (j - 1) * dp[i - 1][j - 1]) %
                 mod;
      if (dp[i][j] < 0)
        dp[i][j] += mod;
    }
  cout << dp[c][d] << endl;
}


Measured memory_bytes: 73424
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;

namespace AtCoderSolve
{
    class Solve
    {

        const int mod = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;


        static int N, W;
        static long[] w, v;
        
        //static long[] A, B;


        public static void Input()
        {
            var cin = new Scanner();
            var input = cin.SplitReader();
            N = input[0];
            W = input[1];
            w = new long[N];
            v = new long[N];
            for(var i = 0; i < N; i++)
            {
                var p = cin.SplitReaderL();
                w[i] = p[0];
                v[i] = p[1];
            }
        }


        static void Main(string[] args)
        {
            Input();

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            long[,] dp = new long[N + 1, W + 1];
            for(var i = 0; i <= W; i++)
            {
                dp[0, i] = 0;
            }

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

            Console.WriteLine(dp[N, W]);

            //Console.Out.Flush();
        }
    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }
}






Measured memory_bytes: 89952
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
using namespace std;
//using namespace boost::multiprecision;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

// Binary Indexed Tree (Fenwick Tree)
template<typename T> // T: type of cost
struct BIT {
    int n;
    vector<T> d;
    BIT(int n=0):n(n),d(n+1) {}
    //配列のインデックスiの要素d[i]に対して、xを加算する。
    void add(int i, T x=1) {
        for (i++; i <= n; i += i&-i) {
            d[i] += x;
        }
    }
    //配列においてインデックスがi以下の要素d[j]たちの和を計算して返す。
    T sum(int i) {
        T x = 0;
        for (i++; i; i -= i&-i) {
            x += d[i];
        }
        return x;
    }
};

int main(){
  
  long long n;
  cin>>n;
  long long a[n];
  REP(i,n){
    cin>>a[i];
    //cout<<a[i]<<' ';
  }
  //cout<<endl;
  long long all_ms = ((n+1)*n)/2;
  long long l = 0, r = 1'000'000'001;//[l,r):答えとなる中央値の取りうる範囲
  while(r - l > 1){
    //cout<<"iteration"<<endl;
    //cout<<l<<' '<<r<<endl;
    long long x = (l + r)/2;
    long long ta[n];
    REP(i,n){
      if(a[i] >= x){
        ta[i] = 1;
      }else{
        ta[i] = -1;
      }
      //cout<<ta[i]<<' ';
    }
    //cout<<endl;
    long long s[n+1] = {};
    REPP(i,n){
      if(i == 1){
        s[i] = ta[i-1];
      }else{
        s[i] = s[i-1] + ta[i-1];
      }
    }
    long long cnt = 0;
    BIT<long long> tree(2*n+1);
    REP(i,n+1){
      if(i == 0){
        tree.add(s[i] + n);
      }else{
        tree.add(s[i] + n);
        cnt += tree.sum(s[i]+n);
        cnt--;
      }
    }
    long long half = (all_ms + 1)/2;
    //cout<<"count: "<<cnt<<endl;
    if(cnt >= half){
      l = x;
    }else{
      r = x;
    }
  }
  //cout<<"answer: ";
  cout<<l<<endl;
  return 0; 
}

Measured memory_bytes: 4200
import java.util.ArrayList;
import java.util.Scanner;

public class Main{
	public static void main(String args[]) {
		ArrayList<Long> yaku = new ArrayList<Long>();

		Scanner scn = new Scanner(System.in);
		long p = scn.nextLong(), q = scn.nextLong();
		scn.close();
		long qs;
		long ans = 1;
		long bp = p,bq = q,buf = p;

		while(bq % bp != 0) {
			buf = bq % bp;
			bq = bp;
			bp = buf;
		}
		qs = q/buf;
		for(long i = 2;i <= Math.sqrt(qs);i++) {
			if(qs % i ==0) {
				while(qs % i == 0) {
					qs /=i;
				}
				ans *= i;
			}
		}
		ans*= qs;
		System.out.println(ans);
	}
}


Measured memory_bytes: 26364
main = solve (0,0,0,0) <$> getLines >>= printAll

getLines = tail . lines <$> getContents

printAll (a, b, c, d) = do
    putStrLn $ "AC x "  ++ show a
    putStrLn $ "WA x "  ++ show b
    putStrLn $ "TLE x " ++ show c
    putStrLn $ "RE x "  ++ show d

solve x [] = x
solve (a,b,c,d) (e:l) = case e of
    "AC"  -> solve (a+1,b,c,d) l
    "WA"  -> solve (a,b+1,c,d) l
    "TLE" -> solve (a,b,c+1,d) l
    "RE"  -> solve (a,b,c,d+1) l


Measured memory_bytes: 11056
n=int(input())
A=list(map(int,input().split()))
counter=0
for i in range(n):
    minj=i
    for j in range(i,n):
        if A[j] < A[minj]:
            minj=j
    if i!=minj:
        tmp=A[i]
        A[i]=A[minj]
        A[minj]=tmp
        counter+=1
for k in range(len(A)):
    if k != len(A)-1:
        print(A[k],end=' ')
    else:
        print(A[k])
print(counter)


Measured memory_bytes: 5600
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int main(){
	int N;
	cin>>N;
	for(int ds=0;ds<N;ds++){
		if(ds!=0) puts("");
		int fld[9][9];
		int cntX[9][9] = {}, cntY[9][9] = {}, cntA[9][9]={};
		for(int i=0;i<9;i++){
			for(int j=0;j<9;j++){
				cin>>fld[i][j]; fld[i][j]--;
				cntY[i][fld[i][j]]++;
				cntX[j][fld[i][j]]++;
				cntA[(i/3)*3+j/3][fld[i][j]]++;
			}
		}

		for(int i=0;i<9;i++){
			for(int j=0;j<9;j++){
				if(cntY[i][fld[i][j]]>1 || cntX[j][fld[i][j]]>1 ||
				   cntA[(i/3)*3+j/3][fld[i][j]]>1)
					printf("*");
				else printf(" ");
				printf("%d",fld[i][j]+1);
			}puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 1152
from sys import stdin

N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()
dp = [[0] * (N + 1) for _ in range(N + 1)]
res = 0

for i in range(1, N):
    for j in range(i):
        if S[i] == S[j]:
            dp[i][j] = dp[i - 1][j - 1] + 1
        res = max(res, min(i - j, dp[i][j]))

print(res)


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

int main() {
  int N,M;cin>>N>>M;
  vector<vector<int> >s(M);
  for (int i=0;i<M;++i){
    int k;cin>>k;
    for (int j=0;j<k;++j){
      int a;cin>>a; --a;
      s[i].push_back(a);
    }
  }
  vector<int>p(M);
  for (int i=0;i<M;++i)cin>>p[i];
  
  long long res=0;
  for (int b=0;b<(1<<N);++b){
    bool ok=true;
    for(int i=0;i<M;++i){
      int con=0;
      for (auto v:s[i]){
        if (b&(1<<v)) ++con;
      }
      if (con%2!=p[i])ok=false;
    }
    if (ok) ++res;
  }
  cout<<res<<endl;
}
  

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

int N, T, A[MAXN + 3], B[MAXN + 3], dp[MAXN + 3][MAXN + 3][2];

int solve(int idx, int timeLeft, int hasTakenLastMeal) {
    if (idx == N + 1)
        return 0;

    if (dp[idx][timeLeft][hasTakenLastMeal] != -1)
        return dp[idx][timeLeft][hasTakenLastMeal];

    int takeLastMeal = (hasTakenLastMeal == 0 ? B[idx] + solve(idx + 1, timeLeft, 1) : 0);
    int take = (timeLeft >= A[idx] ? B[idx] + solve(idx + 1, timeLeft - A[idx], hasTakenLastMeal) : 0);
    int leave = solve(idx + 1, timeLeft, hasTakenLastMeal);

    return dp[idx][timeLeft][hasTakenLastMeal] = max(takeLastMeal, max(take, leave));
}

int main() {
    cin >> N >> T;
    for (int i = 1; i <= N; i++)
        cin >> A[i] >> B[i];

    memset(dp, -1, sizeof(dp));

    cout << solve(1, T - 1, 0) << endl;
}


Measured memory_bytes: 70912
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int num = scanner.nextInt();
		long sum = 0;
		if (num > 0 && num <= 10000) {
			long array[] = new long[num];
			for (int i = 0; i < num; i++) {
				array[i] = scanner.nextLong();
				if (array[i] >= -1000000 && array[i] <= 1000000) {
					sum += array[i];
				}
			}
			Arrays.sort(array);
			System.out.println(array[0] + " " + array[num - 1] + " " + sum);
		}
	}
}

Measured memory_bytes: 41572
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> A(N);
    for (int i = 0; i < N; i++)
    {
        int K;
        cin >> K;
        vector<int> a(K);
        for (int j = 0; j < K; j++)
        {
            cin >> a[j];
        }
        A[i] = a;
    }
    int ans = 0;
    for (int i = 1; i <= M; i++)
    {
        bool flag = true;
        for (int j = 0; j < N; j++)
        {
            if (count(A[j].begin(), A[j].end(), i) == 0)
            {
                flag = false;
                break;
            }
        }
        if (flag)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
  l = input().split()
  
  a = int(l[0])
  o = l[1]
  b = int(l[2])
  
  if o =='?':
    break
 
  if o == '+':
    print( '%d'%(a+b))
  elif o == '-':
    print('%d'%(a-b))
  elif o =='*':
    print('%d'%(a*b))
  else:
    o =='/'
    print('%d'%(a//b))


Measured memory_bytes: 5596
import Data.List
main = getLine >>= main' . read . last . words
    where
        main' t = getLine >>= print . solve (t `div` 2) . map read . words

solve :: Int -> [Int] -> Int
solve t = {-min t .-} snd . foldl' ff (0, 0) . snd . build
    where
        ff (v, n) x
            | v < x = (x, 1)
            | v == x = (v, n + 1)
            | otherwise = (v, n)

        build (z : zs)
            | z > x = (z, 0 : zs')
            | otherwise = (x, (x - z) : zs')
            where
                (x, zs') = build zs

        build _ = (0, [])


Measured memory_bytes: 36348
using System;
using System.Linq;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int[] arr = new int[] { int.Parse(input[0]), int.Parse(input[1]), int.Parse(input[2]) };
    Console.WriteLine(arr.Max() - arr.Min());
  }
}


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

const char NL = '\n';
const int MOD = 1e9 + 7;

void solve()
{
    int n, k; cin >> n >> k;
    vector<int> v;
    for (int i = 0; i < n; ++i) {
        int h; cin >> h;
        v.push_back(h);
    }
    vector<int> dp(n, 0);
    dp[1] = abs(v[1] - v[0]);
    for (int i = 2; i < n; ++i) {
        int minCost = INT_MAX;
        for (int j = max(0, i - k); j < i; ++j) {
            int cost = dp[j] + abs(v[i] - v[j]);
            minCost = min(minCost, cost);
        }
        dp[i] = minCost;
    }
    cout << dp[n - 1] << NL;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 4264