akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


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

const int N=200005;



void solve()
{
    int n;
    cin>>n;
    int d[n];
    int x,y;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y;
        d[i]=x-y;
    }
    for(int i=0;i<n-2;i++)
    {
        if((!d[i])&&(!d[i+1])&&(!d[i+2]))
        {
            cout<<"Yes"<<endl;
            return;
        }
    }
    cout<<"No"<<endl;
    
}

int32_t main()
{
    IOS;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        
        solve();
    }
    return 0;
}



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

using namespace std;


#define MAXN 300001
#define MOD 998244353
typedef long long ll;

inline int mul(int a, int b) {
  return (int) ((ll) a * b % MOD);
}

inline int power(int a, ll b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

int inv(int a) {
  return power(a%MOD, MOD-2);
}

vector <ll> fact(MAXN + 1, 1);
void precalc() {
  for (int i = 2; i <= MAXN; ++i) {
    fact[i]= (fact[i-1]*i) % MOD;
  }
}

ll nCk(int n, int k) {
  return (fact[n]*(((ll)inv(fact[k]) * inv(fact[n-k])) % MOD)) % MOD;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  precalc();
  ll n, a, b, k, ans=0;
  cin >> n >> a >> b >> k;
  for (int x = 0; x <= n; ++x) {
    if (k-x*a<0 || (k-x*a)%b) continue;
    int y = (k-x*a)/b;
    if (y>n) continue;
    ans += nCk(n, x)*nCk(n, y);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
s = input()
if s[0] == "A":
    cnt = 0
    for i in range(2, len(s)-1):
        if s[i]  == "C":
            cnt += 1
    if cnt == 1:
        s = list(s)
        s.remove("A")
        s.remove("C")
        a = ",".join(s)
        if a.islower() == True:
            print("AC")
        else:
            print("WA")
    else:
        print("WA")
else:
    print("WA")

Measured memory_bytes: 9136
#include <iostream>
#include <bits/stdc++.h>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <map>
#include <iterator>
#include <iomanip>
#include <queue>
#include <utility>

using namespace std;
#define ll long long int
#define c(x) ll x;cin>>x
#define cc(x,y) ll x,y;cin>>x>>y
#define ccc(x,y,z) ll x,y,z; cin>>x>>y>>z
#define db long double
#define fast cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false)
#define inf 200000000000000
#define mod 1000000007
#define eps 1e-7
#define PI 3.1415926535897932385
#define pb push_back
#define bitc  __builtin_popcountll
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define len(x) (ll)(x).size()
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define foreach(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define print(arr,n) rep(i,n) cout<<arr[i]<<" "; cout<<endl
#define print2(arr,n,m) rep(i,n){ rep(j,m) cout<<arr[i][j]<<" "; cout<<endl; }
#define dyn1(arr,n) ll* arr=new ll[n]; rep(i,n) arr[i]=0;
#define dyn2(arr,n,m) ll** arr=new ll*[(n)]; rep(i,n) arr[i]=new ll[m]; rep(i,n) rep(j,m) arr[i][j]=0
#define carr(arr,n) rep(i,n) cin>>arr[i]
#define carr2(arr,n,m) rep(i,n) rep(j,m) cin>>arr[i][j]
#define debug(a) cout<<" :: "<<#a<<" == "<<a<<endl



inline ll maxim(ll a,ll b) {if(a>b) return a; else return b;}
inline ll minim(ll a,ll b) {if(a<b) return a; else return b;}
inline bool equals(double a, double b){ return fabs(a - b) < 1e-9; }
ll gcd(ll a, ll b){ return b==0 ? a : gcd(b, a%b); }
ll modpow(ll b, ll e) {
ll ans=1; for(;e;b=b*b%mod,e/=2) if(e&1) ans=ans*b%mod; return ans;}


/*
ll ncr(ll n,ll r)
{
  if(r>n) return 0;
  if((n==r)||(r==0))
  {
    return 1;
  }
  if(r==1) return n;
  if(r>n-r)
  {
    r=n-r;
  }

  string key=to_string(n)+"|"+to_string(r);
  if(m.find(key)==m.end())
  {
    ll answer=ncr(n-1,r-1)+ncr(n-1,r);
    m[key]=answer;
  }
  //cout<<key<<" "<<m[key]<<endl;
  return m[key];
}*/


/*
int modInverse(int a, int m)
{
    int m0 = m;
    int y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        // q is quotient
        int q = a / m;
        int t = m;

        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = y;

        // Update y and x
        y = x - q * y;
        x = t;
    }

    // Make x positive
    if (x < 0)
       x += m0;

    return x;
}

*/

ll n=1000000;
ll arr[1000001];
ll dp[1000001];

ll rec(ll p)
{
  if (dp[p]!=0) return dp[p];
  ll total=1;
  for(int o=p+1;o<=n;o++)
  {
    total+=rec(o);
  }
  dp[p]=total;
  return dp[p];
}

int main()
{
  fast;
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  cout<<setprecision(10)<<fixed;
  c(a);
  string s;
  cin>>s;
  if(a<3200) cout<<"red"<<endl;
  else cout<<s<<endl;

  return 0;
}


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

#define ll long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

void solve()
{
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++) cin>>a[i];
	
	ll gc=a[0];
	for(ll i=1;i<n;i++) gc=__gcd(gc,a[i]);
	
	if(gc!=1) 
	{
		cout<<"not coprime";
		return;
	}
	
	ll h=0;
	for(ll i=0;i<n;i++) h=max(h,a[i]);
	ll dd[h+1]={0};
	
	for(ll i=0;i<n;i++)
	{
		for(ll j=1;j<=sqrt(a[i]);j++)
		{
			if(a[i]%j==0)
			{
				dd[j]++;
				if(j!=a[i]/j) dd[a[i]/j]++;
			}
			if(j!=1 && dd[j]>1)
			{
				cout<<"setwise coprime";
				return;
			} 
			if((a[i]/j)!=1 && dd[a[i]/j]>1)
			{
				cout<<"setwise coprime";
				return;
			}
		}
	}
	cout<<"pairwise coprime";
}

int main()
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

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

int main() {
  int n,a,b;
  cin >> n;
  a = n/10;
  b = n%10;
  if(a==9 ||b==9){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
//AtCoder ABC058 C - 怪文書 / Dubious Document
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    int n;
    cin>>n;
    vector<string> stbl(n);
    vector<int> pt(n,0);
    for(auto&& s:stbl){
        cin>>s;
        sort(s.begin(),s.end());
    }
    string ans;
    const string& base=stbl[0];
    for(int i=0;i<base.size();++i){
        bool flag=true;
        vector<int> tmp=pt;
        for(int no=1;no<stbl.size();++no){
            auto result = stbl[no].find(base[i],pt[no]);
            if(result != string::npos){
                tmp[no]=result+1;
            } else {
                flag=false;
                break;
            }
        }
        if(flag){
            ans.push_back(base[i]);
            pt=tmp;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

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

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

int main(){
  ll N, K; cin >> N >> K;
  vector<pair<ll, ll>> pos(N);
  vector<ll> x;
  vector<ll> y;
  rep(i, N){
    ll X, Y; cin >> X >> Y;
    pos[i] = {X, Y};
    x.push_back(X);
    y.push_back(Y);
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  ll ans = INFL;
  for(int i = 0; i < x.size(); i++){
    for(int j = i + 1; j < x.size(); j++){
      for(int k = 0; k < y.size(); k++){
        for(int l = k + 1; l < y.size(); l++){
          ll cnt = 0;
          for(int p = 0; p < N; p++){
            ll X = pos[p].first, Y = pos[p].second;
            if(x[i] <= X && X <= x[j] && y[k] <= Y && Y <= y[l]) cnt++;
          }
          if(cnt >= K) ans = min(ans, (x[j] - x[i]) * (y[l] - y[k]));
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<algorithm>
struct Node{
    long long l,r;
    int k;
    Node(long long l=0,long long r=0,int k=0):l(l),r(r),k(k){}
    bool operator < (const Node&other)const{
        long long v0 = l-r, v1 = other.l-other.r;
        if(v0!=v1) return v0<v1;
        else return k<other.k;
    }
};
struct rNode{
    long long l,r;
    int k;
    rNode(long long l=0,long long r=0,int k=0):l(l),r(r),k(k){}
    bool operator < (const rNode&other)const{
        long long v0 = r-l, v1 = other.r-other.l;
        if(v0!=v1) return v0<v1;
        else return k>other.k;
    }
};
Node a[200005];
rNode b[200005];

int cmp0(Node a,Node b){ return a.k<b.k; }

int cmp1(rNode a,rNode b){ return a.k>b.k; }

int main(){
    int T;
    scanf("%d",&T);
    while(T--){
    int n;
    scanf("%d",&n);
    int sizeA = 0, sizeB = 0;
    for(int i = 1; i <= n; i++){
        int k; long long l,r;
        scanf("%d%lld%lld",&k,&l,&r);
        if(l>=r) a[++sizeA] = Node(l,r,k);
        else b[++sizeB] = rNode(l,r,k);
    }
    std::sort(a+1,a+1+sizeA,cmp0);
    std::sort(b+1,b+1+sizeB,cmp1);
    std::priority_queue<rNode>QQ;
    long long ans = 0;
    int p = sizeB;
    for(int i = sizeA+1; i <= n+1; i++){
        while(p>=1 && b[p].k<i){
            QQ.push(b[p]);
            p--;
        }
        if(QQ.size()!=0){
            rNode u = QQ.top(); QQ.pop();
            if(i!=n+1) ans += u.r;
            else ans += u.l;
        }
    }
    while(QQ.size()!=0){
        rNode u = QQ.top(); QQ.pop();
        ans += u.l;
    }
    //printf("ans = %lld\n",ans);
    p = sizeA;
    std::priority_queue<Node>Q;
    for(int i = sizeA; i >= 1; i--){
        while(p>=1 && a[p].k>=i){
            Q.push(a[p]);
            p--;
        }
        if(Q.size()!=0){
            Node u = Q.top(); Q.pop();
            ans += u.l;
        }
    }
    while(Q.size()!=0){
        Node u = Q.top(); Q.pop();
        ans += u.r;
    }
    printf("%lld\n",ans);
    }
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, M;
    vector<vector<ll>> A;
    cin >> N >> M;
    A.resize(N);
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        A[a - 1].push_back(b - 1);
    }
    iter(i, A[0]) {
        iter(j, A[i]) {
            if(j == N - 1) {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 8960
def get_index(fixed):
    for y, f in enumerate(fixed):
        try:
            x = f.index(0)
            return x, y
        except ValueError:
            pass


def recursive(i, fixed):
    if i == 9:
        return 1
    result = 0
    x, y = get_index(fixed)
    fixed[y][x] = i
    for dx, dy in ds:
        x2, y2 = x + dx, y + dy
        if not (0 <= x2 < 4 and 0 <= y2 < 4):
            continue
        if fixed[y2][x2]:
            continue
        fixed[y2][x2] = i
        result += recursive(i + 1, fixed)
        fixed[y2][x2] = 0
    fixed[y][x] = 0
    return result


while True:
    ipt = list(map(int, input().split()))
    if len(ipt) == 1:
        break
    ds = list(zip(*[iter(ipt)] * 2))
    print(recursive(1, [[0] * 4 for _ in range(4)]))

Measured memory_bytes: 7728
#include  <iostream>
#include  <stdio.h>
using namespace std;


int main(){

    int H;
    int W;
    int h;
    int w;
    
    cin >> H;
    cin >> W;
    cin >> h;
    cin >> w;

    cout << H * W - ( H * w + W * h - h * w);
    

}

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

int main () {
  
  vector<long long> vec(0);
  
  string S;
  cin >> S;
  
  int n = S.size();
  vector<int> s(n);
  
  for (int i = 0; i < n; i++) {
    s[i] = S[i] - '0';
  }
  
  for (long long bit = 0; bit < (1 << (n - 1)); bit++) {
    
    long long num = 0;
    long long a = 1;
    
    for (int i = n - 1; i >= 0; i--) {
      num += s[i] * a;
      if (i > 0 && bit & (1 << (n - 1 - i))) a *= 10;
      else a = 1;
    }
    
    vec.push_back(num);
    
  }
  
  long long ans = 0;
  
  for (int i = 0; i < vec.size(); i++) ans += vec[i];
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<queue>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
using namespace std;
typedef long double ldouble;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N,K;
  cin>>N>>K;

  ldouble ans=0;

  RREP(i,1,N+1){
    if(i<K){
      int tmp = ceil(log2((ldouble)K/i));
      //cout<<tmp<<endl;
      ans = ans + ((ldouble)1/(ldouble)N) * (1/pow(2,tmp));
    }else{
      ans = ans + ((ldouble)1/(ldouble)N);
    }
  }
  cout<<std::setprecision(12)<<ans;
  
  
  return 0;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import math

N = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

traffics = [a, b, c, d, e]
min_traffic = min(traffics)
ans = math.ceil(N / min_traffic) + 4
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int N;
void dfs(vector<int>& v, int prev, int rem) {
  
  if(rem == 0) {
    for(int i=0; i<v.size(); i++) {
      if(i) cout << " "; cout << v[i];
    }
    cout << endl;
    return;
  }
  
  for(int i=min(prev, rem); i>=1; i--) {
    v.push_back(i); dfs(v, i, rem-i); v.pop_back();
  }
}

int main() {
  
  while(cin >> N && N) {
    vector<int> v;
    dfs(v, N, N);
  }
  
  return 0;
}

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

#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define pp pair<ll,ll>
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FREV(i,a,b) for(i=a;i>=b;i--)
#define DEBUG(x) cerr<<"In file "<< __FILE__ <<" at line "<< __LINE__ <<" :: "<< #x <<" = "<<x<<endl
#define S(n) scanf("%lld", &n)

using namespace std;

int main() {
    ull n;
    vector<ull>city(5);
    cin >> n >> city[0] >> city[1] >> city[2] >> city[3] >> city[4];
    ull bottle_neck = *min_element(all(city));
    ull ans = 5 + (n-1) / bottle_neck ;
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
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; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    ll X; cin >> X;
    repi(a,-1000,1001) {
        repi(b,-1000,1001) {
            if(qp(a,5) - qp(b,5) == X) {
                printf("%d %d\n", a, b);
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3796
#include <iostream>
//#include <bits/stdc++.h>
// a&1 check odd or not and a>>=1 halfs a
// (n-1-i)%i previous in circle (i+n-1)%n next one
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pb(x) push_back(x)
#define F first
#define S second
#define ll long long 
using namespace std;

int n;
vector<pair<int,int>> v;
ll x,y;
void solve(){
	cin>>n;
	ll a,b;
	x=1;
	y=1;
	loop(i,0,n){
		cin>>a>>b;
		ll p=(x+a-1)/a;
		ll q=(y+b-1)/b;
		//~ cout<<p<<" "<<q<<endl;
		ll n=max(p,q);
		x=n*a;
		y=n*b;
		//~ cout<<x<<" "<<y<<endl;
	}
	cout<<x+y<<endl; 
	return;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	solve();

	return 0;
}



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

int main() {
  int N,L;
  cin>>N>>L;
  
  vector<string> S(N);
  
  for(int i=0;i<N;++i){
    cin>>S[i];
  }
  
  sort(S.begin(),S.end());
  string ans="";
  
  for(int i=0;i<N;++i){
  	ans+=S[i];
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
acs=[0]*n
was=[0]*n
WA=0
for i in range(m):
    p,s=input().split()
    p=int(p)
    if acs[p-1]==0:
        if s=="AC":
            acs[p-1]=1
            WA+=was[p-1]
        else:
            was[p-1]+=1
print(sum(acs),WA)

Measured memory_bytes: 4596
#include<bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
ll d[3005][3005][5],a[3005][3005];
int main(){
    ll r,c,n;cin>>r>>c>>n;
    for(ll i=1;i<=n;i++){
        ll x,y,v;cin>>x>>y>>v;
        a[x][y]=v;
    }
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            for(int k=0;k<=3;k++){
                d[i][j][k]=max(d[i][j][k],d[i][j-1][k]);
                d[i][j][0]=max(d[i][j][0],d[i-1][j][k]);
                if(a[i][j]>0){
                    if(k>0) d[i][j][k]=max(d[i][j][k],d[i][j-1][k-1]+a[i][j]);
                    d[i][j][1]=max(d[i][j][1],d[i-1][j][k]+a[i][j]);
                }
            }
        }
    }
    ll ans=0;
    for(int i=0;i<=3;i++){
        ans=max(ans,d[r][c][i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 426096
#include<stdio.h>
#include<iostream>
#include<algorithm> // sort(ALL())
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue> // push(), front(), pop() 先入れ先出し
#include<map> // 連想配列 map<string, int>
#include<iomanip>
#include<set>
#include<utility>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<(b);  ++i)
#define REP(i, n)    for(int i=0;   i<(n);  ++i)
#define REP1(i, n)   for(int i=1;   i<=(n); ++i)
#define pb push_back
#define mp make_pair
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define EPS 1e-7
#define ALL(obj) (obj).begin(), (obj).end()
using ul    = unsigned long;
using ll    = long long;
using ld    = long double;
using vint  = vector<int>;
using vll   = vector<ll>;
using pint  = pair<int, int>;
using pll   = pair<ll, ll>;
using vpint = vector<pint>;
using vpll  = vector<pll>;
const int INF = (int)1e9 + 1;
const int MOD = (int)1e9 + 7;
#define INT(argu) (int)(argu+EPS)



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

  int n;
  cin >> n;
  vint a(n);
  REP(i, n) cin >> a[i];

  sort(ALL(a));
  int cnt = 0;
  vint num = {1};
  REP(i, n-1){
    if(a[i]==a[i+1]){
      num[cnt]++;
    }else{
      num.push_back(1);
      cnt++;
    }
  }

  int ans = 0;
  REP(i, num.size()){
		//cerr << num[i] << endl;
    if(num[i]%2==1) ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1276
n = int(input())
#a,b = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
manzoku = 0
sum_B = sum(B)
for i in range(n-1):
    if A[i+1]-A[i] == 1:
        manzoku += C[A[i]-1]
print(manzoku + sum_B)

Measured memory_bytes: 3064
while True:
    n = int(input())
    if n == 0:
        break
    d = dict()
    for _ in range(n):
        x, y = input().split()
        d[x] = y
    m = int(input())
    result = ""
    for _ in range(m):
        x = input()[0]
        if x in d:
            result += d[x]
        else:
            result += x
    print(result)


Measured memory_bytes: 5708
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#define LEN 100005
using namespace std;

// プロセスを表す構造体
typedef struct pp {
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue() {
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int main() {
    int elaps = 0, c;
    P u;
    int q;
    cin >> n >> q;

    // プロセスを順番にキューに追加する
    for (int i = 1; i <= n; ++i) {
        cin >> Q[i].name;
        cin >> Q[i].t;
    }
    head = 1; tail = n + 1;

    // シミュレーション
    while (head != tail) {
        u = dequeue(); 
        c = min(q, u.t);        // クオンタムが到来するか実行が終わるか
        u.t -= c;               // プロセスの残り時間
        elaps += c;             // 経過時間
        if (u.t > 0) {
            enqueue(u);
        } else {
            cout << u.name << " " << elaps << endl;
        }     
    }

    return 0;
}


Measured memory_bytes: 13172
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main() {
    ll X, A, B;
    cin >> X >> A >> B;

    if (B <= A) {
        cout << "delicious";
    } else if (B <= (A + X)) {
        cout << "safe";
    } else {
        cout << "dangerous";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;

using namespace std;
int main(){
    
    ll n;
    while (cin>>n) {
        vector<ll> v;
        for(int i=0;i<n+1;i++){
            v.push_back(i);
        }
        ll b=v[v.size()-1];
        for(int i=2;i<=n;i++){
            ll j=2;
            while(i*j<=b){
                v[i*j]=0;
                j++;
            }
        }
        ll ans=0;
        for(int i=0;i<v.size();i++){
           // cout<<v[i]<<endl;
            if(v[i]!=0)ans++;
        }
        cout<<ans-1<<endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 18912
#include<stdio.h>
#include<math.h>
#define PI M_PI

double th = 60*PI/180;
void fanction(int n, double p1[], double p2[]){
  double s[2], u[2], t[2];

  s[0]=(2*p1[0]+p2[0])/3;
  s[1]=(2*p1[1]+p2[1])/3;
  t[0]=(p1[0]+2*p2[0])/3;
  t[1]=(p1[1]+2*p2[1])/3;
  u[0]=(t[0]-s[0])*cos(th)-(t[1]-s[1])*sin(th)+s[0];
  u[1]=(t[0]-s[0])*sin(th)+(t[1]-s[1])*cos(th)+s[1];

  if(n == 0){
    printf("%lf %lf\n", p2[0], p2[1]);
    return;
  }
  if(n == 1){
    printf("%lf %lf\n", s[0], s[1]);
    printf("%lf %lf\n", u[0], u[1]);
    printf("%lf %lf\n", t[0], t[1]);
    printf("%lf %lf\n", p2[0], p2[1]);
    return;
  }
  fanction(n-1, p1, s);
  fanction(n-1, s, u);
  fanction(n-1, u, t);
  fanction(n-1, t, p2);
}

void aaaaa(int a){
  int i;
  for(i=0; i<a; i++){}
  for(i=a; i>0; i--){}
}

int main(){
  int n, a=120;
  double p1[2], p2[2];
  scanf("%d", &n);
  p1[0] = 0;
  p1[1] = 0;
  p2[0] = 100;
  p2[1] = 0;
  printf("%lf %lf\n", p1[0], p1[1]);
  fanction(n, p1, p2);
  aaaaa(a);
  return 0;
}



Measured memory_bytes: 2128
from fractions import Fraction

def calc(a):
    return sum(map(int, list(str(a))))

def comp(a, b):
    return a * calc(b) <= b * calc(a)

MAX = 10**17
K = input()
A = set()
base = 0
front = 1
ok = True
while base < MAX:
    for i in xrange(1, 999):
        tmp = i * front + base
        if tmp <= MAX:
            A.add(tmp)
    base = base * 10 + 9
    front *= 10

A = sorted(list(A), key=lambda x: -x)
m = A[0]
ans = []

for i in xrange(1, len(A)):
    if comp(A[i], m):
        m = A[i]
        ans.append(A[i])

ans.sort()
for i in xrange(K):
    print ans[i]

Measured memory_bytes: 37604
#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=1e18+5;


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


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

const int MOD = 1e9 + 7;

// 1～maxまでの数値を足す。
ll sum1(int max) {
    if (max <= 0) return 0;
    if (max == 1) return 1;
    return ((ll)max * (max + 1)) / 2;
}

// start～endまでの数値を足す。両端を含む。
ll sum2(int start, int end) {
    return (sum1(end) - sum1(start - 1));
}

int main() {

    ll n, k;
    cin >> n >> k;

    ll a1 = sum2(0, k - 1);
    ll a2 = sum2(n - k + 1, n);
    ll sum = (a2 - a1 + 1) % MOD;
    for (int i = k; i <= n; i++) {
        a1 += i;
        a2 += (n - i);
        sum += (a2 - a1 + 1);
        sum %= MOD;
    }

    cout << sum << endl;

    return 0;

}


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

using namespace std;


int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    vector <int> h(n),a(n);
    for (int i=0;i<n;i++)
        cin >> h[i];
    for (int i=0;i<n;i++)
        cin >> a[i];

    int base=1;
    while (base<=n)
        base*=2;
    vector <long long> tree(2*base);

    vector <long long> dp(n+1);
    for (int i=0;i<n;i++)
    {
        int x=base+h[i];

        long long best=0;
        while (x>1)
        {
            if (x % 2 == 1)
                best=max(best,tree[x-1]);
            x/=2;
        }

        dp[h[i]]=max(dp[h[i]],best+a[i]);

        for (int j=base+h[i];j>=1;j/=2)
            tree[j]=max(tree[j],dp[h[i]]);
    }

    long long ans=0;
    for (int i=0;i<=n;i++)
        ans=max(ans,dp[i]);
    cout << ans;
}



Measured memory_bytes: 7552
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define int long long

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

const int kMaxN = 200000;

int N;
int A[kMaxN], B[kMaxN];

signed main() {
  cin >> N;
  REP(i, N) { cin >> A[i]; }
  REP(i, N) { B[i] = A[i]; }

  sort(A, A+N);
  int k1 = A[N/2 - 1];
  int k2 = A[N/2];
  REP(i, N) {
    if (B[i] <= k1) {
      cout << k2 << endl;
    } else {
      cout << k1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 5376
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int number = 0;
		List<String> a = new ArrayList<>();

		Scanner sc = new Scanner(System.in);
		String in = sc.next();

		for (int i = 0; i < in.length(); i++) {
			char b = in.charAt(i);
			String c = String.valueOf(b);
			a.add(c);
		}

		for (int i = 0; i < a.size(); i++) {
			if (a.get(i).equals("+")) {
				number++;
			} else if (a.get(i).equals("-")) {
				number--;
			}
		}
		sc.close();

		System.out.println(number);

	}

}


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

int main(){

  int num;
  cin >> num;

  int *numbers = new int[num];

  for (int i=0; i < num; i++){
    cin >> numbers[i];
  }

  bool flag = true;
  int count = -1;

  while(flag){
    count += 1;
    for (int i=0; i < num; i++){
      if (numbers[i] % 2 == 0){
        numbers[i] /= 2;
      } else {
        flag = false;
        break;
      }
    }
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
signed main()
{
    IOS
    int m,d; cin>>m>>d;
    if(d < 22)
    {
        cout<<0<<endl;
        return 0;
    }
    int ans = 0;
    for(int i=22;i<=d;i++)
    {
        int d0 = i%10,d1 = i/10;
        if(d0 >= 2 && d1 >= 2)
        {
            if(d0*d1 <= m) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#define int long long
using namespace std;
int n,a[200010];
int ans=0;
#undef int
int main(){
	#define int long long
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	int l=1,r=1,sumx=a[1],sum=a[1];
	for(int i=1;i<=n;i++){
		while((sumx==sum)&&r<=n){
			sum+=a[r+1];
			sumx^=a[r+1];
			r++;
		}
		ans+=(r-1)-l+1;
		sumx^=a[l];
		sum-=a[l];
		l++;
		if(r<l){
			r=l;
		}
	}
	cout << ans;
}

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

int n, rv = 0;
string s;

int main() {
	cin >> n >> s;
	for (int i = 0, m, d; i < 1000; i++) {
		m = i, d = 0;
		for (int j = 0; j < n && d < 3; j++)
			if (s[j] - '0' == m % 10) {
				d++;
				m /= 10;
			}
		if (d == 3)
			rv++;
	}
	cout << rv << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 13;
int n, a[maxN], ans;
map<int, bool> mark;
map<int, int> cnt;
vector<int> vec;
int main () {
    cin >> n;
    for (int i = 0; i < n; i++) {
	cin >> a[i];
	if (!mark[a[i]]) {
	    mark[a[i]] = 1;
	    vec.push_back(a[i]);
	}
	cnt[a[i]]++;
    }

    for (auto it : vec) {
	if (cnt[it] < it)
	    ans += cnt[it];
	else
	    ans += cnt[it] - it;
    }
    cout << ans << endl;
}


Measured memory_bytes: 9976
n = int(input())
p = 10**9 + 7

def cmb(n, r, p):
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

def pow(a, n, p):
    bi = str(format(n, 'b'))
    res = 1
    for i in range(len(bi)):
        res = (res * res) % p
        if bi[i] == '1':
            res = (res * a) % p
    return res

fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, 10**6 + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

if n == 1:
    print(0)
elif n == 2:
    print(2)
else:
    ans = 0
    powered_2 = pow(2, 1, p)
    for i in range(2, n + 1):
        powered_2 = powered_2 * 2 % p
        tryvalue = ((powered_2 - 2)*cmb(n, i, p)*pow(8, n-i, p))
        ans = (ans + tryvalue) % p
    print(ans)


Measured memory_bytes: 168372
#include <iostream>

using namespace std;

int main(void) {
    int X, Y, Z , tmp;

    cin >> X >> Y >> Z;

    tmp = X;
    X = Y;
    Y = tmp;

    tmp = Z;
    Z = X;
    X = tmp;

    cout << X << " " << Y << " " << Z;

    return 0;
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

function Main(input){
    var A = [];
    for (var i=0; i<3; i++){
	    A[i] = [,,,];
    }
    var lines = input.split("\n");
    for (var i=0; i<3; i++){
        var row = lines[i].split(" ");
        for (var j=0; j<3; j++){
            A[i][j] = parseInt(row[j]);
        }
    }
    var n = parseInt(lines[3]);
    for (var i=4; i<=4+n; i++){
        var b = parseInt(lines[i]);
        for (var j=0; j<3; j++){
            for (var k=0; k<3; k++){
                if (A[j][k] == b){
                    A[j][k] = -1;
                }
            }
        }
    }
    var flag = false;
    for (var i=0; i<3; i++){
        if (A[0][i] == A[1][i] && A[1][i] == A[2][i] && A[2][i] == -1){
            flag = true;
        }
    }
    for (var i=0; i<3; i++){
        if (A[i][0] == A[i][1] && A[i][1] == A[i][2] && A[i][2] == -1){
            flag = true;
        }
    }
    
    if (A[0][0] == A[1][1] && A[1][1] == A[2][2] && A[2][2] == -1){
        flag = true;
    }

    if (A[0][2] == A[1][1] && A[1][1] == A[2][0] && A[2][0] == -1){
        flag = true;
    }
    
    if (flag){
        console.log("Yes");
    } else{
        console.log("No");
    }
    
}

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

Measured memory_bytes: 7500
#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std;
#define DEBUG(X) cerr<<__LINE__<<" "<<#X<<": "<<X<<endl;
#define REP(i, y) for(int i=0;i<y;i++)
#define sci(x) int x;scanf("%d",&x);
#define scii(x, y) int x,y;scanf("%d%d",&x,&y);
typedef long long ll;
int sign(ll n) {
  return ((n > 0) - (n < 0));
}

const int MAX_N = 100001;
bool ht[MAX_N];
bool th[MAX_N];

int main() {
  sci(n)
  ll sum_ht = 0, sum_th = 0;
  ll ans_ht = 0, ans_th = 0;
  ll prev_sum = 0;

  REP(i, n) {
    // head is 1
    ht[i] = (i+1)%2;
    th[i] = i%2;
  }
  REP(i, n) {
    sci(ra)
    ll a = ra;
    ll sum = sum_ht;
    ll tmp = a;
    if (ht[i] && sum + a < 0) {
      tmp = a - (sum + a) + 1;
    } else if (!ht[i] && sum + a > 0) {
      tmp = a - (sum + a) - 1;
    } else if (sum + a == 0) {
      if (ht[i]) tmp++;
      else tmp--;
    }

    sum_ht += tmp;
    ans_ht += abs(tmp - a);

    // tail-head
    sum = sum_th;
    tmp = a;
    if (th[i] && sum + a < 0) {
      tmp = a - (sum + a) + 1;
    } else if (!th[i] && sum + a > 0) {
      tmp = a - (sum + a) - 1;
    } else if (sum + a == 0) {
      if (th[i]) tmp++;
      else tmp--;
    }

    sum_th+=tmp;
    ans_th += abs(tmp - a);
  }
  printf("%llu\n",min(ans_th, ans_ht));
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    ll N, K;
    cin >> N >> K;
    vector<ll> P(N + 1), C(N + 1);
    REP(i, 1, N + 1)
    cin >> P[i];
    REP(i, 1, N + 1)
    cin >> C[i];

    vector<ll> ans(N + 1, -(1LL << 60));
    vector<ll> cycle(N + 1);
    auto solve = [&](auto solve, ll v, ll par, ll rem, bool flag, ll score) {
        ans[par] = max(ans[par], score);

        if (rem == 0)
        {
            return;
        }
        if (v == par && cycle[par] == 0)
        {
            if (flag == 0)
                flag = 1;
            else
            {
                cycle[par] = K - rem;
                if (cycle[par] * 2 <= rem)
                {
                    score *= (K / cycle[par]) - 1;
                    rem = (rem % cycle[par]) + cycle[par];
                }
                ans[par] = max(ans[par], score);
            }
        }
        solve(solve, P[v], par, rem - 1, flag, score + C[P[v]]);
    };

    REP(i, 1, N + 1)
    solve(solve, P[i], i, K - 1, 0, C[P[i]]);
    cout << *max_element(ans.begin(), ans.end()) << endl;
}


Measured memory_bytes: 6072
#include<stdio.h>
int main()
{
    char a[1000],b[1000],c[1000];
    int i,sum=0;
    gets(a);
    gets(b);
    for(i=0;a[i]!='\0';i++)
    {
        c[i]=a[i]-b[i];
        if(c[i]!=0)
        {
            sum=sum+1;
        }
    }
    if(sum==0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


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

const int L = 8;

void solve() {
	int n, m;
	cin >> n >> m;
	int a = (25 * n) / 2;
	int b = m * 10;
	bool f = true;
	for (int i = 1; i <= 1000; ++i) {
		if (int(i * .08) == n and int(i * .1) == m) {
			f = false;
			cout << i << '\n';
			break;
		}
	}
	if (f) cout << -1 << '\n';		
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <string,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
const static int tx[] = {0,1,0,-1};
const static int ty[] = {-1,0,1,0};

int main(){
  int N;
  while(~scanf("%d",&N)){
    if(N == 0) break;
    vector<string> dict;
    int prior[256][256]; // prior[A][B] ::= A is prior to B or not
    memset(prior,-1,sizeof(prior));

    bool isok = true;
    bool res = true;
    for(int current_idx=0;current_idx<N;current_idx++){
      string current;
      cin >> current;

      for(int prev_idx=0;prev_idx<dict.size();prev_idx++){
        for(int char_idx=0;
            char_idx < current.size() && char_idx < dict[prev_idx].size();
            char_idx++){
          if(current[char_idx] == dict[prev_idx][char_idx]) continue;

          if(prior[dict[prev_idx][char_idx]][current[char_idx]] == 1){
            break;
          }

          if(prior[dict[prev_idx][char_idx]][current[char_idx]] == -1){
            prior[dict[prev_idx][char_idx]][current[char_idx]] = 1;
            prior[current[char_idx]][dict[prev_idx][char_idx]] = 0;
            break;
          }
        }

        bool isok = true;
        bool is_first = true;
        for(int char_idx=0;
            char_idx < current.size() && char_idx < dict[prev_idx].size();
            char_idx++){
          if(current[char_idx] == dict[prev_idx][char_idx]) continue;
          if(is_first && prior[current[char_idx]][dict[prev_idx][char_idx]] == 1){
            isok = false;
            break;
          }
          is_first = false;
        }

        if(isok){
          if(current.size() < dict[prev_idx].size()
             && dict[prev_idx].substr(0,current.size()) == current){
            isok = false;
          }
        }

        res &= isok;
      }

      dict.push_back(current);
    }
  found:;
    printf("%s\n",res ? "yes" : "no");
  }
}

Measured memory_bytes: 1520
#include <stdio.h>
#include <string.h>

int main(void)
{
    int a,a1;
    scanf("%d %d",&a,&a1);
    if(a==1||a==3||a==5||a==7||a==8||a==10||a==12) a=1;
    else if(a==2) a=2;
    else a=3;
    if(a1==1||a1==3||a1==5||a1==7||a1==8||a1==10||a1==12) a1=1;
    else if(a1==2) a1=2;
    else a1=3;
    if(a==a1) printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 128
/**
 * @author karayuu
 */
fun main(args: Array<String>) {
    val (a, b, c, x, y) = readLine()!!.split(" ").map { it.toInt() }

    var a_sum = 0
    var b_sum = 0
    var ab_sum = 0

    if ((a + b) < (c * 2)) {
        a_sum += x
        b_sum += y

        println(a_sum * a + b_sum * b + ab_sum * (c * 2))
    } else {
        val check = mutableListOf<Int>()
        val m = mutableListOf(x, y).min()!!
        ab_sum += m
        when {
            x < y -> b_sum += y - m
            x == y -> {

            }
            else -> a_sum += x - m
        }

        check.add(a_sum * a + b_sum * b + ab_sum * (c * 2))
        val max = mutableListOf(x, y).max()!!

        check.add((2 * c) * max)
        println(check.min())
    }
}

Measured memory_bytes: 37872
import sys
import math
import collections
import heapq

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin


def int_input():
    return list(map(int, input().split()))


if __name__ == '__main__':
    # set_debug(True)

    # t = int(input())
    t = 1

    for ti in range(1, t + 1):
        n = int(input())

        A = int_input()

        A.sort()

        res = A[-1]
        for i in range(len(A)-2):
            res += A[-(i//2)-2]
        print(res)



Measured memory_bytes: 32488
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, t, dp[3009][6009], ans;
pair<int, int> dat[3009];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> t;
	for (int i = 1; i <= n; i++) {
		cin >> dat[i].fi >> dat[i].se;
	}
	sort(dat + 1, dat + n + 1);
	for (int j = 0; j < t + 3000; j++) {
		if (j - dat[1].fi >= 0) {
			dp[1][j] = dat[1].se;
			ans = max(ans, dp[1][j]);
		}
	}
	for (int i = 2; i <= n; i++) {
		for (int j = 0; j < t + 3000; j++) {
			if (j - dat[i].fi >= 0) {
				dp[i][j] = dp[i - 1][j];
				if (dp[i][j] < dp[i - 1][j - dat[i].fi] + dat[i].se) {
					dp[i][j] = dp[i - 1][j - dat[i].fi] + dat[i].se;
				}
			}
			else {
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	for (int j = 1; j <= n; j++) {
		ans = max(ans, dp[j - 1][t - 1] + dat[j].se);
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 70656
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = input()
    s_list = list(map(int, list(S)))[::-1]
    MOD = 2019

    sum_v = 0
    cnt = [0] * MOD
    cnt[0] = 1
    x = 1
    for s in s_list:
        sum_v += s * x
        sum_v %= MOD
        x *= 10
        x %= MOD
        cnt[sum_v] += 1
    print(sum([c * (c - 1) // 2 for c in cnt if c > 1]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 88684
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C_fix
# CreatedDate:  2020-08-18 14:31:47 +0900
# LastModified: 2020-08-18 14:42:13 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n = int(input())
    ans_box = dict()
    for _ in range(n):
        s = sorted(map(str, input()))
        if ''.join(s) in ans_box.keys():
            ans_box[''.join(s)] += 1
        else:
            ans_box[''.join(s)] = 1
    ans = 0
    for key, value in ans_box.items():
        if value == 1:
            pass
        else:
            ans += value*(value-1)//2
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 22228
def MI(): return map(int, input().split())
from collections import deque
def bfs(field,s):
  q=deque([(0,s)])
  dist=[[-1]*W for _ in range(H)]
  d,i,j=-1,-1,-1
  MOVE=[(-1,0),(0,-1),(1,0),(0,1)]
  while q:
    d,(i,j)=q.popleft()
    if dist[i][j]!=-1:
      continue
    dist[i][j]=d
    for di,dj in MOVE:
      ni,nj=i+di,j+dj
      if not 0<=ni<H or not 0<=nj<W:
        continue
      if field[ni][nj]=='#':
        continue
      if dist[ni][nj]!=-1:
        continue
      q.append((d+1,(ni,nj)))
  return d
H,W=MI()
field=[input() for _ in range(H)]
ans=0
for i in range(H):
  for j in range(W):
    if field[i][j]=='.':
      d=bfs(field,(i,j))
      ans=max(ans,d)
print(ans)

Measured memory_bytes: 9356