akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    ll h, a; cin >> h >> a;
    cout << (h + a-1)/a << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 100+5;

int n, m;
char c[N][N];

int main(){
	ri2(n,m);
	getchar();
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			c[i][j] = getchar();
		}
		getchar();
	}
	for(int i=1; i<=n+n; i++){
		for(int j=1; j<=m; j++){
			putchar(c[(i+1)/2][j]);
		}
		puts("");
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
#define MAX 100

int n;
int p[MAX];
int m[MAX][MAX];

int min(int x, int y){

  if( x < y )
    return x;

  return y;

}

void matrixChainOrder(){

  int i,j,k,l;
  int q;

  for( i = 0 ; i < n ; i++ ){
    m[i][i] = 0;
  }

  for( l = 2 ; l <= n ; l++ ){
    for( i = 1 ; i <= n-l+1 ; i++ ){
      j = i+l-1;
      m[i][j] = INT_MAX;
      for( k = i ; k <= j-1 ; k++ ){
        q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
        m[i][j] = min(m[i][j],q);
      }

    }

  }

}

int main(int argc, char const *argv[]) {

  int i;

  scanf("%d",&n);

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

  matrixChainOrder();

  printf("%d\n",m[1][n]);

  return 0;
}



Measured memory_bytes: 2044
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<ldouble, ldouble> pdd;

int n, a, b;

void solve() {
	scanf("%d%d%d", &n, &a, &b);
	int c = (b - a) & 1;
	printf("%s\n", c ? "Borys" : "Alice");
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

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

int main() {
  int n;cin>>n;
  map<int,int> list;
  for (int i=0;i<n;i++) {
    int temp;
    cin >> temp;
    for (int j=temp-1;j<temp+2;j++) {
      if(list.count(j)) {
        list.at(j)++;
      }
      else {
        list[j]=1;
      }
    }
  }
  int count=0;
  for (auto p:list) {
    count = max(count,p.second);
  }
  cout << count << endl;
}

Measured memory_bytes: 4736
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<VL> VVL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

int main(){
    ll x,y,n,m,h,k,w,max=-1000000001,min=1000000001,ans=0,sum=0;
    string s,t;
    cin >> n >> s;
    //VL a(n);
    char a[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
    rep(i,s.size()){
        rep(j,26){
            if(s[i] == a[j]){
                if(j+n>25)
                    t.push_back(a[j+n-25-1]);
                else
                    t.push_back(a[j+n]);
            }
        }
            
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 256
input1 = input().split()
N = int(input1[0])
M = int(input1[1])
SUBMIT = []

#提出履歴
for i in range(M):
    input2 = list(input().split())
    SUBMIT.append(input2)

#提出状況
CHECK = []

for i in range(N):
    CHECK.append([i+1,0,"yet"])


for i in range(M):
    if SUBMIT[i][1] == "WA":
        if CHECK[int(SUBMIT[i][0]) - 1][2] == "yet":
            CHECK[int(SUBMIT[i][0]) - 1][1] += 1
    else:
        CHECK[int(SUBMIT[i][0]) - 1][2] = "done"
    
result_1 = 0
result_2 = 0

for i in range(N):
    if CHECK[i][2] == "done":
        result_2 += 1
        result_1 += CHECK[i][1]
        
print(result_2,result_1)

Measured memory_bytes: 39368
#include <stdio.h>
 
int main()
{
    int num1, num2;
    int sum, nDigit;
     
    nDigit = 1;
     
    while (scanf("%d", &num1) != EOF)
    {
          scanf("%d", &num2);
           
          sum = num1 + num2;
           
          //printf("\n suma %d\n", sum);
           
          while (sum >= 10) {
                sum = sum/10;
                nDigit++;
          }
          printf("%d\n",nDigit);
          nDigit = 1;
    }
     
     
     
    //system("PAUSE");
     
    return 0;
}

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

int main(){
  string a;
  cin >> a;
  if("AAA"==a) {
    cout << "No";
    return 0;
  }
  if("BBB"==a) {
    cout << "No";
    return 0;
  }
  cout << "Yes";
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for(int i=1; i<(n); i++)
using namespace std;

int main(){
  int x,count=0;
  cin >> x;
  
  rep(i,400){
    if((x*i) % 360 == 0){
      count = i;
      break;
    }
  }
  
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 3604
from operator import itemgetter
N = int(input())
childs = [list(input().split()) for _ in range(N)]
for i in childs:
    i[1] = int(i[1])

a = sorted(childs, key=itemgetter(1), reverse=True)
b = sorted(a, key=itemgetter(0))

for i in b:
    print(childs.index(i)+1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
ll bin_pow(ll a,ll b,ll m)
{
    ll res=1;
    a%=m;
    while(b>0)
    {
        if(b&1)
            res=res*a%m;
        b>>=1;
        a=a*a%m;
    }
    return res;
}
bool miller_rabin(ll d,ll n)
{
    ll a=2+rand()%(n-4);
    ll x=bin_pow(a,d,n);
    if(x==1 || x==n-1)
        return true;
    while(d!=n-1)
    {
        x=(x*x)%n;
        d*=2;
        if(x==1)
            return false;
        if(x==n-1)
            return true;
    }
    return false;
}
bool prime(ll n,ll k)
{
    if(n==1 || n==4)
        return false;
    if(n<=3)
        return true;
    ll d=n-1;
    while(d%2==0)
        d/=2;
    for(int i=0; i<k; i++)
    {
        if(!miller_rabin(d,n))
            return false;
    }
    return true;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    set<int>s;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        s.insert(x);
    }
    cout<<*s.rbegin()-*s.begin()<<endl;
}


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

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

long long lcm(long long a, long long b){
  if(a < b){
    long long tmp = b;
    b = a;
    a = tmp;
  }
  
  return a / gcd(a, b) * b;
}
      
    
int main(){
  int n; cin >> n;
  stack<long long> t;
  
  for(int i = 0; i < n; i++){
    long long tmp; cin >> tmp;
    t.push(tmp);
  }
  
  while(t.size() > 1){
    long long a = t.top();
    t.pop();
    long long b = t.top();
    t.pop();
    t.push(lcm(a, b));
  }
  
  cout << t.top() << endl; 
}



Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define PI          3.1415926535897932384626433832795l

#define pb push_back
#define mp make_pair
#define lb lower_bound // First element which is not less than val
#define ub upper_bound // First element greater than val
#define f first
#define s second

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;

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

#define endl '\n'
#define re return
#define repz(i, a) for (ll i = 0; i < (a); i++)
#define vecin(n,v) for(ll i = 0; i < n; i++) cin>>v[i];
#define full(v) v.begin(),v.end()

void solve()
{
  int n;
  cin >> n;
  vll a(n), b(n);
  
  repz(i,n)
    cin >> a[i] >> b[i];


  ll sum1 = 0, sum2 =LLONG_MAX;
  for (int i = 0; i < n; i++)
  {
    sum1 += a[i];
    if (a[i] > b[i])
      sum2 = min(sum2,b[i]);
  }

  if (sum2 == LLONG_MAX)
    sum2 = sum1;
  cout << sum1-sum2 << endl;
}

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

  ll t = 1;
  //cin >> t;
  while (t--)
  {
    solve();
  }
}



Measured memory_bytes: 3640
#include<stdio.h>
#include<math.h>

int main(void)
{
        double xa = 0, ya = 0, xb = 0, yb = 0, xc = 0, yc = 0, xd = 0, yd = 0;
        int i = 0;
        int m = 0;
        double s[4] ={0,0,0,0};
        double max = 0.0;
        while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF)
        {
                s[0] = fabs( (xa*yb + xb*yc + xc*ya
                            - ya*xb - yb*xc - yc*xa) /(double)2.0 );/*abc*/
                s[1]= fabs( (xa*yb + xb*yd + xd*ya
                            - ya*xb - yb*xd - yd*xa) /(double)2.0 );/*abd*/
                s[2] = fabs( (xa*yc + xc*yd + xd*ya
                            - ya*xc - yc*xd - yd*xa) /(double)2.0 );/*acd*/
                s[3] = fabs( (xb*yc + xc*yd + xd*yb
                            - yb*xc - yc*xd - yd*xb) /(double)2.0 );/*bcd*/

                max = s[0];
                for(i = 0; i < 4; i++)
                {
                        if(max < s[i])
                        {
                                max = s[i];
                                m = i;
                        }
                }
                s[m] = 0;

                if( max == s[0] + s[1] + s[2] + s[3])
                {
                        printf("NO\n");
                }
                else
                {
                        printf("YES\n");
                }
                for(i = 0; i < 4; i++)
                {
                        s[i] = 0;
                }
                m = 0;
                max = 0;

        }
        return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<string>
#include<algorithm>
#include <sstream>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include <vector>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
const int mod = 1e9+7;

int main()
{
    int n,m;
    vector<pair<int,int>>res;
    int a,b;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        res.push_back({a,b});
    }

    vector<pair<int,int>>v;
    vector<int>v1;
    for(int i=0;i<m;i++)
    {
        cin>>a>>b;
        v.push_back({a,b});
    }

    for(auto &x :res)
    {
        int mi=1e9+10;
        int index =0;
        int k=0;
        for(auto &x1:v)
        {
            k++;
            int dis =abs(x1.first-x.first)+abs(x1.second-x.second);
            if(dis<mi)
            {
                index =k;
                mi = dis;
            }
        }
        v1.push_back(index);
    }

    for(auto &x :v1)
    {
        cout<<x<<endl;
    }
    return 0;
}


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





int main(){
  int n,m;
  int a[60][3]={};
  
  cin >> n >> m;

  
  for(int i=0;i<n;++i){
    for(int t=0;t<m;++t){
      char c;
      cin >> c;
      if(c == 'W'){
	++a[i][0];
      }else if(c == 'B'){
	++a[i][1];
      }else{
	++a[i][2];
      }
    }
  }


  int mx=INT_MAX;  
  for(int i=1;i<=n-2;i++){
    for(int t=1;t+i<n;t++){
      int c=0;
      for(int h=1;h<t;h++){
	c+=m-a[h][0];
      }
      for(int h=t;h<t+i;h++){
	c+=m-a[h][1];
      }
      for(int h=t+i;h<n-1;h++){
	c+=m-a[h][2];
      }
      mx=min(mx,c);
    }
  }
  int count=0;
  count+=m-a[0][0];
  count+=m-a[n-1][2];
  cout<<count+mx<<endl;
  
  return 0;
}



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

using namespace std;

#define endl '\n'

typedef long long ll;

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

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int 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;}

#define _rep3(i,p,n) for(int i=(p),i##_counter=(n); i<i##_counter;++i)
#define _rep2(i,n,_) _rep3(i,0,n)
#define _rep_call(a, b, c, name, ...) name(a, b, c)
#define rep(...) _rep_call(__VA_ARGS__, _rep3, _rep2)

#define dump(x)  cerr << #x << " = " << (x) << '\n'
#define debug(x) cerr << #x << " = " << (x) << " (at line " << __LINE__ << ")" << " " << __FILE__ << '\n'

int cost(const vector<int> &a, int m) {
    int ret = 0;
    for (auto d : a) {
        ret += (d - m) * (d - m);
    }
    return ret;
}

void Main() {
    int N; cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    double mean = 0;
    rep(i, N) mean += a[i];
    mean /= N;
    int cost1 = cost(a, floor(mean));
    int cost2 = cost(a, ceil(mean));
    cout << (cost1 < cost2 ? cost1 : cost2) << endl; 
}

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

Measured memory_bytes: 256
from collections import Counter


from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


S = input()
div = []
s = 0
kurai = 1
for i in range(len(S) - 1, -1, -1):
    # s += int(S[i]) * ((10 ** (len(S) - 1 - i)) % 2019)
    # s %= 2019
    if i == len(S) - 1:
        s += int(S[i]) * kurai
    else:
        s += int(S[i]) * kurai
    kurai *= 10
    kurai %= 2019
    s %= 2019
    div.append(s)
div_cnt = Counter(div)
ans = div_cnt[0]
for l in div_cnt.values():
    if l >= 2:
        ans += l * (l-1) // 2
print(ans)


Measured memory_bytes: 78964
n, k = map(int, input().split())
#10**9+7  で割った余り
#k = k %(10**9 + 7)
#その文字iより前に大きな数字
before_cnt = 0
#その文字より後に大きな数字
after_cnt = 0
n_list = list(map(int, input().split()))
for i in range(n-1):
  for j in range(i+1, n):
    if n_list[i] > n_list[j]:
      before_cnt+=1
    elif n_list[i] < n_list[j]:
      #print("i",i,"j",j)
      after_cnt+=1
      '''
      if i < j:
        after_cnt+=1
      else:
        before_cnt+=1
'''
kurikaesi = int((1 + k)*k//2)
#print("type",type(k),"kurikaesi",kurikaesi)
#print(after_cnt, before_cnt)
print(((after_cnt*(kurikaesi-k) + before_cnt*kurikaesi))%(10**9 + 7))
      

Measured memory_bytes: 3188
import collections

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

c = collections.Counter(a)
ans = 0

for i in range(max(a)+1):
    cnt = c[i]
    if i-1 in c:
        cnt += c[i-1]
    if i+1 in c:
        cnt += c[i+1]
    ans = max(ans, cnt)

print(ans)


Measured memory_bytes: 14564
import heapq

x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p2 = heapq.nlargest(x, p)
q2 = heapq.nlargest(y, q)
r2 = heapq.nlargest(x+y, r)
p2.append(0)
q2.append(0)
r2.append(0)

pi = 0
qi = 0
ri = 0

val = 0

for _ in range(x+y):
    if p2[pi] >= q2[qi] and p2[pi] >= r2[ri]:
        val += p2[pi]
        pi += 1
    elif p2[pi] <= q2[qi] and q2[qi] >= r2[ri]:
        val += q2[qi]
        qi += 1
    else:
        val += r2[ri]
        ri += 1

print(val)


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

int main() {
    int n,ans=0;cin>>n;
    int a[n],b[n-1];
    
    for(int i=0;i<n-1;++i){
        cin>>b[i];
    }
    
    a[0]=b[0];
    for(int i=1;i<n-1;++i){
        a[i]=min(b[i-1],b[i]);
    }
    a[n-1]=b[n-2];
    for(int i=0;i<n;++i){
        ans+=a[i];
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all> // NOTE: AtCoderライブラリ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
// using namespace atcoder; // NOTE: AtCoderライブラリ
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef pair<int, int> pii;
// #define INF __INT32_MAX__
#define INF 1e9
#define LINF __LONG_LONG_MAX__

int main() {
    int X; cin >> X;
    if (X == 1) {
        cout << 0 << endl;
    } else {
        cout << 1 << endl;
    }
}


Measured memory_bytes: 3580
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<ctime>
#include<cstdlib>
#define ll long long
#define db double
using namespace std;
db a[110],b[110],ans,nx,ny,now;
ll n,m;
inline db ji(db x) { return x*x; }
db check(db x,db y)
{
	db ans=0;
	for(ll i=1;i<=n;++i) ans=max(ans,ji(x-a[i])+ji(y-b[i]));
	return ans;
}
void work(db x,db y,db z)
{
	nx=ny=now=0; ans=1e9;
	db a=x-z*1000,b=x+z*1000,c=y-z*1000,d=y+z*1000;
	for(db i=a;i<=b;i+=z)
	{
		for(db j=c;j<=d;j+=z)
		{
			now=check(i,j);
			if(now<ans) ans=now , nx=i ,ny=j;
		}
	}
}
int main()
{
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	cin>>n;
	for(ll i=1;i<=n;++i) cin>>a[i] >>b[i];
	ans=1e9;
	work(0,0,1);
	work(nx,ny,1e-2);
	work(nx,ny,1e-4);
	work(nx,ny,1e-6);
	work(nx,ny,1e-8);
	printf("%.15lf",sqrt(ans));
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>
#include <bitset>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int a[110000], cnt[110000];

int main(){
	int N;
	cin >> N;
	if(N == 2){
		cout << -1 << endl;
		return 0;
	}
	map<int, int> m;
	for(int i = 1; i <= N; i++){
		cin >> a[i];
		cnt[a[i]] += 1;
		m[i] = 0;
	}
	int nex = 0;
	vector<int> v;
	for(int loop = 0; loop < N; loop++){
		auto ite = m.begin();
		while(true){
			int num = ite->first;
			//cout << loop << " " << ite->first << " hoge" << endl;
			if(num == nex){
				ite++;
				continue;
			}
			int rem = m.size() - 1;
			if(rem == 0){
				v.push_back(num);
				break;
			}
			if(cnt[a[num]] >= rem){
				ite++;
				continue;
			}
			if(rem == 2){
				vector<int> v;
				for(P p : m){
					if(num != p.first){
						v.push_back(p.first);
					}
				}
				if(a[v[0]] == v[1] && a[v[1]] == v[0]){
					ite++;
					continue;
				}
			}
			cnt[a[num]] -= 1;
			cnt[num] = 0;
			m.erase(ite->first);
			nex = a[num];
			v.push_back(num);
			break;
		}
	}
	for(int i = 0; i < v.size() - 1; i++){
		cout << v[i] << " ";
	}
	cout << v[v.size() - 1] << endl;
	return 0;
}

Measured memory_bytes: 7168
#include <iostream>
#include <limits.h>
using namespace std;

int main() {
	long long n, x, i, ans = 0, a[10000000];
	cin >> n >> x;
	a[1] = x; a[2] = n - x;
	
	if (a[1] < a[2]) {
	    a[3] = x;
	    ans += (a[1] + a[2]);
	    i = 3;
	    while (a[i - 1] % a[i] != 0) {
	        a[i + 1] = a[i - 1] % a[i];
	        ans += ((a[i - 1] / a[i]) * a[i] * 2);
          	i++;
	    }
	    ans += (((a[i - 1] / a[i]) * 2 - 1) * a[i]);
	}
	
	else if (a[1] > a[2]) {
	    ans += a[1];
	    i = 2;
	    while (a[i - 1] % a[i] != 0) {
	        a[i + 1] = a[i - 1] % a[i];
	        if (i != 2) ans += ((a[i - 1] / a[i]) * a[i] * 2);
          	else ans += (((a[i - 1] / a[i]) * 2 + 1) * a[i]);
          	i++;
	    }
	    if (i != 2) ans += (((a[i - 1] / a[i]) * 2 - 1) * a[i]);
      	else ans += (((a[i - 1] / a[i]) * 2) * a[i]);
	}
	else { // equal 
	    ans = x * 3;
	}
	cout << ans;
	return 0;
}


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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

int c[13];
int a[13][13];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, m, x;
    cin >> n >> m >> x;

    for (int i = 0; i < n; i++){
      cin >> c[i];
      for (int j = 0; j < m; j++) cin >> a[i][j];
    }

    auto test = [](int x, int pos){
      return (x >> pos) & 1;
    };

    int ans = 1e9;

    for (int mk = 0; mk < (1 << n); mk++){

      int cr = 0;
      int cc[13];
      memset(cc, 0, sizeof cc);

      for (int i = 0; i < n; i++){
        if (test(mk, i)){
          cr += c[i];
          for (int j = 0; j < m; j++){
            cc[j] += a[i][j];
          }
        }
      }

      int f = 1;
      for (int j = 0; j < m; j++){
        if (cc[j] < x) f = 0;
      }

      if (f) ans = min(ans, cr);
    }

    if (ans >= 1e9) ans = -1;
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<string>
using namespace std;
int main(){
 int n,k,p;
 cin>>n;
 for(int i=0;i<n;i++){
  cin>>k>>p;
  int ans=k%p;
  if(ans==0)
      ans=p;
  cout<<ans<<endl;
 }
 return 0;   
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, k; cin >> n >> k;
    vi a(n), acnt(60, 0);
    rep(i, n){
        cin >> a[i];
        rep(bit, 60) if(a[i]&(1LL<<bit)) acnt[bit]++;
    }

    ll ans = 0;
    for(ll i=60; i>=-1; i--){
        // X=K以外の場合で、iビット目が0だったら飛ばす。
        if(i != -1 && !(k&(1LL<<i))) continue;

        // iビット目より下位のビットは自由なので、上位ビットから貪欲法で求める。
        ll tmp = 0;
        for(ll bit = 60; bit>=0; bit--){
            ll mask = (1LL<<bit);

            // Kと一致していなきゃいけない箇所ならば
            if(bit>i){
                if(k&mask) tmp += mask*(n-acnt[bit]);
                else tmp += mask*acnt[bit];
            }
            // Kと最初に異なる場所
            else if(bit == i){
                tmp += mask*acnt[bit];
            }
            // 自由な場所
            else{
                tmp += mask*max(acnt[bit], n-acnt[bit]);
            }
        }
        chmax(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
/*メモ 
*/
int main(){
    int n,m;
    std::cin >> n>>m;
    vvector(a,char,n,m,'0');
    vvector(ans,int,n,m,0);
    reprep(i,j,n,m)std::cin >> a[i][j];
    reprep(i,j,n,m){
        for (int ii = max(0,i-1); ii <=min(i+1,n-1) ; ii++) {
            for (int jj = max(0,j-1); jj <=min(j+1,m-1) ; jj++) {
            /* code */
            if((ii!=i||jj!=j)&&a[ii][jj]=='#')ans[i][j]++;
            }
        }
    }
    rep(i,n){
        rep(j,m){
            if(a[i][j]=='#')std::cout << '#';
            else std::cout << ans[i][j];
            
        }
        std::cout << std::endl;
    }
}




Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    v = []
    for _ in range(5):
        v.append(int(input()))
    v.sort()

    ans = INF
    for p in permutations(v):
        t = 0
        for x in p:
            if t % 10 != 0:
                t += 10 - (t % 10)
            t += x

        ans = min(ans, t)

    print(ans)


if __name__ == '__main__':
    main()


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

public class Main
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		double a[] = new double[n];
		int b[] = new int[7];
		Arrays.fill(b, 0);

		for(int i=0; i<n; i++)
			a[i]=sc.nextDouble();
		for(int i=0; i<n; i++)
		{
			if(a[i]<165.0)
			{
				b[1]++;
				continue;
			}
			else if(a[i]<170.0)
			{
				b[2]++;
				continue;
			}
			else if(a[i]<175.0)
			{
				b[3]++;
				continue;
			}
			else if(a[i]<180.0)
			{
				b[4]++;
				continue;
			}
			else if(a[i]<185.0)
			{
				b[5]++;
				continue;
			}
			else if(a[i]>=185.0)
			{
				b[6]++;
				continue;
			}
		}
		for(int i=1; i<=6; i++)
		{
			System.out.print(i+":");
			for(int j=0; j<b[i]; j++)
				System.out.print("*");
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long a,b,c,k;
    scanf("%lld %lld %lld %lld",&a,&b,&c,&k);
    long long sum=0;
    if(k-a<=0){
        sum+=k;
    }
    else{
        sum+=a;
        k=k-a;
        if(k-b>0){
            k=k-b;
            sum=sum-k;
        }
    }
    printf("%lld",sum);
    return 0;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)(j);i <= (int)(k);i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
typedef long long ll;

struct edge{
    ll to,a,b;
};
struct Data{
    ll v,s,t;
    bool operator < (const Data & a)const{return t>a.t;}
};

const ll  MAXN=50,MAXS=MAXN*50,INF=1e18;
ll dp[MAXN+1][MAXS+1];
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n,m,s;cin>>n>>m>>s;
    vector<edge> E[MAXN+1];
    rep(i,1,m){
        int u,v,a,b;
        cin>>u>>v>>a>>b;
        E[u].push_back((edge){v,a,b});
        E[v].push_back((edge){u,a,b});
    }
    vector<int> c(n+1),d(n+1);
    rep(i,1,n){
        cin>>c[i]>>d[i];
    }
    s=min(s,MAXS);
    rep(i,1,n)rep(j,0,MAXS)dp[i][j]=INF;dp[1][s]=0;
    priority_queue<Data> Q;
    Q.push((Data){1,s,0});
    while(!Q.empty()){
        Data dt=Q.top();Q.pop();
        //debug(dt.v),debug(dt.s),debug(dt.t);
        //if(dt.s<0)continue;
        if(dt.t>dp[dt.v][dt.s])continue;
        //change
        ll ns=min(dt.s+c[dt.v],MAXS);
        ll nt=dt.t+d[dt.v];//?dp[dt.v][dt.s]+d[dt.v]
        if(dp[dt.v][ns]>nt){
            dp[dt.v][ns]=nt;
            Q.push((Data){dt.v,ns,nt});
        }
        // trans
       
        for(auto e:E[dt.v]){
            ns=dt.s-e.a;
            nt=dt.t+e.b;//?dt.t+e.b
            if(ns>=0 and dp[e.to][ns]>nt){
                dp[e.to][ns]=nt;
                Q.push((Data){e.to,ns,nt});
            }
        }
    }
    rep(i,2,n){
        ll ans=INF;
        rep(j,0,MAXS){
            ans=min(ans,dp[i][j]);
            
        }
        cout<<ans<<endl;
    }
}
/* 
dp[i][j] min time takes from 1 to node i, have j coin with me.
dp[i][j]=dp[k][j-cost]
wr: 最后的更新出错, INF太小
 */

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



int main(){
    int n;cin >> n;
    map<int,int> mp;
    int cnt = 0;
    rep(i,n){
        int a;cin >> a;
        mp[a]++;
        if(mp[a]==1)cnt++;
    }
    int ecnt = 0;
    for(auto p:mp){
        if(p.second%2==0)ecnt++;
    }

    cout << cnt - (ecnt%2) << endl;
}

Measured memory_bytes: 8272
def bellman_ford(s):
    d = [float('inf')]*(N+1) # 各頂点への最小コスト
    d[s] = 0 # 自身への距離は0
    nega = [0 for i in range(N+1)]
    for i in range(N+1):
        update = False # 更新が行われたか
        for x, y, z in g:
            if d[y] > d[x] + z:
                d[y] = d[x] + z
                update = True
                nega[y] += 1
        if not update:
            break
        # 負閉路が存在
        if i == N :
          d[0] = -1
    return [d,nega]

N,M = map(int,input().split())
g = []

for _ in range(M):
    x, y, z = [int(x) for x in input().split()] # 始点,終点,コスト
    g.append([x, y, -z])

ans = bellman_ford(1)

if ans[1][-1] > 1:
  print("inf")
else:
  print(int(-ans[0][-1]))

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

ll mod = 1e9+7;

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

  string s;
  cin >> s;
  string ret = "Yes";
  if((int)(s.length()) % 2 != 0)ret = "No";
  for(int i = 0;i < s.length()-1;i+=2){
    if(s[i] != 'h' || s[i+1] != 'i'){
      ret = "No";
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6 + 5;
const ll N=1e3+5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;

int main(){
	ll n;
	cin>>n;
	if(n%1000==0) cout<<"0"<<endl;
	else{
		ll k=n/1000;
		cout<<(k+1)*1000-n<<endl;
	}
}

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll ketawa(ll n) {   // nの各桁の数の和
    ll res = 0;    
    while(n != 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    ll ans = 0;
    exrep(x, 1, n) {
        ll m = ketawa(x);
        if(a <= m && m <= b) {
            ans += x;
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    # dp[i][j][k][l] := 長さiの文字において，後ろから3つ目の文字がj,
    # 後ろから2つ目の文字がk, 後ろから1つの文字がlの時の組み合わせ数
    dp = [[[[0] * 5 for _ in range(5)] for _ in range(5)] for _ in range(N + 1)]

    A = 1
    G = 2
    C = 3
    T = 4

    # 文字の意味は，0 => None, 1 => A, 2 => G, 3 => C, 4 => T
    dp[0][0][0][0] = 1
    for i in range(1, N + 1):
        for j in range(5):
            for k in range(5):
                for l in range(5):
                    for m in range(1, 5):
                        if k == A and l == G and m == C:
                            continue
                        if k == A and l == C and m == G:
                            continue
                        if k == G and l == A and m == C:
                            continue
                        if j == A and l == G and m == C:
                            continue
                        if j == A and k == G and m == C:
                            continue

                        dp[i][k][l][m] += dp[i - 1][j][k][l]
                        dp[i][k][l][m] %= MOD

    ans = 0
    for j in range(1, 5):
        for k in range(1, 5):
            for l in range(1, 5):
                ans += dp[-1][j][k][l]
                ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3444
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

// author:Swastik Banerjee

using namespace std;

typedef long long ll;
#define MOD 1000000007

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


  ll s, w;
  cin >> s >> w;
  if (w >= s)
    cout << "unsafe\n";
  else
    cout << "safe\n";
}

Measured memory_bytes: 3640
import sys
import heapq as hq
input = sys.stdin.readline
N, M = list(map(int,input().strip().split()))
A = list(map(int,input().strip().split()))
A = list(map(lambda x:-x, A))
hq.heapify(A)
for i in range(M):
	target = A[0]/2
	hq.heappushpop(A,target)
A = list(map(lambda x:-x, A))
print(sum(map(int,A)))

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

int dp[100005];
vector<int> adj[100005];
bool visited[100005];

void visit(int vertex)
{
    visited[vertex]=1;
    dp[vertex]=0;
    for(int child:adj[vertex])
    {
        if(!visited[child]){
            visit(child);
        }
            dp[vertex]=max(dp[vertex],1+dp[child]);
    }
}

int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
    }

    for(int i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            visit(i);
        }
    }

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


Measured memory_bytes: 12056
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        n: usize,
        s: Chars,
    }

    let s = s.into_iter().map(|c| c.to_digit(10).unwrap()).collect::<Vec<_>>();

    let mut count = 0;

    for i in 0..10 {
        let mut i_index = 0;
        while i_index < n {
            if i == s[i_index] {
                break;
            }
            i_index += 1;
        }
        for j in 0..10 {
            let mut j_index = i_index + 1;
            while j_index < n {
                if j == s[j_index] {
                    break;
                }
                j_index += 1;
            }
            for k in 0..10 {
                let mut k_index = j_index + 1;
                while k_index < n {
                    if k == s[k_index] {
                        break;
                    }
                    k_index += 1;
                }
                if k_index < n {
                    count += 1;
                }
            }
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 2320
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10


N = INT()
S = [input() for _ in range(N)]

print("AC x {}".format(S.count("AC")))
print("WA x {}".format(S.count("WA")))
print("TLE x {}".format(S.count("TLE")))
print("RE x {}".format(S.count("RE")))

Measured memory_bytes: 17648
import fractions
import sys

input = sys.stdin.readline

n = int(input())

list_dayo = [tuple(map(int, input().split())) for _ in range(n)]

list_dayo.sort(key=lambda x: x[1])

flag = True
current_cost = 0
for item in list_dayo:
    current_cost += item[0]
    if current_cost > item[1]:
        flag = False
        break

if not flag:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 33876
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#define mp(i, j) make_pair(i, j)
#define fir first
#define sec second
#define pii pair<int, int>
#define ppi pair<pii, int>
const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f; 
using namespace std;

int n, head[N], cnte, cnt, m, ans[N], in[N], lg[N], s[2][20][N], pw[22], a[N], pos[N];
pii w[N]; 
struct edge { int to, nxt; } e[N << 1]; 
priority_queue<ppi, vector<ppi >, greater<ppi > > q; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

inline void adde(int u, int v) { e[++cnte] = (edge) { v, head[u] }, head[u] = cnte, in[v]++; }

int query(int l, int r, int op)
{
	int x = lg[r - l + 1]; 
	return min(s[op][x][l], s[op][x][r - pw[x] + 1]); 
}

int solve(int l, int r)
{
	if(r - l + 1 == 2)
	{
		cnt++, w[cnt].fir = a[l], w[cnt].sec = a[r];
		return cnt; 
	}
	int x = pos[query(l, r, l & 1)], y = pos[query(x + 1, r, (l & 1) ^ 1)]; 
	cnt++, w[cnt].fir = a[x], w[cnt].sec = a[y]; int tmp = cnt; 
	if(x > l) adde(tmp, solve(l, x - 1)); 
	if(x + 1 < y - 1) adde(tmp, solve(x + 1, y - 1)); 
	if(y + 1 < r) adde(tmp, solve(y + 1, r));
	return tmp; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	n = read <int> ();
	memset(s, 0x3f, sizeof(s)); 
	for(int i = 1; i <= n; i++)
		a[i] = read <int> (), pos[a[i]] = i, s[i & 1][0][i] = a[i]; 
	for(int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1; 
	for(int i = (pw[0] = 1); i <= 20; i++) pw[i] = pw[i - 1] * 2; 
	for(int op = 0; op <= 1; op++)
		for(int i = 1; i <= 18; i++)
			for(int j = 1; j + pw[i] - 1 <= n; j++)
				s[op][i][j] = min(s[op][i - 1][j], s[op][i - 1][j + pw[i - 1]]); 
	solve(1, n); 
	for(int i = 1; i <= cnt; i++) if(!in[i]) q.push(mp(w[i], i));
	while(!q.empty())
	{
		int u = q.top().sec; q.pop();
		ans[++m] = w[u].fir, ans[++m] = w[u].sec; 
		for(int v, i = head[u]; i; i = e[i].nxt)
		{
			v = e[i].to, in[v]--;
			if(!in[v]) q.push(mp(w[v], v)); 
		}
	}
	for(int i = 1; i <= m; i++) printf("%d%c", ans[i], i == m ? '\n' : ' '); 
	return 0; 
}


Measured memory_bytes: 45176
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
int main(){
  string s;
  cin >> s;
  for(int i = 0;i < s.size();i++){
	if(s[i] == ',')s[i] = ' ';
  }
  cout << s << endl;  
  return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<int> vc(n);
	for (int i=0;i<n;i++){
		cin >> vc.at(i);
	}
	for (int i=0;i<n;i++){
		int v, j;
		v = vc.at(i);
		j = i - 1;
		while (j>=0 && vc.at(j)>v){
			vc.at(j+1) = vc.at(j);
			j--;
		}
		vc.at(j+1) = v;
		for (int i=0;i<n;i++){
			if (i<n-1){
			cout << vc.at(i) << " "; 
			}
			else{
				cout << vc.at(i) << endl;
			}
		}
	}

}


Measured memory_bytes: 3104
#include<cstdio>
#include<list>
#include<algorithm>
using namespace std;

int main() {
  int q, x;
  char com[20];
  // 標準ライブラリよりlist を使用
  list<int> v;
  scanf("%d", &q);
  for ( int i = 0; i < q; i++ ) {
    scanf("%s", &com);
    if ( com[0] == 'i' ) {  // insert
      scanf("%d", &x);
      v.push_front(x);
    } else if ( com[6] == 'L' ) {  // deleteLast
      v.pop_back();
    } else if ( com[6] == 'F' ) {  // deleteFirst
      v.pop_front();
    } else if ( com[0] == 'd' ) {  // delete
      scanf("%d", &x);
      for ( list<int>::iterator it = v.begin(); it != v.end(); it++ )
        if ( *it == x ) {
          v.erase(it);
          break;
        }
    }
  }
  int i = 0;
  for ( list<int>::iterator it = v.begin(); it != v.end(); it++ ) {
    if ( i++ ) printf(" ");
    printf("%d", *it);
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 33888
#coding:utf-8
import sys
import bisect
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N = II()
    L = LMIIS()
    L.sort()
    count = 0
    for i in range(N):
        for j in range(i+1,N):
            a = L[i]
            b = L[j]
            l = bisect.bisect_right(L,a-b,lo=j+1)
            r = bisect.bisect_left(L,a+b,lo=j+1)
            count += max(r - l ,0)
    print(count)



if __name__ == '__main__':
    main()

Measured memory_bytes: 45488