akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, m, a;
string str;

int main(){
	cin >> n >> m;
	ll MOD = 1e9+7;
	ll brk[n+1], dp[n+1];
	
	memset(brk, 0, sizeof(brk));
	for(ll j = 1; j <= m; j++){cin >> a; brk[a] = 1;}
	
	dp[0] = 1;
	for(ll i = 1; i <= n; i++){
		if(brk[i] == 0){
			dp[i] = (i != 1)? dp[i-1]+dp[i-2] : dp[i-1];
			dp[i] %= MOD;
		}
		else{
			dp[i] = 0;
		}
	}
	
	cout << dp[n] << endl;
	return 0;
}

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

#define lint long long
#define P pair<int, int>

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

signed main() {

    int N;
    cin >> N;

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

    lint ans = T[0];

    for(int i = 1; i < N; ++i){
        ans /= gcd(ans, T[i]);
        ans *= T[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
// using namespace atcoder;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

template< typename T >
struct SegTree {
    using F = function< T(T, T) >;
    int size;
    vector<T> data;

    const F f;
    const T t0;

    SegTree(int n, const F f, const T &t0) : f(f), t0(t0) {
        size = 1;
        while(size < n) size *= 2;
        data.assign(size*2-1, t0);
    }

    SegTree(vector<T> &vec, const F f, const T &t0) : f(f), t0(t0) {
        size = 1;
        while(size < sz(vec)) size *= 2;
        data.assign(size*2-1, t0);

        rep(i, min(sz(vec), size)) data[i+size-1] = vec[i];
        for(int i=size-2; i>=0; i--) data[i] = f(data[i*2+1], data[i*2+2]);
    }

    void update(int x, const T &val) {
        x += size-1;
        data[x] = val;
        while(x) {
            x = (x-1) / 2;
            data[x] = f(data[x*2+1], data[x*2+2]);
        }
    }

    T query(int a, int b, int k=0, int l=0, int r=-1) {
        if (r<0) r = size;
        if (r<=a || l>=b) return t0;
        if (a<=l && b>=r) return data[k];
        T vl = query(a, b, k*2+1, l, (l+r)/2);
        T vr = query(a, b, k*2+2, (l+r)/2, r);
        return f(vl, vr);
    }
};

int main() {
    int n, k; cin >> n >> k;
    const int MAX_I = 300010;
    SegTree<int> seg(MAX_I, [](int a, int b){return max(a,b);}, 0);

    rep(i, n) {
        int x; cin >> x;
        int l = max(0, x-k), r = min(MAX_I, x+k);
        int maxNum = seg.query(l, r+1);
        debug(x, l, r, maxNum);
        seg.update(x, maxNum+1);
        // rep(i, n) cout << seg.query(i, i+1) << " ";
    }

    cout << seg.query(0, MAX_I) << endl;
}

Measured memory_bytes: 7460
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
const int N = 1e5;  // limit for array size
ll n;  // array size

int main(){
	ll n,x;cin>>n>>x;
	
	vector<ll>v;
	
	ll a;
	
	for(int i=0;i<n;i++){
		cin>>a;
		v.pb(a);
	}
	
	v.pb(x);
	
	sort(v.begin(),v.end());
	
	ll ans=0;
	
	for(int i=1;i<v.size();i++){
		ans=__gcd(ans,v[i]-v[i-1]);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
map<ll,ll> insuu;
void prime_factor(ll n){
    ll k=n;
	for(ll i=2;i*i<=n;i++){
	    while(k%i==0){
	        insuu[i]++;
	        k/=i;
	    }
	}
	if(k!=1) insuu[k]=1;
	return ;
}

int main(){
  ll n;
  cin>>n;
  prime_factor(n);
  ll ans=0;
  vll h(32);
  h[0]=1;
  rep(i,40){
    h[i+1]+=h[i]+i+2;
  }
  for(auto p:insuu){
    rep(i,31){
      if(h[i]>p.S){
        ans+=i;
        break;
      }
    }
  }
  COUT(ans);
}

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

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

  string s = to_string(N);
  int n = 0;
  for (char c : s) n += c - '0';
  if (N % n == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long int 
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define from(i,n)       for(int i=0;i<(int)n;i++)
#define from_j(i,j,n)   for(int i=j;i<(int)n;i++)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
 
int32_t main()
{
    c_p_c();
    int n,k; cin>>n>>k;
    int arr[n]; from(i,n)cin>>arr[i];
    int cost[n]; cost[0]=0; 
    
    for(int i=1;i<n;i++){
        int temp = inf;
        for(int j=1;j<=k;j++){
            if((i-j)<0)break;
            temp = min(cost[i-j]+abs(arr[i]-arr[i-j]),temp); 
        }
        cost[i] = temp; 
    }
    cout<<cost[n-1];
    return 0;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int> > g(n+1);
  int i,j,k;
  int cnt[n+1]={};
  for(i=0;i<m;i++){
    cin >> j >> k;
  	g[j].push_back(k);
    cnt[k]++;
  }

  queue<int> que,topo;
  for(i=1;i<=n;i++){
    if(cnt[i]==0){
      que.push(i);
      topo.push(i);
    }
  }
  
  while(!que.empty()){
    int x = que.front();
    que.pop();
    int s=g[x].size();
    for(i=0;i<s;i++){
      cnt[g[x][i]]--;
      if(cnt[g[x][i]]==0){
        que.push(g[x][i]);
        topo.push(g[x][i]);
      }
    }
  }
  int dp[n+1]={};
  while(!topo.empty()){
    int x = topo.front();
    topo.pop();
    int s = g[x].size();
    for(i=0;i<s;i++){
      dp[g[x][i]]=max(dp[g[x][i]],dp[x]+1);
    }
  }
  int ret=0;
  for(i=1;i<=n;i++)ret=max(ret,dp[i]);
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 6912
def main():
    k, s = map(int, input().split())
    
    c = 0
    for x in range(k + 1):
        for y in range(k + 1):
            if 0 <= s - (x + y) <= k:
                c += 1
    print(c)


if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

struct edge {
    long long to, cost;
};
// firstがその頂点までの最短距離, secondは頂点番号
typedef pair<long long, long long> P;

void dijkstra(long long s, vector<vector<edge>>& G, vector<long long>& d) {//始点、隣接リスト、距離を渡す
    priority_queue<P, vector<P>, greater<P>> que;
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        long long v = p.second;
        if (d[v] < p.first) continue;
        for (long long i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long INF = 1000000000000007;
    
    long long N, M, S, T;
    cin >> N >> M >> S >> T;
    S--;T--;
    vector<vector<edge>> yenG(N);
    vector<long long> yenD(N, INF);
    vector<vector<edge>> sunukuG(N);
    vector<long long> sunukuD(N, INF);
    long long u, v, a, b;
    for (long long i = 0; i < M; i++) {
        cin >> u >> v >> a >> b;
        u--;v--;
        yenG[u].push_back({v, a});
        yenG[v].push_back({u, a});
        sunukuG[u].push_back({v, b});
        sunukuG[v].push_back({u, b});
    }
    dijkstra(S, yenG, yenD);
    dijkstra(T, sunukuG, sunukuD);
    long long ans = 1000000000000000;
    vector<long long> D(N);
    for (long long i = 0; i < N; i++) {
        D[i] = yenD[i] + sunukuD[i];
    }
    for (long long i = N - 1; i > 0; i--) {
        if (D[i - 1]>D[i]) {
            D[i - 1] = D[i];
        }
    }
    for (auto i : D) {
        cout << ans - i << endl;
    }
}

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

using namespace std;

int main()
{
   int a,b,k;
   cin>>a>>b>>k;
   int c=0;
   for(int i=101;i>=0;i--)
   {
       if((a%i==0)&&(b%i==0))
        {
            c++;
            if(c==k){
                cout<<i<<endl;
            return 0;
            }
        }

   }
}


Measured memory_bytes: 256
from sys import stdin,stdout

n = int(stdin.readline())
ls = list()
dp1 = [0] * n
dp2 = [0] * n
dp3 = [0] * n
for i in range(n):
	a, b, c = map(int, stdin.readline().split())
	if i == 0:
		dp1[0] = a
		dp2[0] = b
		dp3[0] = c
	else:
		dp1[i] = max(dp2[i - 1], dp3[i - 1]) + a
		dp2[i] = max(dp1[i - 1], dp3[i - 1]) + b
		dp3[i] = max(dp1[i - 1], dp2[i - 1]) + c
print(max(dp1[n - 1], dp2[n - 1], dp3[n - 1]))


Measured memory_bytes: 76584
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
	Scanner in = new Scanner(System.in);
	int i=1;
	while(true){
	  int num = in.nextInt();
	  if(num==0)break;
	  System.out.println("Case "+ i +": "+num);
	  i++;
	}
    }
}
	  



Measured memory_bytes: 41284
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, l = LI()
origin = 0
m = inf
for i in range(n):
    origin += l + i
    if m > abs(l + i):
        m = min(m, abs(l + i))
        x = l + i
ans = origin - x
print(ans)

Measured memory_bytes: 65164
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,cnt=0,tmp;
  cin >> n;
  ll p[n],q[n];
  for(int i=0;i<n;i++){
    cin >> p[i];
    p[i]--;
    q[p[i]]=i;
  }
  tmp=1;
  for(int i=0;i<n-1;i++){
    if(q[i]>q[i+1]){
      cnt = max(cnt,tmp);
      tmp=1;
    }else{
      tmp++;
    }
  }
  cnt = max(cnt,tmp);
  cout << n-cnt << endl;
}


Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int a[5],k;
	for(int i=0;i<5;i++)
		cin >> a[i];
	cin >> k;
	sort(a,a+5);
	cout << (a[4]-a[0]>k ? ":(":"Yay!") << endl;




}

Measured memory_bytes: 256
N = int(input())
is_approved = True
l = list(map(int, input().split()))
for i in l:
    if i % 2 == 0:
        if not (i % 5 == 0 or i % 3 == 0):
            is_approved = False
            break
print('APPROVED' if is_approved else 'DENIED')

Measured memory_bytes: 3068
#if 1

#include <bits/stdc++.h>
using namespace std;
long long a[1005],b[1005],c[1005],aa,bb,cc;
long long a1[1000005],ans[9000005];
int ap,bp,cp,k;
set <long long> s;

bool cmp(long long x,long long y)
{
    return x < y;
}

typedef struct
{
    int cnt;
    int a;
    int b;
    int c;
}X;

int main()
{
    scanf("%d %d %d %d", &ap, &bp, &cp, &k);
    for(int i = 1;i <= ap;i++)
    {
        scanf("%lld",&a[i]);
    }
    for(int i = 1;i <= bp;i++)
    {
        scanf("%lld",&b[i]);
    }
    for(int i = 1;i <= cp;i++)
    {
        scanf("%lld",&c[i]);
    }
    sort(a+1,a+ap+1,cmp);
    sort(b+1,b+bp+1,cmp);
    sort(c+1,c+cp+1,cmp);
    int cn = 1;
    long long cnt;
    for(int i = 1;i <= ap;i++)
    {
        for(int j = 1;j <= bp;j++)
        {
            a1[(i-1)*bp+j] = a[i]+b[j];
        }
    }
    sort(a1+1,a1+ap*bp+1);
    reverse(a1+1,a1+ap*bp+1);
    for(int i = 1;i <= min(ap*bp,k);i++)
    {
        for(int j = 1;j <= cp;j++)
        {
            ans[(i-1)*cp+j] = a1[i]+c[j];
        }
    }
    sort(ans+1,ans+min(ap*bp,k)*cp+1);
    reverse(ans+1,ans+min(ap*bp,k)*cp+1);
    for(int i = 1;i <= k;i++)
    {
        printf("%lld\n",ans[i]);
    }
    //q.push({a[ap]+b[bp]+c[cp],ap,bp,cp});
    #if 0
    while(!q.empty())
    {
        cnt = q.top().cnt;
        aa = q.top().a;
        bb = q.top().b;
        cc = q.top().c;
        q.pop();
        if(s.count(cnt) == 1) continue;
    }
    #endif
    #if 0
    for(int i = 1;i <= k;i++)
    {
        printf("%lld\n",a[ap]+b[bp]+c[cp]);
        printf("%d %d %d\n",ap,bp,cp);
        aa = (ap == 0) ? 100000000000000 : a[ap]-a[ap-1];
        bb = (bp == 0) ? 100000000000000 : b[bp]-b[bp-1];
        cc = (cp == 0) ? 100000000000000 : c[cp]-c[cp-1];
        m = min(aa,min(bb,cc));
        if(m == aa)
        {
            ap--;
        }
        else if(m == bb)
        {
            bp--;
        }
        else if(m == cc)
        {
            cp--;
        }
    }
    #endif
}


#endif // 1++


Measured memory_bytes: 33408
import sys


#input
lines = [x.strip() for x in sys.stdin.readlines()]

def slv(lines):
    n, y = [int(x) for x in lines[0].split()]
    for yukichi in range(n+1):
        for ichiyo in range(n+1-yukichi):
            if (y-10000*yukichi-5000*ichiyo)/1000 == n-yukichi-ichiyo:
                if n-yukichi-ichiyo < 0:
                    continue
                return " ".join([str(yukichi),str(ichiyo),str(n-yukichi-ichiyo)])

    return "-1 -1 -1"

if __name__ == "__main__":
    print(slv(lines))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    vector<string>s(n);
    for(int i=0;i<n;i++)
    {
            cin>>s[i];
    }
    sort(s.begin(),s.end());
    for(int i=0;i<n;i++)
    {
        cout<<s[i];
    }
}


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

int main() {
  int N,M;
  cin >> N >> M;

  vector<int> A(N);
  string ans ="Yes";
  double total =0;

  for(int i =0;i<N;i++){
    cin >>A.at(i);
    total +=A.at(i);
  }
  double threshold = total/(4*M);

  sort(A.begin(),A.end(),greater<int>());

  if(A.at(M-1) < threshold) {
    ans ="No";
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;

#define rp(i,t) for(int i=0;i<(t);i++)
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define rsp(i,s,t) for(int i=(s);i<(t);i++)
#define rrp(i,t,s) for(int i=(t);i>=(s);i--)
#define rcp(i,s,b,d) for(int i=(s);b;d)
#define mst(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define N 302

#define Dp puts("")
#define Dw printf
#define Ds printf("#")

typedef long long ll;
bool killed[N];
char ch;
int n,m,a[N][N],c[N],mx,ans=INF,p[N];

inline void read(int &x){x=0;do{ch=getchar();}while(ch<'0'||'9'<ch);do{x=x*10+ch-'0';ch=getchar();}while('0'<=ch&&ch<='9');}

int main(void)
{
	read(n),read(m);
	rep(i,1,n)rep(j,1,m)read(a[i][j]);
	rep(i,1,n)c[a[i][p[i]=1]]++;
	rep(i,1,m)
	{
		mx=0;
		rep(i,1,m)if(c[mx]<c[i])mx=i;
		ans=min(ans,c[mx]);
		c[mx]=0;
		killed[mx]=true;
		rep(i,1,n)
		{
			c[a[i][p[i]]]--;
			while(killed[a[i][p[i]]])p[i]++;
			c[a[i][p[i]]]++;
		}
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 998244353

typedef long long int lli;

lli zyou(lli a, lli x)
{
  lli ans = 1;
  rep(i, 0, x) ans = (ans * a) % MOD;
  return ans;
}

int main(void)
{
  int n, d[MAX];
  scanf("%d", &n);

  lli kyori[MAX] = {0}; // kyori[i]:頂点1からの距離がiの個数
  int len = 0;
  rep(i, 0, n)
  {
    scanf("%d", &d[i]);
    len = max(len, d[i]);
    kyori[d[i]]++;
  }

  lli ans = 1;
  rep(i, 0, len)
    ans = (ans * zyou(kyori[i], kyori[i + 1])) % MOD;
  if (kyori[0] != 1 || d[0] != 0)
    ans = 0;
  printf("%lld\n", ans % MOD);
  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>

using namespace std;

void Print(vector<long int> v){

    cout << v[1];
    for(int i = 2;i < v.size(); i++)
        cout << " " << v[i];
    cout << endl;
}

bool check(long int n)
{
    return n < 0;
}

long int MinNumber(vector<long int> v)
{
    long int n;
    if(abs(v[1]) > abs(v[2]))
        n = v[2];
    else
        n = v[1];

    for(int i = 3;i < v.size(); i++)
    {
        if(abs(n) > abs(v[i]))
            n = v[i];
    }


    return n;
}

int main()
{
    int N;
    cin >> N;
    vector<long int> v(N+1, 0);

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

    for(int i = 1;i < v.size()-1; i++)
    {
        if(v[i] <= 0 && v[i+1] <= 0)
        {
            v[i] *= -1;
            v[i+1] *= -1;
        }
    }


    for(int i = 2;i < v.size()-1; i++)
    {
        if(v[i-1] < 0 && v[i+1] < 0)
        {
            v[i-1] *= -1;
            v[i+1] *= -1;
        }
    }


    long long int cnt = count_if(v.begin()+1, v.end(), check), sum = 0;
    if(cnt % 2 == 0)
    {
        for(int i = 1;i < v.size(); i++)
        {
            if(v[i] < 0)
                sum += v[i] * -1;
            else
                sum += v[i];
        }
    }else{
        long int Min = MinNumber(v);

        for(int i = 1;i < v.size(); i++)
        {
            if(v[i] < 0 && v[i] != Min)
                sum += v[i] * -1;
            else if(v[i] == Min && v[i] > 0)
                sum += v[i] * -1;
            else
                sum += v[i];
        }
    }

    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 1792
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
  // ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int A[31];
  for(int i=0;i<31;i++) {
    A[i] = 0;
  }

  for(int i=0;i<n;i++) {
    int k;
    cin >> k;
    for(int j=0;j<k;j++) {
      int likeN;
      cin >> likeN;
      // cout << likeN << endl;
      // cout << i+1 << endl << likeN << endl;
      A[likeN]++;
    }
    // cout << A[i+1] << endl;
  }

  // for(int i=0;i<m;i++) {
  //   cout << "index:" << i << " ans:" << M[i] << endl;
  // }
  // return 0;

  int count = 0;
  for(int i=1;i<=m;i++) {
    if(A[i] == n) {
      count++;
    }
  }

  cout << count;
  return 0;
}


Measured memory_bytes: 256
float X[300],Y[300],x,y,d;N,j,m,c;C(k){c=0;for(k=N;k--;c>m?m=c:0)c+=hypot(X[k]-x/2-X[j]-y*d,Y[k]-y/2-Y[j]+x*d)<1.0001;}main(i){for(;scanf("%d",&N)*N;printf("%d\n",m)){for(i=N;i--;)scanf("%f%f",X+i,Y+i);for(m=1;++i<N;)for(j=i;j--;d<4?C(d=sqrt(1/d-.25)),C(d=-d):0)x=X[i]-X[j],y=Y[i]-Y[j],d=x*x+y*y;}}

Measured memory_bytes: 456
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,k;
ld p[200010],S[200010];

void solve(){
  cin >> n >> k;
  S[0]=0;
  rep(i,n){
    cin >> p[i];
    S[i+1]=S[i]+(p[i]+(ld)1)/(ld)2;
    //cout << S[i+1] << endl;
  }
  ld ma=0;
  rep(i,n-k+1){
    //cout << S[i+k]-S[i] << endl;
    ma=max(ma,S[i+k]-S[i]);
  }
  cout << ma << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}


int main (){
    int n,k;
    ll ans=-inf;
    cin >> n >> k;
    vl v(n);
    rep(i,n) cin >> v[i];
    for(int l=0;l<=k;l++){
        for(int r=0;r<=k;r++){
            if(r+l>k||r+l>n) continue;
            if(l>n||r>n) continue;
            int sute=k-r-l;
            vector<ll>jew;
            if(l!=0)rep(i,l) jew.push_back(v[i]);
            if(r!=0)rep(i,r) jew.push_back(v[n-1-i]);
            sort(jew.begin(),jew.end());
            ll sum=0;
            if(jew.size()!=0){
                rep(i,jew.size()) sum+=jew[i];
                int mn=min(sute,l+r);
                rep(i,mn){
                    if(jew[i]>=0) break;
                    sum-=jew[i];
                }
            }
            ans=max(ans,sum);
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n) {
    int p;
    cin >> p;
    p--;
    mp[p] = i;
  }
  int sum = 0;
  {
    int u = 0;
    while (u < n) {
      int c = 1;
      while (u + 1 < n && mp[u] < mp[u + 1]) {
        c++;
        u++;
      }
      amax(sum, c);
      u++;
    }
  }
  int ans = n - sum;
  cout << ans << endl;
}


Measured memory_bytes: 9600
# C - 白昼夢
def main():
    s = list(input())
    
    while len(s) != 0:
        if ''.join(s[-5:]) == 'dream':
            for _ in range(5):
                s.pop()
        elif ''.join(s[-7:]) == 'dreamer':
            for _ in range(7):
                s.pop()
        elif ''.join(s[-5:]) == 'erase':
            for _ in range(5):
                s.pop()
        elif ''.join(s[-6:]) == 'eraser':
            for _ in range(6):
                s.pop()
        else:
            print('NO')
            exit()
    else:
        print('YES')


if __name__ ==  "__main__":
    main()

Measured memory_bytes: 9900
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
#include <iomanip>
using namespace std;
#define ll long long
#define inf 1000000007

int main(void){
    ll n;
    cin >> n;
    ll p[n+1];
    for(ll i = 0; i < n; i++)
        cin >> p[i];
    p[n] = 0;
    ll count = 0;
    for(ll i = 0; i < n; i++){
        if(p[i] == i+1 && p[i+1] != i+1){
            swap(p[i], p[i+1]);
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<algorithm>
#include<iostream>
#include<numeric>
#include<stdio.h>

int main()
{
	int n;
	char str[9];
	std::cin >> n;
	while( n-- ){
	 	std::cin >> str;
		
		std::sort( str, str + 8, std::greater<int>() );
		int max = atoi( str );
		std::sort( str, str + 8 );
		int min = atoi( str );
		
		std::cout << max - min << std::endl;
	}

 	return 0;
}

Measured memory_bytes: 1192
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

# N 人が 1 列に並んでおり、前から i 番目の人の身長は Ai です。
# それぞれの人の足元に、高さが 0 以上の踏み台を設置し、全ての人が次の条件を満たすようにしたいです。
# 条件：踏み台を込めて身長を比較したとき、自分より前に、自分より背の高い人が存在しない
# この条件を満たす時の、踏み台の高さの合計の最小値を求めてください。

n = I()
a_l = LI()
ans = [0]


for i in range(n-1):
    diff = a_l[i + 1] - a_l[i]
    a = 0
    if diff < 0:
        a_l[i + 1] = a_l[i + 1] + abs(diff)
        a = abs(diff)
    ans.append(a)
print(sum(ans))

Measured memory_bytes: 30560
#include <bits/stdc++.h>
#define COUT(x) cout << #x << " = " << (x) << ", "
typedef long long ll;
using namespace std;
static const ll MOD = 1000000007;

ll N,X,Y;

ll shortPath(ll a, ll b){
  if(b <= X){
    return b - a;
  }
  if(b <= Y && a <= X){
    return min(b - a, Y - b + 1 + X - a);
  }
  if(b <= Y && a > X){
    return min(b - a, Y - b + 1 + a - X);
  }
  if(a <= X){
    return b - Y + 1 + X - a;
  }
  if(a <= Y){
    return min(b - a, a - X + 1 + b - Y);
  }
  return b - a;
}

int main(){
  cin >> N >> X >> Y;
  vector<ll> res(N);
  
  for(ll i = 1; i < N; i++){
    for(ll j = i + 1; j <= N; j++){
      ll tmp = shortPath(i, j);
      res[tmp]++;
    }
  }

  for(int i = 1; i < N; i++){
    cout << res[i] << endl;
  }
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] a) {
    double agv = 1.0 * a.sum / a.length;
    double best = int.max;
    int ans = 0;
    for (int i = 0; i < a.length; i++) {
        double d = abs(agv - a[i]);
        if (d < best) {
            best = d;
            ans = i;
        }
    }
    return ans;
}

void main() {
    readint;
    auto a = readints;
    writeln(calc(a));
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)

using namespace std;
typedef pair<int, int> P;
typedef unsigned long long int ll;

const int INF = 1<<30;
const ll LINF = ll(1e18);
const ll MOD = ll(1e9+7);
vector<ll> cake[] = {vector<ll>(), vector<ll>(), vector<ll>()};
int main(){
  vector<int> lim(3);
  rep(i, 3)cin>>lim[i];
  int K;cin>>K;
  rep(i, 3)cake[i].resize(lim[i]);
  rep(i, 3)rep(j, lim[i])cin>>cake[i][j];
  rep(i, 3)sort(cake[i].begin(), cake[i].end(), greater<ll>());
  vector<ll> ans;
  rep(i, lim[0])rep(j, lim[1])rep(k, lim[2]){
    if((i+1)*(j+1)*(k+1)>K)break;
    ans.push_back(cake[0][i]+cake[1][j]+cake[2][k]);
  }
  sort(ans.begin(), ans.end(), greater<ll>());
  rep(i, K)cout<<ans[i]<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 1404
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	string s[3];
	cin >> s[0] >> s[1] >> s[2];
	int t = 0, cnt[3];
	fill(cnt, cnt+3, 0);

	while(1){
		if(cnt[t]==s[t].length()){
			printf("%c\n", 'A'+t);
			return 0;
		}
		cnt[t]++;
		t=s[t].at(cnt[t]-1)-'a';
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastScanner in = new FastScanner(System.in);
		String s1 = in.nextLine();
		String s2 = in.nextLine();
		if(s2.substring(0, s1.length()).equals(s1)) System.out.println("Yes");
		else System.out.println("No");
	}

}
///////////////////////////////////TEMPLATE///////////////////////////////////
class FastScanner {
	BufferedReader br;
	StringTokenizer st;

	FastScanner(InputStream stream) {
		try {
			br = new BufferedReader(new InputStreamReader(stream));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	FastScanner(File input) {
		try {
			br = new BufferedReader(new FileReader(input));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	String nextLine() {
		String s = "";
		try {
			s = br.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return s;
	}

	String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(next());
	}

	long nextLong() {
		return Long.parseLong(next());
	}

	double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 32420
fun main(args: Array<String>) {


    val n = readLine()!!.toInt()
    val hn = readLine()!!.split(" ").map(String::toInt).toTypedArray()

    var sum = 0
    while (true) {
        val start = hn.indexOfFirst { it != 0 }
        if (start == -1) {
            break
        }

        for (i in start until hn.size) {
            val v = hn[i]
            if (v == 0) {
                break;
                sum++
            }
            hn[i] = v - 1
        }
        sum++
    }
    println(sum)
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> X(M);
  for (int i=0; i<M; i++) {
    cin >> X.at(i);
  }
  sort(X.begin(), X.end());
  int answer;
  if (N >= M) {
    answer = 0;
  }
  else {
    vector<int> L(M-1);
    for (int i=0; i<M-1; i++) {
      L.at(i) = X.at(i+1) - X.at(i);
    }
    sort(L.begin(), L.end());
    reverse(L.begin(), L.end());
    int sum = 0;
    for (int i=0; i<N-1; i++) {
      sum += L.at(i);
    }
    answer = X.at(M-1)-X.at(0)-sum;
  }
  cout << answer << endl;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
n = int(input())
abc = [list(map(int,input().split())) for i in range(n)]
f_min = 0 
dp = [[f_min] * 3 for _ in range(n)]
def chmin(a, b):
    if a > b:
        return b
    else:
        return a
def chmax(a,b):
    if a < b:
        return b
    else:
        return a
def main():
    dp[0][0], dp[0][1], dp[0][2] = abc[0][0], abc[0][1], abc[0][2]
    for i in range(1,n):
            a,b,c = abc[i][0], abc[i][1], abc[i][2]
            dp[i][0] = chmax(dp[i][0], chmax(dp[i-1][1] + a, dp[i-1][2] +a))
            dp[i][1] = chmax(dp[i][1], chmax(dp[i-1][0] + b, dp[i-1][2] +b))
            dp[i][2] = chmax(dp[i][2], chmax(dp[i-1][0] + c, dp[i-1][1] +c))
    print(chmax(dp[n-1][0], chmax(dp[n-1][1],dp[n-1][2])))

if __name__ == "__main__":
    main()

Measured memory_bytes: 47352
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e9
#define INFL          static_cast<lint>(INF)
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
int main()
{
	int n = in();
	int last = in();
	cout << last;
	REPI(i, 1, n)
	{
		int temp = in();
		if (temp != last)
		{
			cout << ' ' << temp;
			last = temp;
		}
	}
	cout << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a, b, p, x=0, y=0, z=0;
	cin>>n>>a>>b;
	REP(i, n){
		cin>>p;
		if(p<=a){
			++x;
		}
		else if(p<=b){
			++y;
		}
		else{
			++z;
		}
	}
	cout<<min({x, y, z})<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  std::vector<pair<string, int>> re(N), ans(N);
  std::vector<pair<int, string>> reg(N);

  for(int i=0;i<N;i++){
    string s;
    int num;
    std::cin >> s >> num;
    reg[i] = make_pair(num, s);
    ans[i] = make_pair(s, num);
  }
  sort(reg.begin(), reg.end());
  reverse(reg.begin(), reg.end());
  for(int i=0;i<N;i++) {
    string s = reg[i].second;
    int num = reg[i].first;
    re[i] = make_pair(s, num);
  }
  sort(re.begin(), re.end());
  string ns = "";
  std::vector<int> aaa;
  for(int i=0;i<N;i++){
    if(ns != re[i].first) {
      if(aaa.size()!=0){
        for(int k=aaa.size()-1;k>=0;k--){
          std::cout << aaa[k] << '\n';
        }
      }
      aaa = std::vector<int> (0);
      ns = re[i].first;
    }
    for(int j=0;j<N;j++){
      if(re[i].first == ans[j].first && re[i].second == ans[j].second){
        aaa.push_back(j+1);
        break;
      }
    }
  }
  if(aaa.size()!=0){
    for(int k=aaa.size()-1;k>=0;k--){
      std::cout << aaa[k] << '\n';
    }
  }
  return 0;
}


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

using namespace std;
typedef long long ll;
#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define repb(i,a,b)         for(ll i=a;i>=b;i--)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define tr(c,it)            for(auto const &it : c)
#define xlr8                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sz(c)               (c).size()
#define all(c)              (c).begin(),(c).end()
#define sl(a)               scanf("%lld",&a);
#define TH                  1000
#define F                   first
#define S                   second
#define pi                  3.14159265359
ll INF=1e18+10;
ll MOD=1e9+7;

const int N=sqrt(1e9);
ll s[101][N+10];
ll b[101][N+10];

int main()
{
    ll n,k;cin>>n>>k;
    ll sqn = sqrt(n);

    mem(s,0);mem(b,0);
    rep(i,1,sqn+1)
    {
        s[1][i]=1;
        b[1][i]=(n/i)-(n/(i+1));
        if(i==(n/i))
            b[1][i]=0;
    }

    for(int i=2;i<=k;i++)
    {
        for(int j=1;j<=sqn;j++)
            s[i-1][j]=(s[i-1][j]+s[i-1][j-1])%MOD;
        for(int j=sqn-1;j>=1;j--)
            b[i-1][j]=(b[i-1][j]+b[i-1][j+1])%MOD;

        for(int j=1;j<=sqn;j++)
        {
            s[i][j]=(s[i-1][sqn]+b[i-1][j])%MOD;
            b[i][j]=(((n/j)-(n/(j+1)))*s[i-1][j])%MOD;
            if(j==(n/j))
            b[i][j]=0;
        }
    }

    ll ans=0;
    for(int i=1;i<=sqn;i++)
    {
        ans+=(s[k][i]);
        ans%=MOD;
        ans+=(b[k][i]);
        ans%=MOD;
    }
    cout<<ans;
}


Measured memory_bytes: 50304
def orderN(N,L,ices):
    upPeak = L - ices[0]
    downPeak = L - ices[0]
    peaks = []
    for i in xrange(len(ices)):
        if i < N-1:
            if ices[i] < ices[i+1]:
                peaks.append(downPeak)
                downPeak = L - ices[i+1]
                upPeak += L - ices[i+1]
            else:
                peaks.append(upPeak)
                upPeak = L - ices[i+1]
                downPeak += L - ices[i+1]
        else:
            peaks.append(upPeak)
            peaks.append(downPeak)
    print(max(peaks))

N,L = map(int,raw_input().strip().split())
ices = [int(raw_input().strip()) for _ in xrange(N)]

orderN(N,L,ices)

Measured memory_bytes: 12636
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int sod(int a) {
    int r = 0;
    while (a) {
        r += a%10;
        a /= 10;
    }
    return r;
}

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

    int n = gi();
    int r = sod(1) + sod(n-1);
    for (int i = 2; i < n; i++) {
        int a = sod(i) + sod(n-i);
        r = MIN(a, r);
    }

    printf("%d\n", r);

    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
lst = list(map(int,input().split()))

loop = []
mark = ['t'] *n
i = 0
loop.append(1)
mark[0] = 0
while True:
  if mark[lst[i]-1] != 't':
    start = mark[lst[i]-1]
    last = mark[i]
    break
  else:
    mark[lst[i]-1] = mark[i] + 1
    loop.append(lst[i])
  i = lst[i]-1
  
  
loop_len = last - start +1
loop_num = loop[start:last+1]
first = start-1

if k <= first:
  print(loop[k])
else:
  q = (k-first) % loop_len
  print(loop_num[q-1])
    
  

Measured memory_bytes: 32296
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int N,M,X;
    cin>>N>>M>>X;
    vector<int> C(N);
    vector<vector<int>> A(N,vector<int>(M));
    rep(i,N){
        cin>>C[i];
  //      cout << C[i] << endl;
        rep(j,M){
            cin>>A[i][j];
        }
    }
    
    bool flag=true;
    int tmp=0;
    int ans =100000000;
    vector<int> Al(M,0);
    //すべての買い方<2^12よりbit全探索
    rep(i,1<<N){
        // cout << "i:" << i << endl;
        tmp=0;
        flag=true;
        rep(j,M){
            Al[j]=0;//初期化
        }

        rep(j,M){
            //買った本のj番目を足す
            rep(k,N){
                if(1<<k&i){
                    // cout << A[k][j] << endl;
                    Al[j]=Al[j]+A[k][j];
                }
            }
        }
        //それぞれの本を買った結果
        //各アルゴリズムがXを超えているか確認
        rep(j,M){
            if(Al[j]<X){
                flag=false;
            }
        }
        // cout << "flag:" <<flag << endl;
        if(flag){
            rep(m,N){
                if(1<<m&i)
                tmp=tmp+C[m];
            }
            ans=min(ans,tmp);
        }
        
    }
    if(ans==100000000){
        cout <<-1<<endl;
        return 0;
    }
    cout << ans << endl;

    return 0;
}

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

const int maxn=3e2+10;
int n,ans;
char s[maxn][maxn];

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;++i)
		scanf("%s",s[i]);
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j)
			for(int k=0;k<n;++k)
				if(s[(j+i)%n][k]!=s[(k+i)%n][j])
					goto gorry;
		ans+=n;
gorry:
		;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
S=gets.chomp
Qn=gets.to_i

ans = S
ans_f = ""
ans_b = ""
reverse_cnt = 0
cnt = 0
Qn.times do |i|
  q=gets.chomp.split
  if q[0] == "1"
    reverse_cnt += 1
  else
    if reverse_cnt % 2 == 0
      if q[1] == "1"
        ans_f = q[2] + ans_f
      else
        ans_b += q[2]
      end
    else
      if q[1] == "1"
        ans_b += q[2]
      else
        ans_f = q[2] + ans_f
      end
    end
  end
  if (i+1) % 10000 == 0
    ans = ans_f + ans + ans_b
    ans.reverse! if reverse_cnt % 2 != 0
    reverse_cnt = 0
    ans_f = ""
    ans_b = ""
  end
end
ans = ans_f + ans + ans_b
ans.reverse! if reverse_cnt % 2 != 0
puts ans

Measured memory_bytes: 9924
n=gets.to_i
hNumbers=gets.split.map(&:to_i)
hNumberLength = hNumbers.length
tempHNumbers=Array.new(hNumberLength,0)
loopCount=0
loop do
  completNumber=0
  growFlag=false
  hNumbers.each_with_index do |value,index|
    if tempHNumbers[index] < value
      tempHNumbers[index] += 1 
      growFlag = true
    elsif tempHNumbers[index] == value
      break if growFlag
      completNumber += 1
    elsif tempHNumbers[index] > value && growFlag
      break
    end
  end
  loopCount += 1
  break if hNumberLength == completNumber
end
puts (loopCount-1)

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = 0;
		int x = 0;
		int max = 0;
		N = scan.nextInt();
		String S = "";
		S = scan.next();
		String T = "";
		
		while (N > 0) {
			T = S.substring(S.length() - N, S.length() - (N - 1));
			if(T.equals("I")) {
				x = x + 1;
				if(max < x) max = x;
			}
			else if(T.equals("D")) {
				x = x - 1;
			}
			N = N - 1;
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n,k;cin>>n>>k;
    vector<ll> w(n);
    rep(i,n) cin>>w[i];

    auto check=[&](int m){
        int need=1;ll sum=0;
        rep(i,n){
            if(w[i]>m) return false;
            if(sum+w[i]>m){
                need++;
                sum=w[i];
            }else{
                sum+=w[i];
            }
        }
        return need<=k;
    };

    int lw=1,hi=INF,ans=INF;
    while(lw<=hi){
        int mid=(lw+hi)/2;
        if(check(mid)){
            hi=mid-1;
            ans=mid;
        }else{
            lw=mid+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b;
	cin >> a >> b;
	int sockets = 1;
	int ans = 0;
	while(sockets < b) {
		sockets--;
		sockets+=a;
		ans++;
	}	
	cout << ans << '\n';
}

Measured memory_bytes: 3572