akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int p[10];
    int N;
    cin >> N;
    int mx=0;
    int ans=0;
    for (int i=0;i<N;i++){
        cin >> p[i];
        if (mx<p[i]){
            mx=p[i];
        }
        ans+=p[i];
    }
    cout << ans-(mx/2) << endl;
    return 0;
}


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

using namespace std;

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

    int a[20];
    unsigned int x[20][20];
    unsigned int y[20][20];

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        for (int j = 0; j < a[i]; ++j) {
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }

    int ans = 0;
    for (unsigned int bits = 1; bits < (1U << n); ++bits) {
        bool isOK = true;
        for (unsigned int i = 0; i < n; ++i) {
            //bitsにおいてi人目が嘘つきならなにもしない
            if ((bits & 1U << i) == 0) continue;
            //i人目の発言をチェック
            for (int j = 0; j < a[i]; j++) {
                //発言の矛盾をチェック
                if ((bits >> x[i][j] & 1U) != y[i][j]) {
                    isOK = false;
                }
            }
        }
        if (isOK) {
            ans = max(ans, __builtin_popcount(bits));
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
int main(){
    int n;cin>>n;
    int m=sqrt(n);
    ll ans;
    REP(i,m+1){
        if(i*i>n){
            ans=(i-1)*(i-1);
            //printf("ans=%d\n",ans);
            break;
        }
    }
    cout<<ans<<endl;
}


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

string plus_string(string a, string b){
	string c;
	reverse( a.begin() , a.end() );
	reverse( b.begin() , b.end() );
	while( a.size() != b.size() ){
		if( a.size() < b.size() ){
			a.push_back('0');
		}else{
			b.push_back('0');
		}
	}
	for(int i=0 ; i < a.size() ; i++ ){
		c.push_back('0');
	}
	int n=0;
	for(int i=0 ; i < a.size() ; i++ ){
		if( n+a[i]+b[i]-'0'-'0' <= 9 ){
			c[i] = a[i] + b[i] - '0' + n;
			n = 0;
		}else{
			c[i] = a[i] + b[i] - '0' - 10 + n;
			n = 1;
		}
	}
	if( n == 1 ){
		c.push_back( '1' );
	}
	reverse( c.begin() , c.end() );
	return c;
}

string change_X(string s, char c){
	for(int i=0 ; i < s.size() ; i++ ){
		if( s[i] == 'X' ){
			s[i] = c;
		}
	}
	return s;
}

void solve(string s){
	string num1, num2, num3, a, b, c;
	int plus, equal;
	for(int i=0 ; i < s.size() ; i++ ){
		if( s[i] == '+' )
			plus = i;
		if( s[i] == '=' )
			equal = i;
	}
	num1 = s.substr( 0 , plus );
	num2 = s.substr( plus+1 , equal-plus-1 );
	num3 = s.substr( equal+1 );
	for(int i=0 ; i <= 9 ; i++ ){
		a = change_X( num1 , i+'0' );
		b = change_X( num2 , i+'0' );
		c = change_X( num3 , i+'0' );
		if( plus_string( a , b ) == c ){
			cout << i << endl;
			return;
		}
	}
	cout << "NA" << endl;
}

int main(){
	string s;
	while( cin >> s ){
		solve( s );
	}
}


Measured memory_bytes: 1200
#include<iostream>
#include<vector>
#include<queue>
#include<utility>
#include<algorithm>
#include<string>
using namespace std;
#define mkp make_pair
#define veb vector<bool>
#define vel vector<long long>
#define vvel vector<vel>
#define vvvel vector<vvel>
#define pin pair<long long,long long>
int main() {
	int  a, b;
	cin >> a >> b;
	if (b%a == 0) { cout << a + b << endl; }
	else { cout << b - a << endl; }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
using Graph = vector<vector<int>>;

int main(){
	string s;
	cin >> s;
	if(s == "Sunny") cout << "Cloudy" << endl;
	if(s == "Cloudy") cout << "Rainy" << endl;
	if(s == "Rainy") cout << "Sunny" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

vector<int> to[100009];
vector<int> a;
bool ok = true;

ll dfs(int v, int p=-1) {
  if (p != -1 && to[v].size() == 1) return a[v];
  ll sum = 0, mx = 0;
  for (auto u : to[v]) {
    if (u == p) continue;
    ll tmp = dfs(u, v);
    sum += tmp;
    chmax(mx, tmp);
  }
  if (sum > a[v] * 2 || a[v] > sum || mx > a[v]) ok = false;
  return a[v] * 2 - sum;
}

int main() {
  int n;
  cin >> n;
  a.resize(n);
  rep(i,n) cin >> a[i];
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ll rec = dfs(0);
  if (to[0].size() == 1 && rec == a[0] && ok || to[0].size() != 1 && rec == 0 && ok) puts("YES");
  else puts("NO");
  return(0);
}

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

int main(){
    fastio;
    int n;
    cin >> n;
    vector<int> a(n+1);
    unordered_map<ll,ll> mp;
    for(int i=1; i <= n; ++i){
        cin >> a[i];
        ++mp[i+a[i]];
    }
    ll res=0;
    for(int i = 1; i <= n; ++i){
        res += mp[i-a[i]];
    }
    cout << res << "\n";
    #ifdef TIMER_
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}

Measured memory_bytes: 19200
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	Int N, a, b;
	cin >> N >> a >> b;

	Int ans = N / (a + b) * a;
	N %= (a + b);
	if (N >= a) { ans += a; }
	else { ans += N; }
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>

#define rep(i,n) for(int (i)=0;(i)<(n); ++(i))
using namespace std;

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

    long long ans = 1;

    long long a;
    long long ch = pow(10, 18);

    bool f = false;

    rep(i, n) {
        cin >> a;
        if(a == 0) {
            cout << "0" << endl;
            return 0;
        }
        if(ch/a < ans) {
            f = true;
        }
        ans *= a;
    }

    if(f) cout << "-1" << endl;

    else cout << ans << endl;

    return 0;
}

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

int main(){
    string N;
    cin >> N;
    if(N[0]=='7'||N[1]=='7'||N[2]=='7'){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
package main

import "fmt"

func pow5(x int) int64 {
	res := int64(1)
	for i := 0; i < 5; i++ {
		res *= int64(x)
	}
	return res
}

func main() {
	var x int64
	fmt.Scan(&x)
	for a := 0; a <= 500; a++ {
		for b := -500; b <= 500; b++ {
			if pow5(a)-pow5(b) == x {
				fmt.Println(a, b)
				return
			}
		}
	}
}


Measured memory_bytes: 1768
using System;

namespace EasyLinear
{
    class Program
    {
        static int K = 0;
        static void Main(string[] args)
        {
            int[] ary = {1,0,-1} ;
            var input = Console.ReadLine().Split(" ");
            K = int.Parse(input[3]);
            int result = 0 ;
            for (int i = 0; i < 3 || K > 0; i++)
            {
                var a = int.Parse(input[i]);
                if (a>K)
                {
                    result += K * ary[i];
                    break;
                }
                K -= a;
                result += a * ary[i];
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 27404
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] input = new int[n];

        for(int i=0;i<n;i++){
            input[i] = sc.nextInt();
        }

        int[] dp = new int[n];

        dp[0] = 0;

        for(int i=1;i<n;i++){
            if(i==1){
                dp[i] = Math.abs(input[i] - input[i-1]);
            }else{
               int a =  dp[i-1] + Math.abs(input[i] - input[i-1]);
               int b =  dp[i-2] + Math.abs(input[i] - input[i-2]);
               if(a>b){
                   dp[i] = b;
               }else{
                   dp[i] = a;
               }
            }
        }

//        for (int i=0;i<n;i++){
//            System.out.println(dp[i]);
//        }

        System.out.println(dp[n-1]);

    }
}


Measured memory_bytes: 49736
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <cmath>

using namespace std;

#define FAST_IO() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define USE_DB() cout << fixed; cout.precision(10);

#define pqu priority_queue
#define que queue
#define stk stack
#define vec vector

typedef long long ll;
typedef double db;
typedef string str;

#define IN(x) cin >> x
#define INI(x) int x; cin >> x
#define INL(x) ll x; cin >> x
#define INS(x) str x; cin >> x

#define FI first
#define SE second
#define PB push_back
#define SZ(x) x.size()
#define ALL(x) x.begin(), x.end()

#define FORN(i, s, e) for (int i = s; i < e; i++)
#define FORR(i, s, e) for (int i = s; i >= e; i--)
#define FORD(i, s, e, d) for (int i = s; i < e; i += d)
#define FORS(i, n) for (int i = 1; i*i <= n; i++)

vec<int> c[9];
int v[9];

void dfs(int here) {
	v[here] = 1;
	for(auto there : c[here]) {
		if (v[there]) continue;
		dfs(there);
		break;
	}
}

int main() {
	FAST_IO();

	FORN(i, 0, 3) {
		INI(a); INI(b);
		c[a].PB(b); c[b].PB(a);
	}
	/*
	FORN(i, 1, 5) {
		for(auto child : c[i]) {
			cout << child << ' ';
		}
		cout << '\n';
	}
	*/
	int r = 0;
	FORN(i, 1, 5) {
		if (SZ(c[i]) == 1)
			r = i;
	}
	//cout << r << '\n';
	dfs(r);
	FORN(i, 1, 5) {
		if (!v[i]) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	
	return 0;	
}


Measured memory_bytes: 256
#include<bits/extc++.h>
#ifndef __unix__
#define readchar _getchar_nolock
#define fread_unlocked _fread_nolock
#else
#define readchar getchar_unlocked
#endif
#ifdef _debug 
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#include<bits/stdc++.h>
#define dout(i) 0&&0
#endif
#pragma GCC optimize("unroll-loops,no-stack-protector,O3")
#define priority_queue __gnu_pbds::priority_queue
#define unordered_map __gnu_pbds::gp_hash_table
#define rep(_n) for(int __i = _n;__i--;)
#define rep0(_i, _n) for(int _i = 0; (_i)<(_n) ;++_i)
#define rep1(_i, _n) for(int _i = 1; (_i)<=(_n) ;++_i)
#define yn(i) ((i)?"Yes" : "No")
#define eout(i) {cout << (i) << '\n';exit(0);}
#define rout(i) {return cout << (i) << '\n', 0;}
#define multi int _T;for(read(_T);_T--;)
using namespace std;
using ll = long long;using ull = unsigned long long;using ul = unsigned;using db = double;
using __gnu_pbds::null_type;
// inline char readchar(){static const size_t bufsize = 1 << 16; static size_t p = 0, end = 0; static char buf[bufsize]; if (p == end) end = fread_unlocked(buf, sizeof(char), bufsize, stdin), p = 0; return p == end ? EOF : buf[p++]; }
inline void read(char &a){static char p; while(isspace(p = readchar())); a = p; }
inline void read(char *a){static char p; while(isspace(p = readchar())); *a = p, ++a; while(isgraph(p = readchar()))*a = p, ++a;}
inline void read(string &a){static char p; while(isspace(p = readchar())); a = p; while(isgraph(p = readchar()))a.push_back(p);}
template<typename T> inline void read(T& a){static char p; static bool b;while (!isdigit(p = readchar()))b = p == '-'; a = p ^ '0'; while (isdigit(p = readchar())) a *= 10, a += p ^ '0'; if(b)a *= -1; }
template<typename T1, typename T2> inline void read(pair<T1, T2> &a){read(a.first), read(a.second);}
template<typename T> inline void read(T begin, const T &end){while(begin != end)read(*begin), ++begin;}
inline void R(){} template<class T1, class... T2> inline void R(T1 &h, T2 &... e){read(h), R(e...);}
template<typename T> inline void write(T begin, const T &end){while(begin != end)cout << *begin << " \n"[next(begin) == end], ++begin;}
template<typename T> using rbtree = __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T> inline ostream& operator << (ostream &ou, const vector<T> &a){for(auto it = a.begin();it != a.end();++it)ou << (it != a.begin() ? " " : "") << *it;return ou;}
template<typename T1, typename T2>inline istream& operator >> (istream &in, pair<T1, T2> &a){return in >> a.first >> a.second;}
template<typename T1, typename T2>inline ostream& operator << (ostream &ou, const pair<T1, T2> &b){return ou << b.first << ' ' << b.second;}
template<typename T> inline long long pow(long long v, long long t, const T &p){long long res = 1;for(;t;t >>= 1, v = v * v % p)if(t & 1)res = res * v % p;return res;}
const int maxn = 300010;
string in[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	string w;
	cin >> w;
	for(int i = 0;;++i)if(in[i] == w)rout(7 - i);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
const int N = 1e2 + 10;
const int mod = 1e9 + 7;



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

    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << ' ' << b << ' ' << c;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

int main(){
  int N;
  cin >> N;
  vector<string> s(N);
  vector<int> t(N);
  for (int i = 0; i < N; i++) cin >> s.at(i) >> t.at(i);
  string x;
  cin >> x;
  int j = 0;
  for (int i = 0; i < N; i++) {
	if (x.compare(s.at(i)) == 0) {
      j = i;
      break;
    }
  }
  ull sum = 0;
  j++;
  while (j < N) {
    sum += t.at(j);
    j++;
  }
  
  cout << sum;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define fast_io() ios::sync_with_stdio(false); cin.tie(nullptr)
#define fix(n) fixed << setprecision(n)

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;


int main(void){
    fast_io();
    
    ll a,b;
    cin >> a >> b;

    bool ans = (1 <= a && a <= 9) && (1 <= b && b <= 9);
    cout << (ans ? a * b : -1) << endl;
    return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,x[110],y[110],h[110];
signed main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>h[i];
	for(int i=0;i<101;i++){
		for(int j=0;j<101;j++){
			int cnt;
			for(int k=0;k<n;k++){
				if(h[k]){
					cnt=h[k]+abs(i-x[k])+abs(j-y[k]);
					break;
				}
			}
			for(int k=0;k<n;k++){
				if(h[k]!=max((long long)0,cnt-abs(i-x[k])-abs(j-y[k])))goto kaage;
			}
			cout<<i<<" "<<j<<" "<<cnt<<endl;
			kaage:;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;
//using Graph = vector<vector<int>>;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> P;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}
LL sum(LL a, LL b){
    LL cnt=0;
    cnt=(b-a+1)*(a+b)/2;
    return cnt;
}
/*LL yaku(int x){
    vector<pair<LL, LL> a=[];
    LL xh;
    if(x==1){
        pair<LL, LL> tmp;
        tmp=MP(1,1);
        return tmp;
    }
    else{
        FOR(i, 1, x/2+1){
            if(x%i==0){
                a.append(MP(i,x/i));
            }
        }
    }
    return a;

}*/
LL cul(int a, int b){
    LL f = pow(a,4)+pow(a,3)*b+pow(a,2)*pow(b,2)+a*pow(b,3)+pow(b,4);
    return f;
} 
int main(){
    int a, b;
    cin >> a >> b;
    if(a==b) cout << "a == b" << endl;
    else if(a < b) cout << "a < b" << endl;
    else cout << "a > b"  << endl;
}
    





Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	int i;
	foe(i, 1, 5) {
		int x;
		cin >> x;
		if(x != i) {
			cout << i;
			return 0;
		}
	}
}


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

int main()
{
  int D, N;
  int res=0;
  cin >> D >>N;

  int n;
  if(D==0) n=1;
  else if(D==1) n=100;
  else n=10000;

  if(N==100) res = n*(N+1);
  else res = n*N;

  cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int w, h;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
int map_[50][50];

int sink(int x, int y) {
    if (map_[x][y] == 0) {
        return 0;
    }
    map_[x][y] = 0;
    for (int i=0; i<8; i++) {
        int x_new = x+dx[i];
        int y_new = y+dy[i];
        if (0 <= x_new && x_new < w && 0 <= y_new && y_new < h) {
            sink(x_new, y_new);
        }
    }
    return 1;
}

int main() {
    while (true) {
        int count = 0;
        cin >> w >> h;
        if (w == 0) {
            break;
        }
        for (int i=0; i<h; i++) {
            for (int j=0; j<w; j++) {
                cin >> map_[j][i];
            }
        }
        for (int i=0; i<h; i++) {
            for (int j=0; j<w; j++) {
                count += sink(j, i);
            }
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
using namespace std;

ll n;
string s;

inline ll read(){
	ll s = 0, w = 1;
	char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) w *= ch == '-' ? -1 : 1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) s = s * 10 + ch - '0';
	return s * w;
}

inline void work(){
	n = read();
	cin >> s;
	if (s.size() <= n) cout << s << endl;
	else {
		REP(i, 0, n - 1) printf("%c",  s[i]);
		puts("...");
	}
}

int main(){
	work();
	return 0;
}

Measured memory_bytes: 3628
N = gets.chomp.to_i
str = gets.split
p = Array.new(0)
m = Array.new(0)
z = Array.new(0)
a = 0
b = 0
c = 0
sum = 0
for x in 0...N
  a = str[x].to_i
  if a > 0
    p.push(a)
    sum += a
  elsif a < 0
    m.push(a)
    sum -= a
  else
    z.push(a)
  end
end

if p.size == 0
  if m.size == 0
    puts 0
    for x in 1...N
      puts "0 0"
    end
    exit
  elsif m.size == 1
    c = m[0]*(-1)
    puts c
    for x in 1...N-1
      print m[0]," 0"
      puts
    end
    print "0 ",m[0]
    puts
    exit
  elsif z.size != 0
    puts sum
    b = z.pop
    c = m.pop
    print "0 ",c
    puts
    p.push(-c)
  else
    m.sort!
    b = m.pop
    m.reverse!
    c = m.pop
    sum += b*2
    puts sum
    print b," ",c
    puts
    p.push(b-c)
  end
elsif m.size == 0
  if p.size == 1
    puts p[0]
    for x in 1...N
      print p[0]," 0"
      puts
    end
    exit
  elsif z.size != 0
    puts sum
    b = z.pop
    c = p.pop
    print "0 ",c
    puts
    m.push(-c)
  else
    p.sort!
    c = p.pop
    p.reverse!
    b = p.pop
    sum -= b*2
    puts sum
    print b," ",c
    puts
    m.push(b-c)
  end
else
  puts sum
end

b = p.pop
c = m.pop
while p.size > 0
  print c," ",b
  puts
  c -= b
  b = p.pop
end

while m.size > 0
  print b," ",c
  puts
  b -= c
  c = m.pop
end

print b," ",c
puts
b -= c

for x in 1..z.size
  print b," 0"
  puts
end

Measured memory_bytes: 11828
# coding: utf-8
n = int(input())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

L = factorization(n)
#print(L)
ans = 0
#print(len(L))
for i in range(len(L)):
    b = L[i][1]
    s = 0
    for j in range(1,b+1):
        s += j
        if s == b:
            ans += j
            break
        elif s > b:
            ans += j-1
            break
    #print(b, s)
if n == 1:
    ans = 0
print(ans)
        

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

#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define endl '\n'
// #define int long long

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

string s;
int fir, last;
bool isMonth(int x){
	return x>=1 && x<=12;
}
int32_t main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	cin >> s;
	fir = 10*(s[0]-'0') + (s[1]-'0');
	last = 10*(s[2]-'0') + (s[3]-'0');
	if (!isMonth(fir) && !isMonth(last)) cout << "NA\n";
	else if (isMonth(fir) && isMonth(last)) cout << "AMBIGUOUS\n";
	else if (isMonth(fir)) cout << "MMYY\n";
	else cout << "YYMM\n";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn=2e5+10;
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
int n,p,f[maxn];
long long ans;
char s[maxn];

int main()
{
    #ifdef __LOCAL__
        freopen("1.in","r",stdin);
        freopen("1.out","w",stdout);
    #endif
    scanf("%d%d%s",&n,&p,s+1);
    if(p==2||p==5)
    {
        _rep(i,1,n)
            if((s[i]-'0')%p==0)
                ans+=i;
    }
    else
    {
        f[0]=1;
        int k=1,t=0;
        for(int i=n;i>=1;i--)
        {
            t=(t+(s[i]-'0')*k)%p;
            ans+=f[t];
            f[t]++;
            k=k*10%p;
        }
    }    
    cout<<ans<<endl;
    
    return 0;
}

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

int main(){
  int n,t[55];
  cin >> n;
  string s[55],x;
  rep(i,n) cin >> s[i] >> t[i];
  cin >> x;
  int ans = 0;
  for(int i = n-1; i >= 0; i--){
    if (s[i] == x) break;
    ans += t[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        
        PriorityQueue<Integer> que = new PriorityQueue<Integer>();
        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            que.add(num);
        }
        
        int[][] array = new int[m][2];
        for (int i = 0; i < m; i++) {
            array[i][0] = sc.nextInt();
            array[i][1] = sc.nextInt();
        }
        Arrays.sort(array, (a, b) -> Integer.compare(b[1], a[1]));
        
        for (int i = 0; i < m; i++) {
            int count = array[i][0];
            int val = array[i][1];
            
            boolean ok = true;
            for (int j = 0; j < count; j++) {
                int min = que.peek();
                
                if (min < val) {
                    que.poll();
                    que.add(val);
                } else {
                    ok = false;
                    break;
                }
            }
            
            if (!ok) {
                break;
            }
        }
        
        long ans = 0;
        while (!que.isEmpty()) {
            ans += que.poll();
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 66712
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


int main() {
	int64_t l, r;
	cin >> l >> r;

	if (r-l>10000) {
		cout << 0 << endl;
		return 0;
	}

	int res = 2019;
	for (int64_t i=l; i<r; i++) {
		for (int64_t j=i+1; j<=r; j++) {
			if (i*j%2019 < res) res = i*j%2019;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
/*


*/
#include <set>
#include <cstdio>
#include <cctype>
#include <algorithm>
#define MAXIN 300000
#define gc() (SS==TT&&(TT=(SS=IN)+fread(IN,1,MAXIN,stdin),SS==TT)?EOF:*SS++)
typedef long long LL;
const int N=1e5+5;

int fa[N];
std::set<int> st[N];
std::pair<int,int> q[N];
char IN[MAXIN],*SS=IN,*TT=IN;

inline int read()
{
	int now=0;register char c=gc();
	for(;!isdigit(c);c=gc());
	for(;isdigit(c);now=now*10+c-'0',c=gc());
	return now;
}
int Find(int x)
{
	return x==fa[x]?x:fa[x]=Find(fa[x]);
}

int main()
{
	const int n=read();
	int h=0,t=0;
	for(int i=n-1<<1; i; --i)
	{
		int u=read(),v=read();
		if(u>v) std::swap(u,v);
		if(!st[u].count(v)) st[u].insert(v), st[v].insert(u);
		else q[t++]=std::make_pair(u,v);
	}
	for(int i=1; i<=n; ++i) fa[i]=i;
	while(h<t)
	{
		int x=Find(q[h].first),y=Find(q[h++].second);
		if(st[x].size()<st[y].size()) std::swap(x,y);//x<-y
		for(std::set<int>::iterator it=st[y].begin(); it!=st[y].end(); ++it)
			if(*it!=x)
			{
				int u=x,v=*it;
				st[v].erase(y);
				if(u>v) std::swap(u,v);
				if(!st[u].count(v)) st[u].insert(v), st[v].insert(u);
				else q[t++]=std::make_pair(u,v);		
			}
		st[x].erase(y), fa[y]=x;
	}
	puts(t==n-1?"YES":"NO");

	return 0;
}

Measured memory_bytes: 27264
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

int main() {
    int h, w, k;
    cin >> h >> w >> k;

    vector<vector<int>> v(h, vector<int>(w, 0));
    char c;
    rep(i, h) {
        rep(j, w) {
            cin >> c;
            if (c == '#') v[i][j]++;
        }
    }

    // int d[1<<h][1<<w];
    int ans = 0;
    int temp=0;
    rep(i, 1<<h) {
        rep(j, 1<<w) {
            rep(s, h) {
                rep(t, w) {
                    if((i>>s)&1) if((j>>t)&1) if(v[s][t]==1) temp++;
                }
            }
            if (temp==k) ans++;
            temp = 0;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;

using namespace std;

int main(){
    string s;
    cin >> s;
    string ans;
    ans = s[0];
    ans += to_string(s.length()-2);
    ans += s[s.length()-1];
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
long int power(int a)
{
    long int m=1;
    for(int i=1; i<a; i++)
        m=m*10;
    return m;

}
int main()
{
    long long int a=0, b, digit=0, m;
    char c;
    string f;
    cin>>f;

    int lenn=f.length();
    for(int i=0; i<lenn; i++)
    {
        c = f.at(i);
        b = c-48;
        a+=b;
    }

    for(int i=0; i<lenn; i++)
    {
        m=lenn-i;
        b=(f.at(i)-48);

        digit+=b*power(m);
    }

    if(digit%a==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>

using namespace std;

string S;
int N;

int main(void)
{
	cin >> S;
	N = S.length();
	int offset = 0;
	int result = 0;
	while(offset < N)
	{
		if(S[offset] == 'O')
		{
			int of = offset;
			int c_O = 0;
			while(S[of] == 'O')
			{
				of++;
				c_O++;
			}
			bool OK = true;
			for(int i = offset - 1;i >= offset - c_O;i--)
			{
				if(i >= 0)
				{
					if(S[i] != 'J')
					{
						OK = false;
						break;
					}
				}
				else
				{
					OK = false;
					break;
				}
			}
			for(int i = of;i < of + c_O;i++)
			{
				if(i < N)
				{
					if(S[i] != 'I')
					{
						OK = false;
						break;
					}
				}
				else
				{
					OK = false;
					break;
				}
			}
			if(OK)
			{
				result = max(result,c_O);
			}
			offset = of;
		}
		else
			offset++;
	}
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 3968
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

bool check(LL x, LL lim) {
  LL x1 = (x + 1LL) / 2LL;
  LL x2 = x + 1LL - x1;
//  cout << x << ":" << x1 << ", " << x2 << " = " << x1 * x2 << "v.s." << lim << "->" << (x1 * x2 < lim) << endl;
  if (x1 * x2 <= lim) return true;
  else               return false;
}

LL solve(LL a, LL b) {
  if (a == b) return 2 * a - 1;

  LL ok = 1, ng = 1e10;
  while (abs(ok-ng) > 1) {
    LL mid = (ok + ng) / 2LL;
//    cout << ok << "  -   " << ng << ", mid: " << mid << endl;
    if (check(mid, a*b-1LL)) ok = mid;
    else                     ng = mid;
  }
  return ok;
}

int main() {
  int Q; cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int a, b; cin >> a >> b;
    cout << solve(a, b) - 1 << endl;
  }
}


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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int mod = 1e9+7;

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    while (cin >> n >> k) {
        VI A(n);
        FOR(i,0,n)
            cin >> A[i];
        LL cnt1 = 0;
        FOR(i,0,n) FOR(j,i+1,n) if (A[i] > A[j])
            cnt1++;
        LL cnt2 = 0;
        FOR(i,0,n) FOR(j,0,n) if (A[i] > A[j])
            cnt2++;
        const LL a = cnt1 * k % mod;
        const LL b = 1LL * k*(k-1)/2 % mod;
        const LL c = cnt2 * b % mod;
        const LL ans = (a + c) % mod;
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio() ios_base::sync_with_stdio(false);
#define rmod(x, y) ((((x)%(y))+(y))%(y))
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template<typename T, typename R = null_type, typename C = less<T>>
tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set(){
	return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>();
}

const ll inf = 1e17;
const int maxn = 17, maxm = (1<<16)+5;
bool vis[maxn][maxm];
int n;
ll a[maxn][maxn], val[maxm], dp[maxm];

ll solve(int mask){
	if (dp[mask] != -1) return dp[mask];
	ll ret = -inf;
	for(int i = mask; i>0; i=(i-1)&mask){
		ret = max(ret, val[i]+solve(mask^i));
	}
	return dp[mask] = ret;
}


int main(){
	memset(dp, -1, sizeof(dp));
	scanf("%d", &n);
	for(int i = 0; i<n; i++)
		for(int j = 0; j<n; j++) scanf("%lld", &a[i][j]);
	for(int i = 0; i<(1<<n); i++){
		if(__builtin_popcount(i) <= 1) val[i] = 0, dp[i] = 0;
		else for(int j = 0; j<n; j++) if ((i>>j)&1){
			for(int k = j+1; k<n; k++)
				if ((i>>k)&1) val[i]+=a[j][k];
		}
	}
	printf("%lld\n", solve((1<<n)-1));
	
	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>

using namespace std;
//max heap size
#define N 2000001

int heap_size=0;
int key[N];

//function parent
int parent(int i){
  return i/2;
}
//function left
int leftc(int i){
  return 2*i;
}
//function right
int rightc(int i){
  return 2*i+1;
}

//function maxHeapify
void maxHeapify(int i){
  int l,r,largest;
  int st;
 
  l=leftc(i);
  r=rightc(i);

  if(l<=heap_size && key[l]>key[i]) largest=l;
  else largest=i;
 
  if(r<=heap_size && key[r]>key[largest]) largest=r;
 
  if(largest!=i){
    st=key[i];
    key[i]=key[largest];
    key[largest]=st;
    maxHeapify(largest); 
  }
}

//function heap increase key
int heapIncreaseKey(int i,int data){
  int st;
  if(data<key[i]) return -1;
  key[i]=data;
  while(i>1 && key[parent(i)]<key[i]){
    st=key[i];
    key[i]=key[parent(i)];
    key[parent(i)]=st;
    i=parent(i);
  }
  return 0;
}

//function max heap insert
void maxHeapInsert(int data){
  heap_size++;
  key[heap_size]=-2047483648;
  heapIncreaseKey(heap_size,data);
}

//function extract
int heapExtractMax(void){
  int max;

  if(heap_size <1) return -1;
  max=key[1];
  key[1]=key[heap_size];
  heap_size--;
  maxHeapify(1);
  return max;
}

int main(){

  int data;
  char str[10];
  int st;

  while(1){
    //load string
    scanf("%s",str);
    //insert
    if(str[0]=='i'){
      scanf("%d",&data);
      maxHeapInsert(data);
    }
    //extract
    else if(strcmp("extract",str)==0){
      st=heapExtractMax();
      if(st!=-1) printf("%d\n",st);
    } 
    //end
    else break;
  }

  return 0;
}

Measured memory_bytes: 4800
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//几个不同

int main(){
  int x,y,z;
  
  cin >> x >> y >> z;
  if(x== y && y == z){
    cout << "1" << endl;
  }else if(x==y || y==z || x==z){
    cout << "2" << endl;
  }else{
    cout << "3" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef double ld;
const long long INF = (1LL << 62);
const double inf = pow(10, 10);
double pi = 3.141592653589793;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int ddx[8] = {1, 0, -1, -1, -1, 0, 1, 1};
const int ddy[8] = {1, 1, 1, 0, -1, -1, -1, 0};

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

  return gcd(a % b, b);
}

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

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

Measured memory_bytes: 1792
n,x=map(int,input().split())
if x==1 or x==2*n-1:
    print('No')
else:
    print('Yes')
    if x<=n-1:
        for i in range(2,x):
            print(i)
        for i in range(x+1,n+1):
            print(i)
        print(1);print(x);print(2*n-1)
        for i in range(n+1,2*n-1):
            print(i)
    else:
        for i in range(2,n):
            print(i)
        print(1);print(x);print(2*n-1)
        for i in range(n,x):
            print(i)
        for i in range(x+1,2*n-1):
            print(i)     

Measured memory_bytes: 49372
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int b[3]={0};
  int n,a;
  scanf("%d",&n);
  while(n--){
    scanf("%d",&a);
    b[a%3]++;
  }
  n=MIN(b[1],b[2]);
  a=n*2;
  a+=MIN(3,MAX(b[1],b[2])-n);
  if(a)a+=b[0];
  else a+=MIN(1,b[0]);
  printf("%d\n",a);
  return 0;
}

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

ll solve() {
    ll X, K, D;
    cin >> X >> K >> D;
    ll y = X < 0 ? -X : X;
    ll t = y/D;
    if ( K <= t ) {
        ll z = y - D*K;
        if ( X < 0 ) return abs(-z);
        else return abs(z);
    } else {
        K -= t;
        y -= D*t;
        if ( K % 2 != 0 ) y -= D;
        if ( X < 0 ) return abs(-y);
        else return abs(y);
    }
    return 0;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3644
// In the name of God
#include <bits/stdc++.h>

using namespace std;
#define Size(x) ((int)(x).size())
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int INF = 1e9 + 10;
const int MN = 1e5 + 10;

int n;
bool mk[MN];
int ans;

int main()
{
	ios_base :: sync_with_stdio(false) ,cin.tie(0) , cout.tie(0);
	cin >> n;
	for(int i=0;i<n;++i){
		int t;cin>>t;
		if(!mk[t]) ans++ , mk[t] = true;
	}
	if(ans%2 == 0) cout << ans - 1 << endl;
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
from itertools import permutations
c = []
for i in range(3):
    c.append(list(map(int, input().split())))
S = sum([c[i][i] for i in range(3)])
perms = list(permutations([1, 2, 3], 3))


def judge(c, S):
    for p in perms:
        s = sum([c[i][p[i] - 1] for i in range(3)])
        if S != s:
            return "No"
    return "Yes"


print(judge(c, S))


Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
	string s;
	cin >> s;
	int cnt = 0;
	for (char c : s) {
		if (c == 'C' && cnt == 0) {
			cnt = 1;
		}
		if (c == 'F' && cnt == 1) {
			cnt = 2;
		}
	}
	cout << (cnt == 2 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<map>
#include<queue>
#include<stack>
#include<cmath>

using namespace std;


int main() {
	string _s;
	list<string> s;
	cin >> _s;
	s.push_back(_s);

	int N;
	cin >> N;
	bool foward = true;
	for (int i = 0; i < N; ++i) {
		int j;
		cin >> j;
		if (j == 1) {
			foward = !foward;
			continue;
		}
		else {
			int a;
			char _b;
			cin >> a >> _b;
			string b = "";
			b = _b;
			--a;
			if (foward && a) {
				s.push_back(b);
			}
			else if (foward) {
				s.push_front(b);
			}
			else if (a) {
				s.push_front(b);
			}
			else {
				s.push_back(b);
			}
		}
	}
	string ans = "";
	for (auto itr = s.begin(); itr != s.end(); ++itr) {
		ans += *itr;
	}
	if (foward) {
		cout << ans << endl;;
	}
	else {
		for (int i = 1; i <= ans.length(); ++i) {
			cout << ans[ans.length() - i];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 16736
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

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

using namespace std;
using namespace __gnu_pbds;

#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1)
	{
		cerr << name << " = " << arg1 << endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args)
	{
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
		__f(comma+1, args...);
	}
#else
#define debug(...)
#endif

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

// priority_queue<ll, vector<ll>, less<ll>>pq;     // Max Heap
// priority_queue<ll, vector<ll>, greater<ll>>pq;  // Min Heap

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth (1 based indexing) smallest: " << *A.find_by_order(k - 1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

const int MAXN = 2e5 + 5;

ll n, k, dp[MAXN], l[20], r[20], mod = 998244353, suff[MAXN];

int main()
{
	FAST_IO;

 	cin >> n >> k;
 	for(int i=0;i<k;i++) cin >> l[i] >> r[i];
 	dp[n - 1] = suff[n - 1] = 1;
 	for(int i=n-2;i>=0;i--)
 	{
 		for(int j=0;j<k;j++)
 		{
 			ll beg = i + l[j];
 			ll end = i + r[j];
 			if(beg < n)
 			{
 				dp[i] = (dp[i] + suff[beg]) % mod;
 				if(end < n - 1)
 					dp[i] = ((dp[i] - suff[end + 1]) % mod + mod) % mod;
 			}
 		}
 		suff[i] = (suff[i + 1] + dp[i]) % mod;
 	}
 	cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 6680