akhauriyash/Code-Regression huggingface dataset:
///
// File:  stable_sort.cpp
// Author: ymiyamoto
//
// Created on Thu Jun 29 08:27:13 2017
//

#include <cstdint>
#include <iostream>
#include <stdexcept>
#include <vector>

using namespace std;

void stable_sort_bubble_sort(pair<int32_t, uint8_t> array[], size_t size)
{
  if ((array == nullptr) || (size == 0)) throw runtime_error("array is null");

  for (uint32_t i = 0; i < size; i++) {
    for (uint32_t j = size - 1; j > i; j--) {
      if (array[j - 1].first > array[j].first) {
        swap(array[j - 1], array[j]);
      }
    }
  }
}

void stable_sort_selection_sort(pair<int32_t, uint8_t> array[], size_t size)
{
  if ((array == nullptr) || (size == 0)) throw runtime_error("array is null");

  for (uint32_t i = 0; i < size; i++) {
    uint32_t min = i;
    for (uint32_t j = i; j < size; j++) {
      if (array[j].first < array[min].first) {
        min = j;
      }
    }
    swap(array[i], array[min]);
  }
}

#if !defined(TEST)
#include <iostream>
static void print_vec(vector<pair<int32_t, uint8_t>> &vec)
{
  for (uint32_t i = 0; i < vec.size(); i++) {
    if (i != 0) cout << ' ';
    cout << vec[i].second << vec[i].first;
  }
  cout << endl;
}

int32_t main(void)
{
  vector<pair<int32_t, uint8_t>> vec1;
  vector<pair<int32_t, uint8_t>> vec2;

  uint32_t len;
  cin >> len;

  for (uint32_t i = 0; i < len; i++) {
    char c;
    int32_t val;
    cin >> c >> val;
    vec1.push_back(make_pair(val, c));
    vec2.push_back(make_pair(val, c));
  }

  stable_sort_bubble_sort(&vec1[0], vec1.size());
  stable_sort_selection_sort(&vec2[0], vec2.size());

  print_vec(vec1);
  cout << "Stable" << endl;

  print_vec(vec2);
  if (vec1 == vec2) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }

  return 0;
}
#endif

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

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

    string s[n];
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }

    int map[n][26];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 26; j++){
            map[i][j] = 0;
        }
    }

    for(int i = 0; i < n; i++){
        int len = s[i].length();
        for(int j = 0; j < len; j++){
            map[i][s[i][j] - 'a']++;
        }
    }

    string ans;
    int cou = 51;

    for(int i = 0; i < 26; i++){
        cou = 51;
        for(int j = 0; j < n; j++){
            if(map[j][i] == 0){
                cou = 0;
                break;
            }else{
                if(cou >= map[j][i]){
                    cou = map[j][i];
                }
            }
        }

        for(int j = 0; j < cou; j++){
            ans += 'a' + i;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
nm = input().split(" ")
N, M = int(nm[0]), int(nm[1])
# print(N, M)

sorted_data = sorted(list(map(int, input().split(" "))), reverse=True)
# print(sorted_data[M - 1] * 4 * M , sum(sorted_data))
if sorted_data[M - 1] * 4 * M >= sum(sorted_data):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38256
n = gets.to_i
a = gets.split.map &:to_i
b = Hash.new(0)
c = Hash.new(0)
d = 0

a.each_with_index do |x, i|
  b[x + i] += 1
  d += c[x + i]
  
  c[i - x] += 1
  d += b[i - x]
end

p d

Measured memory_bytes: 42196
import math
from itertools import combinations
from operator import itemgetter

pts = []
line = input()
n = int(line)
for _ in range(0, n):
    line = input()
    x, y = list(map(float, line.split()))
    pts += [[x, y]]

def dist(p, q):
    x1, y1 = p
    x2, y2 = q
    return (x1 - x2)**2 + (y1 - y2)**2

def solve(p, axis):
    n = len(p)
    if n <= 3:
        d = 100000
        q1 = q2 = []
        for p1, p2 in list(combinations(p, 2)):
            d = min(d, dist(p1, p2))
        return d

    mid = n // 2
    px, py = zip(*p)
    axis1 = 2 * len(set(px)) <= n
    axis2 = not axis1
    if axis1 != axis:
        p.sort(key = itemgetter(axis1))
    
    xy0 = p[mid][axis1]
    left = p[:mid]
    right = p[mid:]
    d = min(solve(left, axis1), solve(right, axis1))
    rd = math.sqrt(d)
    
    Q = []
    for pp in left[::-1]:
        if pp[axis1] < xy0 - rd:
            break
        Q.append(pp)
    for pp in right:
        if pp[axis1] > xy0 + rd:
            break
        Q.append(pp)
    Q.sort(key = itemgetter(axis2))
    for i, p1 in enumerate(Q):
        dd = p1[axis2] + rd
        for p2 in Q[i + 1:]:
            if p2[axis2] > dd:
                break
            norm = dist(p1, p2)
            if d > norm:
                d = norm
    return d

pts.sort(key = itemgetter(0))
ans = solve(pts, 0)
print('%.16f' % math.sqrt(ans))



Measured memory_bytes: 28692
#include<bits/stdc++.h>
#define int long long
#define nl '\n'
 using namespace std;



int32_t main() 
{
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif 
  int k;
  cin >> k;
  string s = "";

  while(k--){
     s += "ACL";
  }

  cout << s;
  return 0;
}



Measured memory_bytes: 3576
#include <iostream>

int main() {
	int h, w;
	int i, j;
	
	while (1)
	{
		std::cin >> h >> w;
		if (h == 0 || w == 0) break;

		for (i = 0; i < h; i++)
		{
			for (j = 0; j < w; j++)
			{
				if(i%2 == 0){
					if (j%2 == 0) std::cout << "#";
					else          std::cout << ".";
				}
				else
				{
					if (j%2 == 0) std::cout << ".";
					else          std::cout << "#";
				}
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3068
#include<stdio.h>

int main(void){

  int i;
  int n;
  int a[101];
  int max;

  for(i=0;i<101;i++)a[i] = 0;

  while(scanf("%d",&n) != EOF)a[n]++;

  max = 0;
  for(i=0;i<101;i++){
    if(max < a[i])max = a[i];
  }

  for(i=0;i<101;i++){
    if(a[i] == max)printf("%d\n",i);
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
#define F first
#define S second
#define fi(a, b) for(ll i=(a);i<=b;i++)
#define fj(a, b) for(ll j=(a);j<=b;j++)
#define fid(a, b) for(ll i=(a);i>=b;i--)
#define fjd(a, b) for(ll i=(a);i>=b;j--)

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for(auto v : V) os << v << " ";
    os << "]";
	return os;
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class T> ostream& operator<<(ostream &os, multiset<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, unordered_map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}

// Kevin Mathew T
// Birla Institute of Technology, Mesra
// LinkedIn - https://www.linkedin.com/in/KevinMathewT/
// GitHub - https://github.com/KevinMathewT
// CodeForces - https://codeforces.com/profile/KevinMathew
// CodeChef - https://www.codechef.com/users/KevinMathew
// HackerRank - https://www.hackerrank.com/KevinMathew

const ll N = 100, M = 1e9 + 7;
ll n;
string s;

void solve(){
	cin >> s;
	n = s.size();
	ll w = 0, moves = 0;

	fid(s.size() - 1, 0) if(s[i] == 'B') moves += w; else w++;
	cout << moves << "\n";
}

int main(){
	// freopen("input.txt", "r", stdin);		//Comment
	// freopen("output.txt", "w", stdout);		//this out.
	ios::sync_with_stdio(false);			//Not
	cin.tie(NULL);							//this.
	cout.tie(0);							//or this.

	// ll T;
	// cin >> T;
	// while(T--)
		solve();

	return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;

ll i,j,k;


int main(){
   ll A,B;
   cin>>A>>B;
   if(A==B)cout<<"Draw"<<endl;
   else if(A==1||A>B&&B!=1)cout<<"Alice"<<endl;
   else cout<<"Bob"<<endl;


}

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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
int N;
vll A;
vll B;

int main(int argc, char** argv) {
  cin >> N;
  A.resize(N+1);
  B.resize(N);

  for (int i=0; i<N+1; i++) {
    cin >> A[i];
  }

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

  ll ret = 0;
  for (int i=0; i<N; i++) {
    ll tmp = min({A[i], B[i]});
    ret += tmp;
    A[i] -= tmp;
    B[i] -= tmp;

    tmp = min({A[i+1], B[i]});
    ret += tmp;
    A[i+1] -= tmp;
    B[i] -= tmp;
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 1792
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    sum=0
    for i in range(x//3+1,n+1):
        for j in range((x-i)//2+1,i):
            if 0<x-i-j<j :   
                sum+=1
    print(int(sum))

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

using namespace std;

int main(){
  string s;bool flag = true;
  cin >> s;
  for(int i = 0;i < s.size()-1;i++)if(s[i] == s[i+1])flag = false;
  if(flag)cout << "Good";
  else cout << "Bad";
  return 0;
}

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

using namespace std;

string S;
int res = 0;
int main()
{
  cin>>S;
  int n = S.size() - 1;
  if ((n+1) % 2 != 0)
  {
    int m = (n)/2;
    int l = 1;
    int r = 1;
    while (m - l >= 0 && r + m <= n)
    {
      if (S[m-l] != S[m+r]) res++;
      l++; r++;
    }
    cout<<res;
  }
  else
  {
      int m = (n)/2;
      int l = 0; int r = 1;
      while (m - l >= 0 && r + m <= n)
        {
              if (S[m-l] != S[m+r]) res++;
              l++; r++;
        }
        cout<<res;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 1e+5+5;

int n,m;
int h[N],tot;
struct edge{
	int x,nxt,fx;
}e[N*2];
int label[N];
int cnt[4];
int siz[N];
int d[N],sum[N];

void inse(int x,int y,int fx){e[++tot].x=y;e[tot].fx=fx;e[tot].nxt=h[x];h[x]=tot;}

bool dfs(int x){
	siz[x]=1;
	sum[x]=d[x];
	bool pd=1;
	for(int p=h[x];p;p=e[p].nxt)
	if (!label[e[p].x]){
		label[e[p].x]=(label[x]+e[p].fx-1)%3+1;
		cnt[label[e[p].x]]++;
		pd&=dfs(e[p].x);
		siz[x]+=siz[e[p].x];
		sum[x]+=sum[e[p].x];
	}
	else if (label[e[p].x]!=(label[x]+e[p].fx-1)%3+1)pd=0;
	return pd;
}

int main(){
	n=get();m=get();
	fo(i,1,m){
		int x=get(),y=get();
		inse(x,y,1);
		inse(y,x,2);
		d[x]++;d[y]++;
	}
	LL ans=0;
	fo(i,1,n)
	if (!label[i]){
		cnt[1]=cnt[2]=cnt[3]=0;
		cnt[1]=label[i]=1;
		if (dfs(i)){
			if (cnt[3]&&cnt[2])ans=ans+1ll*cnt[1]*cnt[2]+1ll*cnt[2]*cnt[3]+1ll*cnt[3]*cnt[1];
			else ans=ans+sum[i]/2;
		}
		else ans=ans+1ll*siz[i]*siz[i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int>A;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        A.push_back(x);
    }
    int dp[n];
    for(int i=0;i<n;i++){
        dp[i]=INT_MAX;
    }
    dp[0]=0;
    for(int i=1;i<n;i++){
        for(int j=max(0,i-k);j<i;j++){
            dp[i]=min(dp[i],dp[j]+abs(A[i]-A[j]));
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 4148
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];
int32_t main(){_

   string s;
   cin >> s;

   if (s == "SUN"){
      cout<<7;
      exit(0);      
   }

   if (s == "MON"){
      cout<<6;
      exit(0);      
   }

   if (s == "TUE"){
      cout<<5;
      exit(0);      
   }

   if (s == "WED"){
      cout<<4;
      exit(0);      
   }

   if (s == "THU"){
      cout<<3;
      exit(0);      
   }

   if (s == "FRI"){
      cout<<2;
      exit(0);      
   }

   if (s == "SAT"){
      cout<<1;
      exit(0);      
   }

   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,t,i,j,c,v[200005];
    cin>>n>>t;
    for(i=0;i<n;i++)
    {
        cin>>v[i];
    }
    c=0;
    for(i=1;i<n;i++)
    {
        if(t>=v[i]-v[i-1])c+=(v[i]-v[i-1]);
        else c+=t;
    }
    cout<<c+t<<endl;
    return 0;
}


Measured memory_bytes: 5064
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


int bitcnt(int n) {
	int ret = 0;
	while (n > 0) {
		ret += n % 2;
		n /= 2;
	}
	return ret;
}
int main() {
	int N, origN;
	cin >> N;
	origN = N;
	vector<int>dv;
	for (int d = 2; d*d <= N; d++) {
		if (N % d == 0) {
			dv.pb(d);
			while (N % d == 0)N /= d;
		}
	}
	if (N != 1)dv.pb(N);

	int M = dv.size(), ans = 0;
	for (int bit = 1; bit < (1 << M); bit++) {
		int popcnt = bitcnt(bit);
		int mul = 1;
		for (int i = 0; i < M; i++) {
			if (bit & (1 << i))mul *= dv[i];
		}
		if (popcnt % 2 == 1)ans += origN / mul;
		else ans -= origN / mul;
	}
	ans = origN - ans;
	puts(ans);
	return 0;
}


Measured memory_bytes: 3148
def digit_sum(x): 
    y = str(x) 
    y_len = len(y) 
    ans = 0
    for j in range(y_len):
        ans += int(y[j]) 

    return ans

answer = 10**8 
n = int(input()) 
for i in range(1,n):
    a = i 
    b = n - a 
    answer = min(answer, digit_sum(a)+ digit_sum(b))

print(answer)

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

template <typename T> T gcd(T x, T y) {
  return y ? gcd(y, x%y) : x;
}

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

  ll sum = 0;
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= K; j++) {
      for (int k = 1; k <= K; k++) {
        sum += gcd(gcd(i, j), k);
      }
    }
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3636
##### UnionFind #####
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

(n, m), p, *q = [list(map(int, o.split())) for o in open(0)]
UF = UnionFind(-~n)
for a, b in q:UF.union(a, b)
print(sum(UF.same(p[i], -~i) for i in range(n)))

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

int main() {
	int p[2]={};
	int n;
	for(int i=0;i<2;i++){
	for(int j=0;j<4;j++){
		cin >> n;
		p[i]+=n;
	}
	}
	cout << max(p[0],p[1]) << endl;
	return 0;
}

Measured memory_bytes: 1160
N = int(input())
X = list(map(int, input().split()))

ave = sum(X)/len(X)
ave_N = sum(X)//len(X)
if( (ave - ave_N) >= (ave_N + 1 - ave)):
  ave = ave_N + 1
else:
  ave = ave_N

total = 0
for i in range(len(X)):
  total += (X[i]-ave)*(X[i]-ave)
print(total)

Measured memory_bytes: 3064
#include<iostream>

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


int main () {
  string number;
  int i, sum;

  while (1) {
    cin >> number;
    if (number == "0") break;
    sum = 0;
    rep(i, number.length()) {
      sum += number.at(i) - '0';
    }
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 1188
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main(void){
	vector<string> ok;
	for (int i = 0; i < (1 << 4); ++i){
		string tmp = "";
		if (i & 1) tmp = "A";
		tmp = tmp + "KIH";
		if (i & 2) tmp = tmp + "A";
		tmp = tmp + "B";
		if (i & 4) tmp = tmp + "A";
		tmp = tmp + "R";
		if (i & 8) tmp = tmp + "A";
		ok.push_back(tmp);
	}
	// for (auto s : ok) cout << s << endl;
	
	string S;  cin >> S;
	for (auto s : ok){
		if (S == s){
			cout << "YES" << endl;
			return 0;
		}
	}

	cout << "NO" << endl;

	return 0;
}

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

int main() {

	int w, a, b; cin >> w >> a >> b;
	if (a + w < b) cout << b - (a + w) << endl;
	else if (b + w < a) cout << a - (b + w) << endl;
	else cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int N;
  long long ans=0;
  long long a[100010][3];
  cin >> N;
  for(int i=0; i<N; i++){
    for(int j=0; j<3; j++) cin >> a[i][j];
  }
  long long dp[100010][3];
  for(int i=0; i<N; i++){
    for(int j=0; j<3; j++) dp[i][j]=0;
  }
  for(int i=0; i<3; i++) dp[0][i]=a[0][i];
  for(int i=1; i<N; i++){
    for(int j=0; j<3; j++){
      for(int k=0; k<3; k++){
        if(k!=j){
          dp[i][k]=max(dp[i][k],dp[i-1][j]+a[i][k]);
        }
      }
    }
  }
  for(int i=0; i<3; i++) ans=max(ans,dp[N-1][i]);
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
const int N=100010;
int n;
int a[N],b[N],c[N];
int A[N],B[N],C[N];
int main()
{
  cin>>n;
  for(int i=1;i<=n;++i) cin>>a[i]>>b[i]>>c[i];
  for(int i=1;i<=n;++i) 
  {
    A[i]=max(B[i-1],C[i-1])+a[i];
    B[i]=max(A[i-1],C[i-1])+b[i];
    C[i]=max(A[i-1],B[i-1])+c[i];
  }
  cout<<max({A[n],B[n],C[n]});
}

Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <bitset>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

const int MAX_N = 200011;
vector<int> C;

int divide(string &X, int m) {
    int ans = 0;
    rep(i, X.size()) {
        ans *= 2;
        ans += X[i] - '0';
        ans = ans % m;
    }
    return ans;
}

ll pow_mod(ll a, ll b, ll m){
    ll ret = 1;
    while (b > 0) {
        if (b & 1) {
            ret = ret * a % m;
        }
        a = a * a % m;
        b >>= 1;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    string X;
    cin >> N >> X;
    
    C.assign(MAX_N, -1);
    C[0] = 0;
    rep(i, 1, MAX_N) {
        int pcnt = (int)bitset<32>(i).count();
        C[i] = 1 + C[i % pcnt];
    }
    
    auto x = bitset<MAX_N>(X);
    int xpcnt = (int)x.count();
    
    int mod_neg = 0;
    if (xpcnt > 1) mod_neg = divide(X, xpcnt - 1);
    int mod_pos = divide(X, xpcnt + 1);
    
    for(int i = N - 1; i >= 0; i--){
        int m;
        if(x[i] == 0) {
            m = (mod_pos + pow_mod(2, i, xpcnt + 1)) % (xpcnt + 1);
            m += xpcnt + 1;
            m %= xpcnt + 1;
            output(1 + C[m]);
        }
        else {
            if(xpcnt <= 1) {
                output(0);
            } else {
                m = (mod_neg - pow_mod(2, i, xpcnt - 1) + xpcnt - 1) % (xpcnt - 1);
                m += xpcnt - 1;
                m %= xpcnt - 1;
                output(1 + C[m]);
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 4420
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl "\n"
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fb(i, a, b) for(ll i=a; i>=b; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector <int>
#define vl vector <long long>
#define pi pair <int, int>
#define sz(x) (int) x.size()
#define M 100005
#define mod 1000000007
using namespace std;

void solve()
{
	ll x;
	cin>>x;
	f(i, -200, 200)
	{
		f(j, -200, 200)
		{
			if(pow(i, 5) - pow(j, 5) == x)
			{
				cout<<i<<' '<<j;
				return;
			}
		}
	}
}

int main()
{
    IOS
    int t = 1;
    //cin>>t;
    f(tno, 1, t+1)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4112
def cal_temperture(x):
    return t - x * 0.006


n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
cal_h = list(map(cal_temperture, h))
ans = 0
temp = 1000000
for i in range(n):
    if temp > abs(cal_h[i] - a):
        temp = abs(cal_h[i] - a)
        ans = i

print(ans+1)

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

int main()
{
	string S;
  cin >> S;
  bool flag = false;
  
  for(int i = 0; i < S.size(); i++){
   if(i%2 == 0){
     if(S.at(i) == 'L'){
       flag = false;
       cout << "No" << endl;
       return 0;
     }	else {
       flag = true;
     }
   } else{
     if(S.at(i) == 'R'){
       flag = false;
       cout << "No" << endl;
       return 0;
     } else {
       flag = true;
     }
   }
  }    
  cout << "Yes" << endl;
  
  return 0;
}

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

int main(void){
    
    int a[3001] = {0};
    int b[3001] = {0};
    
    int setNum = 0;

    for(int i = 0 ; i < 3001 ; i++){
        cin >> a[i] >> b[i];
    
        if( (a[i] == 0) && (b[i] == 0) ){
            setNum = i - 1;
            break;
        }
    }
    
    for(int i = 0 ; i <= setNum ; i++){
        int smale = 0;
        int large = 0;
        (a[i] < b[i]) ? (smale = a[i],large = b[i]) : (smale = b[i],large = a[i]);
        cout << smale << ' ' << large << endl;
    }

    return 0;
}

Measured memory_bytes: 1188
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N = int(input())
px, py, pt = 0, 0, 0
ok = True
for i in range(N):
    t, x, y = map(int, input().split())
    diff = abs((x + y) - (px + py)) 
    if diff > t - pt:
        ok = False
    if diff % 2 != (t - pt) % 2:
        ok = False
    px = x
    py = y
    pt = t

if ok:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9296
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main() {
 int c;
  cin>>c;
  if(c<1200)cout<<"ABC"<<endl;
  else cout<<"ARC"<<endl;
}

Measured memory_bytes: 3568
class UnionFind:
    def __init__(self,n):
        self.parent=[i for i in range(n+1)]
        self.size=[1 for _ in range(n+1)]
    # 親(木構造の根)を返す
    def find(self,x):
        if self.parent[x]==x:
            return x
        else:
            self.parent[x]=self.find(self.parent[x])
            return self.parent[x]
    # 2つの木を併合
    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return
        if self.size[x]<self.size[y]:
            x,y=y,x
        self.size[x]+=self.size[y]
        self.parent[y]=x

n,m=map(int,input().split())
bridge=[list(map(int,input().split())) for _ in range(m)]
bridge.reverse()
uf=UnionFind(n)
dis=n*(n-1)//2
ans=[dis]
for a,b in bridge:
    pa,pb=uf.find(a),uf.find(b)
    if pa!=pb:
        dis-=uf.size[pa]*uf.size[pb]
    ans.append(dis)
    uf.union(a,b)
for a in reversed(ans[:-1]):
    print(a)

Measured memory_bytes: 34976
def area(p,q):
    return (p[0]*q[1]-p[1]*q[0])*0.5

n=int(input())
point=[]
x_1,y_1=[int(i) for i in input().split(" ")]

for i in range(n-1):
    x,y=[int(k) for k in input().split(" ")]
    point.append([x-x_1,y-y_1])



a=0


for i in range(n-2):
    a+=area(point[i],point[i+1])

print(a)

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

int main()
{
  int n, x, w[111] = {0};
  cin >> n;
  for (int i = 1; i <= n; i++)
  {
    cin >> x;
    w[i] = w[i - 1] + x;
  }

  int ans = w[n];
  for (int i = 1; i < n; i++)
    ans = min(ans, abs(w[n] - w[i] * 2));

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int *A;
int partition(int p,int *A, int r);
int main(){
  int r,i,j,k,p=0;
  
  scanf("%d",&r);
  A =malloc(sizeof(int)*r);

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

 k = partition(p,A,r);


 
for(j=0; j<r; j++){
    if(j==r-1){
      printf("%d\n",A[j]); 
    }
    else if(j==k){
      printf("[%d] ",A[j]);
    }
    else{
      printf("%d ",A[j]);
    }
  }
  
  return 0;
}



  int partition(int p,int *A,int r){
  int tmp,tmp2;
  int x,i,j;
  x = A[r-1];
  i =p-1;
  for(j=p ; j<r-1; j++){

    if(A[j] <= x){
  
      i=i+1;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  
  tmp2 = A[i+1];
  A[i+1] = A[r-1];
  A[r-1] = tmp2;

  
  return i + 1;
  }













 
  



Measured memory_bytes: 2104
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>
#include<cstdio>

#define curr(P, i) P[(i) % P.size()]
#define next(P, i) P[(i+1) % P.size()]
#define prev(P, i) P[(i+P.size()-1) % P.size()]
 
using namespace std;
 
double EPS = 1e-10;
const double PI = acos(-1);
 
double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}
 
  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }
 
  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }
 
  point operator * (double d){
    return point(x*d,y*d);
  }
 
  point operator / (double d){
    return point(x/d,y/d);
  }
 
};
 
#define Line pair<point,point>

double dot(point a, point b) {
  return (a.x * b.x + a.y * b.y);
}

double cross(point a, point b) {
  return (a.x * b.y - a.y * b.x);
}
 
double norm(point a){
  return sqrt(a.x*a.x+a.y*a.y);
}
 
int ccw(point a, point b, point c) {
  b = b-a; c = c-a;
  if (cross(b, c) > 0)   return +1;
  if (cross(b, c) < 0)   return -1;
  if (dot(b, c) < 0)     return +2;
  if (norm(b) < norm(c)) return -2; 
  return 0;
}

point intersection_l(point a1, point a2, point b1, point b2) {
  return a1 + (a2 - a1) * (cross(b2 - b1,b1 - a1) / cross(b2 - b1,a2 - a1));
}

point symmetry(point p1, point p2, point Q){
  double xa,ya,xb,yb,t1,t2;
  point R;
 
  xa=Q.x-p1.x,ya=Q.y-p1.y;
  xb=p2.x-p1.x,yb=p2.y-p1.y;
 
  t1=xa*xb+ya*yb,t2=xb*xb+yb*yb;
 
  R.x=2*(p1.x+xb*t1/t2)-Q.x;
  R.y=2*(p1.y+yb*t1/t2)-Q.y;
  return R;
}

 Line parallel_line(point a,point b,double h){
    double t = atan((a.y-b.y)/(a.x-b.x));
 
    point a_(a.x + h*cos(t+PI/2), a.y + h*sin(t+PI/2));
    point b_(b.x + h*cos(t+PI/2), b.y + h*sin(t+PI/2));
 
    if(ccw(a,b,a_)==-1)a_=symmetry(a,b,a_),b_=symmetry(a,b,b_);
 
    return make_pair(a_,b_);
}

vector<point> convex_cut(vector<point>pol,point a,point b){
  vector<point>q;
  for (int i=0; i<pol.size();i++) {
    point A=curr(pol,i),B=next(pol, i);
    if (ccw(a,b,A)!=-1)q.push_back(A);
    if (ccw(a,b,A)*ccw(a,b,B)<0)
      q.push_back(intersection_l(A,B,a,b));
  }
  return q;
}

bool C(vector<point>pol,double d){
  vector<Line>L;
  for(int i=0;i<pol.size();i++){
    L.push_back(Line(curr(pol,i),next(pol,i)));
  }
  
  for(int i=0;i<L.size();i++){
    Line tmp=parallel_line(L[i].first,L[i].second,d);
    pol=convex_cut(pol,tmp.first,tmp.second);
  }
  return pol.size()>0;
}

double Binary_search(vector<point>pol){
  double l=0,r=10000,tc=86;
  while(tc--){
    double d=(l+r)/2;
    if(C(pol,d))l=d;
    else r=d;
  }
  return l;
}

int main(void){

  int n;
  while(cin >> n,n){
    vector<point>pol(n);
    for(int i=0;i<n;i++)cin >> pol[i].x >> pol[i].y;
    printf("%.6f",Binary_search(pol));
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1368
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
a = LIST()

l = []

for i in range(1, N+1):
	tmp = sum(a[:i])
	for j in range(N-i+1):
		l.append(tmp)
		tmp -= a[j]
		if j+i <= N-1:
			tmp += a[j+i]

ans = 0
for i in range(max(l).bit_length()-1, -1, -1):
	nextl = []
	for x in l:
		if (x>>i)&1:
			nextl.append(x)
	if len(nextl) >= K:
		ans += 1<<i
		l = nextl
print(ans)


Measured memory_bytes: 84768
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
int main(){
    int n;cin>>n;
    vector<double>v(n);
    rep(i,n)cin>>v[i];
    rep(i,n-1){
        sort(v.begin(),v.end());
        v[1]=(v[0]+v[1])/(double)2;
        v[0]=2000;
    }
    sort(v.begin(),v.end());
    cout<<v[0]<<endl;
}

Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;

ll MOD = ((ll)1e9 + 7);

/* TEMPLATE ENDS HERE */

bool ok(int m, int d) {
	return (((d % 10) >= 2) && (d / 10 >= 2) && (d % 10) * (d / 10) == m);
}

int main() {
	int m, d;
	cout << fixed << setprecision(12);	
	cin >> m >> d;
	int ret = 0;
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= d; j++) {
			if (ok(i,j)) {
				ret++;
			}
		}
	}
	cout << ret << endl;
	return 0;
}


struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
	}
	
	mod& operator=(const ll & tx) {
		x = tx;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}


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


int main(){

	int A,B,C;
	int i;
	scanf("%d %d %d",&A,&B,&C);

	for(i = 1; i <= 100; i++){
		if(A*i % B == C){
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,q,s[114514],t[114514],x[114514],ans[114514];
int main() {
	cin>>a>>b>>q;
	for(int i=1;i<=a;i++)cin>>s[i];
	for(int i=1;i<=b;i++)cin>>t[i];
	s[0]=t[0]=-1e15,s[a+1]=t[b+1]=1e15;
	for(int i=0;i<q;i++){
		cin>>x[i];
		ll ok=a,ng=-1;
		while(abs(ok-ng)>1){
			ll mid=(ok+ng)/2;
			if(s[mid]>x[i])ok=mid;
			else ng=mid;
		}
		ll sn[2]={s[ok],s[ok-1]};
		ok=b,ng=-1;
		while(abs(ok-ng)>1){
			ll mid=(ok+ng)/2;
			if(t[mid]>x[i])ok=mid;
			else ng=mid;
		}
		ll tn[2]={t[ok],t[ok-1]};
		ans[i]=1e15;
		for(int j=0;j<2;j++)for(int k=0;k<2;k++){
			ans[i]=min(ans[i],abs(sn[j]-x[i])+abs(sn[j]-tn[k]));
			ans[i]=min(ans[i],abs(tn[k]-x[i])+abs(sn[j]-tn[k]));
		}
	}
	for(int i=0;i<q;i++)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 4480
import sys
N, A, B = map(int, input().split())

if N <=A:
    print(N)
    sys.exit()
if N <= (A+B):
    print(A)
    sys.exit()

count = 0

most = N//(A+B)
amari = (N - (A+B)*most)

if amari <= A:
    print((most*A) + amari)
else:
    print((most*A) + A)


Measured memory_bytes: 3060
// ---------- begin chmin, chmax ----------
trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------

use proconio::*;
use proconio::marker::*;

fn run() {
    input! {
        n: usize,
        a: [Usize1; 3 * n],
    }
    let mut dp = vec![vec![-5000; n]; n];
    let mut max = vec![-5000; n];
    dp[a[0]][a[1]] = 0;
    dp[a[1]][a[0]] = 0;
    max[a[0]] = 0;
    max[a[1]] = 0;
    let mut add = 0;
    let mut change = vec![];
    for a in a[2..].chunks_exact(3) {
        let (a, b, c) = (a[0], a[1], a[2]);
        if a == b && b == c {
            add += 1;
            continue;
        }
        change.clear();
        let v = *max.iter().max().unwrap();
        if a == b || b == c || c == a {
            let q = a ^ b ^ c;
            let p = (a + b + c - q) / 2;
            for (i, (max, dp)) in max.iter().zip(dp.iter()).enumerate() {
                change.push((i, q, std::cmp::max(*max, dp[p] + 1)));
                change.push((i, p, *max));
            }
            change.push((p, p, std::cmp::max(v, dp[q][q] + 1)));
            change.push((p, q, v));
        } else {
            change.push((b, c, dp[a][a] + 1));
            change.push((c, a, dp[b][b] + 1));
            change.push((a, b, dp[c][c] + 1));
            change.push((a, b, v));
            change.push((b, c, v));
            change.push((c, a, v));
            for &x in [a, b, c].iter() {
                for (i, max) in max.iter().enumerate() {
                    change.push((x, i, *max));
                }
            }
        }
        for &(x, y, v) in change.iter() {
            dp[x][y].chmax(v);
            dp[y][x].chmax(v);
            max[x].chmax(v);
            max[y].chmax(v);
        }
    }
    let last = *a.last().unwrap();
    let ans = add + std::cmp::max(*dp.iter().flatten().max().unwrap(), dp[last][last] + 1);
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 18136
x, k, d = map(int, input().split())

x = abs(x)
multiplier = x//d
if multiplier <= k:
    x = x - (multiplier * d)
    if (k-multiplier)%2 == 0:
        ans = abs(x)
    else:
        if x > 0:
            ans = abs(x-d)
        else:
            ans = x+d
else:
    ans = x - (k*d)

print(ans)

Measured memory_bytes: 9088
R, C, N = map(int, input().split())
edge = []


def F(x, y):
    if x == 0:
        return y
    if y == C:
        return C + x
    if x == R:
        return R + C * 2 - y
    if y == 0:
        return 2 * R + 2 * C - x
    return -1


for i in range(1, N + 1):
    x1, y1, x2, y2 = map(int, input().split())
    d1 = F(x1, y1)
    d2 = F(x2, y2)
    if d1 < 0:
        continue
    if d2 < 0:
        continue
    edge.append((d1, i))
    edge.append((d2, i))

edge.sort()
stack = []
used = [False] * (N + 1)

ans = "YES"
for _, x in edge:
    if not used[x]:
        used[x] = True
        stack.append(x)
    else:
        y = stack.pop()
        if x != y:
            ans = "NO"
            break

print(ans)

Measured memory_bytes: 27940
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int m = sc.nextInt();
		int d = sc.nextInt();
      
        int ans = 0;
        for(int month = 4; month <= m; month++) {
          for (int day = 22; day <= d; day++) {
            int d1 = day % 10;
            int d10 = (day - d1) / 10;
            if (d1 < 2) {
              continue;
            }
            if (d1 * d10 == month) {
              ans++;
            }
          }
        }

      
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 21972
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()

int main(){
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    if(S[K - 1] == 'A') S[K - 1] = 'a';
    if(S[K -1] == 'B') S[K -1] = 'b';
    if(S[K - 1] == 'C') S[K - 1] = 'c';
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N, M; cin >> N >> M;
    double t = 1900.0*M + 100.0*(N-M);
    double a = pow(0.5, M);
    double w = 1 - a;

    cout << a*t/((1-w)*(1-w)) << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
 
using namespace std;
 
void popular(vector<int>& arr,int m,int sum){
  int popular = 0;
 // int unpopular = 0;
 // cout<<m;
  int checker = (4*m) ;
  //  cout<<checker<<" "<<endl;
    //cout<<sum<<" ";
 // cout<<checker<<endl;
  for(int i=0;i < arr.size();i++){
    //  cout<<"k";
    if(arr[i]*checker >= sum ){
      popular++;
     // cout<<popular;
    }
  }
  if(popular >= m){
    cout<<"Yes";
     // cout<<popular<<" "<<endl;
  }
  else
    cout<<"No";
  
}
 
int main(int args,char **argv){
  int n,m;
  cin>>n>>m;
  vector<int>arr(n);
  for(int i=0;i<arr.size();i++){
    cin>>arr[i];
  }
  
  int sum = 0;
  for(int i=0;i<arr.size();i++){
    sum = sum + arr[i];
  }
    
   //cout<<sum<<endl;
   // cout<<m<<endl;
  popular(arr,m,sum);
  
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> nums(n + 1, 1);
	for (int i = 1; i <= n; ++i)
	{
		for (int j = i; j <= n; j += i)
		{
			nums[j]++;
		}
	}
	long long cnt = 0;
	for (int i = 1; i < n; ++i)
	{
		cnt += (nums[n - i] - 1);
	}
	cout << cnt << '\n';
}

Measured memory_bytes: 7112
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

int main() {
  int a, b;
  cin >> a >> b;
  if (1 <= a && a <= 9 && 1 <= b && b <= 9) {
    cout << a * b << endl;
  }
  else cout << -1 << endl;

  
  return 0;
}

Measured memory_bytes: 256
n,x,y = map(int,input().split())
x,y = x-1,y-1

D = [0 for _ in range(n+1)]
    
for i in range(n-1):
    for j in range(i+1,n):
        dist1 = j-i
        dist2 = abs(i-x) +1 + abs(j-y)
        dist = min(dist1,dist2)
        D[dist] = D[dist]+1


    
for i in range(1,n):
    print(D[i])

Measured memory_bytes: 3444
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <math.h>

int main(void)
{

	int a;
	double p_a;
	int ans;

	scanf("%d", &a);

	p_a = (double)a;

	ans = (int) (p_a + pow(p_a, 2) + pow(p_a, 3));

	printf("%d", ans);


	return 0;
}


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


int main(){

	int H,W;

	while(cin >> H >> W, H && W){
		for(int i=0; i<H; i++){
			for(int j=0; j<W; j++){
				if((i%2)!=0){
					if((j%2)==0)
						cout << ".";
					else
						cout << "#";
				}
				else{
					if((j%2)==0)
						cout << "#";
					else
						cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}



	return 0;
}

Measured memory_bytes: 3048
#include <cstdio>

using namespace std;

bool testcase_ends() {
    int n;
    if (scanf("%d", &n) == EOF)
        return 1;

    int res=0;
    for (int a=0; a<10; ++a)
        for (int b=0; b<10; ++b)
            for (int c=0; c<10; ++c)
                for (int d=0; d<10; ++d)
                    if (a+b+c+d == n)
                        ++res;

    printf("%d\n", res);
    return 0;
}

int main() {
    bool solved_one=false;
    while (!testcase_ends())
        solved_one |= true;

    return !solved_one;
}

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

int main(){
	int n, m, ans,l;
	string str;
	cin>>n>>m>>l;
	
	if(m < l)swap(m,l);
	if(n < m)swap(n,m);
	if(l > m)swap(l,m);
	//cout<<n<<m<<l<<endl;
	ans = abs(m-n)+abs(l-m);
	
	cout<<ans<<endl;
	
	return 0;
}

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

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        int i=0,game=0,team=0,teama,teamb,a,b;
        int[] teams=null;
        boolean first=true;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            while ((line = br.readLine()) != null) {
            	if(first){
            		team=Integer.parseInt(line);
            		teams=new int[team+1];
            		game=team*(team-1)/2;
            		first=false;
            	}else{
            		String[] str=line.split(" ");
            		teama = Integer.parseInt(str[0]);
            		teamb = Integer.parseInt(str[1]);
            		a = Integer.parseInt(str[2]);
            		b = Integer.parseInt(str[3]);
            		if(a>b){
            			teams[teama]+=3;
            		}else if(a==b){
            			teams[teama]++;
            			teams[teamb]++;
            		}else{
            			teams[teamb]+=3;
            		}
            		i++;
                	if(i==game){
                		break;
                	}
            	}
            }

            int[] sort=teams.clone();
            for(int j=1;j<sort.length;j++){
            	int max=sort[j];
            	int store=j;
            	for(int k=j+1;k<sort.length;k++){
                	if(sort[k]>max){
                		max=sort[k];
                		store=k;
                	}
                }
            	int w=sort[j];
            	sort[j]=sort[store];
            	sort[store]=w;
            }
            int rank=1;
            int[] result=new int[sort.length];
            i=0;
            
            for(int k=1;k<sort.length;k++){
            	i=0;
            	for(int l=1;l<teams.length;l++){
            		if(sort[k]==teams[l]&&result[l]==0){
            			result[l]=rank;
            			i++;
            		}
            	}
            	rank+=i;
            }
            for(int k=1;k<result.length;k++){
            	System.out.println(result[k]);
            }
        }
    }

}

Measured memory_bytes: 29988