akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<typename T>
void print(T &arr){
    ll sz = sizeof(arr)/sizeof(arr[0]);
    for(int i = 0;i < sz-1;i++){cout << arr[i] << ' ';}
    cout << arr[sz-1] << endl;
}


int main(){
    ll n,m,l;cin >> n >> m >> l;
    ll INF = 1e10+10;
    vector<vector<ll>> graph(n,vector<ll>(n,INF));
    rep(i,m){
        ll a,b,c;cin >> a >> b >> c;
        a--;b--;
        graph[a][b] = c;
        graph[b][a] = c;
    }
    ll q; cin >> q;
    vector<P> st(q);
    rep(i,q){
        int s,t; cin >> s >> t;
        s--;t--;
        st[i] = P(s,t);
    }
    // ワーシャルフロイド
    rep(i,n)graph[i][i] = 0;
    rep(k,n){
        rep(i,n){
            rep(j,n){
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[j][k]);
            }
        }
    }

    // print(graph);
    vector<vector<ll>> res(n,vector<ll>(n,INF));
    rep(i,n)rep(j,n){
        if(graph[i][j] <= l)res[i][j] = 1;
    }
    rep(i,n)res[i][i] = 0;
    rep(k,n)rep(i,n)rep(j,n)res[i][j] = min(res[i][j], res[i][k] + res[k][j]);

    rep(i,q){
        cout << (res[st[i].first][st[i].second] == INF ? -1 : res[st[i].first][st[i].second] - 1) << endl;
    }
    return 0;
}

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

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

    static class BBounding {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int x = in.nextInt();
            int d = 0;
            int best = 1;
            for (int i = 0; i < n; i++) {
                d += in.nextInt();
                if (d > x) {
                    best = i + 1;
                    break;
                }
                if (i == n - 1)
                    best = n + 1;
            }
            out.println(best);
        }

    }
}



Measured memory_bytes: 23764
// Problem : F - Strivore
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 3e3 + 5;
const ll MOD = 1e9 + 7;

ll dp[maxN][maxN];

ll pow2(ll a, ll b) {
	if (b == 0) return 1;
	if (b == 1) return a;
	ll d = pow2(a, b / 2);
	d = d * d % MOD;
	if (b % 2) return d * a % MOD;
	return d;	
}

const ll MAX = 2e6;
ll fact[MAX + 5], invFact[MAX + 5];
void facts() {
	fact[0] = invFact[0] = 1;
	RI(i, MAX) {
		fact[i] = fact[i - 1] * i % MOD;
		invFact[i] = pow2(fact[i], MOD - 2);
	}
}

ll choose(ll n, ll k) {
	return (fact[n] * invFact[k] % MOD) * invFact[n - k] % MOD;
}


// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	int m = sz(s);
	facts();
	ll ans = 0;
	FOR(i, m, n + m) {
		ll tmp = choose(n + m, i) * pow2(25, n + m - i);
		ans = (ans + tmp) % MOD;
	}
	cout << ans << "\n";
	return 0;
}
 


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

int main() {

  int n;
  cin >> n;

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

    int cnt[10] = {0};

    char c;
    for ( int j = 0; j < 8; j++ ) {
      cin >> c;
      cnt[c-'0']++;
    }

    int x = 0;
    int y = 0;
    int z = 1;

    for ( int j = 0; j < 10; j++ ) {

      if ( cnt[j] != 0 ) {

	cnt[j]--;
	x += j*z;
	y += j*(10000000/z);
	j--;
	z*=10;
	continue;

      }

    }

    cout << x - y << endl;

  }

  return 0;

}

Measured memory_bytes: 1160
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
using namespace std;
int main(){
	int a = 0, b = 0, c = 0, d = 0, e[500] = { 0 }, counto=0;
	pair<char, int>n[10][10];
	cin >> a >> b>>c;
	cout << a * b / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
def solve(string):
    a, b, c, x = map(int, string.split())
    ans = 0
    for i in range(a + 1):
        for j in range(b + 1):
            for k in range(c + 1):
                if 500 * i + 100 * j + 50 * k == x:
                    ans += 1
    return str(ans)


if __name__ == '__main__':
    n = 4
    print(solve('\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end() 
using namespace std;
typedef long long ll;

const int N = 55, MX = 2600;

int n, A, a[N];
ll dp[N][N][MX];

int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cin >> n >> A;
   for(int i=1; i<=n; ++i) cin >> a[i];
   dp[0][0][0] = 1ll;
   // dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-a[i]]
   // among first i cards selecting j cards you can make sum - k
   for(int i=1; i<=n; ++i) {
       for(int j=1; j<=n; ++j) {
           for(int k=0; k<MX-a[i]; ++k) {
               dp[i][j-1][k] += dp[i-1][j-1][k];
               dp[i][j][k+a[i]] += dp[i-1][j-1][k];
           }
       }
   }
   ll res = 0;
   for(int j=1; j<=n; ++j) {
       res += dp[n][j][j*A];
   }
   cout << res << endl;
   return 0;
} 


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

int main() {
  int x,a;
  
  cin >> x;
  
  for(int k=x;;k++){
    a=0;
  for(int i=2; i<x; i++){
    if(k%i==0){
    a=a+1;
    }
    }
    if(a==0){
     cout << k << endl;
      break;
    }
  }
}

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

int main() {
  string S, T;
  cin >> S >> T;

  vector<vector<int>> dp(26 + 'a', vector<int>());
  for (int i = 0; i < S.length(); i++) {
    dp[S[i]].push_back(i);
  }

  for (int j = 0; j < T.length(); j++) {
    if (dp[T[j]].size() == 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  int output = 0;
  int i = -1;
  for (int j = 0; j < T.length(); j++) {
    bool found = false;
    for (int k = 0; k < dp[T[j]].size(); k++) {
      if (dp[T[j]][k] > i) {
        i = dp[T[j]][k];
        found = true;
        break;
      }
    }
    if (!found) {
      output++;
      i = -1;
      j--;
    }
  }

  cout << output * S.length() + i + 1 << endl;

  return 0;
}


Measured memory_bytes: 4204
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct Node1{
  int key1;
  struct Node1 *left,*right,*parent;
};
  
struct Node1 *root,*NIL;
void insert(int );
void ins_order(struct Node1 *);
void pri_order(struct Node1 *);
int main(){
  int k,i,x;
  char order[7];
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%s",order);
    if(strcmp(order,"insert")==0){
    scanf("%d",&x);
    insert(x);
    }else if(strcmp(order,"print")==0){
    ins_order(root);
    printf("\n");
    pri_order(root);
    printf("\n");
    }
  }
  return 0;
}
void insert(int a){
 struct  Node1 *x=root;
 struct Node1 *y=NIL;
 struct  Node1 *z;

  z=(struct Node1 *)malloc(sizeof(struct Node1));
  z->key1=a;
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key1 < x->key1){
      x= x->left;
    }else{
      x= x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key1<y->key1){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}
void ins_order(struct Node1 *u){
  if(u==NIL)return ;
  ins_order(u->left);
  printf(" %d",u->key1);
  ins_order(u->right);
}
void pri_order(struct Node1 *u){
  if(u==NIL)return ;
  printf(" %d",u->key1);
  pri_order(u->left);
  pri_order(u->right);
}

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  int n;
  cin >> n;
  int ans=0;
  ans +=min(9,n);
  ans +=min(900,max(0,n-99));
  ans +=min(90000,max(0,n-9999));
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int a, b;

  std::cin >> a >> b;

  std::string s(b, a + '0'), t(a, b + '0');

  std::cout << (std::stoi(s) >= std::stoi(t) ? s : t) << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define pb push_back
using namespace std;

int main(){
   int a,b,c;
   cin >> a >> b;
   c = a * b;
   if(c%2 == 0) cout << "Even" << endl;
   if(!(c%2 == 0)) cout << "Odd" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

const ll MAX = 1e6+1000;
const ll MOD = 1e9 + 7;
vector<ll> fac(MAX);
vector<ll> finv(MAX);
vector<ll> inv(MAX);

ll fastpow(ll a, ll n){  // a^n mod MOD
  if(n==0) return 1;
  if(n%2==0){
    ll t = fastpow(a, n/2) % MOD;
    return t*t % MOD;
  }
  return a * fastpow(a, n-1) % MOD;
}

void COMinit(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(ll i = 2; i < MAX; i++){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}

ll nCr(ll n, ll r){
  if(n < r) return 0;
  if(n < 0 || r < 0) return 0;
  return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N; cin >> N;
  if(N == 1){
    cout << 0 << endl;
    return 0;
  }
  COMinit();
  ll ans = fastpow(10, N);
  ll tmp = fastpow(9, N);
  ans -= tmp;
  if(ans < 0) ans += MOD;
  ans -= tmp;
  if(ans < 0) ans += MOD;
  ans += fastpow(8, N);
  ans %= MOD;
  cout << ans << endl;
}

Measured memory_bytes: 26604
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

//↑template↑



int main() {

	int n;
	cin >> n;
	vector<string>v(n);
	bool ok = 1;
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		if (i != 0) {
			if (v[i][0] != v[i - 1][v[i - 1].length() - 1]) { ok = 0; }
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (i != j && v[i] == v[j]) { ok = 0; }
		}
	}

	if (ok) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }


}

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

#define endl '\n'
using namespace std;
using ll = long long;

const int N = 1003;
const int M = 20004;

struct Block
{
    ll w, s, v;
    bool operator < (const Block &that)
    {
        return this->w + this->s < that.w + that.s;
//        return this->w <= that.s && this->s < that.w;
    }
};

int n;
Block arr[N];
ll dp[N][M];

void init();
void process();

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> arr[i].w >> arr[i].s >> arr[i].v;
    sort(arr+1, arr+1+n);
}

void process()
{
    for(int i = 1; i <= n; i++)
    {
        /*
        for(int j = 0; j < M; j++)
        {
            dp[i][j] = dp[i-1][j];
            if(j-arr[i].w >= 0 && arr[i].s >= j-arr[i].w) 
                dp[i][j] = max(dp[i][j], dp[i-1][j-arr[i].w]+arr[i].v);
        }
        */
        for(int j = 0; j < M; j++)
        {
            dp[i][j] = max(dp[i][j], dp[i-1][j]);
            if(j <= arr[i].s && j+arr[i].w < M) 
                dp[i][j+arr[i].w] = max(dp[i][j+arr[i].w], dp[i-1][j]+arr[i].v);
        }
    }
    ll ans = 0;
    for(int i = 0; i < M; i++) ans = max(ans, dp[n][i]);
    cout << ans << endl;
}



Measured memory_bytes: 156544
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define CLR2d(x,m,n) memset(x, -1, sizeof(x[0][0]) * m * n)
#define mp make_pair
#define PII pair<int, int>
#define pf printf
#define sf scanf
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >


int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
ll po(ll b,ll p){
    ll res=1;
    while(p){
        res*=b;
        p--;
    }
    return res;
}
ll lg2(ll x){
    ll res=0;
    while(x>1){
        res++;
        x/=2ll;
    }
    return res;
}
void solve(){
    int n,m;
    cin>>n>>m;
    m*=2;
    cout<<max(0,n-m)<<endl;
}

signed main()

{
    IOS;
    /*#ifndef ONLINE_JUDGE
        freopen ("input.txt","r",stdin);
        freopen ("output.txt","w",stdout);
    #endif*/
    int t;
    t=1;
    while(t--){
        solve();
    }

     return 0;

}
///Alhamdulillah




Measured memory_bytes: 3568
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    A=list(map(int,input().split()))
    z=len(bin(max(A)))-2
    l=[0]*z
    for x in A:
        for i in range(z):
            if (x >> i) & 0b1 == 1:
                l[i]+=1
    ans=0
    for i in range(z):
        ans+=l[i]*(N-l[i])*(2**i)
        ans%=MOD
    print(ans)
    
                    
if __name__ == '__main__':
    main()


Measured memory_bytes: 124824
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;


public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskT solver = new TaskT();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskT {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            
        	int K = in.nextInt();
          

            int prev = 7;
            int steps = 0, rem = 0;
            while (steps < 1e7) {
                ++steps;
                rem += prev;
                if (rem % K == 0 || rem == 0) break;
                prev = (prev * 10) % K;
                rem %= K;
            }
        	
        	System.out.println((steps < 1e7) ? steps : -1); 
        	/*
        	int N = in.nextInt();
        	int Q = in.nextInt();
        	int[] balls = new int[N];
        	for(int i = 0 ; i < N ; i ++){
        		balls[i] = in.nextInt();
        	}
        	//how many unique balls at any point to left 
        	Set<Integer> set = new HashSet<>();
        	int[] dp = new int[N];
        	
        	for(int i = 1; i <= N ; i++){
        		set.add(balls[i-1]);
        		dp[i-1] = set.size();
        	}
        	
        	for(int i = 0; i < Q; i++){
        		
        		int left = in.nextInt()-1; //index
        		int right = in.nextInt()-1;
        		
        		System.out.println(dp[right] - dp[left]+1);
        	}*/
        }
        

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        
        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 32980
#include<bits/stdc++.h>
#define rep(i, x, n) for(int i = x; i < n; i++)
#define repr(i, x, n) for(int i = x; i > n; i--)
#define pii pair<int,int>
#define ll long long
const long long iinf = 1e18;
const int inf = 1e9;
const int MOD = (1e6+3);
int dir4[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int knight[8][2] = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{-1,2},{1,-2},{-1,-2}};

using namespace std;

void solve()
{
    int n; cin >> n;
    cout << n + n*n + n*n*n;
}
//new line is printed in the main

int main()
{
    int t = 1;
        // cin >> t; // comment out if no test case is required
    // int i = 1;
    while(t--){
        //cout << "Case " << i++ << ": ";
        solve();
        // printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3620
th, tMon, ah, aMon  = map(int, input().split())
turn = 1
#1 represent takashi monster turn
#0 represent aoki monster turn
while(1):
  if(turn):
    ah-=tMon
    if(ah<=0):
      print("Yes")
      break
  else:
    th-=aMon
    if(th<=0):
      print("No")
      break
  turn^=1

Measured memory_bytes: 9184
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  int64_t four = 0;
  int64_t two = 0;
  int64_t other = 0;
  for (int64_t i = 0; i < N; ++i) {
    cin >> A[i];
    if (A[i] % 4 == 0) {
      ++four;
    } else if (A[i] % 2 == 0) {
      ++two;
    } else {
      ++other;
    }
  }
  bool is_okay = true;
  if (other > four) {
    if (two == 0 && other == four + 1) {
      is_okay = true;
    } else {
      is_okay = false;
    }
  }
  if (is_okay) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
N,M,C = map(int,input().rstrip().split())
B = list(map(int,input().rstrip().split()))
count = 0
sum = 0
for i in range(N):
    A = list(map(int,input().rstrip().split()))
    for k in range(M):
        sum = sum + A[k] * B[k]
    if sum + C > 0 :
        count = count + 1
    sum = 0
print(count)

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

using namespace std;
using ll = long long;
using ld = long double;

#define int ll
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
#define pb push_back
#define sz(x) int(x.size())

int MOD = 1;

const int N = 5002;
int n;
int c[N];
int dp[N][N];

signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> MOD;
	int h = (n - 1) / 2;
	for (int i = 0; i < h; ++i) {
		int l = i + 1;
		int r = n - i - 1;
		for (int j = l + 1; j <= r; ++j) {
			c[j] += 1;
		}
	}
	for (int j = 1; j < n; ++j) {
		++c[j];
	}

	//for (int i = 0; i < n; ++i) {
	//	cerr << c[i] << " ";
	//}
	//cerr << endl;

	dp[1][0] = 1;
	for (int i = 1; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			dp[i][j] %= MOD;
			for (int k = 0; j + c[i] * k < n; ++k) {
				dp[i + 1][j + c[i] * k] += dp[i][j];
			}
		}
	}
	
	int answer = 0;
	for (int j = 0; j < n; ++j) {
		dp[n][j] %= MOD;
		answer += (n - j) * dp[n][j];
		answer %= MOD;
	}
	cout << answer << "\n";
	return 0;
}


Measured memory_bytes: 195712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  ll ans = 0;
  REP(i, n) {
    cin >> a[i];
    ans += 2 * min(a[i], k - a[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define vl vector<ll> 
#define loop(i,a,b) for(ll i=a; i<b; i++)
using namespace std;
#define MAXN 1000001
#define MOD 1000000007
void solve(){
    string s,t;cin>>s>>t;
    ll sl=s.length();
    ll tl=t.length();
    ll flag=0;
    loop(i,0,sl){
        if(s[i]!=t[i]){
            flag=1;
            break;
        }
    }
    if((sl+1)==tl && flag==0) cout<<"Yes\n";
    else cout<<"No\n";
}
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
}

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

using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        for(int q=0; q < n; q++){
            int t[2][4];
            int a[4][4];
            int ret[4];
            for(int i=0; i < 2; i++) for(int j=0; j < 4; j++) cin >> t[i][j];
            for(int i=0; i < 4; i++) for(int j=0; j < 4; j++) a[i][j] = t[0][i] * t[1][j];
            ret[0] = a[0][0] + a[1][1]*-1 + a[2][2]*-1 + a[3][3]*-1;
            ret[1] = a[0][1] + a[1][0] + a[2][3] + a[3][2]*-1;
            ret[2] = a[0][2] + a[1][3]*-1 + a[2][0] + a[3][1];
            ret[3] = a[0][3] + a[1][2] + a[2][1]*-1 + a[3][0];
            for(int i=0; i < 4; i++) cout << (i==0?"":" ") << ret[i];
            cout << endl;
        }
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb emplace_back
typedef pair<int,int> pi;

int n;
double a[3005], dp[3005][3005], ans; // pbility of j heads after i tosses

int main() {
	ios_base::sync_with_stdio(0); 
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i];
	dp[0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= n; ++j) {
			if (j == 0) dp[i][j] = dp[i-1][j] * (1 - a[i-1]);
			else dp[i][j] = dp[i-1][j] * (1 - a[i-1]) + dp[i-1][j-1] * a[i-1];
		}
	}
	for (int i = n / 2 + 1; i <= n; ++i) {
		ans += dp[n][i];
	}
	cout << setprecision(9) << ans;
	return 0;
}


Measured memory_bytes: 74168
L = input()
N = len(L)
MOD = 10**9+7
dp = [[0]*2 for _ in range(101010)]
dp[0][0] = 1
for i in range(N):
    dp[i+1][1] += 3*dp[i][1]
    dp[i + 1][1] %= MOD
    if L[i] == '1':
        dp[i+1][0] += 2*dp[i][0]  # (a,b) = (0,1),(1,0)
        dp[i + 1][0] %= MOD
        dp[i+1][1] += dp[i][0]  # (a,b) = (0,0)
        dp[i + 1][1] %= MOD
    else:
        dp[i+1][0] += dp[i][0]  # (a,b) = (0,0)
        dp[i + 1][0] %= MOD
ans = (dp[N][0] + dp[N][1])%MOD
print(ans)

Measured memory_bytes: 54236
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

    vector<vll> s(20, vll(20, 0));
    vector<pair<int, int>> a;
    REP(i, n) {
        long double a_in;
        cin >> a_in;
        ll aa = (a_in + 1e-10) * 1e9;

        int c2 = 0;
        while(aa % 2 == 0) {
            c2++;
            aa /= 2;
        }

        int c5 = 0;
        while(aa % 5 == 0) {
            c5++;
            aa /= 5;
        }

        c2 = min(18, c2);
        c5 = min(18, c5);
        s[c2][c5] += 1;

        a.eb(c2, c5);
    }

    REP(i, 19) REP(j, 19) {
        s[i + 1][j] += s[i][j];
        s[i][j + 1] += s[i][j];
        s[i + 1][j + 1] -= s[i][j];
    }

    ll ans = 0;
    REP(i, n) {
        int c2 = a[i].fi, c5 = a[i].se;


        ll tmp = 0;
        tmp += s[18][18];
        if (c2 < 18) tmp -= s[18 - c2 - 1][18];
        if (c5 < 18) tmp -= s[18][18 - c5 - 1];
        if (c2 < 18 && c5 < 18) tmp += s[18 - c2 - 1][18 - c5 - 1];

        if (2 * c2 >= 18 && 2 * c5 >= 18) tmp--;

        ans += tmp;
    }

    print(ans / 2);

}


Measured memory_bytes: 5388
#include <iostream>
#include <set>
#include <map>
#include <queue>
using namespace std;
using llong = long long;

int n;
int a[100005];
int b[100005];
map<llong, llong> mp;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		mp[a[i] + b[i]]++;
	}
	
	llong x = -100;
	while (mp.upper_bound(x) != mp.end()) {
		x = mp.upper_bound(x)->first;
		
		if (mp[x] >= 2) {
			mp[x + 1] += mp[x] / 2;
			mp[x] %= 2;
		}
		
		if (mp[x] == 0) {
			mp.erase(x);
		}
	}
	
	for (auto p:mp) {
		cout << p.first << ' ' << 0 << endl;
	}
	
	return 0;
}


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

using namespace std;


typedef long long ll;
const int N=1e5+10;
int n;
ll tot;
ll d[N],w[N],benef[N];
void prepare(){
        cin>>n>>tot;
        for(int i=1;i<=n;i++) cin>>d[i]>>w[i];
}

ll solve(){
        ll ans=0;
        ///1->i
        for(int pha=0;pha<=1;pha++){
                ll sum=0;
                for(int i=1;i<=n;i++) {
                        sum+=w[i];
                        benef[i]=max(sum-d[i],benef[i-1]);
                }
                ans=max(ans,benef[n]);
                sum=0;
                for(int i=n;i>=1;i--){
                        sum+=w[i];
                        ans=max(ans,sum-(tot-d[i]));
                        ans=max(ans,sum-2*(tot-d[i])+benef[i-1]);
                        
                }
                for(int i=1;i<=n;i++) d[i]=tot-d[i];
                reverse(d+1,d+n+1);
                reverse(w+1,w+n+1);
              
        }
        return ans;
}
int main(){
        prepare();
        cout<<solve();
}


Measured memory_bytes: 2688
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while ((line = br.readLine()) != null) {
			String[] arr = line.split(" ");
			int h = Integer.parseInt(arr[0]);
			int w = Integer.parseInt(arr[1]);
			if (h == 0 && w == 0)
				break;

			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (i == 0 || i == h -1 || j == 0 || j == w - 1)
						System.out.print("#");
					else
						System.out.print(".");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

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

int main(){
int a, b;
char op;

while(1){
cin >> a >> op >> b;
if ( op == '?' ) break;

if ( op == '+' ) cout << a + b << endl;
else if ( op == '-' ) cout << a - b << endl;
else if ( op == '*' ) cout << a * b << endl;
else if ( op == '/' ) cout << a / b << endl;
}

return 0;
}


Measured memory_bytes: 3092
import sys

K, N = map(int, input().split())
A = list(map(int, sys.stdin.readline().split()))

max_diff = A[1] - A[0]

for i in range(N - 1):
    diff = A[i + 1] - A[i]
    if diff > max_diff:
        max_diff = diff

diff = A[0] + (K - A[N - 1])
if diff > max_diff:
    max_diff = diff

ans = K - max_diff

print(ans)

Measured memory_bytes: 25880
V, E = map(int, input().split())

#distance_list[j][i] = 頂点j→iの距離（有向）
distance_list = [[float('inf') for i in range(V)] for j in range(V)]
for i in range(V):
    distance_list[i][i] = 0
for node in range(E):
    start, goal, distance = map(int, input().split())
    distance_list[start][goal] = distance

dp = [[-1 for v in range(V)] for S in range(1 << V)]
def TSP(S, v):
    if dp[S][v] >= 0:
        return dp[S][v]
    else:
        if S == (1 << V) - 1 and v == 0:
            dp[S][v] = 0
            return 0
        else:
            ans = float('inf')
            for u in range(V):
                if (S >> u) & 1 == 0:
                    ans = min(ans, TSP(S | (1 << u), u) + distance_list[v][u])
            dp[S][v] = ans
            return ans
if TSP(0,0) == float('inf'):
    print(-1)
else:
    print(TSP(0,0))



Measured memory_bytes: 19044
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    ll int n,m,s=0,i;
     priority_queue<ll int>q;
     cin>>n>>m;
     for( i=1;i<=n;i++)
     {
       cin>>s;
       q.push(s);
     }
    for(i=m;m>0;m--)
     {
       s=q.top();
       q.pop();
       s/=2;
       q.push(s);
     }
     s=0;
     while(!q.empty())
     {
       s+=q.top();
       q.pop();
     }
     cout<<s<<endl;



}


Measured memory_bytes: 1400
# coding = SJIS
k, s = map(int, input().split())
if s < k:
    ans = (s + 1) * (s + 2) / 2
elif s <= 2 * k:
    t = 2 * k - s
    ans = ((k + 1) * (k + 2) / 2) - ((2 * k - s) * ((2 * k - s) + 1) / 2) + (t * (2 * k - ((2 * k - s) - 1)) / 2)
elif s <= 3 * k:
    ans = (3 * k - s + 1) * ((3 * k - s + 1) + 1) / 2
print(int(ans))

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

int main() {
  ll n; cin >> n;
  vector <ll> v(4, 0);
  rep(i, n) {
    string s; cin >> s;
    if (s.at(0) == 'A') v.at(0)++;
    else if (s.at(0) == 'W') v.at(1)++;
    else if (s.at(0) == 'T') v.at(2)++;
    else v.at(3)++;
  }
  cout << "AC x " << v.at(0) << endl;
  cout << "WA x " << v.at(1) << endl;
  cout << "TLE x " << v.at(2) << endl;
  cout << "RE x " << v.at(3) << endl;
}

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

int main() {
  string s;
  int pos;
  cin >> s >> pos;
  vector<string> subs;

  for (int k = 0; k < (int)s.size(); k++) {
    for (int l = 0; l < 5; l++) {
      subs.push_back(s.substr(k, l+1));
    }
  }
  sort(subs.begin(), subs.end());
  unique(subs.begin(), subs.end());
  cout << subs[pos-1] << endl;
}

Measured memory_bytes: 1660
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <bitset>
#include <iterator>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <random>
#include <numeric>
#include <set>
#include <cassert>
#include <cmath>
#include <cinttypes>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}
template<class T> T read_val() { throw 1; }
template<> int read_val() { int tmp; scanf("%" PRId32, &tmp); return tmp; }
template<> long long read_val() { long long tmp; scanf("%" PRId64, &tmp); return tmp; }
auto read_int = read_val<int>; auto read_long = read_val<long long>;
template<class T> void scanf_vec(vector<T>& vec) { for (int i = 0; i < vec.size(); i++) vec[i] = read_val<T>(); }

#define MOD 1000000007
#define inf 2000000000
#define FWT_SIZE 2000000
#define pii pair<int,int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define sort_all(x) sort(all(x))
#define make_unique(x) (x).erase(unique(all(x)), (x).end())


long long a, b, c, d;

unordered_map<long long, long long> mm;

long long rec(long long n)
{
	if (n == 1)
		return d;
	if (mm.find(n) != mm.end())
	{
		return mm[n];
	}
	long long ans = 3LL * 1e18;
	if (n < ans / d) ans = n * d;
	
	if (n >= 3)
	{
		long long rem3 = n % 3;
		if (rem3 < (3 - rem3))
			ans = min(ans, d * rem3 + b + rec(n / 3LL));
		else
			ans = min(ans, (3 - rem3) * d + b + rec(n / 3LL + 1LL));
	}

	if (n>=5)
	{
		long long rem5 = n % 5;
		if (rem5 < (5 - rem5))
			ans = min(ans, d * rem5 + c + rec(n / 5LL));
		else
			ans = min(ans, d * (5 - rem5) + c + rec(n / 5LL + 1LL));
	}

	if (1)
	{
		if (n % 2 == 0)
			ans = min(ans, a + rec(n / 2LL));
		else
		{
				ans = min(ans, d + a + rec((n + 1) / 2LL));
				ans = min(ans, d + a + rec((n) / 2LL));

		}
	}
	mm[n] = ans;
	return ans;
}

int main() {

#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

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

	int t;
	cin >> t;
	while (t-- > 0)
	{
		long long n;
		mm.clear();
		mm.reserve(1024);
		mm.max_load_factor(0.25);
		cin >>n>> a >> b >> c >> d;
		cout << rec(n) << "\n";
	}

	return 0;
}

Measured memory_bytes: 5000
import java.util.*;

//update 2019/12/13

public class Main{

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {

    long n = nextLong();
    long[] a = new long[5];
    for(int i=0;i<5;i++){
      a[i] = nextLong();
    }

    long min = minLong(a,5);

    long ans = 0;

    if(n<=min){
      ans = 5;
    }
    else{
      if(n%min==0){
        ans = n/min + 4;
      }
      else{
        ans = n/min + 5;
      }
    }

    System.out.println(ans);


  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char aaa){
    return aaa - 48;
  }

  public static int maxInt(int[] a,int lng){
    int max=a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }

  public static int minInt(int[] a,int lng){
    int min=a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }

  public static long maxLong(long[] a,int lng){
    long max=a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }

  public static long minLong(long[] a,int lng){
    long min=a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }

  public static long minmin(long a,long b){
    long ans = 0;
    if(a>=b){
      ans = b;
    }
    else{
      ans = a;
    }
    return ans;
  }

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;

void solve() {
	ll x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	ll times = (x + d - 1) / d;
	if (times <= k) {
		
		k -= times;
		if (x%d == 0) {
			if (k & 1)cout << d;
			else cout << 0;
			return;
		}
		if (k & 1) {
			cout << x%d;
		}
		else {
			cout << d - x%d;
		}
	}
	else {
		cout << x - k*d;
	}
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}



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

#define ll long long
#define pb push_back
#define mp make_pair


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

	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r+", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w+", stdout);
	// #endif

    string a,b;
    cin >> a >> b;
    int n = a.length();
    int m = b.length();

    ll dp[n+1][m+1];

    for(int i=0;i<=n;i++) {
    	dp[i][0] = 0;
    }
    for(int i=0;i<=m;i++) {
    	dp[0][i] = 0;
    }
    for(int i=1;i<=n;i++) {
    	for(int j=1;j<=m;j++) {
    		if(a[i-1] == b[j-1]) {
    			dp[i][j] = dp[i-1][j-1] + 1;
    		}
    		else {
    			dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
    		}
    	}
    }

    // for(int i=0;i<=n;i++) {
    // 	for(int j=0;j<=m;j++) {
    // 		cout << dp[i][j] << " ";
    // 	}
    // 	cout << '\n';
    // }

    // cout << dp[n][m] << '\n';

    string c = "";
    while(n > 0 and m > 0) {
    	// cout << n << " " << m << '\n';
    	if(a[n-1] == b[m-1]) {
    		c = a[n-1] + c;
    		m--;
    		n--;
    		// continue;
    	}
    	else if(dp[n-1][m] > dp[n][m-1]) {
    		n--;
    		// continue;
    	}
    	else {
    		m--;
    		// continue;
    	}
    }
    cout << c;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define mod 1000000007
#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a;i<b;i++)
#define maxx 100005
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main() {
    FASTIO
    ll a,b,c,d,a1,a2,a3,a4;
    cin>>a>>b>>c>>d;
    a1=a*c;a2=a*d;
    a3=b*c;a4=b*d;
    cout<<max({a1,a2,a3,a4})<<endl;
    return 0;
}


Measured memory_bytes: 3640
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
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")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn f(a: &mut usize, b: &mut usize, t1: usize, t2: usize) {
    let r1 = (t1 - *a % t1) % t1;
    let r2 = (t2 - *b % t2) % t2;
    let bn = (*a + r1) / t1 * t2;
    let an = (*b + r2) / t2 * t1;
    if bn < *b {
        *a = an;
        *b += r2;
    } else if an < *a {
        *b = bn;
        *a += r1;
    } else {
        let c1 = bn - *b + r1;
        let c2 = an - *a + r2;
        if c1 < c2 {
            *b = bn;
            *a += r1;
        } else {
            *a = an;
            *b += r2;
        }
    }
}

fn main() {
    input! {
        n: usize,
        ta: [(usize, usize); n],
    }

    let mut a = 1;
    let mut b = 1;

    for i in 0..n {
        f(&mut a, &mut b, ta[i].0, ta[i].1);
    }

    println!("{}", a + b);
}


Measured memory_bytes: 4352