akhauriyash/Code-Regression huggingface dataset:
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>

const long long INF = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    llong N,R;
    cin >> N >> R;
    if(N>=10){
        cout << R << endl;
        exit(0);
    }else{
        cout << R+100*(10-N) << endl;
    }
    return 0;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; ++i)
#define frab(i, a, b) for (int i = a; i < b; ++i)
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef double ld;

const int N = 1e5 + 10;
const int INF = 1e9 + 10;

vector <int> g[N];

int sz[N];
int n;
bool used[N];
bool fnd = false;

void dfs(int v, int par) {
    //used[v] = true;
    for (auto t: g[v])
        if (t != par)
            dfs(t, v);
    int sum = 0;
    int odd = 0;
    for (auto t: g[v])
        if (t != par) {
            sum += sz[t];
            if (sz[t] % 2)
                odd++;
        }
    sz[v] = sum + 1;
    if ((n - sum - 1) % 2)
        odd++;
    if (odd >= 2) fnd = true;
}

int main() {
    //freopen("a.in", "r", stdin);
    cin >> n;
    fr(i, n - 1) {
        int v, u;
        cin >> v >> u;
        g[--v].pb(--u);
        g[u].pb(v);
    }

    dfs(0, -1);
    if (fnd)
        cout << "First";
    else
        cout << "Second";
}


Measured memory_bytes: 6272
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define sortV(v) v.begin(),v.end()
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
/*ncr mod m
const int mod=1000000009;
int c[r+1];
void ncr(int n,int r){c[0]=1;repre(i,1,n)for(int j=min(i,r);j>0;j--)c[j]=((c[j-1]%mod)+(c[j]%mod))%mod;return c[r];}*/
int32_t main()
{
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  fastio
  int n;
  cin>>n;
  double arr[n];
  priority_queue<double,vector<double>,greater<double> >q;
  rep(i,n)
  {cin>>arr[i];
    q.push(arr[i]);
  }
  if(n==1)
  {
    double temp=q.top();
    cout<<temp<<endl;
    q.pop();
    exit(0);
  }
  int ans=0;
  while(q.size()!=1)
  {
    double temp1=q.top();
    q.pop();
    double temp2=q.top();
    q.pop();
    double res=temp1+temp2;
    res=res/2.0;
    q.push(res);
  }
  double temp=q.top();
  cout<<temp<<endl;
  q.pop();

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int A = 0;
    int B = 0;
    for(int i= 1; i <= b ; i++ ){
        int v = (int)Math.pow(10,i-1);
        A += v*a;
    }
    for(int i= 1; i <= a ; i++ ){
        int z = (int)Math.pow(10,i-1);
        B += z*b;
    }
    if(A>=B){
        System.out.println(A);
    }else{
        System.out.println(B);
    }

        sc.close();
    }    
}


Measured memory_bytes: 23764
n = int(input())
a = [0] * n
b = [0] * n
for x in range(n):
    tmp = list(map(int, input().split()))
    a[x] = tmp[0]
    b[x] = tmp[1]

a.sort()
b.sort()
if n % 2 == 1:
    l = a[n // 2]
    r = b[n // 2]
    print(r - l + 1)
else:
    l1, l2 = a[n // 2 - 1], a[n // 2]
    r1, r2 = b[n // 2 - 1], b[n // 2]
    print((r1 + r2) - (l1 + l2) + 1)


Measured memory_bytes: 80160
#include<iostream>
using namespace std;
int main(){
  double a;
  int i=0;
  while(cin>>a){
    if(a<=48.00) cout<<"light fly"<< endl;
    else if(a<=51.00) cout<<"fly"<<endl;
    else if(a<=54.00) cout<<"bantam"<<endl;
    else if(a<=57.00) cout<<"feather"<<endl;
    else if(a<=60.00) cout<<"light"<<endl;
    else if(a<=64.00) cout<<"light welter"<<endl;
    else if(a<=69.00) cout<<"welter"<<endl;
    else if(a<=75.00) cout<<"light middle"<<endl;
    else if(a<=81.00) cout<<"middle"<<endl;
    else if(a<=91.00) cout<<"light heavy"<<endl;
    else if(a>=91.00) cout<<"heavy"<<endl;
  }
}

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

int main(){
  int n;
  cin >> n;
  vector<int> b(n-1);
  for (int i=0;i<n;++i) cin >> b[i];
  vector<int> a(n);
  a[0]=b[0];
  for (int i=1;i<=n-2;++i){
    a[i]=min(b[i],b[i-1]);//問題文の言い換え
  }
  a[n-1]=b[n-2];
  
  int ans=0;
  rep(i,n) ans+=a[i];
  cout << ans << endl;
}

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

int n;
ll a[20][20];
ll cost[1<<16];

vector < int > moves;
void sos(int i , int mask)
{
    if(i == n)
    {
        moves.push_back(mask);
        return;
    }
    if(!(mask>>i&1))
        sos(i+1,mask);
    else
        sos(i+1,mask) , sos(i+1,mask^(1<<i));
}
ll dp[1<<16];
ll get(int mask = (1<<n)-1)
{
    if(mask == 0)return 0;
    if(~dp[mask]) return dp[mask];
    dp[mask] = 0;

    moves.clear();
    sos(0,mask);

    for(auto mask2 : moves)
        dp[mask] = max(dp[mask] , get(mask^mask2) + cost[mask2]);

    return dp[mask];
}
int main()
{
    scanf("%d",&n);
    for(int i = 0 ; i < n; i++)
        for(int j = 0 ; j < n; j++)
            scanf("%lld",&a[i][j]);

    for(int mask = 0 ; mask < (1<<n) ; mask++)
        for(int i = 0 ; i < n; i++)
            if(mask>>i&1)
            for(int j = i+1 ; j < n ; j++)
                if(mask>>j&1)
                    cost[mask] += a[i][j];
    memset(dp,-1,sizeof dp);
    printf("%lld\n",get());
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

int main() {
	uint H, W;
	cin >> H >> W;

	ull mod = pow(10, 9) + 7;

	vector<ull> cmb(W);
	cmb[0] = 1;

	for(uint i=0; i<H; i++) {
		string l;
		cin >> l;
		
		for(uint j=0; j<W; j++) {
			if(l[j] != '.'){
				cmb[j] = 0;
			} else if(j > 0) {
				cmb[j] = (cmb[j-1] + cmb[j]) % mod;
			} else {
				cmb[j] = cmb[j];
			}
		}
	}

	cout << cmb[W-1] << endl;
	return 0;

}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
using intpair = pair<int, int>;

int main(){
    int N; cin >> N;
    priority_queue<intpair,vector<intpair>,greater<intpair>> q;
    rep(i,N){
        int X, L;
        cin >> X >> L;
        q.push(intpair(X+L,X-L));
    }
    stack<intpair> decided;
    decided.push(q.top());
    q.pop();
    while(!q.empty()){
        if(decided.top().first <= q.top().second){
            decided.push(q.top());
        }
        q.pop();
    }
    cout << decided.size() << endl;
}

Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  map<string,string> mp;
  mp["Rainy"] = "Sunny";
  mp["Sunny"] = "Cloudy";
  mp["Cloudy"] = "Rainy";
  
  cin >> s;
  cout << mp[s] << endl;
  
  return 0;
}

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

using namespace std;
int main()
{
    int a,b,c,d;
    int i = 0;

    cin >> a;
    cin >> b;
    cin >> c;
    i = b;
    d = 0;
    while(i<=c){
        if(i%a==0){
            d = 1;
            break;
        }
        i++;
    }
    if(d == 0){
        cout << "NG";
    }
    else{
        cout << "OK";
    }
    
}

Measured memory_bytes: 3596
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    string nap;
    cin >> nap;
    int a = 0, z = nap.size() - 1;
    while (nap[a] != 'A')
        ++a;
    while (nap[z] != 'Z')
        --z;
    cout << z - a + 1;
    return 0;
}


Measured memory_bytes: 720
import fractions
import math

A, B = map(int, input().split())
C = fractions.gcd(A, B)
pfac = []

def get_primes(n):
  primes = [2]
  for i in range(3, (n+1), 2):
    for p in primes:
      if i % p == 0:
        break
      if i < p ** 2:
        primes.append(i)
        break
    else:
      primes.append(i)
  return primes

def get_primes2(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n == 1:
        return []
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

for q in get_primes2(min(C, 10**6)):
  if q ** 2 > C:
    break
  if C % q == 0:
    pfac.append(q)
    while C % q == 0:
      C //= q
if C != 1:
  pfac.append(C)


print(len(pfac) + 1)

Measured memory_bytes: 48788
using System;
using System.Linq;

class ABC110_B{
  static void Main(string[] args){
    
    string S = Console.ReadLine();
    string T = Console.ReadLine();
    int[] s_alphabet = new int[26];
    int[] t_alphabet = new int[26];
    for(int i = 0; i < 26; i++){
      s_alphabet[i] = 0;
      t_alphabet[i] = 0;
    }
    
    for(int i = 0; i < S.Length; i++){
      s_alphabet[S[i] - 'a']++; 
    }
    for(int i = 0; i < T.Length; i++){
      t_alphabet[T[i] - 'a']++;
    }
    
    s_alphabet = s_alphabet.OrderBy(x => x).ToArray();
    t_alphabet = t_alphabet.OrderBy(x => x).ToArray();
    
    bool flag = true;
    for(int i = 0; i < 26; i++){
      if(s_alphabet[i] != t_alphabet[i]) flag = false;
    }
    
    Console.WriteLine(flag ? "Yes" : "No");
    
  }
}

Measured memory_bytes: 14816
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD =1e9+7;
using ll=long long;
using Graph = vector<vector<int>>;

int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    ll ans = b/x - a/x;
    if(a%x==0) ans ++;
    cout << ans << endl;
}

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

typedef long long LL;
const int N = 2e5 + 100;
struct Stack {
	int sep, idx;
};

Stack stk[N];
int n, top, a[N];
LL preSum, ans;

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++) {
		scanf("%d", &a[i]);
	}
	for(int i = 1; i <= n; i ++ ) {
		int x = 0;
		while ( a[ stk[ top].idx] > a[i]) {
			x += stk[top].sep;
			preSum -= (LL)stk[top].sep * a[ stk[top].idx];
			top --;
		}
		stk[ ++ top].idx = i, stk[top].sep = x + 1;
		preSum += (LL)stk[top].sep * a[ stk[top].idx];
		ans += preSum;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2560
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)
var buf = make([]byte, 10000)

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

func main() {
	sc.Buffer(buf, 1000000)
	NAB := strings.Split(nextLine(), " ")
	N, _ := strconv.Atoi(NAB[0])
	A, _ := strconv.Atoi(NAB[1])
	B, _ := strconv.Atoi(NAB[2])
	X := strings.Split(nextLine(), " ")
	L := make([]int, N)
	for i, v := range X {
		L[i], _ = strconv.Atoi(v)
	}
	ans := 0
	for i := 0; i < N-1; i++ {
		a := A * (L[i+1] - L[i])
		if a < B {
			ans += a
		} else {
			ans += B
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6272
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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; }

int a,b,c,d;

int main(){
    cin>>a>>b>>c>>d;
    out(max(a*b,c*d));
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
       Scanner sc = new Scanner(System.in);   
      // 参加人数
	  int N = sc.nextInt();
      // 初期得点
      int K = sc.nextInt();
      // 問題数
      int Q = sc.nextInt();
      // 正解者配列
      int[] A = new int[Q]; 
      // 参加者のポイント配列
      int[] P = new int[N];
      
      //正解者にポイントを与える
      for(int i=0;i<Q;i++){
        A[i] = sc.nextInt();
        P[A[i]-1]++;
      }

      //勝ち残り
      for(int i=0;i<N;i++){
        if(P[i]+K-Q>0){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
      }
    }
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int sum_digit(int x){
    int sumx = 0;
    FOR(j, 1, 6)
    {
        sumx += (x % (int)pow(10, j)) / (int)pow(10, j - 1);
    }
    return sumx;
}

int main()
{
    int n;cin >> n;
    int ans=100000;
    int a, b;
    FOR(i,1,(n/2)+1){
        a = i;
        b = n - a;
        ans = min((sum_digit(a) + sum_digit(b)), ans);
    }

    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define ll long long
    #define mod 1000000007
    #define maxn 200005
    #define vi vector<int>
    #define vl vector<ll>
    #define mii map<int,int>
    #define mli map<ll,int>
    #define forit(it,v) for(auto it=v.begin();it!=v.end();++it)
    #define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
    using namespace std;
    void solve()
    {
        ll n,d,c=0;
        cin>>n>>d;
        // map<pair<ll,ll>,int> mp;
        for (int i = 0; i < n; ++i)
        {
            ll x,y;
            cin>>x>>y;
            if (sqrt(x*x+y*y)<=d)
            {
                // mp[{x,y}]=1;
                c++;
            }   
        }
        cout<<c;
    }
    int main()
    {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
        fastIO;
        // sieve();
        int t=1;
        // int t;
        // cin>>t;
        while(t--)
        {
            solve();
        }
        return 0;
    }

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  while (true) {
    int n; cin >> n;
    if (n == 0) break;
    VV<> t(n, V<>(n + 1));
    for (int i = 0; i < n; ++i) for (int j = 0; j <= n; ++j) {
      cin >> t[i][j];
    }
    V<> dp(1 << n, 1e9);
    dp[0] = 0;
    for (int bit = 0; bit < 1 << n; ++bit) {
      for (int i = 0; i < n; ++i) {
        if (bit & 1 << i) continue;
        dp[bit | 1 << i] = min(dp[bit | 1 << i], dp[bit] + t[i][0]);
        for (int j = 0; j < n; ++j) if (bit & 1 << j) {
          dp[bit | 1 << i] = min(dp[bit | 1 << i], dp[bit] + t[i][j + 1]);
        }
      }
    }
    cout << dp.back() << '\n';
  }
}


Measured memory_bytes: 3476
#!/usr/bin/env python3
import math

N = int(input().split()[0])
X = N / 1.08

if math.floor(math.ceil(X) * 1.08) == N:
    ans = math.ceil(X)
elif math.floor(math.floor(X) * 1.08) == N:
    ans = math.floor(X)
else:
    ans = ":("

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 main(){
   int n,m;scanf("%d%d",&n,&m);
   int ans=0;
   ans+=n*(n-1)/2;
   //printf("%lld %lld %lld %d\n",f(n),(2*f(n-2)),f(n-2),ans);
   ans+=m*(m-1)/2;
   printf("%d\n",ans);
}


Measured memory_bytes: 128
import java.util.*;
class Main {
 
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int val = a - (int)(a/10)*10;
    Integer[] ponArr = new Integer[]{0,1,6,8};
    Integer[] bonArr = new Integer[]{3};
    List<Integer> ponList = Arrays.asList(ponArr);
    List<Integer> bonList = Arrays.asList(bonArr);
    
    if(ponList.contains(val)){
      System.out.println("pon");
    }else if(bonList.contains(val)){
      System.out.println("bon");
    }else{
      System.out.println("hon");
    }
  }
}

Measured memory_bytes: 35688
#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 10;
int a[N], num[N], n, wh[N];
vector<int> gr[N];
void getAns(int v) {
	bool z = false;
	for (auto u : gr[v]) {
		if (wh[u] == -1 && a[u] != a[v])
			z = true;
	}
	if (z) {
//		cout <<"w" << endl;
		wh[v] = 1;
	}
	else {
//		cout << "l" << endl;
		wh[v] = -1;
	}
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) 
		cin >> a[i];
	iota(num, num + n, 0);
	sort(num, num + n, [] (int x, int y) { return a[x] < a[y]; });
	for (int i = 0; i < n - 1; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		gr[y].push_back(x), gr[x].push_back(y);
	}
	for (int i = 0; i < n; i++) {
//		cout << num[i] << " : ";
		getAns(num[i]);
	}
	vector<int> ans;
	for (int i = 0; i < n; i++)
		if (wh[i] == 1)
			ans.push_back(i);
//	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++)
		cout << ans[i] + 1 << " ";
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

void Do(int N, int A, int B){
  int max, min, M, m;
  max = A;
  min = A;
  if(max < B) max = B;
  else min = B;
  M = min;
  m = max + min - N;
  if(m < 0) m = 0;
  printf("%d %d\n", M, m);
}

int main(void){
  int N, A, B;
  scanf("%d %d %d", &N, &A, &B);
  Do(N, A, B);
  return 0;
}

Measured memory_bytes: 128
N,K = gets.split.map &:to_i
H = gets.split.map &:to_i
DP = [0]

1.upto(N-1) do |i|
  min = Float::INFINITY
  [0, i-K].max.upto(i-1) do |j|
    cost = (H[i] - H[j]).abs + DP[j]
    min = cost if min > cost
  end
  DP[i] = min
end

p DP[-1]

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

using namespace std;

int solve(const int stones_height[], int memo[], const int &n){
    int ans;
    if(memo[n] != -1) ans = memo[n];
    else if(n == 2) ans = abs(stones_height[n] - stones_height[n - 1]);
    else if(n == 3) ans = min(abs(stones_height[n] - stones_height[n - 2]), abs(stones_height[n] - stones_height[n - 1]) + solve(stones_height, memo, n - 1));
    else{
        ans = min(abs(stones_height[n] - stones_height[n - 1]) + solve(stones_height, memo, n - 1), abs(stones_height[n] - stones_height[n - 2]) + solve(stones_height, memo, n - 2));
    }
    return memo[n] = ans;
}

int main(){
    int n;
    while(scanf("%d", &n) != EOF){
        int stones_height[n + 1], memo[n + 1];
        for(int i = 0; i < n; i++){
            scanf("%d", &stones_height[i + 1]);
            memo[i + 1] = -1;
        }
        printf("%d\n", solve(stones_height, memo, n));
    }
    return 0;
}

Measured memory_bytes: 7676
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    //int a;
    //cin >> a;
    //スペース区切りの整数の入力
    int b,c;
    cin >> b >> c;
    // 文字列の入力
    string s, t, u;
    //cin >> s;
    // 出力
    s = "Alice";
    t = "Bob";
    u = "Draw";
    if(b==c)
        cout << u << endl;
    else if (b!=1&&c!=1){
    if(b > c)
        cout << s << endl;
    else
        cout << t << endl;
    }
    else if(b==1)
        cout << s << endl;
    else
        cout << t << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int r = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());
		sc.close();
		
		int ans = x;
		for(int i=0; i<10; i++) {
			ans = r*ans - D;
			System.out.println(ans);
		}

	}

}


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

int main(){
  int N, P; cin >> N >> P;
  string S; cin >> S;
  vector<int> A(N);
  rep(i, N) A[i] = S[i] - '0';
  long long ans = 0;
  if (P == 2 || P == 5) {
    rep(i, N) {
      if (A[i] % P == 0) ans += i + 1;
    }
    cout << ans << endl;
    return 0;
  }
  vector<int> Am(N + 1);
  int k = 1;
  for (int i = N - 1; i >= 0; i--) {
    Am[i] = (k * A[i] + Am[i + 1]) % P;
    k = (k * 10) % P;
  }
  map<int, int> mp;
  rep(i, N + 1) mp[Am[i]]++;
  rep(i, N + 1) {
    mp[Am[i]]--;
    ans += mp[Am[i]];
  }
  cout << ans << endl;
}


Measured memory_bytes: 2436
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        string s1, s2;
        if(!(cin >> s1 >> s2))
            return 0;

        int n = s1.size();
        int m = s2.size();

        int ret = 0;
        vector<vector<int> > len(n, vector<int>(m, 0));
        for(int i=0; i<n; ++i){
            if(s1[i] == s2[0])
                ret = len[i][0] = 1;
        }
        for(int i=0; i<m; ++i){
            if(s1[0] == s2[i])
                ret = len[0][i] = 1;
        }

        for(int i=1; i<n; ++i){
            for(int j=1; j<m; ++j){
                if(s1[i] == s2[j]){
                    len[i][j] = len[i-1][j-1] + 1;
                    ret = max(ret, len[i][j]);
                }
            }
        }

        cout << ret << endl;
    }
}

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

int main(){
  int N;
  cin>>N;
  vector<pair<int,int>> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i].first;
    a[i].second=i+1;
  }
  sort(a.begin(),a.end());
  for(int i=0;i<N;i++) printf("%d ",a[i].second);
}


Measured memory_bytes: 1536
a, b, c, d = map(int,input().split())
if a <= 0 <= b or c <= 0 <= d:print(max(a * c,b * d, a * c, b * d,a * d,b * c,0))
else:print(max(a * c,b * d, a * c, b * d,a * d,b * c))


Measured memory_bytes: 61604
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>

using namespace std;


struct Node
{
	int realParent;
	std::set<int> parents;
	std::set<int> children;
};

Node nodes[100010];
int n, m;

int main()
{
	scanf("%d%d", &n, &m);
	
	int limit = n + m - 1;
	int a, b;
	for (int i = 0 ; i < limit ; i++)
	{
		scanf("%d%d", &a, &b);
		
		nodes[a].realParent = -1;
		nodes[a].children.insert(b);
		nodes[b].realParent = -1;
		nodes[b].parents.insert(a);
	}
	
	int rootNode;
	for (int i = 1 ; i <= n ; i++)
	{
		if (nodes[i].parents.size() == 0)
		{
			rootNode = i;
			nodes[rootNode].realParent = 0;
			break;
		}
	}
	
	int curNode;
	std::queue<int> q;
	q.push(rootNode);
	while (!q.empty())
	{
		curNode = q.front();
		q.pop();
		
		std::set<int>::iterator iNode;
		for (iNode  = nodes[curNode].children.begin() ; 
			 iNode != nodes[curNode].children.end() ; 
			 iNode++)
		{
			if (nodes[*iNode].parents.size() == 1)
			{
				q.push(*iNode);
				nodes[*iNode].realParent = curNode;
			}
			else
				nodes[*iNode].parents.erase(curNode);
		}
	}
	
	for (int i = 1 ; i <= n ; i++)
	{
		printf("%d\n", nodes[i].realParent);
	}
	

	return 0;
}


Measured memory_bytes: 20736
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<std::complex<double>> v;
    for (int i = 0; i < n; i++) {
        double x, y;
        std::cin >> x >> y;
        v.emplace_back(x, y);
    }
    std::sort(v.begin(), v.end(), [](auto lhs, auto rhs) { return std::arg(lhs) < std::arg(rhs); });
    double ret = 0;
    for (int i = 0; i < n; i++) {
        std::complex<double> p;
        for (int j = 0; j < n; j++) {
            p += v[(i + j) % n];
            ret = std::max(ret, std::abs(p));
        }
    }

    std::cout << std::fixed << std::setprecision(12) << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
n, w = STDIN.gets.split(/\s+/).map { |s| s.to_i }
wv = [] # [[w0, v0], [w1, v1], ...]
W = 0; V = 1
(1..n).each { |i|
  wv[i] = STDIN.gets.split(/\s+/).map { |s| s.to_i }
}

r = Hash.new(0)
r[0] = 0
(1..n).each { |j|
  r.keys.sort.reverse_each { |w0|
    if w0 + wv[j][W] <= w
      r[w0 + wv[j][W]] = [r[w0 + wv[j][W]], r[w0] + wv[j][V]].max
    end
  }
}
p r.values.max


Measured memory_bytes: 2552
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
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; }
typedef long long ll;
const ll INF = 1LL << 60;


int N;
int a[110000],L[110000],R[110000];
map<int,int> m;


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

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

    if(N==2){
        cout << max(a[0],a[1]) << endl;
        return 0;
    }

    L[0] = 0;
    R[N+1] = 0;
    for(int i = 0; i <= N; ++i){
        L[i+1] = gcd(a[i],L[i]);
    }

    for(int i = N; i >= 0; --i){
        R[i] = gcd(a[i],R[i+1]);
    }

    int ans = 0;
    for(int i = 0; i < N; ++i){
        ans = max(ans, gcd(L[i],R[i+1]));
    }
    
    cout << ans << endl;
}

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

for i in range(n):
    a[i] = a[i] - (i + 1)

a.sort()

if n % 2 == 1:
    median = a[n // 2]
else:
    median = (a[n//2 - 1] + a[n//2]) // 2

ans = 0
for i in range(n):
    ans += abs(a[i] - median)

print(ans)

Measured memory_bytes: 25196
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;//namespace

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define SANKOU(n,a,b) cout << ((n) ? (a) : (b) ) << endl;

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);// warshall-floyd

#define CIN(x) int x;cin>>x;
#define SCIN(x) string x;cin>>x;
#define COUT(x) cout<<(x)<<endl;
#define SCOUT(x) cout<<(x)<<" ";
#define ENDL cout<<endl;

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_;
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl;

#define ALL(obj) (obj).begin(),(obj).end()// iterator

#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end());

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>

#define pb(a) push_back(a)//push_back
#define mp make_pair// make_pair


int main(){

    CIN(n);CIN(m);
    COUT((n-1)*(m-1));

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// typedef
typedef std::vector<int> VI;
typedef std::vector<VI> VII;
typedef std::vector<std::string> VS;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

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

void formula(std::string s, int sofar, std::string exp, std::string &ans) {
  if (s == "") {
    if (sofar == 7) {
      ans = exp + "=7";
    }
    return;
  }
  std::string first = s.substr(0, 1);
  std::string rest = s.substr(1);
  int a = std::stol(first);
  formula(rest, sofar + a, exp + "+" + first, ans);
  formula(rest, sofar - a, exp + "-" + first, ans);
}

void solve() {
  std::string s;
  std::cin >> s;
  
  std::string ans;
  std::string first = s.substr(0, 1);
  std::string rest = s.substr(1);
  formula(rest, std::stol(first), first, ans);
  cout(ans);
}

Measured memory_bytes: 256
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2)
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)

#enumerate input

def main():
    h,w=map(int,input().split())
    stack=deque()
    grid=[["#"]*(w+2)]
    for i in range(h):
        tmp=[]
        for k,v in enumerate(input()):
            if v=="#":
                tmp.append("#")
                stack.appendleft((i+1,k+1))
            else:
                tmp.append(v)
        grid.append(["#"]+tmp+["#"])
    grid.append(["#"]*(w+2))
#    for i in grid:
#        print(*i)
    for i in range(h*w):
        tmp=deque()
        while stack:
            y,x=stack.pop()
            for my,mx in ((0,1),(1,0),(-1,0),(0,-1)):
                if grid[y+my][x+mx]==".":
                    grid[y+my][x+mx]="#"
                    tmp.appendleft((y+my,x+mx))
        stack=tmp
        if not len(stack):
            print(i)
            exit()
if __name__ == '__main__':
    main()


Measured memory_bytes: 128472
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Wall solver = new Wall();
        solver.solve(1, in, out);
        out.close();
    }

    static class Wall {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int h = in.nextInt();
            int w = in.nextInt();

            int[][] c = new int[10][10];
            warshallFloydInit(c);

            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    c[i][j] = Integer.parseInt(in.next());
                }
            }
            warshallFloyd(c);

            long result = 0;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    int v = Integer.parseInt(in.next());
                    if (v == -1 || v == 1) {
                        continue;
                    }
                    result += c[v][1];
                }
            }
            out.println(result);

        }

        static void warshallFloydInit(int[][] g) {
            int n = g.length;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    g[i][j] = (i == j) ? 0 : Integer.MAX_VALUE;
                }
            }
        }

        static void warshallFloyd(int[][] g) {
            int n = g.length;
            for (int k = 0; k < n; k++) {
                for (int i = 0; i < n; i++) {
                    if (g[i][k] == Integer.MAX_VALUE) {
                        continue;
                    }
                    for (int j = 0; j < n; j++) {
                        if (g[k][j] == Integer.MAX_VALUE) {
                            continue;
                        }
                        g[i][j] = Math.min(g[i][j], g[i][k] + g[k][j]);
                    }
                }
            }
        }

    }
}



Measured memory_bytes: 53824
#include <iostream>
#include <stdio.h>
#include <math.h> 
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <string>
#include <numeric>
#include <bitset>
#include <queue>

using namespace std;
vector<long long> pt;
vector<long long> mid;
vector<long long> ans;

int gcd(long long u, long long v) {
	long long r;
	while (0 != v) {
		r = u % v; u = v; v = r; /* swap */
	}
	return u;
}


int main() {
	//input
	long long n,x;
	cin >> n >> x;

	for (long long i = 0; i < n; ++i) {
		long long tmp = 0;
		cin >> tmp;
		pt.push_back(tmp);
	}

	if (n == 1) {
		sort(pt.begin(), pt.end());
		cout << abs(pt[0] - x) << endl;
		return 0;
	}

	pt.push_back(x);
	sort(pt.begin(), pt.end());

	//各差を取得
	for (long long i = 0; i < pt.size() - 1; ++i) {
		long long tmp = 0;
		tmp = pt.at(i + 1) - pt.at(i);
		mid.push_back(tmp);
	}

	//各差の最大公約数
	for (long long i = 0; i < mid.size() - 1; ++i) {
		long long tmp = 0;
		tmp = gcd( mid.at(i + 1) , mid.at(i) );
		ans.push_back(tmp);
	}

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

	cout << ans.at(0) << endl;

	return 0;
}

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;cin>>n;
  vector<ll>A(n);
  vector<ll>B(n);
  for(int i=0;i<n;i++)
    cin>>A[i]>>B[i];
  ll ans=0;
  for(int i=n-1;i>=0;i--){
    if((A[i]+ans)%B[i]){
      ans+=(ll)B[i]-(A[i]+ans)%B[i];
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
// AOJ 1275
#include<iostream>
#include<vector>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

int solve(int n, int k, int m) {
  vector<int> v(n);
  REP(i,n) { v[i] = i; }
  
  int rem = 0;
  REP(i, n-1) {
    v.erase(v.begin()+rem);
    rem = (rem + k - 1) % v.size();
  }
  return (v[0] + m - 1) % n + 1;
}

int main() {
  int n, k, m;
  while (cin >> n >> k >> m and n * k * m) {
    cout << solve(n, k, m) << endl;
  }
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll A, B;
    cin >> A >> B;

    if (A-2*B > 0) {
        cout << A-2*B << endl;
    } else {
        cout << 0 << endl;
    }
    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))

char s[525252];
int n;

short buf[525252];

bool check(int k){
  REP(i,n)buf[i] = s[i]-'0';
  FOR(i,n,525252)buf[i]=0;
  // +k
  int up = 0;
  int kk = k;
  REP(i,525252){
    buf[i] += kk%10;
    buf[i] += up;
    up = buf[i]/10;
    buf[i] %= 10;
    kk /= 10;
  }
  // *9
  int sum = 0;
  up = 0;
  REP(i,525252){
    buf[i] *= 9;
    buf[i] += up;
    up = buf[i]/10;
    buf[i] %= 10;
    sum += buf[i];
  }
  // DEBUG(k);
  // DEBUG(sum);
  // REP(i,n+2)putchar(buf[i]+'0');puts("");
  return sum <= 9*k;
}

int main(){
  scanf("%s",s);
  n = strlen(s);
  reverse(s,s+n);
  int low = 0, high = n;
  // high is ok
  while(low+1<high){
    int mid = (low+high)/2;
    if(check(mid))high=mid;
    else low=mid;
  }
  printf("%d\n",high);
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{
	int n,a,sum=0;
	vi v;
	cin>>n;
	for(int i=0;i<2*n;i++)
	{
		cin>>a;
		v.pb(a);
	}
	sort(v.rbegin(),v.rend());
	for(int i=0;i<2*n;i+=2)
	{
		sum+=v[i+1];
	}
	cout<<sum<<endl;
	return 0;
}

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

typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	vector <ll> a(n + 1, 0);
	for (int i = 1; i <= n; i++)
		cin >> a[i], a[i] += a[i - 1];
	
	vector <vector <ll> > dp(
		n, vector <ll> (n, LLONG_MAX));
	
	for (int len = 1; len <= n; len++)
		for (int l = 0, r = len - 1; r < n; l++, r++) {
			if (len == 1) dp[l][r] = 0;
			for (int i = l; i < r; i++)
				dp[l][r] = min(dp[l][r], dp[l][i] + dp[i + 1][r] + a[r + 1] - a[l]);
		}
	
	cout << dp[0][n - 1] << '\n';
	return 0;
}

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

int dp[3000][3000][2];
int n; 
int a[3000];
int solve(int i,int j, bool turn){
    if(i>j){
        return 0;
    }
    if(dp[i][j][turn]!=-1){
        return dp[i][j][turn];
    }
    if(turn){
    return dp[i][j][1]=max(a[i]+solve(i+1,j,0), a[j]+solve(i,j-1,0));
    }
    return dp[i][j][0]=min(solve(i+1,j,1), solve(i,j-1,1));
}
int32_t main() {
  cin>>n;
  memset(dp, -1, sizeof dp);
  int sum=0;
  for(int i=0;i<n;++i){
      cin>>a[i];
      sum+=a[i];
  }
     int x=solve(0,n-1, 1);
     int y=sum-x;
     cout<<x-y;





return 0;
}


Measured memory_bytes: 144420
k, a, b = map(int,input().split())
ans = 1

if b-a < 3 or a >= k:
    ans += k
else:
    ans += (a-1)
    k -= (a-1)
    tmp = k//2
    k -= 2*tmp
    ans += ((b-a)*tmp) + k%2

print(ans)


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

int main(){
	int a;
	cin>>a;
	if(a>=64){
		cout<<64<<endl;
	}
	else if(a>=32){
		cout<<32<<endl;
	}
	else if(a>=16){
		cout<<16<<endl;
	}
	else if(a>=8){
		cout<<8<<endl;
	}
	else if(a>=4){
		cout<<4<<endl;
	}
	else if(a>=2){
		cout<<2<<endl;
	}
	else{
		cout<<1<<endl;
	}
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int n, m;
  cin >> n >> m;
  vector<int> solved(n);
  vector<int> wa_count(n);
  for (int i = 0; i < m; i++) {
    int p;
    string code;
    cin >> p >> code;
    p--;
    if (code == "AC") {
      solved[p] = 1;
    } else {
      if (!solved[p]) wa_count[p]++;
    }
  }

  int ac_count = 0;
  int penalty = 0;
  for (int i = 0; i < n; i++) {
    if (solved[i]) {
      ac_count++;
      penalty += wa_count[i];
    }
  }
  cout << ac_count << " " << penalty << endl;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  int x = b*10;
  for(int i=x;i<x+10;i++){
    if(a==i*2/25){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

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

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; ++i)cin >> a[i];
	sort(a.begin(), a.end());
	for (ll i = 1; i < n; ++i) {
		if (a[i - 1] == a[i]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int a[110],b[110];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		cin>>a[i];
	}
	b[0]=b[1]=a[0];
	for(int i=1;i<n-1;i++){
		if(a[i]<=a[i-1])
		b[i]=b[i+1]=a[i];
		else b[i+1]=a[i];
	}
	int ans=0;
	for(int i=0;i<n;i++)
	ans+=b[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> arr;
	for(int i =0;i<n;i++)
	{
		int a;
		cin>>a;
		arr.push_back(a);
	}
	sort(arr.begin(),arr.end());
	bool ok = true;
	for(int i =0;i<arr.size()-1;i++)
	{
		if(arr[i] == arr[i+1])
		{
			ok = false;
			break;
		}
		else
			continue;
	}
	if(ok)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
		
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n,0);
    rep(i,n) cin >> a.at(i);
    for(int i = n; i >= 1;i--){
        int x = a.at(i-1);
        ll now = 0;
        for(int j = i;j <= n;j+=i) now += b.at(j-1);
        if(a.at(i-1) % 2 != now % 2) b.at(i-1)++;
    }
    ll total = 0;
    rep(i,n) total+=b.at(i);
    cout << total << endl;
    rep(i,n) if(b.at(i) > 0) cout << (i+1) << endl;
}

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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int k;
	string s;

	cin >> k >> s;

	if (s.size() <= k) cout << s << endl;
	else {
		cout << s.substr(0, k);
		cout << "..." << endl;
	}
}


Measured memory_bytes: 3624
a[5000],i,j,s,m;main(n,S){for(;~scanf(S="%d\n",&n);n&&printf(S,m))for(m=-1e5,i=0;i<n;)for(s=!scanf(S,a+i),j=++i;j--;m=s>m?s:m)s+=a[j];}

Measured memory_bytes: 0
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    			
    		Scanner scan =new Scanner(System.in);
    		
    		int n=Integer.parseInt(scan.next());
    		int k=Integer.parseInt(scan.next());
    		
    		if(n%k>0) {
    			System.out.print(1);
    		}else {
    			System.out.print(0);
    		}
   
     
    }
    }
// end 

Measured memory_bytes: 21716
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np

a, b, c = MAP()
if 4*a*b < (c-a-b)**2 and c-a-b > 0:
	print("Yes")
else:
	print("No")


Measured memory_bytes: 5200
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
int n,tmp,best,t;
int g[100005];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>g[i];
	for(int i=1;i<=n;i++)
		if(g[i]==i)tmp=g[i],g[i]=g[i+1],g[i+1]=tmp,best++;
	cout << best<<"\n";
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
    int a,b,X,Y,Z;
	
	scanf("%d %d",&a,&b);
    X = a + b;
    Y = a - b;
    Z = a * b;
    if(X >= Y){
        if(X >= Z){
            printf("%d",X);
        }else{
            printf("%d",Z);
        }
    }else if(Y >= Z){
        printf("%d",Y);
    }else{
        printf("%d",Z);
    }
	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////




int main() {

	ll N;
	cin >> N;
	vector<ll> A(N + 1);
	
	repn(i, N) cin >> A[i];

	vector<ll> c(N + 1, 0);
	repn(i, N) c[A[i]]++;

	ll ans = 0;
	repn(i, N) ans += c[i] * (c[i] - 1) / 2;

	repn(i, N) {
		cout << ans - c[A[i]] + 1<<endl;
	}

	system("PAUSE");

}


Measured memory_bytes: 5888
s = int(input())
m = [0]*10**7
m[s]=1
a = 1

while True:
    a +=1
    if s%2==0:
        s//=2
    else:
        s=3*s+1
    if m[s]==1:
        print(a)
        exit()
    else:
        m[s]=1


Measured memory_bytes: 116336