akhauriyash/Code-Regression huggingface dataset:
// ABC067B - 

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

typedef unsigned long long int ull;
typedef long long int ll;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> l(N);
	for (int i = 0; i < N; i++) {
		cin >> l[i];
	}
	sort(l.begin(), l.end(), greater<int>());

	int sum = 0;
	for (int i = 0; i < K; i++) {
		sum += l[i];
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
  i64 X,Y;
  cin >> X >> Y;
  int cnt = 1;
  while(X * 2 <= Y){
    X *=2;
    cnt++;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
N = int(input())
A = input().split()
l=list()
for i in range(N):
    A[i] = int(A[i])
    if A[i] % 2 == 1:
        l.append(0)
        break
    else:
        for j in range(30):
            A[i] = A[i] / 2
            if A[i] % 2 == 1:
                l.append(j+1)
                break
print(min(l))

Measured memory_bytes: 65848
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 1e3 + 10,Bit = 35;

struct node {
	int x,y;
}Pos[N];
char Opt[N][Bit];
int n,cnt,Val[Bit];

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

inline void Work(int val) {
	int id = ++cnt;
	For(i,1,n) {
		if(abs(Pos[i].x) > abs(Pos[i].y)) {
			if(Pos[i].x > 0) {
				Pos[i].x -= val;
				Opt[i][id] = 'R';
			} else {
				Pos[i].x += val;
				Opt[i][id] = 'L';
			}
		} else {
			if(Pos[i].y > 0) {
				Pos[i].y -= val;
				Opt[i][id] = 'U';
			} else {
				Pos[i].y += val;
				Opt[i][id] = 'D';
			}
		}
	}
}

int main() {

	n = read();int val = -1,tot = 0;
	For(i,1,n) {
		Pos[i].x = read(),Pos[i].y = read();
		if(val < 0) val = (Pos[i].x + Pos[i].y) & 1;
		else if(((Pos[i].x + Pos[i].y) & 1) != val) return puts("-1"),0;
	}
	Fordown(i,30,0) Work(1 << i),Val[++tot] = 1 << i;
	if(!val) Work(1),Val[++tot] = 1;
	printf("%d\n",tot);
	For(i,1,tot) printf("%d%c",Val[i],i == iend ? '\n' : ' ');
	For(i,1,n) {
		For(j,1,tot) printf("%c",Opt[i][j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, p, Ce = 0, Co = 0;
    cin >> n >> p;
    vi a(n);
    map<ll, ll> cnt;
    rep(i, n){
        cin >> a[i];
        cnt[a[i]%2]++;
    }
    Ce = pow(2LL, cnt[0]);
    Co = pow(2LL, n-1);
    // 全部偶数の場合
    if(cnt[0] == n) cout << (!p ? Ce : 0) << endl;
    // 奇数が存在する場合
    else cout << Co << endl;
}

Measured memory_bytes: 4048
let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let solve n q =
  let a = Array.init n (fun i -> (i, 0)) in
  let rec find_set x =
    if x <> fst a.(x) then a.(x) <- (find_set (fst a.(x)), snd a.(x));
    fst a.(x) in
  let link x y =
    if snd a.(x) > snd a.(y) then a.(y) <- (x, snd a.(y))
    else begin
      a.(x) <- (y, snd a.(x));
      if snd a.(x) = snd a.(y) then a.(y) <- (fst a.(y), snd a.(y) + 1)
    end in
  let unite x y = link (find_set x) (find_set y) in
  let same_p x y = find_set x = find_set y in
  let rec doit i =
    if i < q then begin
      begin match List.map int_of_string (split (read_line ()) ' ') with
      | 0 :: x :: y :: _ -> unite x y
      | 1 :: x :: y :: _ -> print_endline (if same_p x y then "1" else "0")
      | _ -> ()
      end;
      doit (i + 1)
    end in
  doit 0

let () =
  match List.map int_of_string (split (read_line ()) ' ') with
  | [n; q] -> solve n q
  | _ -> ()

Measured memory_bytes: 6740
#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;

#define INF ((i64)(1e18))
#define MOD ((i64)(1e9+7))
#define REP(i, n) for(i64 i = 0; i < (n); i++)
#define RREP(i, n) for(i64 i = (n)-1; i >= 0; i--)
#define RANGE(i, a, b) for(i64 i = (a); i < (b); i++)
#define RRANGE(i, a, b) for(i64 i = (b)-1; i >= (a); i--)
#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) ((i64)(v).size())
template<class T> inline void chmax(T &a, const T &b) { if (a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if (a > b) a = b; }

int main() {
  i64 n;
  cin >> n;
  string x;
  cin >> x;
  reverse(ALL(x));
  i64 c = 0;
  REP(i, n) if (x[i] == '1') c++;
  vector<i64> mod0(n, 0), mod1(n, 0);
  i64 c0 = c+1, c1 = c-1;
  i64 tmp0 = 1, tmp1 = 1;
  REP(i, n) {
    if (c0 > 0) {
      mod0[i] = tmp0%c0;
      tmp0 = (tmp0*2)%c0;
    }
    if (c1 > 0) {
      mod1[i] = tmp1%c1;
      tmp1 = (tmp1*2)%c1;
    }
  }

  i64 origin0 = 0, origin1 = 0;
  REP(i, n) {
    if (x[i] == '1') {
      if (c0 > 0) origin0 = (origin0+mod0[i])%c0;
      if (c1 > 0) origin1 = (origin1+mod1[i])%c1;
    }
  }

  vector<i64> ppc(n);
  ppc[0] = 0;
  RANGE(i, 1, n) {
    i64 tmp = i, keta = 0;
    while (tmp > 0) {
      if (tmp&1) keta++;
      tmp /= 2;
    }
    ppc[i] = ppc[i%keta]+1;
  }

  vector<i64> ans(n);
  RREP(i, n) {
    if (x[i] == '1' && c1 == 0) {
      cout << 0 << endl;
      continue;
    }
    i64 value = 0;
    if (x[i] == '0' && c0 > 0) {
      value = (origin0+mod0[i])%c0;
    } else if (x[i] == '1' && c1 > 0) {
      value = (origin1+c1-mod1[i])%c1;
    }
    cout << ppc[value]+1 << endl;
  }

  return 0;
}


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

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

typedef long long ll;
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  /*
  if(a == b){
    printf("%d\n", c);
  }
  else if(a == c){
    printf("%d\n", b);
  }
  else{
    printf("%d\n", a);    
  }
  */
  printf("%d\n", a^b^c);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

    string s;
    cin>>s;
    int n=s.size();
    if(s[n-1]=='s')
    {
        s+="es";
    }
    else
    {
        s+='s';
    }
    cout<<s<<endl;
    return 0;
}


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

int main() {

	int n; cin >> n;

	vector<long long> a(n+1); for (int i = 1; i <= n; ++i) cin >> a[i];

	vector<long long> ans(n+1, 0);
	vector<long long> b;

	for (int i = n; i >= 1; --i) {

		int tmp_sum = 0;
		for (int j = 2 * i; j <= n; j += i) {			
			tmp_sum += ans[j];
		}

		if (tmp_sum % 2 != a[i]) {
			ans[i] = 1;
		}

	}
	
	for (int i = 1; i <= n; ++i) {
		if (ans[i]) { b.push_back(i); }
	}

	cout << b.size() << endl;

	for (int i = 0; i < b.size(); ++i) {
		cout << b[i] << " ";
	}

	return 0;
}

Measured memory_bytes: 4980
#!/usr/bin/ruby
while true
h,w=gets.split.map(&:to_i)
break if h==0
a=h.times.map{gets.chomp.chars.map{|c|c=='.' ? 1 : 0}+[0]}
#accum=h.times.map{[0]*w}
1.step(h-1){|i|
	0.step(w-1){|j|
		a[i][j]+=a[i-1][j] if a[i][j]>0
	}
}
#a.each{|e|p e}
ans=0
0.step(h-1){|i|
	stk=[]
	0.step(w){|j|
		cur=a[i][j]
		if stk.empty? or stk.last[1]<cur
			stk.push([j,cur])
		elsif stk.last[1]>cur
			idx=j
			while !stk.empty? and stk.last[1]>=cur
				height=stk.last[1]
				idx=stk.last[0]
				ans=[ans,height*(j-idx)].max
				stk.pop
			end
			stk.push([idx,cur])
		end
	}
}
p ans
end

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

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

  long ans=0;
  for(int i=0;i<N.size();i++){
    ans+=int(N[i]-'0');
  }

if(ans%9==0) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}


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

int main(void)
{
    int n, sum = 0;
    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        sum+=x-1;
    }
    cout <<sum <<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int[] alp = new int[26];
        boolean bre  = false;
        for (int i = 0; i < s.length(); i++) {
            if (alp[s.charAt(i) - 'a'] == 1) {
                bre = true;
                break;
            } else {
                alp[s.charAt(i) - 'a'] = 1;
            }
        }
        if (bre) {
            System.out.println("no");
        } else {
            System.out.println("yes");
        }
    }
}

Measured memory_bytes: 22868
#include <cstdio>
using namespace std;
int n;
char s[30005];

int test(int i){
    int arr[3];
    arr[2]=i%10+'0';
    i/=10;
    arr[1]=i%10+'0';
    i/=10;
    arr[0]=i%10+'0';
    
    int counter=0;
    
    for (int x=0;x<n;x++){
        if (s[x]==arr[counter]) counter++;
        if (counter==3) return 1;
    }
    return 0;
}

int main(){
    scanf("%d",&n);
    scanf("%s",&s);
    
    int ans=0;
    for (int x=0;x<1000;x++){
        ans+=test(x);
    }
    
    printf("%d\n",ans);
}

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

#define ll long long
#define endl "\n"

void solve() {
  string s;
  cin >> s;
  ll one = 0, zc = 0;
  for (char x : s) {
    if (x == '0')
      ++zc;
    else
      ++one;
  }
  cout << 2 * min(one, zc) << endl;
}

int main() {
  ll t;
  // cin >> t;
  t = 1;
  while (t--)
    solve();
  return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
#define mod 1000000007
using namespace std;

void solve()
{
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    solve();
    ll n,k;
    cin>>n>>k;
    ll a[n];
    ll maxi = -1;
    for (ll i = 0; i < n; i++)
    {
        /* code */
        cin>>a[i];
        maxi = max(a[i], maxi);
    }
    vector< vector<ll> > dp(n, vector<ll>(k + 1, 0));
    dp[0][0] = 1;
    for(ll i=1; i<=min(a[0], k); i++)
    {
        dp[0][i] = 1;
    }
    if(n==1)
    {
        cout<<dp[0][k]<<'\n';
        return 0;
    }
    for (ll i = 1; i <=k; i++)
    {
        dp[0][i] += dp[0][i-1];
    }
    
    for(ll i=1; i<n; i++)
    {
        for (ll j = 0; j <= k; j++)
        {
            if(j == 0)
            {
                dp[i][j] = 1;
            }
            else
            {
                ll l = max(j - a[i], (ll)0);
                if(l>0)
                    dp[i][j] = (dp[i-1][j] - dp[i-1][l - 1] + mod )%mod;
                else
                {
                    dp[i][j] = dp[i-1][j];
                }
            }  
        }
        if(i == (n - 1) )
            break;
        for (ll j = 1; j <=k; j++)
        {
            dp[i][j] = (dp[i][j - 1] + dp[i][j])%mod;
        }
    }
    cout<<dp[n-1][k]<<'\n';
}

Measured memory_bytes: 82212
#include <bits/stdc++.h>
#include <cstdlib>
#include<climits>
#define ll long long int
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
using namespace std;
const int INF=1e9+5;
			
int main(){
    
    fio;
    int n;cin>>n;
    vector<int>arr(n);
    for(int i=0;i<n;i++)cin>>arr[i];   
    vector<int>dp(n,INF);
    dp[0]=0;
    for(int i=0;i<n;i++){
      for(int j:{i+1,i+2}){
		  if(j<n){
			  dp[j]=min(dp[j],dp[i]+abs(arr[i]-arr[j]));
		  }
	  }
  }
  cout<<dp[n-1]<<'\n';  
		  
    
}
     


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <iostream>
#define MN 101000

typedef long long ll;

int b[MN], l[MN], r[MN];
ll v[MN];
int p[MN];
int n, x;

bool cmp(int a, int b) {return v[a] > v[b];}

ll solve(ll t)
{
	ll ans = -1e18, B = 0;
	ll cnt = t / x, lst = t % x;
	
	for(int I = 1; I <= n; I++) {int i = p[I]; B += 1ll * b[i] * l[i];}
	
	ll tot = 0;
	for(int I = 1; I <= cnt; I++) {int i = p[I]; tot += v[i];}
	
	if(lst == 0) return tot - B;
	
	tot += v[p[cnt + 1]];
	for(int I = 1; I <= n; I++)
	{
		int i = p[I];
		ll val = std::max(1ll * lst * l[i], 1ll * lst * r[i] - 1ll * (r[i] - l[i]) * b[i]);
		if(I > cnt) ans = std::max(ans, tot - v[p[cnt + 1]] + val);
		else ans = std::max(ans, tot - v[i] + val);
	}
	return ans - B;
}

int main()
{
	scanf("%d%d", &n, &x);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d%d%d", &b[i], &l[i], &r[i]);
		v[i] = std::max(1ll * x * l[i], 1ll * x * r[i] - 1ll * (r[i] - l[i]) * b[i]);
		p[i] = i;
	}
	std::sort(p + 1, p + n + 1, cmp);
	ll l = 0, r = 1ll * n * x + 1;
	while(l < r)
	{
		ll mid = l + r >> 1;
		if(solve(mid) >= 0) r = mid;
		else l = mid + 1;
	}
	printf("%lld\n", r);
}

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

int main(void){
  vector<int> nums;
  int a, b, c, d, e;

  cin >> a >> b >> c >> d >> e;
  nums.push_back( a );
  nums.push_back( b );
  nums.push_back( c );
  nums.push_back( d );
  nums.push_back( e );

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

  cout << nums[0];
  for(int i = 0; i < 4; i++)
    cout << ' ' << nums[i + 1];
  cout << endl;
  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  string S;
  cin>>S;
  if(S.back()=='s') {
S+="es";
  }
  else {
S+='s';
  }
  cout<<S<<endl;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    int cnt1=0;
    int cnt2=0;
    vector<int> p(n);
    vector<int> q(n);
    for(int i=0;i<n;i++){
        cin >> p[i];
    }
    for(int i=0;i<n;i++){
        cin >> q[i];
    }
    vector<int> a(n);
    for(int i=0;i<n;i++){
        a[i]=i+1;
    }
    do{
        cnt1++;
        bool flag=true;
        for(int i=0;i<n;i++){
            if(a[i]!=p[i]){
                flag=false;
                break;
            }
        }
        if(flag){
            break;
        }
    }while(next_permutation(a.begin(),a.end()));
    vector<int> b(n);
    for(int i=0;i<n;i++){
        b[i]=i+1;
    }
    do{
        cnt2++;
        bool flag=true;
        for(int i=0;i<n;i++){
            if(b[i]!=q[i]){
                flag=false;
                break;
            }
        }
        if(flag){
            break;
        }
    }while(next_permutation(b.begin(),b.end()));
    cout << abs(cnt1-cnt2) << endl;
}

Measured memory_bytes: 256
'use strict';

function Main(input) {
  const N = Number(input.split("\n")[0]);
  if(N === 1) {
    console.log("Hello World");
  }
  if(N === 2) {
    const A = Number(input.split("\n")[1]);
    const B = Number(input.split("\n")[2]);
    console.log(A + B);
  }

};

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 21064
#N,Tの取得
N,T = map(int, input().split())
#秒のリストを取得
tl = list(map(int, input().split()))

bt = 0 #直前のスイッチを押した時間
gt = T #秒数総和
for t in tl[1:]:
    if t - bt > T:
        gt += T #スイッチオフの時はT秒追加
    else:
        gt += t - bt #スイッチがオンのとき、前回からの経過時間を加算
    bt = t

print(str(gt))

Measured memory_bytes: 26832
s=input()

t={s[0],s[1]}
K=[]
if len(s)==2 and len(t)==1:
    print('1 2')
    K.append(1)
else:
    for i in range(len(s)-2):
        if s[i]==s[i+1] or s[i]==s[i+2] or s[i+1]==s[i+2]:
            print(str(i+1)+' '+str(i+3))
            K.append(1)
            break

if K==[]:
    print('-1 -1')


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s1,t,s;
	cin>>s1>>t;
	bool ok=0;
	s=string(s1.size(),'z');
	if(s1.size()<t.size())
	{
		cout<<"UNRESTORABLE";
		return 0;
	}
	for(int i=0;i<=s1.size()-t.size();i++)
	{
		bool flag=1;
		for(int j=0;j<t.size();j++)
		{
			if(s1[i+j]!='?'&&s1[i+j]!=t[j])
			{
				flag=0;
				break;
			}
		}
		if(flag)
		{
			ok=1;
			string ts=s1;
			for(int j=0;j<t.size();j++)
				ts[i+j]=t[j];
			for(int j=0;j<ts.size();j++)
				if(ts[j]=='?')
					ts[j]='a';
			if(ts<s)
				s=ts;
		}
	}
	if(ok)
		cout<<s;
	else
		cout<<"UNRESTORABLE";
	return 0;
}

Measured memory_bytes: 3624
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String arg[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());
        int pre = -1;
        int cur = 0;
        int count = 0;
        for(int i=0;i<N;i++){
            int now = Integer.parseInt(st.nextToken());
            if(now!=pre){
                count += cur/2;
                pre = now;
                cur = 1;
            }else{
                cur++;
            }
        }
        count += cur/2;
        System.out.println(count);
    }
}


Measured memory_bytes: 21460
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <queue>
using namespace std;
typedef long long LL;
const LL N = 1000000007;

LL n,m,k,smx,smi;
LL a[500005];
LL fac[500005],inv[500005];

bool cmp2(LL x,LL y){
	return x > y;
}

LL kpw(LL x,LL y){
	LL ans = 1,tmp = x;
	while(y){
		if(y & 1) ans = (ans * tmp) % N;
		tmp = (tmp * tmp) % N;
		y >>= 1;
	}
	return ans;
}

LL comb(LL x,LL y){
	return (((fac[x] * inv[y]) % N) * inv[x - y]) % N;
}

LL solve(){
	LL ret = 0;
	for(LL i = k;i <= n;i ++){
//		cout << i - 1 << ' ' << k - 1 << endl;
//		cout << comb(i - 1,k - 1) << endl;
		ret += (a[i] * comb(i - 1,k - 1)) % N;
		ret %= N;
	}
	return ret;
}

int main(){
	fac[0] = 1; for(LL i = 1;i <= 200000;i ++) fac[i] = (fac[i - 1] * i) % N;
	for(LL i = 0;i <= 200000;i ++) inv[i] = kpw(fac[i],N - 2);
	cin >> n >> k;
	for(LL i = 1;i <= n;i ++) cin >> a[i];
	sort(a + 1,a + 1 + n);
	smx = solve();
	sort(a + 1,a + 1 + n,cmp2);
	smi = solve();
	cout << (smx - smi + N) % N << endl;
	return 0;
}

Measured memory_bytes: 9984
using System;

class Program
{
    static void Main()
    {
        string line = Console.ReadLine();
        string[] digit = line.Split();

        int c = int.Parse(digit[0]);
        int r = int.Parse(digit[1]);

        int[] colSum = new int[r];
        int wholeSum = 0;

        for (int y = 0; y < c; ++y)
        {
            line = Console.ReadLine();
            digit = line.Split();

            int rowSum = 0;

            for (int x = 0; x < r; ++x)
            {
                int n = int.Parse(digit[x]);

                rowSum += n;
                colSum[x] += n;
            }

            wholeSum += rowSum;
            Console.WriteLine(line + " " + rowSum);
        }

        for (int x = 0; x < r; ++x)
        {
            Console.Write(colSum[x] + " ");
        }

        Console.WriteLine(wholeSum);
    }
}


Measured memory_bytes: 15980
"use strict";

const main = arg => {
    // 標準入力の不要な空白と改行を削除し、配列に格納する
    const input = arg.trim().split(" ");
    const money = parseInt(input[0]);

    const div500 = Math.floor(money / 500);
    const amari500 = money % 500;
    const div5 = Math.floor(amari500 / 5);

    const happiness = (div500 * 1000) + (div5 * 5);
    console.log(happiness);

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));  

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

typedef long long ll;
const int MAXN = 200010;
const ll inf = 0x3f3f3f3f3f3f3f3f;

int n, m, A, B;
int x[MAXN];

#define ls (o << 1)
#define rs (o << 1 | 1)

struct Node
{
	ll s, s1, s2;
	ll tag;
}t[MAXN << 2];

inline void pushup(int o)
{
	t[o].s = min(t[ls].s, t[rs].s);
	t[o].s1 = min(t[ls].s1, t[rs].s1);
	t[o].s2 = min(t[ls].s2, t[rs].s2);
}

inline void pushdown(int o)
{
	if(t[o].tag)
	{
		t[ls].s += t[o].tag, t[rs].s += t[o].tag;
		t[ls].s1 += t[o].tag, t[rs].s1 += t[o].tag;
		t[ls].s2 += t[o].tag, t[rs].s2 += t[o].tag;
		t[ls].tag += t[o].tag, t[rs].tag += t[o].tag;
		t[o].tag = 0;
	}
}

void build(int o, int l, int r)
{
	if(l == r)
	{
		if(l == B) t[o].s = 0;
		else t[o].s = inf;
		t[o].s1 = t[o].s + l;
		t[o].s2 = t[o].s - l;
		return;
	}
	int mid = (l + r) >> 1;
	build(ls, l, mid);
	build(rs, mid + 1, r);
	pushup(o);
}

void add(int o, int l, int r, int L, int R, ll v)
{
	if(L <= l && r <= R)
	{
		t[o].s += v, t[o].s1 += v;
		t[o].s2 += v, t[o].tag += v;
		return;
	}
	pushdown(o);
	int mid = (l + r) >> 1;
	if(L <= mid) add(ls, l, mid, L, R, v);
	if(R > mid) add(rs, mid + 1, r, L, R, v);
	pushup(o);
}

ll getmin(int o, int l, int r, int L, int R, int op)
{
	if(l > r) return inf;
	if(L <= l && r <= R)
	{
		if(op == 1) return t[o].s1;
		if(op == 2) return t[o].s2;
		return t[o].s;
	}
	pushdown(o); ll res = inf;
	int mid = (l + r) >> 1;
	if(L <= mid) res = min(res, getmin(ls, l, mid, L, R, op));
	if(R > mid) res = min(res, getmin(rs, mid + 1, r, L, R, op));
	return res;
}

void modify(int o, int l, int r, int pos, ll v)
{
	if(l == r)
	{
		t[o].s1 -= t[o].s;
		t[o].s2 -= t[o].s;
		t[o].s = v;
		t[o].s1 += v;
		t[o].s2 += v;
		return;
	}
	pushdown(o);
	int mid = (l + r) >> 1;
	if(pos <= mid) modify(ls, l, mid, pos, v);
	else modify(rs, mid + 1, r, pos, v);
	pushup(o);
}

#undef ls
#undef rs

int main()
{
	scanf("%d %d %d %d", &n, &m, &A, &B);
	for(int i = 1; i <= m; ++i) scanf("%d", &x[i]);
	x[0] = A; build(1, 1, n);
	for(int i = 1; i <= m; ++i)
	{
		ll v = abs(x[i] - x[i - 1]);
		ll mn1 = inf, mn2 = inf;
		if(x[i] <= n) mn1 = getmin(1, 1, n, x[i], n, 1) - x[i];
		if(x[i] >= 2) mn2 = getmin(1, 1, n, 1, x[i] - 1, 2) + x[i];
		add(1, 1, n, 1, n, v);
		modify(1, 1, n, x[i - 1], min(mn1, mn2));
	}
	printf("%lld\n", getmin(1, 1, n, 1, n, 3));
	return 0;
}

Measured memory_bytes: 19456
let rec f()=let z,n=ref 0,read_int()in for a=0to 9do for b=0to 9do for c=0to 9do for d=0to 9do if a+b+c+d=n then incr z;done;done;done;done;f(Printf.printf"%d
"!z);;try f()with _->()

Measured memory_bytes: 2348
#include <bits/stdc++.h>
#define Tayeb ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int main()
{
    Tayeb;
    int N,count=0;
    cin >> N;
    int arr[N];
    for(int i=0; i<N; i++)
    {
        cin >> arr[i];
    }
    sort(arr,arr+N);
    for(int i=1; i<N; i++)
    {
        if(arr[i]==arr[i-1])
        count++;
    }
    if(count==0)
    cout << "YES" << "\n";
    else
    cout << "NO" << "\n";


    return 0;

}


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

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

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> cnt(n+1);
    int res = n;
    for (int i=0; i<k; ++i) {
        int d;
        cin >> d;
        for (int j=0; j<d; ++j) {
            int tmp;
            cin >> tmp;
            cnt.at(tmp)++;
            if (cnt.at(tmp) == 1) --res;
        }
    }
    cout << res << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;

 int main() {
   int N;
   cin >> N;
   vector<vector<bool>> F(N, vector<bool>(10, false));

   rep(i, 0, N) {
     rep(j, 0, 10) {
       int b;
       cin >> b;
       if (b) F.at(i).at(j) = true;
     }
   }

   vector<vector<int>> P(N, vector<int>(11));

   rep(i, 0, N) {
     rep(j, 0, 11) {
       cin >> P.at(i).at(j);
     }
   }

   int ans = -1000000000;

   for (int i = 1; i < (1 << 10); i++) {
     int tmp = 0;
     rep(j, 0, N) {
       int cnt = 0;
       rep(k, 0, 10) {
         if (i & (1 << k) && F.at(j).at(k)) cnt++;
       }
       tmp += P.at(j).at(cnt);
     }
     ans = max(ans, tmp);
   }

   cout << ans << endl;
 }


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

int main()
{
    string s;
    int count=0;
    cin>>s;
    for(int i=0;i<s.length()/2;++i)
    {
        if(s[i]!=s[s.length()-i-1])
        count++;
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
<?PHP
$ans = fgets(STDIN);
$aaa = fgets(STDIN);
$heights = explode(" ", $aaa);
$array = explode(" ", $ans);
$amount=$array[0];
$kick_power=$array[1];
$dps=[];

foreach (range(0, $amount-1) as $index) {
    $dps[$index] = INF;
    if($index===0){
        $dps[0]=0;
        continue;
    }
    $dps[$index]=$dps[$index-1]+abs($heights[$index]-$heights[$index-1]);

    foreach (range(1, $kick_power) as $i) {
        if($index>=$i){
            if ($dps[$index]> abs($dps[$index - $i] + abs($heights[$index] - $heights[$index - $i]))){$dps[$index]=abs($dps[$index - $i] + abs($heights[$index] - $heights[$index - $i]));}
        }

    }
}

echo end($dps);

Measured memory_bytes: 23028
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin >> p[i];
        p[i]--;
    }

    long long cnt = 0;
    for(int i=0;i<n-1;i++){
        if(p[i] != i)
            continue;
        swap(p[i], p[i+1]);
        cnt++;
        i++;
    }
    if(p[n-1] == n-1)
        cnt++;
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
int main(){
	/*
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	#endif
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n,a,b;
	cin>>n>>a>>b;
	int ans=1000000;
	for(int i=0;i<=n;i++){
		ans=min(ans,(i<n?b:0)+i*a);
	}
	cout<<ans;
}


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

#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ll long long
#define ldb long double 
#define db double
#define str string

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mll map<ll,ll>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const ll INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

ll power(ll a,ll n)
{
 ll res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a*=a;
  n/=2;
}
return res;
}

ll abst(ll a)
{
 return ((a<0)?(-1*a):(a));
}

int main()
{
  int n,r;
  cin>>n>>r;
  if(n>=10)
  {
      cout<<r<<"\n";
  }
  else
      {
         int res=r+100*(10-n);
         cout<<res<<"\n";
      }
      return 0;
}

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

using namespace std;

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

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

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

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

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

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  ll x,y;
  cin>>x>>y;
  int ans = 1;
  while(2ll*x<=y){
    x *= 2ll;
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
#define N_MAX (1000001)
int prime[N_MAX];
int a,d,n;

void init(){
	for(int i=0;i<N_MAX;i++)prime[i]=1;
	prime[0]=prime[1]=0;
	for(int i=2;i<N_MAX;i++){
		for(int j=2;j*i<N_MAX;j++){
			prime[j*i]=0;
		}
	}
}
void solve(){
	int cnt=0;
	for(int i=a;1;i+=d){
		if(prime[i]){
			cnt++;
			if(cnt==n){
				cout<<i<<endl;
				break;
			}
		}
	}
}
int main(){
	init();
	while(cin>>a>>d>>n&&(a||d||n)){
		solve();
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main()
{
	int n;
	cin >> n;
	int a[n];
	REP(i, n) cin >> a[i];

	int count = 0;

	REP(i, n){
		if (a[a[i] - 1] == i + 1) count++;
	}

	cout << count / 2 << endl;
}


Measured memory_bytes: 640
m = Array.new(4).map{Array.new(3).map{Array.new(10,0)}}
N = gets.to_i
N.times do |i|
    b,f,r,v = gets.split.map(&:to_i)
    m[b-1][f-1][r-1] += v
end
m.each_with_index do |x,i|
    x.each_with_index do |y,j|
        puts ' ' + y.join(' ')
    end
    puts "####################" unless i == 3
end


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, K;
    cin >> N >> K;

    ll res = 0;
    for(ll b=1;b<=N;b++){
    	res += ((N+1)/b)*max(b-K, 0ll);
    	res += max((N+1)%b - K, 0ll);
    }
    if(K == 0) res -= N;
    cout << res << endl;
    return 0;
}

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

public class Main {

    private static int N;
    private static double[][][] memo;

    private static double rec(int one, int two, int three) {

        // System.out.println("one " + String.valueOf(one) + " two " + String.valueOf(two) + " three " + String.valueOf(three));

        if (memo[one][two][three] > 0){
            return memo[one][two][three];
        }

        if (one == 0 && two == 0 && three == 0) {
            return 0;
        }

        double res = 0;

        res += 1.0 / ((one + two + three) / (double) N); // EP of picking a coin on the first try in the current situation

        if (one > 0) {
            res += (((double) one) / (one + two + three) ) * rec(one - 1, two, three); // the child created by eliminating 1 plate of sushi
            // System.out.println("res of child");
            // System.out.println(res);
        }
        if (two > 0) {
            res += (((double) two) / (one + two + three) ) * rec(one + 1, two - 1, three); // if you remove 1 sushi from a plate with 2 sushis you get one more one sushi plate
        }
        if (three > 0) {
            res += (((double) three) / (one + two + three) ) * rec(one, two + 1, three - 1);
        }

        memo[one][two][three] = res;

        return res;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));

        N = Integer.parseInt(f.readLine()); // number of plates

        int oneSushi = 0;
        int twoSushis = 0;
        int threeSushis = 0;

        StringTokenizer st = new StringTokenizer(f.readLine());

        for (int i = 0; i < N; i++) {
            int plate = Integer.parseInt(st.nextToken());
            if (plate == 1) {oneSushi++;}
            else if (plate == 2){twoSushis++;}
            else if (plate == 3){threeSushis++;}
        }

        int totalPlates = oneSushi + twoSushis + threeSushis;

        memo = new double[totalPlates+1][totalPlates+1][totalPlates+1];
        System.out.println(rec(oneSushi, twoSushis, threeSushis));

    }
}

Measured memory_bytes: 303700
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;
const int MOD=1000000007;

LL p[100010],q[100010],r[100010];
vector<LL> nuee;
int main(){
	int X,Y,A,B,C;
	LL ans=0;
	
	cin>>X>>Y>>A>>B>>C;
	for(int i=0;i<A;i++)cin>>p[i];                
	for(int i=0;i<B;i++)cin>>q[i];
	for(int i=0;i<C;i++)cin>>r[i];
	
	sort(p,p+A,greater<int>());
	sort(q,q+B,greater<int>());
	
	for(int i=0;i<X;i++)nuee.push_back(p[i]);
	for(int i=0;i<Y;i++)nuee.push_back(q[i]);
	for(int i=0;i<C;i++)nuee.push_back(r[i]);
	
	sort(nuee.begin(),nuee.end(),greater<int>());
	for(int i=0;i<X+Y;i++)
	{
		ans=ans+nuee[i];
	}
	cout<<ans<<endl;
} 


Measured memory_bytes: 8560
#include <stdio.h>

int maximum(int a, int b){ return a > b ? a : b; }

int main(){
    int A, B, C, X, Y, i;
    long int min=10000000000, ans;

    scanf("%d %d %d %d %d", &A, &B, &C, &X, &Y);

    for(i=0; i<=100000; i++){
        ans = i*2*C + maximum(0, X-i)*A + maximum(0, Y-i)*B;
        if(min > ans)
            min = ans;
    }

    printf("%ld\n", min);

    return 0;
}

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

int main() {
    int N, M; cin >> N >> M;
    int ans[N] = {0};
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        ans[a - 1]++;
        ans[b - 1]++;
    }
    for (int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
}


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

int parent(int);
int left(int);
int right(int);
void maxHeapify(int*,int);
void insert(int*,int);
void extract(int*);
void increase(int*,int);

int h=0;

int main(){
  int i,k,*A;
  char s[10];

  A = (int *)malloc(sizeof(int)*2000000);

  while(1){
    scanf("%s",s);
    if(s[0]=='e'){
      if(s[1]=='n') break;
      else if(s[1]=='x') extract(A);
    }
    else if(s[0]=='i'){
      scanf("%d",&k);
      insert(A,k);
    }
    
  }


  return 0;
}

int parent(int i){
  return i/2;
}

int left(int i){
  return i*2;
}

int right(int i){
  return i*2+1;
}

void maxHeapify(int* A,int i){
  int l,r,largest,tmp;
  
  l = left(i);
  r = right(i);

  if(l<=h && A[l]>A[i]) largest = l;
  else largest = i;

  if(r<=h && A[r]>A[largest]) largest = r;
  
  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(A,largest);
  }

  return;
}

void insert(int* A,int k){
  h++;
  A[h]=k;
  increase(A,k);
  return;
}

void extract(int* A){
  printf("%d\n",A[1]);
  A[1]=A[h];
  h--;
  maxHeapify(A,1);
  return;
}

void increase(int* A,int k){
  int tmp,i;
  i=h;
  if(k<A[i]) return;
  A[i] = k;
  while(i>1 && A[parent(i)]<A[i]){
    tmp = A[i];
    A[i]=A[parent(i)];
    A[parent(i)]=tmp;
    i=parent(i);
  }
  return;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
  int a;
  int b;
  cin >> a >> b;
  if(a < 10 && b < 10)
  {
    cout << a * b;
  }
  else
  {
    cout << -1;
  }
  
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int D = scan.nextInt();
		int count = 0;

		while(A>0 && C>0) {
			if(count % 2 == 0) {
				C -= B;
				count += 1;
			}else {
				A -= D;
				count += 1;
				}
			}

		if(A <= 0) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}

		scan.close();
	}

}


Measured memory_bytes: 35732
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int ijk[100][100];
bool v[100][100];
vector<pair<int,int> >g[100];
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a){
		for(int i=0;i<a;i++)g[i].clear();
		for(int i=0;i<b;i++){
			int d,e,f;
			scanf("%d%d%d",&d,&e,&f);
			g[d-1].push_back(make_pair(e-1,f));
		}
		for(int i=0;i<a;i++)
			for(int j=0;j<a;j++){
				ijk[i][j]=999999999;
				v[i][j]=false;
			}
		priority_queue<pair<int,pair<int,int> > >Q;
		Q.push(make_pair(0,make_pair(0,0)));
		ijk[0][0]=0;
		while(Q.size()){
			int cost=-Q.top().first;
			int at=Q.top().second.first;
			int val=Q.top().second.second;
			Q.pop();
			if(v[at][val])continue;
			v[at][val]=true;
			for(int i=0;i<g[at].size();i++){
				if(!v[g[at][i].first][val]&&ijk[at][val]+g[at][i].second<ijk[g[at][i].first][val]){
					ijk[g[at][i].first][val]=ijk[at][val]+g[at][i].second;
					Q.push(make_pair(-ijk[g[at][i].first][val],make_pair(g[at][i].first,val)));
				}
				if(val<a-1&&!v[g[at][i].first][val+1]&&ijk[at][val]<ijk[g[at][i].first][val+1]){
					ijk[g[at][i].first][val+1]=ijk[at][val];
					Q.push(make_pair(-ijk[g[at][i].first][val+1],make_pair(g[at][i].first,val+1)));
				}
			}
		}
		for(int i=0;i<a;i++)if(ijk[a-1][i]<=c){
			printf("%d\n",i);break;
		}
	}
}

Measured memory_bytes: 1316
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class C { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long N = GetLong();
		long X = GetLong();
		var x = GetLongs(N);

		var ans = x.Select(a => Abs(a - X)).Aggregate((a, c) => a = gcd(a, c));
		WriteLine(ans);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 37624
N = int(input())

D_list = []
for i in range(N):
    d1, d2 = map(int, input().split())
    D_list.append([d1, d2])

cnt = 0
for i in range(N):
    if D_list[i][0] == D_list[i][1]:
        cnt += 1
        if cnt == 3:
            print("Yes")
            break
    else:
        cnt = 0
    if i == N-1:
        print("No")

Measured memory_bytes: 62304
#include<stdio.h>

static const int N = 100;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j;
  int A[N+1];
  int key=0;
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);
 
  for(i=1;i <= n;i++){
    key = A[i];
    j = i-1;
    while(j > 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
      A[j+1] = key;
    }
     if(i > 1) {
      trace(A,n);
       }
  }  
  return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double debt = 100000;

        for(int i = 0; i < n; i++){
            debt *= 1.05;
            double s = debt / 1000;
            s = Math.ceil(s);
            debt = s * 1000;
        }

        System.out.println((int)debt);
    }
}

Measured memory_bytes: 26048
/*
 * main.cpp
 *
 *  Created on: 2011/04/01
 *      Author: satoki
 *      21:38 ~ 21:47
 */
#include <iostream>
#include <string.h>
using namespace std;

int iN, iM, iOutput;

bool input() {
  if (scanf("%d %d", &iN, &iM) == EOF) return false;
  return true;
}

void manage() {
  iOutput = 0;
  for (iN += iM; iN != 0; iN /= 10) {
    iOutput++;
  }
}

int main() {
  while (1) {
    if (!input()) break;
    manage();
    printf("%d\n", iOutput);
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

long long fac[COMMAX], finv[COMMAX], inv[COMMAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};
int ahako[50];
int bhako[50];
int chako[50];
int main(){
  int n;
  cin >> n;
  rep(i,0,n)cin >> ahako[i];
  rep(i,0,n)cin >> bhako[i];
  rep(i,0,n-1)cin >> chako[i];
  int res = bhako[ahako[0]-1];
  rep(i,1,n){
    res += bhako[ahako[i]-1];
    if(ahako[i-1] + 1 == ahako[i])res += chako[ahako[i-1]-1];
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <numeric>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// using namespace std;

using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

void Main() {
  int n;
  std::cin >> n;

  std::vector<int> p(n);
  rep(i, n) { std::cin >> p[i]; }

  int res = 0;
  for (int i = 0; i < p.size() - 2; ++i) {
    if (((p[i] < p[i + 1]) && (p[i + 1] < p[i + 2])) ||
        ((p[i] > p[i + 1]) && (p[i + 1] > p[i + 2]))) {
      ++res;
    }
  }
  std::cout << res << std::endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 888