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

int main(void) {
    int w, a, b, ans = 0;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> w >> a >> b;
    if (abs(a - b) > w) {
        ans = abs(a - b) - w;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int N;
LL C[501],S[500],F[500];
LL solve(int now, int t){
	if(now == N-1) return 0;
	LL next = ceil((double)t/F[now]); //何本目？
	if(F[now]*next >= S[now]) return F[now]*next - t + C[now] + solve(now+1, F[now]*next + C[now]);
	else return S[now] - t + C[now] + solve(now+1, S[now] + C[now]);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);
	
	cin >> N;
	for(int i=0; i<N-1; i++){
		cin >> C[i] >> S[i] >> F[i];
	}
	C[N-1] = 0;
	for(int i=0; i<N; i++){
		cout << solve(i,0) << endl;
	}

	return 0;
}



Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int N = 3010;

//head

int r, c, k;
vector<P> item[N];
ll dp[N][4], dpu[N];
auto now = dp;
auto pre = dpu;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> r >> c >> k;
  rep(i, k) {
    int r, c, v;
    cin >> r >> c >> v;
    r--; c--;
    item[r].emplace_back(c, v);
  }

  //cout << endl;

  rep(i, r) {
    if(item[i].empty()) continue;
    sort(all(item[i]));
    int sh = 0;
    int siz = item[i].size();
    rep(j, c) {
      copy(now[j], now[j]+4, now[j+1]);
      if(sh != siz and item[i][sh].first == j) {
        ll nv = item[i][sh++].second;
        chmax(now[j+1][0], pre[j+1]);
        for(int u = 3; u > 0; u--) {
          chmax(now[j+1][u], now[j+1][u-1] + nv);
        }
      }
      chmax(pre[j+1], *max_element(now[j+1], now[j+1]+4));
      //cout << i << ' ' << j << ' ' << pre[j+1] << endl;
    }
  }

  cout << pre[c] << endl;
}

Measured memory_bytes: 6628
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

class mint {
public:
    long long x;
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    //mint operator-() const{ return mint(-x);}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

};

int main(){
  int N, M; cin >> N >> M;
  vector<int> broken(N + 1, 0);
  rep(i, M) {
    int a; cin >> a;
    broken[a] = 1;
  }

  vector<mint> dp(N + 1, 0);
  dp[0] = 1;
  for (int i = 0; i < N + 1; ++i){
    if (!broken[i + 1] && i + 1 <= N) dp[i + 1] += dp[i];
    if (!broken[i + 2] && i + 2 <= N) dp[i + 2] += dp[i];
  }
  cout << dp[N].x << endl;
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define ALL(x) x.begin(), x.end()

void Main() {
    int n;
    cin >> n;
    vector<int> p(n);
    for(auto& x : p){
        cin >> x;
    }

    vector<int> p2 = p;
    sort(ALL(p2));
    int cnt = 0;
    rep(i, n){
        if(p[i] != p2[i]){
            cnt++;
        }
    }
    if(cnt == 0 || cnt == 2){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

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


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

int main() {

	int n;
	int b;
	int f;
	int r;
	int v;
	int num[4][3][10] = { 0 };

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> b >> f >> r >> v;
		num[b-1][f-1][r-1] += v;
	}

	for (int i = 0; i < 4; i++) { //building

		for (int j = 0; j < 3; j++) { //floor

			for (int k = 0; k < 10; k++) { //room

				cout << " " << num[i][j][k];
				if (k == 9) cout << endl;
				if (k == 9 && j == 2 && i < 3) cout << "####################" << endl;

			}
		}
	}

	return 0;
}


Measured memory_bytes: 3104
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long x = sc.nextLong();

		LinkedList<Long> ll = new LinkedList<Long>();
		for ( int i=0; i<=300; i++ ) {
			ll.add((long)Math.pow(i,5));
		}

		for ( int i=-300; i<=300; i++ ) {
			long a5 = 0;
			if ( i>=0 ) {
				a5 = ll.get(i);
			} else {
				a5 = 0l - ll.get(0-i);
			}
			for ( int j=-300; j<i; j++ ) {
				long b5 = 0;
				if ( j>=0 ) {
					b5 = ll.get(j);
				} else {
					b5 = 0l - ll.get(0-j);
				}
				if ( a5>b5 && x==a5-b5 ) {
					System.out.println(i + " " + j);
					System.exit(0);
				}
			}
		}
	}
}


Measured memory_bytes: 39252
import scala.annotation.tailrec
import scala.collection.mutable

object Main extends App {

  import scala.io.StdIn._

  val mod = 1000000007
  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val state = Array.tabulate(n * m){_ ⇒ Free: State}
  for ((r, i) ← readLine.trim.split(' ').map(_.toInt).zipWithIndex){
    state(r - 1) = state(r - 1).addRow(i)
  }
  for ((c, i) ← readLine.trim.split(' ').map(_.toInt).zipWithIndex){
    state(c - 1) = state(c - 1).addColumn(i)
  }
  println(solve(state))
  def solve(state: Array[State]): Long = {
    val rowFree = Array.tabulate(n){_ ⇒ true}
    val columnFree = Array.tabulate(m){_ ⇒ true}
    @tailrec
    def sub(state: List[State], r: Int = 0, c: Int = 0, f: Int = 0, prev: Long = 1): Long = {
      state match {
        case Nil ⇒ prev
        case RC(row, column)::t if rowFree(row) && columnFree(column) ⇒
          rowFree(row) = false
          columnFree(column) = false
          sub(t, r + 1, c + 1, f + c + r, prev)
        case R(row)::t if rowFree(row) && c > 0 ⇒
          rowFree(row) = false
          sub(t, r + 1, c, f + c - 1, (c * prev) % mod)
        case C(column)::t if columnFree(column) && r > 0 ⇒
          columnFree(column) = false
          sub(t, r, c + 1, f + r - 1, (r * prev) % mod)
        case Free::t if f > 0 ⇒ sub(t, r, c, f - 1, (f * prev) % mod)
        case _ ⇒ 0L
      }
    }
    sub(state.reverse.toList)
  }

  sealed trait State {
    def addRow(row: Int): State = {
      this match {
        case C(c) ⇒ RC(row, c)
        case Free ⇒ R(row)
        case _ ⇒ Failure
      }
    }
    def addColumn(column: Int): State = {
      this match {
        case R(r) ⇒ RC(r, column)
        case Free ⇒ C(column)
        case _ ⇒ Failure
      }
    }
  }
  case class R(row: Int) extends State
  case class C(column: Int) extends State
  case class RC(row: Int, column: Int) extends State
  case object Free extends State
  case object Failure extends State
  implicit class Extension[T](value :T){
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}

Measured memory_bytes: 89788
import sys


# input = sys.stdin.readline

def main():
    S = input()
    count =1
    for i in S:
        if count %2==1 and i =="L":
            print("No")
            exit()
        elif count%2 ==0 and i =="R":
            print("No")
            exit()

        count+=1
    print("Yes")





if __name__ == "__main__":
    main()

Measured memory_bytes: 9052
#include <bits/stdc++.h>
#define ll long long
#define str string
#define pb push_back
#define optimizator ios_base::sync_with_stdio(0);
using namespace std;
int main(){
	optimizator;
	str a,b,c;
	cin>>a>>b;
	int s,d;
	cin>>s>>d;
	cin>>c;
	if(a==c){
		cout<<s-1<<" "<<d;
	}
	else{
		cout<<s<<" "<<d-1;
	}
}

Measured memory_bytes: 256
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

ll a[N];

ll ceil_div(ll x, ll y);

int main() {
	int k;
	cin >> k;
	for (int i = 1; i <= k; ++i) {
		cin >> a[i];
	}

	ll l = 2, r = 2;
	for (int i = k; i >= 1; --i) {
		ll s = a[i] * (ceil_div(l, a[i]));
		ll t = a[i] * (r / a[i]);
		if (s > r) {
			cout << "-1\n";
			return 0;
		} else {
			l = s;
			r = t + a[i] - 1;
		}
	}

	cout << l << ' ' << r << endl;
}

ll ceil_div(ll x, ll y) {
	return (x / y) + !!(x % y);
}

Measured memory_bytes: 1024
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N,M;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>M;
	int last = 1;
	for (int i = 1; i*i <= M; ++i)
	{
		if (M%i!=0) {
			continue;
		}

		if (i >= N) {
			out << M / i << endl;
			return 0;
		}

		if (M / i < N) {
			out << last << endl;
			return 0;
		}
		last = i;
	}

	out << last << endl;
	return 0;
}
#endif


Measured memory_bytes: 888
n = int(input())
absum = []
for a in range(1,n):
    b = n-a
    asum = 0
    bsum = 0
    alen = len(str(a))
    blen = len(str(b))
    for j in range(alen):
        a0 = (a//(10**j)) % 10
        asum = asum + a0
    for k in range(blen):
        b0 = (b//(10**k)) % 10
        bsum = bsum + b0
    absum.append(asum+bsum)
print(min(absum))    

Measured memory_bytes: 9652
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
typedef long long ll;
int n,k;
vector<ll> a;
ll dp[110][100010];
ll mod = 1000000007;

int main(){
 cin >> n >> k;
 a.resize(n);
 for(int i = 0; i < n; ++i) cin >> a[i];
 for(int i = 0; i <= n; ++i) dp[i][0] = 1; //i人目までに0個配る方法は1通り

 for(int i = 1; i <= n; ++i){
   for(int j = 1; j <= k; ++j){
     dp[i][j] = (dp[i - 1][j] + dp[i][j - 1])%mod;
     if(j - a[i - 1] - 1 >= 0){
       dp[i][j] = (dp[i][j] + mod - dp[i - 1][j - a[i - 1] - 1])%mod;
     }
   }
 }
 cout << dp[n][k] << endl;
 return 0;
}

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

int main(){
    long long n, x, ans, a, b, check, tmp;
    cin >> n >> x;
    long long N[n];

    for(long long i=0;i<n;i++){
        cin >> N[i];
    }
    b = abs(x-N[0]);
    for(long long i=1;i<n;i++){
        a = abs(x-N[i]);
        if(a<b){
            tmp = a;
            a = b;
            b = tmp;
        }
        check = a % b;
        while(check != 0){
            a = b;
            b = check;
            check = a % b;
        } 
    }
    ans = b;
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    ll sum = 0;
    rep(i, 60){
        ll cnt = 0;
        rep(j,n){
            if((v[j]>>i) & 1) cnt++;
        }
        ll now = cnt * (n - cnt);
        now %= mod;
        rep(j,i){
            now *= 2;
            now %= mod;
        }
        sum += now;
        sum %= mod;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 5520
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

struct cmp {
	int mod;
	cmp(int x) :mod(x) {}
	bool operator()(const int& a, int& b)const {
		return a % mod < b % mod;
	}
};

int main() {
	int n; cin >> n;
	vector<int>a(n), b(n); for (auto&& x : a)cin >> x; for (auto&& x : b)cin >> x;
	int ans = 0;
	for (int i = 0; i < 30; i++) {
		sort(b.begin(), b.end(), cmp(1 << i));
		bool btg = false;
		for (int j = 0; j < n; j++) {
			btg ^= (b[j] >> i) & 1;
		}
		for (int j = 0; j < n; j++) {
			int v = (1 << i) - (a[j] % (1 << i)) - 1;
			int pos = upper_bound(b.begin(), b.end(), v, cmp(1 << i)) - b.begin();
			int pv = (a[j] >> i) & 1;
			bool tg = (pv ? pos & 1 : (n - pos) & 1);
			tg ^= btg;
			if (tg)ans ^= (1 << i);
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	string s;
  	cin>>s;
  
  if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]){
  	cout<<"Bad"<<endl;
  }
  
  else{
  	cout<<"Good"<<endl;
  }
}

Measured memory_bytes: 256
N, Y = gets.split.map(&:to_i)

score = [-1, -1, -1]
(N + 1).times do |a|
  (N + 1).times do |b|
    c = N - a - b
    if c >= 0 && c <= N && Y == 10000 * a + 5000 * b + 1000 * c
    score = [a, b, c]
    end
  end
end
ans = "#{score[0]} #{score[1]} #{score[2]}"
puts ans
 

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};

int n,m,s,t;
vector<vector<int>>uv(100010);
vector<vector<ll> >dist(100010,vector<ll>(3,-1));
queue<pair<int,int> >q;

ll bfs()
{
    dist[s][0]=0;
    q.push({s,0});
    while(!q.empty())
    {
        pair<int,int>cur=q.front();q.pop();
        int now=cur.first;int b=cur.second;
        for(auto next:uv[now])
        {
            int bb=(b+1)%3;
            if(dist[next][bb]==-1)
            {
                dist[next][bb]=dist[now][b]+1;
                q.push({next,bb});
            }
        }
    }
    if(dist[t][0]==-1)return -1;
    else return dist[t][0]/3;
}

int main()
{
    cin>>n>>m;
    uv.resize(n);
    REP(i,m){int u,v;cin>>u>>v;u--;v--;uv.at(u).push_back(v);}
    cin>>s>>t;s--;t--;
    cout<<bfs()<<endl;
}

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

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

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
signed main()
{
    int n;
    cin>>n;
    int a[n],b[n],c[n-1];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    for(int i=0;i<n-1;i++)cin>>c[i];
    int tot=b[a[0]-1];
    for(int i=1;i<n;i++)
    {
        tot+=b[a[i]-1];
        if(a[i-1]+1==a[i])
        tot+=c[a[i-1]-1];
    }
    cout<<tot<<endl;
}

Measured memory_bytes: 256
import math

N, K = map(int, input().split())
H = list(map(int, input().split()))
INF = math.inf

dp = [INF]*N
dp[0] = 0

for i in range(N-1):
  for j in range(1, min(K+1, N-i)):
    dp[i+j] = min(dp[i+j], dp[i] + abs(H[i+j] - H[i]))

print(dp[-1])

Measured memory_bytes: 85756
import sys
readline = sys.stdin.readline

N,X,M = map(int,readline().split())
nex = [0] * M
sums = [0] * M

for i in range(M):
  nex[i] = i * i % M
  sums[i] = i

ans = 0
while N:
  if N & 1:
    ans += sums[X]
    X = nex[X]
  sums = [sums[i] + sums[nex[i]] for i in range(M)]
  nex = [nex[nex[i]] for i in range(M)]
  N >>= 1
  
print(ans)

Measured memory_bytes: 151684
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h, w; cin >> h >> w;
  vector<string> ss(h);
  vector<bool> hh(h, false), ww(w, false);
  for (int i = 0; i < h; i++){
    string s; cin >> s; ss[i] = s;
    for (int j = 0; j < w; j++) {
      if (s[j] == '#') {
        hh[i] = true; ww[j] = true;
      }
    }
  }
  for (int i = 0; i < h; i++){
    if (!hh[i]) continue;
    for (int j = 0; j < w; j++) {
      if (!ww[j]) continue;
      cout << ss[i][j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N = int(input())
  ans = 0
  if N==1:
    ans = 0
  else:
    ans = (N-1) * N//2
  print(ans)
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
<?php
list($H, $W, $A, $B) = ints();
for($i = 0; $i < $H; $i++){
  for($j = 0; $j < $W; $j++){
    echo (($j < $A) + ($i < $B)) % 2;
  }
  echo "\n";
}

function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

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

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

    std::vector<int> A(N);
    int A_total = 0;
    for (int i = 0; i < N; i++)
    {
        std::cin >> A[i];
        A_total += A[i];
    }
    // A_total = std::accumulate(A.begin(), A.end(), 0);  // 合計はこれでも算出できる

    
    double th = (double)A_total / (4 * (double)M);
    std::sort(A.begin(), A.end(), std::greater<int>());
    // if (A[M-1] >= th)
    //     std::cout << "Yes" << std::endl;
    // else
    //     std::cout << "No" << std::endl;

    bool flag = true;
    for (int i = 0; i < M; i++)
    {
        if ((float)A[i] < th)
        {
            flag = false;
            break;
        }
    }

    if (flag == true)
        std::cout << "Yes" << std::endl;
    else if (flag == false)
        std::cout << "No" << std::endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static int mod =1000000007;
	public static void main(String[] args) {
		int N=sc.nextInt();
		int D=sc.nextInt();
		int X=sc.nextInt();
		int ans=X;
		for(int i=0;i<N;i++) {
			int A=sc.nextInt();
			int B=1;
			while(B<=D) {
				ans++;
				B+=A;
			}
		}
		p(ans);
		//System.out.println(me);
		
	}

	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
}
	


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

main(){
	set<int> x{1,3,5,7,8,10,12},y{4,6,9,11},z{2};
  	int a, b;
	cin >>a>>b;
  	
  	if (x.count(a) == 1 && x.count(b) == 1){
      	cout << "Yes" << endl;}
  	else if (y.count(a) == 1 && y.count(b) == 1){
      	cout << "Yes" << endl;
    	}
  	else if (z.count(a) == 1 && z.count(b) == 1){
      	cout << "Yes" << endl;
    	}
 	else {cout << "No" << endl;}
  	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

const int MAX_N=100000;
int N,K;
ll h[MAX_N+1];
ll dp[MAX_N+1];

void solve(){
    dp[1]=0;
    dp[2]=abs(h[1]-h[0]);
    for(int i=3;i<=N;i++){
        dp[i]=dp[i-1]+abs(h[i-1]-h[i-2]);
        for(int j=2;j<=K;j++){
            if(i-j>=1) dp[i]=min(dp[i],dp[i-j]+abs(h[i-j-1]-h[i-1]));
        }
    }
    cout<<dp[N]<<endl;
}

int main(){
    cin>>N>>K;
    rep(i,N) cin>>h[i];
    solve();
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class Main {

    public static class Node {
        int index;
        long step;
        public Node(int index, long step) {
            this.index = index;
            this.step = step;
        }
    }

    public static void solve(int n, long[] steps, int[] visited1, int [] visited2, int[] visited3, int s, int t, Map<Integer, Set<Integer>> graph ) {
        BlockingQueue<Node> queue = new LinkedBlockingQueue<>();
        queue.add(new Node(s, 0L));
        visited1[s] = 1;
        while (!queue.isEmpty()) {
            Node node = queue.poll();
            long step = node.step;
            int current = node.index;
           // System.out.println("current: " + current);

            Set<Integer> next1s = graph.getOrDefault(current, new HashSet<>());
            Set<Integer> canNext1s = new HashSet<>();
            for (Integer next1 : next1s) {
                if (visited2[next1] == 0) {
                    canNext1s.add(next1);
                    visited2[next1] = 1;
                }
            }
            Set<Integer> canNext2s = new HashSet<>();
            for (Integer next2 : canNext1s) {
                Set<Integer> next3s = graph.getOrDefault(next2, new HashSet<>());
                for (Integer next3 : next3s) {
                    if (visited3[next3] == 0) {
                        canNext2s.add(next3);
                        visited3[next3] = 1;
                    }
                }
            }
            for (Integer next3: canNext2s) {
                Set<Integer> next4s = graph.getOrDefault(next3, new HashSet<>());
                for (Integer next4 : next4s) {
                    if (visited1[next4] == 0) {
                        visited1[next4] = 1;
                        queue.add(new Node(next4, step + 1));
                        steps[next4] = step + 1;
                    }
                }
            }


        }


    }
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        Map<Integer, Set<Integer>> graph = new HashMap<>();
        for (int i = 1; i <= m; ++i) {
            int u = scanner.nextInt();
            int v = scanner.nextInt();
            Set<Integer> next = graph.getOrDefault(u, new HashSet<>());
            next.add(v);
            graph.put(u, next);
        }
        int s = scanner.nextInt();
        int t = scanner.nextInt();
        int [] visited1 = new int[n + 1];
        int [] visited2 = new int[n + 1];
        int [] visited3 = new int[n + 1];
        long[] steps = new long[n + 1];
        solve(n, steps, visited1, visited2, visited3, s, t, graph);
        if (steps[t] > 0) {
            System.out.println(steps[t]);
        } else {
            System.out.println(-1);
        }
    }

}


Measured memory_bytes: 132180
#include <iostream>
#include <cstdio>
#include <cmath>
#define N 100005
using namespace std;
int n, c, d, t[N], x[N], y[N];
int main() {
	cin>>n;
	for(int i=1; i<=n; i++) {
		scanf("%d%d%d", &t[i], &x[i], &y[i]);
		c = abs(t[i] - t[i-1]);
		d = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]);
		if(!(c>=d && (c-d)%2==0)) {puts("No"); return 0;}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

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

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;

void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    int sum=a+b+c;
    out(sum-max({a,b,c}));

}

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

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    const int MAX_V = 1000001;
    int prime[MAX_V],sum[MAX_V];
    int i,k,n,ans;
    for(i = 0; i < MAX_V; i ++){
        prime[i] = 1;
        sum[i] = 0;
    }
    prime[0] = 0;
    prime[1] = 0;
    for(i = 2; i * i < MAX_V; i ++){
        if(prime[i]){
            for(k = 2 * i; k < MAX_V; k += i){
                prime[k] = 0;
            }
        }
    }
    for(i = 2; i < MAX_V - 1; i ++){
        sum[i+1] = sum[i] + prime[i];
    }
    while(scanf("%d",&n) != EOF){
        ans = sum[n+1];
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 8404
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

const ll mod = 998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll A, B, C, D;
mint dp[3010][3010];
combination comb( 10000 );

int main() {
  std::cin >> A >> B >> C >> D;

  dp[A][B] = 1;

  repi( i, A, C+1 ) repi( j, B, D+1 ) {
    if( i == A && j == B )
      continue;

    dp[i][j] = dp[i-1][j]*j+dp[i][j-1]*i;
    dp[i][j] -= dp[i-1][j-1]*(i-1)*(j-1);
  }

  std::cout << dp[C][D].x << std::endl;

  return 0;
}

Measured memory_bytes: 74564
#include<iostream>
#include<cstdio>
#include<vector>
#include<utility>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<limits>
#include <bitset>      


#define LL long long
#define f first
#define s second
#define pb push_back
#define mp make_pair


using namespace std;

LL dp[102][100005];



int main(){

    int n, w;
    cin >> n >> w;

    int e[n+1], v[n+1];

    memset(dp, 0, sizeof dp);


    for(int i = 1; i <= n; i++){
        cin >> e[i] >> v[i];
      }
    

    for(int i = 1; i <= n; i++){
        for(int k = 1; k <= w; k++){
             if(k >= e[i])
                dp[i][k] = max(dp[i][k], dp[i-1][k-e[i]] + v[i]);
             
             dp[i][k] = max(dp[i][k], dp[i-1][k]);
            }
        } 
    


    cout << dp[n][w];



    return 0;
}


Measured memory_bytes: 80000
# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 01/08/2020

from sys import stdin, stdout
import sys
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007
sys.setrecursionlimit(100000)
n, m = iia()
dp = [-1] * (n + 1)
d = {}
for i in range(m):
    a, b = iia()
    d.setdefault(a, []).append(b)

def dfs(cur):
    if dp[cur] != -1:
        return dp[cur]
    t = 0
    for i in d.get(cur, []):
        t = max(1 + dfs(i), t)
    dp[cur] = t
    return dp[cur]

res = 0
for i in range(1, n + 1):
    res = max(res, dfs(i))
print(res)

Measured memory_bytes: 69080
n, k = map(int, input().split())
A = list(map(lambda x: int(x)-1, input().split()))
bit = k.bit_length()
table = [[0]*bit for _ in range(n)]
for i in range(n):
    table[i][0] = A[i]

for i in range(1, bit):
    for j in range(n):
        table[j][i] = table[table[j][i-1]][i-1]

ans = 0
for i in reversed(range(bit)):
    if (1 << i) <= k:
        k -= 1 << i
        ans = table[ans][i]
print(ans+1)


Measured memory_bytes: 202804
import io.StdIn.readLine
object Main extends App {
  val s = readLine
  println(solve(s))

  def solve(s: String) = {
    (for (ab <- 'a' to 'z') yield {
      val fs = s.split(ab)
      if (fs.isEmpty) 0 else fs.map(_.length).max
    }).min
  }
}


Measured memory_bytes: 25544
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;

int main(int argc, char* argv[])
{
    long a,b,c,d;
    scanf("%ld%ld%ld%ld", &a, &b, &c, &d);

    if(a*b>=c*d) {
        printf("%ld\n", a*b);
    }
    else {
        printf("%ld\n", c*d);
    }

    return 0;
}


Measured memory_bytes: 128
stdin.ReadLine()
|> fun x -> x.Split(' ')
|> Array.map int
|> fun x -> (x.[0], x.[1], x.[2], x.[3], x.[4])
|> fun (a, b, c, x, y) ->
  [1..(max x y)]
  |> List.fold (
    fun ret i ->
      a * (max (x - i) 0) +
      b * (max (y - i) 0) +
      c * i * 2
      |> min ret
  ) (a * x + b * y)
|> printfn "%d"


Measured memory_bytes: 16092
#include<stdio.h>
int main(void)
{	
	int S;
	scanf("%d",&S);
	int H = S/3600;
	int M = (S%3600)/60;
	int s1 = (S%3600)%60;

	printf("%d:%d:%d\n",H,M,s1);

	return 0;
} 

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define inf 1001001001
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
bool cal(int n) {
    int c = 0;
    for(int i=1; i<=n; i++) {
        if(n%i == 0) c++;
        if(c > 8) return false;
    }
    if(c == 8) return true;
    else return false;
}
int main(void) {
    int n; cin >> n;
    int cnt = 0;
    for(int i=1; i<=n; i+=2) {
        if(cal(i)) cnt++;
    }
    cout << cnt;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// ?????????????????\????????????
		Scanner sc = new Scanner(System.in);

		// ??????????????\??????????????°?????\???????????°
		int lin = sc.nextInt();
		int col = sc.nextInt();

		// ????¬???????????????????
		int[][] grid = new int[lin + 1][col];

		// ????¬???????????????????lft:?????????????????????rgt:?????????????????????
		int lft;
		int rgt;

		// ??\??????????????°?????????????????\??????
		for (lft = 0; lft <= lin; lft++) {

			for (rgt = 0; rgt < col; rgt++) {

				grid[lft][rgt] = sc.nextInt();

			}
		}

		// ????¨??????\?????????????????????
		int[] sum = new int[lin];

		// ???????????????
		for (lft = 0; lft < lin; lft++) {

			for (rgt = 0; rgt < col; rgt++) {

				sum[lft] += grid[lft][rgt] * grid[lin][rgt];

			}
			System.out.println(sum[lft]);
		}
		sc.close();
	}
}

Measured memory_bytes: 40456
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	int mx = 0;
	for (int& i : a) {
		cin >> i;
		mx = max(mx, i);
	}
	int dis = INT32_MAX, num = 0;
	for (int i : a) {
		if (mx > i && abs(mx / 2 - i) < dis) {
			num = i;
			dis = abs(mx / 2 - i);
		}
	}
	cout << mx << " " << num << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll, ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // Emily <3
  int n;
  cin >> n;
  VI heights(n);
  forx(i,n) cin >> heights[i];
  VI cost(n, INF); // cost[i] is min cost to reach i
  int jumpMax = 2;
  cost[0] = 0;
  for(int i = 1; i < n; ++i) {
    for(int j = 1; j <= jumpMax; ++j) {
      int o = i-j;
      if (o >= 0) {
        cost[i] = min(cost[i], cost[o] + abs(heights[o] - heights[i]));
      }
    }
  }
  cout << cost[n-1];
  
  cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl;
  return 0;
}



Measured memory_bytes: 1024
arr = []

while true
  h, w = gets.split(" ").map(&:to_i)
  break if h.zero? && w.zero?
  arr << [ h, w ]
end

value = "#"
arr.each do |array|
  str = ""
  array[0].times do |ind1|
    ind1 += 1
    array[1].times do |ind2|
      ind2 += 1
      if value == "#"
        if ind2.odd?
          str += "#"
        else
          str += "."
        end
      else
        if ind2.odd?
          str += "."
        else
          str += "#"
        end
      end
    end

    if value == "#"
      value = "."
    else
      value = "#"
    end
    str += "\n"
  end
  value = "#"
  puts str
  puts "\n"
end

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

#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define inf 1e18
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 1000
// <<fixed << setprecision(9)

void err()
{
	cout<<"NO\n";
	exit(0);
}

int main()
{
	int n,i;
	boost;
	
	cin>>n;
	int dp[n],ht[n];
	rep(i,0,n)cin>>ht[i];
	
	dp[0]=0;
	dp[1]=abs(ht[1]-ht[0]);
	rep(i,2,n)
	{
		dp[i]=min(abs(ht[i]-ht[i-1]) + dp[i-1],abs(ht[i]-ht[i-2]) + dp[i-2]);
	}
	cout<<dp[n-1];
	
}



Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
	String S = sc.next();
   
	if(S.charAt(2)==S.charAt(3) && S.charAt(4)==S.charAt(5)){
      System.out.println("Yes");
    }else{
		System.out.println("No");
    }
}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define fasterthanlight ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define test int T; cin>>T; while(T--)
#define endl "\n"
#define int long long
#define vi vector<int>
#define pb push_back
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define hi "visited\n" //sasta debugging
using namespace std;

//author::@whohet-->Het Patel

signed main()
{
	fasterthanlight;
	int x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	int z=(x/d);
	if(z<k)
	{
		k-=z;
		x-=z*d;
		if(k%2==0)
		{
			cout<<abs(x);
		}
		else
			{
				cout<<abs(x-d);
			}
	}
	else
		cout<<abs(x-k*d);

	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}

Measured memory_bytes: 3612
//bcw0x1bd2 {{{
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define SZ(x) ((int)((x).size()))
#define ALL(x) begin(x),end(x)
#define REP(i,x) for (int i=0; i<(x); i++)
#define REP1(i,a,b) for (int i=(a); i<=(b); i++)

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

#ifdef DARKHH
#define FILEIO(name)
#else
#define FILEIO(name) \
  freopen(name".in", "r", stdin); \
  freopen(name".out", "w", stdout);
#endif

#ifdef DARKHH
template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
  int c=0;
  while ( *s!=',' || c!=0 ) {
    if ( *s=='(' || *s=='[' || *s=='{' ) c++;
    if ( *s==')' || *s==']' || *s=='}' ) c--;
    cerr<<*s++;
  }
  cerr<<"="<<head<<", ";
  _dump(s+1,tail...);
}

#define dump(...) do { \
  fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
  _dump(#__VA_ARGS__, __VA_ARGS__); \
} while (0)

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
  s<<"[";
  for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
  s<<"]";
  return s;
}

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T,N> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
#else
#define dump(...)
#endif
// }}}
// Let's Fight! ~OAO~~

int N,M;
string mp[514];
string red[514],blue[514];

int main() {
  IOS;
  cin >> N >> M;
  REP(i,N) cin >> mp[i];
  REP(i,N) {
    red[i] = blue[i] = mp[i];
    red[i][0] = '#';
    blue[i][M-1] = '#';
  }
  REP(i,N) {
    if (i % 2 == 0) {
      REP1(j,1,M-2) red[i][j] = '#';
    } else {
      REP1(j,1,M-2) blue[i][j] = '#';
    }
  }


  REP(i,N) cout << red[i] << endl;
  cout << endl;

  REP(i,N) cout << blue[i] << endl;
  cout << endl;

  REP(i,N) REP(j,M) {
    if (mp[i][j] == '.') {
      if ((red[i][j] == '#' and blue[i][j] == '#')) {
        dump(i,j);
      }
      assert(!(red[i][j] == '#' and blue[i][j] == '#'));
    } else {
      if (!(red[i][j] == '#' and blue[i][j] == '#')) {
        dump(i,j);
      }
      assert((red[i][j] == '#' and blue[i][j] == '#'));
    }
  }

  return 0;
}



Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int LEN = 1e5+100;
int ar[LEN];
int main()
{
   int n;
   while(cin>>n)
   {
       memset(ar,0,sizeof(ar));
       int  a;
       for(int i = 0; i < n; ++i)
       {
           scanf("%d",&a);
           if(a>0)
            ar[a-1]++;
           ar[a]++;
           ar[a+1]++;
       }
       int Max = 0;
       for(int i = 0;i < LEN; ++i)
        Max = max(ar[i],Max);
       printf("%d\n",Max);

   }



    return 0;
}


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

int main() {
    int k, t; cin >> k >> t;
    int sum = 0;
    int maxa = 0;
    for (int i=0; i<t; ++i) {
        int a; cin >> a;
        sum += a;
        maxa = max(maxa, a);
    }
    cout << max(0, maxa - (sum - maxa) - 1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#define INF (long)1e9
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	for(int bit = 0; bit < (1<<3); bit++)
	{
		int res = s[0] - '0';
		for(int i = 0; i < 3; i++)
		{
			if(bit & (1<<i))
				res += s[i + 1] - '0';
			else
				res -= s[i + 1] - '0';
		}
		if(res == 7)
		{
			cout << s[0];
			for(int i = 0; i < 3; i++)
			{
				if(bit & (1<<i))
					cout << '+';
				else
					cout << '-';
				cout << s[i + 1];
			}
			cout << "=7" << endl;
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


fn main() {
    let a:u64 = read();
    print!("{}", a + a*a + a*a*a);
}


Measured memory_bytes: 2108
#include <iostream>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin >> W >> H >> x >> y >> r;
	if(W<x+r||0>x-r||H<y+r||0>y-r){
		cout << "No" << endl;
	}else {
		cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 3100
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif
int N;
vi C;
vvi es;
vl ns;
int idx;
void dfs(int n) {
    if (n >= N) return;
    if (ns[n] >= 0) return;

    ns[n] = C[idx];
    idx++;

    for(int nn : es[n]) {
        dfs(nn);
    }
}

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

    cin >> N;
    vi A(N-1), B(N-1); 
    REP(i, N-1) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }

    C = vi(N); REP(i, N) cin >> C[i];
    sort(C.begin(), C.end(), greater<int>());

    es = vvi(N);
    REP(i,N-1){
        es[A[i]].push_back(B[i]);
        es[B[i]].push_back(A[i]);
    }

    idx = 0;
    ns = vl(N, -1);
    dfs(0);

    ll ans = 0;
    FOR(i,1,N) ans += ns[i];
    cout << ans << endl;

    cout << ns[0];
    FOR(i, 1, N) cout << " " << ns[i];
    cout << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <queue>

using namespace std;

int main(){
    int N, M;
    while(cin >> N >> M){
        priority_queue<int> qu;
        for(int i=0;i<N;i++){
            int A; cin >> A;
            qu.push(A);
        }
        for(int i=0;i<M;i++){
            int t = qu.top(); qu.pop();
            qu.push(t/2);
        }
        long long res = 0;
        while(!qu.empty()){
            res += qu.top();
            qu.pop();
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 892