akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int N;
const int MAXV = 1000005;
int A[1005][1005];
int ID[1005][1005];
vector<int> to[MAXV];

int toId(int i, int j)
{
  if (i > j)
  {
    swap(i, j);
  }
  return ID[i][j];
}

vector<int> dp(MAXV, -1);
vector<bool> visited(MAXV, 0);
int dfs(int u)
{
  if (visited[u])
  {
    return dp[u]; // 訪問済だが、dpが未決定の場合は閉路が存在
  }
  visited[u] = 1;
  int ret = 1;
  for (auto v : to[u])
  {
    int res = dfs(v);
    if (res == -1)
      return -1;
    ret = max(ret, res + 1);
  }
  return dp[u] = ret;
}

int main()
{
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N - 1; j++)
    {
      cin >> A[i][j];
      A[i][j]--;
    }
  }
  int V = 0;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      if (i < j)
      {
        ID[i][j] = V++; // 各試合にノードのIDを割り当てる
      }
    }
  }
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N - 1; j++)
    {
      A[i][j] = toId(i, A[i][j]); // i: 自分, j: 対戦相手, でIDに変換
    }
    for (int j = 1; j < N - 1; j++)
    {
      to[A[i][j]].push_back(A[i][j - 1]); // 入力のノード
    }
  }
  int ans = 0;
  for (int i = 0; i < V; i++)
  {
    int res = dfs(i);
    if (res == -1)
    {
      cout << -1 << endl;
      return 0;
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
}

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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

int main() {
    int X;
    cin >> X;

    int cur = 0;
    if (X <= 599) {
        ;
    }
    else if (X <= 799) cur =1;
    else if (X <= 999) cur = 2;
    else if (X <= 1199) cur = 3;
    else if (X <= 1399) cur = 4;
    else if (X <= 1599) cur = 5;
    else if (X <= 1799) cur = 6;
    else cur = 7;

    int ans[] = {8,7,6,5,4,3,2,1};
    cout << ans[cur] << endl;
}


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



int main(){
  int N;
  cin >> N;
  vector<int> vec(N, 0);

  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());

  int ans = 0;

  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
      for(int k = j+1; k < N; k++){
        if(vec[k] >  vec[j] - vec[i] && vec[k] < vec[j] +  vec[i]){
          ans += 1;
        } else {
          break;
        }
      }
    }
  }

  cout << ans << endl;
}




Measured memory_bytes: 256
#エラトネスの篩
def Eratosthene(n):
    prime = [1]*(n+1)
    prime[0] = 0
    prime[1] = 0

    for i in range(2, int(n**0.5)+1, 1):
        if prime[i]==0:
            continue
        for j in range(i+1, n+1, 1):
            if prime[j]==0:
                continue
            if j%i==0:
                prime[j] = 0
    return prime

Q = int(input())
Query = []
for _ in range(Q):
    l,r = map(int, input().split())
    Query.append([l, r])

prime = Eratosthene(10**5)
A     = [0]*len(prime)
for i in range(len(prime)):
    if prime[i]==1 and (i+1)%2==0 and prime[(i+1)//2]==1:
        A[i] = 1
S     = [0]*(len(prime)+1)

for i in range(len(prime)):
    S[i+1] = S[i] + A[i]

for l,r in Query:
    print(S[r+1]-S[l])

Measured memory_bytes: 26908
#include<bits/stdc++.h>
#define MX 1000000
using namespace std ;

int W[10004], cost[10004], dp[104][1004], ans[1000] ;

int NS(int i, int w, int cap, int n){
    int p1, p2 ;
    if(i > n) return 0 ;
    if(dp[i][w] != -1) return dp[i][w] ;
    if(w + W[i] <= cap){
        p1 = cost[i] + NS(i+1, w + W[i], cap, n) ;
    }
    else{
        p1 = 0 ;
    }
    p2 = NS(i+1, w, cap, n) ;
    dp[i][w] = max(p1, p2) ;
    if(w+W[i] <= cap) ans[w+W[i]] = dp[i][w] ;
    return dp[i][w] ;
}
void solve(){
    string s ;
    cin>>s ;
    for(int i = 1; i < s.size(); i++){
        if(s[i-1] == 'A' && s[i] == 'C'){
            cout<<"Yes"<<'\n' ;
            return ;
        }
    }
    cout<<"No"<<'\n' ;
}
int main(){
    solve() ;
    return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

bool dp[82][82][20000];
int a[82][82];
int b[82][82];

int main(){
    int h, w;
    cin >> h >> w;
    rep(i, h) rep(j, w) {
        cin >> a[i][j];
    }
    rep(i, h) rep(j, w) {
        cin >> b[i][j];
    }
    
    int ini = abs(a[0][0]-b[0][0]);
    dp[0][0][ini] = true;
    
    rep(i, h) rep(j, w) {
        if (i==0 && j==0) continue;
        int v = abs(a[i][j] - b[i][j]);
        rep(k, 13000) {
            if (i>0) {
                dp[i][j][k] |= dp[i-1][j][k+v];
                if (k-v>=0) {
                    dp[i][j][k] |= dp[i-1][j][k-v];
                }
                else {
                    dp[i][j][k] |= dp[i-1][j][v-k];
                }
            }
            if (j>0) {
                dp[i][j][k] |= dp[i][j-1][k+v];
                if (k-v>=0) {
                    dp[i][j][k] |= dp[i][j-1][k-v];
                }
                else {
                    dp[i][j][k] |= dp[i][j-1][v-k];
                }
            }
        }
    }
    
    int ans = 0;
    while (!dp[h-1][w-1][ans]) {
        ans++;
    }
    
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 128896
#include <stdio.h>
const int N = 10000;
int main ()
{	
   
	int a[N] = {0}, n, maxn = -1000000, minn = 1000000;
	long long sum = 0;
	
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		if(a[i] > maxn)
		{
			maxn = a[i];
		}
		if(a[i] < minn)
		{
			minn = a[i];
		}
		sum += a[i];
	}
	printf("%d %d %lld\n", minn, maxn, sum);
	return 0;	
}


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

int main()
{
    int S,h,m,s;
	scanf("%d",&S);
	h=S/3600;
	m=(S-h*3600)/60;
	s=(S-h*3600-m*60);
	printf("%d:%d:%d\n",h,m,s);
    return 0;
}


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

int main() {
  string X, Y;
  int x, y;
  cin >> X >> Y;
  if(X == "A") {
    x = 10;
  }
  if(X == "B") {
    x = 11;
  }
  if(X == "C") {
    x = 12;
  }
  else if(X == "D") {
    x = 13;
  }
  else if(X == "E") {
    x = 14;
  }
  else if(X == "F") {
    x = 15;
  }
  if(Y == "A") {
    y = 10;
  }
  if(Y == "B") {
    y = 11;
  }
  if(Y == "C") {
    y = 12;
  }
  if(Y == "D") {
    y = 13;
  }
  if(Y == "E") {
    y = 14;
  }
  if(Y == "F") {
    y = 15;
  }
  if(x < y) {
    cout << "<" << endl;
  }
  if(x == y) {
    cout << "=" << endl;
  }
  if(x > y) {
    cout << ">" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;
//西暦⇒時代の歴
ll a[100010];
int main()
{
    ll N, K;
    cin >> N >> K;

    ll ans = 0;
    for (ll b = 1; b <= N; ++b)
    {
        for (ll q = 0; K + b * q <= N; ++q)
        {
            ll lb = max(1LL, K + b * q);
            ll ub = min(N, b * (q + 1) - 1);
            if (lb <= ub)
                ans += ub - lb + 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)

puts a.join(" ")

i = 1

while (i < a.count) do
  v = a[i]
  j = i - 1
  while (j >= 0 && a[j] > v) do
    a[j + 1] = a[j]
    j = j - 1
  end
  a[j + 1] = v
  i = i + 1

  puts a.join(" ")
end



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

using namespace std;

const int INF=1e9+5;

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

    vector<int>dp(n,INF);
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
         for(int j=i+1;j<=i+k;j++)
         {
             if(j<n)
                 dp[j]=min(dp[j],dp[i]+(abs(h[i]-h[j])));

         }
    }

    cout<<dp[n-1]<<"\n";
    return 0;
}


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

using namespace std;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()

const int MX = (int)1e5 + 10;
const int mod = (int)1e9 + 7;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

int main(){

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

    int n;
    cin >> n;

    vector<pair<int, int>> A(n), B(n);
    int id = 0;
    for(auto &p : A){
        cin >> p.X;
        p.Y = id++;
    }
    id = 0;
    for(auto &p : B){
        cin >> p.X;
        p.Y = id++;
    }

    sort(all(A));
    sort(all(B));

    for(int i = 0; i < n; ++i)
        if(A[i].X > B[i].X) return puts("No"), 0;

    for(int i = 0; i < n - 1; ++i)
        if(A[i + 1].X <= B[i].X) return puts("Yes"), 0; // can sort every element of the remaining n - 2 elements with at most n - 2 swaps

    vector<int> perm(n);
    for(int i = 0; i < n; ++i)
        perm[B[i].Y] = A[i].Y; // what order should B be if sorted ascending-ly

    int idx = 0;
    int cycle_length = 0;

    do{
        idx = perm[idx]; // loop through permutation cycle
        cycle_length++;
    }while(idx != 0);

    //if cycle contains all n elements, it requires n - 1 swaps at minimum
    return puts(cycle_length == n ? "No": "Yes"), 0;
}

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

// long long floor(float x){
//     return (long long)x;
// }
int main(){

    ll n; cin >> n;

    if( n < 2  || n % 2 == 1){
        cout << 0 << endl;
        return 0;
    }

    ll res = 0;
    while(n > 0){
        res += n / 10;
        n /= 5;
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#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 fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, M, S;
vector<pair<int,int>> E[50];
int A[101], B[101], C[50], D[50];
ll dist[50][3010];
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
bool vis[50][3010];
ll ans[50];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M >> S;
    chmin(S, 3000);
	rep(i, 0, M) {
		int u, v; cin >> u >> v; u--; v--;
		cin >> A[i] >> B[i];
		E[u].push_back({ v, i });
		E[v].push_back({ u, i });
	}
	rep(i, 0, N) cin >> C[i] >> D[i];

    rep(i, 0, N) rep(s, 0, 3001) dist[i][s] = infl;
    rep(i, 0, N) rep(s, 0, 3001) vis[i][s] = false;
    rep(i, 0, N) ans[i] = infl;

    min_priority_queue<pair<ll, int>> que;

    dist[0][S] = 0;
    que.push({ 0, 0 * 5010 + S });

    while (!que.empty()) {
        auto q = que.top(); que.pop();

        ll cst = q.first;
        int cu = q.second / 5010;
        int s = q.second % 5010;

        if (vis[cu][s]) continue;
        vis[cu][s] = true;

        chmin(ans[cu], cst);

        fore(p, E[cu]) {
            int to = p.first;
            int i = p.second;
            if (s < A[i]) continue;

            ll cst2 = cst + B[i];
            if (chmin(dist[to][s - A[i]], cst2)) que.push({ dist[to][s - A[i]], to * 5010 + s - A[i] });
        }

        ll cst2 = cst + D[cu];
        int s2 = min(3000, s + C[cu]);
        if (chmin(dist[cu][s2], cst2)) que.push({ dist[cu][s2], cu * 5010 + s2 });
    }

    rep(i, 1, N) printf("%lld\n", ans[i]);
}







Measured memory_bytes: 6636
n, k = map(int, input().split())
mo = 10 ** 9 + 7
ans = 0
def calc(t):
    u = (0 + t - 1) * t // 2
    v = (n + n - t + 1) * t // 2
    return v - u + 1
for i in range(k, n + 2):
    ans = (ans + calc(i)) % mo
print(ans)

Measured memory_bytes: 63940
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;

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

int main() {
    // 入力
    int N;
    cin >> N;
    string S; 
    cin >> S;

    vector<ll> al(26, 0);
    rep(i, 0, N) {
        al[S[i]-'a']++;
    }

    long long res = 1;
    rep(i, 0, 26) {
        if (al[i] > 0) {
            res *= (al[i] + 1);
            res %= MOD;
        }
    }
    res--;

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vll vector<ll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
ll mod1 = 1e9 + 7;
ll mod2 = 998244353;

ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=(z*x);x =(x*x) ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll max(ll a,ll b,ll c){
	return max(max(a,b),c);
}







int main(){
	ll cr,cg,r,g,cl,ans = 0;
	cin>>cr>>cg>>r>>g>>cl;
	vector<ll> vr,vg,vc;
	fo(i,r){
		ll temp;
		cin>>temp;
		vr.pb(temp);
	}
	fo(i,g){
		ll temp;
		cin>>temp;
		vg.pb(temp);
	}
	fo(i,cl){
		ll temp;
		cin>>temp;
		vc.pb(temp);
	}
	sort(all(vr));
	sort(all(vg));
	auto it1 = vr.begin();
	auto it2 = vg.begin();
	fo(i,r-cr){
	    it1++;
	}
	fo(i,g-cg)it2++;
	vr.erase(vr.begin(),it1);
	vg.erase(vg.begin(),it2);
	vector<pll> s;
	fo(i,vr.size()){
	    s.pb(mp(vr[i],0));
	}
	fo(i,vg.size()){
	    s.pb(mp(vg[i],1));
	}
	fo(i,vc.size()){
	    s.pb(mp(vc[i],2));
	}
	sort(all(s));
	ll n = s.size();
	ll cnt = cr+cg;
	ll r1=0,g1=0,c1=0;
	//cout<<cr<<endl<<cg;
	for(ll i = n-1;i>=n-cnt;i--){
	    
	    ans+=s[i].ff;
	    
	}
	cout<<ans<<endl;
    
	
	
	
}

Measured memory_bytes: 12908
N,K,S = map(int,input().split())

if S == 10**9:
    ans = [ str(S) if i<K else str(S//2+1) for i in range(N)]
else:
    ans = [ str(S) if i<K else str(S+1) for i in range(N)]

ans = ' '.join(ans)
print(ans)

Measured memory_bytes: 11288
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()


n,m = na()
a = []

for i in range(m):
    b = na()
    a.append(b)
    
p = na()

ans = 0

for i in range(1 << n):
    d = True
    for j in range(len(a)):
        c = 0
        for k in range(1,a[j][0]+1):
            if i >> (a[j][k]-1) & 1:
                c += 1
        if c%2 != p[j]:
            d = False
    if d:
        ans += 1

print(ans)

Measured memory_bytes: 3064
n = int(input())
h = list(map(int, input().split()))

ans = 'Yes'
m = h[0] - 1
for i in range(1, n):
    if m == h[i]:
        continue
    if m < h[i]:
        m = h[i] - 1
        continue
    ans = 'No'
    break
print(ans)



Measured memory_bytes: 14396
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;



int main()
{
    int n;
    scanf("%d",&n);
    if(n < 1200)
        printf("ABC\n");
    else if(n < 2800)
        printf("ARC\n");
    else printf("AGC\n");
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import deque

def solve(A: int, B: int, C: int, D: int, E: int):
    q = deque([])

    l = [A,B,C,D,E]
    for i in [0,9,8,7,6,5,4,3,2,1]:
        for j in l:
            if(j%10 == i):
                q.append(j)

    # print(q)
    ans = 0
    while len(q) > 0:
        x = q.popleft()
        if(x%10 == 0 or q == deque([])):
            ans += x
        else:
            ans += x+10-x%10
        # print(ans)
    print(ans)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    E = int(next(tokens))  # type: int
    solve(A, B, C, D, E)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
def main():
    n, a, b, c, d = [int(_) for _ in raw_input().split()]
    x0 = int(round((b - a) / (c + d) * 1.0 + (n - 1) / 2.0))
    for x in xrange(max(0, x0 - 2), min(x0 + 3, n - 1)):
        m1 = a + c * x
        M1 = a + d * x
        m2 = b - c * (x - n + 1)
        M2 = b - d * (x - n + 1)
        if max(m1, m2) <= min(M1, M2):
            return True
    return False


if __name__ == '__main__':
    print("YES" if main() else "NO")


Measured memory_bytes: 2568
#include <iostream>
#include <queue>

using namespace std;

priority_queue<int> q;

int main() {
    int n, m, x;
    cin >> n >> m;
    for(int i=0;i<n;i++) {
        cin >> x;
        q.push(x);
    }
    while(m--) {
        int tmp = q.top();
        q.pop();
        q.push(tmp/2);
    }
    long long ans = 0;
    while(!q.empty())
        ans += q.top(), q.pop();
    cout << ans << endl;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)

int main(){
    ll n;
    cin >> n;
    if(n%2==0){
        cout << n << endl;
    }else{
        cout << 2*n << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ll long long int
#define ALL(x) x.begin(),x.end()
using namespace std;
ll ans = 0, sum = 0, n, k, counter = 0, w, h;
string s;
vector<ll> v;
vector < pair<ll, ll > > vp;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> vs;

/*--------------------template--------------------*/

int main() {
	cin >> n >> k >> h >> w;
	if (n - k > 0) {
		ans = k*h + (n - k)*w;
	}
	else {
		ans = n*h;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
/*
 * atcoder ABC 136 : B. Build Stairs
 * Solution : Geothermal
 * edited by : anaksoleh
 * 22 august 2019
 *
 */

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

int N;
int arr[100005];

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

	cin >> N;
	int curr ; cin >> curr ; curr--;
	for(int i = 1 ; i < N ; i++){
		cin >> arr[i];
	}

	for(int i = 1 ; i < N ; i++){
		int next = arr[i];

		if(next > curr) next--;
		if(next < curr){
			cout << "No" << '\n';
			return 0;
		}
		curr = next;
	}

	cout << "Yes\n";

	return 0;
}

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

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

    int n, k;
    cin >> n >> k;
    vector<ll> a(n+1);
    rep(i, n) cin >> a[i+1];

    ll mod = 1e9 + 7, s = 0;

    ll dp[110][200010] = {0};

    dp[0][k] = 1;

    forx(i,1,n+1)rep(j,k+1){
        if(j==0){
            s = 0;
            rep(l, a[i] + 1){
                s += dp[i-1][l];
                s %= mod;
            }
        }
        else
            s += (dp[i-1][j + a[i]] - dp[i-1][j - 1]);
        s %= mod;
        dp[i][j] += s;
        dp[i][j] %= mod;
    }

    cout << (dp[n][0]+100*mod)%mod << endl;

    return 0;
}


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

int const N = 2000, inf = 1e9;
vector<int> tr[N + 1];
char s[N + 2];

pair<int, pair<int, int> > go(int v, int p = 0){
	int c = s[v] == '1', sma = 0;
	vector<pair<int, int> > w;
	f(i, 0, tr[v].size())if (tr[v][i] != p){
		pair<int, pair<int, int> > t = go(tr[v][i], v);
		sma += t.second.second + t.first;
		w.push_back(make_pair(t.second.second + t.first, t.second.first + t.first));
		c += t.first;
	}
	if (w.empty())return make_pair(c, make_pair(0, 0));
	sort(w.begin(), w.end());
	int s = 0;
	f(i, 0, w.size() - 1)s += w[i].first;
	if (s >= w.back().second)return make_pair(c, make_pair(0, sma));
	else return make_pair(c, make_pair(w.back().second - s, sma));
}

int main(){
	int n;
	scanf("%d%s", &n, s + 1);
	f(i, 1, n){
		int a, b;
		scanf("%d%d", &a, &b);
		tr[a].push_back(b);
		tr[b].push_back(a);
	}
	int o = inf;
	f(i, 1, n + 1){
		pair<int, int> t = go(i).second;
		if (t.second & 1 || t.first)continue;
		o = min(o, t.second >> 1);
	}
	printf("%d\n", o == inf ? -1 : o);
}

Measured memory_bytes: 640
import math
a, b= list(map(str, input().split()))
a_=int(a)
# 少数何桁か
b_=int(b.replace('.',''))
if len(str((a_*b_)))<3:
    print(0)
    exit()
seisu=str((a_*b_))[0:len(str(a_*b_))-2]
print(seisu)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int a,b;
  char c;
  cin >> a >> c >> b;
  if(c=='+')  cout << a+b;
  else  cout << a-b;
  
  return 0;
}


Measured memory_bytes: 764
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

template<typename T = ll>
struct FordFulkerson {
    struct Edge { int to, rev; T cap; Edge(int t, int r, T c) : to(t), rev(r), cap(c) {} };
    vector<vector<Edge>> graph;
    vector<bool> used;

    void add_edge(int from, int to, T cap) {
        graph[from].emplace_back(to, graph[to].size(), cap);
        graph[to].emplace_back(from, graph[from].size() - 1, 0);
    }

    T dfs(int v, int t, T f) {
        if (v == t) return f;
        used[v] = true;
        for (auto& e : graph[v]) {
            if (!used[e.to] && e.cap > 0) {
                T ret = dfs(e.to, t, min(f, e.cap));
                if (ret > 0) {
                    e.cap -= ret;
                    graph[e.to][e.rev].cap += ret;
                    return ret;
                }
            }
        }
        return 0;
    }

    T max_flow(int s, int t) {
        T flow = 0;
        for (;;) {
            used.assign(graph.size(), false);
            T f = dfs(s, t, numeric_limits<T>::max());
            if (f == 0) return flow;
            flow += f;
        }
    }
};

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> A(H);
    rep(i, H) cin >> A[i];

    int s = -1, t = -1;
    rep(i, H) rep(j, W) {
        if (A[i][j] == 'S') s = W * i + j;
        if (A[i][j] == 'T') t = W * i + j;
    }
    if (s / W == t / W || s % W == t % W) {
        write(-1);
        return 0;
    }

    int N = H * W;
    FordFulkerson<int> ff;
    ff.graph.resize(2 * N);
    rep(i, H) rep(j, W) {
        int v = W * i + j;
        ff.add_edge(v, N + v, 1);
    }
    rep(h, H) {
        rep(i, W - 1) rep(j, i + 1, W) {
            if (A[h][i] != '.' && A[h][j] != '.') {
                int v = W * h + i, u = W * h + j;
                ff.add_edge(N + v, u, H + W);
                ff.add_edge(N + u, v, H + W);
            }
        }
    }
    rep(w, W) {
        rep(i, H - 1) rep(j, i + 1, H) {
            if (A[i][w] != '.' && A[j][w] != '.') {
                int v = W * i + w, u = W * j + w;
                ff.add_edge(N + v, u, H + W);
                ff.add_edge(N + u, v, H + W);
            }
        }
    }

    write(ff.max_flow(N + s, t));
}

Measured memory_bytes: 62080
n = int(input())
ans = 0
import sys
sys.setrecursionlimit(10**9)
def func(a):
  global ans
  if a <= n and '3' in str(a) and '5' in str(a) and '7' in str(a):
    ans += 1
  if a < n:
    func(int(str(a)+'3'))
    func(int(str(a)+'5'))
    func(int(str(a)+'7'))
func(3)
func(5)
func(7)
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

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

		int dataSet = scan.nextInt();

		// [½ÔÚÌf[^Zbg]ÌÅåÅ¬
		int[] maxUp = new int[dataSet];
		int[] maxDown = new int[dataSet];

		// 0Åú»
		for (int i = 0; i < dataSet; i++) {
			maxUp[i] = 0;
			maxDown[i] = 0;
		}

		// [½ÔÚÌf[^Zbg][i·Ì]
		int[][] block = new int[dataSet][];

		// ubNÉlüÍ
		for (int i = 0; i < dataSet; i++) {
			// ubNÌ
			int numberOfBlock = scan.nextInt();
			block[i] = new int[numberOfBlock];

			for (int j = 0; j < numberOfBlock; j++) {
				block[i][j] = scan.nextInt();
			}

		}

		// Å¬ÆÅåðvZ
		for (int i = 0; i < block.length; i++) {
			for (int j = 0; j < block[i].length - 1; j++) {
				if (block[i][j] < block[i][j + 1] && (block[i][j + 1] - block[i][j]) > maxUp[i]) {
					maxUp[i] = block[i][j + 1] - block[i][j];

				} else if (block[i][j + 1] < block[i][j] && (block[i][j] - block[i][j + 1]) > maxDown[i]) {
					maxDown[i] = block[i][j] - block[i][j + 1];
				}
			}
			System.out.println(maxUp[i] + " " + maxDown[i]);
		}

	}
}

Measured memory_bytes: 0
#include <stdio.h>
int main(void)
{
	int a, b;
	scanf("%d",&a);
	scanf("%d",&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: 2556
#include <iostream>
#include <cmath>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    int A, B, C;

    cin >> A >> B >> C;
    cout << max(C - (A - B), 0) << endl;

    return 0;
}


Measured memory_bytes: 256
N=int(input())
A=[list(map(int, input().split())) for _ in range(N)]
L,R=zip(*A)
L=sorted(L)
R=sorted(R)[::-1]
if N%2==1:
  #print(R[N//2],L[N//2])
  print(R[N//2]-L[N//2]+1)
else:
  r1,r2=R[N//2-1],R[N//2]
  l1,l2=L[N//2-1],L[N//2]
  #print(r1,r2,l1,l2)
  print((r1+r2)-(l1+l2)+1)

Measured memory_bytes: 61208
#include"bits/stdc++.h"
using namespace std;

template<typename T>
T gcd(T a, T b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

void Main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  vector<int> l(n), r(n);
  l[0] = a[1];
  l[1] = a[0];
  for (int i = 2; i < n; i++) {
    l[i] = gcd(l[i - 1], a[i - 1]);
  }

  r[n - 1] = a[n - 2];
  r[n - 2] = a[n - 1];
  for (int i = n - 3; i >= 0; i--) {
    r[i] = gcd(a[i + 1], r[i + 1]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, gcd(l[i], r[i]));
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
using namespace std;


void solve(){
  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  vector<int> aida(n + 1);
  aida[0] = abs(a[0]);
  for(int i = 1; i < n; i++){
    aida[i] = abs(a[i] - a[i - 1]);
  }
  aida[n] = abs(a[n - 1]);
  int sum = 0;
  for(int i = 0; i <= n; i++) sum += aida[i];
  int ans = 0;
  ans = sum - aida[0] - aida[1] + abs(a[1]);
  cout << ans << endl;
  for(int i = 1; i < n - 1; i++){
    ans = sum - aida[i] - aida[i + 1] + abs(a[i + 1] - a[i - 1]);
    cout << ans << endl;
  }
  ans = sum - aida[n - 1] - aida[n] + abs(a[n - 2]);
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


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

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int m = scan.nextInt();
			if(n == 0 && m == 0){
				break;
			}
			int[] p = new int[n];
			for(int i = 0;i < n;i++){
				p[i] = scan.nextInt();
			}
			Arrays.sort(p);
			int sum = 0;
			int count = 0;
			for(int i = 0;i < n;i++){
				if(count == m-1){
					count = 0;
					continue;
				}
				sum += p[n-1-i];
				count++;
			}
			System.out.println(sum);			
		}
	}
}

Measured memory_bytes: 54584
#include <cstdio>
#include <cmath>
int main(void) {
	int n, s[1000];


	while (scanf("%d", &n) != EOF) {
		float m = 0, sig = 0;
		if (!n)return 0;
		for (int i = 0; n > i; i++) {
			scanf("%d", &s[i]);
			m += s[i];
		}
		m /= n;
		for (int i = 0; n > i; i++) {
			sig += (s[i] - m)*(s[i] - m);
		}
		printf("%f\n", sqrt(sig / n));
	}
	return 0;
}

Measured memory_bytes: 1064
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

set<int> merge(set<int>& a, set<int>& b) {
	set<int> ret = a;
	for (auto itr = b.begin(); itr != b.end(); itr++) {
		ret.insert(*itr);
	}
	return ret;
}
set<int> merge_(set<int> a, set<int> b) {
	set<int> ret = a;
	for (auto itr = b.begin(); itr != b.end(); itr++) {
		ret.insert(*itr);
	}
	return ret;
}

//Segment Tree
struct ST {
private:
	int n;
	vector<set<int>> node;
public:
	ST(vector<set<int>> v) {
		int sz = v.size();
		n = 1; while (n < sz)n *= 2;
		node.resize(n * 2 - 1, set<int>());

		for (int i = 0; i < sz; i++)node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--)node[i] = merge(node[2 * i + 1], node[2 * i + 2]);
	}
	void update(int x, set<int> val) {
		x += (n - 1);
		node[x] = val;
		while (x > 0) {
			x = (x - 1) / 2;
			//node[x] = min(node[2 * x + 1], node[2 * x + 2]);
			node[x] = merge(node[2 * x + 1], node[2 * x + 2]);
		}
	}
	set<int> get(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = n;
		if (r <= a || b <= l)return set<int>();
		if (a <= l && r <= b)return node[k];
		return merge_( get(a, b, 2 * k + 1, l, (l + r) / 2), get(a, b, 2 * k + 2, (l + r) / 2, r) );
	}
};

int main() {
	int N, Q;
	string S;
	cin >> N >> S >> Q;
	vector<set<int>> v(N+1);
	for (int i = 0; i < N; i++) {
		v[i+1].insert((int)S[i]);
	}
	ST segtree(v);
	for (int i = 0; i < Q; i++) {
		int a;
		cin >> a;
		if (a == 1) {
			int b; char c;
			cin >> b >> c;
			set<int> tmp;
			tmp.insert(c);
			segtree.update(b, tmp);
		}
		else {
			int b, c;
			cin >> b >> c;
			cout << segtree.get(b, c+1).size() << endl;
		}
	}
}

Measured memory_bytes: 282372
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int h[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int dp[n];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout << dp[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
int MOD = 1000000007;

using namespace std;

signed main(){
    
    int n; 
    cin >> n;

    int ans = 0;

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

    SORT(a);

    int s = a[0];

    for(int i = 1; i <= n-1;i++){
        if(2*s >= a[i]){
            s += a[i];
        }else{
            s += a[i];
            ans = i;
        }
    }
    
    cout << n - ans << endl;

    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef		vector<ll>      vll;
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define     pii             pair<ll,ll>
const double eps = 1e-8;


int main()
{

//     ios::sync_with_stdio(0);
//	cin.tie(0);

  ll flag=1;
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  ll ans=0;
  ll mn=min(a,k);
  ans+=mn;
  k-=mn;
  if(k>0)
  {
      mn=min(b,k);
      k-=mn;
  }
  if(k>0)
  {
      ans-=k;
  }
  cout<<ans<<nn;




}



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

/*==========type============*/
typedef long long ll;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
typedef std::pair<std::string,ll> psl;

/*==========constant============*/
#define INF INT_MAX
#define INF_L LONG_MAX
#define INF_LL LLONG_MAX
#define MOD 1000000007

/*==========function============*/
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

using namespace std;

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

    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    
    ll ans = 0;
    if(a >= k){
        ans += k;
        k -= a;
    }else{
        ans += a;
        k -= a;
    }
    if(k <= 0){
        cout << ans << endl;
        return 0;
    }

    if(b >= k){
        k -= b;
    }else{
        k -= b;
    }
    if(k <= 0){
        cout << ans << endl;
        return 0;
    }

    if(c >= k){
        ans -= k;
        k -= c;
    }else{
        ans -= c;
        k -= c;
    }
    if(k <= 0){
        cout << ans << endl;
        return 0;
    }


    cout << ans << endl;

    return 0;
}    

Measured memory_bytes: 3640
a = input()
b = input()
c = input()
x = 0
y = 0
z = 0
q = "a"
ans = 0
while 1:
    
    if q == "a":
        if len(a) == x:
            ans = "A"
            break
        q = a[x]
        x += 1
        
    elif q == "b":
        if len(b) == y:
            ans = "B"
            break
        q = b[y]
        y += 1
        
    else:
        if len(c) == z:
            ans = "C"
            break
        q = c[z]
        z += 1
        
print(ans)

Measured memory_bytes: 9144
#include<iostream>
#include<stdio.h>

using namespace std;

int main() {

	int h, w;

	while (true) {
		cin >> h >> w;
		if (h == 0 && w == 0) break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (i == 0 || i == h-1 || j == 0 || j == w - 1) cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3044
#include <iostream>
#include <math.h>
using namespace std;
int main(){
        int N,counter=0;
        cin >> N;
        for(int i=0 ; i<N ; i++ ){
                int x;
                cin >> x;
                bool sign=1;
                for(int l=2 ; l<=sqrt(x) ; l++ ){
                        if(!(x%l)){
                                sign=0;
                                break;
                        }
                }
                if(sign){
                        counter++;
                }
        }
        cout << counter << endl;
        return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <stack>
typedef long long ll;

using namespace std;

int main() {
    ll l, r;
    cin >> l >> r;
    
    ll ans = 2019;
    for(ll i = l; i <= r; i++) {
        if(i % 2019 == 0) {
            ans = 0;
            break;
        }
        
        bool flag = false;
        for(ll j = i + 1; j <= r; j++) {
            if(j % 2019 == 0) {
                ans = 0;
                break;
            }
            else {
                ans = min(ans, (i * j) % 2019);
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
ll qpow(ll a,ll b){
    ll res=1,rem=a;
    while(b){
        if(b&1) res=(res*rem)%MOD;
        rem=(rem*rem)%MOD;
        b>>=1;
    }
    return res;
}
struct Euler{
    static const ll MAXN=1e5+10;
    static const ll MOD=1e9+7;
    ll pri[MAXN],jud[MAXN],phi[MAXN]={0,1},cnt;
    void work(ll tmt){
        for(ll i=2;i<=tmt;i++){
            if(!jud[i]){
                pri[cnt++]=i;
                phi[i]=(i-1)%MOD;
            }
            for(ll j=0;j<cnt&&i*pri[j]<=tmt;j++){
                jud[i*pri[j]]=1;
                if(i%pri[j]==0){
                    phi[i*pri[j]]=phi[i]*pri[j];
                    break;
                }
                phi[i*pri[j]]=phi[i]*phi[pri[j]];
            }
        }
    }
}euler;
int main(){
    ll n,k;scanf("%lld %lld",&n,&k);
    euler.work(k);
    ll res=0;
    for(ll i=1;i<=k;i++) res=(res+qpow(k/i,n)*euler.phi[i])%MOD;
    printf("%lld\n",res);
    return 0;
}


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

using namespace std;

typedef long long ll;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename T>
string to_string(vector<T> v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int mx_sf = a[0];
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] < mx_sf) {
      ans += (ll) abs(a[i] - mx_sf);
    }
    mx_sf = max(mx_sf, a[i]);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3992
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		ArrayList<Integer> array = new ArrayList<Integer>();

		for(int i=1;i<=x;i++) {
			String tmp = Integer.toString(i);
			if(i%3==0 || tmp.contains("3")) {
				array.add(i);
			}
		}

		for(int i=0;i<array.size();i++) {
			System.out.print(" " + array.get(i));
		}
		System.out.println();

		sc.close();
	}
}


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

bool isPrime(int x) {
    if(x == 1) return false;

    for (int i = 2; i < x; i++) {
        if(x % i == 0) return false;
    }
    return true;
}

int main() {
    int n;
    cin >> n;

    vector<int> Prime;
    for (int i = 2; i <= n; i++) {
        if(isPrime(i)) Prime.push_back(i);
    }
    int m = Prime.size();

    vector<int> divisor(110);

    for (int i = 1; i <= n; i++) {
        int x = i;
        while (x > 1) {
            for (auto d : Prime) {
                if (x % d == 0) {
                    x /= d;
                    divisor[d]++;
                }
            }
        }
    }

    vector<int> comb(110);
    vector<int> a = {2, 4, 14, 24, 74};

    for (auto it : a) {
        for (auto num : divisor) {
            if(num >= it) comb[it]++;
        }
    }

    int ans = 0;
    ans += comb[74];
    ans += comb[24] * (comb[2] - 1);
    ans += comb[14] * (comb[4] - 1);
    ans += (comb[4] * (comb[4] - 1) / 2) * (comb[2] - 2);

    cout << ans << '\n';
}

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

int main(){
	vector<int> data(3);
  	for(int i=0;i<3;i++){
    	cin >> data.at(i);
    }
  	sort(data.begin(),data.end());
  	if(data.at(0)==5 && data.at(1)==5 && data.at(2)) {cout << "YES" << endl;}
  	else {cout << "NO" << endl;}
  	
}

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

typedef long long ll;

int A[100010];

int main() {
  int N,K; cin >> N >> K;
  for ( int i = 1; i <= N; i++ ) cin >> A[i];
  int cnt = 1;
  N -= K;
  while(N>0) {
    N -= K-1;
    cnt++;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
#define N 10000

main(){
  int n,b[N],i,j,k=0,d=0;

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

    for(j=3;j<=sqrt(b[i]);j+=2){
     
      if(b[i]%j==0) d=1;
    } 
      if(d==0) k++;
      d=0;
    }
  
    printf("%d\n",k);
    return 0;
  }

Measured memory_bytes: 628
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int ans = (n-1)*n + m*(m-1);
    ans /= 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
int n,k,x[maxn];
inline int mymin(int a,int b){return a<b?a:b;}
int main(){
    scanf("%d%d",&n,&k);
    for(register int i=1;i<=n;i++) scanf("%d",&x[i]);
    int ll=1,mint=(int)4e8+10;
    if(x[n]<0){
        printf("%d",-x[n-k+1]);
        return 0;
    }
    while(x[ll+k-1]<0) ll++;
    while((x[ll]<=0)&&(ll+k-1<=n)){
        mint=mymin(mint,x[ll+k-1]-x[ll]+mymin(x[ll+k-1],-x[ll]));
        ll++;
    }
    if(ll+k-1<=n){
        mint=mymin(mint,x[ll+k-1]-x[ll]+mymin(x[ll+k-1],x[ll]));
        ll++;
    }
    printf("%d",mint);
    return 0;
}

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

result = [0] * (n-1)
short = y - x - 1
for i in range(n-1):
  for j in range(n-i-1):
    start = i + 1
    end = j + i + 2
    dist_no_shortcut = end - start
    dist_with_shortcut = abs(start - x) + abs(end - y) + 1
    dist = min(dist_no_shortcut, dist_with_shortcut)
    result[dist-1] += 1

for v in result:
  print(v)

Measured memory_bytes: 46300
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007

int main()
{
    int n, k;
    cin >> n >> k;
    int a[200000];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int l = 0, r = MOD;
    while (r - l > 1)
    {
        int mid = (r + l) / 2;
        int cnt = 0;
        for (int i = 0; i < n; i++)
        {
            cnt += a[i] / mid;
            if (a[i] % mid == 0)
                cnt--;
        }
        if (cnt <= k)
        {
            r = mid;
        }
        else
        {
            l = mid;
        }
    }
    cout << r << endl;
}

Measured memory_bytes: 4440
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long
//cout << fixed << setprecision (10);   小数点以下１０桁まで

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

    cout <<min(b/a,c)<< endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define eps 1e-9
#define N 200
using namespace std;
typedef double ld;
typedef pair<int,int> p;
typedef pair<ld,p> P;

int n;
ld px[N],py[N],pz[N],vx[N],vy[N],vz[N],r[N],vr[N];

ld getlen(int a,int b,ld M){
  ld ax=px[a]+vx[a]*M,ay=py[a]+vy[a]*M,az=pz[a]+vz[a]*M,ar=r[a]-vr[a]*M;
  ld bx=px[b]+vx[b]*M,by=py[b]+vy[b]*M,bz=pz[b]+vz[b]*M,br=r[b]-vr[b]*M;
  ld dx=ax-bx,dy=ay-by,dz=az-bz;
  return sqrt(dx*dx+dy*dy+dz*dz)-(ar+br);
}

ld check(int a,int b){
  ld L=0,R=100,M;
  int s=50;
  while(s--){
    M=(L+R)/2;
    ld len=getlen(a,b,M),len1=getlen(a,b,M+eps);
    if(len<len1||len<0)R=M;
    else L=M;
  }
  if(getlen(a,b,R)>0)return 100;
  return R;
}

int main(){
  while(cin>>n,n){
    for(int i=0;i<n;i++)
      cin>>px[i]>>py[i]>>pz[i]>>vx[i]>>vy[i]>>vz[i]>>r[i]>>vr[i];
    priority_queue<P,vector<P>,greater<P> > q;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++)
	q.push(P(check(i,j),p(i,j)));
      q.push(P(r[i]/vr[i],p(i,i)));
    }
    ld used[200]={};
    while(!q.empty()){
      ld t=q.top().first;
      int a=q.top().second.first,b=q.top().second.second;
      q.pop();
      if(used[a]||used[b])continue;
      used[a]=used[b]=t;
    }
    for(int i=0;i<n;i++)printf("%.10lf\n",used[i]);
  }
  return 0;
}

Measured memory_bytes: 3748
while True:
	n, m = [int(i) for i in input().split()]
	if (n == 0) & (m == 0):
		break
	a = [int (i) for i in input().split()]
	ans = 0
	for i in range(n):
		for j in range(n):
			if i == j:
				continue
			if (a[i] + a[j] <= m) & (a[i] + a[j] > ans):
				ans = a[i] + a[j]

	if ans == 0:
		print('NONE')
	else:
		print(ans)

Measured memory_bytes: 7848