akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

ll merged(int A[], int l, int q, int r)
{
    ll i, j, k, inversions = 0;

    int n1 = q - l + 1;
    int n2 = r - q;

    int L[n1], R[n2];

    for (i = 0; i < n1; ++i)
        L[i] = A[l + i];

    for (j = 0; j < n2; ++j)
        R[j] = A[q + j + 1];

    for (i = 0, j = 0, k = l; k <= r; ++k)
    {
        if (i == n1)
            A[k] = R[j++];
        else if (j == n2)
            A[k] = L[i++];
        else if (L[i] <= R[j])
            A[k] = L[i++];
        else
        {
            A[k] = R[j++];
            inversions += n1 - i;
        }
    }
    return inversions;
}

ll merge_sort(int A[], int l, int r)
{
    if (l < r)
    {
        ll inversions = 0;
        int q = (l + r) / 2;
        inversions += merge_sort(A, l, q);
        inversions += merge_sort(A, q + 1, r);

        inversions += merged(A, l, q, r);
        return inversions;
    }
    else
        return 0;
}

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

    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; ++i)
    {
        int a;
        cin >> a;
        A[i] = a;
    }

    ll ans = merge_sort(A, 0, N - 1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,k;
  string s;
  cin >> n >> s >> k;
  char c = s.at(k-1);
  for (char cc : s) {
    if (cc == c) cout << cc;
    else cout << '*';
  }
  cout << endl;
  return 0;
}


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

int main() {
    string S;
    cin >> S;
    int N = S.size();
    int count = 0;
    for (int i = 0; i < N; i++) {
        if (S.at(i) == 'x') {
            count++;
        }
    }

    if (count > 7) {
        cout << "NO" << endl;
    }
    else {
        cout << "YES" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  char x;
  int a=0,b=0,c=0;
  for(int i=0;i<3;i++){
    cin>>x;
    if(x=='a')a++;
    else if(x=='b')b++;
    else if(x=='c')c++;
  }
  if(a==1&&b==1&&c==1)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
typedef long long ll;



int main() {
	int n;
	cin >> n;
	int a[105];
	for (int i = 1; i <= n; i++) { cin >> a[i]; }
	for (int i = 1; i <= n; i++){
	if (a[i] % 2 == 0) {
		if (a[i] % 3 && a[i] % 5) {
			cout << "DENIED"; return 0;
		}
	}
	
	}
	cout << "APPROVED";
	return 0;
}

Measured memory_bytes: 256
from bisect import *
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[0]
for i in a:
    c+=[c[-1]+i]
d=[0]
for i in b:
    d+=[d[-1]+i]

ans=j=bisect(d,k)-1

for i in range(n+1):
    while c[i]+d[j]>k and c[i]<k:
        j-=1
    if c[i]+d[j]<=k:    
        ans=max(ans,i+j)
print(ans)

Measured memory_bytes: 47556
import collections
import sys
input = sys.stdin.readline
import heapq
def solve():
  n = int(input())

  query2 = []
  edge = [[] for _ in range(n)]
  ans = [ 0 for i in range(n)]
  for i in range(n-1):
    a,b = (int(i) for i in input().split())
    query2.append(a)
    query2.append(b)
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
  c = list(int(i) for i in input().split())
  if n == 1:
    print(0)
    print(c[0])
    exit()
  c = collections.deque(sorted(c,reverse =True))
  d = collections.Counter(query2)
  d2 = d.most_common()
  bfs = []
  heapq.heappush(bfs,(-1*d2[0][1],d2[0][0]-1))#回数,場所、親
  ct = 0
  visit = [False]*n
  
  while bfs:
    times,place = heapq.heappop(bfs)
    if visit[place]:
      continue
    else:
      visit[place] = True

      for i in range(len(edge[place])):
        newp = edge[place][i]
        newtimes = len(edge[newp])
        if not visit[newp]:
          heapq.heappush(bfs,(-1*newtimes,newp))
      #print(place,parent,times)
      ans[place] = c.popleft()

      #print(c,place)

  print(sum(ans)-max(ans))
  print(*ans)
  
solve()


Measured memory_bytes: 8384
#include<iostream>
#include<cstring>
using namespace std;
int main(){
  double c,a[10]={48.00,51.00,54.00,57.00,60.00,64.00,69.00,75.00,81.00,91.00};
  string b[11]={"light fly","fly","bantam","feather","light","light welter",
	      "welter","light middle","middle","light heavy","heavy"};
  while(cin>>c)
    for(int i=0;i<10;i++)
      if(c<=a[i]){
	cout<<b[i]<<endl;
	break;
      }
      else if(c>a[9]){
	cout<<b[10]<<endl;
	break;
      }
  return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,l;
    cin >> n;
    vector<vector<ll>> d(n,vector<ll>(n)),to(n,vector<ll>(n));
    rep(i,n) rep(j,n){
        cin >> l;
        d[i][j] = l;
        to[i][j] = l;
    }
    rep(k,n){
        rep(i,n){
            rep(j,n){
                chmin(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    bool out = 0;
    rep(i,n){
        rep(j,n){
            rep(k,n){
                if (to[i][j] > d[i][k]+d[k][j]) out = 1;
            }
        }
    }
    if (out){
        PRINT(-1);
        return 0;
    }
    ll cnt = 0;
    rep(i,n){
        rep(j,n){
            bool ok = 0;
            rep(k,n){
                if (i == k || j == k) continue;
                if (d[i][j] == d[i][k]+d[k][j]) ok = 1;
            }
            if (ok == 0) cnt += to[i][j];
        }
    }
    PRINT(cnt/2);
}


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

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

    String s = sc.next();

    if(s.equals("Sunny")){
      System.out.println("Cloudy");
    }else if(s.equals("Cloudy")){
      System.out.println("Rainy");
    }else if(s.equals("Rainy")){
      System.out.println("Sunny"); 
    }

  }
}

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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a+b > c+d){
        cout << "Left" << endl;
    }else if(a+b < c+d){
        cout << "Right" << endl;
    }else{
        cout << "Balanced" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    ll n, k;
    cin >> n >> k;
    vector<P> a(n);
    rep(i, n) {
        cin >> a[i].first >> a[i].second;
    }
    sort(a.begin(), a.end());

    ll num = 0;
    rep(i, n) {
        num += a[i].second;
        if(num >= k) {
            cout << a[i].first << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
        public static void main(String[] args) {
                Scanner scanner = new Scanner(System.in);
                int N = scanner.nextInt();
                int[] B = new int[N];
                for (int i = 0; i < N - 1; i++) {
                        int A = scanner.nextInt();
                        B[A - 1]++;
                }

                for (int i = 0; i < N; i++)
                        System.out.println(B[i]);
        }
}

Measured memory_bytes: 69312
import numpy as np

n = int(input())
a = list(map(int,input().split()))
a = np.array(a,dtype=np.int64)
point = 0
mod = 10**9+7

b = [((a>>i)&1).sum() for i in range(61)]
c = [n-b[i] for i in range(61)]
d = [c[i]*b[i]%mod for i in range(61)]

point = 0
now = 1

for i in range(61):
    point += now*d[i]
    point %= mod
    now *= 2
    now %= mod

print(point)

Measured memory_bytes: 48808
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1e+9;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

vector<ll> h;
vector<bool> ok;

int main() {
  int N,M;
  cin >> N >> M;
  h.resize(N);
  ok.resize(N,true);
  rep(i,N) cin >> h[i];
  rep(i,M) {
    int a,b;
    cin >> a >> b;
    a--;b--;
    if(h[a] > h[b]) ok[b] = false;
    if(h[b] > h[a]) ok[a] = false;
    if(h[b] == h[a]) ok[a] = ok[b] =false;
  }
  int ans = 0;
  rep(i,N) if(ok[i]) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  string S; cin >> S;
  int N = S.size();
  int l[N+1], r[N+1];
  int cntl = 0, cntr = 0;
  rep(i,N+1){
    if (i<N){
      l[i] = cntl;
      if (S[i]=='<') cntl++;
      else cntl = 0;
    }
    else l[i] = cntl;
  }

  for (int i = N;i>=0;i--){
    if (i>0){
      r[i] = cntr;
      if (S[i-1]=='>') cntr++;
      else cntr = 0;
    }
    else r[i] = cntr;
  }

  ll retval = 0;
  rep(i,N+1) retval += max(l[i],r[i]);
  cout << retval << endl;



  // cout << fixed << setprecision(6);
  return 0;
}



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

#define nil NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *p;
  int key;
};
typedef struct node * Node;

Node root;

Node treeMinimum(Node);
Node treeMaximum(Node);
Node treeSearch(Node, int);
Node treeSuccessor(Node);
void treeDelete(Node);
void transplant(Node,Node);
void insert(int);
void inorder(Node);
void preorder(Node);

int main(){
  int n, a, x;
  char command[20];
  scanf("%d",&n);

  for(a = 0; a < n; a++){
    scanf("%s",command);
    if(command[0] == 'f'){
      scanf("%d",&x);
      Node t = treeSearch(root,x);
      if(t != nil) printf("yes\n");
      else printf("no\n");
    }
    else if(command[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(command[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(command[0] == 'd'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }

  return 0;
}

Node treeMinimum(Node x){
  while(x->left != nil) x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != nil) x = x->right;
  return x;
}

Node treeSearch(Node x, int k){
  if(x == nil || k == x->key) return x;
  if(k < x->key) return treeSearch(x->left,k);
  else return treeSearch(x->right,k);
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != nil) return treeMinimum(x->right);
  y = x->p;
  while(y != nil && x == y->right){
    x = y;
    y = y->p;
  }
  return y;
}

void treeDelete(Node z){
  Node y;
  if(z->left == nil) transplant(z,z->right);
  else if(z->right == nil) transplant(z,z->left);
  else{
    y = treeMinimum(z->right);
    if(y->p != z){
      transplant(y,y->right);
      y->right = z->right;
      y->right->p = y;
    }
    transplant(z,y);
    y->left = z->left;
    y->left->p = y;
  }
}

void transplant(Node u, Node v){
  if(u->p == nil) root = v;
  else if(u == u->p->left) u->p->left = v;
  else u->p->right = v;
  if(v != nil) v->p = u->p;
}

void insert(int k){
  Node y = nil;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = nil;
  z->right = nil;
  
  while(x != nil){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->p = y;
  if(y == nil) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node x){
  if(x != nil){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  }
}

void preorder(Node x){
  if(x != nil){
    printf(" %d",x->key);
    preorder(x->left);
    preorder(x->right);
  }
}



Measured memory_bytes: 20476
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};



int main()
{
  ll N,M,G,F;
  string S,T,SS="",TT="";
  map<int,char> mp;
  cin >> N >> M;
  cin >> S;
  cin >> T;
  G = __gcd(N,M);
  F = N*M/G;
  REP(i,N){
    mp[1+i*F/N] = S[i];
  }
  REP(i,M){
    if(mp[1+i*F/M] == 0)
      mp[1+i*F/M] = T[i];
    else if(mp[1+i*F/M] != T[i]){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << F << endl;
  return 0;
}



Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int main() {
        map<string, int> dic;
        int n;
        string op, word;
        cin >> n;
        while (n-->0) {
                cin >> op >> word;
                switch (op[0]) {
                case 'i':
                        dic[word] = 1;
                        break;
                case 'f':
                        if (dic[word]) {
                                cout << "yes" << endl;
                        } else {
                                cout << "no" << endl;
                        }
                }
        }
        return 0;
}

Measured memory_bytes: 52564
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line[] = br.readLine().split(" ");
		int n = Integer.parseInt(line[0]);
		int k = Integer.parseInt(line[1]);

		System.out.println(n % k == 0 ? "0" : "1");

	}

}

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

#define ll long long int

#define rep(p,q) for(int i = p; i < q;i++)

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

//5
int main(void) {
	ll a, b;
	while (cin >> a >> b) {
		ll g = gcd(a, b);
		ll l = a * b / g;
		cout << g << " " << l << endl;
	}
}



Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
 
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> P;
 
#define all(x) x.begin(),x.end()
 
const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;
 
int n,k,cnt;
vector<int> flag;
vector<vector<P> > g;
vector<P> edge;


void delete_count(int x,int len,int lim){
    flag[x] = 1;
    if(len > lim) cnt++;
    for(int i = 0; i < g[x].size(); i++){
        int now = g[x][i].second;
        if(flag[now]<0) delete_count(now,len+1,lim);
    }
}
 
int main()
{
    cin>>n>>k;
    g.resize(n);
    flag.resize(n);
    for(int i = 0; i < n-1; i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(P(1,b));
        g[b].push_back(P(1,a));
        edge.push_back(P(a,b));
    }
 

    int ans = INF;
    if(k%2==0){
        for(int i = 0; i < n; i++){
            flag.assign(flag.size(),-1);
            cnt = 0;
            delete_count(i,0,k/2);
            ans = min(ans,cnt);
        }
    }else{
        for(int i = 0; i < edge.size(); i++){
            int x = edge[i].first,y = edge[i].second;
            flag.assign(flag.size(),-1);
            cnt = 0;
            flag[x]=1;
            flag[y]=1;
            delete_count(x,0,(k-1)/2);
            delete_count(y,0,(k-1)/2);
            ans = min(ans,cnt);
        }
    }

    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    string s;
    cin >> s;
    string fes = "FESTIVAL";
    rep(i,s.size()-fes.size()){
        cout << s[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define dumpP(p) cerr << "( " << p.first << " , " << p.second << " )" << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define SORT(c) sort((c).begin(),(c).end())
#define MIN(vec) *min_element(vec.begin(), vec.end());
#define MAX(vec) *max_element(vec.begin(), vec.end());
#define UNIQ(vec) vec.erase(unique(vec.begin(), vec.end()),vec.end());
#define IN(n,m)  (!(m.find(n) == m.end()))
#define TO_INT(vec,s) REP(i,s.length()){vec.push_back(s[i] - ‘0’);}
#define ENUM_v(vec) for (auto e : vec)
#define dump_MAP(m) for(auto itr = m.begin(); itr != m.end(); ++itr) { cerr << itr->first << " --> "  << itr->second << endl; }
#define FINDL(vec,x) (lower_bound(vec.begin(),vec.end(),x) - vec.begin())
#define FINDU(vec,x) (upper_bound(vec.begin(),vec.end(),x) - vec.begin())
#define ROUND(N) setprecision(N)
using namespace std;
constexpr long mod = 1000000007;
constexpr short shINF = 32767;
constexpr long loINF = 2147483647;
constexpr long long llINF = 9223372036854775807;
typedef long long LL;
typedef vector<long> VI;
typedef vector<VI> VVI;

template <typename T,typename D>
class Tree {
private:
	typedef struct {T node;D dist;T prev;} P;
	typedef pair<T,D> pr;
	typedef vector<pr> VP;
	vector<VP> E;
	T V;
public:
	Tree() : V(0){}
	Tree(T v) : V(v),E(v) {}

	void addEdgeDirected(T start,T goal,D weight){
		E[start].push_back(pr(goal,weight));
	}

	void addEdgeUndirected(T start,T goal,D weight){
		E[start].push_back(pr(goal,weight));
		E[goal].push_back(pr(start,weight));
	}

	pair<T,D> getDiameter(void){
		stack<P> st;
		pair<T,D> farV(V-1,0);
		st.push(P {V-1,0,-1});
		while (!st.empty()) {
			P e = st.top();
			st.pop();
			if (farV.second < e.dist) farV = pair<T,D> (e.node,e.dist);
			for ( auto &p : E[e.node]) {
				if (p.first != e.prev) st.push(P {p.first,e.dist+p.second,e.node});
			}
		}
		pair<T,D> farV2(farV.first,0);
		st.push(P {farV.first,0,-1});
		while (!st.empty()) {
			P e = st.top();
			st.pop();
			if (farV2.second < e.dist) farV2 = pair<T,D> (e.node,e.dist);
			for ( auto &p : E[e.node]) {
				if (p.first != e.prev) st.push(P {p.first,e.dist+p.second,e.node});
			}
		}

		return farV2;
	}
};

int main(void) {
	long N,s,t,w;
	cin >> N;
	Tree<long,long> tr(N);
	REP(i,N-1){
		cin >> s >> t >> w;
		tr.addEdgeUndirected(s,t,w);
	}
	auto p = tr.getDiameter();
	cout << p.second << endl;
}


Measured memory_bytes: 10696
// nlather (Nishant Raj Lather)
// Chrollo_Lucifer

/* ------------------------------ TEMPLATE BEGIN ------------------------------ */

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

/* ----------------- ORDERED SET (POLICY BASED DS) ----------------- */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree
    <T, null_type, less<T>, rb_tree_tag, 
    tree_order_statistics_node_update>;

/* -------------- BETTER RANDOM (RAND() IS DANGEROUS) -------------- */
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

/* ----------------- CUSTOM HASH FUNCTION FOR UMAP ----------------- */
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = 
            chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

/* ----------------------- DEBUGGING UTILITY ----------------------- */
#define cerr cout
void _print() {cerr << "]\n";}
template <typename T, typename... V> void _print(T t, V... v) {
    cerr << t; if(sizeof...(v)) cerr << ", "; _print(v...);
}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define rep(i, x, n) for (ll i = (ll)(x); i < (ll)(n); i++)
#define rrep(i, x, n) for (ll i = (ll)(x); i >= (ll)(n); i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define bs binary_search
#define minSelf(a, b) a = min(a, b)
#define maxSelf(a, b) a = max(a, b)
#define mem(arr, x) memset(arr, x, sizeof(arr))
using ll = long long int;
using ld = long double;
template <typename T, typename V> using P = pair<T, V>;
template <typename T> using V = vector<T>;
 ll MOD = 998244353LL;
const ll INF = 0x3f3f3f3f; // ~1e9 (1061109567)
const ld PI = 3.1415926535897932384626;
const ld EPS = 1e-9;
#define endl '\n' // REMOVE FOR INTERACTIVE TASKS
const ll MAX = 1e7+5;

/* ------------------------------- TEMPLATE END ------------------------------- */

int main() {
    boost
    ll x;
    cin >> x;
    ll ans = 0, n = 100;
    while(n < x) {
        ans++;
        n += n/100;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int bfs[30][30][1<<5][3];
int dx[3][4]={{1,0,-1,0},{1,0,-1,0},{1,0,-1,0}};
int dy[3][4]={{0,1,0,-1},{0,1,0,-1},{0,1,0,-1}};
int dt[3][4]={{1,2,1,2},{0,1,0,1},{2,0,2,0}};
char str[30][30];
struct wolf{
	wolf(){}
	int row,col,bit,t;
	wolf(int a,int b,int c,int d){
		row=a;col=b;bit=c;t=d;
	}
};
int main(){
	int H,W,L;
	scanf("%d%d%d",&H,&W,&L);
	dx[0][2]=dy[0][3]=-L;
	dx[1][0]=L;dy[2][1]=L;
	for(int i=0;i<H;i++)scanf("%s",str[i]);
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)for(int k=0;k<(1<<5);k++)for(int l=0;l<3;l++)
		bfs[i][j][k][l]=99999999;
	int sr,sc;
	int gr,gc;
	for(int i=0;i<H;i++)for(int j=0;j<W;j++){
		if(str[i][j]=='S'){sr=i;sc=j;}
		if(str[i][j]=='G'){gr=i;gc=j;}
	}
	bfs[sr][sc][0][0]=0;
	queue<wolf>Q;
	Q.push(wolf(sr,sc,0,0));
	while(Q.size()){
		wolf now=Q.front();
		Q.pop();
		for(int i=0;i<4;i++){
			int tr=now.row+dx[now.t][i];
			int tc=now.col+dy[now.t][i];
			int tt=dt[now.t][i];
			int br=tr;
			int bc=tc;
			if(tt==1)br+=L-1;
			if(tt==2)bc+=L-1;
			if(tr<0||tc<0||br>=H||bc>=W)continue;
			bool dame=false;
			for(int j=tr;j<=br;j++)for(int k=tc;k<=bc;k++){
				if('a'<=str[j][k]&&str[j][k]<='e'){
					int shu=str[j][k]-'a';
					if(!(now.bit&(1<<shu)))dame=true;
				}
				if(str[j][k]=='#')dame=true;
			}
			if(dame)continue;
			if(tt==0&&str[tr][tc]=='^')continue;
			int tbit=now.bit;
			if(tt==0&&'A'<=str[tr][tc]&&str[tr][tc]<='E'){
				tbit^=(1<<(str[tr][tc]-'A'));
			}
			if(bfs[tr][tc][tbit][tt]>999999){
				bfs[tr][tc][tbit][tt]=bfs[now.row][now.col][now.bit][now.t]+1;
				Q.push(wolf(tr,tc,tbit,tt));
			}
		}
	}
	int ret=99999999;
	for(int i=0;i<(1<<5);i++)ret=min(ret,bfs[gr][gc][i][0]);
	if(ret>9999999)printf("-1\n");
	else printf("%d\n",ret);
}

Measured memory_bytes: 1360
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vec<int> M(2),D(2);
    cin >> M[0] >> D[0] >> M[1] >> D[1];
    cout << (M[0]==M[1]? 0:1) << endl;   
}

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

int main() {
  long double L,ans;
  cin >> L;
  ans = pow(L/3,3);
  cout << fixed;
  cout << setprecision(12) <<ans << endl;
  //cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007LL
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  150
#define tmod             998244353LL
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll SUMD(ll n);
ll BS(vector<pair< ll ,ll > > &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
//bool P[N+1];
void Sieve(int n=N);
ll Powb(ll b,ll n,ll m);

int main()
{
fast;
ll q=1,t;
//cin >> q; t = q;
while(q--)
{
    ll i,j,n,m,k,l,r,a,b,c=0,d=0,e,g=0,p,u,v,w,x,y,flag=1;
    //n=m=k=i=j=l=r=a=b=c=d=u=v=w=p=x=y=0;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    ans = min(a,k);
    k -= min(a,k);
    k -= min(b,k);
    ans -= min(k,c);
    cout << ans;

}
    return 0;
}

//*****************************************************************************************************************************************

ll Powb(ll b,ll n,ll m)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2,m);
    if(n%2==0){return (temp*temp)%m;}
    else{return (b*((temp*temp)%m))%m;}
}

ll SUMD(ll n)
{   ll sum=0;
    while(n>0){sum += n%10;n = n/10;}
    return sum;

}
ll BS(vector<pair<ll,ll> > &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid].F==ser)
    {
        return mid;
    }
    else if(PS[mid].F > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}
/*
void Sieve(int n)
{
    memset(P,true,sizeof(P));
    P[0] = false;
    P[1]= false;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i])
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                P[j]=false;
            }
        }
    }

}

*/


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

const int maxn=1e6+5;

int n,a[maxn];
char s[maxn];

bool calc()
{
	bool re=0;
	fo(i,0,n) if (a[i]&1)
	{
		bool pd=1;
		for(int nn=n, ii=i; nn; nn>>=1, ii>>=1) if (!(nn&1) && (ii&1)) {pd=0; break;}
		re^=pd;
	}
	return re;
}

int main()
{
	scanf("%d",&n); n--;
	scanf("%s",s);
	bool one=0;
	fo(i,0,n)
	{
		a[i]=s[i]-'1';
		one|=(a[i]&1);
	}
	
	if (calc()) {puts("1"); return 0;}
	if (one) {puts("0"); return 0;}
	fo(i,0,n) if (a[i]==2) a[i]--;
	printf("%d\n",calc()<<1);
}

Measured memory_bytes: 5120
#include<iostream>
#include<cstring>
#include<map>
#include<deque>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	int t;
	long long s=0;
	cin>>t;
	s=(1+t)*t/2;
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<pdd> vdd;
typedef vector<pdi> vdi;
typedef vector<pdl> vdl;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
const ll MAXLL=0x3f3f3f3f3f3f3f3f;
const int MAX=0x3f3f3f3f;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template<class T>
void rsort(vector<T>& v){
	sort(v.rbegin(),v.rend());
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
bool is_sorted(vector<T>& v){
	return is_sorted(v.begin(),v.end());
}
template<class T>
bool sorted(vector<T>& v){
	return is_sorted(v);
}
void precompute(){
 
	return;
}
void solve(){
	int n,m;
	cin>>n>>m;
	int mx=0;
	vi v(m);
	for(int i=0;i<m;i++)cin>>v[i];
	for(int i=1;i<m;i++)mx=max(mx,v[i]-v[i-1]);
	mx=max(v[0]+n-v[m-1],mx);
	cout<<n-mx;
}
 
int main(){
	ios::sync_with_stdio(0);
	int numberofsubtestcases=1;
//	cin>>numberofsubtestcases;
	precompute();
	for(int looping=1;looping<=numberofsubtestcases;looping++){
//		cout<<"Case #"<<looping<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   int a,b,k;
           cin>>a>>b>>k;
           rep(i,0,k){
             if(i%2==0){
                  if(a%2==1)a--;
                  a/=2;
                  b+=a;
             }
             else{
                  if(b%2==1)b--;
                  b/=2;
                  a+=b;
             }
             //cout<<a<<" "<<b<<endl;
           }
           cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 3596
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int r = scanner.nextInt();
			int c = scanner.nextInt();
			if ((r | c) == 0)
				break;
			int[] a = new int[c];
			for (int i = 0; i < r; i++)
				for (int j = 0; j < c; j++)
					a[j] = a[j] * 2 + scanner.nextInt();
			int ans = 0;
			for (int i = 0; i < 1 << r; i++) {
				int k = 0;
				for (int j = 0; j < c; j++) {
					int bitc = Integer.bitCount(a[j] ^ i);
					k += Math.max(bitc, r - bitc);
				}
				ans = Math.max(ans, k);
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 75580
#include"bits/stdc++.h"
using namespace std;
int a,b;

int main(){
    cin>>a>>b;
    if(a>0)cout<<"Positive";
    else if(a==0||(a<0&&b>0))cout<<"Zero";
    else if((abs(b)-abs(a))%2!=0)cout<<"Positive";
    else cout<<"Negative";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//freopen("transmitters.in","r",stdin);
//cout<<fixed<<setprecision(6)<<n<<endl;
// transform(s.begin(), s.end(), s.begin(), ::tolower);
//double PI=3.14159265359,c=0;
#define all(v) v.begin(),v.end()
#define endl '\n'
#define ll long long
//#define f(n) for(int i=;i<n;i++)
double PI = acos(-1);
using namespace std;
void fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
ll arr[10000000],n;
vector<ll>v(1e6,-1);
ll minCost(int indx)
{
    ll path1,path2;
    if(indx==n-1)
        return 0;
        
    if(v[indx]!=-1)
        return v[indx];
        
    if(indx+1<n)
        path1=abs(arr[indx]-arr[indx+1])+minCost(indx+1);

    if(indx+2<n)
        path2=abs(arr[indx]-arr[indx+2])+minCost(indx+2);

    return v[indx]=min(path1,path2);
}
int main()
{
    fast();
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];

    cout<<minCost(0)<<endl;

    return 0;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    vector<ll> a(n);rep(i,n)cin>>a[i];
    vector<ll> one(60,0);
    for(int i=0; i<n; i++){
        for(int j=0; j<60; j++){
            if((a[i]>>j)&1LL)one[j]++;
        }
    }
    ll ans = 0;
    for(int j=0; j<60; j++){
        ll o = one[j];
        ans = (ans + o*(n-o)%MOD*((1LL<<j)%MOD))%MOD;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(z) for(int i=1;i<=z;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define mod  1000000007
#define cl(n,m) (int)(ceil(double(n)/double(m)))
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

signed main(){
	int a,b,c ;
	cin>>a>>b>>c ;
	if(a>b) swap(a,b) ;
	if(a<=c && b>=c) cout<<"Yes\n" ;
	else cout<<"No\n" ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n+1);
  rep(snip_i, n+1) cin >> a.at(snip_i);
  ll ans = 0;
  rep(i, n){
    int b;
    cin >> b;
    if(a.at(i) <= b){
      ans += a.at(i);
      b -= a.at(i);
      if(b == 0) continue;
      if(a.at(i+1) <= b){
        ans += a.at(i+1);
        a.at(i+1) = 0;
      }else{
        ans += b;
        a.at(i+1) -= b;
      }
    }else{
      ans += b;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		double a=sc.nextDouble(),b=sc.nextDouble(),c=sc.nextDouble(),PI=Math.acos(-1),c1=c*PI/180,S,L,h;
		S=a*b*Math.sin(c1)/2;
		L=a+b+Math.sqrt(a*a+b*b-2*a*b*Math.cos(c1));
		h=b*Math.sin(c1);
		System.out.println(S);
		System.out.println(L);
		System.out.println(h);
	}
}



Measured memory_bytes: 27828
#include <iostream>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;

llint n;
llint a[100005], b[100005];
vector<llint> vec;

int main(void)
{
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) cin >> b[i];
	
	llint sum = 0, ans = 0, need = 0;
	for(int i = 0; i < n; i++){
		sum += a[i] - b[i];
		if(b[i] > a[i]){
			ans++;
			need += b[i] - a[i];
		}
		if(b[i] < a[i]){
			vec.push_back(a[i] - b[i]);
		}
	}
	if(sum < 0){
		cout << -1 << endl;
		return 0;
	}
	sort(vec.rbegin(), vec.rend());
	
	for(int i = 0; i < vec.size(); i++){
		if(need <= 0) break;
		ans++;
		need -= vec[i];
	}
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;

int main() {

    int n, k;
    int r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;

    vector<char> datas(n, ' ');

    unsigned long long sum = 0;
    for(int i=0; i<k; i++) {
        for(int j=i; j<n; j+=k) {
            if(t[j]=='r') {
                if(j-k>=0 && datas[j-k]=='p') {
                    if(j+k<n && t[j+k]=='r') {
                        datas[j] = 'r';
                    }
                    if(j+k<n && t[j+k]=='s') {
                        datas[j] = 's';
                    }
                    if(j+k<n && t[j+k]=='p') {
                        datas[j] = 'r';
                    }
                }
                else {
                    datas[j] = 'p';
                    sum += p;
                }
            }
            else if(t[j]=='s') {
                if(j-k>=0 && datas[j-k]=='r') {
                    if(j+k<n && t[j+k]=='r') {
                        datas[j] = 's';
                    }
                    if(j+k<n && t[j+k]=='s') {
                        datas[j] = 's';
                    }
                    if(j+k<n && t[j+k]=='p') {
                        datas[j] = 'p';
                    }
                }
                else {
                    datas[j] = 'r';
                    sum += r;
                }
            }
            else if(t[j]=='p') {
                if(j-k>=0 && datas[j-k]=='s') {
                    if(j+k<n && t[j+k]=='r') {
                        datas[j] = 'r';
                    }
                    if(j+k<n && t[j+k]=='p') {
                        datas[j] = 'p';
                    }
                    if(j+k<n && t[j+k]=='p') {
                        datas[j] = 'p';
                    }
                }
                else {
                    datas[j] = 's';
                    sum += s;
                }
            }
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    ll sum = 0;
    rep(i,n){
        if((i+1)%3==0||(i+1)%5==0)continue;
        else sum += (i+1);
    }
    cout << sum << endl;
}

Measured memory_bytes: 3624
from collections import deque

H, W = map(int, input().split())
B = deque()
check = [[H*W for _ in range(W)] for _ in range(H)]
for h in range(H):
    a = input()
    if a.count("#") > 0:
        b = [(h, w) for w, e in enumerate(a) if e == "#"]
        B += b
        for bx, bw in b:
            check[bx][bw] = 0

move = [(1, 0), (-1, 0), (0, 1), (0, -1)]

while B:
    x, y = B.pop()
    for dx, dy in move:
        nx, ny = x + dx, y + dy
        if -1 < nx < H and -1 < ny < W:
            if check[nx][ny] > check[x][y] + 1:
                check[nx][ny] = check[x][y] + 1
                B.appendleft((nx, ny))
print(max(max(c) for c in check))


Measured memory_bytes: 86876
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll


signed main(){
  int n;
  cin>>n;
  if(n==0){
    cout<<0<<en;
    RE;
  }
  string ret="";
  while(n!=0){
    if(n%(-2)!=0){
      ret+='1';
      n--;
    }else ret+='0';
    n/=-2;
  }
  reverse(ret.begin(), ret.end());
  cout<<ret<<en;
}






Measured memory_bytes: 256
def islikecoffee(s):
    return s[2] == s[3] and s[4] == s[5]

def test():
    ans = islikecoffee('coffee'), islikecoffee('abccdd'), islikecoffee('abccds')
    print(ans)

print('Yes' if islikecoffee(input()) else 'No')


Measured memory_bytes: 2940
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

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

  ll N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;

  for (int i = 0; i < N; i++) {
    ll mi = -D * i + (N - 1 - i) * C;
    ll ma = -C * i + (N - 1 - i) * D;
    if (mi <= B - A && B - A <= ma) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 384
// Author: 23forever
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second
typedef long long LL;
const int MAXN = 400;
const int P = 1e9 + 7;
using namespace std;

inline int read() {
  int x = 0; char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return x;
}

int n, c, a[MAXN + 5], b[MAXN + 5];

void init() {
  n = read(), c = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = 1; i <= n; ++i) b[i] = read();
}

namespace subtask1 {

int dp[MAXN + 5][MAXN + 5], x[MAXN + 5][MAXN + 5];

void solve() {
  for (int i = 1; i <= n; ++i) {
    x[i][0] = 1;
    for (int j = 1; j <= c; ++j) {
      x[i][j] = 1LL * x[i][j - 1] * a[i] % P;
    }
  }

  dp[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= c; ++j) {
      dp[i][j] = 1; 

      int sum = 0; 
      for (int k = 0; k <= j; ++k) {
        sum = (sum + 1LL * dp[i - 1][j - k] * x[i][k]) % P;
      }
      dp[i][j] = 1LL * dp[i][j] * sum % P;
    }
  }

  printf("%d\n", dp[n][c]);
}
}

namespace subtask2 {

int dp[MAXN + 5][MAXN + 5], x[MAXN + 5][MAXN + 5];

int qpow(int b, int m) {
  int ret = 1;
  while (m) {
    if (m & 1) ret = 1LL * ret * b % P;
    b = 1LL * b * b % P;
    m >>= 1;
  }
  return ret;
}

void solve() {
  for (int i = 1; i <= n; ++i) {
    int sum = 0;
    for (int j = 0; j <= c; ++j) {
      for (int k = a[i]; k <= b[i]; ++k) {
        x[i][j] = (x[i][j] + qpow(k, j)) % P;
      }
    }
  }

  //1 ^ 2 + 2 ^ 2 + 3 ^ 2

  dp[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= c; ++j) {
      dp[i][j] = 1; 

      int sum = 0; 
      for (int k = 0; k <= j; ++k) {
        sum = (sum + 1LL * dp[i - 1][j - k] * x[i][k]) % P;
      }
      dp[i][j] = 1LL * dp[i][j] * sum % P;
    }
  }

  printf("%d\n", dp[n][c]);
}
}

int main() {
#ifdef forever23
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
#endif
  init();

  subtask2::solve();

#ifdef forever23
  printf("Running Time = %d ms\n", int(clock() * 1000.0 / CLOCKS_PER_SEC));
#endif
  return 0;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <vector>
#include <algorithm>

int valid(const std::vector<int> &v) {
  return !std::count(v.begin(), v.end()-1, 0);
}

int main() {
  int N, W, H;
  scanf("%d %d %d", &N, &W, &H);

  std::vector<int> X(W+1), Y(H+1);
  for (int i=0; i<N; ++i) {
    int x, y, w;
    scanf("%d %d %d", &x, &y, &w);

    int xl=std::max(0, x-w), xr=std::min(W, x+w);
    int yd=std::max(0, y-w), yu=std::min(H, y+w);
    ++X[xl], --X[xr];
    ++Y[yd], --Y[yu];
  }

  for (int i=0; i<W; ++i)
    X[i+1] += X[i];

  for (int i=0; i<H; ++i)
    Y[i+1] += Y[i];

  if (valid(X) || valid(Y)) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
#define INF 123456789

int main(){
  int a, b, c;

  cin>>a>>b>>c;


  if(a==b && b== c)cout<<1<<endl;
  else if(a==b || b==c || c==a)cout<<2<<endl;
  else cout<<3<<endl;
  return 0;
}


Measured memory_bytes: 256
n,a,b = map(int,input().split())
s = str(input())
lists_s = list(enumerate(s))
ans = []
cnt = 0
b_rank = 0
for i,c in lists_s:
    if c == "a":
        if cnt >= (a+b):
            ans.append("No")
        elif cnt < (a+b):
            ans.append("Yes")
            cnt += 1
    elif c == "b":
        b_rank += 1
        if cnt < (a+b) and b_rank <= b:
            ans.append("Yes")
            cnt += 1
        else:
            ans.append("No")
    else:
        ans.append("No")
for i in ans:
    print(i)


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

using namespace std;

int n[25], a[25], b[25], c[25];

int main() {
    int n;
    scanf("%d", &n);

    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
    for (int i = 1; i <= n - 1; i++) scanf("%d", &c[i]);

    int res = 0;

    for (int i = 1; i <= n; i++) {
        res += b[a[i]];
        if (i > 1 && a[i - 1] + 1 == a[i]) res += c[a[i - 1]];
    }

    printf("%d\n", res);
}


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


int main(){
    string s;
    cin>>s;
    int n=s.size();
    reverse(all(s));

    vector<ll> v;
    v.push_back(0LL);
    ll p=1;
    ll pre=0;
    rep(i,n){
        ll x=s[i]-'0';
        x=(x*p)%2019;
        x=(x+pre)%2019;
        v.push_back(x%2019);
        p=(p*10)%2019;
        pre=x;
    }
    map<int,int> m;
    rep(i,n+1){
        m[v[i]]++;
    }

    ll ans=0;
    for(auto e : m){
        int num=e.second;
        if(num>1){
            ans+=(num*(num-1))/2;
        }
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 5348