akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;



int main(){
  ll N, K;
  cin>>N>>K;
  vector<ll> P(N), C(N);
  rep(i, N){
    cin>>P[i];
    P[i]--;
  }
  rep(i, N){
    cin>>C[i];
  }
  ll Ans=-1*INF;
  rep(i, N){
    ll Score=0;
    ll Turn=0;
    ll Now=i;
    while(1){
      Now=P[Now];
      Score+=C[Now];
      Turn++;
      if(Now==i)break;
    }
    if(Score<0){
      ll Sum=0;
      rep(j, Turn){
        Now=P[Now];
        Sum+=C[Now];
        Ans=max(Ans, Sum);  
      }
      continue;
    }
    //cout<<Turn<<" "<<Score<<endl;
    ll Sum=0;
    ll Role=K/Turn;
    ll Nokori=K;
    if(Role>0){
      Sum+=Score*(Role-1);
      Nokori-=(Role-1)*Turn;
    }
    //cout<<"Role"<<Role<<endl;
    ll Max=-1*INF;
    if(Nokori<K)Max=Sum;
    Now=i;
    //cout<<"Nokori"<<Nokori<<endl;
    rep(j, Nokori){
      Now=P[Now];
      Sum+=C[Now];
      Max=max(Sum, Max);
    }
    //cout<<Max<<endl;
    Ans=max(Ans, Max);
  }
  cout<<Ans<<endl;
}

Measured memory_bytes: 3704
def get_input():
    input_data = int(input())
    return input_data

def get_data_list():
    data_list = input().split()
    for i in range(len(data_list)):
        data_list[i] = int(data_list[i])
    return data_list

class Checker:
    def __init__(self, sorted_list):
        self.sorted_list = sorted_list
        self.a = 0
        self.b = 1
        self.min_num = float("inf")
        self.try_num = len(self.sorted_list) - 1 # for not subtract last + 1 from last

    def detect_min_num(self):
        for i in range(self.try_num):
            tmp_num = self.sorted_list[self.b] - self.sorted_list[self.a]
            if tmp_num <= self.min_num:
                self.min_num = tmp_num
            self.a, self.b = self.b, self.b + 1


if __name__ == "__main__":
    while True:
        student_num = get_input()
        if student_num == 0:
            break
        data_list = get_data_list()
        sorted_list = sorted(data_list)
        # print("data_list", data_list) # debug
        # print("sorted_list", sorted_list) # debug
        checker = Checker(sorted_list)
        checker.detect_min_num()
        min_num = checker.min_num
        # print("min_num", min_num) # debug
        print(min_num)




Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    cin>>str;
    int z=0,o=0;
    for(int i=0;str[i];i++)
    {
        if(str[i]=='0')
            z++;
        else
            o++;
    }
    cout<<(2*min(z,o))<<endl;
    return 0;
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def divisors(n):
    S,T=[],[]
    for i in range(1,int(n**.5)+1):
        if(n%i==0):
            S.append(i)
            T.append(n//i)
    T.reverse()
    return S+T if(S[-1]!=T[0]) else S+T[1:]

def resolve():
    n = int(input())
    res = set(divisors(n-1))
    res.remove(1)
    res.add(n)

    for s in divisors(n):
        if s == n:
            continue
        tmp = s
        t = n // s
        if s < t: # s >= t
            continue
        while s % t == 0:
            s //= t
        s %= t
        if s == 1:
            res.add(tmp)

    print(len(res))
resolve()

Measured memory_bytes: 39152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

const ll N=1e5+10;
mat G(N);
vec w(N),b(N);

void dfs(ll cur,ll pre) {
  w[cur]=1,b[cur]=1;
  for(ll nex:G[cur]) {
    if(nex==pre) continue;
    dfs(nex,cur);
    (b[cur]*=w[nex])%=mod;
    (w[cur]*=w[nex]+b[nex])%=mod;
  }
}

int main() {
  ll n;
  cin >> n;
  for(ll i=0;i<n-1;i++) {
    ll x,y;
    cin >> x >> y;
    x--,y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(0,-1);
  cout << (w[0]+b[0])%mod << endl;
}

Measured memory_bytes: 14208
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <string>
#include<vector>
#include <utility>
#include <cstdio>
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    cin>>n;
    ll h[n];
    for(ll i=0;i<n;i++){
        cin>>h[i];
    }
    ll m= 999999999;
    ll dp[n];
    dp[0]=0;
    for(ll i=1;i<n;i++)
        dp[i]=m;
    for(ll i=0;i<n;i++){
        for(ll j=i+1;j<=i+2;j++){
            if(j<n){
                dp[j]= min(dp[j],dp[i]+abs(h[i]-h[j]));
            }
        }
    }
    cout<<dp[n-1];
}




Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
V<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
V<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    int n; cin >> n;
    V<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] >= a[i-1]) continue;
        ans += a[i-1] - a[i];
        a[i] = a[i-1];
    }
    cout << ans << endl;

    return 0;
}

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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type / Class / Struct Definitions:
using ll = long long;
using ull = unsigned long long;

//Constants:
const int INF = (1ll << 30) - 1;  //nearly 1.07e9
const ll INFLL = 1ll << 60;       //nearly 1.15e18
const int MOD = 1e9 + 7;
const long double EPS = 1.0e-14;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

//================ Main Loop ================
int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a), q(b), r(c);
    rep(i, a) {
        cin >> p[i];
    }
    rep(i, b) {
        cin >> q[i];
    }
    rep(i, c) {
        cin >> r[i];
    }
    sort(all(p), greater<int>());
    sort(all(q), greater<int>());
    sort(all(r), greater<int>());

    vector<int> apples;

    rep(i, x) {
        apples.emplace_back(p[i]);
    }
    rep(i, y) {
        apples.emplace_back(q[i]);
    }
    rep(i, min(x + y, c)) {
        apples.emplace_back(r[i]);
    }
    sort(all(apples), greater<int>());

    ll ans = 0;
    rep(i, x + y) {
        ans += apples[i];
    }

    cout << ans << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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


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

using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORD(i, m, n) for (int i = m; i >= n; i--)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 0; i <= n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using ll = long long;
using ull = unsigned long long;
using ld = long double;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin>>n;
	string s;
	cin>>s;
	string s1=s;
	sort(s.begin(),s.end());
	int ans=0;
	REP(i, n) {
		if(s[i]!=s1[i])ans++;
	}
	cout << ans/2 << endl;

	return 0;
}

Measured memory_bytes: 3872
package main

import (
	"fmt"
	"math"
)

func rad(x float64) float64 {
	return x * math.Pi / 180.0
}

func main() {
	var a, b, h, m int
	fmt.Scan(&a, &b, &h, &m)
	hangle := float64(30*h) + 0.5*float64(m)
	mangle := float64(6 * m)
	angle := math.Abs(hangle - mangle)
	c2 := float64(a*a+b*b) - float64(2*a*b)*math.Cos(rad(angle))
	ans := math.Sqrt(c2)
	fmt.Printf("%.10f\n", ans)
}


Measured memory_bytes: 1840
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, s;
            string[] word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);
            int m = a;
            if (b > m) m = b;
            if (c > m) m = c;
            s = a + b + c - m;
            Console.WriteLine(s);

            //Console.ReadKey();
        }
    }
}


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

using namespace std;

int* inputArray(int num){
    int* ans;
    ans = new int[num];
    for(int i = 0; i < num; i++){
        scanf("%d", &ans[i]);
    }
    return ans;
}

int max(int* nums, int size){
    int ans = nums[0];
    for(int i = 1; i < size; i++){
        if(ans < nums[i]){
            ans = nums[i];
        }
    }
    return ans;
}

int main(){
    int n;
    int *a;
    cin >> n;
    a = inputArray(n);
    bool* flag = new bool[max(a, n)];
    for(int i = 0; i < n; i++){
        if(flag[a[i]]){
            cout << "NO" << endl;
            return 0;
        }else{
            flag[a[i]] = true;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 976896
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
	#define SAY(X) cout << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

void solve() {
	int n = fetch<int>();
	auto a = fetch_vec<int>(n);
	auto b = fetch_vec<int>(n);

	auto ord_a = a;
	sort(ord_a.begin(), ord_a.end());

	auto ord_b = b;
	sort(ord_b.begin(), ord_b.end());

	for(int i = 0; i < n; ++i) {
		if(ord_a[i] > ord_b[i]) {
			cout << "No\n";
			return;
		}
	}

	for(int i = 1; i < n; ++i) {
		if(ord_b[i - 1] == ord_b[i]) {
			cout << "Yes\n";
			return;
		}
	}

	vector<int> fst(n);

	for(int i = 0; i < n; ++i) {
		fst[i] = lower_bound(ord_b.begin(), ord_b.end(), ord_a[i]) - ord_b.begin();
	}

	sort(fst.begin(), fst.end());
	DBG(fst);

	for(int i = 1; i < n; ++i) {
		if(fst[i - 1] == fst[i]) {
			cout << "Yes\n";
			return;
		}
	}

	vector<pii> ba(n);

	for(int i = 0; i < n; ++i) {
		ba[i].first = b[i];
		ba[i].second = a[i];
	}

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

	vector<int> p(n, NIL), used(n, 0);
	map<int, int> val_to_pos;
	int cycles = 0;

	for(int i = 0; i < n; ++i) {
		val_to_pos[ba[i].second] = i;
	}

	for(int i = 0; i < n; ++i) {
		p[i] = val_to_pos[ord_a[i]];
	}

	DBG(p);

	for(int i = 0; i < n; ++i) {
		if(!used[i]) {
			++cycles;

			for(int j = i; !used[j]; j = p[j]) {
				used[j] = 1;
			}
		}
	}

	DBG(cycles);
	cout << (cycles > 1 ? "Yes\n" : "No\n");
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 8448
#include<stdio.h>
int main() {
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>=-1000 && a<=1000 && b>=-1000 && b<=1000) {
		if(a<b) {
			printf("a < b\n");
		} else if(a>b) {
			printf("a > b\n");
		} else if(a==b) {
			printf("a == b\n");
		}	
	}
	return 0;
}

Measured memory_bytes: 1752
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int M ,N;
    std::vector<int> A;
    cin >> M >> N;
    int sum = 0;
    for(int i =0; i < N; i++){
        int tmp;
        cin >> tmp;

        sum += tmp;
    }
    cout << ((0 <= M - sum)? M- sum : -1) << endl;
    
}


Measured memory_bytes: 3636
#include <iostream>

int main(){
    int a,b,c;
    std::cin>>a>>b>>c;
    if(c/a-b/a>=1){
        std::cout<<"OK"<<std::endl;
    }else if(b%a==0){
        std::cout<<"OK"<<std::endl;
    }else {
        std::cout<<"NG"<<std::endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n,a,b; cin >> n >> a >> b;
    vl v(n);
    rep(i,n) cin >> v[i];
    sort(v.rbegin(), v.rend());
    double value = 0.0;
    rep(i,a){
        value += v[i];
    }
    value = value / (double)a;
    printf("%.8f\n",value);
    ll ans = 0;
    if(v[0] == v[a-1]){
        ll cnt = 0;
        rep(i,n) if(v[0] == v[i]) cnt++;
        REP(i,a,b+1){
            if(v[i-1] != v[0]) break;
            ll t = 1;
            rep(j,i){
                t *= cnt-j;
                t /= j+1;
            }
            ans += t;
        }
    }else{
        ll cnt1 = 0;
        ll cnt2 = 0;
        rep(i,n) if(v[i] == v[a-1]) cnt1++;
        rep(i,n){
            if(v[i] == v[a-1]) break;
            cnt2++;
        }
        cnt2 = a - cnt2;
        ans = 1;
        rep(i,cnt2){
            ans *= cnt1 - i;
            ans /= i+1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e18;
const ll MOD = 1000000007;  // 1e9 + 7

template<typename T> void print_queue(T& q) {
  vector<ll> tmp;
  while(!q.empty()) {
    ll v = q.top();
    cout << v << " ";
    q.pop();
    tmp.push_back(v);
  }
  for (auto v : tmp) {
    q.push(v);
  }
  cout << endl;
}

// The size of "smaller" is equal or larger by 1.
priority_queue<ll> smaller; // decreasing order
priority_queue<ll, vector<ll>, greater<ll>> larger; // increasing order

void balance() {
  while (1) {
    ll s_size = smaller.size();
    ll l_size = larger.size();
    if ((s_size == l_size) || (s_size == l_size+1)) { return; }

    if (s_size > l_size) {
      ll v = smaller.top(); smaller.pop();
      larger.push(v);
    } else { // s_size < l_size
      ll v = larger.top(); larger.pop();
      smaller.push(v);
    }
  }
}

void add(ll v) {
  if (smaller.size() == 0) {
    smaller.push(v);
    return;
  }

  if (v <= smaller.top()) {
    smaller.push(v);
  } else {
    larger.push(v);
  }

  balance();

  // For Debug
  // cout << "smaller: " << endl;
  // print_queue(smaller);
  // cout << "larger: " << endl;
  // print_queue(larger);
}

ll current() {
  return smaller.top();
}

int main(int argc, char** argv) {
  ll Q;
  cin >> Q;

  bool updated = false;
  ll f_min = 0; // The minimum f(x) of each step.

  rep(i, Q) {
    int t;
    cin >> t;
    if (t == 1) { // update
      ll a, b;
      cin >> a >> b;

      if (!updated) { // first state.
        updated = true;
        f_min = b;
        add(a);
      } else {
        bool prev_balanced = (smaller.size() == larger.size());
        ll old_x = current();
        add(a);
        ll new_x = current();

        // from prev
        if (prev_balanced) {
          if (new_x < old_x) {
            f_min += abs(new_x - old_x);
          } else {
            // Do nothing.
          }
        } else { // old_x is an unique minimum point.
          f_min += abs(new_x - old_x);
        }
        f_min += b + abs(new_x - a);
      }
    } else { // query
      cout << current() << " " << f_min << endl;
    }
  }
}


Measured memory_bytes: 3828
#include<stdio.h>
#include<stack>
#include<vector>
using namespace std;

int main() {
  char c;
  stack<int> a;
  stack<pair<int, int> > b;
  for ( int i = 0; scanf("%c", &c) != EOF; i++ ) {
    if ( c == '\\' ) a.push(i);
    else if ( c == '/' && !a.empty()) {
      int correspond = a.top();
      a.pop();
      int tv = i - correspond;
      while(!b.empty() && b.top().first > correspond) {
        tv += b.top().second;
        b.pop();
      }
      b.push(make_pair(correspond, tv));
    }
  }

  int tv = 0;
  vector<int> vv;
  while(!b.empty()) {
    int v = b.top().second;
    vv.push_back(v);
    tv += v;
    b.pop();
  }

  printf("%d\n%lu", tv, vv.size());
  for (vector<int>::reverse_iterator ri = vv.rbegin(); ri != vv.rend(); ri++ ) {
    printf(" %d", *ri);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2848
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, m;
vector<vector<int>> g;
vector<bool> vis;

i64 dfs(int u) {
  if (vis[u]) return 0;
  vis[u] = true;
  i64 s = u <= n;
  for (int v : g[u]) {
    s += dfs(v);
  }
  return s;
}

int main() {
  cin >> n >> m;
  init_n(g, n + m + 1);
  for (int i = 1; i <= n; ++i) {
    i64 k; cin >> k;
    for (i64 j = 0; j < k; ++j) {
      i64 l; cin >> l;
      l += n;
      g[i].push_back(l);
      g[l].push_back(i);
    }
  }
  init_n(vis, n + m + 1);
  cout << (dfs(1) == n ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 8440
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.List (unfoldr)
import Data.Bifunctor (first)
import Control.Monad
import Control.Monad.ST
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS
import Data.Bits

type SegTree a = (Int, U.Vector a)
type MSegTree s a = (Int, U.MVector s a)

queryM :: Int -> MSegTree s Int64 -> ST s Int64
queryM !i (!depth, vec) = UM.read vec (2^depth - 1 + i)

-- queryRangeM i j st == maximum <$> sequence [query k st | k <- [i..j-1]]
queryRangeM :: Int -> Int -> MSegTree s Int64 -> ST s Int64
queryRangeM !i !j (!depth, vec) | i < j = doQuery 0 depth i j
                                | otherwise = return minBound
  where
    -- Invariant: 0 <= k*2^l <= i < j <= (k+1)*2^l <= 2^depth
    doQuery !k 0 !i !j | i == k, j == k+1 = UM.read vec (2^depth - 1 + k)
                       | otherwise = error "query"
    doQuery !k l !i !j | i == (k `shiftL` l), j == (k+1) `shiftL` l = UM.read vec (2^(depth-l) - 1 + k)
                       | m <= i = doQuery (2*k+1) (l-1) i j
                       | j <= m = doQuery (2*k) (l-1) i j
                       | otherwise = max <$> doQuery (2*k) (l-1) i m <*> doQuery (2*k+1) (l-1) m j
      where m = (2*k+1) `shiftL` (l-1)

set :: Int -> MSegTree s Int64 -> Int64 -> ST s ()
set !i (!depth, vec) !x = forM_ [0..depth] $ \k ->
  UM.modify vec (max x) (2^k - 1 + (i `shiftR` (depth - k)))

main = do
  n <- readLn
  hs <- U.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  as <- U.unfoldrN n (readInt64 . BS.dropWhile isSpace) <$> BS.getLine
  let ht = U.create $ do
        ht <- UM.new n
        flip U.imapM_ hs $ \i h -> do
          UM.write ht (h - 1) i
        return ht
  let (h2i,m) = runST $ do
        h2i <- UM.new n
        let loop !i !j !k | i == n = return k
                          | otherwise = do
                              let j' = ht U.! i
                                  k' = if j < j' then k else k+1
                              UM.write h2i i k'
                              loop (i+1) j' k'
        k <- loop 0 0 0
        h2i <- U.unsafeFreeze h2i
        return (h2i,k+1)
  let depth = ceiling (logBase 2 (fromIntegral m) :: Double) :: Int
  let result = U.create $ do
        vec <- UM.replicate (2^(depth+1)-1) 0
        let st = (depth, vec)
        forM_ [0..n-1] $ \i -> do
          let h = hs U.! i
              k = h2i U.! (h-1)
          x <- queryRangeM 0 (k+1) st
          set k st (x + as U.! i)
        return vec
  print $ U.head result

readInt64 :: BS.ByteString -> Maybe (Int64, BS.ByteString)
readInt64 s = first fromIntegral <$> BS.readInt s


Measured memory_bytes: 19068
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <complex>
#include <queue>
#include <stack>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
  int r,d,x;
  cin>>r>>d>>x;
  rep(_,10){
    x=r*x-d;
    cout<<x<<endl;
  }
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
/// my holy template
# define F first    
# define S second
# define mp make_pair
# define pii pair<int,int>         
/// eveything goes according to my plan
# define long long long  
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
/// countdown BEGAN. 10 , 9 , 8 ...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right
/// dzyn dzyn dzyn   
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long MXLL = 9223372036854775807;
const int Sz = 1110111;

using namespace std;

inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm("rdtsc" : "=A"(seed));
  srand(seed);
}
int a, b, n;     
                              
int main() 
{
  Read_rap ();
  cin >> n >> a >> b;

  cout << min (b, a * n);


  return 0;
} 










// Coded by Z...

Measured memory_bytes: 256
n,*a=map(int,open(0).read().split())
b,m=sum(a),n*-~n//2
n-=1
c=b//m
f=b%m>0
for i,j in zip(*[iter([a[-1]]+a*2)]*2):
  j-=i
  if n:
    t=min(0,j//n)
    f|=c!=j+n*-t-t
print('YNEOS'[f::2])

Measured memory_bytes: 69920
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<sstream>
#include<map>
#include<algorithm>
using namespace std;

string change(string,int);

int main(){
   int n,i;
   int pl;
   string str,z;
   string::size_type ind;
   
   cin>>n;
   getline(cin,z);
   for(i=0;i<n;i++){
      getline(cin,str);
      
      ind=str.find("Hoshino");
      while(ind!=string::npos){
         pl = (int)str.find("Hoshino");
         str = change(str,pl);
         ind = str.find("Hoshino");
      }
      cout<<str<<endl;
   }
   return 0;
}

string change(string str,int pl){
   int i,l=0;
   string name = "Hoshina";
   
   for(i=pl;i<pl+7;i++){
      str[i]=name[l];
      l++;
   }
   return str;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    string S[N];
    int T[N];
    for(int i = 0; i < N;i++)cin >> S[i] >> T[i];
    
    string tar;
    cin >> tar;
    
    bool flag = false;
    int sum = 0;
    
    for(int i = 0; i< N;i++){
        
        if(flag)sum += T[i];
        if(tar==S[i])flag = true;
    }
    cout << sum <<endl;
}


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

const double inf = (int)1e8;

int cost[2][100][100];
int d[100];
bool used[100];
int n, m;

int dijkstra(int s, int e, int req){
	fill(d, d+m, inf);
	fill(used, used+m, false);
	d[s] = 0;

	while(true){
//		cout << "hogehoge" << endl;

		int v = -1;

		for(int u =  0; u < m; u++){
			if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
		}

		if(v == -1) break;

		used[v] = true;

		for(int u = 0; u < m; u++){
			d[u] = min(d[u], d[v] + cost[req][v][u]);
		}
	}
	return d[e];
}

//#define DEBUG

int main(){
	while(cin >> n >> m){
		if(n == 0 && m == 0) break;
		for(int i = 0; i < 2; i++){
			for(int j = 0; j < m; j++)
				for(int k = 0; k < m; k++){
					cost[i][j][k] = inf;
				}
		}
		for(int i = 0; i < n; i++){
			int a, b, c, t;
			cin >> a >> b >> c >> t;
			a--; b--;
			cost[0][a][b] = c;
			cost[0][b][a] = c;

			cost[1][a][b] = t;
			cost[1][b][a] = t;
		}

#ifdef DEBUG
	//test
		for(int i	= 0; i < m; i++){
			for(int j = 0; j < m; j++){
				cout << cost[0][i][j] << " ";
			}
		}
#endif

		int  num;
		cin >> num;
		for(int i = 0; i < num; i++){
			int p, q, req;
			cin >> p >> q >> req;
			p--; q--;
			cout << dijkstra(p, q, req) << endl;
		}
	}
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
template<typename T>
struct UnionFind
{
	vector<T> par;
	vector<T> rank;
	vector<T> sizes;
	UnionFind(T n):par(n),rank(n,0),sizes(n,1){
	   for(T i=0;i<n;i++){
	     par[i]=i;
	   }
	}
	T root(T x){
	  return par[x]==x?x:par[x]=root(par[x]);
	}
	bool unite(T x,T y){
	  if(x==y) return false;
	  x=root(x); y=root(y);
	  if(x==y) return false;
	  if(rank[x]<rank[y]) swap(x,y);
	  if(rank[x]==rank[y]) rank[x]++;
	  par[y]=x;
	  sizes[x]=sizes[x]+sizes[y];
	  return true;
	}
	bool same(T x,T y){
	  return root(x)==root(y);
	}
	T size(T x){
	  return sizes[root(x)];
	}
};
int main(){
  ll n,m;
  cin>>n>>m;
  vll a(m),b(m);
  rep(i,m) cin>>a[i]>>b[i];
  vll ans(m);
  UnionFind<ll> uf(n+1);
  ans[m-1]=(n*(n-1)/2);
  for(int i=m-1;i>0;i--){
    if(uf.same(a[i],b[i])){
      ans[i-1]=ans[i];
    }
    else{
      ans[i-1]=ans[i]-uf.size(a[i])*uf.size(b[i]);
      uf.unite(a[i],b[i]);
    }
  }
  rep(i,m){
    COUT(ans[i]);
  }
}


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

#define ll long long
#define PB push_back
#define PII pair<int, int>
#define MP make_pair
#define all(x) x.begin(), x.end()
#define REP(x, y, z) for(int x = y; x <= z; x++)
#define REPP(x, y, z) for(int x = y; x >= z; x--)
#define F first
#define S second
#define MSET(x, y) memset(x, y, sizeof(x)) 
#define EB emplace_back
#define maxn

//structure

//declaration
string str;
//functions

bool check(string ss)
{
	int k = 0;
	for(int i = 0; i < str.size(); i++)
	{
		if(str[i] == ss[k])
		{
			k++;
			if(k == 3)
				return true;
		}
	}

	return false;
}
int main(void)
{
	#ifdef DBG
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
	#endif

	int n;
	

	scanf("%d\n", &n);
	cin >> str;

	string tmp;
	int ans = 0;

	for(char i = '0'; i <= '9'; i++)
	{
		for(char j = '0'; j <= '9'; j++)
		{
			for(char k = '0'; k <= '9'; k++)
			{
				tmp = "";
				tmp += i;
				tmp += j;
				tmp += k;

				if(check(tmp))
					ans++;
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var w, h, x, y float64
	fmt.Scan(&w, &h, &x, &y)
	area := w * h / 2
	var hasMultipleAnswer int
	if x == w/2 && y == h/2 {
		hasMultipleAnswer = 1
	} else {
		hasMultipleAnswer = 0
	}
	fmt.Printf("%v %v\n", area, hasMultipleAnswer)
}


Measured memory_bytes: 512
s = input()
q = int(input())

head = []
tail = []
flip = 0

for i in range(q):
	query = input().split()
	if query[0] == '1':
		flip ^= 1
	else:
		f = int(query[1]) - 1
		c = query[2]
		if (f ^ flip) == 0:
			head.append(c)
		else:
			tail.append(c)

if flip:
	head, tail = tail, head
	s = s[::-1]

head = ''.join(head)
tail = ''.join(tail)

print(head[::-1] + s + tail)

Measured memory_bytes: 70104
object Main {
  def main(args: Array[String]): Unit = {
    val num  = scala.io.StdIn.readInt
    var snum = calcSnum(num)

    if(num%snum == 0) println("Yes")
    else              println("No")
  }

  def calcSnum(num: Int): Int = {
    if(num < 10) return num
    else         return num%10 + calcSnum(num/10)
  }
}

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

//cmdで g++ test.cpp とするとコンパイルできる
typedef long long ll;

const int MOD=1000000007;

//https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

int main() {
    int H,W;
    cin>>H>>W;
    vector<vector<char>> M(H,vector<char>(W,0));
    for(int i=0;i<H;i++){
        string s;
        cin>>s;
        for(int j=0;j<W;j++){
            M.at(i).at(j)=s.at(j);
        }
    }

    int ans=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(M.at(i).at(j)=='#')continue;
            vector<vector<int>> dist(H,vector<int>(W,MOD));
            queue<pair<int,int>> Q;
            dist.at(i).at(j)=0;
            Q.push(make_pair(i,j));

            while(!Q.empty()){
                int qx=Q.front().first,qy=Q.front().second;
                Q.pop();
                int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
                for(int k=0;k<4;k++){
                    int x=qx+dx[k],y=qy+dy[k];
                    if(x<0||H<=x||y<0||W<=y)continue;
                    if(M.at(x).at(y)!='.'||dist.at(x).at(y)<MOD)continue;
                    Q.push(make_pair(x,y));
                    dist.at(x).at(y)=dist.at(qx).at(qy)+1;
                    ans=max(ans,dist.at(x).at(y));
                }
            }
        }
    }
    cout<<ans<<endl;
}


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

using ll=long long;

ll a(int n){
    return (1LL<<(n+1))-1;
}
ll b(int n){
    return (1LL<<(n+2))-3;
}

ll dfs(int n,ll x){
    if(n==0 && x==1) return 1;
    if(x==0) return 0;
    if(x==1) return 0;
    x--;
    if(x<=b(n-1)) return dfs(n-1,x);
    x-=b(n-1);
    ll res=a(n-1);
    if(x==0) return res;
    x--;
    res++;
    if(x<=b(n-1)) return res+dfs(n-1,x);
    return res+a(n-1);
}

int main(){
    int n;
    ll x;
    cin>>n>>x;
    cout<<dfs(n,x)<<endl;
    return 0;
}

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

int main()
{

        int A, B, H, M;
        cin >> A >> B  >> H >> M;

        double mrad = 2.0 * M_PI / 60.0 * M;
        double hrad = (2.0 * M_PI / 12.0 * H ) + (2.0 * M_PI  / 12.0 / 60.0 * M);

        double angle1 = abs(mrad - hrad);

        double angle2 = 360.0 - angle1;

        double hang = min(angle1, angle2);

        double ax = A;
        double ay = 0.0;
        double cosv = cos(hang);
        double sinv = sin(hang);
        double bx = (cosv * B);
        double by = (sinv * B);

        double tmp = ((bx - ax) * (bx - ax)) + ((by - ay) * (by - ay));
        tmp = sqrt(tmp);
        printf("%.20lf\n", tmp);

}


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

int n, m;
char s[505][505];
char a[505][505], b[505][505];
int main()
{
    scanf("%d%d\n", &n, &m);
    for(int i = 1; i <= n ; ++i) scanf("%s", s[i] + 1);
    for(int i = 1; i <= n ; ++i) for(int j = 1; j <= m ; ++j) a[i][j] = s[i][j], b[i][j] = a[i][j];
    for(int i = 1; i <= n ; i += 2){
        for(int j = 1; j < m ; ++j) a[i][j] = '#';
        a[i + 1][1] = '#';
        for(int j = 2; j <= m ; ++j) b[i + 1][j] = '#';
        b[i][m] = '#';
    }
    for(int i = 1; i <= n ; ++i) printf("%s\n", a[i] + 1);
    printf("\n");
    for(int i = 1; i <= n ; ++i) printf("%s\n", b[i] + 1);
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    int res = 0;
    int now = 1;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] == now){
            res++;
            now++;
        }
    }
    if (res == 0) cout << -1 << endl;
    else cout << n - res << endl;
}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





int main() {
  ll n;
  string s,t;
  cin>>n>>s>>t;

  ll ans=1;
  int pre=0;
  rep(i,n){
    if(s[i]==t[i]){
      if(pre==0) ans*=3;
      if(pre==1) ans*=2;
      pre=1;
      ans%=mod;
    }
    if(s[i]!=t[i]){
      if(pre==0) ans*=6;
      if(pre==1) ans*=2;
      if(pre==2) ans*=3;
      pre=2;
      i++;
      ans%=mod;
    }
  }

  cout << ans << endl;
}


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

int main(){
  string s;
  cin>>s;
  bool check=true;
  for(char c='a';c<='z'&&check;c++){
    for(int i=0;i<s.length();i++){  		
      if(s.at(i)==c){
      	check = !check;
      }
  	}
  }
  cout<<(check?"Yes":"No")<<endl;
  return 0;
}

Measured memory_bytes: 256
/* ***********************************************
Author        :guanjun
Created Time  :2016/8/21 20:02:42
File Name     :at003a.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
	int x,y;
};
struct cmp{
    bool operator()(Node a,Node b){
        if(a.x==b.x) return a.y> b.y;
        return a.x>b.x;
	}
};

bool cmp(int a,int b){
    return a>b;
}
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
    #endif
    //freopen("out.txt","w",stdout);
    string s;
	cin>>s;
	int a=0,b=0,c=0,d=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='N')a=1;
		if(s[i]=='S')b=1;
		if(s[i]=='W')c=1;
		if(s[i]=='E')d=1;
	}
	if((a^b)||(c^d)){
		puts("No");
	}
	else puts("Yes");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Size 309
unsigned graph[Size][Size], dis[Size][Size];
int main() {
    //freopen("input.txt", "r", stdin);
    int N;
    scanf("%d", &N);
    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++)
            cin>>graph[i][j];
    memset(dis, -1, sizeof(dis));
    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++)
            for(int k=0; k<N; k++)
                dis[i][j] = min(dis[i][j], graph[i][k]+graph[k][j]);
    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++)
            if(dis[i][j]!=graph[i][j])
                return puts("-1")*0;
    long long ans = 0;
    for(int i=0; i<N; i++)
        for(int j=i+1; j<N; j++) {
            bool ck = true;
            for(int k=0; k<N; k++)
                if((dis[i][j] == dis[i][k]+dis[k][j]) && (dis[i][j] != dis[i][k]) && (dis[i][j]!=dis[k][j])) {
                    ck = false;
                    break;
                }
            if(ck)
                ans += dis[i][j];
        }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>	
int main(void)
{
		int a,b,c;
		scanf("%d",&a);					
		scanf("%d",&b);
		c=a*b;
		if(c%2==0) {
		      printf("Even\n");
		}
		else {
		      printf("Odd\n");
		}
		return 0;
}		

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    a = list(map(int, input().split()))
    CNT = 0
    ID = 1
    for i in range(N):
        if a[i] == ID:
            ID += 1
        else:
            CNT += 1
    if CNT != 0 and ID != 1:
        print(CNT)
    elif CNT == 0 and ID != 1:
        print(CNT)
    elif CNT != 0 and ID == 1:
        print(-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 25912
#include<stdio.h>
int main(){
  int a,b,c,count;
  scanf("%d%d%d",&a,&b,&c);
  if(a>=b && a>=c)
    count=2*a-b-c;
  else if(b>=a && b>=c)
    count=2*b-a-c;
  else
    count=2*c-a-b;
  if(count%2==0)
    printf("%d\n",count/2);
  else
    printf("%d\n",(count+3)/2);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const int A = 26;
    int D; cin >> D;
    vector<int> c(D);
    REP(i,D) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(A));
    REP(i,D) REP(j,A) cin >> s[i][j];

    REP(i,D) OUT(1)

    return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>

#define S 0
#define H 1
#define C 2
#define D 3

int main(){
  int n, num, l, i, j, c[5][16] = {};
  char m;
  scanf("%d", &n);
  for(i = 0;i < n;i++){
    scanf(" %c %d", &m, &num);
    switch(m){
    case 'S': c[S][num] = -1; break;
    case 'H': c[H][num] = -1; break;
    case 'C': c[C][num] = -1; break;
    case 'D': c[D][num] = -1; break;
    }
  }

  for(i = 0;i < 4;i++){
    for(j = 1;j < 14;j++){
      if(c[i][j] != -1){
	switch(i){
	case S: putchar('S'); break;
	case H: putchar('H'); break;
	case C: putchar('C'); break;
	case D: putchar('D'); break;
	}
	printf(" %d\n", j);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    int n = s.length();
    rep(i,n-1){
        if(s[i] == 'A' && s[i+1] == 'C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e3+7;
const int mod=1e9+7;
char ch[N],g[N][N]; int dp[N][N];
main()
{
    int r,c;
    scanf("%lld%lld",&r,&c);
    for(int i=1;i<=r;i++)
    {
        scanf("%s",&ch);
        for(int j=0;j<c;j++)
            g[i][j+1]=ch[j];
    }
    for(int i=1;i<=r;i++)
    {
        for(int j=1;j<=c;j++)
        {
            if(i==1&&j==1) dp[i][j]=1;
            else
            {
                if(g[i][j]=='#') dp[i][j]=0;
                else dp[i][j]=((dp[i][j-1])%mod+(dp[i-1][j])%mod)%mod;
            }
        }
    }
    printf("%lld\n",dp[r][c]%mod);
}


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

int w,h,n;
int mas[20][20];
int dp[20][20];

int solve(){
  dp[0][0] = 1;
  for(int i=1;i<w;i++){
    if(mas[0][i] == 0) dp[0][i] = dp[0][i-1];
  }
  for(int i=1;i<h;i++){
    if(mas[i][0] == 0) dp[i][0] = dp[i-1][0];
  }
  for(int i=1;i<h;i++){
    for(int j=1;j<w;j++){
      if(mas[i][j] == 0) dp[i][j] = dp[i-1][j] + dp[i][j-1];
    }
  }
  return dp[h-1][w-1];
} 

int main(){
  while(cin >> w >> h,w||h){
    memset(mas,0,sizeof(mas));
    memset(dp,0,sizeof(dp));
    cin >> n;
    int x,y;
    while(n--){
      cin >> x >> y;
      mas[y-1][x-1] = 1;
    }
    cout << solve() << endl;
  }
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  int sa = 1000000000;
  for (int i = 0; i < n - k + 1; i++) {
    sa = min(sa, h[i + k - 1] - h[i]);
  }
  cout << sa << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)         cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)      cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)   cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int N = 300000 , mod = 1000000007;
int main()
{
    fastio;
    int a[5];
    map<int,int>mp;
    for(int i=0;i<5;i++){cin>>a[i];mp[a[i]]++;}
    for(int i=1;i<=5;i++)
    {
        if(mp.count(i)==0)
        {
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>

int main(){
   int n, i, k;
   scanf("%d", &n);

   for(i = 3; i <= n; i++){
      k = i;
      if(k % 3 == 0){
         printf(" %d", i);

      }else{
         while(k / 10 != 0){
            if(k / 10 == 3 || k % 10 == 3){
               printf(" %d", i);
               break;
            }
            k = k / 10;
         }
      }
   }
   printf("\n");

   return 0;
}



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

int	main()
{
  char	c;
  cin >> c;
  
  if (c == 97 || c == 101 || c == 105 || c == 111 || c == 117)
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
  return (0);
}


Measured memory_bytes: 256
L = list(map(int,input().split()))
N = L[0]
M = L[1]
PY = list()

for x in range(0,M):
    X = list(map(int,input().split()))
    PY.append((X[0],X[1],x))

sortedPY = sorted(PY, key=lambda x:x[1])
ID = [0 for i in range(N)]

for y in range(0,M):
    n = sortedPY[y][0]
    n = n-1
    ID[n] = ID[n] + 1
    nstr = str(ID[n])
    Pstr = str(sortedPY[y][0])
    while len(nstr) < 6:
        nstr = '0' + nstr
    while len(Pstr) < 6:
        Pstr = '0' + Pstr
    PY[sortedPY[y][2]] = Pstr + nstr
    number = Pstr + nstr

for x in range(0,M):
    print(PY[x])

Measured memory_bytes: 30416
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

#define ll long long



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

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

	int first = 0;
	int second = 0;

	for (int i = 0; i < n; i++)
	{
		if (arr[i] >= first)
		{
			second = first;
			first = arr[i];
		}
		else if (arr[i] >= second && arr[i] != first)
		{
			second = arr[i];
		}
	}

	for (int i = 0; i < n; i++)
	{
		if (arr[i] == first)
		{
			cout << second << endl;
		}
		else
		{
			cout << first << endl;
		}
	}
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int antena[5];
    for (int i = 0; i < 5; i++) cin >> antena[i];
    int K;
    cin >> K;
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            if (antena[j] - antena[i] > K) {
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256