akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{

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

ll lcm(ll a,ll b)
{
    return (a/(gcd(a,b)))*b;

}
int main()
{

    //  #ifndef oj
    //freopen("in", "r", stdin);
    //freopen("out.txt","w",stdout);
    //#endif
    // system("cls");
    //getchar();

    ll n;
    cin>>n;
    ll arr[n];

    for(int i=0;i<n;i++)
        cin>>arr[i];

    int pos=1,cnt=0;

    for(int i=0;i<n;i++)
    {
        if(arr[i]==pos)
        {
            pos++;
            cnt++;
        }
    }
    if(pos >1)
        cout<<n-cnt<<endl;
    else
        cout<<-1<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
 #include<vector>
 #include<math.h>
 // #include <ext/pb_ds/tree_policy.hpp>
 // #include <ext/pb_ds/assoc_container.hpp>
 // #include<chrono>
 using namespace std;
 // using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define int         long long 
 #define vii        vector<int>
 #define big        1e18


  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
   
    #endif
}


void solve()
{
 
 int n;
 cin >> n ;
 int x[n],open[n],close[n];

 forf(i,0,n) 
 {
  cin >> open[i] >> close[i];

}

// if(n==1)
// {
//   cout<<close[0]-open[0]+1;
//   return ;
// }
 

 sort(open,open+n);
 sort(close,close+n);
 
 int an;
 if(n%2==0)
 { 
   an = close[n/2]+close[n/2-1] - open[n/2]-open[n/2-1]+1;

 }else
 {
   an = close[n/2] - open[n/2] +1;
 }

  cout<<an<<endl;

}

int32_t main()
{
  pr_init();
  fastio;
  
  
  solve();
  
 }


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

int main(){


    int Q = 0;

    cin >> Q;

    for(int i=0; i<Q; i++){
        int c,a,n;

        cin >> c >> a >> n;

        if(c == 0 || (c < 2 && a == 0) || (c == 0 && a == 0 && n == 0)){
          cout << 0 << endl;
          continue;
        }

        int answer = 0;

        while(c > 0 && a > 0 && n > 0){
          answer++;
          c--;
          a--;
          n--;
        }


        while(c > 1 && a > 0){
          answer++;
          c -= 2;
          a--;
        }

        if(c > 2){
          answer += c/3;
        }
        cout << answer << endl;

    }


    return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

struct point {
    int vertex, silver;
};

struct edge {
    point to;
    int cost;
};

int main() {
    int N, M, S;
    cin >> N >> M >> S;
    int A = 2500;
    S = min(S, A);
    vector<vector<vector<edge>>> G(N, vector<vector<edge>>(A + 1));
    for (int i = 0; i < M; i++) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;
        v--;
        for (int j = a; j <= A; j++) {
            G[u][j].push_back(edge{point({v, j - a}), b});
            G[v][j].push_back(edge{point({u, j - a}), b});
        }
    }

    for (int i = 0; i < N; i++) {
        int c, d;
        cin >> c >> d;
        for (int a = 0; a <= A; a++) {
            int s = min(A, a + c);
            if (s != a) {
                G[i][a].push_back(edge{point({i, s}), d});
            }
        }
    }

    vector<vector<ll>> dist(N, vector<ll>(A + 1, 1e18));
    dist[0][S] = 0;
    auto compare = [&](const pair<ll, point>& a, const pair<ll, point>& b) {
        return a.first > b.first;
    };
    priority_queue<pair<ll, point>, vector<pair<ll, point>>, decltype(compare)> que{compare};
    que.push({0, point({0, S})});
    while (!que.empty()) {
        auto [d, now] = que.top();
        que.pop();
        if (d > dist[now.vertex][now.silver]) {
            continue;
        }
        for (auto e : G[now.vertex][now.silver]) {
            if (dist[e.to.vertex][e.to.silver] > d + e.cost) {
                dist[e.to.vertex][e.to.silver] = d + e.cost;
                que.push({d + e.cost, e.to});
            }
        }
    }

    vector<ll> ans(N, 1e18);
    for (int i = 1; i < N; i++) {
        for (int a = 0; a <= A; a++) {
            ans[i] = min(ans[i], dist[i][a]);
        }
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 20528
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int res[11][100];

int pr(int n,int m,int i){
	res[n+1][m+i]++;
	if(i<9){
		pr(n+1,m+i,i+1);
		pr(n,m,i+1);
	}
	return 0;
}

int main() {
	pr(0,0,0);
	int n,s;
	/*for(int i=0;i<10;i++){
		for(int j=0;j<100;j++){
			cout<<res[i][j]<<" ";
		}
		cout<<endl;
	}*/
	for(;n=in(),s=in(),n;){
		if(s<100&&n<11){cout<<res[n][s]<<endl;}
		else {cout<<0<<endl;}
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int A[100000];
int n;

int par(int p,int r){
  int x,i,j,t;
  i=p-1;
  x=A[r];
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;

  return i+1;
}

int main(){
  int i,q;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  q=par(0,n-1);
  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==q)printf("[");
    printf("%d",A[i]);
    if(i==q)printf("]");
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 992
#include<iostream>
#include<vector>
#include<string>
#include <algorithm>
#include <queue>
#include <climits>
#include<cmath>
#include <sstream>
#include <iomanip>

bool sort_pair( std::pair< int64_t, std::string > origin, std::pair< int64_t, std::string > another )
{
    return origin.first < another.first;
}


int main()
{
    std::string a,b;
    std::cin>> a;
    b = "Yes";
    
    for( int i = 0; i < a.size(); i++ )
    {
        if( ( i + 1 ) % 2 == 0 )
        {
            if( a[i] == 'R' )
            {
                b = "No";
                break;
            }
        }
        else
        {
            if( a[i] == 'L' )
            {
                b = "No";
                break;
            }
        }
    }

    std::cout<< b;
}


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

#include <iostream>
#include <fstream>

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

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(),(x).end()
//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;
void _mod(ll &x){x = mod(x, MOD);}
//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}


//#define int ll

class A2FightingOverCandies {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int a,b,c;
    cin >> a >> b >> c;
    if(abs(a-b) == c || a+b == c)cout << "Yes\n";
    else cout << "No\n";
}
};


#undef int
int main() {
	A2FightingOverCandies 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>
/// TONI BO$$ was here
/// #MLC

using namespace std;
vector <string> v;
int main()
{
    int n,i,j,rez;
    cin>>n;
    string s;
    while(n--)
    {
        cin>>s;
        v.push_back(s);
    }
    sort(v.begin(),v.end());
    n=v.size();
    for(i=0,rez=0; i<n; rez++)
    {
        j=i;
        while(j<n && v[j]==v[i]) j++;
        i=j;
    }
    printf("%d",rez);

    return 0;
}


Measured memory_bytes: 11600
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;


public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] abk = br.readLine().split(" ");
        int a = Integer.parseInt(abk[0]);
        int b = Integer.parseInt(abk[1]);
        int k = Integer.parseInt(abk[2]);
        
        
        for (int i = 0; i < k; i++) {
            if (i % 2 == 0) {
                if (a % 2 != 0) {
                    a--;
                }
                a /= 2;
                b += a;
            }
            else {
                if (b % 2 != 0) {
                    b--;
                }
                b /= 2;
                a += b;
            }
        }
        
        System.out.println(a + " " + b);
    }
}


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

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

  sort(v.begin(),v.end());

  double ans=v.at(0);
  for(int i=1;i<N;i++){
    ans = (ans+v.at(i))/2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) (a<<b)
#define Rshift(a,b) (a>>b)
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;

vector<int> in;

int main() {
    int n, i, j;
    cin >> n;
    in.resize(n);
    rep(i, n) {
        cin >> in[i];
    }
    vector<int> res;
    for (i = n; i; i--) {
        for (j = in.size() - 1; j >= 0; j--) {
            if (in[j] == j + 1) {
                in.erase(in.begin() + j);
                res.pb(j + 1);
                break;
            }
        }
        if (j < 0) {
            cout << -1 << endl;
            return 0;
        }
    }
    for (i = n - 1; i >= 0; i--) {
        cout << res[i] << endl;
    }
}


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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

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 solver() {
    i64 a;
    long double b;
    cin >> a >> b;

    cout << i64(floor(a * b)) << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3756
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int sum[100002] = {0};

signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int2(n, t);
    rep(i, n){
      int2(x, y);
      ++sum[x]; --sum[y];
    }

    int ma = sum[0];
    rep1(i, t + 1){
      sum[i] += sum[i - 1];
      ma = max(ma, sum[i]);
    }

    pri(ma);

/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,W;
struct item{
    ll Wt;
    ll val;
};
ll solve(vector<item> v){
    ll dp[n+1][W+1];
    for(ll i=0;i<=W;i++){
        dp[1][i]=0;
    }

    dp[1][v[1].Wt]=v[1].val;
    for(ll i=2;i<=n;i++){
        for(ll w=0;w<=W;w++){
            dp[i][w]=dp[i-1][w];
            if(w<v[i].Wt){continue;}
            dp[i][w]=max(dp[i][w],dp[i-1][w-v[i].Wt]+v[i].val);
        }
    }

   

    return *max_element(dp[n],dp[n]+W+1);
}
int main(){
    
    cin>>n>>W;
    vector<item> v(n+1);
    for(ll i=1;i<=n;i++){
        cin>>v[i].Wt>>v[i].val;
    }
    
    cout<<solve(v);
    return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
#define ul unsigned long long
#define ll long long

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

  return 0;
}



Measured memory_bytes: 3192
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int a,b,t;
    cin >> a >> b >> t;
    int sum = 0;
    for(int i=a;i<=t+0.5;i+=a){
        sum+=b;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

    int N,K;

    scanf("%d", &N);
    scanf("%d", &K);

    char str[N];

    scanf("%s", str);

    if(str[K-1] == 'A'){
        str[K - 1] = 'a';
    }else if(str[K-1] == 'B'){
        str[K - 1] = 'b';
    }else if(str[K-1] == 'C'){
        str[K - 1] = 'c';
    }

    printf("%s", str);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
const ll mod = 1e9+7;

ll power(ll a,ll b) {
    ll res = 1;
    while(b) {
        if(b&1) {
            res = (res*a)%mod;
        }
        a = (a*a)%mod;
        b >>= 1;
    }
    return res;
}

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    vector<ll> a(N);
    map<int,int> mp;
    for(int i=0;i<N;i++) {
        cin >> a[i];
        mp[a[i]] += 1;
    }
    map<int,int> :: iterator it;
    map<int,ll> contri;
    ll ans = 0;
    for(it = mp.begin();it!= mp.end();it++) {
        ll x = it->second;
        ans += (x*(x-1))/2;
        contri[it->first] = (x*(x-1))/2;
    }
    for(int i=0;i<N;i++) {
        ll x = mp[a[i]] - 1;
        cout << ans - (contri[a[i]] - (x*(x-1))/2) << endl;
    }
    return 0;
}


Measured memory_bytes: 17024
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
import networkx as nx
def resolve():
    n = int(input())
    A = [tuple(map(int, input().split())) for _ in range(n)]
    B = [tuple(map(int, input().split())) for _ in range(n)]
    G = nx.Graph()
    G.add_nodes_from(range(n))
    G.add_nodes_from(range(n, 2 * n))
    for i in range(n):
        ax, ay = A[i]
        for j in range(n):
            bx, by = B[j]
            if ax < bx and ay < by:
                G.add_edge(i, n + j)

    A = nx.algorithms.bipartite.matching.hopcroft_karp_matching(G, top_nodes = range(n))
    print(len(A) // 2)
resolve()

Measured memory_bytes: 54052
class in { // Range Iterator
  struct _Impl {
    int it;const bool rev;
    explicit constexpr _Impl(int it_, bool rev=false):it(it_), rev(rev) {}
    int operator*() { return it; }
    bool operator!=(_Impl& r) { return it!=r.it; }
    void operator++() { rev?--it:++it; }
  };
  const _Impl i,n;
public:
  explicit constexpr in(int n): i(0), n(n<0?0:n) {}
  explicit constexpr in(int i, int n): i(i,n<i), n(n) {}
  const _Impl& begin() { return i; }
  const _Impl& end() { return n; }
};

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

using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using usize = uint64_t;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    i32 n, m;
    cin >> n >> m;
    vector<i32> a(n, 0);
    for (int i : in(n)) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    i32 sum = accumulate(a.begin(), a.end(), 0);
    if (f64(a[n - m]) < f64(sum) / (m * 4) ) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

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

#define debug(a) cerr << #a << ": " << a << endl
#define int long long
#define ii pair<int,int>

const int maxn = 150001;

string s, t;
set<int> v[26];

int32_t main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);

      cin >> s >> t;
      int rep = 0;
      for(int i = 0; i < s.size(); i++)
      {
            v[s[i] - 'a'].insert(i);
      }
      int prev = -1;
      for(int i = 0; i < t.size(); i++)
      {
            int  now = t[i] - 'a';
            auto it = v[now].lower_bound(prev + 1);
            if(it == v[now].end() and v[now].size() == 0)
            {
                  cout << -1;
                  return 0;
            }
            else if(it == v[now].end())
            {
                  rep++;
                  prev = *v[now].begin();
            }
            else
            {
                  prev = * it;
            }

      }
      cout<< rep * s.size() + prev + 1;

      return 0;
}


Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N;
  long A;
  long B;
  cin >> N >> A >> B;
  long ans;
  long shou;
  long amari;
  shou = N / (A+B);
  amari = N %  (A+B);
  ans += shou*A;  
    if (amari < A) {
     ans += amari;
  }else{
    ans += A;
    }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

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 (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n, C; cin >> n >> C;
    vvint cost(C, vint(C));
    rep(i, C) {
        rep(j, C) {
            int c; cin >> c;
            cost[i][j] = c;
        }
    }
    vvint c(n, vint(n));
    rfor(v, c) vin(v);
    vvint cnts(3, vint(C, 0));
    vvint color(3);
    rep(i, n) {
        rep(j, n) {
            color[(i + j) % 3].push_back(c[i][j]);
            cnts[(i + j) % 3][c[i][j] - 1]++;
        }
    }


    int ans = INT_MAX;
    rep(i, C) rep(j, C) if(i != j) rep(k, C) if(j != k && k != i) {
        int res = 0;
        rep(x, C) res += cnts[0][x] * cost[x][i];
        rep(x, C) res += cnts[1][x] * cost[x][j];
        rep(x, C) res += cnts[2][x] * cost[x][k];
        chmin(ans, res);
    }
    print(ans);




    return 0;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

signed main() {
  int N = read();
  vector<string> citys;
  vi scores;
  vi indices(N);
  iota(ALL(indices), 0);
  REP(i, N) {
    citys.PB(readString());
    scores.PB(read());
  }
  sort(ALL(indices),
       [&citys](size_t i1, size_t i2) { return citys[i1] < citys[i2]; });
  sort(ALL(indices), [&scores, &citys](size_t i1, size_t i2) {
    if (citys[i1] == citys[i2])
      return scores[i1] > scores[i2];
    else
      return citys[i1] < citys[i2];
  });
  REP(i, N) { print(indices[i] + 1); }
}


Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <random>
#include <iomanip>
#include <functional>
#include <list>
#include <unordered_map>
#include <sstream>
#include <istream>
#include <iterator>
#include <numeric>
using namespace std;

int main()
{
	int x, y;
	cin >> x >> y;

	cout << x + y / 2;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  char c;
  cin >> c;
  string S = "aeiou";
  for(int i=0; i<5; ++i){
    if(c == S[i]){
      cout << "vowel" << endl;
      return 0;
    }
  }
  cout << "consonant" << endl;
}

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

ll mul(ll a, ll b) {
    ll r = 0;
    a %= mod;
    while (b) {
        if (b & 1) {
            r = (r + a) % mod;
        }
        a = (a + a) % mod;
        b /= 2;
    }
    return r;
}

ll power(ll x, ll n) {
    ll res = 1;
    x %= mod; 
    while (n > 0)  
    {  
        if (n & 1)  res = (res*x)%mod;  
        n = n>>1; 
        x = (x*x)%mod;  
    }  
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> f(n+1, 0);
    for(int i=0; i<n; i++) {
        cin >> a[i];
        f[a[i]]++;
    }
    ll answer = 0;
    vector<ll> c = a;
    sort(c.begin(), c.end());
    for(int i=0; i<n;) {
        ll count = 0, itr = c[i];
        while(itr == c[i]) {
            count++;
            i++;
        }
        answer += (count*(count-1))/2;
    }
    for(int i=0; i<n; i++) {
        cout << answer - (f[a[i]]-1) << "\n";
    }
    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  if(n==1){
    cout << 1 << endl;
  }
  else if(n<4){
    cout << 2 << endl;
  }
  else if(n<8){
    cout << 4 << endl;
  }
  else if(n<16){
    cout << 8 << endl;
  }
  else if(n<32){
    cout << 16 << endl;
  }
  else if(n<64){
    cout << 32 << endl;
  }
  else{
    cout << 64 << endl;
  }
}

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

# F(A, B)を定義する
def F(A, B):
    A = str(A)
    B = str(B)
    if len(A) >= len(B):
        return len(A)
    else:
        return len(B)

minimumList = []
for a in range(1, int(N**0.5) + 1):
    if N % a == 0:
        b = N // a  # 商
        minimumList.append(F(a, b))
print(min(minimumList))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1e15;
const int MOD = 1000000007;

const int MAX_V = 1024;
const int MAX_E = 2048;

struct edge {int from, to; ll cost;};

edge es[MAX_E];

ll dis[MAX_V];
int V, E;
//負の閉路が存在すればtrueを返す
bool bellmanford(int s) {
    rep(V, v) dis[v] = INF;
    dis[s] = 0LL;
    rep(V, i) {
        rep(E, e) {
            edge ne = es[e];
            if (dis[ne.to] > dis[ne.from] + ne.cost) {
                dis[ne.to] = dis[ne.from] + ne.cost;
                if (i == V-1 and ne.to == V-1) return true;
            }
        }
    }
    return false;
}
//abc061d
void solve(void){
    cin >> V >> E;
    rep(E, e){
        int a, b;ll c;
        scanf("%d %d %lld\n", &a, &b, &c);
        a--; b--;
        es[e] = edge {a, b, -c};
    }
    if (bellmanford(0)) cout << "inf" << endl;
    else cout << -dis[V-1] << endl;
}

int main(void){
  solve();
  return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int p = max(a,max(b,c));
  int r = min(a,min(b,c));
  int q = (a+b+c) - (p+r);
  int n = p-q;
  int m = p-r;
  if((n+m)%2==0) cout << (n+m)/2 << endl;
  else cout << (n+m+3)/2 << endl;
  return 0;
}

Measured memory_bytes: 256
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const ll mod = 1e9 + 7 ;
const ll inf = 1e18L + 5; 
void add_self(ll& a , ll b){a =  (a + b)%mod;}
//#define (x)  get<0>(x) 
//#define (x)  get<1>(x)
//#define (x)  get<2>(x)
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

ll n , w ; 
cin>>n>>w ; 
vector<vector<ll>>v(n,vector<ll>(2));
for(auto &i:v)cin>>i[0]>>i[1];
// for(auto i:v)for(auto j:i)cout<<j<<endl;
ll maxValue = 	0  ;
for(auto i:v){
	// for(auto j:i){
	maxValue+=i[1];
	// }
}
// cout<<maxValue;


vector<ll>dp(maxValue+1,inf) , newdp(maxValue + 1 ,inf) ; 

for(ll item  = 0 ; item <n ; item ++){
	newdp[v[item][1]] = min(newdp[v[item][1]], v[item][0]);
	// cout<<newdp[v[item][1]]<<endl;
for(ll value = v[item][1] + 1; value <= maxValue ; value ++ ){
newdp[value] = min(dp[value] , dp[value - v[item][1]] + v[item][0]);
// cout<<newdp[value]<<endl;
}
dp = newdp;
}
ll ans  = 0 ,newans = 0;
for(ll i = 0 ;i<=maxValue; i++){
	if(dp[i]<=w){
		ans = max(ans , dp[i]);
		newans = i;
	}
}
cout<<newans;





	
}

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int f[60][60],a[60],b[60]; 
int n,ans[60],tot;
bool solve(int mx)
{
	memset(f,0,sizeof(f));
	for (int i=0;i<=50;i++)
	{
		f[i][i]=1;
		for (int j=1;j<mx;j++) f[i][i%j]=1;
		for (int j=1;j<=tot;j++) f[i][i%ans[j]]=1;
	}
	for (int k=0;k<=50;k++)
		for (int i=0;i<=50;i++)
			for (int j=0;j<=50;j++) f[i][j]|=f[i][k]&f[k][j];
	bool p=1;
	for (int i=1;i<=n;i++)
		p&=f[a[i]][b[i]];
	return p; 
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) scanf("%d",&b[i]);
	for (int i=50;i>=1;i--)
		if (!solve(i)) ans[++tot]=i;
	long long cnt=0;
	for (int i=1;i<=tot;i++) cnt+=1ll<<ans[i];
	if (tot==50)printf("-1");
	else printf("%lld",cnt);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int Left = a + b;
  int Right = c + d;
  if( Left > Right  )
  {
    cout << "Left" << endl;
  }
  else if ( Left == Right  )
  {
    cout << "Balanced" << endl;
  }
  else if ( Left < Right  )
  {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

        map<ll, ll> mp;
        ll ans = 0;
        rep (i, n) {
                int a;
                cin >> a;

                ans += mp[a - i];
                mp[-a - i]++;
        }

        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 26236
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

from collections import deque
from heapq import *

def main():
	n=II()
	A=LI()

	X=A[:n]
	Y=[-i for i in A[2*n:]]
	M=A[n:2*n]

	heapify(X)
	heapify(Y)

	xs=sum(X)
	ys=sum(Y)
	XX=[xs]
	YY=[ys]

	for i in M:
		heappush(X,i)
		a=heappop(X)
		xs+=+i-a
		XX.append(xs)

	for i in reversed(M):
		heappush(Y,-i)
		a=heappop(Y)
		ys+=-i-a
		YY.append(ys)

	ans=-10**18

	for i,j in zip(XX,YY[::-1]):
		ans=max(ans,i+j)

	print(ans)
if __name__ == "__main__":
	main()


Measured memory_bytes: 118168
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std ;
int main(){
   int n, k, x, y;
   cin >> n >> k >> x >> y;
  
   if(n > k){
       cout << k*x + (n-k)*y << endl;
   }else{
       cout << n*x << endl;
   }
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include <set>
#include <queue>
#include <iomanip>
#include <sstream>
typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}

int main() {
	cin >> n;
	vector<ll> b(n + 1);
	stack<ll> bp;
	for (ll i = 1; i <= n; i++) {
		cin >> b[i];
	}
	while (n >= 1) {
		ll flg = 0;
		for (ll i = n; i > 0; i--) {
			if (b[i] == i) {
				bp.push(i);
				b.erase(b.begin() + i);
				flg = 1;
				--n;
				break;
			}
		}
		if (!flg) {
			cout << -1 << endl;
			return 0;
		}
	}
	while (!bp.empty()) {
		cout << bp.top() << endl;
		bp.pop();
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] c = new char[H][W];
		int n = H * W;
		int[] d  = new int[n];
		for(int i = 0; i < H; i++) {
			String s = sc.next();
			for(int j = 0; j < W; j++) {
				c[i][j] = s.charAt(j);
				int idx = i * W + j;
				if(c[i][j] == '#') {
					d[idx] = 0;
				}else {
					d[idx] = 1;
				}
			}
		}
		sc.close();
		DisjointSet ds = new DisjointSet(n);

		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				if(i + 1 < H && c[i][j] != c[i + 1][j]) {
					ds.unite(W * i + j, W * (i + 1) + j);
				}
				if(j + 1 < W && c[i][j] != c[i][j + 1]) {
					ds.unite(W * i + j, W * i + j + 1);
				}
			}
		}

		long ans = 0;
		long[] b = new long[n];
		long[] w = new long[n];
		for(int i = 0; i < n; i++) {
			if(d[i] == 0) {
				b[ds.findSet(i)]++;
			}else {
				w[ds.findSet(i)]++;
			}
		}
		for(int i = 0; i < n; i++) {
			ans += b[i] * w[i];
		}
		System.out.println(ans);
	}
	static class DisjointSet {
        int[] p;
        int[] rank;
        int[] size;
        DisjointSet(){}
        DisjointSet(int size){
            this.rank = new int[size];
            this.p = new int[size];
            this.size = new int[size];
            for(int i = 0; i < size; i++) {
                makeSet(i);
            }
        }
        void makeSet(int x) {
            p[x] = x;
            rank[x] = 0;
            size[x] = 1;
        }
        boolean same(int x, int y) {
            return findSet(x) == findSet(y);
        }
        void unite(int x, int y) {
            link(findSet(x), findSet(y));
        }
        void link(int x, int y) {
            if(rank[x]  > rank[y]) {
                p[y] = x;
                size[x] = size[x] + size[y];
            }else if(rank[x] < rank[y]){
                p[x] = y;
                size[y] = size[x] + size[y];
            }else if(x != y) {
            	p[y] = x;
            	rank[x]++;
            	size[x] = size[x] + size[y];
            }
        }
        int findSet(int x) {
            if(x != p[x]) {
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
        int size(int x) {
        	if(x != p[x]) {
        		size[x] = size(findSet(x));
        	}
        	return size[x];
        }
    }
}

Measured memory_bytes: 32584
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<numeric>
//#include <bits/stdc++.h>
#include<cstring>
#include<iostream>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<char> s(N);
	for (int i = 0; i < N; i++)
		cin >> s[i];
	for (int i = 0; i < N; i++)
		if (s[i] == 'Y') {
			cout << "Four" << endl;
			//cin >> N;
			return 0;
		}
	cout << "Three" << endl;
	//cin >> N;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <map>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;

int main()
{
	map<string, int> m;
	string best;
	string longest;
	
	char word[33];
	while(scanf("%s", word) != EOF){
		string s(word);
		if(m.count(s))
			m[s]++;
		else
			m[s] = 1;

		if(m[best] < m[s])
			best = s;
		if(longest.size() < s.size())
			longest = s;
	}
	printf("%s %s\n", best.c_str(), longest.c_str());

	return 0;
}

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

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

    vector<int> p(n);
    for(int i=0; i<n; i++){
        cin >> p[i];
    }
    sort(p.begin(), p.end());

    int ans = 0;
    for(int i=0; i<n-1; i++){
        ans += p[i];
    }
    ans += p[n-1] / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

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

int n;
ll c;
ll x[105000];
int v[105000];
ll tokei[105000];
ll hantokei[105000];
ll mx_to[105000];
ll mx_han[105000];

int main()
{
	cin >> n >> c;
	ll xi; int vi;
	for (int i = 1; i <= n; i++) {
		cin >> xi >> vi;
		x[i] = xi; v[i] = vi;
	}
	x[0] = 0; x[n + 1] = c;
	
	tokei[0] = 0;
	for (int i = 1; i <= n; i++) {
		tokei[i] = tokei[i - 1] + v[i] - (x[i] - x[i - 1]);
	}

	hantokei[n+1] = 0;
	for (int i = n; i >=1; i--) {
		hantokei[i] = hantokei[i + 1] + v[i] + (x[i] - x[i + 1]);
	}

	ll tmx = 0;
	ll hmx = 0;
	for (int i = 1; i <= n; i++) {
		tmx = max(tmx, tokei[i]);
		mx_to[i] = tmx;
	}
	for(int i=n+1;i>=1;i--){
		hmx = max(hmx, hantokei[i]);
		mx_han[i] = hmx;
	}

	//tokei->hantokei
	ll thmx = 0;
	for (int i = 0; i <= n; i++) {
		ll iki = tokei[i] - x[i];
		ll cur = iki + mx_han[i + 1];
		thmx = max(thmx, cur);
		//cout << i << " " << iki << " " << mx_han[i + 1] << " " << cur << " " << thmx << endl;
	}

	//hantokei->tokei
	ll htmx = 0;
	for (int i = n + 1; i >= 1; i--) {
		ll iki = hantokei[i] - (c - x[i]);
		ll cur = iki + mx_to[i - 1];
		htmx = max(htmx, cur);

		//cout << i << " " << iki << " " << mx_to[i + 1] << " " << cur << " " << htmx << endl;
	}
	/*
	cout << "tokei[i]:" << " ";
	for (int i = 0; i <= n; i++) {
		cout << tokei[i] << " " ;
	}
	cout << endl;
	cout << "hantokei[i]:" << " ";
	for (int i = n + 1; i >= 1; i--) {
		cout << hantokei[i] << " ";
	}
	cout << endl;
	cout << "mx_to[i]" << " ";
	for (int i = 0; i <= n; i++) {
		cout <<mx_to[i] << " ";
	}
	cout << endl;
	cout << "mx_han[i]" << " ";
	for (int i = n+1; i >= 1; i--) {
		cout << mx_han[i] << " ";
	}
	cout << endl;
	*/
	

	cout << max(thmx,htmx) << endl;


	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;

#define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define forw(i,l,r) for(int i=(l);i<(r);i++)
#define forb(i,r,l) for(int i=(r);i>(l);i--)
#define log2i(x) 32 - __builtin_clz((x)) - 1
#define log2ll(x) 64 - __builtin_clzll((x)) - 1
#define Pi acos(-1.0)
#define sz(x) (int)x.size()
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const int N = 18;
int n;
int a[N][N];
ll dp[1<<N]={0};

int main() {
#ifndef ONLINE_JUDGE
    //freopen("test.inp","r",stdin);
    //freopen("test.out","w",stdout);
#endif
    fastIO;
    cin >> n;
    forw(i,0,n) {
        forw(j,0,n) cin >> a[i][j];
    }
    forw(i,1,1<<n) {
        ll res=0;
        forw(j,0,n) {
            forw(k,0,j) {
                if(((i>>j)&1)&&((i>>k)&1)) res+=a[j][k];
            }
        }
        for(int j=i;j;j=((j-1)&i)) res=max(res,dp[j]+dp[i-j]);
        dp[i]=res;
    }
    cout << dp[(1<<n)-1];
    return 0;
}


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

int main(){
  double a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  
  double res=0;
  double ans=0;
  rep(i,31)rep(j,31){
    double p=min(f-100*(a*i+b*j),e*(a*i+b*j));
    if(p<0) continue;
 
    double q=0;
    rep(k,int(p/c)+1){
      q=max(c*k+d*(int((p-c*k)/d)),q);
    }
    if(ans<q/(100*(a*i+b*j)+q)){
      res=100*(a*i+b*j)+q;
      ans=q/(100*(a*i+b*j)+q);
    }
  }
  if(res!=0) cout<<res<<" "<<res*ans<<endl;
  else cout<<100*a<<" "<<0<<endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N, Q, K;
vector<pair<int, int>> e[100000];

ll dep[100000];
void depth(int n, int p, ll d){
    dep[n] = d;
    rep(i, e[n].size()){
        if(e[n][i].first == p) continue;
        depth(e[n][i].first, n, d+e[n][i].second);
    }
}

signed main(){
    cin >> N;
    rep(i, N-1){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        e[a].pb({ b, c });
        e[b].pb({ a, c });
    }
    cin >> Q >> K;
    depth(K-1, -1, 0);
    rep(i, Q){
        int a, b;
        cin >> a >> b;
        cout << dep[a-1] + dep[b-1] << endl;
    }
}

Measured memory_bytes: 15872