akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(){
	int matrix[4][3][10]={0},a,b,c,d,m;
	cin >> m;
	for(int i = 0; i < m; i++){
		cin >> a;
		cin >> b;
		cin >> c;
		cin >> d;
		matrix[a-1][b-1][c-1]=matrix[a-1][b-1][c-1]+d;
	}
	for(int j = 0; j < 3; j++){
		for(int k = 0; k < 3; k++){
			for(int l = 0; l < 10; l++){
				cout << " " << matrix[j][k][l] ;
			}
			cout << "\n" ;
		}
			for(int o = 0; o < 20; o++){
				cout << "#" ;
			
		}
			cout << "\n" ;
	}
	for(int k = 0; k < 3; k++){
			for(int l = 0; l < 10; l++){
				cout << " " << matrix[3][k][l] ;
			}
			cout << "\n" ;

	}
	return 0;
}

Measured memory_bytes: 1160
import scipy as sp

k, n = list(map(int, input().split()))
a_list = list(map(int, input().split()))

a_list = sp.array(a_list)
sub_a_list = (a_list - sp.roll(a_list, 1))[1:]
sub_a_list = sp.append(sub_a_list, a_list[0]+k-a_list[-1])
print(k-max(sub_a_list))

Measured memory_bytes: 35504
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<pll> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<pll> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n,k ;
	cin >> n >> k ;
	vll x(n) ;
	for(auto &i:x) cin >> i ;
	ll ans = 1000000000 ;
	for(int i=0;i<n-k+1;i++){
		ll sub ;
		if(x.at(i+k-1)<=0) sub = x.at(i)*-1 ;
		else if(x.at(i)>=0) sub = x.at(i+k-1) ;
		else sub = x.at(i+k-1)-x.at(i)+min(x.at(i)*-1,x.at(i+k-1)) ;
		if(ans>sub) ans = sub ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  int n,k;
  cin>>n>>k;
  if(((n+1)/2)<k)cout<<"NO";
  else cout<<"YES";

  return 0;

}


Measured memory_bytes: 256
C = [list(map(int,input().split())) for i in range(3)]

import sys

a1 = max(C[0])
a2 = max(C[1])
a3 = max(C[2])

for i in range(a1+1):
    for j in range(a2+1):
        for k in range(a3+1):
            if C[0][0] - i == C[1][0] - j and C[1][0] - j == C[2][0] - k:
                if C[0][1] - i == C[1][1] - j and C[1][1] - j == C[2][1] - k:
                    if C[0][2] - i == C[1][2] - j and C[1][2] - j == C[2][2] - k:
                        print('Yes')
                        sys.exit()
                        
print('No')

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main(){
    int H, W, M; cin >> H >> W >> M;
    vector<int> maxH(H), maxW(W);
    map<pii, int> mp;
    int mxh = -1; int mxw = -1;
    rep(i, M){
        int a, b; cin >> a >> b; a--; b--;
        maxH[a]++;
        chmax(mxh, maxH[a]);
        maxW[b]++;
        chmax(mxw, maxW[b]);
        mp[{a,b}] = 1;
    }
    int res = mxh + mxw;
    ll cnt1 = 0, cnt2 = 0, cnt3 = 0;

    rep(i, H){
        if(maxH[i]==mxh)cnt1++;
    }
    rep(i, W){
        if(maxW[i]==mxw)cnt2++;
    }
    ll sumcnt = cnt1 * cnt2;
    for(auto m: mp){
        int a = m.first.first, b = m.first.second;
        if(maxH[a] == mxh && maxW[b] == mxw)cnt3++;
    }
    if(cnt3 == sumcnt)res--;
    /*cout << mxh << " " << mxw << ln;
    cout << sumcnt << " " << cnt3 << ln;*/
    cout << res << ln;
}
    


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

using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  int N,M;
  cin >> N >> M;

  if (N==M) {
    cout << "Yes" << endl;
  }

  else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
n=int(input())
a,b=[],[]
for i in range(n):
    c,d=map(int,input().split())
    a.append(c)
    b.append(d)
a.sort()
b.sort()
if n%2==0:
    x=[a[n//2-1],a[n//2]]
    y=[b[n//2-1],b[n//2]]
    print(sum(y)-sum(x)+1)
else:
    x=a[n//2]
    y=b[n//2]
    print(y-x+1)

Measured memory_bytes: 25556
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

INF = 1<<29

DIV = 10**9+7

def make2d_arr(w,h,val =INF):
    return [[val]*w for i in xrange(h)]

def floyd_warshall(costs):
    N = len(costs)
    for k in xrange(N):
        for i in xrange(N):
            for j in xrange(N):
                costs[i][j]  = min(costs[i][j],costs[i][k]+costs[k][j])
    return costs

def findMinDiff(N,A,B,checked):
    for i in xrange(N):
        if checked[i]:
            continue
        if ((A ^ B)& (1<<i))!= 0:
            return i
    return -1


def findC(N,A,B,checked):
    #print N,A,B
    now_chk = checked[:]
    m = findMinDiff(N,A,B,checked)
    if m ==-1:
        return [A]
    now_chk[m]= True
    exp_m = 1<<m
    for i in xrange(N):
        if not now_chk[i]:
            exp_i = (1<<i)
            C = A ^ exp_i
            fst = findC(N,A,C, now_chk)
            snd = findC(N,C,B, now_chk)
            snd = map(lambda x: (x&((1<<N)-1-exp_m)) + (B & exp_m),  snd)
            return fst+snd

    else:
        return [A,B]

N,A,B = ints_raw()

DIF_B = []
A2s = []
B2s = []
num_db =0

for i in xrange(N):
    a2 = (A>>i)%2
    b2 = (B>>i)%2
    A2s.append(a2)
    B2s.append(b2)
    if a2 == b2:
        DIF_B.append(0)    
    else:
        DIF_B.append(1)
        num_db+=1
    
numP = (2**N)-1
if (num_db > numP) or (num_db%2 ==0):
    print "NO"
else:
    print "YES"
    ans =  findC(N,A,B,[False]*N)
    for a in ans:
        print a,









Measured memory_bytes: 9832
#include<iostream>
#include <string>
#include <stdio.h>
using namespace std;

int main()
{
    //　数値の定義
    int natsu; //夏休み
    int kadai; //課題数
    cin >> natsu;
    cin >> kadai;

    int use[kadai]; //必要日数
    int total = 0;
    
    for(int i = 0; i < kadai; i++){
        cin >> use[i];
        total += use[i];
    }


    // 操作
    
    
    //判定
    if(total > natsu){
        cout << "-1" << endl;
    }else{
        cout << natsu - total << endl;
    }
    return 0;
}

Measured memory_bytes: 3236
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
//#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define reps(i, j, k) for(auto i = j; i < k; ++i)
#define rep(i, j) reps(i, 0, j)
#define decs(i, j, k) for(auto i = j; i >= k; --i)
#define dec(i, j) decs(i, j, 0)
#define iter(i, j) for(auto i = j.begin(); i != j.end(); ++i)
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int, int>
#define vpi vector<pi>
#define vb vector<bool>
#define F first
#define S second
#define mp make_pair
#define um unordered_map
#define all(x) (x).begin(), (x).end()  
#define fast_io ios::sync_with_stdio(0); cin.tie(0);
#define file_io freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define IMAX std::numeric_limits<int>::max()
#define IMIN std::numeric_limits<int>::min()
using namespace std;

int main()
{
    string s; cin >> s;
    int n = s.length();
    rep(i, n) s[i] = 'x';
    cout << s;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
     public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while (true) {
            int mid = input.nextInt();
            int last = input.nextInt();
            int makeUp = input.nextInt();
            int tot = mid + last;
            if ( mid == -1 && last == -1 && makeUp == -1){
                break;
            }
            if (mid == -1 || last == -1) {
                System.out.println("F");
            }else if (tot >= 80) {
                System.out.println("A");
            } else if (tot >= 65) {
                System.out.println("B");
            } else if (tot >= 50) {
                System.out.println("C");
            } else if (tot >= 30) {
                String res = makeUp >= 50 ? "C" : "D";
                System.out.println(res);
            } else {
                System.out.println("F");
            }
        }
    }
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (ll i = 0; i < N; ++i) cin >> A[i];
    sort(A.rbegin(), A.rend());
    ll res = A[0];
    ll j = 1;
    int count = 0;
    for (ll i = 2; i < N; ++i) {
        if (count == 0) { 
            res += A[j];
            count++;
            continue;
        }
        if (count == 1) {
            res += A[j];
            j++;
            count = 0;
            continue;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4828
import itertools
n = int(input())
p = tuple(((map(int,input().split()))))
q = tuple(((map(int,input().split()))))

num = []
for i in range(1,n+1):
    num.append(i)
ans = []
for i in itertools.permutations(num,n):
    ans.append(i)

print(abs(ans.index(p)-ans.index(q)))


Measured memory_bytes: 44784
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 5000
#define MO 1000000007
using namespace std;
char str[MAXN+5];
int N;
int dp[MAXN+5][MAXN+5];//dp[i][j]:走到第i位花了j步
int main()
{
	scanf("%d",&N);
	scanf("%s",str+1);
	int len=strlen(str+1);
//	int len=N/2;
	dp[0][0]=1;
	for(int tmn=1;tmn<=N;tmn++)
	{
		for(int pos=0;pos<=N;pos++)
		{
			if(pos!=N)
				dp[tmn][pos]=(1LL*dp[tmn][pos]+2LL*dp[tmn-1][pos+1]%MO)%MO;
			if(pos!=0)
				dp[tmn][pos]=(1LL*dp[tmn][pos]+1LL*dp[tmn-1][pos-1])%MO;
			if(pos==0)
				dp[tmn][pos]=(1LL*dp[tmn][pos]+1LL*dp[tmn-1][pos])%MO;
		}
	}
	printf("%d\n",dp[N][len]);
	return 0;
}

Measured memory_bytes: 97920
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<map>
#include <bits/stdc++.h>
typedef long long ll;
#define N 100010
using namespace std;

void solve()
{
	string s;
	cin>>s;
	for (int i=0;i<s.size();i++)
		if (s[i]=='?')
			cout<<'D';
		else
			cout<<s[i];
}

int main() 
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	int t;
//	cin>>t;
//	while (t--) 
		solve();
	return 0;
}

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

public class Main { // "Main" should be used for most online judges
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int result = 1;
		int hiCount = 0;
		int tempNumb = 0;
		int count = 0;
		for(int i = n; i > 0; i--){
			tempNumb = i;
			//System.out.println("temp: " + tempNumb);
			while(i % 2 == 0) {
				count++;
				i = i/2;
			}
			//System.out.println(tempNumb);
			i = tempNumb;
//			System.out.println("i: " + i + " Count: " + count);
//			System.out.println("High Count: " + hiCount);
			if(count > hiCount) {
				result = tempNumb;
				hiCount = count;
			}
			count = 0;
		}
		System.out.println(result);

		sc.close();
	}
	
}

Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

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

int main() {

    ll x,y;
    cin >> x >> y;
    ll out = abs(abs(x)-abs(y));
    if(x*y==0){
        if(x>y) out ++;
    }else if(x*y>0){
        if(x>y) out += 2;
    }else out++;
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int l,i,j,sum=0,ban;
  scanf("%d",&l);
  int num[3+1][l+1];
  for(i=1;i<=3;i++){
    for(j=1;j<=l;j++){
      scanf("%d",&num[i][j]);
      if(i==3&&j==l-1){
        break;
      }
    }
  }
  for(i=1;i<=l;i++){
    ban=num[1][i];
    sum+=num[2][ban];
    if(num[1][i]+1==num[1][i+1]){
      sum+=num[3][ban];
    }
  }
  printf("%d",sum);
  return 0;
}
  


Measured memory_bytes: 128
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){

  long n,ii;
  vector<long> a;
  long zeroNum = 0;
  long plsNum = 0;
  long minusNum = 0;
  long min = LONG_MAX;
  long minPos = -1;
  long sum =0;
  cin >> n;

  a.resize(n);
  for(ii=0;ii<n;ii++){
    cin >> a[ii];

    if(a[ii] == 0){
      zeroNum++;
    }
    else if(a[ii] > 0){
      plsNum++;
    }
    else if(a[ii] < 0){
      minusNum++;
    }

    if( abs(a[ii]) < abs(min)){
      min = a[ii];
      minPos = ii;
    }
  }

  //cout << "minPos" << minPos << endl << LONG_MIN << endl;
  if(zeroNum >= 1 ||
     (minusNum % 2) == 0){

    for(ii=0;ii<n;ii++){
      sum += abs(a[ii]);
    }
    
  }
  else{

    for(ii=0;ii<n;ii++){
      if(ii==minPos){
	if(a[ii] > 0){
	  sum -= a[ii];
	}
	else{
	  sum += a[ii];
	}
      }
      else{
	sum += abs(a[ii]);
      }
    }
  }

  cout << sum << endl;
    
  return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1ll, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	rep(i, 0, n)cin >> a[i];
	rep(i, 0, n)cin >> b[i];
	reverse(all(b));
	rep(i, 0, n) {
		if (a[i] == b[i]) {
			bool check = false;
			rep(i2, 0, n) {
				if (a[i] != a[i2] && b[i2] != a[i]) {
					swap(b[i], b[i2]);
					check = true;
					break;
				}
			}
			if (!check) {
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	rep2(v, b)printf("%d ", v);
	puts("");
	return 0;
}


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

int main(){
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  cout<<abs(a-d)+(b!=e||c!=f)*( (a-d)*(b*100+c-e*100-f)>=0 )<<endl;
  return 0;
}



Measured memory_bytes: 3096
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

template <typename T>
class fenwick_tree {
  int size, depth;
  vector<T> data;

public:
  fenwick_tree() = default;
  explicit fenwick_tree(int n)
    : size(n), depth(int(log2(n)) + 1), data(n + 1) {}

  T query(int i) {
    T result = 0;
    for (; i > 0; i -= i & -i) result += data[i];
    return result;
  }
  void update(int i, T x) {
    for (; i <= size; i += i & -i) data[i] += x;
  }
  int lower_bound(T x) {
    T sum = 0;
    int pos = 0;
    for (int i = depth; i >= 0; --i) {
      int j = pos + (1 << i);
      if (j <= size && sum + data[j] < x) {
        sum += data[j];
        pos += 1 << i;
      }
    }
    return pos + 1;
  }
};

int main() {
  int n;
  cin >> n;
  ll x;
  vector<pair<ll, int>> a;
  rep(i, 0, n) {
    cin >> x;
    a.emplace_back(x, i + 1);
  }

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

  fenwick_tree<ll> ft(n);

  ll ans = 0;
  rep(i, 0, n) {
    auto [val, idx] = a[i];
    ll l = 0, r = 0;

    ll left_cnt = ft.query(idx);
    if (left_cnt == 0)
      l = idx;
    else {
      int pos = ft.lower_bound(left_cnt);
      l = idx - pos;
    }
    int pos = ft.lower_bound(left_cnt + 1);
    r = pos - idx;
    ans += val * l * r;
    ft.update(idx, 1);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 8036
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.D_Challenge
{
    class ABC_096
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            long[] primes = PrimeNumbers(1, 55555);
            int primeI = 0;
            for(int i = 0; i < n; i++)
            {
                for (; primeI < primes.Length; primeI++)
                {
                    if (primes[primeI] % 5 == 1)
                    {
                        Console.Write(primes[primeI] + " ");
                        primeI++;
                        break;
                    }
                }
            }
        }

        static long[] PrimeNumbers(long min, long max)
        {
            var primes = new List<long>();
            if (min <= 2 && max >= 2)
            {
                primes.Add(2);
            }
            for (long i = 3; i <= max; i += 2)
            {
                long rootI = (long)Math.Sqrt(i);
                bool isPrime = true;
                for (long j = 3; j <= rootI; j += 2)
                {
                    if (i % j == 0)
                    {
                        isPrime = false;
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
                if (isPrime)
                {
                    primes.Add(i);
                }
            }
            return primes.ToArray();
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11156
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef double R;
typedef complex<R> P;

const R EPS = 1e-10;
const R PI = acos((R)(-1));

R radNorP(R x) {
    return fmod(fmod(x, 2*PI)+2*PI, 2*PI);
}

const int MN = 330;

P p[MN];
typedef pair<R, int> Pi;

bool solve() {
    int n;
    cin >> n;
    if (!n) return false;

    for (int i = 0; i < n; i++) {
        R x, y;
        cin >> x >> y;
        p[i] = P(x, y);
    }

    int res = 1;
    for (int i = 0; i < n; i++) {
        vector<Pi> v;
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            if (2.0 < abs(p[j]-p[i])) continue;
            R th = acos(abs(p[j]-p[i])/2.0);
            R l = radNorP(arg(p[j]-p[i])-th);
            R r = radNorP(arg(p[j]-p[i])+th);
            if (r < l) {
                v.push_back(Pi(l, 1));
                v.push_back(Pi(2*PI, -1));
                v.push_back(Pi(0, 1));
                v.push_back(Pi(r, -1));
            } else {
                v.push_back(Pi(l, 1));
                v.push_back(Pi(r, -1));
            }

        }

        sort(v.begin(), v.end());
        int sm = 1;
        for (Pi p: v) {            
            sm += p.second;
            res = max(res, sm);
        }
    }
    cout << res << endl;
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}

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

//4 % 6 6,4
//6 % 4 4,2
//4 % 2 = 0 2
//(4 / 2) * (6 / 2)  * 2;
//(4 + 6) / 2 * 2;
//(c[0] / gcd) * (c[0] / gcd)
//(4 / 2) * (6 / 2) * (12 / 2) * 2;
//1 * 3 * 3 * 2 = 12

//a = a'm
//b = b'm
//c = c'm
//a',b',c'ªf
//a'b'c' / m ^ 2
//2 3 6
long long int gcd(long long int a, long long int b){
	if(b == 0)return a;
	return gcd(b,a % b);
}

//4 6 2 * (4 / 2) * (6 / 2)
//=2 * 2 * 3 = 12
long long int lcm(long long int a, long long int b){
	return a * b / gcd(a,b);
}

int main(){
	long long int a[3], m[3], p[3] = {1,1,1}, c[3] = {0};
	while(1){
		memset(c,0,sizeof(c));
		cin >> a[0] >> m[0] >> a[1] >> m[1] >> a[2] >> m[2];
		if(!a[0])break;
		for(int i=0;i<3;i++){
			do{
			p[i] = (a[i] * p[i]) % m[i];
			//cout << "Turn " << c[i] << ": " << p[i] << endl;
			c[i] += 1;
			}while(p[i] != 1);
		}
		//cout << c[0] << c[1] << c[2] << endl;
		//int gcd = rec(c[0],rec(c[1],c[2])),
		//lcm = rec(c[0],gcd) * rec(c[1],gcd) * rec(c[2],gcd) * gcd;
			//cout << gcd << " " << lcm << endl;
		cout << lcm(lcm(c[0],c[1]),c[2]) << endl;
	}
	//2 * 1 % 5 = 2;
	//2 * 2 % 5 = 4;
	//2 * 4 % 5 = 3;3ñÚÅÍÈ¢©D
	//2 * 3 % 5 = 1;
	//3 * 1 % 7 = 3;
	//3 * 3 % 7 = 2;
	//3 * 2 % 7 = 6;
	//3 * 6 % 7 = 4;
	//3 * 4 % 7 = 5;
	//3 * 5 % 7 = 1;6ñÚ
	return 0;
}

Measured memory_bytes: 0
N, M, Q = list(map(int, input().split()))

trains = [[0]*N for j in range(N)]

for i in range(M):
    l, r = list(map(int, input().split()))
    trains[r-1][l-1] += 1

ans = [[0]*N for j in range(N)]
ans[0][0] = trains[0][0]

for e in range(1, N):  # endのe
    for s in reversed(range(N)):  # startのs
        if s == e:
            ans[e][s] = trains[e][s]
        else:
            ans[e][s] = sum(trains[e][s:]) + ans[e-1][s]


for i in range(Q):
    p, q = list(map(int, input().split()))
    print(ans[q-1][p-1])


Measured memory_bytes: 13020
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  a.push_back(-1e9);
  ll ans = 1000;
  ll tmp = 0, bf = a.at(0);
  bool mode;
  if(a.front() < a.at(1)) mode = true;
  else mode = false;
  rep2(i, 1, n+1){
    // cerr << ans << " " << mode << endl;
    if(mode == false){
      if(a.at(i-1) < a.at(i)){
        bf = a.at(i-1);
        mode = true;
      }
    }else{
      if(a.at(i-1) > a.at(i)){
        tmp = ans/bf * a.at(i-1);
        ans = ans % bf;
        ans += tmp;
        mode = false;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
from sys import stdin
import numpy as np
from operator import itemgetter

N, D = [int(x) for x in stdin.readline().rstrip().split()]
X = []
for i in range(N):
    xi = [int(x) for x in stdin.readline().rstrip().split()]
    X.append(xi)

def distance(a,b):
    ret = 0
    for i in range(D):
        ret += (a[i] -b[i])**2

    ret = np.sqrt(ret)
    return ret

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        d = distance(X[i], X[j])
        if d-int(d)==0:
            ans+=1
print(ans)


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

using namespace std;


void solve() {
    int n; cin >> n;
    set<int> s;
    for (int _ = 0; _ < n; _++) {
        int x; cin >> x;
        s.insert(x);
    }
    int res = s.size();
    if ((n-s.size())&1) res--;
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 4992
#include<stdio.h>
int main()
{
  int i,j,k,v,N,A[100];
  scanf("%d",&N);
  for(i=0;i<N;i++)
    {
      scanf("%d",&A[i]);
    }

        for(k=0;k<N-1;k++)
	{
	  printf("%d ",A[k]);
	}
      printf("%d\n",A[N-1]);
      
  for(i=1;i<N;i++)
    {
      v=A[i];
      j=i-1;
      while(j>=0&&A[j]>v)
	{
	  A[j+1]=A[j];
	  j--;
	}
      A[j+1]=v;
      for(k=0;k<N-1;k++)
	{
	  printf("%d ",A[k]);
	}
      printf("%d\n",A[N-1]);
    }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
long long m=1e9+7;
long long fact[1000001],inv[1000001];

long long modRecursive(long long a,long long b,long long c)
{
	if(b == 0) return 1;
	if(b%2 ==0) return modRecursive((a*a)%c,b/2,c);
	else return ((a%c)*(modRecursive((a*a)%c,b/2,c)))%c;
}

int main()
{
    string s;
    cin>>s;
    stack<string> x;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i]=='0' || s[i]=='1') x.push(s.substr(i,1));
        else if(s[i]=='B')
            if(!x.empty()) x.pop();
    }
    string ans="";
    while(!x.empty())
    {
        ans = ans+x.top();
        x.pop();
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    if(n == 1e5 || n == 1e4 || n == 1e3 || n == 10) cout << 10 << endl;
    else {
        int a = n / 10000;
        int b = (n - 10000 * a) / 1000;
        int c = (n - 10000 * a - 1000 * b) / 100;
        int d = (n - 10000 * a - 1000 * b - 100 * c) / 10;
        int e = n % 10;
        cout << a + b + c + d + e << endl;
    } 
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

int N, X[2000], Y[2000], odds = 0;
void findPath(int x, int y) {
  for(int i = 30;i >= 0;i--) {
    if((abs(x) < abs(y)) & y > 0) {
      cout << "U";
      y = y - (1 << i);
    } else if((abs(x) < abs(y)) & y < 0) {
      cout << "D";
      y = y + (1 << i);
    } else if((abs(x) > abs(y)) & x > 0) {
      cout << "R";
      x = x - (1 << i);
    } else {
      cout << "L";
      x = x + (1 << i);
    }
  }
}

int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  cin >> N;
  for(int i = 0;i < N;i++) {
    cin >> X[i] >> Y[i];
    if((abs(X[i]) + abs(Y[i])) % 2 != 0) odds++;
  }

  if(odds > 0 and odds < N) {
    cout << "-1" << endl;
    return 0;
  }

  if(odds == 0) {
    for(int i = 0;i < N;i++) X[i] -= 1;
  }

  if(odds == 0) cout << "32" << endl;
  else cout << "31" << endl;

  if(odds == 0) cout << 1 << " ";
  for(int i = 30;i >= 0;i--) {
    cout << (1LL << i) << " ";
  }

  cout << endl;

  for(int i = 0;i < N;i++) {
    if(odds == 0) cout << "R";
    findPath(X[i], Y[i]);
    cout << endl;
  }

  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

const int MOD = 1e9+7;

ll mulM(ll a, ll b){
	return ((a % MOD) * (b % MOD)) % MOD;
}

int n, k;
vvi to;
ll ans;

void dfs(int v = 0, int p = -1){
    int color = k-1;
    if(p != -1) color--;
    for(auto u : to[v]){
        if(u == p) continue;
        ans = mulM(ans, color);
        color--;
        dfs(u, v);
    }
}

void Main(){
    cin >> n >> k;
    to.resize(n);
    rep(i, n-1){
        int a, b; cin >> a >> b; a--; b--;
        to[a].pb(b);
        to[b].pb(a);
    }
    ans = k;
    dfs();
    cout << ans << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 13404
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
n,k=IL()
if n%2==0:
    if 2*k>n:
        print("NO")
    else:
        print("YES")
else:
    if n//2+1<k:
        print("NO")
    else:
        print("YES")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define ll long long
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
const double pi = acos(-1.0);
const double eps = 1e-9;
using namespace std;

void solve(){
    int n;
    cin >> n;
    vector <int> a(n), b(n);
    
    for (int i = 0; i < n; i++) cin >> a[i];

    for (int i = 0; i < n; i++) b[i] = a[i];
    
    sort(b.begin(), b.end());

    map <int, int> mp;
    for (int i = 0; i < n; i++) mp[b[i]] = i;
    vector <int> pos;
    for (int i = 0; i < n; i++){
        if (abs(mp[a[i]] - i) % 2) pos.pb(i);
    }
    
    cout << (int)pos.size() / 2 << endl;
}   
int main(){
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(10);
    //freopen("input.txt", "r", stdin);//freopen("output1.txt", "w", stdout);
    //freopen("icecream.in","r",stdin);// freopen("exam.out", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++){
         solve();
    }
}


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

using ll = long long;
const ll INF = 1e10;

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> posis;
  vector<ll> negas;
  {
    ll x;
    for(int i = 0; i < N; ++i) {
      cin >> x;
      if(x >= 0) {
        posis.push_back(x);
      } else {
        negas.push_back(x);
      }
    }
  }
  sort(posis.begin(), posis.end(), less<int>());
  sort(negas.begin(), negas.end(), greater<int>());

  if(posis.size() == 0) {
    cout << abs(negas[K - 1]) << endl;
    return 0;
  }
  if(negas.size() == 0) {
    cout << posis[K - 1] << endl;
    return 0;
  }

  int posi_limit = min(K, (int)posis.size());
  int nega_limit = min(K, (int)negas.size());

  ll ans = INF;

  for(int k = posi_limit - 1; k >= 0; --k) {
    auto posi_num = k + 1;
    auto nega_num = K - posi_num;
    if(nega_num > nega_limit) {
      break;
    }
    if(posi_num == 0) {
      chmin(ans, abs(negas[nega_num - 1]));
      continue;
    }
    if(nega_num == 0) {
      chmin(ans, posis[posi_num - 1]);
      continue;
    }
    chmin(ans, posis[posi_num - 1] + abs(negas[nega_num - 1]) * 2);
    chmin(ans, posis[posi_num - 1] * 2 + abs(negas[nega_num - 1]));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1656
using System;

class myclass
{
    public static void Main()
    {
        string name = Console.ReadLine();
        char a = name[0];
        char b = name[2];
        char ans = ' ';

        if (a == 'H') //AtCoDeerくんが正直者
        {
            if (b == 'H')  //「Tくんは正直者だよ！」
                ans = 'H';
            if (b == 'D')  //Tくんはうそつきだよ
                ans = 'D';
        }
        else if (a == 'D')  //AtCoDeerくんはうそつき
        {
            if (b == 'H')  //「Tくんは正直者だよ！」
                ans = 'D';
            if (b == 'D')  //Tくんはうそつきだよ
                ans = 'H';
        }

        Console.Write(ans);
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  int c = 0;
  rep3(i, 1, n - 1) {
    if (max({a[i - 1], a[i], a[i + 1]}) != a[i] && min({a[i - 1], a[i], a[i + 1]}) != a[i]) c++;
  }
  cout << c << '\n';
}


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

typedef long long int64;

int main()
{
  int N;
  cin >> N;
  vector< int64 > a(N);
  map< int64, int64 > mp;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    mp[a[i]]++;
  }

  int64 ans = 0ll;
  for (auto&& mi : mp) {
    if (mi.second < mi.first) {
      ans += mi.second;
    } else {
      ans += mi.second - mi.first;
    }
	
    // ans += min(mi.second, abs(mi.second - mi.first));
  }

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


Measured memory_bytes: 7040
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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

__attribute__ ((constructor))
void init() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
}

ll gcd(ll a, ll b){
    if(a < b)  swap(a,b);
    if(a%b==0) return b;
    else return gcd(b,a%b);
}
ll ngcd(vector<ll> a){
    ll res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
ll nlcm(vector<ll> numbers) {
    ll res;
    res = numbers[0];
    for (ll i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}

ll calc(ll a,ll b){
    ll x = 1, y = 1;
    rep(i,b){
        x *= a - i;
        y *= b - i;
        ll copy = gcd(x, y);
        x /= copy;
        y /= copy;
    }
    return x / y;
}

signed main(){
    ll n, p;
    cin >> n >> p;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];
    ll a = 0, b = 0;
    rep(i,n){
        if(v[i]%2==1)
            a++;
        else
            b++;
    }
    if(p==0){
        if(a == 0)
            cout << (1LL << b) << endl;
        else{
            ll cnt = 0;
            rep(i,a+1){
                if(i%2!=0)
                    continue;
                cnt += calc(a, i);
            }
            cout << (1LL << b) * cnt << endl;
        }
    }
    else{
        if(a==0)
            cout << 0 << endl;
        else{
            ll cnt = 0;
            rep(i,a+1){
                if(i%2==0)
                    continue;
                cnt += calc(a, i);
            }
            cout << (1LL << b) * cnt << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3620
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n;
  rd(n);
  auto a = readln.split.to!(long[]);

  import std.math : abs;

  int arg_abs_max = 0;
  foreach (i; 1 .. n) {
    if (abs(a[arg_abs_max]) < abs(a[i])) {
      arg_abs_max = i;
    }
  }
  struct T {
    int y, x;
    string toString() {
      return format("%d %d", x, y);
    }
  }

  T[] ans;
  foreach (i; 0 .. n) {
    if (i != arg_abs_max) {
      ans ~= T(i + 1, arg_abs_max + 1);
      a[i] += a[arg_abs_max];
    }
  }
  if (a[arg_abs_max] >= 0) {
    foreach (i; 1 .. n) {
      ans ~= T(i + 1, i);
      a[i] += a[i - 1];
    }
  } else {
    foreach_reverse (i; 1 .. n) {
      ans ~= T(i, i + 1);
      a[i - 1] += a[i];
    }
  }
  import std.exception : enforce;

  enforce(ans.length <= n * 2);
  foreach (i; 1 .. n)
    enforce(a[i - 1] <= a[i]);
  writeln(ans.length);
  writefln("%(%s\n%)", ans);
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define int long long
# define endl "\n"
using namespace std;

void solve() {

	int x, k, d;
	cin >> x >> k >> d;
	if (x < 0) {
		x *= -1;
	}
	int md = x % d;
	int k1 = x / d;
	int ans;
	if (k1 >= k) {
		ans = x - k * d;
	}
	else {
		k -= k1;
		if (k % 2 == 0) {
			ans = md;
		}
		else {
			ans = d - md;
		}
	}
	cout << ans << endl;
}
signed main() {

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

# ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
# endif

	// int t;
	// cin >> t;
	// while (t--)
	solve();

	return 0;
}

Measured memory_bytes: 3648
import math
N,K=map(int,input().split())

points=[]
for i in range(N):
    x=K/(i+1)
    y=math.log(x)/math.log(2)
    y=max(0,math.ceil(y))
    z=pow(2,-math.ceil(y))
    points.append(z)
print(sum(points)/N)

Measured memory_bytes: 4120
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    S,W = map(int,input().split())

    if S <= W:
        res = 'unsafe'
    else:
        res = 'safe'

    print(res)



main()


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll dp[2][2500];

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

    string S; cin >> S;

    ll ans = 0;

    ll N = S.size();

    for (int i = 0;i < N;i++){
        ans += dp[i%2][0];
        //cout << i << " " << ans << endl;
        dp[(i+1)%2][S[i]-'0'] += 1;
        for (int j = 0;j < 2019;j++){
            if(dp[(i)%2][j] == 0) continue;
            dp[(i+1)%2][(j*10+S[i]-'0')%2019] += dp[i%2][j];
        }
        for (int j = 0;j < 2019;j++){
            dp[(i)%2][j] = 0;
        }
    }

    ans += dp[(S.size())%2][0];

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 3748
#include<cstdio>

int main(){
	char b;
	scanf("%c", &b);
	if(b == 'A') printf("T\n");
	else if(b == 'T') printf("A\n");
	else if(b == 'G') printf("C\n");
	else printf("G\n");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main() {
	int A,B;
	scanf("%d %d",&A,&B);
	int tmp1 = A/10, tmp2 = B/10;
	if (tmp1 > 0 || tmp2 > 0) printf("-1\n");
	else printf("%d\n",A*B);
	return 0;
}

Measured memory_bytes: 128
import collections as col
N , X , Y = map(int,input().split())

l = []

for i in range(1,N+1):
    for j in range(i+1,N+1):
        mindis = min(abs(j - i), abs(X - i) + 1 + abs(j - Y ), abs(Y - i) + 1 + abs(j - X))
        l.append(mindis)
        
d = col.Counter(l)

for k in range (N-1):
    print(d[k+1])

Measured memory_bytes: 67808
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;

map<string, long long> res;

int main() {
	int N;
	cin >> N;
	vector<string> S(N);
	vector<char> tmp(10);

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> tmp.at(j);
		}

		sort(tmp.begin(), tmp.end());
		string tmp2;
		for (int j = 0; j < 10; j++) {
			tmp2 = tmp2 + tmp.at(j);
		}

		if (res.count(tmp2) == 0) {
			res.insert(make_pair(tmp2, 0));
		}
		else {
			res[tmp2] = res[tmp2] + 1;
		}
	}
	long long result = 0;
	for (auto itr = res.begin(); itr != res.end(); itr++) {
		
		for (int i = 0; i < itr->second; i++)
		{
			result = result + i + 1;
		}
	}
	cout << result << endl;
}

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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

//---------------------------------------------------------------
//---------------------------------------------------------------

int N;

signed main(){
	cin >> N;
	
	int t, x, y, st=0, sx=0, sy=0;
	REP(i, 0, N) {
		cin >> t >> x >> y;
		if(((t - st) % 2) != ((x - sx + y - sy) % 2)
				|| (t - st) < (x - sx + y - sy)) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	
	return 0;
}


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

#define int long long
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

const unsigned int M = 1e9 + 7;

int32_t main() {
	fastio;

	char c;
	cin >> c;
	if(islower(c)) cout << 'a';
	else cout << 'A';

	return 0;
}


Measured memory_bytes: 3608
#include <algorithm>
#include <array>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>


int main ()
{
  int N, M;
  std::cin >> N >> M;

  const int nmax = 4;
  std::array<int, nmax> arr;

  const int NIL = -1;
  arr.fill(NIL);

  int s, c;
  for (int i=0; i<M; ++i)
    {
      std::cin >> s >> c;

      if (arr[s] == NIL)
        {
          arr[s] = c;
        }
      else if (arr[s] != c)
        {
          std::cout << -1 << std::endl;
          return 0;
        }
    }

  for (int i=1; i<=N; ++i)
    {
      if (arr[i] == NIL)
        {
          if (N == 1)
            arr[i] = 0;
          else {
            if (i == 1)
              arr[i] = 1;
            else
              arr[i] = 0;
          }
        }
    }

  if (N>1 && arr[1] == 0) {
    std::cout << -1 << std::endl;
    return 0;
  }

  int ans = 0;
  int keta = 1;
  for (int i = N; i >= 1; --i) {
    ans += arr[i] * keta;
    keta *= 10;
  }
  
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

int main(){
   int N, A;
   cin >> N >> A;

   bool is_ok = false;
   for(int i = 0; i <= A; i++){
      int j = 0;
      int cost = 0;
      while(cost <= N){
         cost = 500 * j + i;
         if(cost == N){
            is_ok = true;
         }
         j++;
      }
   }
   if(is_ok){
      cout << "Yes" << endl;
   }
   else{
      cout << "No" << endl;
   }
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, a[200005];
int main() {
	cin >> n;
	for (int i = 1; i <= n; i ++) cin >> a[i];
	if (n & 1) {
		for (int i = n; i >= 1; i -= 2) {
			cout << a[i] << " ";
		}
		for (int i = 2; i <= n; i += 2) {
			cout << a[i] << " ";
		}
	}
	else {
		for (int i = n; i >= 1; i -= 2) {
			cout << a[i] << " ";
		}
		for (int i = 1; i <= n; i += 2) {
			cout << a[i] << " ";
		}
	}
	cout << endl;
	return 0; 
}


Measured memory_bytes: 2944
x,y=map(int,input().split())
if 0<=x<y:
    print(abs(y-x))
elif -y<x<y:
    print(abs(y+x)+1)
elif x<=-y<0:
    print(abs(-y-x)+1)
elif x<y<=0:
    print(abs(y-x))
elif 0<y<x:
    print(abs(-y+x)+2)
elif y==0 and y<x:
    print(abs(x)+1)
elif -x<=y<0:
    print(1+abs(y+x))
elif 0<=x<-y:
    print(abs(-y-x)+1)
else:
    print(abs(-y+x)+2)


Measured memory_bytes: 3064