akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int dp[100050];

int main () {
  int h, n;
  cin >> h >> n;
  vi a(n), b(n);
  rep(i,n) {
    cin >> a[i] >> b[i];
  }

  rep(i,100050) dp[i] = INF;
  dp[0] = 0;
  rep(i,50000) {
    rep(j,n) {
      if (dp[i] == INF) continue;
      chmin(dp[i+a[j]], dp[i]+b[j]); 
    }
  }

  int ans = INF;
  for (int i = h; i <= h+10000; ++i) {
    chmin(ans, dp[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
typedef struct Pos{
	int x,y,h;
}O;
int abs(int x){
	return (x>=0) ?  x:-x; 
}
int max(int a,int b){
	return (a>b) ? a:b;
}
int main()
{
	int n;
	while(scanf("%d", &n)!=EOF){
		O pos[n];
		int minx = 101 ,miny = 101, maxx = -1, maxy = -1, maxh = -1;
		for(int i = 0; i < n; i++){
			scanf("%d%d%d", &pos[i].x, &pos[i].y, &pos[i].h);
			if(pos[i].x < minx) minx = pos[i].x;
			if(pos[i].y < miny) miny = pos[i].y;
			if(pos[i].x > maxx) maxx = pos[i].x;
			if(pos[i].y > maxy) maxy = pos[i].y;
			if(pos[i].h > maxh) maxh = pos[i].h;
		}
		int dis = maxx - minx + maxy - miny,flag = 0;
		O center;
		for(int k = 0; k <= dis && !flag; k++)
		{
			center.h = maxh + k;
			for(int i = minx; i <= maxx && !flag; i++)
				for(int j = miny; j <= maxy && !flag; j++){
					center.x = i; center.y = j;
					int a = 0;
					for(int d = 0; d < n; d++){
						if(max(center.h-abs(i - pos[d].x)-abs(j - pos[d].y),0) == pos[d].h){
							a++;
						}
						else break;
					}
					if(a == n) {
						flag = 1;
					}
				}
		}
		printf("%d %d %d\n", center.x, center.y, center.h);
	}
}

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

int main(int argc, char const* argv[]) {
	int A, B, C, D;
	scanf("%d %d %d %d", &A, &B, &C, &D);
	if (A + B > C + D) printf("Left\n");
	else if (A + B < C + D) printf("Right\n");
	else printf("Balanced\n");
	return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


struct mint {
    ll x;
    mint(ll x=0):x(x%MOD){}
    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;
    }
};

int main() {
    int n;
    string s;
    cin >> n >> s;
    sort(all(s));
    vpair rl;
    rl.emplace_back(s[0], 1);
    srep(i, n, 1) {
        if (s[i] == rl.back().fi) rl.back().se++;
        else rl.emplace_back(s[i], 1);
    }
    mint ans = 1;
    for (auto x : rl) {
        ans *= x.se + 1;
    }
    ans -= 1;

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

Measured memory_bytes: 512
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N, M;
ll A, B;
vector<ll> adj[100005];
ll dp[100005];

ll dfs(int node) {
	ll &ans = dp[node];
	if(ans != -1) {
		return ans;
	}
	ans = 0;
	for(int i = 0; i < adj[node].size(); i++) {
		ans = max(ans, 1 + dfs(adj[node][i]));
	}
	return ans;
}

int main() {
	scanf("%lld %lld", &N, &M);
	for(int i = 0; i < M; i++) {
		scanf("%lld %lld", &A, &B);
		adj[A].push_back(B);
	}
	memset(dp, -1, sizeof(dp));
	ll ans = 0; 
	for(int i = 0; i <= N; i++) {
		ans = max(ans, dfs(i));
	}
	printf("%lld\n", ans);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

int main(){

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

	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	
	long long int a;
	float b;
	cin>>a>>b;

	long long int x = (long long int) ((b + 0.005) * 100) * a;
	
	cout<< x / 100 <<endl;
	
	return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int K;

long long dfs(int d, vector<int> a, vector<int> b) {
  if (d == -1) {
    long long ret = 0;
    for (int i = 0; i < a.size(); i++) {
      ret += b[i];
    }
    return ret;
  }
  if (~K >> d & 1) {
    vector<int> aa, bb;
    for (int i = 0; i < a.size(); i++) {
      if (~a[i] >> d & 1) {
        aa.push_back(a[i]);
        bb.push_back(b[i]);
      }
    }
    return dfs(d - 1, aa, bb);
  } else {
    long long z = 0;
    for (int i = 0; i < a.size(); i++) {
      if (~a[i] >> d & 1) {
        z += b[i];
      }
    }
    return max(dfs(d - 1, a, b), z);
  }
}

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

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

  cout << dfs(29, a, b) << endl;
}


Measured memory_bytes: 48244
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
    }

    let mut g = vec![vec![0; n]; n];

    odd_cycle(0, n, 1, &mut g);

    // let ans = g.iter().map(|e| e.iter().max().unwrap()).max().unwrap();
    // println!("{}", ans);

    for i in 0..n - 1 {
        for j in i + 1..n {
            if j != i + 1 {
                print!(" ");
            }
            print!("{}", g[i][j]);
        }
        println!("");
    }
}

fn odd_cycle(l: usize, r: usize, col: usize, g: &mut Vec<Vec<usize>>) {
    if r - l == 1 {
        return;
    }
    if r - l == 2 {
        g[l][r - 1] = col;
        g[r - 1][l] = col;
        return;
    }

    let m = (l + r) / 2;

    for i in l..m {
        for j in m..r {
            g[i][j] = col;
            g[j][i] = col;
        }
    }

    odd_cycle(l, m, col + 1, g);
    odd_cycle(m, r, col + 1, g);
}


Measured memory_bytes: 6652
<?php

$s = trim(fgets(STDIN));
$s = explode(' ',$s);
$a = $s[0];
$b = $s[1];
$c = $s[2];

if ($a < $b && $b < $c) {
  echo 'Yes' . PHP_EOL;
} else {
  echo 'No' . PHP_EOL;
}
exit;

?>

Measured memory_bytes: 15272
N, M = map(int,input().split())
A_B = [[0] for i in range(M)]
for i in range(N):
  A, B = map(int,input().split())
  if A <= M:
    A_B[A-1].append(-B)
  
import heapq
q = []
ans = 0
heapq.heapify(q)

for i in range(M):
  for j in A_B[i]:
    heapq.heappush(q, j)
  ans -= heapq.heappop(q)
  
print(ans)


Measured memory_bytes: 69024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];

  sort(h.begin(), h.end(), greater<ll>());
  ll ans = INF;
  rep(i, n-k+1) {
    chmin(ans, h[i] - h[i+k-1]);
  }
  cout << ans << endl;


  return 0;
}


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


int main(){
	vector<string> s(3);
	for(int i=0;i<3;i++) cin>>s[i];
	string ret = "";
	for(int i=0;i<3;i++) ret += s[i][i];
	cout<<ret<<endl;
	return 0;
}
	

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

class point {
public:
	double x, y;
	point() {}
	point(double a, double b) { x = a; y = b; }
	point operator +( point p ) { return point( x + p.x, y + p.y ); }
	point operator -( point p ) { return point( x - p.x, y - p.y ); }
	point operator *( double a ) { return point( x * a, y * a ); }
	point operator /( double a ) { return point( x / a, y / a ); }
};

double dot( point p1, point p2 ) { return p1.x * p2.x + p1.y * p2.y; }
double norm( point p ) { return p.x * p.x + p.y * p.y; }

int main()
{
	point c;
	double r;
	cin >> c.x >> c.y >> r;
	int q;
	cin >> q;
	for( int i = 0; i < q; i++ ) {
		point p1, p2;
		cin >> p1.x >> p1.y >> p2.x >> p2.y;
		point base = p2 - p1;
		double rr = dot( c - p1, base ) / norm( base );
		point pr = p1 + base * rr;
		point e = (p2 - p1) / sqrt( norm( p2 - p1 ) );
		double b = sqrt( r * r - norm( pr - c ) );
		point cp1 = pr + e * b;
		point cp2 = pr - e * b;
		if( cp1.x > cp2.x ) swap( cp1, cp2 );
		else if( cp1.x == cp2.x && cp1.y > cp2.y ) swap( cp1, cp2 );

		cout << fixed << setprecision(10) << cp1.x << " " << cp1.y  << " " << cp2.x << " " << cp2.y << endl;
	}
}



Measured memory_bytes: 3292
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  int *A,*B;

  int C[VMAX+1];
  int n,i,j;
  scanf("%d",&n);

  A=malloc(sizeof(int)*n+1);
  B=malloc(sizeof(int)*n+1);

  for(i=0;i<=VMAX;i++) C[i]=0;

  for(i=0;i<n;i++){
    scanf("%d",&A[i+1]);
    C[A[i+1]]++;
  }

  for(i=1;i<=VMAX;i++) C[i]+=C[i-1];

  for(j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }


  for(i=1;i<=n;i++){
    if(i>1)printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 16276
#include <iostream>
#include <string>
#include <algorithm>

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

using namespace std;

int N, money;

int main() {
	cin >> N >> money;
	for (int i = 0; i <= N; i++) {//10000
		int num = money;
		if (num >= i * 10000) {
			num -= i * 10000;
			for (int j = 0; j <= N - i; j++) {
				if (num - j * 5000 - (N - i - j) * 1000 == 0) {
					cout << i << ' ' << j << ' ' << N - i - j << endl;
					return 0;
				}
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> d(n), x(n);
  for(int i = 0; i < n; i++){
    cin >> d.at(i);
    x.at(i) = d.at(i);
  }
  
  if(d.at(0) != 0){
    cout << 0 << "\n";
    return 0;
  }
  
  sort(x.begin(), x.end());
  
  if(n > 1){
    if(x.at(1) == 0){
      cout << 0 << "\n";
      return 0;
    }
  }
  
  vector<long long> y;
  long long count = 1;
  for(int i = 1; i < n; i++){
    if(x.at(i - 1) == x.at(i)){
      count++;
    }
    else if(x.at(i - 1) + 1 == x.at(i)){
      y.push_back(count);
      count = 1;
    }
    else{
      cout << 0 << "\n";
    return 0;
    }
  }
  y.push_back(count);
  
  long long ans = 1;
  for(int i = 1; i < (int) y.size(); i++){
    long long a, b;
    a = y.at(i - 1);
    b = y.at(i);
    for(int j = 1; j <= b; j++){
      ans *= a;
      ans = ans % 998244353;
    }
  }
  
  cout << ans << "\n";
}

Measured memory_bytes: 2168
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

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

    int ans = -1;
    for(int i=1; i<=2000; i++){
        if(floor(0.08*i) == A && floor(0.1*i) == B){
            ans = i; break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
// author:  Harsh Nema
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;

//ll modexp(ll x, ll y, ll p)
//{
//	ll res = 1;
//	x = x % p;
//	while (y > 0)
//	{
//		if (y & 1)
//			res = (res * x) % p;
//		y = y >> 1;
//		x = (x * x) % p;
//	}
//	return res;
//}

//ll mulmod(ll a, ll b,ll m)
//{
//	return ((a % m) * (b % m)) % m;
// }

// ll sub_mod(ll a, ll b, ll m){
//    if (a >= b)
//        return a - b;
//    else
//        return m - b + a;
// }

// ll add_mod(ll a, ll b){
//    if (0 == b)
//        return a;

//    b = mod - b;
//    if (a >= b)
//        return a - b;
//    else
//        return mod - b + a;
// }

// ll gcd(ll a, ll b)
// {
// 	if (a == 0)
// 		return b;
// 	else
// 		return gcd(b % a, a);
// }

// ll modInv(ll a)
// {
//     ll g = gcd(a, mod);
//     if (g != 1)
//         return -1;
//     else
//         return modexp(a, mod-2, mod);
// }

int main()
{
	fastio;
    ll n=0;
    cin>>n;
    double x[n],y[n];
    vector<double>d;
    for(ll i=0;i<n;++i){
        cin>>x[i]>>y[i];
    }
    for(ll i=0;i<n-1;++i){
        for(ll j=i+1;j<n;++j){
            double di=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
            d.pb(di);
        }
    }
    double ans=0;
    for(auto i:d)
        ans+=i;
    ans=2*ans/n;
    printf("%.10lf",ans);
}


Measured memory_bytes: 256
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces
gi = lambda : list(map(int,input().split()))
n, = gi()
l = gi()
ans = 0
cur = 1
for k in range(1, n):
	if l[k] <= l[k - 1]:
		cur += 1
	else:
		ans = max(ans, cur - 1)
		cur = 1
ans = max(ans, cur - 1)
print(ans)

Measured memory_bytes: 14252
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

int n, m;
struct statement{
    int l, r, d;
}s[200005];
struct Edge{
    int u, v, w;
    int next;
}edge[400005];
int last[100005], x[100005], vis[100005];
int tot;
void addedge(int u, int v, int w) {
    tot++;
    edge[tot].u = u;
    edge[tot].v = v;
    edge[tot].w = w;
    edge[tot].next = last[u];
    last[u] = tot;
}

bool bfs(int s) {
    queue < int > q;
    q.push(s);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int k = last[u]; k != -1; k = edge[k].next) {
            Edge e = edge[k];
            if (!vis[e.v]) {
                vis[e.v] = 1;
                x[e.v] = x[u] + e.w;
                q.push(e.v);
            } else {
                if (x[e.v] != x[u] + e.w) return false;
            }
        }
    }
    return true;
}


int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i <= n; i++) last[i] = -1;
    for (int i = 1; i <= m; i++) {
        scanf("%d%d%d", &s[i].l, &s[i].r, &s[i].d);
        addedge(s[i].l, s[i].r, s[i].d);
        addedge(s[i].r, s[i].l, -s[i].d);
    }
    bool flag = true;
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            flag = bfs(i);
        }
        if (!flag) break;
    }
    if (flag) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 10368
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define endl "\n"
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    cins(s);
    cins(t);
    int ans=0;
    for(int i=0; i<3; i++)
        if(s[i]==t[i])
            ans++;

    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
   int a,b;
   cin >> a >> b;
   int sum,dif,pro;
   sum = a + b;
   dif = a - b;
   pro = a * b;
   if(sum >= dif && sum >= pro){
       cout << sum << endl;
   }else if(dif > sum && dif > pro){
       cout << dif << endl;
   }else{
       cout << pro << endl;
   }

}

Measured memory_bytes: 256
//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 pb  push_back
#define mp make_pair
#define ll long long
#define pr pair<int, int> 
#define vpr vector<pr> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define all(n) n.begin(),n.end()
#define Test printf("Case %d: ",tc++);
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
const int mod = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;

int solve() 
{
	//happy coding

	int n;
	cin>>n;
	ll sum = 0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			int c = __gcd(i,j);
			for(int k=1;k<=n;k++){
				sum+=(__gcd(c,k));
				//sum+=1;
			}
		}
	}	
	cout<<sum<<endl;

	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

Measured memory_bytes: 3632
#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 = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){ 
    int h, w, a, b; cin >> h >> w >> a >> b;
    string s, t;
    rep(i, w - a){
        s += "0"; t += "1";
    }
    rep(i, a){
        s += "1"; t += "0";
    }

    rep(i, b) cout << s << ln;
    rep(i, h - b) cout << t << ln;
}

Measured memory_bytes: 1280
N, W = list(map(int, input().split()))
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(1, N+1):
    w, v = list(map(int, input().split()))
    for lim_w in range(W+1):
        if lim_w - w < 0:
            dp[i][lim_w] = dp[i-1][lim_w]
            continue
        dp[i][lim_w] = max(dp[i-1][lim_w-w] + v, dp[i-1][lim_w])

print(max(dp[N]))


Measured memory_bytes: 171400
#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()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n;
	cin >> n;
	vector<string> s(n);
	rep(i,n) cin >> s[i];
	vector<int> v(26);
	rep(j, s[0].size()) v[(int) (s[0][j] - 'a')]++;
	for (int i = 1; i < n; i++) {
		vector<int> u(26);
		rep(j, s[i].size()) u[(int) (s[i][j] - 'a')]++;
		rep(j, 26) {
			v[j] = min(v[j], u[j]);
		}
	}
	rep(i,26) {
		rep(j,v[i]) {
			cout << (char) (i + 'a');
		}
	}
	cout << endl;
}

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

Measured memory_bytes: 3568
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll A, B;
  cin >> A >> B;

  rep (i, 100000) {
    ll foo = i * 0.08;
    ll bar = i * 0.1;
    if (foo == A and bar == B) {
      cout << i << endl;
      return;
    }
  }

  cout << -1 << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N , a , b , c , d;
  cin >> N;
  a = N / 1000;
  b = N % 1000 / 100;
  c = N % 100 / 10;
  d = N % 10;
  if ((a == b && b == c) || (b == c && c == d)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n = int(input())

balls = list(map(int, input().split()))

a = [0 for i in range(n)]

for ball in balls:
    a[ball-1] += 1

b = list(map(lambda x: x *(x-1) // 2, a))

c = sum(b)

for ball in balls:
    print(c - a[ball-1] + 1)


Measured memory_bytes: 26012
m,d=map(int,input().split())
count = 0

if d >= 22:

    for mm in range(1,m+1,1):
        
        for dd in range (22,d+1):
            dd = str(dd)
            d10 = int(dd[0])
            d1 = int(dd[1])
            
            if d1>=2 and mm == d1*d10 :
                count +=1
print(count)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int mx = 100005;
int n, k, a[105];
bool used[mx], win[mx];
int solve(int m){
    if(used[m]) return win[m];
    used[m] = true;
    for(int i = 0; i < n; i++){
        if(m - a[i] >= 0 && !solve(m - a[i])){
            return win[m] = true;
        }
    }
    return false;
}
int main(){
    scanf("%d%d", &n, &k);
    for(int i = 0; i < n; i++) scanf("%d", a+i);
    puts(solve(k) ? "First" : "Second");
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007


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

    int N, H; cin >> N >> H;
    vi a(N), b(N);
    rep(i, N) cin >> a[i] >> b[i];
    
    int ans = 0;
    ll sum = 0;
    if (N==1) {
        sum += b[0];
        ans++;
        if (sum < H) {
            ans += ((ll)H - sum + (a[0]-1)) / a[0];
        }
    } else {
        sort(all(a), greater<int>());
        sort(all(b), greater<int>());
    
        for (int i = 0; i < N; i++) {
            if (b[i] > a[0]) {
                sum += b[i];
                ans++;
                if (sum >= H) break;
            } else {
                break;
            }
        }
        if (sum < H) {
            ans += ((ll)H - sum + (a[0]-1)) / a[0];
        }
    }

    cout << ans << endl;
}


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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  ll x, k, d;
  cin >> x >> k >> d;

  x = abs(x);

  ll ans = -1;
  if (cpp_int(k) * cpp_int(d) > cpp_int(x)) {
    ll cnt = x / d;
    x %= d;
    k -= cnt;
    if (k % 2) {
      ans = d - x;

    } else {
      ans = x;
    }
  } else {
    ans = x - k * d;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3656
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <climits>
using namespace std;

int main() {
    int z,x,y,a1,a2,a3,b1,b2,b3;
    vector<vector<int>>c(4,vector<int>(4));
    for(int i=1;i<4;i++){
        for(int j=1;j<4;j++){
            cin >> c[i][j];
        }
    }
    if(c[1][1]+c[2][2]+c[3][3]==c[3][1]+c[2][2]+c[1][3]){
        z=c[1][1]+c[2][2]+c[3][3];
    }else{
        cout << "No";
        return 0;
    }
    for(int i=0;i<=z;i++){
        x=i;
        y=z-i;
        if((c[1][1]+c[1][2]+c[1][3]-y)%3==0 && (c[2][1]+c[2][2]+c[2][3]-y)%3==0 && (c[3][1]+c[3][2]+c[3][3]-y)%3==0){
            a1=(c[1][1]+c[1][2]+c[1][3]-y)/3;
            a2=(c[2][1]+c[2][2]+c[2][3]-y)/3;
            a3=(c[3][1]+c[3][2]+c[3][3]-y)/3;
        }else{
            continue;
        }
        if((c[1][1]+c[2][1]+c[3][1]-x)%3==0 && (c[1][2]+c[2][2]+c[3][2]-x)%3==0 && (c[1][3]+c[2][3]+c[3][3]-x)%3==0){
            b1=(c[1][1]+c[2][1]+c[3][1]-x)/3;
            b2=(c[1][2]+c[2][2]+c[3][2]-x)/3;
            b3=(c[1][3]+c[2][3]+c[3][3]-x)/3;
        }else{
            continue;
        }
        if(c[1][1]==a1+b1 && c[1][2]==a1+b2 && c[1][3]==a1+b3 && c[2][1]==a2+b1 && c[2][2]==a2+b2 && c[2][3]==a2+b3 && c[3][1]==a3+b1 && c[3][2]==a3+b2 && c[3][3]==a3+b3){
            cout << "Yes";
            return 0;
        }else{
            continue;
        }
    }
    cout << "No";
}

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

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

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

    cout << (h+a-1)/a << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int l[100010];
int r[100010];

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

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  l[0]=a[0];
  for(int i=1;i<n;i++){
    l[i]=gcd(l[i-1],a[i]);
  }
  r[n-1]=a[n-1];
  for(int i=n-2;i>=0;i--){
    r[i]=gcd(r[i+1],a[i]);
  }
  int mx=1;
  rep(i,n){
    if(i==0) chmax(mx,r[1]);
    if(1<=i&&i<=n-2) chmax(mx,int(gcd(l[i-1],r[i+1])));
    if(i==n-1) chmax(mx,l[n-2]);
  }
  cout << mx << endl;
}

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

using namespace std;

#define MAX 1000001
using ull = unsigned long long;

const ull b = 1000000007ULL;

vector<ull> rolling_hash(char* S, int N, vector<ull>& p)
{
    vector<ull> h(N + 1);
    for (int i = 0; i < N; i++) {
        h[i + 1] = h[i] * b + S[i];
        p[i + 1] = p[i] * b;
    }
    return h;
}

int main()
{
    char S[MAX];
    scanf("%s", S);
    
    int N = strlen(S);
    vector<ull> p(N + 1);
    p[0] = 1;
    
    bool found = 0;
    auto h = rolling_hash(S, N, p);    
    
    vector<int> v;
    for (int i = 0; i < N; i++) {
        int A = i + 1;
        int B = (N - 3 * A) / 2;

        if (B <= 0) continue;
        if ((N - 3 * A) % 2 != 0) continue;

        auto A1 = h[A] - h[0] * p[A];
        auto B1 = h[A + B] - h[A] * p[B];
        auto A2 = h[A * 2 + B] - h[A + B] * p[A];
        auto B2 = h[2 * (A + B)] - h[A * 2 + B] * p[B];
        auto A3 = h[N] - h[2 * (A + B)] * p[A];

        if (A1 == A2 && A2 == A3 && B1 == B2) {
            found = 1;
            v.emplace_back(A + B);
        }
    }
    
    if (!found) {
        printf("mitomerarenaiWA\n");
    } else {
        printf("Love ");
        int size = *min_element(v.begin(), v.end());
        for (int i = 0; i < size; i++) {
            printf("%c", S[i]);
        }
        printf("!\n");
    }        
    return 0;
}

Measured memory_bytes: 19436
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
#define ALL(a)  (a).begin(),(a).end()
const int MOD = 1000000007;
int n, m, c, k,sum = MOD;
int main() {
    string s; cin >> s;
    for (char a = 'a';a <= 'z';a++) {
        k = 0; c = 0;
        for (auto it : s) {
            if (it == a) k = 0;
            else c = max(c, ++k); // ++k != k++
        }
        sum = min(sum, c);
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MAX int( 1e5 +5)


int main(){
    int n;
    cin >> n;
    llong dp[2][3];
    REP(i,3) dp[1][i] = 0;
    REP(i,n){
        llong cost[3];
        REP(j,3) scanf("%lld",&cost[j]);

        
        REP(j,3){
            dp[i%2][j] = 0;
            REP(k,3){
                if(k!=j) dp[i%2][j] = max(dp[i%2][j],dp[(i+1)%2][k] + cost[j]);
            }
        }
    }
    llong ans = 0;
    REP(i,3) ans = max(ans,dp[(n-1)%2][i]);
    cout << ans << endl;

}

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

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

#define RFOR(i, b, a) for(int(i)=(b); (i)>=(a); (i)--)
#define RREP(i, n) FOR((i), (n), 0)

#define pb push_back
#define mp make_pair 

using namespace std;

const int INF=INT_MAX/4;
const int MOD=1000000007;
const double EPS=1e-14;

const bool debug_flag=true;

void debug(string str){
	if(debug_flag){
		cout<<str<<endl;
	}
}

void debugs(string str){
	if(debug_flag){
		cout<<str;
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout.precision(10);

	int N;
	cin>>N;
	vector<long> A(N), B(N);
	for(int i=0; i<N; i++){
		cin>>A[i]>>B[i];
	}

	long ans=0;
	for(int i=N-1; i>=0; i--){
		if((A[i]+ans)%B[i] != 0){
			ans+=B[i]-(A[i]+ans)%B[i];
		}
	}

	cout<<ans<<endl;

	return 0;
}



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

int main() {
    ll N;
    cin >> N;
    vector<ll> h(N);
    for (ll i = 0; i < N; i++) {
        cin >> h[i];
    }

    ll ans = h[0];
    for (ll i = 1; i < N; i++) {
        ans += max(h[i] - h[i - 1], (ll)0);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
//Littleboy123 Template 1.7
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

//pragmas

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")


typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef unsigned long long int ull;
typedef long double ld;
typedef unsigned long long ull;

const long double pi = acos(-1.0);

#define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
#define TC(n) cout << "Case #" << (n) << ": "
#define DEBUG(x) cout << "DEBUG " << #x << ' ' << x << '\n';
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>

void init(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void infile(){
    freopen("fenwick.in", "r", stdin);
}

void outfile(){
    freopen("fenwick.out", "w", stdout);
}

ll modex(ll a, ll b, ll mod){
    if(b == 0)
        return 1;
    if(b == 1)
        return a;
    ll tmp = modex(a, b/2, mod);
    tmp = (tmp * tmp) % mod;
    if(b & 1)
        tmp = (tmp * a) % mod;
    return tmp;
}

//End of template

int main(){
    init();

    ll x, k, d;
    cin >> x >> k >> d;
    ll dist = abs(x/d);
    dist = min(dist, k);
    if((k-dist) % 2 == 0){
        cout << min(abs(x-dist*d), abs(x+dist*d));
    }
    else{
        cout << min(abs(x-(dist+1)*d), abs(x+(dist+1)*d));
    }
    return 0;
}


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

int main()
{
	int r = 0;
	int d = 0;
	int a,b,c;
	char t;
	while ( cin>>a>>t>>b>>t>>c )
	{
		if ( a*a+b*b==c*c )
			r++;
		if ( a==b )
			d++;
	}
	cout << r << endl;
	cout << d << endl;
	return 0;
}

Measured memory_bytes: 0
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
using namespace std;
const int inf=0x7fffffff;
const double eps=1e-10;
const double pi=acos(-1.0);
//char buf[1<<15],*S=buf,*T=buf;
//char getch(){return S==T&&(T=(S=buf)+fread(buf,1,1<<15,stdin),S==T)?0:*S++;}
inline int read(){
	int x=0,f=1;char ch;ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch&15);ch=getchar();}
	if(f)return x;else return -x;
}
using namespace std;
const int N=300005;
int n,L,ans=1,cnt,ok;
int x[N],t[N];
bool l[N],r[N];
int main(){
	n=read();L=read()<<1;
	for(int i=1;i<=n;i++)x[i]=read()<<1;
	for(int i=1;i<=n;i++)t[i]=read();
	for(int i=1;i<=n;i++){
		int v=t[i]%L;//v：火车从商场 i出发后，到购物完成，与商场i的距离。 
		ans+=(1ll*t[i]+L-1)/L;//ans记录跑了其中多少个来回。 
		if(!v)continue;
		l[i]=(v<=x[i]);//l[i] 代表是否可以从左边来接他 
		r[i]=(v<=L-x[i]);//r[i] 代表是否可以从右边来接他 
	}
	for(int i=1;i<n;i++)
		if(cnt&&r[i]){if(l[i])++ok;--ans;--cnt;}
		else if(l[i]) ++cnt;
		else if(r[i]&&ok) --ok,++cnt;
	if(r[n])ans--;
	printf("%lld\n",1ll*ans*L);
	return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();


// bool cmp(pair<int,int>p,pair<int,int>q) {
//     // return p.first>q.first;//descending by first
//     // return p.first<q.first;//ascending by first
//     // return p.second>q.second;//descending by second
//     return p.second<q.second;//ascending by second
// }

bool cmp(int p,int q) {
    return p>q;//descending
    // return p<q;//ascending
}


int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    int n,k;
    cin>>n>>k;
    lli a[n];
    f1(i,n) {
        cin>>a[i];
    }

    sort(a,a+n,cmp);
    lli sum=0;
    for(int i=k;i<n;++i) {
        sum+=a[i];
    }
    cout<<sum<<endl;
    

    // ()?cout<<"Yes"<<endl:cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 5204
#include <iostream>
#include <math.h>
#include <string>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
	string str;
	string str1 = "AAA";
	string str2 = "BBB";

	cin >> str;

	if (str==str2 || str==str1)
	{
		cout << "No" << endl;
		return 0;
	}
	else
	{
		cout << "Yes" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
//author-micheal corleone
//the godfather
#include <bits/stdc++.h>
#include <set> 
#include<algorithm>
#include <set> 
#include<algorithm>
#define ll long long int
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define out(n) printf("%lld\n",n)
#define inf 100000000000000
#define endl "\n"
#define precise(x) fixed << setprecision(x) 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
const int MOD =998244353;
#define f(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
 
using namespace std;

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[1] < v2[1]; 
}
 ll mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}
 //ll power(ll x, ll y) 
//{ 
  //  ll temp; 
    //if( y == 0) 
     //   return 1; 
    //temp = power(x, y/2); 
    //temp=temp%MOD;
    //if (y%2 == 0) 
     //   return (temp%MOD)*(temp%MOD); 
    //else
      //  return (x%MOD)*(temp%MOD)*(temp%MOD); 
//} 
 
 
ll ncr(ll n,ll r){if(n==1 || r==0)return 1;if(r>n/2)r=n-r;
	ll ans=1;for(ll i=1;i<=r;i++){ans=((ans * n )/i);n--;}return ans;
}
ll ncrsum(ll n,ll r, ll mod){
    if(n==1 || r==0)return 1;
  //  ll ans=1,sum=1;for(ll i=1;i<=r;i++){ans=((((ans * n)%MOD )*modinv(i,MOD))%mod);n--;sum+=ans;sum%=mod;}return sum;
}
 //diamond[2000005],ans[1000006];
 const int maxn=2e5+100;
 

int main()
{
	ios_base::sync_with_stdio(0);
   cin.tie(0);
    cout.tie(0);
     ll t;
   //cin>>t;
   
   t=1;	
   while(t--)
    {
        ll i1,i2,k,j,j1,a1,i31,i3,j2,i5,i4,i6,i7,i,n,m;
        ll x,y,z;
        ll total=0,cnt=0;
        ll flag=0;
        y=0;
        ll res,res1,ans,res2,q;
        ans=0;
        res1=0,res=0;
        ll s1,s2,s3;
        s2=0;
        ll sum=0,flag1=0;
        s1=0;
        ll k1,k2,k3;
        k1=0,k2=0;
        ll d,required,days;
        //cin>>h>>c>>required;
         string a,b;
         cin>>a>>b;
         n=a.length();
         m=b.length();
         ll dp[n+1][m+1];
         
         for(i=0;i<=n;i++)
         {
         	for(j=0;j<=m;j++)
         	{
         		if(i==0 || j==0 )dp[i][j]=0;
         		
         	   else if(a[i-1]==b[j-1])
         		{
         			dp[i][j]=dp[i-1][j-1]+1;
				 }
				 else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
				 
			 }
		 }
		 string answer="";
		 
		 i=n;
		 j=m;
		 while(i>0 && j>0)
		 {
		 	if(a[i-1]==b[j-1])
		 	{
		 		answer=answer+a[i-1];
		 		i--;
		 		j--;
			 }
			 else if(dp[i-1][j]>dp[i][j-1])
			 {
			 	i--;
			 }
			 else
			 {
			 	j--;
			 }
		 }
		reverse(answer.begin(),answer.end());
		 cout<<answer<<endl;
	
     }
    
}
	

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
  int n; cin >> n;
  int rtn = 0;
  for (int i = 1; i <= n; ++i) {
    int inp; cin >> inp;

    if (i % 2 == 1 && inp % 2 == 1) rtn++;
  }
  cout << rtn << endl;
}


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

#define ll long long int
using namespace std;

int main()
{
    ll N, A, B;
    cin>>N>>A>>B;
    ll k, j;
    k = N / (A+B);
    j = N % (A+B);

    ll ans = k * A + min(A, j);
    cout<<ans<<"\n";    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n;
	scanf("%d", &n);
	int(*a)[3] = (int(*)[3])malloc(sizeof(int)*(n+1) * 3);
	int *b = (int *)malloc(sizeof(int)*(n+1));
	int i, j;
	for (i = 0; i < n-1; i++)
	{
		for (j = 0; j < 3; j++)
		{
			scanf("%d", &a[i][j]);
			b[i] = a[i][1];
		}
	}
	for (i = 0; i < n-1; i++)
	{
		for (j = i; j < n-1; j++)
		{
			while (!(b[i] % a[j][2] == 0) || b[i] < a[j][1])
			{
				b[i]++;
			}
			b[i] += a[j][0];
		}
	}
	for (i = 0; i < n-1; i++)
		printf("%d\n", b[i]);
	printf("0\n");
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
A.append(0)
okane = 1000
kabu = 0
for i in range(N):
    if A[i] <= A[i+1]:
        buy = okane//A[i]
        okane -= buy*A[i]
        kabu += buy
    if A[i] > A[i+1]:
        okane += kabu*A[i]
        kabu = 0
print(okane)


Measured memory_bytes: 9124
#define _USE_NATH_DEFINES
#include <iostream>
#include<algorithm>
#include<functional>
using namespace std;

int main() {
	int n;
	int a[110];
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a,a+n, greater<int>());

	int Alice = 0;
	int Bob = 0;
	for (int i = 0; i < n; ++i) {
		if (i % 2 == 0) {
			Alice += a[i];
		}
		else {
			Bob += a[i];
		}
	}
	cout << Alice - Bob << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    vector<vector<int> > code(10, vector<int>(10, '*'));
    for(int i=0; i<26; ++i)
        code[i/5+1][i%5+1] = 'a' + i;
    code[6][2] = '.';
    code[6][3] = '?';
    code[6][4] = '!';
    code[6][5] = ' ';

    for(;;){
        string s;
        if(!(cin >> s))
            return 0;

        int n = s.size();
        if(n % 2 == 1){
            cout << "NA" << endl;
            continue;
        }

        string ret(n/2, ' ');
        bool na = false;
        for(int i=0; i<n; i+=2){
            char c = code[s[i]-'0'][s[i+1]-'0'];
            if(c == '*'){
                na = true;
                break;
            }
            ret[i/2] = c;
        }

        if(na)
            cout << "NA" << endl;
        else
            cout << ret << endl;
    }
}

Measured memory_bytes: 0