akhauriyash/Code-Regression huggingface dataset:
#[allow(dead_code)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

fn main() {
    input!{
        n: usize,
        m: usize,
        lrs: [(usize, usize); m],
    }
    let lmax = lrs.iter().map(|&(l, _)| l).max().unwrap();
    let rmin = lrs.iter().map(|&(_, r)| r).min().unwrap();

    let result = if rmin < lmax {
        0
    } else {
        rmin - lmax + 1
    };
    println!("{}", result);
}


Measured memory_bytes: 6396
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
const int MaxN = 1e4;
typedef long long LL;
using namespace std;
bool cmp(LL x , LL y){
	return x > y;
}
int k , n;
LL a[MaxN + 5];
int main()
{
		scanf("%d%d" , &n , &k );
		int Max = 0;
		for(int i = 1;i <= n;i++)
			scanf("%lld" , &a[i]);
		sort(a + 1 , a + n + 1 ,cmp);
		for(int i = 1;i <= n;i++){
			LL sum = 0;
			for(int j = i;j <= n;j++){
				sum += a[j];
				if(sum >= k){
					Max = max(Max , j);
					sum -= a[j];
				}
			}
		}
		cout << n - Max << endl;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    G = [list(map(int, readline().split())) for _ in range(N)]

    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            needed = True
            for k in range(N):
                if G[i][j] > G[i][k] + G[k][j]:
                    print(-1)
                    return
                if k not in (i, j) and G[i][j] == G[i][k] + G[k][j]:
                    needed = False
            if needed:
                ans += G[i][j]

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 42588
n, k = map(int,input().split())
a = list(map(int, input().split()))
flg = [True] * n
dst = [1]
twn = 0
for _ in range(k):
    if flg[twn]:
        dst.append(a[twn])
        flg[twn] = False
        twn = a[twn] - 1
    else:
        index = dst.index(a[twn])
        ld = len(dst[:index])
        cyc = len(dst[index:])
        print(dst[(ld - 1) + (k + 1 - ld) % cyc] if (k + 1 - ld) % cyc != 0 else dst[-1])
        exit()
print(dst[-1])

Measured memory_bytes: 32292
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vi A(N),B(N);
  priority_queue<pair<pii,int>> P,Q;
  rep(i,0,N){
    cin>>A[i]>>B[i];
    P.push(mp(mp(A[i]+B[i],A[i]),i));
    Q.push(mp(mp(A[i]+B[i],B[i]),i));
  }
  int ans=0;
  vector<bool> F(N,1);
  rep(i,0,N){
    if(i%2==0){
      while(1){
        int X=P.top().first.first,Y=P.top().first.second,Z=P.top().second;
        P.pop();
        if(F[Z]){
          F[Z]=0;
          ans+=Y;
          break;
        }
      }
    }
    else{
      while(1){
        int X=Q.top().first.first,Y=Q.top().first.second,Z=Q.top().second;
        Q.pop();
        if(F[Z]){
          F[Z]=0;
          ans-=Y;
          break;
        }
      }
    }
  }
  cout<<ans<<endl;
  }


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

class Info
{
    public:
        int index, value;
        Info( int a = 0, int b = 0 );
        void setData( int a, int b );
};

Info::Info( int a, int b )
{
    index = a;
    value = b;
}

void Info::setData( int a, int b )
{
    index = a;
    value = b;
}

int calcAP( int a, int d, int n );
int getIndex( vector<Info> v, int* a, int j );

int main()
{
    int n, a, d, m, k;
    Info s, t;
    vector<Info> v;

    cin >> n >> a >> d >> m;

    int x[m], y[m], z[m];
    for( int i = 0; i < m; i++ )
    {
        cin >> x[i] >> y[i] >> z[i];
        s.setData( y[i], calcAP( a, d, y[i] ) );
        t.setData( z[i], calcAP( a, d, z[i] ) );

        bool judge1 = true, judge2 = true;
        for( int j = 0; j < v.size(); j++ )
        {
            if( v[j].index == s.index )
                judge1 = false;
            if( v[j].index == t.index )
                judge2 = false;
        }
        if( judge1 )
            v.push_back( s );
        if( judge2 )
            v.push_back( t );
    }

    cin >> k;

    for( int i = 0; i < m; i++ )
    {
        if( x[i] )
        {
            int c1 = getIndex( v, y, i ), c2 = getIndex( v, z, i );
            v[c1].value = v[c2].value;     
        }
        else
        {
            int c1 = getIndex( v, y, i ), c2 = getIndex( v, z, i );

            int temp = v[c1].value;
            v[c1].value = v[c2].value;
            v[c2].value = temp;   
        }
    }

    bool judge3 = true;
    for( int i = 0; i < v.size(); i++ )
        if( v[i].index == k )
        {
            cout << v[i].value << endl;
            judge3 = false;
        }

    if( judge3 )
        cout << calcAP( a, d, k ) << endl;

    return 0;
}

int calcAP( int a, int d, int n )
{ 
    return a + ( n - 1 ) * d;
}

int getIndex( vector<Info> v, int* a, int j )
{
    for( int i = 0; i < v.size(); i++ )
        if( v[i].index == a[j] )
            return i;
}


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

int main(){
    int r;
    cin >> r;
    if(r<1200){
        cout << "ABC" << endl;
    }
    else if(r<2800){
        cout << "ARC" << endl;
    }
    else{
        cout << "AGC" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
const double pi = acos(-1);
int main()
{
    Hello
    //2pir
    int n;
    cin >> n;
    cout << fixed << setprecision(2) << 2.0 * pi * n;
    return 0;
}

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

int main()
{
	int N,K;
	cin>>N>>K;
	vector<int> stone(N);
	vector<int> dp(K+1,0);
	for(int i=0;i<N;i++){
		int v;
		cin>>v;
		stone[i]=v;
	}
	for(int i=1;i<=K;i++){
		for(int j=0;j<stone.size();j++){
			if(stone[j]<=i){
				if(dp[i-stone[j]]==0){
					dp[i]=1;
				}
			}
		} 
	cout<<endl;
	}
	if(dp[K]==1)
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;	
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
int a[200100];
int pos[200100];
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&a[i]);
		a[i]--;
		pos[a[i]]=i;
	}
	int ans = 0;
	for(int i=0;i<N;i++){
		int r = i;
		while(r<N&&pos[r]<pos[r+1])r++;
		ans = max(ans,r-i+1);
		i=r;
	}
	cout << N-ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   long long A,B,K;
   cin >> A >> B >>K;
   B = max(min(B, B-K+A), 0LL);
   A = max(0LL, A-K);
   cout << A << " " << B << endl;
   return 0;
}


Measured memory_bytes: 256
A=[list(map(int,input().split())) for i in range(3)]
N=int(input())
B=[int(input()) for i in range(N)]
han=[]
for i in range(3):
    for j in range(3):
        for k in range(N):
            if A[i][j]==B[k]:
                A[i][j]=0
if A[0][0]==A[0][1]==A[0][2]==0 or A[1][0]==A[1][1]==A[1][2]==0 or A[2][0]==A[2][1]==A[2][2]==0:
    print("Yes")
    exit()
if A[0][0]==A[1][0]==A[2][0]==0 or A[0][1]==A[1][1]==A[2][1]==0 or A[0][2]==A[1][2]==A[2][2]==0:
    print("Yes")
    exit()
if A[0][0]==A[1][1]==A[2][2]==0 or A[0][2]==A[1][1]==A[2][0]:
    print("Yes") 
    exit()
print("No")

Measured memory_bytes: 3064
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define inf 1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
signed main(){
    int a,b;cin>>a>>b;
    int ans=3000000007;
    rep(i,0,2){
        rep(j,0,2){
            int c=a,d=b;
            if(i)c*=-1;if(j)d*=-1;
            if(c<=d){
                ans=min(ans,d-c+i+j);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;


int main() {
    int n;
    cin >> n;
    double r=1;
    r/=2;
    if (n%2==0) cout << fixed << setprecision(10) << r << endl;
    else {
        r=(n/2+1);
        r/=n;
        cout << fixed << setprecision(10) << r << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long // for codeforces

int main(){
  int n;
  cin>>n;
  cout << 800*n - n/15*200 << endl;

  return 0;
}


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

#define int long long
#define ll unsigned long long
#define pb push_back
#define mp make_pair
#define veci vector<int>
#define pii pair<int,int>
#define reset(a, b) memset(a, b, sizeof(a))
#define rep(i,b) for(int i=0; i<b; i++)
#define repi(i,a,b) for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define fi first 
#define se second
#define all(v) v.begin(),v.end()

int mod=1e9+7;

int powerm(int x,int y, int M){ int res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
int  power(int x,int y){ int res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
bool isprime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; }
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int T;
    T=1;
//    cin>>T;
while(T--){
    string s,t;
    cin>>s>>t;
    int ans=0;
    rep(i,s.length()){
        if(s[i]!=t[i]) ans++;
    }
    cout<<ans<<endl;
}
    
    return 0;
}

Measured memory_bytes: 3820
# D - XOR World

A, B = map(int, input().split())

def from_zero_ones_in_digit(X, n):
    if n > len(str(bin(X))):
        return 0
    else:
        return (X//(2**n))*2**(n-1) + max(0, X % (2**n) - (2**(n-1) - 1))

ans = 0
for n in range(1, len(str(bin(B)))):
    if (from_zero_ones_in_digit(B, n) - from_zero_ones_in_digit(A-1, n)) % 2 == 1:
        ans += 2**(n-1)

print(ans)

Measured memory_bytes: 3064
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

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

void solve() {
	int n, m; cin >> n >> m;
    string s, t; cin >> s >> t;
    int d = gcd(n, m);
    for(int i = 0, j = 0; i < n && j < m; i += n / d, j += m / d) {
        if(s[i] != t[j]) {
            cout << -1 << endl;
            return;
        }
    }
    cout << n * m / d << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define w(e) int e ; cin >> e ; while (e--)  
#define ll long long 
#define endl "\n"
#define mod  10000000007
#define pi 3.1415926535897932384626433
#define setbit(x) __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)  
/*
*/
int32_t main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
        long long X;
     cin >> X;
     long long P = 100, step = 0;
     while(P < X){
     P += P / 100;
     step++;
        }
        cout << step << endl;
	return  0;
}

Measured memory_bytes: 3540
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK =2;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra(){
priority_queue<pair<int, int> >PQ;
int color[MAX];
int d[MAX];
for(int i=0;i<n;i++){
  d[i]=INFTY;
  color[i]=WHITE;
}
d[0]=0;
PQ.push(make_pair(0,0));
color[0]=GRAY;

while(!PQ.empty()){
  pair<int, int>f=PQ.top();PQ.pop();
  int u=f.second;
  color[u]=BLACK;

  if(d[u]<f.first*(-1))continue;

  for(int j=0;j<adj[u].size();j++){
    int v=adj[u][j].first;
    if(color[v]==BLACK)continue;
    if(d[v]>d[u]+adj[u][j].second){
      d[v]=d[u]+adj[u][j].second;
      PQ.push(make_pair(d[v]*(-1),v));
      color[v]=GRAY;
    }
  }
}
for(int i=0;i<n;i++){
  cout<<i<<" "<<(d[i]==INFTY ? -1:d[i])<<endl;
}
}

int main(){
  int k,u,v,c;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v>>c;
      adj[u].push_back(make_pair(v,c));
    }
  }
dijkstra();
return 0;
}


Measured memory_bytes: 8016
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int a;
main()
{
	cin>>a;
	while(a)
	{
		int c[4]={},ans[4],m=1e9;
		for(int i=0;i<4;i++)cin>>c[i];
		for(int i=0;i<=c[0];i++)for(int j=0;j<=c[1];j++)for(int k=0;k<=c[2];k++)for(int l=0;l<=c[3];l++)
		{
			int ret=i*10+j*50+k*100+l*500;
			ret=a-ret;
			if(ret>0)continue;
			ret*=-1;
			int now=c[0]-i+c[1]-j+c[2]-k+c[3]-l;
			now+=ret/500;
			ret%=500;
			now+=ret/100;
			ret%=100;
			now+=ret/50;
			ret%=50;
			now+=ret;
			if(m>now)
			{
				ans[0]=i,ans[1]=j,ans[2]=k,ans[3]=l;
				m=now;
			}
		}
		for(int i=0;i<4;i++)
		{
			if(!ans[i])continue;
			cout<<(i==3?"500 ":i==2?"100 ":i==1?"50 ":"10 ")<<ans[i]<<endl;
		}
		cin>>a;
		if(a)cout<<endl;
	}
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
string s_prime;
string t;

int main() {
	cin >> s_prime >> t;
	int N = s_prime.length();
	int M = t.length();
	set<string>ans;
	for (int R = N; R >= M; R--) {
		int L = R - M;
		bool ok = true;
		for (int i = 0; i < M; i++) {
			if (!(s_prime[L + i] == '?' || s_prime[L + i] == t[i])) {
				ok = false;
			}
		}
			if (ok) {
				string s;
				for (int i = 0; i < N; i++) {
					s += s_prime[i];
				}
				for (int i = 0; i < M; i++) {
					s[L + i] = t[i];
				}
				for (int i = 0; i < N; i++) {
					if (s[i] == '?') {
						s[i] = 'a';
					}
				}
				ans.insert(s);
			}
		
	}
	if (ans.size() == 0) {
		cout << "UNRESTORABLE" << endl;
	}
	else {
		cout << *(ans.begin()) << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=1e6+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a) memset(a,0,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first 
#define se second
char ans[N];
int main(){
	string s;
	cin>>s;
	int n=s.size();
	int x=0;
	for(int i=0;i<n;i++){
		if(s[i]=='0') ans[++x]='0';
		else if(s[i]=='1') ans[++x]='1';
		else if(s[i]=='B'&&x){
			x--;
		}
	}
	for(int i=1;i<=x;i++) cout<<ans[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3636
a, b, c, x, y = map(int, input().split())

# ABを買わない、AorBを買わない、AandBを買わない
if x >= y:
    print(min(x*a + y*b, 2*y*c + (x - y)*a, 2*x*c))
else:
    print(min(x*a + y*b, 2*x*c + (y - x)*b, 2*y*c))

Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;
// const double PI = M_PI;

int N;
vector<int> A;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  A.resize(N);
  rep(i, N) { cin >> A[i]; }

  vector<int> dp(N, INF);
  rep(i, N) {
    int idx = lower_bound(dp.begin(), dp.end(), A[i]) - dp.begin();
    dp[idx] = A[i];
  }
  cout << lower_bound(dp.begin(), dp.end(), INF) - dp.begin() << endl;
  return 0;
}



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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int main(void)
{
  int n, a[100010];
  cin >> n;
  int g = 0, k = 0;
  REP(i, n) {
    cin >> a[i];
    if(a[i]%2 == 0) g++;
    else k++;
  }

  if(g % 2 == 0 && k % 2 == 0) {
    cout << "YES" << endl;
  } else if(g % 2 == 1 && k % 2 == 0) {
    cout << "YES" << endl;
  } else if(g % 2 == 0 && k %2 == 1) {
    cout << "NO" << endl;
  } else if(g % 2 == 1 && k % 2 == 1) {
    cout << "NO" << endl;
  } else {
    assert(false);
  }

  return 0;
}


Measured memory_bytes: 640
import math

def isprime(n):
    for i in range(2, int(math.sqrt(n))+1):
        if n != i and n % i == 0:
            return False
    return True

ans = 0
N = int(raw_input())
for _ in range(N):
    if isprime(int(raw_input())):
        ans += 1
print ans



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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> blue(n);
    set<string> bcard;
    for (int i = 0; i < n; i++) {
        cin >> blue[i];
        bcard.insert(blue[i]);
    }
    int m;
    cin >> m;
    vector<string> red(m);
    for (int i = 0; i < m; i++) {
        cin >> red[i];
    }

    int ans = 0;
    for(auto s : bcard){
        int buf = 0;
        for (string t: blue) {
            if (t == s) buf++;
        }
        for (string t: red) {
            if (t == s) buf--;
        }
        if(ans < buf){
            ans = buf;
        }
    }

    cout << ans << endl;
}



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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vst = vector<st>;
using vch = vector<char>;
using vbl = vector<bl>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
#define mkp(a, b) make_pair(a, b) 
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main() {
  ll a, b, v, w, t;
  cin >> a >> v >> b >> w >> t;
  if(v <= w){
    cout << "NO" << endl;
    return 0;
  }
  cout << (abs(a - b) <= (v - w) * t ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3632
package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {

	var X, N, number, Result, A int
	fmt.Scanf("%d %d", &X, &N)

	if N == 0 {
		fmt.Println(X)
	} else {

		p := make([]int, N)
		for i := 0; i < N; i++ {
			fmt.Scanf("%d", &p[i])
		}

		sort.Ints(p)
		number = 0
		Result = X
		A = 0
		for i := 0; i < 102; i++ {
			if p[number] == i {
				if number < N-1 {
					number++
				}
				continue
			} else {
				if Result > int(math.Abs(float64(X-i))) {
					Result = int(math.Abs(float64(X - i)))
					A = i
				}
			}
		}
		fmt.Println(A)
	}
}


Measured memory_bytes: 1840
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N)]
AB.sort()
m=0
c=0
for i,x in enumerate(AB):
    m += x[1]
    c += x[0]*x[1]
    if m >= M:
        c -= (m-M)*x[0]
        print(c)
        exit()

Measured memory_bytes: 60760
n = int(input())
nums = list(map(int, input().split()))

mydict = {}

for num in nums:
    if not num in mydict:
        mydict[num] = 1
    else:
        mydict[num] += 1

# print(mydict)

all_sum = 0
for key, value in mydict.items():
    all_sum += value * (value - 1)// 2

for num in nums:
    print(all_sum - (mydict[num] - 1))


Measured memory_bytes: 26268
#include<bits/stdc++.h>
using namespace std;
int n,cnt[101][101];
long long ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x=i;
		int fir,la;
		la=x%10;
		while(x){
			fir=x%10;
			x/=10;
		}
		cnt[fir][la]++;
	}
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++)ans+=1LL*cnt[i][j]*cnt[j][i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
h = gets.to_i
w = gets.to_i
n = gets.to_i
i = 0

if h >= w
  loop do
    if h * i >= n
      break
    else
      i += 1
    end
  end
else
  loop do
    if w * i >= n
      break
    else
      i += 1
    end
  end
end

puts i

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

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

using namespace std;
using lint=long long;

int main(){
	int k,q; scanf("%d%d",&k,&q);
	vector<lint> d0(k);
	rep(i,k) scanf("%lld",&d0[i]);

	vector<lint> d(k);
	rep(_,q){
		lint n,x,m; scanf("%lld%lld%lld",&n,&x,&m);

		rep(i,k) d[i]=d0[i]%m;

		lint res0=0;
		res0+=count(d.begin(),d.end(),0)*((n-1)/k);
		res0+=count(d.begin(),d.begin()+(n-1)%k,0);

		lint last=x;
		last+=accumulate(d.begin(),d.end(),0LL)*((n-1)/k);
		last+=accumulate(d.begin(),d.begin()+(n-1)%k,0LL);
		lint res1=last/m-x/m;

		printf("%lld\n",(n-1)-res0-res1);
	}

	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
int main(){
	int N,T,t,tt,i,ans=0;
	scanf("%d%d%d",&N,&T,&tt);
	for(i=1;i<N;i++){
		scanf("%d",&t);
		ans+=t-tt>T?T:t-tt;
		tt=t;
	}
	printf("%d\n",ans+T);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007, mod998 = 998244353;

string s;
int l, r;

int main() {
	cin >> s;
	l = intmax;
	for (int i = 0; i != s.size(); ++i) {
		if (s[i] == 'A')
			l = min(l, i);
		if (s[i] == 'Z')
			r = max(r, i);
	}
	cout << r - l + 1 << endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef  unsigned int uint;
typedef  long double ld;


int main()
{

	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif

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

	int k, n;
	cin >> k >> n;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a,a + n);
	
	int maxAdj = a[0] + (k - a[n - 1]);
	for (int i =0; i < n - 1; i++)
		if (a[i + 1] - a[i] > maxAdj) maxAdj = a[i +1] - a[i];
	cout << k - maxAdj << "\n";	


	return 0;
}

Measured memory_bytes: 1024
import numpy as np

data = input()
data = data.split()
x = int(data[0])
y = int(data[1])

vec_1 = []
vec_2 = []
group = [[1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 11], [2]]


for i in range(3):
	if x in group[i]:
		vec_1.append(1)
	else:
		vec_1.append(0)

for i in range(3):
	if y in group[i]:
		vec_2.append(1)
	else:
		vec_2.append(0)

vec_1 = np.array(vec_1)
vec_2 = np.array(vec_2)


if sum(vec_1 * vec_2) == 1:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 21524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<string,ll> si;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
#define sort(a) sort(a.begin(),a.end());
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define mp make_pair
#define F first
#define S second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define nl "\n"
#define TC cin>>t;while(t--)
const int MOD = 1e9+7;
const ld PI = 3.1415926535898;
const ll LLMAX = LLONG_MAX;

int main()
{
    int n;
    cin>>n;
    while(n)
    {
        if(n%10==7)
            {cout<<"Yes"<<nl;return 0;}
        else
            n/=10;

    }
    cout<<"No"<<nl;
}

Measured memory_bytes: 3624
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = Integer.parseInt(sc.next());
        Deque<Long> q = new ArrayDeque<>();
        for (int i = 1; i <= 9; i++) {
            q.addFirst((long)i);
        }
        long ans = 0;
        for (int i = 0; i < k; i++) {
            ans = q.pollLast();
            if (ans % 10 != 0) {
                q.addFirst(ans * 10 + (ans % 10) - 1);
            }
            q.addFirst(ans * 10 + (ans % 10));
            if (ans % 10 != 9){
                q.addFirst(ans * 10 + (ans % 10) + 1);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 30036
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;


int main(){
  int H,W; cin >> H >> W;
  vector<string> a(H);
  rep(h,H) cin >> a[h];
  int cnt_4 = (H/2)*(W/2);
  int cnt_1 = (H*W)%2;
  int cnt_2 = (H*W - 4*cnt_4 - cnt_1)/2;

  map<char,int> C;
  rep(h,H) rep(w,W) {
    C[a[h][w]]++;
  }
  
  for(auto c : C) {
    int num = c.second;
    
    while(num/4 > 0 && cnt_4 > 0){
      num -= 4;
      cnt_4--;
    }
    while(num/2 > 0 && cnt_2 > 0){
      num -= 2;
      cnt_2--;
    }
    while(num > 0 && cnt_1 > 0){
      num -= 1;
      cnt_1--;
    }
  }
  if(cnt_1 == 0 && cnt_2 == 0 && cnt_4 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    long long x,k,d;
    cin>>x>>k>>d;
    long long pos = x;
    if(pos > 0){
        long long divi = pos/d;
        if(divi >= k){
            pos -= (k*d);
            k=0;
        }
        else{
           pos -= (divi*d);
           k -= divi;
        }
    }
    else if(pos <0){
        long long divi = abs(pos)/d;
        if(divi >= k){
            (pos) += (k*d);
            k=0;
        }
        else{
            pos += (divi*d);
            k -= divi;
        }
    }
    if(k == 0){
        cout<<abs(pos);
    }
    else{
        long long f = pos - d;
        long long s = pos + d;
        long long fl=0;
        long long divi = k/2;
        if(k%2 != 0){
            fl =1;
        }
        if(abs(f) > abs(s)){
            pos = pos + (d*(divi+fl)) - (d*(divi));
        }
        else{
            pos = pos + (d*(divi)) - (d*(divi+fl));
        }
        cout<<abs(pos);
    }
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>a(n);
    int sum=0;
    for(int i=0;i<n;i++){
        cin >>a[i];
    }
    for(int i=0;i<n;i++)sum+=a[i];
    int ans=0;
    
    int c=4*m,k;
    if(sum % c == 0) k=sum/c;
    else{
        k=sum/c;
        k++;
        }
    for(int i=0;i<n;i++){
        if(a[i]>=k)ans++;
    }
    if(ans>=m)cout <<"Yes"<<endl;
    else{
        cout <<"No"<<endl;
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <map>
#include <iomanip>

using namespace std;

using ULL = unsigned long long;

int main() {
  string str;
  cin >> str;
  auto i1 = str.find(','), i2 = str.find(',', i1+1);
  str[i1] = ' ';
  str[i2] = ' ';
  cout << str << endl;
  return 0;
}

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

void solve(long long X) {
  long long n = 100;
  for (int i = 0;; i++) {
    if (n >= X) {
      cout << i << endl;
      return;
    }
    n = 1.01 * n;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long X;
  scanf("%lld", &X);
  solve(X);
}


Measured memory_bytes: 3712
import java.util.*;

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

        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();

        char[] c = s.toCharArray();

        int cnt = 1;

        for (int i=0; i<n-1; i++){
            if (c[i]!=c[i+1]){
                cnt++;
            }
        }
//        System.out.println(cnt);
        if (cnt%2==0){
            if (k>=cnt/2){
                cnt = 1;
            }else{
                cnt -= k*2;
            }
        }else{
            if (k>=cnt/2){
                cnt = 1;
            }else {
                cnt -= k*2;
            }
        }

        System.out.println(n-cnt);
    }

}

Measured memory_bytes: 26496
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000;
char s[maxn], t[maxn];
int n;
void solve() {
	scanf("%d", &n);
	if (n & 1)puts("No"), exit(0);
	n >>= 1;
	scanf("%s", s);
	for (int i = 0; i < n; ++i) {
		if (s[i] != s[i + n]) {
			puts("No");
			exit(0);
		}
	}
	puts("Yes");
}
int main() {
	solve();

	return 0;
}

Measured memory_bytes: 256
import math
import sys
import bisect
input=sys.stdin.readline
#t=int(input())
t=1
for _ in range(t):
    #n=int(input())
    n,d=map(int,input().split())
    #l=list(map(int,input().split()))
    cnt=0
    for __ in range(n):
        x,y=map(int,input().split())
        
        dist=x**2+y**2
        if dist<=d**2:
            cnt+=1
            
    print(cnt)

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

using namespace std;

int a[510][510],dp[510][510];
int main()
{
    int n,m,q;
    while(scanf("%d%d%d",&n,&m,&q)==3){
        memset(a,0,sizeof(a));
        memset(dp,0,sizeof(dp));
        int l,r;
        for(int i=0;i<m;i++){
            scanf("%d%d",&l,&r);
            a[l][r]++;
        }
        for(int i=n;i>0;i--){
            for(int j=1;j<=n;j++){
                dp[i][j]=a[i][j]+dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1];
            }
        }
        while(q--){
            scanf("%d%d",&l,&r);
            printf("%d\n",dp[l][r]);
        }
    }
    return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<queue>

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

#define ARRAY_MAX 1005

int main(){

    ll n,t;
    cin >> n >> t;
    vector<ll> a(n),profit(n);
    ll mini = INF;
    ll maxi_profit = -1;

    REP(i,n){
        cin >> a[i];
        mini = min(mini,a[i]);
        profit[i] = a[i]-mini;
        maxi_profit = max(maxi_profit,profit[i]);
    }

    ll ans = 0;
    REP(i,n){
        if(profit[i] == maxi_profit){
            ans++;
        }
    }
    cout << ans << endl;


    return 0;
}

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

 
/*
ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
 
 
ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}
*/


int main(){
    ll N;
    cin>>N;
    vector<ll> A(N);
    for(ll i=0;i<N;i++){
        cin>>A.at(i);
    }
    vector<ll> a(N);
    for(ll i=0;i<N;i++){
        a.at(i)=A.at(i);
    }
    map<ll,ll> mp;
    for(ll i=0;i<N;i++){
        mp[A.at(i)]++;
    }
    map<ll,ll> mp2;
    map<ll,ll> mp3;
    for(ll i=0;i<N;i++){
        mp2[A.at(i)]=mp[A.at(i)]*(mp[A.at(i)]-1)/2;
        mp3[A.at(i)]=(mp[A.at(i)]-1)*(mp[A.at(i)]-2)/2;
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ll maxi=a.at(0);
    ll cnt=0;
    for(ll i=0;i<=maxi;i++){
        cnt+=mp2[i];
    }
    //cout<<cnt<<endl;
    for(ll i=0;i<N;i++){
        
        cout<<cnt+mp3[A.at(i)]-mp2[A.at(i)]<<endl;
        //cout<<mp[A.at(i)]<<" "<<mp2[A.at(i)]<<" "<<mp3[A.at(i)]<<endl;
    }
}

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

const int N=200010;
const int Mod=1e9+7;

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    long long low = 0;
    long long high = 0;
    for (int i=0;i<k;i++) {
        low += i;
        high += n-i;
    }
    long long ans = 0;
    for (int i=k;i<=n+1;i++) {
        ans += high-low+1;
        ans %= Mod;
        high += n-i;
        low += i;
    }
    printf("%lld\n",ans);
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    
    vector<int> a(n);
    vector<int> ans(n);
    rep(i,n){
        cin >> a[i];
        ans[a[i]-1] = i+1;
    }
    
    rep(i,n){
        cout << ans[i] << " ";
    }

    
}


Measured memory_bytes: 1536
n=int(input())
s=input()
mx=0
for i in range(1,n):
  c=0
  for j in range(n-i):
    if s[j]==s[j+i]:
      c+=1
      mx=max(mx,c)
      if c==i:
        break
    else:
      c=0
print(mx)


Measured memory_bytes: 73540
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
#define lson o<<1
#define rson o<<1|1
#define mid (l+r)/2
using namespace std;
struct Edge
{
	int l,r;
	ll c;
}e[100005];
int n,m;
ll f[100005],minn[400005];
bool cmp(Edge a,Edge b)
{
	return a.r<b.r;
}
void pushup(int o)
{
	minn[o]=min(minn[lson],minn[rson]);
}
void update(int o,int l,int r,int p,ll v)
{
	if(l==r)
	{
		minn[o]=v;
		return;
	}
	if(p<=mid)update(lson,l,mid,p,v);
	else update(rson,mid+1,r,p,v);
	pushup(o);
}
ll ask(int o,int l,int r,int from,int to)
{
	if(l>=from&&r<=to)return minn[o];
	ll ans=1000000000000000000;
	if(from<=mid)ans=min(ans,ask(lson,l,mid,from,to));
	if(to>mid)ans=min(ans,ask(rson,mid+1,r,from,to));
	return ans;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d%d%lld",&e[i].l,&e[i].r,&e[i].c);
	sort(e+1,e+m+1,cmp);
	memset(minn,0x7f,sizeof(minn));
	update(1,1,n,1,0);
	int now=1;
	for(int i=2;i<=n;i++)
	{
		f[i]=1e18;
		while(now<=m&&e[now].r==i)
		{
			f[i]=min(f[i],ask(1,1,n,e[now].l,e[now].r-1)+e[now].c);
			now++;
		}
		update(1,1,n,i,f[i]);
	}
	if(f[n]>1e17)printf("-1\n");
	else printf("%lld\n",f[n]);
	return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
typedef long long ll;

int res(int diff, int uncover) {
    return ((diff + 1) * diff) / 2   - uncover;
}

int main(int argc, char const *argv[]) { 
    int a, b;
    cin >> a >> b;
    int d = b - a;
    cout << res(d, b) << '\n';
    return 0;
}


Measured memory_bytes: 256
import collections

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

a=collections.Counter(A)

total=0
for v in a.values():
    if v>1:
        c=(v*(v-1))//2
        total+=c

for i in A:
    ans=total-(a[i]*(a[i]-1))//2+((a[i]-1)*(a[i]-2))//2
    print(ans)

Measured memory_bytes: 26772
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int X;
  cin>>X;
  int ct=0;

  rep(i,1000000){
    ct+=i;
    if(ct>=X) {
      cout << i <<"\n";
      return;
    }
  }
}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
N,M = map(int,input().split())

L = [tuple(map(int,input().split())) for i in range(M)]
flag = 0

P = []
for i in range(2) :
    for j in range(M) :
        if (L[j][i] == 1) or (L[j][i] == N) :
            if i == 0 :
                P.append(L[j][1])
            else :
                P.append(L[j][0])

Q = list(set(P))
if len(P) != len(Q) :
    flag = 1

if flag == 1 :
    print("POSSIBLE")
else :
    print("IMPOSSIBLE")
    


Measured memory_bytes: 40788
import qualified Data.Map as M

toInt x = read x :: Int

employeeList n = [1..n]
countList = cycle [0]

countcheck :: [Int] -> M.Map Int Int -> M.Map Int Int
countcheck [] mapEmployeeCount = mapEmployeeCount
countcheck (x:xs) mapEmployeeCount
    = M.update (\x -> Just(x+1)) x $ countcheck xs mapEmployeeCount

main = do
    n <- readLn
    m <- map toInt . words <$> getLine
    let employeeCount = zip (employeeList n) countList
        mapEmployeeCount = M.fromList employeeCount
        checkedEmployeeCount = countcheck m mapEmployeeCount
    mapM_ print $ map snd $ M.toList checkedEmployeeCount

Measured memory_bytes: 97760
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  string s; cin >> s;
  int left = 0, right = s.size() - 1, ans = 0;
  while (left < right) {
    // debug2(left, right);
    if (s[left] == s[right]) {
      left++;
      right--;
    } else if (s[left] == 'x' && s[right] != 'x') {
      left++;
      ans++;
    } else if (s[left] != 'x' && s[right] == 'x') {
      right--;
      ans++;
    } else {
      outl(-1);
      return;
    }
  }
  outl(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 632
import sys
from bisect import bisect_left, bisect_right
inout = sys.stdin.readline

def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))
    
    ans = 0
    for Bi in B:
        Ai = bisect_left(A, Bi)
        Ci = N - bisect_right(C, Bi)
        ans += (Ai*Ci)

    print(ans)


if __name__ == '__main__': main()


Measured memory_bytes: 107108
#![allow(non_snake_case)]
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let N:i32 = sc.read();
    let mut ans:String = "No".to_string();
    for i in 1..10 {
        for j in 1..10 {
            if N == i*j{
                ans = "Yes".to_string();
                break;
            }
        }
    }
    println!("{}", ans);

}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
        .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}



Measured memory_bytes: 4352
s = input()
y = int(s[:4])
m = int(s[5:7])
d = int(s[8:])
flag = 1
if y > 2019:
    flag = 0
elif y == 2019:
    if m >= 5:
        flag = 0


if flag == 1:
    print("Heisei")
else:
    print("TBD")


Measured memory_bytes: 38468
import sys

for weight in sys.stdin:
    binary=[0]*10
    weight = int(weight)
    i=0
    while i<=9 or weight!=0:
        binary[i]=weight%2
        weight/=2
        i+=1
    print ' '.join(map(str,[2**b for b in range(len(binary)) if binary[b]==1]))

Measured memory_bytes: 4204