akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define MAX 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];

int dijkstra(){
  int i,v,u,minv;
  int d[MAX],color[MAX];

  for(i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }

  d[0]=0;
  color[0]=GRAY;
  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv > d[i] && color[i] != BLACK){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1) break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v] != BLACK && M[u][v] != INFTY){
	if(d[v]>d[u]+M[u][v]){
	  d[v]=d[u]+M[u][v];
	  color[v]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d ",i);
    if(d[i]==INFTY) printf("-1\n");
    else printf("%d\n",d[i]);
  }
}

int main(){
  int i,j;
scanf("%d",&n);
for(i=0;i<n;i++){
    for(j=0;j<n;j++)
      M[i][j]=INFTY;
  }

 int k,c,u,v;
 for(i=0;i<n;i++){
   scanf("%d %d",&u,&k);
   for(j=0;j<k;j++){
     scanf("%d %d",&v,&c);
     M[u][v]=c;
   }
 }

 dijkstra();

 return 0;
}



Measured memory_bytes: 2112
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

minus = 0
ans = 0

for i in [a,b,c,d,e]:
    shou = i//10
    amari = i% 10
    if amari == 0:
        amari = 10
    minus = max(minus,10-amari)
    ans += (shou+1)*10 if amari != 10 else + shou*10
ans -= minus


print(ans)

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

template<typename T>
istream& operator >> (istream& istr, vector<T>& v){
    for(T& x: v) istr >> x;
    return istr;
}

template<typename T, typename U>
istream& operator >> (istream& istr, pair<T,U>& p){
    istr >> p.first >> p.second;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& v){
    if(!v.empty()){
        ostr << v.front();
        for(auto itr = ++v.begin(); itr != v.end(); itr++)
            // ostr << *itr;
            // ostr << " " << *itr;
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    // ostr << p.first << p.second;
    // ostr << p.first << ", " << p.second;
    ostr << "(" << p.first << ", " << p.second << ")";
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& vv){
    if(!vv.empty()){
        ostr << vv.front();
        for(auto itr = ++vv.begin(); itr != vv.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vp){
    if(!vp.empty()){
        ostr << vp.front();
        for(auto itr = ++vp.begin(); itr != vp.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<double> vd;
// vll v(n); v[i]=x;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
typedef vector<vd> vvd;
// vvll v(m,vll(n)); v[i][j]=x;
typedef pair<ll,ll> pll;
typedef pair<double,double> pd;
typedef vector<pll> vpll;
typedef vector<pd> vpd;
// vpll v(n); v[i]=make_pair(x,y); v[i].first/second;
// v.front() : v[0]
// v.back()  : v[v.size()-1]

#define PI 3.1415926535897932
#define EPS 1e-12
#define INF ((ll)1e+12)
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<=(b); i++)
#define FORR(i,a,b) for(ll i=(b); i>=(a); i--)
#define fix(x) cout << fixed << setprecision(x)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()

template<typename T> T sum(vector<T>& v){return accumulate(all(v), (T)0);}
template<typename T> inline void sort(vector<T>& v){sort(all(v));}
template<typename T> inline void rsort(vector<T>& v){sort(all(v), greater<T>());}
template<typename T> inline void chmin(T& a, T b){if(a>b) a=b;}
template<typename T> inline void chmax(T& a, T b){if(a<b) a=b;}

int main(){
    ll n, x = 0;
    cin >> n;
    vll a(n,0);
    REP(i,n-1){
        cin >> x;
        x--;
        a[x]++;
    }
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 4756
r, c = map(int, raw_input().split())
sheet = list()
for i in range(r):
    sheet.append(map(int, raw_input().split()))
for i in range(r):
    sheet[i].append(sum(sheet[i]))
for i in sheet:
    print(" ".join(str(j) for j in i))
temp = list()
for i in range(c):
    result = 0
    for j in range(r):
        result += sheet[j][i]
    temp.append(result)
temp.append(sum(temp))
print(" ".join(str(i) for i in temp))

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


int main() {
    string s;
    cin >> s;
    if(s == "Sunny")cout << "Cloudy\n";
    else if(s == "Cloudy")cout << "Rainy\n";
    else cout << "Sunny\n";
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

#define Pair make_pair
#define Push push_back
typedef long long lli;
typedef pair<lli,lli> pll;
typedef vector<lli> vcL;
typedef vector<pll> vPL;


void solve() {
	string s;
	lli k;
	cin >> s >> k;
	
	if ( k == 1 ) cout << s[0] << '\n';
	else if ( s[0] != '1' ) cout << s[0] << '\n';
	else {
		for (int i = 1; i < s.size(); ++i) {
			if ( i >= k ) {
				cout << '1' << '\n';
				break;
			}
			if ( i == s.size()-1 or s[i] != '1' ) {
				cout << s[i] << '\n';
				break;
			}
		}
	}
}

int main() {
	int t = 1;
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve();
	}
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<functional>
#include<cmath>

#define Vi vector<int>
#define Vs vector<string>
#define PB push_back
#define ALL(a) a.begin(),a.end()
#define FOR(i,n) for(int i=0;i<n;i++)
#define DEB cout<<"!"
#define MOD 1000000007
using namespace std;

typedef pair<int,int> pii;
typedef pair<int,pii> piii;

int main(){
  int n;
  string s;
  cin>>n>>s;
  stack<int> l,r;
  FOR(i,n){
    switch(s[i]){
    case '(':
      l.push(1);
      break;
    case ')':
      if(l.empty())r.push(1);
      else l.pop();
      break;
    }
  }
  while(!r.empty()){
    r.pop();
    cout<<"(";
  }
  cout<<s;
  while(!l.empty()){
    l.pop();
    cout<<")";
  }
  cout<<endl;
}

Measured memory_bytes: 256
#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        print(*args,  file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit


    
N, K = getIntList()
#print(N)
za  = getIntList()
zt = []

for i in range(N):
    tot = 0
    for j in range(N-i):
        tot += za[i+j]
        zt.append(tot)
zt.sort(reverse = True)

def find(z, bh):
    g = (1<<bh)
    zr = []
    for x in z:
        if g&x:
            zr.append(x)
    return zr

nowh = 40
result= 0
while nowh>=0:
    zr = find(zt,nowh)
    if len(zr)<K:
        nowh-=1
        continue
    result |= (1<<nowh)
    nowh-=1
    zt = zr

    
print(result)




Measured memory_bytes: 67708
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQUE(c)   sort(ALL((c)));(c).erase(unique(ALL((c))),(c).end())
# define LOWER(s)    transform(ALL((s)),(s).begin(),TL<char>)
# define UPPER(s)    transform(ALL((s)),(s).begin(),TU<char>)
# define FOR(i,a,b)  for(LL i=(a);i<(b);i++)
# define RFOR(i,a,b) for(LL i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int h, w;
string maze[10101];

int main(){
	cin >> h >> w;
	REP(i, h) {
		cin >> maze[i];
	}
	for (int i = 1; i < h-1; i++) {
		for (int j = 1; j < w - 1; j++) {
			int cnt = 0;
			if (maze[i][j] != '#')continue;
			REP(k, 4) {
				if (maze[i + dy[k]][j + dx[k]] == '#')cnt++;
			}
			if (cnt == 0) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 384
N = int(input())
S = input()
Answer = 0
White = 0
Red = S.count('R')
for j in range(len(S)):
    i = S[j]
    if i == 'W':
        White += 1
    elif i == 'R' and White >0 and j+1 > Red:
        Answer += 1
        White -= 1
print(Answer)

Measured memory_bytes: 9484
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A.at(i);
    }
    
    std::sort(A.begin(),A.end(),std::greater<int>());
    
    int num = 1;
    int now_min = A.at(A.size() - 1);
    
    for(int i=0;i<N-1;i++){
        A.pop_back();
        if(A.at(A.size()-1) > now_min){
            now_min = A.at(A.size()-1);
            num++;
        }
    }
    
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h> 
 
using namespace std;
 
#define len(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vi vector<int> 
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<int, int>
#define beg begin
 
#ifdef LOCAL
    #define dbg(x) cout << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 

template<class T> istream& operator>>(istream &str, vector<T> &a) {
	for (auto &i : a) {
		str >> i; 
	}
	return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(10);
    solve();    
}

const int INF = 1e18, MAXN = 2e5 + 10, MOD = 1e9 + 7;
int n, m, q;
vi a(MAXN), t[4 * MAXN];

vi merge(vi &a, vi &b) {
	vi tmp;
	int i = 0, j = 0;
	while (i < len(a) && j < len(b)) {
		while (i < len(a) && a[i] <= b[j]) {
			tmp.pb(a[i++]);
		}
		while (j < len(b) && b[j] <= a[i]) {
			tmp.pb({b[j++]});
		}
	}

	while (i < len(a)) {
		tmp.pb(a[i++]);
	}
	while (j < len(b)) {
		tmp.pb(b[j++]);
	}

	return tmp;
}

void build(int v, int tl, int tr) {
	if (tl == tr) {
		t[v].pb(a[tl]);
	}
	else {
		int tm = (tl + tr) / 2;
		build(v * 2, tl, tm);
		build(v * 2 + 1, tm + 1, tr);
		t[v] = merge(t[v * 2], t[v * 2 + 1]);
	}
}

int cnt(int v, int tl, int tr, int l, int r, int i, int j) {
	if (r < tl || tr < l) {
		return 0;
	}

	if (l <= tl && tr <= r) {
		int id1 = lower_bound(all(t[v]), i) - t[v].beg();
		int id2 = upper_bound(all(t[v]), j) - t[v].beg();
		return id2 - id1;
	}

	int tm = (tl + tr) / 2;
	int ans1 = cnt(v * 2, tl, tm, l, r, i, j);
	int ans2 = cnt(v * 2 + 1, tm + 1, tr, l, r, i, j);

	return ans1 + ans2;
}	

void solve() {
	cin >> n >> m >> q;
	vector<pair<int, int>> sg;
	for (int i = 0; i < m; ++i) {
		int l, r;
		cin >> l >> r;
		sg.pb({l, r});
	}

	sort(all(sg));

	for (int i = 0; i < m; ++i) {
		a[i] = sg[i].y;
	}

	build(1, 0, m - 1);

	for (int i = 0; i < q; ++i) {
		int l, r;
		cin >> l >> r;
		pii it1 = {l, 0ll};
		pii it2 = {r, INF};
		int id1 = lower_bound(all(sg), it1) - sg.beg();
		int id2 = upper_bound(all(sg), it2) - sg.beg(); id2--;

		// dbg(id1 << " " << id2)

		if (id1 > id2) {
			cout << 0 << endl;
			continue;
		}

		cout << cnt(1, 0, m - 1, id1, id2, l, r) << endl;
	}
}

Measured memory_bytes: 69356
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
ll a[100000];
int cnt[40];
int keta[40];//どの桁を減らすことができるか
int main()
{
	int n;
	ll ans=0;
	cin>>n;
	fill(cnt,cnt+40,0);
	fill(keta,keta+40,0);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		bool f=false;
		for(ll bit=0;bit<40;bit++)
		{
			if(a[i]&(1LL<<bit))
			{
				if(!f)
				{
					f=true;
					keta[bit]++;
				}
				cnt[bit]++;
			}
		}
	}
	//上の桁から調べる
	for(int i=39;i>-1;i--)
	{
		if(!(cnt[i]&1))
			continue;
		if(keta[i]==0)
		{
			ans=-1;
			break;
		}
		ans++;
		cnt[i]--;
		for(int j=0;j<i;j++)
			cnt[j]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1000000000100000000;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    cout << (n-h+1) * (n-w+1) << ln;
}


Measured memory_bytes: 3640
public class Main {
	public static void main(String[]args) {
		
		java.util.Scanner scanner = new java.util.Scanner(System.in);
		
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		
		System.out.print( a * b +" ");
		System.out.println((a + b) * 2 );
	}
}

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

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

int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if (a == 7 && b == 5 && c == 5 || a == 5 && b == 7 && c == 5 || a == 5 && b == 5 && c == 7) printf("YES\n"); 
  else printf("NO\n");
}


Measured memory_bytes: 256
def comb(a, b)
    b = a - b if 2 * b > a
    b.times.inject(1) {|r, v| r * (a - v) / (v + 1)}
end

n, pp = gets.split.map(&:to_i)

h = Hash.new(0)
gets.split.each {|e| h[e.to_i % 2] += 1}

if pp == 0
    ans = 0.step(h[1], 2).inject(0) {|r, v| r + comb(h[1], v)}
else
    ans = 1.step(h[1], 2).inject(0) {|r, v| r + comb(h[1], v)}
end

puts ans * 2 ** h[0]


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N,M;cin >> N >> M;
    vector<vector<int>> G(N,vector<int>());
    vector<int> h(N);
    rep(i,N-1+M){
        int a,b;cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        h[b]++;
    }
    queue<int> zero;

    rep(i,N)if(h[i] == 0)zero.push(i);

    vector<int> dist(N);    //dist[i]:=i番目の頂点を通るときの最長経路      この問題では根っこが1つしかないはずなので、根っこからの最長距離にあたるはず
    
    int j = 0;
    while(zero.size()){
        int v = zero.front();zero.pop();
        for(auto nv : G[v]){
            h[nv]--;
            chmax(dist[nv],dist[v]+1);
            if(h[nv] == 0)zero.push(nv);
        }
    }

    vector<int> ans(N,-1);
    rep(v,N) for(auto nv : G[v]) if(dist[nv] - dist[v] == 1) ans[nv] = v;   // 距離の差が1のものが必然的に隣り合ったもので、これがもともとのグラフの経路のはず。※1

    rep(i,N)cout << ans[i] + 1 << endl;     // +1 はグラフ作成時に0indexにしたやつをもとに戻すのと、根っこは0を出力なので、-1+1=0にするため。根は一つしかないから（至言）

}

// ※1 これに関しては、解説放送がわかりやすい。
//     端的に説明すると、距離差が2以上のとき、つまり頂点をジャンプして子孫につながるルートが正規ルートだと仮定すると、距離差１の経路は新たに頂点を生まないと生えてこないことになる。
//     これは明らかにグラフ形成と有向辺の追加のルールに反しているので矛盾。


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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cout << #x << " : " << x << '\n'

const int INF = 1e9;

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

  int ans = 0;
  int N;
  cin >> N;
  int l, r;
  FOR(i, 0, N) {
    cin >> l >> r;
    ans += r - l + 1;
  }

  cout << ans << '\n';

  return 0;
}

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

int main()
{
	constexpr auto pow_mod = [](int64_t a, int64_t n, int64_t mod) {
		int64_t r = 1;
		for (; n; n >>= 1)
		{
			if (n & 1)
			{
				(r *= a) %= mod;
			}
			(a *= a) %= mod;
		}
		return r;
	};
	int64_t n, mod = 1000000007;
	cin >> n;
	if (n == 2)
	{
		cout << 1 << endl;
		return 0;
	}
	vector<int64_t> fact(n + 1), fact_rev(n + 1);
	fact[0] = 1;
	for (int64_t i = 1; i <= n; i++)
	{
		fact[i] = fact[i - 1] * i % mod;
	}
	fact_rev[n] = pow_mod(fact[n], mod - 2, mod);
	for (int64_t i = n - 1; 0 <= i; i--)
	{
		fact_rev[i] = fact_rev[i + 1] * (i + 1) % mod;
	}
	vector<int64_t> f(n, 0);
	for (int64_t k = 2; k < n; k++)
	{
		int64_t a = 2 * k - n, b = n - k - 1;
		if (a < 0 || b < 0)
		{
			continue;
		}
		f[k] = fact[a + b] * fact_rev[a] % mod * fact_rev[b] % mod * fact[k] % mod * fact[n - k - 1] % mod;
	}
	int64_t ans = 0;
	for (int64_t k = 2; k < n; k++)
	{
		int64_t num = f[k] - f[k - 1];
		if (num < 0)
		{
			num += mod;
		}
		(ans += k * num % mod) %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807;
const ll half_inf = 0x3f3f3f3f;
const ll inf = 0x7fffffff;
const ll mod = 1e9 + 7;
const ll maxn = 200005;
ll ans=0;
int main(){  
	cin.tie(0);
    ios::sync_with_stdio(false);
	ll n,m;
	scanf("%lld%lld",&n,&m);
	//printf("%lld %lld\n",(m+1)/2*((n+1)/2),(m-1)/2*((n-1)/2));
	if(n!=1&&m!=1) printf("%lld",(m*n+1)/2);
	else printf("1");
    return 0;
}




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

using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,k,h) for(int i = k; i < h; ++i)
#define rep3(i,k,h) for(int i = k; i <= h; ++i)
#define INF LONG_LONG_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;


int main() {
    string s;
    ll count = 0,Bcou = 0;
    cin >> s;
    rep(i,s.length()) {
        if(s[i] == 'W') {
            count += Bcou;
        continue;
        }
        Bcou++;
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n ; i++)

int main(){
    int N, K;
    cin >> N >> K;
    int sum = 0;

    rep(i, N){
        int x;
        cin >> x;

        int A = x;
        int B = K - x;

        if(A < B){
            sum += 2*A;
        } else{
            sum += 2*B;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 3648
//ABC067B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> l(n);
	for(int i=0;i<n;i++){
		cin >> l.at(i);
	}
	sort(l.begin(),l.end());
	int ans = 0;
	for(int i=0;i<k;i++){
		ans += l.at(n-i-1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
ls=[1]

for i in range(1,7):
  ls.append(6**i)
  ls.append(9**i)
dp = [float('inf') for i in range(n+2)]
dp[0] = 0

#円の総合計
for i in range(1,n+1):
  for j in ls:
    if i-j>=0:
      dp[i] = min(dp[i-1]+1, dp[i-j]+1,dp[i])
    else:
      dp[i] = min(dp[i-1]+1,dp[i])
print(dp[n])

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

int main() {
    vector<int> x(5);
    rep(i,5){
        cin >> x[i];
        if (x[i]==0) cout << i+1 << endl;
    }
}

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

using namespace std;
using LL = long long;
using VI = vector<int>;
using PI = pair<int, int>;

int main() {
	double x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	cout << setprecision(12) << fixed << hypot(abs(x1 - x2), abs(y1 - y2)) << endl;
	return 0;
}



Measured memory_bytes: 3340
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <complex>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

typedef long long ll;
typedef vector<int> vi;

// geometry library start

const double EPS = 1.0e-10;

class P {
public:
	double x, y;
	P() {}
	P(int x_, int y_) : x(x_), y(y_) {}
	P(double x_, double y_) : x(x_), y(y_) {}
	P(const P& p) : x(p.x), y(p.y) {}
	P operator+(const P& p) const { return P(x+p.x, y+p.y); } 
	P operator-(const P& p) const { return P(x-p.x, y-p.y); }
	P operator-() const { return P(-x, -y); }
	P operator*(double s) const { return P(x*s, y*s); }
	P operator/(double s) const { return P(x/s, y/s); }
	P& operator=(const P& p) { x=p.x; y=p.y; return (*this); }
	double dot(const P& p) const { return x*p.x + y*p.y; }
	double det(const P& p) const { return x*p.y - y*p.x; }
	double norm() const { return sqrt(x*x + y*y); }
	double norm2() const { return x*x + y*y; }
	P proj(const P& p) const { double k=det(p)/norm2(); return P(x*k, y*k); }
};

double tri(P a, P b, P c) { return (b - a).det(c - a); }
int sign(double r) { return r < -EPS ? -1 : r > EPS ? 1 : 0; }

class L {
public:
	P s, t;
	L() {}
	L(P s_, P t_) : s(s_), t(t_) {}
	L(const L& l) : s(l.s), t(l.t) {}
	L& operator=(const L& l) { s=l.s; t=l.t; return (*this); }
	double length() { return (s - t).norm(); }
	P vec() const { return t - s; }
	P proj(const P& p) { return s + vec().proj(p - s); }
	int iLL(const L& l) const {
		if(sign(vec().det(l.vec()))) return 1;
		if(sign(vec().det(l.s - s))) return 0;
		return -1;
	}
	bool iLS(const L& l) const { return sign(tri(s, t, l.s)) * sign(tri(s, t, l.t)) <= 0; } 
	bool iSS(const L& l) const { return iLS(l) && l.iLS(*this); }
	P pLL(const L& l) const { return s + vec() * (l.s - s).det(l.vec()) / vec().det(l.vec()); }
	double dLP(const P& p) const { return abs(tri(s, t, p)) / vec().norm(); }
	double dSP(const P& p) const {
		if(sign(vec().dot(p - s)) <= 0) return (p - s).norm();
		if(sign(vec().dot(p - t)) >= 0) return (p - t).norm();
		return dLP(p);
	}
};

class C {
public:
	P p;
	double r;
	C() {}
	C(P p_, double r_) : p(p_), r(r_) {}
	C(const C& c) : p(c.p), r(c.r) {}
	C& operator=(const C& c) { p=c.p; r=c.r; return (*this); }
};

// geometry library end

int main() {
	double x1, y1, x2, y2, x3, y3, xp, yp;
	while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp) != EOF) {
		P p1(x1, y1);
		P p2(x2, y2);
		P p3(x3, y3);
		P  p(xp, yp);

		double d1 = (p1 - p).det(p2 - p);
		double d2 = (p2 - p).det(p3 - p);
		double d3 = (p3 - p).det(p1 - p);
		if(sign(d1) == sign(d2) && sign(d2) == sign(d3)) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}
	}
}

Measured memory_bytes: 1196
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
import numpy as np

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()
N = 50

ans = np.array(list(range(50)))
ans += K//N
K = K%N

for i in range(K):
	ans[i] += 51
	ans -= 1
print(N)
print(*ans)


Measured memory_bytes: 13628
import java.util.*;
public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n= sc.nextInt();
        int x= sc.nextInt();
        int y=sc.nextInt();
        int dist[] = new int[n];
        //int maxLength = 1 + (x-1) + (n-x);
        //int total = n*(n-1)/2 ;
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                 int minDistance = Math.min(Math.abs(j-i),Math.abs(x-i)+1+Math.abs(y-j));
                 dist[minDistance]++;
            }
        }
        for(int i=1;i<n;i++)
            System.out.println(dist[i]);
        
    }
}

Measured memory_bytes: 22604
// luogu-judger-enable-o2
#include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	cin>>n;
	int cnt[n+1];
	long long ans=0;
	for(int i=1;i<=n;i++){
		cin>>cnt[i];
	}
	for(int i=1;i<n;i++){
		ans+=cnt[i]/2;
		if(cnt[i]%2&&cnt[i+1]){
			cnt[i+1]--;
			ans++;
		}
	}
	cout<<ans+cnt[n]/2<<endl;
	return 0;
}

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

int ISP(char str[]) 
{ 
    
    int l = 0; 
    int h = strlen(str) - 1; 
  
     
    while (h > l) 
    { 
        if (str[l++] != str[h--]) 
        { 
            return -1; 
            break; 
        } 
    } 
    return 1; 
}

int main()
{
    char ch[100];
    cin>>ch;
    
    int a,b,c,N=strlen(ch),t1,t2;
    a=ISP(ch);
    t1=(N-1)/2;
    t2=((N+3)/2);
    
    int i;
    //cout<<t1<< "chek"<<t2<<endl;
    char str1[100],str2[100];
    for( i=0;i<t1;++i)
    {
        str1[i]=ch[i];
        
    }
    str1[i]='\0';
    
    for( i=0;i<t2;++i)
    {
        str2[i]=ch[i+(t2-1)];
    }
    
    b=ISP(str1);
    c=ISP(str2);
    
    //cout<<ch<<" # "<<str1<< " $ "<<str2<<endl;
    if(a==1&&(b==1&&c==1))
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int d, score;
vector<int> c(26);
vector<vector<int>> s(400, vector<int>(26)), pos(26);

int get_score(vector<int> t){
    vector<int> pos(26, 0);
    int ans = 0;
    rep(i, d){
        int l = i + 1 - pos[t[i]];
        ans -= (l * (l-1) / 2) * c[t[i]];
        ans += s[i][t[i]];
        pos[t[i]] = i+1;
    }
    rep(i, 26){
        int l = d + 1 - pos[i];
        ans -= (l * (l-1) / 2)* c[i];
    }
    return ans;
}

int main() {
    cin >> d;
    rep(i, 26)cin >> c[i];
    rep(i, d)rep(j, 26)cin >> s[i][j];
    //-----code------// 
    int score = 0;
    vector<int> t(d, 0), pos(26, 0);
    rep(i, d){
        int ma = 0;
        rep(j, 26){
            int now = score;
            now += s[i][j];
            now -= (i + 1 - pos[j]) + (i - pos[j]) / 2 * c[j];
            ma = max(ma, now);
        }
        rep(j, 26){
            int now = score;
            now += s[i][j];
            now -= (i + 1 - pos[j]) + (i - pos[j]) / 2 * c[j];
            if(now == ma){
                pos[j] = i+1;
                t[i] = j;
            }
        }
    }
    score = get_score(t);
    while(clock() < 1950000){
        int D = rand() % d, q = rand() % 26;
        int old = t[D], olds = get_score(t);
        t[D] = q;
        if(get_score(t) < olds)t[D] = old;
    }
    rep(i, d)cout << t[i]+1 << endl;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    ll n, k; cin >> n >> k;
    modint res;
    rep(i, min(n, k+1)){
        res += comb(n, i)*comb(n-1, i);
    }
    cout << res.n << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7792
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;

int solve() 
{
	//happy coding

	ll a,b;
	cin>>a>>b;
	cout<<(a*b)/__gcd(a,b)<<endl;
	
	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys
#from heapq import heapify, heappush, heappop
#from heapq import nlargest, nsmallest

iimr = lambda: map(int, sys.stdin.readline().rstrip().split())
readline = sys.stdin.readline
# puorquoi le sys.stdin.buffer.readline() ne fonctionne plus sur atcoder?
#sys.setrecursionlimit(10 ** 7)
#INF = 1 << 30 # 大体 1e9


def debug(*x):
    print(*x, file=sys.stderr)


# s == self
class atcoder():
    def __init__(s):
        s.N = int(input())

    def çözmek(s):
        
        res = []
        res.append(s.関数(s.N))
        if res[0] == True:
            print("Yes")
        else: 
            print("No")
    
    def 関数(self, n):
        tsuzuku = 0
        trouve = False
        for i in range(n):
            a, b = map(int, input().split())
            #debug([a,b])
            if a == b:
                tsuzuku += 1
            else: 
                tsuzuku = 0
            if tsuzuku == 3:
                trouve = True

        return trouve 

if __name__ == "__main__":
    ima = atcoder()
    ima.çözmek()



Measured memory_bytes: 9272
/*
Date: 2017/01/07 19:53:24 Saturday
*/
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#ifdef LOCAL
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 
#endif
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x3f3f3f3f;
const int mo=1000000007;
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
template<class T1,class T2>inline void gn(T1&r,T2&s){gn(r),gn(s);}
template<class T1,class T2,class T3>inline void gn(T1&r,T2&s,T3&t){gn(r),gn(s),gn(t);}
template<class T1,class T2,class T3,class T4>inline void gn(T1&r,T2&s,T3&t,T4&u){gn(r),gn(s),gn(t),gn(u);}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll powmod(ll a,ll b,ll mo) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111,M=111111;
int l,m,n,t,C,x,y,z;
int a[N][N],b[N][N];
struct zcc{int x,y,z;}E[M];
int main(){
#ifdef LOCAL
	freopen("D.in","r",stdin);//freopen("D.out","w",stdout);
#endif
	scanf("%d%d",&n,&m);
	rep(i,1,n)rep(j,1,n)b[i][j]=inf;
	rep(i,1,n)b[i][i]=0;
	rep(i,1,m)scanf("%d%d%d",&x,&y,&z),a[x][y]=b[x][y]=b[y][x]=z,E[i]={x,y,z};
	rep(k,1,n)rep(i,1,n)rep(j,1,n)MIN(b[i][j],b[i][k]+b[k][j]);
	int ans=0;
	rep(j,1,m){
		int ok=0;
		int x=E[j].x,y=E[j].y;
		if(b[x][y]==E[j].z)ok=1;
		if(!ok)++ans;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
int main(){
  int cnt = 0;
  char S[100000];
  scanf("%s",&S);
  for(int i = 0;i < strlen(S) - 1;i++){
    if(S[i] != S[i + 1]){
      cnt++;
    }
  }
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    X,K,D=MI()
    t=abs(X)//D
    if t>=K:
        ans=abs(X)-D*K
    else:
        a=abs(abs(X)-D*t)
        rem=K-t
        if rem%2==0:
            ans=a
        else:
            ans=a=abs(abs(X)-D*(t+1))
        
        
    print(ans)
    
    

main()


Measured memory_bytes: 61768
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;

int main(){
    //freopen("in.txt", "r", stdin);
    string s;
    cin>>s;

    int n1, n2;
    n1 = s[0] - '0';
    n1 *= 10; 
    n1 += s[1] - '0';

    n2 = s[2] - '0';
    n2 *= 10;
    n2 += s[3] - '0';

    bool YYMM = false, MMYY = false;

    if (n2 > 0 && n2 <= 12) YYMM = true;
    if (n1 > 0 && n1 <= 12) MMYY = true;

    if (YYMM && MMYY) cout<<"AMBIGUOUS"<<endl;
    else if (YYMM) cout<<"YYMM"<<endl;
    else if (MMYY) cout<<"MMYY"<<endl;
    else cout<<"NA"<<endl;

    return 0;
}

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

bool check(int x, int y, vector<bool> lock) {
	for (int i = x;i < y ;i++) {
		if (!lock[i] && !lock[i + 1])
			return false;
	}
	return true;
}

int main() {
	int n,a, b, c, d;
	string s;
	cin >> n >> a >> b >> c >> d >> s;
	vector<bool> lock(n,true);
	for (int i = 0;i < n;i++) {
		if (s[i] == '#')
			lock[i] = false;
	}
	a--;b--;c--;d--;
	bool ans=false;
	if (check(a, c, lock) && check(b, d, lock))
		ans = true;
	else {
		ans = false;
	}
	if (ans) {
		if (d < c) {
			int gg = 0;
			bool ju = false;
			int i = b - 1;
			int co = 0;
			while (i < d + 2) {
				if (lock[i]) {
					co++;
					gg = max(gg, co);
				}
				else {
					co = 0;
				}
				i++;
			}
			if (gg < 3) {
				ans = false;
			}
		}
	}
	if (ans)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n;
vector<pair<int, int>> v[100000];
int d[100000];

template<typename T> class RPQ : public PQ<T, vector<T>, greater<T>> { };
template<typename Cost> void dijkstra(int start, vector<pair<int, Cost>> g[], Cost dist[]) {
	RPQ<pair<Cost, int>> q;
	dist[start] = 0;
	q.emplace(dist[start], start);
	while(! q.empty()) {
		auto cp = q.top(); q.pop();
		int  p = cp.SE;
		Cost c = cp.FI;
		if(dist[p] != c) { continue; }
		for(auto && e : g[p]) {
			int  ep = e.FI;
			Cost ec = e.SE;
			if(setmin(dist[ep], dist[p] + ec)) { q.emplace(dist[ep], ep); }
		}
	}
	return;
}

int main() {
	cin >> n;
	inc(i, n) {
		int a;
		cin >> a;
		a--;
		v[i].EB(a, 1);
	}
	
	inc(i, n) { d[i] = n + 1; }
	dijkstra(0, v, d);
	if(d[1] == n + 1) { d[1] = -1; }
	
	cout << d[1] << endl;
	
	return 0;
}


Measured memory_bytes: 6144
using static System.Math;
using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public int L { get; set; }
    public int h { get; set; }
    public int[] a { get; set; }
}

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var m = int.Parse(line[1]);
            var k = int.Parse(line[3]);
            if (n == 0 && m == 0 && line[2] == "0" && k == 0) break;
            var d = new Dictionary<int, int>();
            for (int i = 1; i <= n; i++)
                d[i] = int.Parse(Console.ReadLine().Trim());
            var pw = new P[m];
            for (int i = 0; i < m; i++)
            {
                line = Console.ReadLine().Trim().Split(' ');
                var L = int.Parse(line[0]);
                var h = int.Parse(line[1]);
                pw[i] = new P {  L = L, h = h, a = new int[4] };
            }
            var ps = pw.OrderBy(x => x.h).ToArray();
            getData(ps, d, n, m);
            var jdata = getJdata(ps, m, k);
            getAns(ps, jdata, k);
        }
    }
    static void getAns(P[] ps, int[] jdata, int k)
    {
        var jsum = jdata.Sum();
        var ans = jsum;
        foreach (var x in ps)
        {
            var t = jsum;
            var a = x.a[0];
            if (a <= k) t += x.a[2] - jdata[a];
            var b = x.a[1];
            if (b <= k) t += x.a[3] - jdata[b];
            ans = Min(ans, t);
        }
        Console.WriteLine(ans);
    }
    static int[] getJdata(P[] ps, int m, int k)
    {
        var count = 0;
        var j = new int[k + 1];
        foreach (var x in ps)
        {
            var wa0 = x.a[0];
            if (wa0 >= 1 && wa0 <= k)
            {
                var wa3 = x.a[3];
                if (j[wa0] == 0)
                {
                    j[wa0] = wa3;
                    count++;
                    if (count == k) break;
                }
            }
            var wa1 = x.a[1];
            if (wa1 >= 1 && wa1 <= k)
            {
                var wa2 = x.a[2];
                if (j[wa1] == 0)
                {
                    j[wa1] = wa2;
                    count++;
                    if (count == k) break;
                }
            }
        }
        return j;
    }
    static void getData(P[] ps, Dictionary<int, int> d, int n, int m)
    {
        var dt = new Dictionary<int, int>();
        for (int i = 1; i <= n; i++) dt[i] = i;
        for (int i = 0; i < m; i++)
        {
            ps[i].a[0] = dt[ps[i].L];
            ps[i].a[1] = dt[ps[i].L + 1];
            swap(dt, ps[i].L, ps[i].L + 1);
            var ri = m - 1 - i;
            ps[ri].a[2] = d[ps[ri].L];
            ps[ri].a[3] = d[ps[ri].L + 1];
            swap(d, ps[ri].L, ps[ri].L + 1);
        }
    }
    static void swap(Dictionary<int, int> d, int x, int y)
    {
        var t = d[x];
        d[x] = d[y];
        d[y] = t;
    }
}



Measured memory_bytes: 34852
#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <iostream>
 
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define FORN(k, s, n) for (int k = s; k < n; k++)
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);
 
#pragma warning(disable : 6031)
#pragma warning(disable : 4101)
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;
 
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
 
// Solution

const int MAXN = 100005;

int n, DP[MAXN];

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

    DP[1] = 1;

    for (int i = 2; i <= n; i++) {
        DP[i] = DP[i - 1] + 1;

        for (int k = 1; k <= 10; k++) {
            if (pow(6, k) <= i) {
                DP[i] = min(DP[i], DP[i - (int)pow(6, k)] + 1);
            }

            if (pow(9, k) <= i) {
                DP[i] = min(DP[i], DP[i - (int)pow(9, k)] + 1);
            }
        }
    }

    printf("%d\n", DP[n]);

    return 0;
}

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

using namespace std;

#define ll long long

struct UnionFind{
    vector<int> data;
    /* constructor */
    UnionFind(int sz){ data.assign(sz,-1); }
    /* merge the set to which x belongs and the set to which y belongs */
    bool unite(int x,int y){
        x = find(x); y = find(y);
        if (x == y) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
    /* find the root of k */
    int find(int k){
        if (data[k] < 0) return k;
        return data[k] = find(data[k]);
    }
    /* calculate the size of the set to which k belongs */
    int size(int k){ return -data[find(k)]; }
};

int main(void){
    int N, K, L; cin >> N >> K >> L;
    UnionFind road(N), rail(N);
    while (K--){
        int p, q; cin >> p >> q;
        --p, --q;
        (void)(road.unite(p, q));
    }
    while (L--){
        int r, s; cin >> r >> s;
        --r, --s;
        (void)(rail.unite(r, s));
    }
    map<pair<int, int>, int> cnt;
    for (int i = 0; i < N; ++i)
        ++cnt[{road.find(i), rail.find(i)}];
    for (int i = 0; i < N; ++i){
        int c = cnt[{road.find(i), rail.find(i)}];
        cout << c << " ";
    }
    cout << endl;
    return 0;
}

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

int main() {
  string N;
  cin >> N;
  
  int s = N.size();
  int x;
  int ans = 0;
  
  for(int i=0;i<s;i++){
    x = N[i] - 48;
    ans += x;
  } 
  
  if(ans % 9 == 0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3744