akhauriyash/Code-Regression huggingface dataset:
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;

template <typename T>
class segmentTree {
  typedef function<T(const T& a, const T& b)> MergeFunc;
  int n;
  vector<T> st;
  MergeFunc merge;
  T emptySegmentValue;
  inline int L(int cur) { return 2 * cur + 1; }
  inline int R(int cur) { return 2 * cur + 2; }
  void update(int cur, int s, int e, int index, T newValue) {
    if(s > index || e < index) return;
    if(s == e) return void(st[cur] = newValue);
    int mid = (s + e) / 2;
    update(L(cur), s, mid, index, newValue);
    update(R(cur), mid + 1, e, index, newValue);
    st[cur] = merge(st[L(cur)], st[R(cur)]);
  }
  T query(int cur, int s, int e, int i, int j) {
    if(s > j || e < i) return emptySegmentValue;
    if(s >= i && e <= j) return st[cur];
    int mid = (s + e) / 2;
    auto left = query(L(cur), s, mid, i, j);
    auto right = query(R(cur), mid + 1, e, i, j);
    return merge(left, right);
  }
public:
  segmentTree(int n, T emptySegmentValue, MergeFunc merge) :
    n(n), emptySegmentValue(emptySegmentValue), merge(merge) { st.resize(n << 2, T()); }
  segmentTree(int n, T emptySegmentValue, T defaultValue, MergeFunc merge) :
    n(n), emptySegmentValue(emptySegmentValue), merge(merge) { st.resize(n << 2, defaultValue); }
  void update(int index, T newValue) { update(0, 0, n - 1, index, newValue); }
  T query(int l, int r) { return query(0, 0, n - 1, l, r); }
};

const int N = 2e5 + 5;

int n;
int a[N], h[N];

struct Node {
  long long val;
};


int main()
{
  scanf("%d", &n);
  for(int i = 0; i < n; i++)
    scanf("%d", &h[i]), h[i]--;
  for(int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  segmentTree<Node> st(n, Node(), [](const Node& a, const Node& b) -> Node { return { max(a.val, b.val) }; });
  long long best = 0;
  for(int i = 0; i < n; i++) {
    long long cur = a[i] + st.query(0, h[i]).val;
    best = max(best, cur);
    st.update(h[i], {cur});
  }
  cout << best << endl;
  return 0;
}


Measured memory_bytes: 8064
dp=[[1<<30 for _ in range(1001)] for _ in range(1001)]
dp[0][0]=0
n,m=map(int,input().split())
d=[int(input()) for _ in range(n)]+[0]
c=[int(input()) for _ in range(m)]+[0]
for i in range(m):
    for j in range(n+1):
        if dp[i][j]< dp[i+1][j]:dp[i+1][j]=dp[i][j]
        e=d[j]*c[i]
        if dp[i][j]+e<dp[i+1][j+1]:dp[i+1][j+1]=dp[i][j]+e;
dp=list(zip(*dp[::-1]))
print(min(dp[n]))

Measured memory_bytes: 31284
using System;
using System.Collections;
using System.Collections.Generic;
public class App
{
    public static void Main(string[] args)
    {
        var r = Console.ReadLine().Split();
        var a = long.Parse(r[0]);
        var b = long.Parse(r[1]);
        long x = 0;
        for(long i = a;i%4!=0;i++)
            x^=i;
        for(long i = b;i%4!=3 && i %4!=-1;i--)
            x^=i;
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node { int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print(int u) {
  int c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if (T[u].p == NIL) cout << "root, ";
  else if (T[u].l == NIL) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for (int i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
    if (i) cout << ", ";
    cout << c;
  }

  cout << "]" << endl;
}

int rec(int u, int p) {
  D[u] = p;
  if (T[u].r != NIL) rec(T[u].r, p);
  if (T[u].l != NIL) rec(T[u].l, p+1);
}

int main() {
  int d, v, c, l, r;
  cin >> n;
  for (int i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;

  for (int i = 0; i < n; i++) {
    cin >> v >> d;
    for (int j = 0; j < d; j++) {
      cin >> c;
      if (j == 0) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for (int i = 0; i < n; i++) {
    if (T[i].p == NIL) r = i;
  }

  rec(r, 0);

  for (int i = 0; i < n; i++) print(i);

  return 0;

}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ld long double
#define mem(x,y) memset(x,y,sizeof x)

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
int fact[1000009];
void solve()
{
	int n;
	cin>>n;
	ll ans=0;
	for(int i=1;i<=n;i++)
	for(int j=1;i*j<=n;j++)
	{
		fact[i*j]++;
	}
	for(int i=1;i<n;i++)
	ans += fact[n-i];
	cout<<ans<<'\n';
}

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


Measured memory_bytes: 7496
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N; cin >> N;
  if(N < 3) {
    cout << 1 << endl;
    return 0;
  }
  vector<ll> A(N);
  for(int i = 0; i < N; i++) cin >> A.at(i);
  int count = 0;
  bool down = 0, up = 0, set = 1;
  for(int i = 0; i < N - 1; i++) {
    if(set) {
      if(A.at(i + 1) < A.at(i)) {
        down = 1; set = 0; count++; //cout << "di = " << i << endl;
      } else if(A.at(i + 1) > A.at(i)) {
        up = 1; set = 0; count ++; //cout << "ui = " << i << endl;
      }
      else {
        if(i == (N - 2)) count++;
        continue;
      }
    } else {
      if(down) {
        if(A.at(i + 1) > A.at(i)) {
          down = 0; set = 1; //cout << "endi" << i << endl; //i--;
          if(i == N - 2) count++;
        }
      } else if(up) {
        if(A.at(i + 1) < A.at(i)) {
          up = 0; set = 1; //cout << "endi" << i << endl; //i--;
          if(i == N - 2) count++;
        }
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    ll x;
    cin >> x;
    ll tmp=x%11;
    int a=1;
    if(tmp >= 7){
        a=2;
    }
    if(tmp == 0){
        a=0;
    }
    
    ll ans = 2*(x/11)+a;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
	
	int N, X;
	int ans = 0;
	
	cin >> N >> X;
	
 	int* m = new int[N];
	
	for(int i = 0;i < N;i++){
		
		cin >> m[i];
		
	}
	
	for (int i = 0; i < N; i++) {
	
		X = X - m[i];
		ans++;
	}
	
	int min = 100000;
	for (int i = 0; i < N; i++) {
		if (min > m[i]) 
			min = m[i];
	}
	
	ans = ans + X / min;
	
	cout << ans;
	
	return 0;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 305
const int MAX = 43;

ll N;
ll dp[MAX][2][2];
ll A[SIZE];


int main(){

	scanf("%lld",&N);

	for(ll i = 0; i < N; i++){

		scanf("%lld",&A[i]);
	}

	ll X = 0;
	for(ll i = 0; i < N; i++){

		X ^= A[i];
	}

	ll a = A[0],b = A[1];

	X ^= (a^b);
	ll S = a+b;

	vector<int> xs,ss,as;

	for(int i = 0; i < MAX; i++){
		for(int j = 0; j < 2; j++){
			for(int k = 0; k < 2; k++){

				dp[i][j][k] = -1;
			}
		}
	}

	dp[0][0][0] = 0; //dp[今何桁目か][繰り上がりがあるかどうか][今までの範囲がA以下かどうか] = 最大値

	ll v = 1;
	for(ll i = 0; i < MAX-1; i++){

		ll cx = X&1; //Xの下位iビット目
		ll cs = S&1; //Sの下位iビット目
		ll ca = a&1; //aの下位iビット目

		xs.push_back(cx);
		ss.push_back(cs);
		as.push_back(ca);

		for(ll j = 0; j < 2; j++){
			for(ll k = 0; k < 2; k++){
				if(dp[i][j][k] == -1)continue;
				for(ll na = 0; na < 2; na++){
					for(ll nb = 0; nb < 2; nb++){
						ll ni = i+1;//次の桁
						ll nj = 0; //次の繰り上がり
						ll nk = k; //その桁がAの該当桁以下かどうか(0:Aの該当桁以下 1:Aの該当桁より大きい)

						if((na^nb) != cx)continue;

						ll ns = na+nb+j;
						if(ns%2 != cs)continue;

						if(ns >= 2){
							nj = 1;
						}
						if(ca < na){

							nk = 1;
						}else if(ca == na){

							nk = k;

						}else{ //ca > na

							nk = 0;
						}

						dp[ni][nj][nk] = max(dp[ni][nj][nk],dp[i][j][k]|(v*na));
					}
				}
			}
		}
		X >>= 1;
		S >>= 1;
		a >>= 1;
		v <<= 1;
	}

	ll tmp = dp[MAX-1][0][0];

	if(tmp == -1 || tmp == 0){

		printf("-1\n");
		return 0;

	}else{

		printf("%lld\n",A[0]-tmp);
	}

	return 0;
}


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

int main() {
  int n,m,k;
  cin >> n >> m >> k;

  vector<int> a(n);
  vector<int> b(m);  
  //vectorに全入力値を代入する
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];

  ll t = 0;
  rep(i,m) t += b[i];

  int ans = 0, j = m;
  rep(i,n+1) {
    while (j > 0 && t > k) {
      --j;
      t -= b[j];
    }
    if (t > k) break;
    ans = max(ans, i+j);
    if (i == n) break;
    t += a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4776
def Repsept():
    
    num = int(input())

    f=0
    n=num
    
    for i in range(10**6+1):
      if n==0:
        f=1
        print(i)
        break
      n=((n*10)+7)%num
    if f==0:
      print(-1)


if __name__ == '__main__':
    Repsept()



Measured memory_bytes: 9176
#include<cstdio>
#define mx 100005
#define For(n) for(int i;i<n;i++)
using namespace std;
int n,m,p[mx],b[mx],c[mx];
long long a[mx];
int f(int s){
  int t=p[s];
  return t<0?s:p[s]=f(t);
}
long long g(int j){
  int x=f(b[j]),y=f(c[j]),s=0,t;
  if(x!=y){
    s=p[x],t=p[y];
    if(s>t){
      p[x]=y;
      p[y]+=s;
    }
    else{
      p[y]=x;
      p[x]+=t;
    }
  }
  return 1ll*s*t;
}
int main(){
  scanf("%d%d",&n,&m);
  a[m-1]=1ll*n*(n-1)/2;
  For(n)p[i]=-1;
  For(m)scanf("%d%d",&b[i],&c[i]);
  for(int i=m-2;i>=0;i--)a[i]=a[i+1]-g(i+1);
  For(m)printf("%lld\n",a[i]);
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    ll sum = 1;
    char temp;
    temp = s[0];
    for (int i = 1; i < n; ++i) {
        if (s[i] != temp) {
            sum++;
            temp = s[i];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x,n) for(ll i=x;i<n;i++)
#define modd 998244353
#define umap unordered_map<ll,ll>
ll n,k;
ll dp[100001];

ll fun(ll k,ll a[]){
  if(k==0){
    return 0;
  }
  if(dp[k]!=-1)return dp[k];
  ll ck=0;
  fori(0,n){
    if(k>=a[i] and fun(k-a[i],a)==0){
      ck=1;break;
    }
  }

  if(ck==1)return dp[k]=1;
  else return dp[k] = 0;

}


int32_t main() 
{ 
  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    
  
    cin>>n>>k;
    memset(dp,-1,sizeof dp);

    ll a[n];
    fori(0,n)cin>>a[i];

    if(fun(k,a)==1)
    cout<<"First"<<"\n";
     else 
      cout<<"Second"<<"\n";





    
  



  

    







    
    
 
 
return 0;
}    

Measured memory_bytes: 7468
#!/usr/bin/env python3
import sys


def solve(N: int):
    print(N * (N + 1) // 2)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


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

const int INF = INT_MAX;

int c[10][1005];

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i,h) cin >> s.at(i);
  int ans = INF;
  rep(div,1<<(h-1)) {
    int g = 0;
    vector<int> id(h);
    rep(i,h) {
      id[i] = g;
      if(div>>i&1) g++;
    }
    g++;
    rep(i,g)rep(j,w) c[i][j] = 0;
    rep(i,h)rep(j,w) c[id[i]][j] += (s[i][j]-'0');

    int num = g-1;
    vector<int> now(g);
    auto add = [&](int j) {
      rep(i,g) now[i] += c[i][j];
      rep(i,g) if(now[i]>k) return false;
      return true;
    };
    rep(j,w) {
      if(!add(j)) {
        num++;
        now = vector<int>(g);
        if(!add(j)) {
          num = INF;
          break;
        }
      }
    }
    ans = min(ans,num);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    int n;
    cin >> n;
    int sum=0;
    int tmp=n;
    while(tmp>0){
        sum+=tmp%10;
        tmp/=10;
    }
    if(n%sum==0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M = map(int, readline().split())
    A = [int(i) for i in readline().split()]

    ans = N - sum(A)
    print(ans if ans >= 0 else -1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9880
package main

import "fmt"

func main() {
	array := make([]int, 5)
	for i := 0; i < 5; i++ {
		fmt.Scan(&array[i])
	}

	for i, a := range array {
		if a == 0 {
			fmt.Println(i + 1)
		}
	}
}


Measured memory_bytes: 1768
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        X: u64,
        A: u64,
        B: u64,
    }
    println!("{}",(X-A)%B);
}

Measured memory_bytes: 4352
(setq x(setq y 0))(setq xx(read))(setq yy(read))
(dotimes(i(read))
  (setq a(read))(setq b(read))(setq c(read))
  (cond
	((= c 1)(setq x(max x a)))
	((= c 2)(setq xx(min xx a)))
	((= c 3)(setq y(max y b)))
	(t(setq yy(min yy b)))))
(princ(*(max(- xx x)0)(max(- yy y)0)))


Measured memory_bytes: 15328
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
int a[100005];
int n, c, k;
int pos, cot = 1;
int main()
{
	scanf("%d%d%d", &n, &c, &k);
	for(int i = 1; i <= n ; i++)scanf("%d", &a[i]);
	sort(a + 1, a+ n + 1);
	pos = 1;
	for(int i = 1; i <= n; i++)
	{
		if(a[i] - a[pos] > k || i - pos + 1 > c) cot++ , pos = i;
	}
	printf("%d\n", cot);
}

Measured memory_bytes: 512
n = int(input())
l = []
d = {}
for i in range(n):
  s,p = input().split()
  if s not in l:
    l.append(s)
    d[s] = []
  d[s].append([int(p), i+1])

for i in sorted(l):
  for j in sorted(d[i], reverse=True):
    print(j[1])

Measured memory_bytes: 9004
import java.util.Scanner;

public class Main {

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

        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        int maxNum = Math.min(A, B);
        int minNum = (A + B) > N ? (A + B - N) : 0;

        System.out.println(maxNum + " " + minNum);
    }
}


Measured memory_bytes: 25172
def uneven_numbers(n):

    ans = 0

    for i in range(1, n+1):
        if len(str(i)) % 2 != 0:
            ans += 1

    return ans

def main():
    n = int(input())
    print(uneven_numbers(n))

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
s=list(str(input()))
b=0
while len(s)>=7:
  if s[-1]=='r':
    sd=[s[-7],s[-6],s[-5],s[-4],s[-3],s[-2],s[-1]]
    se=[s[-6],s[-5],s[-4],s[-3],s[-2],s[-1]]
    if ''.join(sd)=='dreamer':
      del s[-7:]
    elif ''.join(se)=='eraser':
      del s[-6:]
    else:
      print('NO')
      b+=1
      break
  elif s[-1]=='m':
    sd=[s[-5],s[-4],s[-3],s[-2],s[-1]]
    if ''.join(sd)=='dream':
      del s[-5:]
    else:
      print('NO')
      b+=1
      break
  elif s[-1]=='e':
    sd=[s[-5],s[-4],s[-3],s[-2],s[-1]]
    if ''.join(sd)=='erase':
      del s[-5:]
    else:
      print('NO')
      b+=1
      break  
  else:
    print('NO')
    b+=1
    break
if len(s)==0 or (len(s)==6 and ''.join(s)=='eraser') or (len(s)==5 and ''.join(s)=='dream') or (len(s)==5 and ''.join(s)=='erase'):
  print('YES') 
elif b!=1:
  print('NO')

Measured memory_bytes: 4212
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<stdlib.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<math.h>
using namespace std;
int main()
{
   
    long long n,k,  a[20010], dolution=0;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a, a+n);
    for(int i=1;i<=k;i++)
    {
        dolution+=a[n-i];
    }
    cout<<dolution<<endl;
return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define fast ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int N=3000;
double dp[N][N]={0};
int main()
{
    fast
    int n;cin>>n;
    vector<double>p(n+1);
    for(int i=1;i<=n;i++)cin>>p[i];
    dp[0][0]=1;dp[1][0]=1-p[1];
    for(int i=2;i<=n;i++)dp[i][0]=dp[i-1][0]*(1-p[i]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=i;j++){
            dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*(p[i]);
        }

    double ans=0;
    for(int i=n/2+1;i<=n;i++)
        ans+=dp[n][i];
    cout<<fixed<<setprecision(10)<<ans;
return 0;
}


Measured memory_bytes: 68992
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<int,int>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int INF=1000000007;
using ll=long long;


int w,h;
char c[55][55];
int ddx[8]={-1,-1,-1,0,0,1,1,1};
int ddy[8]={-1,0,1,-1,1,-1,0,1};
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
bool used[55][55]={};
void dfs(int W,int H){
	if(W<0||W>=w||H<0||H>=h||used[W][H])return;
	used[W][H]=true;
	if(c[W][H]=='1'){
		rep(i,0,8)dfs(W+ddx[i],H+ddy[i]);
	}
}
int main(){
	while(1){
		int land=0;
		cin>>w>>h;
		if(w==0)break;
		rep(j,0,h){
			rep(i,0,w){
				cin>>c[i][j];
				used[i][j]=false;
			}
		}
		rep(j,0,h){
			rep(i,0,w){
				if(used[i][j]==false&&c[i][j]=='1'){
					dfs(i,j);
					land++;
				}
			}
		}
		print(land);
	}
	return 0;
}



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

#define x first
#define y second
#define pb push_back
#define mp make_pair

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

#define ll long long
#define ld long double
#define int long long

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin >> x;
    int y = 360;
    cout << y / __gcd(y, x);
    return 0;
}


Measured memory_bytes: 3612
n = input().split()
a,b,c = 0,0,0

N = int(n[0])
Yen = int(n[1])

X,Y,Z = -1,-1,-1

for x in range(0,N+1):
    for y in range(0,N+1):
        z = N-x-y
        if Yen == 10000*x + 5000*y + 1000*z:
            if z < 0:
                continue
            else:
                X,Y,Z = x,y,z
        else:
            continue

print(X,Y,Z)


Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
  int i,j,n,m,count,max;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&m);
    count=0;
    while(m/10!=0 && count<100){
      max=(m/10)*(m%10);
      for(j=100;m/j!=0;j*=10){
	if(max<(m/j)*(m%j))max=(m/j)*(m%j);
      }
      m=max;
      count++;
    }
    if(count!=100)printf("%d\n",count);
    else printf("-1\n");
  }
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n,l,r;
	cin >> n;
	int ans = 0;
	for (int i = 0;i < n;i++){
		cin >> l >> r;
		ans += r - l + 1;
	}
	cout <<ans<< endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);

int main() {
   double a, b, h, m;
   cin >> a >> b >> h >> m;
   // h --> 0.5 ang / min
   // m --> 6 ang / min
   double h_ang = 0.5 * ((h * 60) + m) * (pi / 180);
   double m_ang = 6 * ((h * 60) + m) * (pi / 180);
   double yh = sin(h_ang) * a, xh = cos(h_ang) * a;
   double ym = sin(m_ang) * b, xm = cos(m_ang) * b;
   double ans = sqrt(pow(xh-xm,2)+pow(yh-ym,2));
   cout << fixed << setprecision(20) << ans << endl;
   return 0;
}

Measured memory_bytes: 4032
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

string S;

// rec(l, r) = S[l, r] + sigma_p=l+1^r-1{rec(l, p) + rec(p, r)}
ll rec(int l, int r) {
    if (l == r) {
        return 0;
    }
    else {
        ll sum = 0;
        for (int p = l + 1; p <= r - 1; p++) {
            sum += stoll(S.substr(l, p - l)) * pow(2, r - p - 1) + rec(p, r);
        }
        sum += stoll(S.substr(l, r - l));
        return sum;
    }
}

int main()
{
    cin >> S;
    cout << rec(0, S.length()) << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

ll n;

ll doCalc(vl v){
  if(v.size() == 1) return (v[0]+n-1)/v[0];
  ll minn = INF;
  int minnIndex = -1;
  F0R(i,v.size()) {
    if(minn > v[i]) {
      minn = v[i];
      minnIndex = i;
    }
  }
  if(minnIndex == 0) return (v[0]+n-1)/v[0] + v.size() - 1;
  vl v1;
  FOR(i,minnIndex,v.size())
    v1.pb(v[i]);
  return doCalc(v1) + minnIndex;
}

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

    vl v;
    ll x;
    cin >> n;
    F0R(i,5){
        cin >> x;
        v.pb(x);
    }

    cout << doCalc(v)<<endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#define M 1100
using namespace std;
int n;
long long a[M],x,y;
long long gcd(long long  x,long long y)
{
    return y == 0 ? x : gcd(y,x%y);
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        x = 1;
        for (int i = 1; i <= n; i++)
        scanf("%lld",&a[i]);
        for (int i = 1; i <= n; i++)
        {
            x = a[i]/gcd(x,a[i]) * x;
        }
        printf("%lld\n",x);
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
	int r,c;
	while(1){
		scanf("%d %d\n", &r,&c);
		if(r==0&&c==0) break;
		for(int i=0;i<r;i++) {
			for(int j=0;j<c;j++) {
				if(i==0||i==r-1||j==0||j==c-1) printf("#");
				else printf(".");
			}
		printf("\n");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2684
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	VI H(N);
	REP(i, N)cin >> H[i];
	int ans = 0, cnt = 0;
	REP(i, N-1) {
		if (H[i] >= H[i + 1])cnt++;
		else {
			ans = max(ans, cnt);
			cnt = 0;
		}
		//cout << i << " " << cnt << endl;
	}
	ans = max(ans, cnt);
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long int ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const int MOD = 1000000007;
const int INF = INT_MAX;




int main(void) {

    int a, b;
    cin >> a >> b;

    cout << 6 - a - b << endl;
}



//              g++ -std=c++1z  

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

int main(){
  long long n;
  cin >> n;
  vector <long long> a(n);
  for( int i = 0; i<n ; i++ )
    cin >> a.at(i);
  
  long long ans = 0;
  for( int i= 1; i < n; i++){
    if(a.at(i-1) > a.at(i)) {
      ans += a.at(i-1) - a.at(i);
      a.at(i) = a.at(i-1);
    }
    else if(a.at(i-1) <= a.at(i)){
      ans += 0;
    }
  }
  cout << ans << endl;
    
  
}

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

typedef long long ll;
const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, H;
    cin >> N >> H;
    vector<int> a(N),b(N);
    for (int i=0;i<N;i++) cin >> a[i] >> b[i];
    sort(a.rbegin(),a.rend());
    sort(b.rbegin(),b.rend());
    int ans = INF;
    for (int i=0;i<=N;i++){
        if (i > 0) H-=b[i-1];
        int cnt = 0;
        if (H > 0) cnt = (H+a[0]-1)/a[0];
        ans = min(ans, i+cnt);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1024
/*------U Have To DO It------*/
/*      BY-> RicoProg        */
/*        ___ 
           __|__|
          |  |___           */
#include <bits/stdc++.h>
using namespace std;
 
/**/
 
//---------------------------------------------------MACROS----------------------------------------------------------
#define ll long long
#define ld long double
#define beg(i ,n) for(ll i=0;i<n;i++)
#define beg1(i ,n) for(ll i=1;i<n;i++)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back 
#define eb emplace_back
#define mp make_pair
#define nl "\n" 
#define sp " "
#define vec(v , n) vector<ll> v(n)
#define all(x) x.begin() , x.end()
#define pii pair<int , int>
#define pll pair<ll , ll>
#define mii map<int , int>
#define mll map<ll , ll>
#define mlb map<ll , bool>
#define msi map<string , int>
#define mci map<char , int>
#define f1 first
#define f2 second

//---------------------------------------------------GLOBAL----------------------------------------------------------
const ll MOD2 = 998244353 ;
const ll MOD = 1e9 + 7 ;
const ll MAX = 1e5 + 7 ;
const ll inf = 1e18L + 5 ;
const double pi = 3.14159265358979323846 ;
ll fpow(ll n , ll m ){ll res=1 ;while(m>0){if(m&1){res*=n ;}m/=2 ;n*=n ;}return res;}
ll modInv(ll n){return fpow(n , MOD-2);}
//---------------------------------------------------FUNCTIONS-------------------------------------------------------

const ll nax = 1e6 + 5 ;

int m[nax] ;

void solve(){
	ll n , ans = 0 ;
    cin >> n ;
    vector<ll> v(n) ;
    bool flag = false ;
    beg(i , n) cin >> v[i] , m[v[i]]++ ;
    beg(i , n){
        flag = true ;
        for(ll j=1 ; j*j<=v[i] ; ++j){
            if(v[i]%j == 0){
                if(m[j] && j!=v[i]){
                    flag = false ;
                    break ;
                }
                if(j!=1 && j*j != v[i] && m[v[i]/j]){
                    flag = false ;
                    break ;
                }
            }
        }
        if(flag && m[v[i]] == 1) ++ans ;
    }
    cout << ans ;
}

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

Measured memory_bytes: 8680
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int d = scan.nextInt();
		int t = scan.nextInt();
		int s = scan.nextInt();

		String message = "No";

		if(d <= t*s) {
			message = "Yes";
		}

		System.out.println(message);

	}

}


Measured memory_bytes: 27084
import itertools
N,M=map(int,input().split())
edge=[]
for i in range(N+1):
  edge.append([0]*(N+1))
for j in range(M):
  a,b=map(int,input().split())
  edge[a][b]=1
  edge[b][a]=1
roots=list(itertools.permutations(range(2,N+1)))
ans=0
for root in roots:
  pos=1
  for i in range(N-1):
    nxt=root[i]
    if edge[pos][nxt]==1:
      pos=nxt
    else:
      break
  else:
    ans+=1
print(ans)
  

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
int main() {
  int n;cin>>n;
  string s;cin>>s;
  int len=s.size();
  bool ans=false;
  if(len%2!=0){
    cout<< "No"<<endl;
    return 0;
  }
  len/=2;
  string a=s.substr(0,len);
  string b=s.substr(len,len);
  ans=(a.compare(b)==0);
  cout << (ans==true?"Yes":"No")<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int used[5010];
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,k,p[5010],c[5010],ans=-INF;
    cin>>n>>k;
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    rep(i,n)cin>>c[i];
    rep(i,n){
        int pos=i;
        int cur=0;
        if(k<=n){
            rep(_,k){
                pos=p[pos];
                cur+=c[pos];
                chmax(ans,cur);
            }
        }
        else{
            fill(used,used+n,-1);
            used[pos]=0;
            vector<int>v={0};
            int memo=-1;
            rep(hoge,10000){
                pos=p[pos];
                cur+=c[pos];
                v.pb(cur);
                if(used[pos]!=-1){
                    memo=used[pos];
                    used[pos]=hoge;
                    break;
                }
                used[pos]=hoge;
            }
            int copyk=k;
            int fir=0;
            if(memo){
                fir=v[memo];
                chmax(ans,*max_element(v.begin(),v.begin()+memo));
                rep(_,memo)v.erase(v.begin());
                k-=memo;
                for(int &j:v)j-=fir;
            }
            int ma=*max_element(v.begin()+1,v.end());
            if(memo)chmax(ans,fir+max(0ll,ma));
            else chmax(ans,ma);
            if(v.back()>0){
                int t=k/(v.size()-1);
                chmax(ans,fir+v.back()*t+(*max_element(v.begin(),v.begin()+k%(v.size()-1)+1)));
                t--;
                if(t)chmax(ans,fir+v.back()*t+max(0ll,ma));
            }
            k=copyk;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

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

    char now = s[0];
    int ans = 0;
    for (int i = 1; i < s.size(); ++i) {
        if (s[i] != now) {
            ans++;
            now = s[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3672
-- C Build Stairs

import Data.List

main:: IO()
main = do
  l <- getLine
  let n = read l :: Int
  l2 <- getLine
  let a = take n (map read (words l2) :: [Int])
  let ans = solve a
  case ans of
    True -> putStr ("Yes\n")
    False -> putStr ("No\n")

solve:: [Int] -> Bool
solve (x1:x2:xs)
  | (x1 - x2 >= 1) = False
  | (x1 - x2 == 0) = solve (x2:xs)
  | otherwise = solve ((x2 - 1):xs)
solve x = True


Measured memory_bytes: 36220
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;
char str[99999];
int parse(int i){
	if('0'<=str[i]&&str[i]<='9')return strtol(str+i,NULL,10)/2+1;
	assert(str[i]=='[');
	vector<int>v;
	int j=i,c=0;
	for(;;j++){
		if(str[j]=='[')if(++c==1)v.push_back(parse(j+1));
		if(str[j]==']')if(--c==-1)break;
	}
	sort(v.begin(),v.end());
	for(c=j=0;j<=v.size()/2;j++)c+=v[j];
	return c;
}
main(){
	int T;
	for(scanf("%d",&T);T--;printf("%d\n",parse(1)))scanf("%s",str);
}

Measured memory_bytes: 1096
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    int a,b,c;cin>>a>>b>>c;
    int d1,d2,d3;
    d1=abs(a-b);
    d2=abs(a-c);
    d3=abs(b-c);
    cout<<min(d1+d2,min(d1+d3,d2+d3))<<endl;
    return 0;
}

Measured memory_bytes: 256
n = input()

hons = ["2", "4", "5", "7", "9"]

pons = ["0", "1", "6", "8"]

ans = ""

for i in hons:
    if n[-1] == i:
        ans = "hon"

for i in pons:
    if n[-1] == i:
        ans = "pon"

if n[-1] == "3":
    ans = "bon"

print(ans)

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

int main() {

    int i, j, num, feet;
    cin >> num >> feet;
    int flag = 0;

    for (i = 0; i <= num; i++) {//鶴0匹から
        j = num - i;//亀num匹から
        if (feet == i * 2 + j * 4)flag = 1;
    }
    
    if (flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3628
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-8
#define M_PI 3.141592653589793
#define bs 1000000007

#define bsize 256

#define ldouble long double

using namespace std;

long long INF = 1e9;
const int N = 700031;

long long n;

pair<vector<int>,vector<int> > solve(long long need){

	pair<vector<int>,vector<int> > ret;

	if (need==1)
	{
		ret.first.push_back(1);
		ret.second.push_back(1);
		return ret;
	}

	if (need%2==1)
	{
		pair<vector<int>,vector<int> > p1=solve(need/2);
		int cur=p1.first.size()+1;
		p1.first.push_back(cur);
		p1.second.push_back(cur);
		return p1;
	}
	pair<vector<int>,vector<int> > p1=solve(need-1);
	int cur=p1.first.size()+1;
	p1.first.insert(p1.first.begin(),cur);
	p1.second.push_back(cur);
	return p1;

}

int main(){
	//freopen("cinema.in","r",stdin);
	//freopen("cinema.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);

	cin>>n;

//	n=(1ll<<39)-1;

	pair<vector<int> ,vector<int> > p=solve(n);

	for (int i=0;i<p.second.size();i++)
	{
		p.first.push_back(p.second[i]);
	}

	cout<<p.first.size()<<endl;

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

	cin.get(); cin.get();
	return 0;
}


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

#define for0(i, n) for (ll i = 0; i < (ll)(n); ++i) // 0 based indexing
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (ll i = (ll)(l); i <= (ll)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (ll i = (ll)(n); i >= 1; --i) // reverse 1 based

#define ff first
#define ss second
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	ll ans =0;
	vector < ll > val(n);
	for0(i,n){
		cin >> val[i];
	}
	for0(i,n) {
		forc(j,i+1,n-1){
			ans += val[i]*val[j];
		}
	}
	cout << ans << endl;
	return 0;
}


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

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

  string ans;
  if (stoi(s.substr(0, 4)) <= 2018) {
    ans = "Heisei";
  } else if (s.substr(0, 4) == "2019" && stoi(s.substr(5, 2)) <= 4) {
    ans = "Heisei";
  } else ans = "TBD";

  cout << ans << endl;
}


Measured memory_bytes: 256
// debug
#if __has_include("../library/Basic/Debug.hpp")
#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>


/* ----- Type Alias ----- */
using Int = int_fast64_t;
using Real = long double;
using String = std::string;
template <class... Ts>
using Tuple = std::tuple<Ts...>;

template <class T>
using Vector = std::vector<T>;
template <class T>
using Queue = std::queue<T>;
template <class T>
using Stack = std::stack<T>;
template <class T>
using Deque = std::deque<T>;

template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
using Set = std::set<T>;
template <class T, class U>
using Map = std::map<T, U>;

template <class T, class... Us>
using Func = std::function<T(Us...)>;

template <class T>
T genv(T v) { return v; }

template <class T, class... Ts>
auto genv(size_t l, Ts... ts) {
    return Vector<decltype(genv<T>(ts...))>(l, Vector<T>(ts...));
}

template <class Cost = Int>
struct Edge {
    Int src, dst;
    Cost cost;
    Edge(Int src = -1, Int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = Int>
using Edges = Vector<Edge<Cost>>;
template <class Cost = Int>
using Graph = Vector<Vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */

struct Fio {
    Int precision;
    Fio(Int precision) : precision(precision) {}
};

std::ostream& operator<<(std::ostream& os, const Fio& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}


/* ----- Constants ----- */
// constexpr Int INF = std::numeric_limits<Int>::max() / 3;
// constexpr Int MOD = 1000000007;
// constexpr Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

int main() {
    Int n;
    std::cin >> n;

    Real ans = 0;
    for (Int i = 0; i < n; ++i) {
        Real x;
        String u;
        std::cin >> x >> u;
        if (u == "BTC") {
            x *= 380000;
        }
        ans += x;
    }

    std::cout << Fio(10) << ans << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
#define PI acos(-1.0)
#define MOD 2520
#define E 1e-12
using namespace std;
typedef long long ll;
const int MAXN=500000+5;//最大元素个数
int n,m;//元素个数
int c[MAXN];//c[i]==A[i]+A[i-1]+...+A[i-lowbit(i)+1]
//返回i的二进制最右边1的值
int lowbit(int i)
{
    return i&(-i);
}
//返回A[1]+...A[i]的和
int sum(int x)
{
    int sum = 0;
    while(x)
    {
        sum += c[x];
        x -= lowbit(x);
    }
    return sum;
}
//令A[i] += val
void add(int x, int val)
{
	
    while(x <= n)   //注意这里的n，是树状数组维护的长度
    {
        c[x] += val;
        x += lowbit(x);
    }
}
struct node
{
	int l,r;
}a[MAXN];
bool cmp(node x,node y)
{
	return x.r-x.l<y.r-y.l;
}
int main()
{

    while(scanf("%d%d",&m,&n)!=-1)
    {
        memset(c,0,sizeof(c));
        for(int i=1;i<=m;i++)
		{
			scanf("%d%d",&a[i].l,&a[i].r);
		}
		sort(a+1,a+m+1,cmp);
		
		int j=0;
		for(int d=1;d<=n;d++)
		{
			int temp=0;
			for(int i=d;i<=n;i+=d)
			{
				temp+=sum(i);
			}
			printf("%d\n",temp+m-j)  ;
			
			while(j<m&&a[j+1].r-a[j+1].l<=d)
			{
				add(a[j+1].l,1);
				add(a[j+1].r+1,-1);
				j++;
			}
			
		}
    }
    return 0;
}


Measured memory_bytes: 6784
N, M = map(int, input().split())
tree = dict(zip(range(1, N+1), [[] for i in range(N)]))
for i in range(M):
  a, b = map(int, input().split())
  tree[a].append(b)


is_visited = [False]*(N+1)
num_visited = 0
def find_cycle(d):
  global is_visited
  global num_visited
  cycle = []
  l = 1001
  while d:
    node = d[-1]
    if tree[node]:
      child = tree[node].pop()
      if not is_visited[child]:
        is_visited[child] = True
        num_visited += 1
      if child in cycle and node in cycle:
        idn = cycle.index(node)
        idc = cycle.index(child)
        cycle = cycle[:idn+1] + cycle[idc:]
        l = len(cycle)
      if child in d:
        idx = d.index(child)
        if len(d) - idx < l:
          cycle = d[idx:]
          l = len(cycle)
      else:
        d.append(child)
    else:
      d.pop()
  return cycle


is_visited[0] = True
num_visited += 1
i = 1
while num_visited < N+1:
  while is_visited[i]:
    i += 1
  d = [i]
  is_visited[i] = True
  num_visited += 1
  cycle = find_cycle(d)
  if cycle:
    print(len(cycle))
    print(*cycle, sep='\n')
    quit()

print(-1)

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

using namespace std;

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

#define N 100010
#define M 200010
#define endl "\n"
#define mod 1000000007

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);

    int n;

    cin >> n;

    string ans = "";
    for(int i = 0; i < n; i++) ans += "ACL";

    cout << ans <<endl;

	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
using namespace std;
int main(void)
{
    int y = 100000;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        y += y * 0.05;
        if (y % 1000 != 0)
        {
            y = ((y / 1000) + 1) * 1000;
        }
    }
    cout << y << endl;
}



Measured memory_bytes: 3096
from collections import defaultdict
from math import gcd

P=defaultdict(lambda :0)
n=int(input())
AB=[tuple(map(int,input().split()))for i in range(n)]

zero=0 #これがいるときは一匹のみ
a0=0 #a0とb0はお互いがペア
b0=0
for a,b in AB:
    g=gcd(a,b)
    if a==0 and b==0:
        zero+=1
    elif a==0:
        a0+=1
    elif b==0:
        b0+=1
    elif a<0:
        a//=-g
        b//=-g
        P[(a,b)]+=1
    else:
        a//=g
        b//=g
        P[(a,b)]+=1

ans=1
others=n-zero-a0-b0
mod=1000000007
from copy import copy
k=copy(list(P.keys()))
for p in k:
    me=P[p]
    if me==0:
        continue
    a,b=p
    oppidx=(-b,a) if b<0 else (b,-a)
    opp=P[oppidx]
    if P[oppidx]!=0:
        others-=me+opp
        ans*=pow(2,me,mod)+pow(2,opp,mod)-1
        ans%=mod
    P[p]=0
    P[oppidx]=0

if a0!=0 and b0!=0:
    ans*=pow(2,a0,mod)+pow(2,b0,mod)-1
    ans%=mod
elif a0!=0 or b0!=0:
    others+=a0+b0

ans*=pow(2,others,mod)
ans%=mod
ans=ans+zero-1
ans%=mod

print(ans)

"""
7
0 1
0 1
1 0
1 0
1 -1
1 1
1 3
"""

Measured memory_bytes: 173300
x,k,d = map(int,input().split())
if x < 0: x = -x
c = x//d
mod = x%d
if c>=k:
	l = x - k*d
	print(l)
else:
	if c%2 == k%2:
		print(mod)
	else:
		print(d-mod)


Measured memory_bytes: 61624