akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

struct max_flow{
    struct Edge { int to,cap,rev; };
    int V; vector<vector<Edge>> G; vector<int> itr,level;
public:
    max_flow(int V):V(V){G.assign(V,vector<Edge>()); }
    void add_edge(int from,int to,int cap){
        G[from].push_back({to,cap,(int)G[to].size()});
        G[to].push_back({from,0,(int)G[from].size()-1});
    }
    void bfs(int s){
        level.assign(V,-1); queue<int> q;
        level[s]=0; q.push(s);
        while(!q.empty()){
            int v=q.front(); q.pop();
            for(auto& e:G[v]){
                if(e.cap>0&&level[e.to]<0) {
                    level[e.to]=level[v]+1;
                    q.push(e.to);
                }
            }
        }
    }
    ll dfs(int v,int t,int f){
        if(v==t)return f;
        for(int& i=itr[v];i<(int)G[v].size();i++){
            Edge& e=G[v][i];
            if(e.cap>0&&level[v]<level[e.to]){
                ll d=dfs(e.to,t,min(f,e.cap));
                if(d>0){
                    e.cap-=d,G[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        } return 0;
    }
    ll run(int s,int t){
        ll ret=0,f;
        while(bfs(s),level[t]>=0){
            itr.assign(V,0);
            while((f=dfs(s,t,inf))>0)ret+=f;
        } return ret;
    }
};

int main(){
    int n; scanf("%d",&n);
    vector<int> a(n);
    rep(i,0,n)scanf("%d",&a[i]);
    max_flow g(n+2); int s=n,t=n+1; ll sum=0;
    rep(i,0,n){
        if(a[i]>0){
            sum+=a[i]; g.add_edge(i,t,a[i]);
        }
        else g.add_edge(s,i,-a[i]);
        int idx=2*(i+1);
        while(idx<=n){
            g.add_edge(i,idx-1,inf); idx+=(i+1);
        }
    }
    printf("%lld\n",sum-g.run(s,t));
    return 0;
}

Measured memory_bytes: 256
def main():
    K, N = map(int, input().split())
    A = list(map(int, input().split()))

    shiftA = A[1:] + [K+A[0]]

    subA = [shiftA[i] - A[i] for i in range(N)]
    maxA = max(subA)
    subA.remove(maxA)

    print(sum(subA))

if __name__ == '__main__':
    main()

Measured memory_bytes: 26444
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;
import java.lang.Object;
 
public class Main {
    Scanner sc = new Scanner(System.in);
   
    public static void main(String[] args) {
        new Main(); 
    }
   
    public Main() {
        new A().doIt();
    }
    class A{
    	void doIt(){
    		long a[] = new long[3];
    		for(int i = 0;i < 3;i++)a[i] = sc.nextLong();
    		Arrays.sort(a);
    		long sum = a[0] * a[1];
    		long Red = a[2] / 2;
    		long Blue = a[2] - Red;
    		long ans = sum * (Blue - Red);
    		System.out.println(ans);
    	}
    }
}

Measured memory_bytes: 8916
from functools import reduce
from decimal import *
from operator import mul

def main():
    w, h, k = input_list()
    for x in range(w+1):
        for y in range(h+1):
            if x*(h-y) + y*(w-x) == k:
                print('Yes')
                exit()
    print('No')

def count_tento(l, cur):
    count = 0
    for v in l:
        if v > cur:
            count += 1
    return count

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

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if __name__ == '__main__':
    main()


Measured memory_bytes: 60524
<?php
//Request Question
function getq($get_word=null){
	if($get_word===null){
		return str_replace("\n","",fgets(STDIN));
	}else if($get_word===1){
		return explode(" ",str_replace("\n","",fgets(STDIN)));
	}
}

/*		START		*/
$S = getq();
$ans=true;
if($S[0]=="a"||$S[1]=="a"||$S[2]=="a"){
}else{
	$ans=false;
}
if($S[0]=="b"||$S[1]=="b"||$S[2]=="b"){
}else{
	$ans=false;
}
if($S[0]=="c"||$S[1]=="c"||$S[2]=="c"){
}else{
	$ans=false;
}
if($ans){
	echo "Yes\n";
}else{
	echo "No\n";
}
?>

Measured memory_bytes: 4728
n, m = map(int, input().split())
h = list(map(int, input().split()))
 
is_good_peak_arr = [True] * n
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    
    if h[a] >= h[b]: is_good_peak_arr[b] = False
    if h[b] >= h[a]: is_good_peak_arr[a] = False
 
print(is_good_peak_arr.count(True))

Measured memory_bytes: 20080
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long ll;
string s;

ll f(int n) {
	vector<string> v;
	string ss;
	for(int i = 0; i < s.size(); i++) {
		ss += s[i];
		if(n >> i & 1) {
			v.push_back(ss);
			ss = "";
		}
	}
	v.push_back(ss);
	ll sum = 0;
	for(int i = 0; i < v.size(); i++) {
		sum += atoll(v[i].c_str());
	}
	return sum;
}


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

	cin >> s;

	ll ans = 0;
	for(int i = 0; i < 1 << (int)s.size() - 1; i++) {
		ans += f(i);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef pair<long long,long long> Paint;
int main(){
  int n;cin>>n;
  vector<Paint> a;
  for(int i = 0; n > i; i++){
    int te,mp;cin>>te>>mp;
    a.push_back({te,mp});
  }
  long long ans = 0;
  long long nwget = 0;
  for(int i = n-1; 0<= i; i--){
    ans += (a[i].second - ((a[i].first+ans)%a[i].second))%a[i].second;
  }
  cout << ans << endl;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n, m, s;
  cin >> n >> m >> s;

  vector<vector<tuple<int,int,int>>> g(n);
  vii cst(n);
  rep(i,0,m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    --u; --v;
    g[u].eb(v,a,b);
    g[v].eb(u,a,b);
  }

  rep(i,0,n) {
    int c, d;
    cin >> c >> d;
    cst[i] = mp(c, d);
  }

  const ll inf = 1e18;

  vvl dist(n, vl(50001, inf));
  dist[0][min(s,50000)] = 0;
  priority_queue<tuple<ll, int, int>, vector<tuple<ll, int, int>>, greater<tuple<ll, int,int>>> q;
  q.emplace(0, 0, min(s, 50000));
  while (not q.empty()) {
    auto [d, u, sil] = q.top(); q.pop();
    if (dist[u][sil] > d) continue;

    if (dist[u][sil+cst[u].fst] > d+cst[u].snd) {
      dist[u][sil+cst[u].fst] = d+cst[u].snd;
      q.emplace(d+cst[u].snd, u, sil+cst[u].fst);
    }

    for (auto [v, a, b]: g[u]) {
      ll nd = d+b;  
      int nsilv = sil-a;
      if (nsilv >= 0 and dist[v][min(nsilv,50000)] > nd) {
        dist[v][min(nsilv,50000)] = nd;
        q.emplace(nd, (int)v, min(nsilv,50000));
      }
    }
  }

  rep(i,1,n) {
    cout << *min_element(all(dist[i])) << '\n';
  }

}

Measured memory_bytes: 39668
use proconio::{input, fastout};
use std::cmp::*;

#[fastout]
fn main() {
    input!{
        n: usize,
        k: usize,
        p: [usize;n],
    }

    let mut sum = 0;
    for i in 0..k {
        sum += p[i];
    }
    let mut max_sum = sum;
    for i in 1..n-k+1 {
        sum = sum + p[i+k-1]- p[i-1];
        max_sum = max(max_sum, sum);
    }
    let ans = ((max_sum+k) as f64) / 2.0;
    println!("{}", ans);
}


Measured memory_bytes: 4424
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

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

int main() {
    int n = read();
    int k = ceil(n * 1.0 / 1000);
    cout << k * 1000 - n << endl;
    return 0;
}

Measured memory_bytes: 3616
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""abc079_c"""

import sys
import pprint
import re

import copy
from itertools import tee

import itertools
pp = pprint.PrettyPrinter(indent=2)

def main():
    """Main function."""
    d = list(map(int, list(input())))

    sentinel = object()
    def solve(v, it, s):
        n = next(it, sentinel)
        if v == 7 and n == sentinel:
            print(s[1:]+'=7')
            sys.exit(0)
        if n == sentinel:
            return
        solve(v+n, copy.copy(it), s+'+'+n.__str__())
        solve(v-n, copy.copy(it), s+'-'+n.__str__())

    solve(0, iter(d), '')

if __name__ == '__main__':
    sys.exit(main())

Measured memory_bytes: 3828
#include <stdio.h>

 int main()
 {
 	int a, b;
 	scanf ("%d %d", &a, &b);
 	if (a > b)
	{
		printf ("a > b\n");	
	}
	else if (a < b)
	{
		printf ("a < b\n");
	}
	else 
	{
		printf ("a == b\n");
	}

 	return 0;
 } 


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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

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

int N, K;
vector<int> a;

bool isUnnecessary(int cur) {
    // dp[x][y] = x枚目まで使った時総和をyにできるか？
    vector<vector<bool> > dp(N+1, vector<bool>(K+1, false));
    dp[0][0] = 1;
    REP(i, N) REP(j, K+1) {
        if (i == cur) {
            dp[i+1][j] = dp[i][j];
        } else {
            if(dp[i][j]) {
                if (j + a[i] <= K) {
                    dp[i+1][j+a[i]] = 1;
                }
                dp[i+1][j] = 1;
            }
        }
    }
    bool ret = false;
    FOR(i, max(0, K-a[cur]), K) {
        ret |= dp[N][i];
    }
    
    return !ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin >> N >> K;
    a = vector<int>(N);
    REP(i, N) cin >> a[i];
    sort(a.begin(), a.end());
    
    
    // コーナーケース (良い集合なし)
    {
        ll sum = 0;
        for(auto x: a) {
            sum += x;
        }
        if (sum < K) {
            cout << N << endl;
            return 0;
        }
    }
    
    int lb = 0, ub = N;
    while(ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if (isUnnecessary(mid)) {
            lb = mid;
        } else {
            ub = mid;
        }
    }
    
    if (!isUnnecessary(lb)) {
        cout << 0 << endl;
    } else {
        cout << lb + 1 << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3668
#include <stdio.h>
#define MAX 100005
#define NIL -1

struct Node{
  int p,l,r;
};

struct Node T[MAX];
int n,D[MAX];

void print(int u){
  int i,c;
  printf("node %d: " ,u);
  printf("parent = %d, " ,T[u].p);
  printf("depth = %d, " ,D[u]);

  if(T[u].p == NIL) printf("root, ");
  else if (T[u].l == NIL) printf("leaf, ");
  else printf("internal node, ");

  printf("[");

  for(i=0,c=T[u].l ; c!=NIL ; i++,c=T[c].r){
    if(i) printf(", ");
    printf("%d" ,c);
  }
  printf("]\n");
}

int rec(int u ,int p){
  D[u]=p;
  if(T[u].r != NIL) rec(T[u].r,p);
  if(T[u].l != NIL) rec(T[u].l,p+1);
}

int main(){
  int i,j,d,v,c,l,r;
  scanf("%d" ,&n);
  for(i=0 ; i<n ;i++) T[i].p = T[i].l = T[i].r = NIL;

  for(i=0 ; i<n ; i++){
    scanf("%d %d" ,&v,&d);
    for(j=0 ; j<d ; j++){
      scanf("%d" ,&c);
      if(j==0) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for(i=0 ; i<n ; i++){
    if(T[i].p == NIL) r=i;
  }

  rec(r,0);

  for(i=0 ; i<n ; i++) print(i);

  return 0;
}



Measured memory_bytes: 6380
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<setprecision(10);
    int r;
    cin>>r;
    cout<<r*r<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
  void solve()
{
 string S,T;
     cin>>S>>T;
    T.pop_back();
  if(S==T)
  
    cout<<"Yes"<<endl;
  
    else
        cout<<"No"<<endl;
  
}
int main()
{
   solve();
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[1001],s=0,m=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    for(int i=0;i<n;i+=2)
    {
        s=s+a[i];
    }
    for(int i=1;i<n;i+=2)
    {
        m=m+a[i];
    }
    cout<<s-m<<endl;
}


Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main(){
  int a,b;
  char op;
  while(cin >>a>>op>>b && op!='?'){
    switch(op){
    case '+':
      cout<<a+b<<endl;
      break;
    case '-':
      cout<<a-b<<endl;
      break;
    case '*':
      cout<<a*b<<endl;
      break;
    case '/':
      cout<<a/b<<endl;
      break;}
    }
    return 0;
  }
  

Measured memory_bytes: 1160
listi = list(input())
a=listi[0]
b=listi[1]
c=listi[2]
d=listi[3]

 

res = ""


def hugou(i):
    if i=="0":
        return "+"
    else:
        return "-"
    

for x in range(2 ** 3):

    z = str(format(x, '03b')) #2進数に変換
    ans = 0
    ans += int(a)
    if z[0]=="0":
        ans += int(b)
    else:
        ans += int(b) * -1
    if z[1]=="0":
        ans += int(c)
    else:
        ans += int(c) * -1   
    if z[2]=="0":
        ans += int(d)
    else:
        ans += int(d) * -1        
        
    
    
    if ans == 7:
        res += a
        res += hugou(z[0])
        res += b
        res += hugou(z[1]) 
        res += c
        res += hugou(z[2])
        res += d 
        
        res += "=7"
        print(res)
        break

Measured memory_bytes: 38256
import sys

H, W = map(int, sys.stdin.readline().strip().split())

if H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    ans = min(H, W)
    for i in range(1, H):
        sq = [i * W, (H-i) * (W//2), (H-i) * (W - W//2)]
        ans = min(ans, max(sq) - min(sq))
    H, W = W, H
    for i in range(1, H):
        sq = [i * W, (H-i) * (W//2), (H-i) * (W - W//2)]
        ans = min(ans, max(sq) - min(sq))
    print(ans)

Measured memory_bytes: 41692
#include <cstdio>

int main(){
    char num[1000];
    int sum,i,n;
    for(;;){
        scanf("%s",num);
        i= 0;
        sum = 0;
        while(num[i] != 0){
            sum = sum + (num[i] - '0');
            i++;
            }
        if(sum == 0){
            break;
        }
        printf("%d\n", sum);
    }
        return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n,a,b;
  cin>>n>>a>>b;
  string s;
  cin>>s;
  
  ll cnt=0;
  ll cnt_b=0;
  REP(i,n){
    if(s[i]=='a' && cnt<a+b){
      cout<<"Yes"<<endl;
      cnt++;
    }
    else if(s[i]=='b' && cnt<a+b && cnt_b<b){
      cout<<"Yes"<<endl;
      cnt++;
      cnt_b++;
    }
    else
      cout<<"No"<<endl;
  }
  
      
}

Measured memory_bytes: 848
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    string s;
    io.read(s);
    cout << s.front() << s.size() - 2 << s.back();
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

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

    let mut ret = 0;
    for i in 0..(n - 2) {
        if s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C' {
            ret += 1;
        }
    }
    println!("{}", ret);
}


Measured memory_bytes: 2160
from sys import stdin
#, setrecursionlimit, stdout
#setrecursionlimit(1000000)
#from collections import deque
from math import sqrt, floor
#, ceil, log, log2, log10, pi, gcd, sin, cos, asin
#from heapq import heapify, heappop, heappush, heappushpop, heapreplace
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def si(): return stdin.readline().rstrip()
def lsi(): return list(si())
#mod=1000000007
res=['NET', 'DA']
############# CODE STARTS HERE #############


def sieve(x):
    a=[2]*(x+1)
    a[1]=1
    sq=floor(sqrt(x))
    for i in range(2, sq+1):
        if a[i]:
            for j in range(i*i, x+1, i):
                a[j]+=2
            a[i*i]-=1
    return a


test_case=1
while test_case:
    test_case-=1


    n=ii()
    a=sieve(n)
    c=0
    #print(a)
    for i in range(1, n+1):
        c+=i*a[i]
    print(c)

Measured memory_bytes: 143976
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(n):
  if i+2==n:
    break
  elif p[i]<p[i+1]<p[i+2] or p[i]>p[i+1]>p[i+2]:
      ans+=1
print(ans)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int b[100005];
int main(void)
{
    int n,k,q,a;
    cin >> n >> k >> q;
    for(int i=1;i<=q;i++)
    {
        cin >> a;
        b[a]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(k-q+b[i]<=0)
            cout << "No";
        else cout << "Yes";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint = long;
using ll = long long;
#define rep(i,n) for(lint (i) = 0;(i) < (lint)(n);(i)++)
#define repInRange(i,start,end) for(lint (i) = (start);(i) < (end);++(i))
#define pb push_back
using Vecint = vector<lint>;

void Main() {
	lint H,A;
	cin >> H >> A;
	cout << (H%A ? H/A + 1: H/A) << '\n';
}

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

Measured memory_bytes: 256
n,x,y= map(int, input().split())

ans=[0]*(n-1)

for i in range(1,n):
    for j in range(i+1,n+1):
        ans[min(j-i,1+abs(i-x)+abs(j-y))-1]+=1

for i in range(n-1):
    print(ans[i])

Measured memory_bytes: 46044
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

r=a[0]
sum=0
for i in range(n):
  if r + a[i+1] > b[i]:
    sum += b[i]
    r = a[i+1] - max(b[i]-r,0)
  else:
    sum += r + a[i+1]
    r = 0
print(sum)

Measured memory_bytes: 19116
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,k,x,y;
  cin >> n >> k >> x >> y;
  if (n <= k) {
    cout << x*n << endl;
  } else {
    int z = k*x;
    z += (n-k)*y;
    cout << z << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int ans = 1000;
    for (int a = 1; a < N; a++) {
      int A = a;
      int B = N-a;
      int tmp = 0;
      while (A > 0) {
        tmp += A%10;
        A /= 10;
      }
      while (B > 0) {
        tmp += B%10;
        B /= 10;
      }
      ans = Math.min(ans, tmp);
    }
    System.out.println(ans);
  }
}



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

const int MX = 1e5 + 5;

int main() {
	int A, B;
	cin >> A >> B;
	if(A >= 1 && A <= 9 && B >= 1 && B <= 9) 
		cout << (A * B) << endl;
	else 
		cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int modpow(int x,int k){
	// x ^ k mod inf
	int res = 1;
	while(k>0){
		if(k%2)res = (res*x)%inf;
		x = (x*x)%inf;
		k >>=1;
	}
	return res;
}
vector< pair<int,int> > divs[114514];
signed main(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){ cin>>a[i]; }
	map<int,int> mope;
	for(int i=0;i<n;i++){
		int cur = a[i];
		for(int j=2;j*j<=cur;j++){
			int cnt = 0;
			while( cur % j == 0 ){
				cnt ++ ;
				cur /= j;
			}
			if( cnt > 0 ){
				mope[j] = max( mope[j], cnt );
				divs[i].pb( mp( j, cnt ) );
			}
		}
		if( cur > 1 ){
			mope[cur] = max( mope[cur], 1LL );
			divs[i].pb( mp( cur, 1LL ) );
		}
	}
	int prod = 1;
	for( auto it = mope.begin(); it != mope.end(); ++it ){
		pair<int,int> pa = *it;
		prod *= modpow( pa.first, pa.second );
		prod %= inf;
	}
	int ans = 0;
	for(int i=0;i<n;i++){
		int cur = prod;
		for(int j=0;j<divs[i].size();j++){
			int num = divs[i][j].first;
			int shisu = divs[i][j].second;
			int inv = modpow( num, inf-2 );
			cur *= modpow( inv, shisu );
			cur %= inf;
		}
		ans += cur;
		ans %= inf;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define mp(a, b) make_pair((a),(b))
#define bs(n) ((ull)1<<((ull)n))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr double pi = asin(1) * 2;
constexpr ll mod = 1000000007;
constexpr double eps = 0.000000001;

int main() {
    int v, e, c[100][100] = {{0}}, r = 0;
    cin >> v >> e;
    rep(i, e) {
        int u, v;
        cin >> u >> v;
        cin >> c[u][v];
    }
    while (true) {
        queue<int> bfs;
        int frm[100];
        for (auto &e:frm)e = -1;
        frm[0] = 0;
        bfs.push(0);
        while (!bfs.empty()) {
            int g = bfs.front();
            bfs.pop();
            rep(i, v) {
                if (c[g][i] > 0 && frm[i] == -1) {
                    frm[i] = g;
                    bfs.push(i);
                }
            }
        }
        if (frm[v - 1] == -1) break;
        int sz = INT32_MAX / 2, cur = v - 1;
        while (cur != 0) {
            int s = frm[cur], t = cur;
            sz = min(sz, c[s][t]);
            cur = s;
        }
        r += sz;
        cur = v - 1;
        while (cur != 0) {
            int s = frm[cur], t = cur;
            c[s][t] -= sz;
            c[t][s] += sz;
            cur = s;
        }
    }
    cout << r << endl;
}




Measured memory_bytes: 3140
bounds = [sum([26 ** i for i in range(n)]) for n in range(1, 12)]
lis = 'abcdefghijklmnopqrstuvwxyz'
N = int(input())
for b in reversed(bounds):
    if b <= N:
        break
N -= b 
length = bounds.index(b) + 1
s = ''
for i in range(length - 1, 0, -1):
    idx, N = divmod(N, 26**i)
    s = s + lis[idx]
print(s + lis[N])

Measured memory_bytes: 9208
#include<bits/stdc++.h>
#define m 1000000007
using namespace std;
void add_mod(int& a,int b){
    a+=b;
    if(a>m)
        a-=m;
}
int main(){
    int n;
    scanf("%d",&n);
    vector<vector<int>> a(n,vector<int>(n));
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            scanf("%d",&a[i][j]);
    vector<int> dp(1<<n);
    dp[0] = 1;
    for(int mask = 0;mask<(1<<n)-1;mask++){
        int i = __builtin_popcount(mask);
        for(int j=0;j<n;j++){
            if(a[i][j]&&!(mask&(1<<j))){
                int temp = mask^(1<<j);
                add_mod(dp[temp],dp[mask]);
            }
        }
    }
    printf("%d\n",dp[(1<<n)-1]);
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n, m; cin >> n >> m;
  vector<vector<int>> g(n, vector<int>(n, 0));
  rep(i, m) {
    int a, b; cin >> a >> b;
    --a; --b;
    g[a][b] = g[b][a] = 1;
  }
  vector<int> v(n);
  rep(i, n) v[i] = i;
  int ans = 0;
  do {
    if(v[0] != 0) continue;
    bool ok = true;
    rep(i, n-1) {
      if(g[v[i]][v[i+1]] == 0) {
        ok = false;
        break;
      }
    }
    if(ok) ++ans;
  } while(next_permutation(ALL(v)));
  cout << ans << endl;
}

Measured memory_bytes: 256
def resolve():
    H, W = list(map(int, input().split()))
    S = [list(input()) for _ in range(H)]
    import collections
    maxdist = 0

    for startx in range(H):
        for starty in range(W):
            if S[startx][starty] == "#":
                continue
            visited = [[-1 for _ in range(W)] for __ in range(H)]
            visited[startx][starty] = 0
            q = collections.deque([(startx, starty)])
            while q:
                x, y = q.pop()
                for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
                    nx = x + dx
                    ny = y + dy
                    if 0 <= nx < H and 0 <= ny < W and S[nx][ny] != "#" and visited[nx][ny] == -1:
                        visited[nx][ny] = visited[x][y] + 1
                        q.appendleft((nx, ny))
            maxdist = max(maxdist,max(sum(visited, [])))
    print(maxdist)
    

if '__main__' == __name__:
    resolve()


Measured memory_bytes: 74804
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
6
5
3
1
3
4
3

output:
3
"""

import sys


def solve():
    # write your code here
    max_profit = -1 * float('inf')
    min_stock = prices[0]
    for price in prices[1:]:
        max_profit = max(max_profit, price - min_stock)
        min_stock = min(min_stock, price)
    return max_profit


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    p_num = int(_input[0])
    prices = list(map(int, _input[1:]))
    print(solve())

Measured memory_bytes: 31476
using System;
using System.Collections.Generic;
using System.Text;

namespace ALDS1_9_C {
    class PriorityQueue {
        List<int> _heap;
        int _size;

        public PriorityQueue() {
            _heap = new List<int>();
            _heap.Add(int.MinValue);
        }

        public void Enqueue(int num) {
            _size++;
            _heap.Add(int.MinValue);
            IncreaseKey(_size, num);
        }

        public int Dequeue() {
            if (_size < 1)
                return int.MinValue;
            int ret = _heap[1];
            _heap[1] = _heap[_size];
            _heap.RemoveAt(_size);
            _size--;
            MaxHeapify(1);
            return ret;
        }

        public int Peek() {
            return _heap[1];
        }

        public int Count {
            get {
                return _size;
            }
        }

        private void MaxHeapify(int i) {
            int l = i * 2;
            int r = i * 2 + 1;
            int largest = (l <= _size && _heap[l] > _heap[i]) ? l : i;
            if (r <= _size && _heap[r] > _heap[largest])
                largest = r;

            if (largest != i) {
                Swap(i, largest);
                MaxHeapify(largest);
            }
        }

        private void IncreaseKey(int i, int key) {
            if (key < _heap[i])
                return;
            _heap[i] = key;
            while (i > 1) {
                int j = i / 2;
                if (_heap[j] < _heap[i])
                    Swap(i, j);
                i = j;
            }
        }

        private void Swap(int a, int b) {
            int temp = _heap[a];
            _heap[a] = _heap[b];
            _heap[b] = temp;
        }
    }

    class Program {
        static void Main(string[] args) {
            PriorityQueue pq = new PriorityQueue();
            StringBuilder sb = new StringBuilder();
            bool inputEnd = false;
            while (!inputEnd) {
                string[] input = Console.ReadLine().Split(' ');
                switch (input[0]) {
                    case "insert":
                        pq.Enqueue(int.Parse(input[1]));
                        break;
                    case "extract":
                        sb.AppendLine(pq.Dequeue().ToString());
                        break;
                    case "end":
                        inputEnd = true;
                        break;
                }
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 31324
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <utility>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <climits>
#include <map>
#include <unordered_map>
#include <string>
#include <ctime>
#include <unistd.h>

using namespace std;
#define ll long long
#define max(A, B) ((A) > (B) ? (A) : (B))
#define min(A, B) ((A) < (B) ? (A) : (B))
#define mp make_pair
#define pb push_back
#define fi first
#define sd second
#define fu(A, B, C) for(ll (A) = (B); (A) < (C); (A)++)
#define fu0(A, B) fu((A), 0, (B))
#define fd(A, B, C) for(ll (A) = (B); (A) >= (C); (A)--)
#define mem(A, B) memset((A), (B), sizeof((A)))
#define vd(A, B, C) vector<ll> (A)((B), (C))
#define v2d(A, B, C) vector<vector<int>> (A)((B), vector<int> (C));
#define all(x) (x.begin(), x.end())
#define endl "\n"
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;

ll gcd(int a, int b){if(!a)return b;return gcd(b%a,a);}

void perform() {
  int n; cin >> n;
  n %= 10;
  string ans = "";
  switch(n) {
    case 3: ans = "bon";break;
    case 0:case 1:case 6:case 8: ans = "pon";break;
    default:ans = "hon";break;
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  ll t = 1; //cin >> t;
  while(t--) {perform();}
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define chmax(x,y) x = max(x, y)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using G = vector<vector<int>>;
const int MOD = 1000000007;
const int INF = 1001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    int n;
    cin >> n;
    mint a, b, c;
    a = 1;
    b = 1;
    c = 1;
    rep(i, n) a *= 10;
    rep(i, n) b *= 9;
    rep(i, n) c *= 8;
    mint ans = 0;
    ans = a - (mint) 2 * b + c;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define mod2 1000000006
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
#define pi 3.141592653589793
 
using namespace std ;
 
typedef tree<pair<pll,lli>,null_type,less<pair<pll,lli>>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

lli fac[100005];

#define N 100005
lli power(lli x, lli y, lli p) 
{ 
    lli res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
lli modInverse(lli n, lli p) 
{ 
    return power(n, p-2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
lli ncr(lli n, lli r, lli p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r  
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 

int main() 
{
/////////////////////////////////////
    
    fastio;
 
/////////////////////////////////////  
   	 
    fac[0] = 1; 
    for (lli i=1 ; i<=100000; i++) 
        fac[i] = (fac[i-1]*i)%mod;
    lli n,k;
    cin>>n>>k;

    lli a[n+1];
    loopl(i,1,n+1) cin>>a[i];

    sort(a+1,a+n+1);

    if(k == 1)
    {
    	cout<<0;
    	return 0;
    }

    lli ans1 =0 ,ans2=0;
    loopl(i,k,n+1)
    {
    	ans1 += ncr(i-1,k-1,mod)*a[i];
    	ans1 %= mod;
    }

    for(lli i=n-k+1;i>=1;i--)
    {
    	ans2 += ncr(n-i,k-1,mod)*a[i];
    	ans2 %=mod;
    }

    ans1 = (ans1-ans2+mod)%mod;

    cout<<ans1<<endl;

	
}

        
 


Measured memory_bytes: 1792
/*
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
ordered_set -> less -> less_equal
ordered_set find_by_order() -> возвращает k-ый элемент(отсчёт с нуля)
ordered_set order_of_key() -> возвращает количество элементов в множестве,строго меньших,чем наш элемент
*/
#include <bits/stdc++.h>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;
using namespace __gnu_pbds;

template<typename T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());


typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int> > matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=2e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=(1ll<<61)-1;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};


int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    cout<<(n/500)*1000+((n%500)/5)*5;
	exit(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using node = pair<string,ll>;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9+7;
#define maxPrime 10000000

int prime[maxPrime];

int main(void) {
  ll n,p;
  cin >> n >> p;
  if(n == 1) {
    cout << p << endl;
    return 0;
  }
  vector< ll > primes;
  fill(prime, prime + maxPrime, 1);
  for(ll i = 2;i < maxPrime;++i){
    if(prime[i]){
      primes.push_back(i);
      for(ll j = i*2;j < maxPrime;j += i){
        prime[j] = 0;
      }
    }
  }
  ll res = 1;
  for(ll i : primes) {
    ll cnt = 0;
    ll d = (ll)pow(i,n);
    while(p % d == 0) {
      p /= d;
      res *= i;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 49644
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
void ban() {
    cout << "Impossible" << endl;
    exit(0);
}
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
    vector <int> a(n);
    map <int, int> cnt;
    int diam = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        diam = max(diam, a[i]);
        ++cnt[a[i]];
    }
    int mn = 1e18;
    for (int e : a) 
        mn = min(mn, e);

    if (diam % 2 == 0) {
        if (mn != diam/2)
            ban();
        if (cnt[mn] != 1)
            ban();
    }
    else {
        if (mn != (diam+1)/2)
            ban();
        if (cnt[mn] != 2)
            ban();
    }   
    
    for (int i = mn + 1; i <= diam; ++i) {
        if (cnt[i] < 2) 
            ban();
    }   
    cout << "Possible" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n + 1];
        for (int i = 0; i < n; i++) {
            a[i + 1] = in.nextInt();
        }
        int[] c1 = new int[n + 1], c2 = new int[n+1];
        int sum = 0;
        for (int i = 0; i < n-1; i++) {
            c1[i] = Math.abs(a[i] - a[i + 1]);
            c2[i] = Math.abs(a[i] - a[i + 2]);
//            System.out.println(c2[i]);
            sum += c1[i];
        }
        c1[n-1] = Math.abs(a[n-1] - a[n]);
        c1[n] = Math.abs(a[n]);
        c2[n-1] = Math.abs(a[n-1]);
        sum += c1[n - 1];sum += c1[n];
//        System.out.println("sum = " + sum);
        for (int i = 0; i < n; i++) {
            System.out.println(sum - c1[i] - c1[i + 1] + c2[i]);
        }
    }
}


Measured memory_bytes: 61768
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define BITBOOL(x,a) (((x)>>(a))&1)
constexpr int INF = (1 << 29);
constexpr ll INF_ = (1LL << 58);
constexpr ld EPS = (1e-10);
constexpr ld PI_ = 3.141592653589793238;//46264338327950288
constexpr ld E_ = 2.71828182845904523;//5360287471352
int main(){
  int N; string S;
  cin >> N >> S;
  int cnt = 0;
  FOR(i,0,N-2){
    if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C') cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    char s[4];

    scanf("%s", s);

    if((s[0] == s[1] && s[0] == s[2]) || (s[1] == s[2] && s[1] == s[3]))
        printf("Yes\n");
    else
        printf("No\n");
    
    return 0;
}

Measured memory_bytes: 128
S = input()
s = [int(c) for c in S]
def to_s(a):
  if a>=0:
    return "+"+str(a)
  return str(a)

for b in [-s[1],s[1]]:
  for c in [-s[2],s[2]]:
    for d in [-s[3],s[3]]:
      if s[0]+b+c+d == 7:
        print(S[0]+to_s(b)+to_s(c)+to_s(d)+"=7")
        exit()

Measured memory_bytes: 3064
s = gets.chomp.to_s
n = s.length
t = (n - 1) / 2
d = (n + 3) / 2

kai = s.slice(0, t)
kai2 = s.slice(d - 1, n - 1)
if kai == kai2
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 3836
X, N = ARGF.gets.chomp.split.collect {|el| el.to_i}
P = ARGF.gets.chomp.split.collect {|el| el.to_i}

dd = 0
xc = X + dd

102.times do |dd|
  xc = X - dd
  unless P.include?(xc)
    break
  end
  xc = X + dd
  unless P.include?(xc)
    break
  end
end

puts xc


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

using namespace std;

typedef long long int ll;

const ll inf = 1e18;

struct edge {
  int u, v, wt;
};

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

  int n, m, p;
  cin >> n >> m >> p;
  vector < edge > edges(m);
  for (int i = 0; i < m; i++) {
    cin >> edges[i].u >> edges[i].v >> edges[i].wt;
    edges[i].wt = p - edges[i].wt;
  }

  vector < ll > d(n + 1, LLONG_MAX);
  d[1] = 0;
  for (int i = 0; i < 2 * n; i++) {
    for (edge e : edges) {
      int u = e.u, v = e.v, wt = e.wt;
      if (d[u] != LLONG_MAX && d[v] > d[u] + (ll)wt) {
        d[v] = max(-inf, d[u] + wt);
        if (i > n - 1) d[v] = -inf;
      }
    }
  }

  if (d[n] == -inf) {
    // graph has -ve cycles from 1.
    cout << -1 << '\n';
  } else {
    cout << max( -d[n], (ll)0) << '\n';
  }
}


Measured memory_bytes: 384