akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main() {
    int N;
    int W;
    scanf("%d", &N);
    scanf("%d", &W);
    int w[N];
    int v[N];
    long DP[N][W+1]; // [i番目の荷物][重さj以下で最大の価値の最大値]
    for (int i = 0; i < N; i++) {
        scanf("%d", &w[i]);
        scanf("%d", &v[i]);
    }

    // 初期値
    for (int j = 0; j < W + 1; j++) {
        if (j < w[0])
            DP[0][j] = 0;
        else
            DP[0][j] = v[0];
    }

    int max = 0;
    for (int i = 1; i < N; i++) {
        for (int j = 0; j < W + 1; j++) {
            // w[i]がjより大きければ、iは持って帰れない。
            if (j < w[i]) {
                DP[i][j] = DP[i-1][j];
            } else {
            // 持って帰る場合
                DP[i][j] = ((DP[i-1][j - w[i]] + v[i]) > DP[i-1][j]) ? (DP[i-1][j - w[i]] + v[i]) : DP[i-1][j];
            }
        }
    }

    long ans = DP[N-1][W];
    printf("%ld\n", ans);
    return 0;
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define ll long long
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
int main() {
  INIT;
  
  int N;
  cin >> N;
  int p[N];
  REP(i,N){
    cin >> p[i];
  }
  std::vector<int> v(p, p+N);
  //std::vector<int> data(10, 5);      //  要素数10、全ての要素の値5 で初期化
  //std::vector<int> data(123);  //  int 型で、初期要素数 123 の動的配列 data の宣言
  
  int imax = *max_element(v.begin(), v.end());
  int isum =0;
  REP(i,N){
    isum += v[i];
  }
  cout << isum - imax/2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int main() {
    int N, K; cin >> N >> K;
    vector<int> L(N); rep(i, N) cin >> L[i];
    vector<double> a(N);

    rep(i, N) {
        int p = L[i];
        L[i] = (1 + L[i]) * L[i] / 2;
        a[i] = (double)L[i] / p;
    }

    vector<double> ans(N-K+1);
    ans[0] = 0;
    rep(i, K) {
        ans[0] += a[i];
    }
    reps(1, i, N-K+1) {
        ans[i] = ans[i-1]-a[i-1]+a[i-1+K];
    }

    double aa = 0;
    rep(i, N-K+1) {
        aa = max(aa, ans[i]);
    }

    cout << aa << endl;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=55;
const int mod=1e9+7;
char s[2][max_n];
int n;
int main(){
    scanf("%d",&n);
    for(int i=0;i<2;i++)scanf(" %s",s[i]+1);
    ll res=1;
    for(int i=1;i<=n;){
        if(s[0][i]==s[1][i]){
            if(i==1)res=res*3%mod;
            else{
                if(s[0][i-1]==s[1][i-1])res=res*2%mod;
            }
            i++;
        }
        else{
            if(i==1)res=res*6%mod;
            else{
                if(s[0][i-1]==s[1][i-1])res=res*2%mod;
                else res=res*3%mod;
            }
            i+=2;
        }
    }
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = set([int(input()) for i in range(m)])

mod = 10**9 + 7
dp = [0] * (n + 3)
dp[0] = 1
if 1 not in a:
    dp[1] = 1
if 2 not in a:
    dp[2] = dp[0] + dp[1]
for i in range(3, n + 1):
    if i not in a:
        dp[i] = (dp[i - 1] + dp[i - 2]) % mod
print(dp[n] % mod)


Measured memory_bytes: 56792
N = int(input())
A = list(map(int, input().split()))

ans = 1000
k = 0
for i in range(len(A)-1):
    if A[i] < A[i+1] and (ans//A[i]) != 0:
        k = ans // A[i]
        ans = ans % A[i]
        ans += k * A[i+1]
        k = 0
    else:
        continue

print(ans)

Measured memory_bytes: 9132
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

int main(){
	int a=0, b=0, o=0, ab=0;
	int tmp;
	char blood[3];
	while(scanf("%d,%s", &tmp, blood) != EOF){

		if(blood[1]=='B') ab++;
		else if(blood[0]=='A')a++;
		else if(blood[0]=='B')b++;
		else o++;
	}

	cout << a << endl;
	cout << b << endl;
	cout << ab << endl;
	cout << o << endl;
}

Measured memory_bytes: 1208
k, n = list(map(int, input().split()))
a = list(map(int, input().split()))
m = k + a[0] - a[n-1]
# print(m)
for i in range(n-1):
    forw = abs(a[i+1] - a[i])
    m = max(forw, m)
#     print(m)
print(k-m)

Measured memory_bytes: 77772
d = int(input())
c = [0] + list(map(int, input().split(' ')))

s = [[]] + [[0] + list(map(int, input().split(' '))) for _ in range(d)]

t = 0 # 算出結果

ca = [0] * (1 + 26) # 放置された不満の数々
cat = [] # 不満度の最適な算出のための一時配列
dc = 0 # カレントな満足度
#dl = [] # 満足度のログ

for i in range(1, d + 1):
    cat = [c[i2] * (i - ca[i2]) for i2 in range(1, 27)]
    t = cat.index(min(cat)) + 1
    dc += s[i][t]
    ca[t] = i
    dc -= sum(cat)
    print(t)

Measured memory_bytes: 9396
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define ld long double
#define F first
#define S second
//
#define int long long
#define ll long long
#define db(x)                cerr<<#x<<": "<<x<<endl
#define db2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define db3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define db4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define db5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define db6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
//
#define mem(x,y) memset(x,y,sizeof(x))
#define bitcount    __builtin_popcount
//
#define pii pair<int, int>
#define all(v) v.begin(),v.end()
//
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define vi vector<int>
#define vvi vector< vector<int> >
#define si set<int>
#define pb push_back
#define lp(i,a,b) for(int i=a;i<b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)
#define mk make_pair
const int N=2e5+3;
const int mod=1e9+7;
const int mod1=998244353;
const int inf=1e16+7;
using namespace std;

void solve(){
    int s,w;
    cin>>s>>w;
    if(w>=s){
        cout<<"unsafe";
       
    }
     else cout<<"safe";
}
 

int32_t main() {
    IOS;
    int t;
   // cin>>t;
    
    t=1;
    for(int i=1;i<=t;i++){
       // cout<<"Case #"<<i<<": ";
        solve();
        cout<<'\n';
    }
   
}

















Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};

int main(){
    ll X,Y; cin >> X >> Y;
    int cnt=0;
    ll a=X;
    while(a<=Y){
        a*=2;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

if n == 1:
    start = 0
    stop = 9
elif n == 2:
    start = 10
    stop = 99
else:
    start = 100
    stop = 999

ans = -1
for num in range(start, stop + 1):
    no_flag = False
    for i in range(m):
        if str(num)[sc[i][0]-1] != str(sc[i][1]):
            no_flag = True
    if not no_flag:
        ans = num
        break

print(ans)


Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
using namespace std;


int main(void){
    int i,j;
    long long n;
    long long x,m;
    int b[100100];
    long long L1,L2;

    cin >> n >> x >> m;
    x = x%m;
    long long x0=x;
    long long x1;
    for(i=0;i<m;i++){
        b[i] = -1;
    }
    
    int k=0;
    int r;
    long long s=0;
    while(true){
    // cout << "x=" << x << ",b[x]=" << b[x] << endl;
        if(b[x] != -1){
            x1=x;
            r=b[x];
         //cout << "r=" << r << endl;
        };
        if(b[x] != -1)break;
        b[x] = k;
        s = s+x;
     //cout << x << "+" << endl;
        x = x*x%m;
        k++;
    }
    //cout << "s=" << s << endl;
    k=k-r;
    //cout << "k=" << k << endl;
    long long ans=0;

    for(i=0;i<r;i++){
        ans += x0;
        x0 = x0*x0%m;
    }

    s = s - ans;
    //cout << "s=" << s << endl;

    ans += s * ((n-r)/k);

    long long d = (n-r)%k;
    //cout << "d=" << d << endl;
    for(i=0;i<d;i++){
        ans += x1;
        x1 = x1*x1%m;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4008
namespace Coder {
  class Scanner {
    private buffer: string = '';
    private stdinQueue: any = [];

    constructor() {
      process.stdin.resume();
      process.stdin.setEncoding('utf8');
      process.stdin.on(
        'data',
        (chunk): void => {
          this.buffer += chunk;
          while (this.stdinQueue.length > 0) {
            const i = this.buffer.indexOf('\n');
            if (i < 0) {
              break;
            }
            let line = this.buffer.substr(0, i);
            if (line.endsWith('\r')) {
              line = line.slice(0, -1);
            }
            this.buffer = this.buffer.substr(i + 1);
            this.stdinQueue.shift()(line);
          }
        },
      );
    }
    public getLine(): Promise<string> {
      return new Promise((resolve, reject) => {
        const i = this.buffer.indexOf('\n');
        if (i >= 0 && this.stdinQueue.length === 0) {
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          resolve(line);
        } else {
          this.stdinQueue.push(resolve);
        }
      });
    }

    public async getNumbers(): Promise<number[]> {
      return (await this.getLine()).split(' ').map((x) => +x);
    }

    public async getStrings(): Promise<string[]> {
      return (await this.getLine()).split(' ');
    }

    public close(): void {
      process.stdin.pause();
    }
  }

  async function solve() {
    const sc = new Scanner();
    const N = (await sc.getStrings())[0];
    let S = (await sc.getStrings())[0];
    const K = (await sc.getNumbers())[0];

    const regex = new RegExp(`[^${S[K - 1]}*]`);

    while (S.match(regex) !== null) {
      S = S.replace(regex, '*');
    }
    console.log(S);

    sc.close();
  }

  solve();
}


Measured memory_bytes: 7500
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <bitset>
#include <utility>
#include <sstream>
#include <fstream>
#include <stack>
#include <cstdlib>
#include <complex>
#include <set>
#include <iomanip>

using namespace std;

#define INF 1070000000LL
#define pb push_back
#define irep(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) irep(i,0,n)

typedef long long lint;
typedef pair<int, int> pint;
typedef vector<vector<pint> > Graph;


int main(){
    int n,k;
    cin >> n >> k;
    double result = 0.0;
    rep(i,n){
	if(k <= i+1){
	    result += 1;
	    continue;
	}
	else{
	    double tmp = (double)k/(i+1);
	    int rp = ceil(log2(tmp));
	    result += pow(0.5,rp);
	}
    }
    result /= (double)n;
    cout << setprecision(9) << result << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;


int main(){
	string s;
	std::cin >> s;
	int le=s.size();
	int ans=0;
	rep(i,le){
		if(s[i]=='A'){
			for (int j = i; j < le; j++) {
				if(s[j]=='Z'){
					int l=j-i+1;
					if(l>ans)ans=l;
				}
				/* code */
			}
			std::cout << ans << std::endl;
			exit(0);
		}
	}
	
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

namespace ALDS1_8A{
    public class Program{
        public static void Main(string[] args){
            var N = int.Parse(Console.ReadLine());
            var tree = new Tree();

            for(var i = 0; i < N; i++){
                var rl = Console.ReadLine().Split(' ');
                if(rl[0] == "insert"){
                    tree.Add(int.Parse(rl[1]));
                }
                if(rl[0] == "print"){
                    Console.WriteLine(" " + string.Join(" ", tree.Order(TreeWalk.InOrder).Select(n => n.Id.ToString()).ToArray()));
                    Console.WriteLine(" " + string.Join(" ", tree.Order(TreeWalk.PreOrder).Select(n => n.Id.ToString()).ToArray()));
                }
            }
        }
    }

    public enum TreeWalk{
        PreOrder,
        InOrder,
        PostOrder
    }

    public class Tree{
        public Dictionary<int, Node> Nodes = new Dictionary<int, Node>();
        public Node Root;

        public void Add(int id){
            Nodes.Add(id, new Node(id));

            if(Root == null){
                Root = Nodes[id];
                return;
            }

            var end = false;
            Action<Node> insert = null;
            insert = n =>{
                if(end) return;

                if(n.Id > id){
                    if(n.Left == null){
                        n.Left = Nodes[id];
                        Nodes[id].Parent = n.Left;
                    } else{
                        insert(n.Left);
                        end = true;
                    }
                }

                if(n.Id < id){
                    if(n.Right == null){
                        n.Right = Nodes[id];
                        Nodes[id].Parent = n.Right;
                    } else{
                        insert(n.Right);
                        end = true;
                    }
                }
            };

            insert(Root);
        }

        public List<Node> Order(TreeWalk tw){
            var res = new List<Node>();

            Action<Node> parse = null;
            parse = node =>{
                if(node == null) return;

                if(tw == TreeWalk.PreOrder) res.Add(node);
                parse(node.Left);
                if(tw == TreeWalk.InOrder) res.Add(node);
                parse(node.Right);
                if(tw == TreeWalk.PostOrder) res.Add(node);
            };
            parse(Nodes.Single(n => n.Value.Parent == null).Value);

            return res;
        }
    }

    public class Node{
        public int Id;
        public Node Parent;
        public Node Left;
        public Node Right;

        public Node(int id){
            Id = id;
        }
    }
}

Measured memory_bytes: 103304
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int x[105];
signed main(void)
{
  int n, k;
  cin >> n >> k;
  REP(i, n) cin >> x[i];

  int ret = 0;
  REP(i, n) ret += min(x[i], k-x[i])*2;
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void){
  int N;
  scanf("%d",&N);
  int a[N];
  long int sum=0;
  for(int i=0;i<N;i++){
    if((i+1)%3==0||(i+1)%5==0){
      a[i]=0;
    }else{
      a[i]=i+1;
    }
    sum+=a[i];
  }
  printf("%ld",sum);
  return 0;
}

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

struct edge{
    int to;
    int cost;
    edge(int a, int b){
        to=a;
        cost=b;
    }
};
typedef pair<long long, int> P;

int n;
vector<edge> g[100008];
long long d[100008],INF=1000000000000000000;

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> q;
    fill(d,d+n+1,INF);
    d[s]=0;
    q.push(P(0,s));
    while(!q.empty()){
        P p=q.top();
        q.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int 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;
                q.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(void){
    int q,k;
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b,c;
        cin>>a>>b>>c;
        g[a].push_back(edge(b,c));
        g[b].push_back(edge(a,c));
    }
    cin>>q>>k;
    dijkstra(k);
    for(int i=0;i<q;i++){
        int x,y;
        cin>>x>>y;
        cout<<d[x]+d[y]<<endl;
    }
}


Measured memory_bytes: 9460
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

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

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class DShiftAndFlip {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      string a, b; cin >> a >> b;
      int n = a.size();
      bool bnotempty = false;
      bool anotempty = false;
      for(auto c: a) {
        if (c == '1') anotempty = true;
      }
      for(auto c: b) {
        if (c == '1') bnotempty = true;
      }
      if (!anotempty && !bnotempty) {
        cout << 0 << endl;
        return;
      }
      if (anotempty && !bnotempty) {
        cout << -1 << endl;
        return;
      }

      vector<int> left(n), right(n);
      for(int i=0; i<n; i++) {
        if (a[i] == '0') {
          left[i] = -1;
          right[i] = -1;
          continue;
        }
        int now = 0;
        while(b[(i-now+n)%n] != '1') {
          now++;
        }
        left[i] = now;
        now = 0;
        while(b[(i+now)%n] != '1') {
          now++;
        }
        right[i] = now;
      }

      int ret = INT_MAX/2;
      // turn left
      for(int i=0; i<n; i++) {
        int now = i;
        vector<int> v(n);
        for(int j=0; j<n; j++) {
          if (a[j] != b[(j-i+n)%n]) {
            now++;
            if (i < left[j]) chmax(v[left[j]-i], right[j]);
          }
        }
        int penalty = INT_MAX/2;
        int maxy = 0;
        for(int j=n-1; j>=0; j--) {
          chmin(penalty, j+maxy);
          chmax(maxy, v[j]);
        }
        now += penalty*2;
        chmin(ret, now);
      }
      // turn right
      for(int i=0; i<n; i++) {
        int now = i;
        vector<int> v(n);
        for(int j=0; j<n; j++) {
          if (a[j] != b[(j+i+n)%n]) {
            now++;
            if (i < right[j]) chmax(v[right[j]-i], left[j]);
          }
        }
        int penalty = INT_MAX/2;
        int maxy = 0;
        for(int j=n-1; j>=0; j--) {
          chmin(penalty, j+maxy);
          chmax(maxy, v[j]);
        }
        now += penalty*2;
        chmin(ret, now);
      }
      cout << ret << endl;
    }
};

signed main() {
  DShiftAndFlip solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine().trim());
        if(t>=30){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }


    }
}


Measured memory_bytes: 32512
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int h, w, n; cin >> h >> w >> n;
	vector<int> a(n); rep(i, 0, n - 1)cin >> a[i];
	vector<int> b;
	rep(i, 0, n - 1)
	{
		rep(j, 1, a[i])
		{
			b.push_back(i + 1);
		}
	}
	vector<vector<int>> ans(h, vector<int>(w));
	int cnt = 0;
	rep(i, 0, h - 1)
	{
		rep(j, 0, w - 1)
		{
			int x;
			if (i % 2 == 0)x = j;
			else x = w - 1 - j;
			ans[i][x] = b[cnt];
			++cnt;
		}
	}
	rep(i, 0, h - 1)
	{
		rep(j, 0, w - 1)
		{
			cout << ans[i][j] << " ";
		}
		cout << "" << endl;
	}
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 2010
ll po(ll x,ll y){
	if(y<0)return 1;
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
ll inv(ll x){
	return po(x,mod-2);
}
ll fac[2*N],ivf[2*N];
ll C(ll n,ll k){
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
ll H(ll n,ll k){
	return C(n+k,n);
}

ll dp[N][N];
void init(){
	fac[0]=ivf[0]=1;
	for(ll i=1;i<2*N;i++){
		fac[i]=fac[i-1]*i%mod;
		ivf[i]=ivf[i-1]*inv(i)%mod;
	}
	
	rep(i,N)dp[1][i]=0;
	dp[1][0]=1;
	for(int i=2;i<N;i++){
		ll rui=0;
		for(int j=0;j<i;j++){
			mad(rui,dp[i-1][j]);
			dp[i][j]=rui;
		}
		for(int j=i;j<N;j++){
			dp[i][j]=0;
		}
	}
}

int main(){
	init();
	ll n,k; cin>>n>>k;
	ll ans=0;
	if(k==1)ans=1;
	else{
		for(int p=0;p<k-1;p++){
			ll res=H(k-1-p,n-k)*dp[k-1][p]%mod;
			mad(ans,res);
		}
	}
	ans=ans*po(2,n-k-1)%mod;
	cout<<ans<<endl;
}





Measured memory_bytes: 31872
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, m,n) for (int i = m; i < (int)(n); i++)
int main(){
  int ans=0;
int N,M; cin>>N>>M; vector<int>H(N); vector<int>G(N);
  rep(i,N){cin>>H.at(i);}
  
rep(i,M){int A,B; cin>>A>>B; 
        if(H.at(A-1)>H.at(B-1)){G.at(B-1)=1;}
         else if(H.at(A-1)<H.at(B-1)){G.at(A-1)=1;}
         else{G.at(B-1)=1; G.at(A-1)=1;}
        }
  rep(i,N){if(G.at(i)==0){ans++;}
          else{continue;}}
  cout<<ans<<endl;
}

Measured memory_bytes: 4060
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n, m, k = LI()
    a = LI()
    b = LI()
    a = list(itertools.accumulate(a))
    b = list(itertools.accumulate(b))
    ans = bisect_right(a, k)
    for i, bi in enumerate(b, start=1):
        if bi > k:
            break
        ans = max(ans, i + bisect_right(a, k - bi))
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 147456
package main 
import (
        "fmt"
        "unicode/utf8"
        "strconv"
)

func main () {
        var s string 
        var a int
        fmt.Scan(&s)
        a = utf8.RuneCountInString(s)
        b := a -1
        ko := s[1:b]
        c := s[0:1]
        d :=s[b:a]
        x := utf8.RuneCountInString(ko)
        k := strconv.Itoa(x)
        fmt.Println(c+k+d)
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void){

int a, b, c, i, s ;

s=0;

scanf("%d %d %d", &a, &b, &c);

for(i= a ; i<= b ; i ++)

{

if(c%i == 0){

s=s+1;

}

}

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

return 0;

}

Measured memory_bytes: 596
/*****************************
Filename: dkljlkfd.cpp
Author: hbb
Create: 2020-04-05 13:36:56
 *****************************/
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = INT_MAX >> 1;
typedef long long int LL;

LL n, k;
LL a[maxn];

int main(){
	scanf("%lld %lld", &k, &n);
	for(int i = 1; i <= n; i++){
		scanf("%lld", &a[i]);
	}
	sort(a + 1, a + 1 + n);
	LL ans = a[1] + (k - a[n]);
	LL m = ans;
	for(int i = 2; i <= n; i++){
		ans += (a[i] - a[i - 1]);
		m = max(a[i] - a[i - 1], m);
	}
	printf("%lld\n", ans - m);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n >> q;
  vector<priority_queue<int>> S(n);
  while (q--) {
    int op, t;
    cin >> op >> t;
    if (op == 0) {
      int x;
      cin >> x;
      S[t].push(x);
    } else if (op == 1) {
      if (S[t].size()) cout << S[t].top() << endl;
    } else if (op == 2) {
      if (S[t].size()) S[t].pop();
    }
  }

  return 0;
}


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

int main(int argc, const char * argv[]) {
    string S;
    cin >> S;
    
    size_t size = S.size();
    int count = 0;
    for (int i = 0; i < size/2; i++) {
        if (S[i] != S[size - 1 - i]) {
            count++;
        }
    }
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 760
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>

//#define PI 3.141592653589

using namespace std;



int main()
{
	int n;
	int ice[10];
	int type;
	
	while (1)
	{
		cin >> n;
		if (n == 0) break;
		
		for (int i=0; i<10; i++) ice[i] = 0;
		for (int i=0; i<n; i++)
		{
			cin >> type;
			ice[type]++;
		}
		for (int i=0; i<10; i++)
		{
			if (ice[i] == 0)
			{
				cout << "-";
			} else {
				for (int j=0; j<ice[i]; j++)
				{
					cout << "*";
				}
			}
			cout << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll=long long;
 
vector<ll> t[200005];
vector<ll> v(200005,0);
 
void dfs(ll i,ll j){
  for(int k:t[i]){
    if(k==j) continue;
    v[k]+=v[i];
    dfs(k,i);
  }
}
 
int main(){
  int N,Q,A,B,P,X; cin>>N>>Q;
  
  REP(i,N-1){
    cin>>A>>B;
    t[A].push_back(B);
    t[B].push_back(A);
  }
  
  REP(i,Q){
    cin>>P>>X;
    v[P]+=X;
  }
  
  dfs(1,0);
  REP(i,N) cout<<v[i+1]<<" ";
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> A(M);
  REP(i, M) cin >> A[i];
  int ans1 = 0;
  for(int i = X; i < N; i++) {
    for(int j = 0; j < M; j++) {
      if(i == A[j]) ans1++;
    }
  }
  int ans2 = 0;
  for(int i = X; i > 0; i--) {
    for(int j = 0; j < M; j++) {
      if(i == A[j]) ans2++;
    }
  }
  cout << min(ans1, ans2) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int a,b,c;
		cin>>a>>b>>c;
		if(pow(a,2)+pow(b,2)==pow(c,2)){
			cout<<"YES"<<endl;
		}else if(pow(b,2)+pow(c,2)==pow(a,2)){
			cout<<"YES"<<endl;
		}else if(pow(a,2)+pow(c,2)==pow(b,2)){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
}

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

typedef pair<int, int> pint;

int K, X, Y;
bool xflip, yflip, xyswap;
vector<pint> def;
void pushdef(int x, int y) {
    if (xyswap) { swap(x, y); }
    if (xflip) { x *= -1; }
    if (yflip) { y *= -1; }
    def.push_back(pint(x, y));
}
signed main() {
    cin >> K >> X >> Y;
    if (X < 0) { xflip = true, X *= -1; }
    if (Y < 0) { yflip = true, Y *= -1; }
    if (X > Y) { xyswap = true, swap(X, Y); }
    if (X + Y & 1 && ~K & 1) {
        cout << -1 << endl;
        return 0;
    }
    if (X + Y < K && X + Y & 1) {
        pushdef(X, -K + X);
        pushdef((K + X - Y) / 2, K - (K + X - Y) / 2);
        pushdef(-(K + X - Y) / 2, K - (K + X - Y) / 2);
    } else {
        int tarx, tary;
        if (X + Y < K || K & 1 && ((X + Y) / K & 1) == (X + Y & 1)) {
            int U = X + Y, V = -X + Y;
            int u = U - U % K + K, v = V - K;
            tarx = (u - v) / 2, tary = (u + v) / 2;
        } else {
            int U = X + Y, V = -X + Y;
            int u = U - U % K, v = V - K;
            tarx = (u - v) / 2, tary = (u + v) / 2;
        }
        if ((X + Y) % K != 0) { pushdef(X - tarx, Y - tary), X = tarx, Y = tary; }
        for (int i = 0; i < X / K; i++) { pushdef(K, 0); }
        for (int i = 0; i < Y / K; i++) { pushdef(0, K); }
        if (X % K != 0) { pushdef(X % K, Y % K); }
    }
    cout << def.size() << endl;
    int x = 0, y = 0;
    for (int i = 0; i < def.size(); i++) { x += def[i].first, y += def[i].second, cout << x << " " << y << endl; }
}


Measured memory_bytes: 3952
n, k = input().split()
d = list(map(int, input().split()))

a = []

for i in range(10):
    if i not in d:
        a.append(i)

n = list(map(int, list(n)))

for i in range(len(n)):
    if n[i] in d:
        ind = i

        done = False
        while not done:
            for j in range(n[ind]+1, 10):
                if j in a:
                    n[ind] = j
                    done = True
                    break

            if not done:
                ind -= 1

                if ind < 0:
                    n.insert(0, a[1] if a[0] == 0 else a[0])
                    ind = 0
                    done = True

        for j in range(ind+1, len(n)):
            n[j] = a[0]

        break

print("".join(list(map(str, n))))

Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    int n;
    cin >> n;
    vector<int> a(n),l(n),r(n);
    rep(i,n) cin >> a[i];
    l[0]=a[0];
    rep(i,n-1){
        l[i+1] = __gcd(l[i],a[i+1]);
    }   
    r[0]=a[n-1];
    rep(i,n-1){
        r[i+1] =  __gcd(r[i],a[n-2-i]);
    }
    int ans = max(l[n-2],r[n-2]);
    for(int i=1; i<=n-2; i++){
        int now;
        now = __gcd(l[i-1],r[n-i-2]);
        ans = max(ans,now);
    }
    cans;
    return 0;
}

Measured memory_bytes: 4576
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
typedef complex<double> cd; 
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define all(v) v.begin(),v.end()
#define pb(v) push_back(v)
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define rev(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b)
{
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s)
{
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
void pv(mv v)
{
	forl(i,v.size())
	{
		cout<<v[i]<<" ";
	}
	cout<<"\n";
}
void pa(ll *v,ll size)
{
	forl(i,size)
	{
		cout<<v[i]<<" ";
	}
	cout<<"\n";
}
// ll nck(ll N,ll K,ll mod)
// {
// 	if(N<K)
// 	{
// 		return 0;
// 	}
// 	return (((facs[N]*facsinv[N-K])%mod)*facsinv[K])%mod;
// }
ll power(ll x,ll y,ll p)
{
	ll res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		{
			res=(res*x)%p;
		}
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x,ll mod)
{
	if(x>=mod)
	{
		x%=mod;
	}
}
ll sumofgp(ll a,ll n,ll m)
{
	// n = number of terms - 1
	if(n<0)
	{
		return 0;
	}
	if(n==0)
	{
		return 1;
	}
	if(n==1)
	{
		return (1+a)%m;
	}
	ll ans;
	if(n%2)
	{
        ans=(1+a)*sumofgp((a*a)%m,(n-1)/2,m);
	}
    else
    {
        ans=1+((a*(1+a))%m)*sumofgp((a*a)%m,n/2-1,m);
    }
    return ans%m;
}
ll power_of_2_not_less(ll n)
{
	if(!n)
	{
		return 1;
	}
	n--;
	n |= n>>1;
	n |= n>>2;
	n |= n>>4;
	n |= n>>8;
	n |= n>>16;
	n |= n>>32;
	n++;
	return n;
}
// void checktime()
// {
// 	struct timespec ts;
// 	printf("Running Program\n");
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double st=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	// Call Funcn Here
// 	clock_gettime(CLOCK_MONOTONIC_RAW,&ts);
// 	long double en=ts.tv_nsec/(1e9)+ts.tv_sec;
// 	printf("Program ended\nTime = %Lf\n",en-st);
// }
int main(void)
{
	fastio
	string s;
	cin>>s;
	if(s[2] == s[3] && s[4] == s[5])
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int sign(int n){
	return (n>0)-(n<0);
}
int main(){
	int N;
	int flag=1;
	int X[1001],Y[1001];
	int distmod;
	int distmax=0;
	char MC[4]={'D','L','U','R'};
	string w[1001];
	vll d;
	scan(N);
	rep(i,N){
		scan(X[i]);scan(Y[i]);
		if(i==0) distmod=(abs(X[i])+abs(Y[i]))%2;
		else{
			if(distmod!=(abs(X[i])+abs(Y[i]))%2) flag=0;
		}
		distmax=max(distmax,abs(X[i])+abs(Y[i]));
	}
	if(flag==0) prin("-1");
	/*else if(flag&&distmax<=40){
		int m=distmax;
		if(m==0) m=2;
		prin(m);
		rep(i,m) printf("%d ",1);
		kaigyo;
		rep(i,N){
			int dist=abs(X[i])+abs(Y[i]);
			rep(xa,abs(X[i])){
				if(X[i]>0) printf("R");
				else printf("L");
			}
			rep(ya,abs(Y[i])){
				if(Y[i]>0) printf("U");
				else printf("D");
			}
			rep(k,(m-dist)/2){
				printf("LR");
			}
			kaigyo;
		}
	}*/
	else{
		int m;
		if(distmod==0) m=33;
		else m=32;
		prin(m);
		for(int i=31;i>=0;i--){
			printf("%lld ",1LL<<i);
		}
		if(distmod==0) printf("1");
		kaigyo;
		rep(i,N){
			ll x=X[i],y=Y[i];
			for(int j=31;j>=0;j--){
				if(x+y>0&&x-y>0){
					printf("R");
					x-=(1LL<<j);
				}
				else if(x+y>0&&x-y<=0){
					printf("U");
					y-=(1LL<<j);
				}
				else if(x+y<=0&&x-y>0){
					printf("D");
					y+=(1LL<<j);
				}
				else if(x+y<=0&&x-y<=0){
					printf("L");
					x+=(1LL<<j);
				}
			}
			if(distmod==0){
				printf("%c",MC[(x+1)*(y+2)-1]);
			}
			kaigyo;
		}
	}
	return 0;
}


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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

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

    string S;
    cin >> S;

    if(S.size() <= K) cout << S << endl;
    else
    {
        for(int i=0;i<K;i++)
        {
            cout << S[i];
        }
        cout << "..." << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func rs() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	input := rs()
	abcd := make([]int, 4)
	for i := 0; i < 4; i++ {
		abcd[i] = int(input[i] - '0')
	}

	for x := 0; x < 8; x++ {
		var sum = abcd[0]
		var s = string('0' + abcd[0])
		for i := 0; i < 3; i++ {
			switch (x >> uint(i)) & 1 {
			case 1:
				sum += abcd[i+1]
				s = s + "+" + string(abcd[i+1]+'0')
			case 0:
				sum -= abcd[i+1]
				s = s + "-" + string(abcd[i+1]+'0')
			}
		}

		if sum == 7 {
			s += "=7"
			fmt.Println(s)
			return
		}
	}
}


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;		
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b) 
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

int main()
{
	long n;
	cin >> n;
	ll min = max;
	bool m = false;
	ll sum = 0;
	for (long i = 0; i < n; i++)
	{
		ll in;
		cin >> in;
		if (in < 0)
		{
			in *= -1;
			m = !m;
		}

		if (in < min)
			min = in;
		sum += in;
	}

	if (m)
		sum -= min * 2;

	printf("%lld", sum);

	return 0;
}


Measured memory_bytes: 632
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
  int a[4];
  cin >> a[1] >> a[2] >> a[3];
  sort(a+1, a+4);
  cout << a[3] - a[1];
    return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "100" ].parse.expand.solve == "ABC100" );
	assert( [ "425" ].parse.expand.solve == "ABC425" );
	assert( [ "999" ].parse.expand.solve == "ABC999" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip;
	return tuple( n );
}

auto solve( string n )
{
	return "ABC" ~ n;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
ModNum = (10**9)+7

def main():
    N,K = map(int,input().split())
    A = [int(a) for a in input().split()]
    inversion_in_L = [0]*N
    inversion_in_R = [0]*N
    for i in range(N):
        for j in range(N):
            if j<i and A[j]>A[i]:
                inversion_in_L[i] += 1
            elif i<j and A[j]>A[i]:
                inversion_in_R[i] += 1
    ans = 0
    for i in range(N):
        ans += (K-1)*K*inversion_in_R[i]//2
        ans %= ModNum
        ans += (K+1)*K*inversion_in_L[i]//2
        ans %= ModNum

    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 40560
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	ll a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	ll mx = max(x,y);
	ll mn = 1000000000000000LL;
	rep(i,0,mx+1){
		ll x1 = x;
		ll y1 = y;
		ll a1 = 0;
		a1 += i*(c*2);
		x1 -= i;
		y1 -= i;
		if(x1>0){
			a1 += x1*a;
		}
		if(y1>0){
			a1 += y1*b;
		}
		mn = min(mn,a1);
	}
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 256
n,a,b,c,d=map(int,input().split())
s=input()
if c<d:
    print("No" if "##" in s[a-1:d] else "Yes")
else:
    print("Yes" if "##" not in s[a-1:c] and "..." in s[b-2:d+1] else "No")

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

int n, m;
vector<int> a;

void abc105d() {
  vector<ll> s(n);
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      s[i] = a[i];
    } else {
      s[i] = s[i - 1] + a[i];
    }
  }

  map<ll, ll> mp;
  for (int i = 0; i < n; i++) {
    mp[s[i] % m]++;
  }

  ll ans = 0;
  for (auto p : mp) {
    ll tmp1 = p.first;
    ll tmp2 = p.second;
    if (tmp1 == 0) {
      ans += tmp2;
    }
    if (tmp2 >= 2) {
      ans += tmp2 * (tmp2 - 1) / 2;
    }
  }
  cout << ans << '\n';
  return;
}

int main() {
  cin >> n >> m;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  abc105d();
  return 0;
}

Measured memory_bytes: 5376
s = int(input())
ans = [s]

for i in range(10**5):
    if s % 2 == 0:
        s //= 2
        ans.append(s)
    else:
        s = 3*s + 1
        ans.append(s)

check = []

for i in range(len(ans)):
    if ans[i] not in check:
        check.append(ans[i])
    else:
        print(i+1)
        break


Measured memory_bytes: 3860
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int n,m;
char s[100][11], t[100][11];
int num=0;
int max1=-150, max2=-150, maxnum1, maxnum2;

int main(void){
	scanf("%d", &n);
  	for(int i=0;i<n;i++)	scanf("%s", s[i]);
	scanf("%d", &m);
  	for(int i=0;i<m;i++)	scanf("%s", t[i]);

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(strcmp(s[i], s[j])==0)	num++;			
		}
		for(int j=0;j<m;j++){
			if(strcmp(s[i], t[j])==0)	num--;
		}
		if(num>max1){
			max1 = num;
			maxnum1 = i;
		}
		num=0;
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			if(strcmp(t[i], s[j])==0)	num++;			
		}
		for(int j=0;j<m;j++){
			if(strcmp(t[i], t[j])==0)	num--;
		}
		if(num>max2){
			max2 = num;
			maxnum2 = i;
		}
		num=0;
	}

	if(max1<0 && max2<0)	printf("0");
	else if(max1 > max2)	printf("%d", max1);
	else	printf("%d", max2);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
	int r,D,x2000;
	cin >> r >> D >> x2000;
	int ans = x2000;
	for (int i = 0; i < 10; ++i)
	{
		ans = r * ans - D;
		cout << ans << endl;
	}
	return 0;
}

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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

vector< pair<i64, i64> > res;
i64 x;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    res.eb(mp(-1, -1));
    for (i64 i = -2;; --i) {
        i64 temp = i*i*i*i*i;
        if (temp < -(i64)1e15) break;
        res.eb(mp(temp, i));
    }
    res.eb(mp(0, 0));
    res.eb(mp(1, 1));
    for (i64 i = 2;; ++i) {
        i64 temp = i*i*i*i*i;
        if (temp > (i64)1e15) {
            break;
        }
        res.eb(mp(temp, i));
    }
    //cout << SZ(res) << endl;
    cin >> x;
    for (int i = 0; i < SZ(res); ++i) {
        for (int j = 0; j < SZ(res); ++j) {
            if (res[i].fi - res[j].fi == x) {
                cout << res[i].se << ' ' << res[j].se << '\n';
                return 0;
            }
        }
    }

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

int main(void){
  vector<int> v;
  int num=0;
  for (int i=0; i<2; i++){
    int n; cin >> n;
    num += n;
    for (int j=0; j<n; j++){
      int h,m;
      cin >> h >> m;
      v.push_back(h*100+m);
    }
  }
  sort(v.begin(), v.end());
  printf("%d:%02d", v[0]/100, v[0]%100);
  for (int i=1; i<num; i++){
    if (v[i]==v[i-1]) continue;
    printf(" %d:%02d", v[i]/100, v[i]%100);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3276