akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

#include <vector>

template <typename T>
struct WeightedUnionFind
{
    vector<int> data;
    vector<T> weight_diff;


    WeightedUnionFind(int sz) : data(sz, -1), weight_diff(sz) {}

    int find(int k)
    {
        if (data[k] < 0)
            return k;
        auto par = find(data[k]);
        weight_diff[k] += weight_diff[data[k]];
        return data[k] = par;
    }

    T weight(int t)
    {
        find(t);
        return weight_diff[t];
    }

    bool unite(int x, int y, T w)
    {
        w += weight(x);
        w -= weight(y);
        x = find(x), y = find(y);
        if (x == y)
            return false;
        if (data[x] > data[y])
        {
            swap(x, y);
            w *= -1;
        }
        data[x] += data[y];
        data[y] = x;
        weight_diff[y] = w;
        return true;
    }

    T diff(int x, int y)
    {
        return weight(y) - weight(x);
    }

    bool same(int x, int y)
    {
        return (find(x) == find(y));
    }
};

int main()
{
    int N, q;
    cin >> N >> q;
    WeightedUnionFind<int> uf(N);
    for (int i = 0; i < q; i++)
    {
        int a;
        cin >> a;
        if (a == 0)
        {
            int x, y, z;
            cin >> x >> y >> z;
            uf.unite(x, y, z);
        }
        else
        {
            int x, y;
            cin >> x >> y;
            if (uf.same(x, y) == true)
            {
                cout << uf.diff(x, y) << endl;
            }
            else
            {
                cout << "?" << endl;
            }
        }
    }
}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#define REP(i,a) for(int i = 0; i < (a); i++)
using namespace std;

int main(){
	int n;
	string s;
	cin >> n >> s;
	int r = 0,b = 0;
	REP(i,n){
		if(s[i] == 'R')r++;
		else b++;
	}
	if(r > b)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
typedef long long ll;

const int MAX_N = 1e+5 + 10;
const ll INF = 1LL << 60;

ll a[3 * MAX_N], left_max[3 * MAX_N], right_max[3 * MAX_N];

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < 3 * N; i++) {
        cin >> a[i];
    }
    ll left_score = 0, right_score = 0;
    priority_queue<ll> left_que, right_que;
    left_que.push(0);
    right_que.push(0);
    for (int i = 0; i < N; i++) {
        left_que.push(-a[i]);
        left_score += a[i];
    }
    for (int i = 3 * N - 1; i >= 2 * N; i--) {
        right_que.push(a[i]);
        right_score += a[i];
    }
    for (int i = N; i <= 2 * N; i++) {
        ll min_a = -left_que.top();
        left_que.pop();
        left_score -= min_a;
        left_max[i] = left_score;
        left_que.push(-a[i]);
        left_score += a[i];
    }
    right_max[2 * N] = right_score;
    for (int i = 2 * N - 1; i >= N; i--) {
        right_que.push(a[i]);
        right_score += a[i];
        ll max_a = right_que.top();
        right_que.pop();
        right_score -= max_a;
        right_max[i] = right_score;
    }
    // どこを境界にしたら最大スコアになるか全探索
    ll ans = -INF;
    for (int i = N; i <= 2 * N; i++) {
        ans = max(ans, left_max[i] - right_max[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7668
#include <iostream>
#include <vector>
#define INF 0x3f3f3f3f

using namespace std;
typedef pair<int, int> pii;
int main() {
  int n;
  cin >> n;
  vector<int> a(3 * n);
  for (int i = 0; i < 3 * n; ++i)
    cin >> a[i];
  vector<vector<int>> f(n + 1, vector<int>(n + 1, -INF));
  vector<int> local_opt(n + 1, -INF);
  f[a[0]][a[1]] = f[a[1]][a[0]] = 0;
  local_opt[a[0]] = 0, local_opt[a[1]] = 0;
  vector<pair<pii, int>> updates;
  int triplets = 0, opt = 0;
  for (int i = 2; i < 3 * (n - 1); i += 3) {
    vector<int> b(3);
    for (int j = 0; j < 3; ++j)
      b[j] = a[i + j];
    if (b[0] == b[1] && b[0] == b[2]) {
      triplets++;
      continue;
    }
    updates.clear();
    for (int p = 0; p <= 2; ++p) {
      int q = (p + 1) % 3, s = (p + 2) % 3;
      updates.push_back({{b[p], b[q]}, opt});
      updates.push_back({{b[p], b[q]}, f[b[s]][b[s]] + 1});
      for (int x = 1; x <= n; ++x) {
        updates.push_back({{b[p], x}, local_opt[x]});
        if (b[q] == b[s])
          updates.push_back({{b[p], x}, f[x][b[q]] + 1});
      }
    }
    for (const auto &u : updates) {
      int x = u.first.first, y = u.first.second, val = u.second;
      if (f[x][y] < val) {
        f[x][y] = f[y][x] = val;
        opt = max(opt, val);
        local_opt[x] = max(local_opt[x], val);
        local_opt[y] = max(local_opt[y], val);
      }
    }
  }
  opt = triplets + max(opt, f[a.back()][a.back()] + 1);
  printf("%d", opt);
}

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

using namespace std;


int main() {


	long long n, a, b,ans;

	cin >> n >> a >> b;

	long long amari = n % (a + b);
	long long syou = n / (a + b);

	if (amari < a) {
		ans = a * syou + amari;
	}
	else {
		ans = a * syou + a;
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

/////////////////////////////////////////////////////////

void Main() {
  ll N; cin >> N;
  vector<ll> A(N);
  rep(i, 0, N) cin >> A[i];
  sort(all(A));
  vector<ll> cusum(N);
  ll sum = 0;
  rep(i, 0, N){
    sum += A[i];
    cusum[i] = sum;
  }
  ll res = 1;
  for(int i = N - 2; i >= 0; i--){
    if(cusum[i] * 2 >= A[i + 1]) res++;
    else break;
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

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

  Main();
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    int c = 1;
    int prev = -1;
    while (N > 0)
    {
        int n = N % 10;
        if (n == prev)
            c++;
        else
        {
            c = 1;
            prev = n;
        }
        if (c == 3)
        {
            cout << "Yes" << endl;
            return 0;
        }
        N /= 10;
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

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

#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
#define deb(x) cout<<#x<<" "<<x<<"\n"
#define Clear(x) memset(x,0,sizeof(x))
#define all(x) (x).begin(),(x).end()

void checkpoint1()
{
	/******think more code less******/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}

bool comp(pair< ll,ll > &a,pair< ll,ll > &b)
{
	if(a.ff!=b.ff)
		return a.ff<b.ff;
	else
	{
		if(a.ss>b.ss)
			return b.ss<a.ss;
		else if(a.ss<b.ss)
			return a.ss<b.ss;
	}
	return a.ff>b.ff;
}

ll powe(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b&1)
		{
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}

int main()
{
	checkpoint1();
	ll a,b,c;
	cin>>a>>b>>c;
	ld op=(ld)a/c;
	if(b>=op)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3616
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=[]
y=0
for i in range(k-1):
    x.append(a[i+1]-a[i])
x.append(n-a[-1]+a[0])
x=sorted(x)
for j in range(k-1):
    y+=x[j]
print(y)

Measured memory_bytes: 26420
// https://atcoder.jp/contests/abc157/tasks/abc157_f
#include <bits/stdc++.h>
using namespace std;

#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) for(int i=int(n-1);i>=0;i--)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define D(a) cerr << #a << " = " << a << endl
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
typedef pair<int,int> pii;
typedef long long int ll;
typedef vector<int> vi;
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first

const double EPS = 1e-9;
#define le(a,b) ((a) < (b) - EPS)      // <
#define gr(a,b) ((a) > (b) + EPS)      // >
#define leq(a,b) ((a) < (b) + EPS)     // <=
#define geq(a,b) ((a) > (b) - EPS)     // >=
#define eq(a,b) (abs((a) - (b)) < EPS) // ==

struct pto {
	double x, y;
	pto(double _x=0, double _y=0) : x(_x),y(_y) {}
	pto operator+(pto a) { return pto(x + a.x, y + a.y); }
	pto operator-(pto a) { return pto(x - a.x, y - a.y); }
	pto operator*(double a) { return pto(x*a, y*a); }
	pto operator/(double a) { return pto(x/a, y/a); }
	double norm() { return sqrt(x*x + y*y); }
};
double dist(pto a, pto b) { return (b-a).norm(); }
pto CCW90(pto p) { return pto(-p.y, p.x); }

struct circle { 
    pto p; double r; 
    bool contains(pto &a) { return leq(dist(p, a), r); }
};

vector<pto> interCC(circle &a, circle &b) {
    vector<pto> r;
    double d = dist(a.p, b.p);
    if (gr(d, a.r + b.r) || le(d + min(a.r, b.r), max(a.r, b.r))) return r;
    double x = (d*d + a.r*a.r - b.r*b.r) / (2*d);
    double y = sqrt(a.r*a.r - x*x);
    pto v = (b.p - a.p) / d;
    r.pb(a.p + v*x + CCW90(v)*y);
    if (gr(y, 0)) r.pb(a.p + v*x - CCW90(v)*y);
    return r;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    
    int n,k; cin >> n >> k;
    vector<pto> a(n); 
    int b[n];
    forn(i, n) cin >> a[i].x >> a[i].y >> b[i];

    auto f = [&](double t) { // O(n^3)
        vector<circle> cir(n);
        forn(i, n) cir[i] = {a[i], t/b[i]};

        vector<pto> can(all(a));
        forn(i, n) forsn(j, i+1, n)
            for (pto &p : interCC(cir[i], cir[j])) 
                can.pb(p);

        int m = 0;
        for (auto &p : can) {
            int q = 0;
            for (auto &c : cir)
                if (c.contains(p)) q++;
            m = max(m, q);
        }
        return m < k;
    };

    double l = 0, h = 3e5;
    while (!eq(l, h)) {
        double m = (l+h)/2;
        if (f(m)) l = m;
        else h = m;
    }
    cout << fixed << setprecision(6) << h << endl;
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

string s;

int solve() {
    int res = 0;
    int len = s.size();
    for (int i = 0; i < len-1; i++) {
        if (s[i] != s[i+1])
            res++;
    }
    return res;
}

void input() {
    cin >> s;
}

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

    input();
    cout << solve() << endl;
}

Measured memory_bytes: 512
def main():
    inp = input()
    st = inp.split()
    n = int(st[0])
    a = int(st[1])
    b = int(st[2])
    c = int(st[3])
    d = int(st[4])
    inp = input()
    # 2 rocks
    rock_count = 0
    for i in range(a, b):
        if inp[i] == '#':
            rock_count += 1
        elif inp[i] == '.':
            rock_count = 0
        if rock_count == 2:
            print("No")
            return
    if inp[b] == "#" and (inp[b-1] == "#" or inp[b+1] == "#"):
        print("No")
        return

    max_cd = c if c > d else d
    continuous_count = 0
    nothing_count = 0
    nothing_3 = False
    if inp[b-1] == '.':
        nothing_count += 1
    if inp[b-2] == '.':
        nothing_count += 1
    for i in range(b, max_cd):
        if inp[i] == '#':
            continuous_count += 1
            nothing_count = 0
        elif inp[i] == '.':
            continuous_count = 0
            nothing_count += 1
        if continuous_count == 2:
            print("No")
            return
        if nothing_count == 3 and i < d + 1:
            nothing_3 = True

    # c < d
    if c < d or nothing_3:
        print("Yes")
    else:
        if (inp[d-1] == '.' and inp[d-2] == '.') and (inp[d] == '.' or inp[d-3] == '.'):
            print("Yes")
        else:
            print("No")
    return


if __name__ == '__main__':
    main()


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

int main(){
    int a, b;
    cin >> a >> b;
    int c = a * b;
    int d=c%2;
  if(d==0)
  cout<<"Even"<<endl;
  else
    cout<<"Odd"<<endl;
  
  
  return 0;
  
  
    }

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,M=get_i
ab=array(N)
N.times do|i|
    ab[i]=get_i
end
ab.sort!{|x,y| x[0]<=>y[0]}
m=M
ans=0
i=0
while m>0
    min=min(ab[i][1],m)
    ans+=min*ab[i][0]
    m-=min
    i+=1
end
puts ans

Measured memory_bytes: 10360
#include<iostream>
#include<set>
#include<string>
#include<iterator>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string str;
		set<string>s;
		cin >> str;
		for (int j = 1; j < (int)str.size(); j++) {
			string str1, str2, rstr1, rstr2;
			str1 = str.substr(0, j);
			str2 = str.substr(j);
			for (auto itr = str1.rbegin(); itr != str1.rend(); itr++)rstr1 += *itr;
			for (auto itr = str2.rbegin(); itr != str2.rend(); itr++)rstr2 += *itr;
			s.insert(str1 + str2); s.insert(rstr1 + str2); s.insert(str1 + rstr2); s.insert(rstr1 + rstr2);
			s.insert(str2 + str1); s.insert(rstr2 + str1); s.insert(str2 + rstr1); s.insert(rstr2 + rstr1);
		}
		cout << s.size() << endl;
	}
}

Measured memory_bytes: 3148
#include <iostream>
#include <vector>
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef vector<ll> vecl;
typedef vector<vecl> mat;

mat matMul(mat& A, mat& B) 
{
  int N = A.size(), K = B.size(), M = B[0].size();
  // should be A[0].size() == B.size()
  mat res(N, vecl(M, 0));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      for (int k = 0; k < K; k++) {
        // MODをとるときはここに注意
        (res[i][j] += A[i][k] * B[k][j]) %= MOD;
      }
    }
  }
  return res;
}

mat matPow(mat A, ll n)
{
  // shoud be A row == A col
  mat res(A.size(), vecl(A.size(), 0));
  for (int i = 0; i < A.size(); i++) res[i][i] = 1;
  while (n > 0) {
    if (n % 2) res = matMul(res, A);
    A = matMul(A, A);
    n /= 2;
  }
  return res;
}

// ======== verify ========

void solve_EDPC_R()
{
  ll N, K;
  cin >> N >> K;
  mat A(N, vecl(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A[i][j];
    }
  }
  mat B(matPow(A, K));
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      (ans += B[i][j]) %= MOD;
    }
  }
  cout << ans << endl;
}

// ========================

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


Measured memory_bytes: 512
#include"bits/stdc++.h"
 
 
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = (l);x<=(u);x++)
#define RREP(x,l,u) for(ll x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()
 
typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
 
const int maxn = 200010;
const int mod = 1e9+7;
const double eps = 1e-6;
const double PI = acos(-1);
 
template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
 
template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}
 
int n,X,Y,cnt,tot,ans=1;
 
int c[maxn],w[maxn],fac[maxn],in[maxn],has[maxn],vi[maxn],vi2[maxn];

int mn[maxn];

PII B[maxn];

vector<int> G[maxn];
 
void dfs(int u){
	if(vi[u])return;
	vi[u]=1;
	ans=1LL*ans*in[tot]%mod*fac[tot+1]%mod;
	ans=1LL*ans*fac[has[c[u]]]%mod*in[has[c[u]]+1]%mod;
//	cout<<u<<endl;
//	cout<<ans<<endl;
//	cout<<tot<<' '<<has[c[u]]<<endl;
	has[c[u]]++;
	tot++;
	for(auto v:G[u])dfs(v);
}

void dfs2(int u){
	if(vi2[u])return;
	vi2[u]=1;
	tot--;
	has[c[u]]--;
	for(auto v:G[u])dfs2(v);
}
 
void Work(){
	REP(i,1,n)if(!vi[i]){
		dfs(i);
		dfs2(i);
	}
	iout(ans);
}

void addedge(int u,int v){
//	cout<<u<<' '<<v<<endl;
	G[u].PB(v);G[v].PB(u);
}

void Init(){
	read(n,X,Y);
	fac[0]=1;REP(i,1,n)fac[i]=1LL*fac[i-1]*i%mod;
	in[n]=fexp(fac[n],mod-2);
	RREP(i,n,1)in[i-1]=1LL*in[i]*i%mod;
	REP(i,1,n){
		read(c[i],w[i]);
		if(!mn[c[i]]||w[mn[c[i]]]>w[i])mn[c[i]]=i;
	}
	REP(i,1,n)if(mn[i])B[++cnt]=MP(w[mn[i]],i);
	sort(B+1,B+cnt+1);
	REP(i,1,n)if(mn[c[i]]!=i&&w[i]+w[mn[c[i]]]<=X)addedge(i,mn[c[i]]);
	REP(i,1,n){
		if(c[i]!=B[1].se&&w[i]+w[mn[B[1].se]]<=Y)addedge(i,mn[B[1].se]);
		if(cnt>1&&c[i]!=B[2].se&&w[i]+w[mn[B[2].se]]<=Y)addedge(i,mn[B[2].se]);
	}
}
 
int main(){
	Init();
	Work();
	return 0;
}

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

const int N = 10;
int p[N], q[N], n, x[N], a, b;

int main() {
  	cin >> n;
  	for (int i = 0; i < n; i++)
      	cin >> p[i];
  	for (int i = 0; i < n; i++)
      	cin >> q[i];
  	iota(x, x + n, 1);
  	for (int i = 0; i < 8 * 5040; i++) {
		bool flag = true;	
      	for (int j = 0; j < n; j++)
        	if (x[j] != p[j])
              	flag = false;
     	if (flag)
          	a = i;
      	flag = true;
      	for (int j = 0; j < n; j++)
          	if (x[j] != q[j])
				flag = false;
     	if (flag)
          	b = i;
     	next_permutation(x, x + n);
    }
  	cout << abs(a - b) << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
#define lld long double
#define F first
#define S second
#define f(i,a,b) for(int i=a;i<=b;i++)
#define g(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mh make_heap
#define ph push_heap
#define pq priority_queue
#define bits(x) __builtin_popcountll(x)
#define op(x) cout<<"Case #"<<x<<": "
#define op1(x) cout<<"Scenario #"<<x<<": "
#define endl "\n"
using namespace std;
const ll mod = 1000000007;
const ll INF = LLONG_MAX;
const ll NEGINF = LLONG_MIN;
const int N = 18;
const ll MAXN = 1000001;
#define MAX 5


void solve(int t)
{
	ll n;
	cin >> n;

	ll mi = INF;
	ll ma = NEGINF;
	ll p[n], q[n];

	for (int i = 0; i < n; i++)
	{
		ll x, y;
		cin >> p[i] >> q[i];
		x = p[i], y = q[i];
		mi = min(x + y, mi);
		ma = max(x + y, ma);

	}

	ll ans = abs(mi - ma);
	mi = INF;
	ma = NEGINF;

	for (int i = 0; i < n; i++)
	{
		ll x, y;
		x = p[i], y = q[i];
		mi = min(x - y, mi);
		ma = max(x - y, ma);
	}

	ans = max(ans, abs(mi - ma));

	cout << ans << endl;




}


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





	int t = 1;
	//cin >> t;



	for (int i = 1; i <= t; i++)
	{
		solve(i);

	}
}

Measured memory_bytes: 6708
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//下限の数取得
		int a = sc.nextInt();
		
		//上限の数取得
		int b = sc.nextInt();
		
		b = b/2;
		
		int sum = a + b;
		
		System.out.println(sum);
		
		
	}

}

Measured memory_bytes: 22740
#include<cstdio>
#include<cstring>
#define MN 1000
char s[MN+5][MN+5];
int main()
{
	int n,m,a,b,i,j;
	scanf("%d%d%d%d",&n,&m,&a,&b);
	if((n&1)&&(m&1)&&n>1&&m>1&&a>1&&b>1)
	{
		int aa=a,bb=b;
		s[n-2][m-2]='^';s[n-2][m-1]='<';s[n-2][m]='>';
		s[n-1][m-2]='v';               ;s[n-1][m]='^';
		s[n  ][m-2]='<';s[n  ][m-1]='>';s[n  ][m]='v';
		for(a-=2,i=1;i<m-3;i+=2)if(a)s[n][i]='<',s[n][i+1]='>',--a;
		for(b-=2,i=1;i<n-3;i+=2)if(b)s[i][m]='^',s[i+1][m]='v',--b;
		for(i=1;i<n;i+=2)for(j=1;j<m;j+=2)if(i<n-3||j<m-3)
			if(a)
			{
				s[i][j]='<';s[i][j+1]='>';
				if(--a)s[i+1][j]='<',s[i+1][j+1]='>',--a;
			}
			else if(b)
			{
				s[i][j]='^';s[i+1][j]='v';
				if(--b)s[i][j+1]='^',s[i+1][j+1]='v',--b;
			}
		if(a||b)memset(s,0,sizeof(s)),a=aa,b=bb;
		else
		{
			puts("YES");
			for(i=1;i<=n;puts(s[i++]+1))for(j=1;j<=m;++j)if(!s[i][j])s[i][j]='.';
			return 0;
		}
	}
	if(n&1)for(i=1;i<m;i+=2)if(a)s[n][i]='<',s[n][i+1]='>',--a;
	if(m&1)for(i=1;i<n;i+=2)if(b)s[i][m]='^',s[i+1][m]='v',--b;
	for(i=1;i<n;i+=2)for(j=1;j<m;j+=2)
		if(a)
		{
			s[i][j]='<';s[i][j+1]='>';
			if(--a)s[i+1][j]='<',s[i+1][j+1]='>',--a;
		}
		else if(b)
		{
			s[i][j]='^';s[i+1][j]='v';
			if(--b)s[i][j+1]='^',s[i+1][j+1]='v',--b;
		}
	if(a||b)return 0*puts("NO");
	puts("YES");
	for(i=1;i<=n;puts(s[i++]+1))for(j=1;j<=m;++j)if(!s[i][j])s[i][j]='.';
}

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

int main() {
  int N;
  cin >> N;
  string s = to_string(N);
  bool a = false;
  rep(i,3){
    if(s.at(i)=='7') a =true;
  }
  if(a) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 3692
#include<stdio.h>
#include<stdlib.h>
 
#define MAX 100001
 
typedef struct{
  int parent;
  int left;
  int right;
} Node;
 
Node T[MAX];
 
int getDepth(int);
int getHeight(int);
int Degree(int);
int Sibling(int,int);
void PrintState(int);
 
int main(){
  int n,i,id,r,l;
 
  scanf("%d",&n);
 
  for(i = 0; i < n; i++){
    T[i].parent = -1;
    T[i].left = -1;
    T[i].right = -1;
  }
 
  for(i = 0; i < n; i++){
    scanf("%d%d%d",&id ,&r ,&l);
 
    T[r].parent = id;
    T[l].parent = id;
    T[id].left = r;
    T[id].right = l;
  }
 
  for(i=0; i<n; i++) PrintState(i);
 
  return 0;
}
 
int getDepth(int x){
  if(T[x].parent == -1) return 0;
  else return 1+getDepth(T[x].parent);
}
 
int getHeight(int x){
  int lefth = 0, righth = 0;
 
  if(x == -1) return 0;
 
  if(T[x].left != -1) lefth = getHeight(T[x].left)+1;
  if(T[x].right != -1) righth = getHeight(T[x].right)+1;
 
  if(lefth > righth) return lefth;
  else return righth;
 
}
 
int Degree(int x){
  if(T[x].left != -1 && T[x].right != -1) return 2;
  else if(T[x].left != -1 || T[x].right != -1) return 1;
  else return 0;
}
 
int Sibling(int parent,int x){
  if(parent == -1) return -1;
  else if(T[parent].left == x)return T[parent].right;
  else return T[parent].left;
}
 
void PrintState(int u){
  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, " ,u ,T[u].parent ,Sibling(T[u].parent,u) ,Degree(u) ,getDepth(u) ,getHeight(u));
 
  if(T[u].parent == -1) printf("root\n");
  else if(T[u].left == -1 && T[u].right == -1) printf("leaf\n");
  else printf("internal node\n");
}

Measured memory_bytes: 612
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int n;
int a[10005];
int b[10005];

long long ans;

int main()
{
	cin >> n;
	for (int i = 1;i <= n;i++)
		cin >> a[i];
	for (int i = 1;i <= n;i++)
	{
		cin >> b[i];
		a[i] -= b[i];
	}
	for (int i = 1;i <= n;i++)
		if (a[i] <= 0)
			ans += -a[i] / 2;
		else
			ans -= a[i];
	if (ans >= 0)
		puts("Yes");
	else
		puts("No");
	return 0;
}

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

int main() {
  int a,b,c,d; cin >> a >> b >> c >> d;
  if(a+b==c+d) cout << "Balanced" << endl;
  else if(a+b>c+d) cout << "Left" << endl;
  else cout << "Right" << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
# read = sys.stdin.read
input = sys.stdin.readline
# readlines = sys.stdin.readlines
days = int(input())

prev = [0, 0, 0]
while days:
    nxt = [0, 0, 0]
    a, b, c = map(int, input().split())
    nxt[0] = a + max(prev[1], prev[2])
    nxt[1] = b + max(prev[0], prev[2])
    nxt[2] = c + max(prev[0], prev[1])
    prev = nxt
    days -= 1

print(max(prev))

Measured memory_bytes: 3064
N = int(input())
ABC = [[None]*3 for i in range(N)]

for i in range(N):
    ABC[i][0], ABC[i][1], ABC[i][2] = map(int, input().split())

happiness = [[0] *3 for i in range(N+1)]

for i in range(N):
    for j in range(3):
        happiness[i+1][j] = max(happiness[i][j-1] + ABC[i][j], happiness[i][j-2] + ABC[i][j])

print(max(happiness[N]))

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

typedef long long LL;
typedef pair<int, int> II;

const int MAXN = 3000 + 10;
int x[MAXN], y[MAXN];

int main() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	
	memset(x, 0, sizeof x);
	for (int i = 0; 100 * a * i <= f; ++i)
		for (int j = 0; 100 * b * j + 100 * a * i <= f; ++j)
			x[100 * a * i + 100 * b * j] = 1;
	memset(y, 0, sizeof y);
	for (int i = 0; i * c <= f; ++i)
		for (int j = 0; j * d + i * c <= f; ++j)
			y[i * c + j * d] = 1;
	
	int a1 = 0, b1 = 100 * a;
	for (int i = 1; i <= f; ++i) if (x[i])
		for (int j = 0; j <= f; ++j) if (y[j])
			if (i + j <= f && j * 100 <= e * i && a1 * (i + j) < (a1 + b1) * j) a1 = j, b1 = i;
	printf("%d %d\n", a1 + b1, a1);
	return 0;
}

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

typedef long long ll; 

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

  
  int n,k; cin>>n>>k; 
  int a[n]; 
  for(int i=0;i<n;i++) cin>>a[i]; 
  int ans=0; 
  for(int i=0;i<n-1;i+=k-1){
    ans++; 
  }
  cout<<ans; 
  

  return 0; 
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;

int manh(int x1, int x2, int y1, int y2) {
	return abs(x1 - x2) + abs(y1 - y2);
}

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

	ll n, m;
	cin >> n >> m;

	ll sum = 0;
	sum += 1900LL * m + 100LL * (n - m);

	out(sum * (1LL << m));

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int n;
    while (cin >> n, n) {
        string s;
        cin >> s;
        vector<vector<bool>> dp(1 << 10, vector<bool>(10, false));
        bool ng = false;
        for (int i = 0, j = 0; i < n; ++i, ++j) {
            int bit = 0;
            while (j < n && s[j] != 'u') {
                if (bit >> (s[j] - '0') & 1) ng = true;
                dp[bit][s[j] - '0'] = true;
                bit |= (1LL << (s[j++] - '0'));
            }
            i = j;
        }
        if (ng) {
            cout << "UNSAFE" << endl;
            continue;
        }
        REP (s1, 1LL << 10) REP (t1, 10) if (dp[s1][t1]) {
            REP (s2, 1LL << 10) REP (t2, 10) if (dp[s2][t2]) {
                bool flag1 = !(s1 & s2) && (s2 >> t1 & 1);
                bool flag2 = !(s1 & s2) && (s1 >> t2 & 1);
                if (flag1 && flag2) ng = true;
                else if (flag1) dp[s1 | s2][t2] = true;
                else if (flag2) dp[s1 | s2][t1] = true;
            }
        }
        cout << (ng ? "UNSAFE" : "SAFE") << endl;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}


Measured memory_bytes: 3280
#include <stdio.h>
#include <stdlib.h>
int gcd2(int m,int n)
{
    int r;
    while(n!=0)
    {
        r=m%n;
        m=n;
        n=r;
    }
    return m;
}
int gcd(int a,int b,int c)
{
    return gcd2(gcd2(a,b),c);
}
int main()
{
   int K;
   scanf("%d",&K);
   int a,b,c;
   int sum=0;
   for(a=1;a<=K;a++)
   {
       for(b=1;b<=K;b++)
       {
           for(c=1;c<=K;c++)
           {
               sum=sum+gcd(a,b,c);
           }
       }
   }
   printf("%d",sum);
    return 0;
}


Measured memory_bytes: 1732
from collections import defaultdict

N = int(input())
a = [ int(input()) for i in range(N) ]
d = defaultdict(int)

cnt = 0
for i in a:
    if d[i] == 1:
        d[i] = 0
        cnt -= 1
    else:
        d[i] = 1
        cnt += 1


print(cnt)


Measured memory_bytes: 16628
#include <iostream>
#include <cstdio>
using namespace std;
const int P=998244353;
const int L=1000000;
int fact[L+5],invf[L+5];
int n,K,ans;
inline int quick_power(int x,int y)
{
	int ret=1;
	for (;y;y>>=1,x=1ll*x*x%P) if (y&1) ret=1ll*ret*x%P;
	return ret;
}
void pre()
{
	fact[0]=1;
	for (int i=1;i<=L;++i) fact[i]=1ll*fact[i-1]*i%P;
	invf[L]=quick_power(fact[L],P-2);
	for (int i=L;i>=1;--i) invf[i-1]=1ll*invf[i]*i%P;
}
inline int C(int n,int m){return n>=m?1ll*fact[n]*invf[m]%P*invf[n-m]%P:0;}
inline int calc(int n,int m,int t)
{
	if (m-n>=t||t<=0) return 0;
	return (C(n+m,m)-C(n+m,n+t)+P)%P;
}
int main()
{
	pre(),scanf("%d%d",&n,&K),ans=0;
	for (int R=K,B;R>=K-R&&R>=0;--R)
	{
		B=K-R;
		if (R==B) (ans+=calc(R,B-1,R-n+1))%=P;
		else (ans+=calc(R,B,R-n+1))%=P;
	}
	printf("%d\n",ans);
	fclose(stdin),fclose(stdout);
	return 0;
}

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

int main(){
    int a,b,x;
    cin >> a >> b >> x;
    if(x>=a){
        if(b>=x-a){
            cout << "YES" << endl;
        }

    else cout << "NO" << endl;
    }
    
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<ll, ll>P;
ll N;
ll memo=1;
void num(vector<P> &a, ll x, ll g,ll h){
	if(x==N){return;}
	auto z=a[x];
    if(z.first>=h){::memo++;num(a,x+1,z.first,z.second);}
  	else if(z.second<h){num(a,x+1,z.first,z.second);}
    else{num(a,x+1,g,h);}
}

int main(){
  cin>>N;
  vector<ll>X(N);
  vector<ll>L(N);
  vector<P>A(N);
  rep(i,N){
  	cin>>X[i]>>L[i];
  	ll p=X[i]-L[i];
  	ll q=X[i]+L[i];
  	A[i]=P(p,q);
  }
  sort(A.begin(),A.end());
  auto t=A[0];
  ll a01=t.first,a02=t.second;
  num(A,1,a01,a02);
  cout<<memo;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] A = new int[N];
        int[] buka = new int[N];
        for (int i = 0; i<N-1; i++) {
            A[i] = scanner.nextInt();
            buka[A[i]-1]++;
        }

        for (int i = 0; i<N; i++) {
           System.out.println(buka[i]);
        }
    }
}


Measured memory_bytes: 62836
s = input()
k = int(input())
if len(s) == 1:
    print(s)
elif k == 1:
    print(s[0])
else:
    flag = 0
    for i in range(min(len(s), k)):
        if s[i] == '1':
            pass
        else:
            flag = 1
            print(s[i])
            break
    if flag == 0:
        print('1')


Measured memory_bytes: 3060
import collections

n = int(input())
a = [ input() for _ in range(n)]
b = collections.Counter(a)
c = b.values()
c = list(c)
m = len(b)
ans = 0
for i in range(m):
    if c[i]%2==0:
        continue
    else:
        ans +=1
print(ans)

Measured memory_bytes: 19708
'use strict'

function main(input) {
  const nums = input.split('\n').map(n => parseInt(n, 10))
  let count = 0

  const A = nums[0]
  const B = nums[1]
  const C = nums[2]
  const X = nums[3]

  for (let i = 0; i <= A; i ++) {
    for (let j = 0; j <= B; j ++) {
      for (let k = 0; k <= C; k ++) {
        let sum = 500 * i + 100 * j + 50 * k
        if (sum === X) count ++
      }
    }
  }

  console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 9420
#include<cstdio>
#include<algorithm>
int main(){
    char s[6];
    scanf("%s",s);
    for(int i=0;s[i+1]!='\0';i++){
        if(s[i]=='A' && s[i+1]=='C'){
            printf("Yes");
            return 0;
        }
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    int r;
    cin >> r;
    cout << r*r <<endl;
    return 0;
}

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

using namespace std;

const int N = 100005;
int n, dp[N], h[N];
int cal(int x) {
  if (x > n) return 2e9;
  if (x == n) {
    return 0;
  }
  int &ret = dp[x];
  if (ret < 2e9) {
    return ret;
  }
  ret = cal(x+1) + abs(h[x] - h[x+1]);
  ret = min(ret, cal(x+2) + abs(h[x] - h[x+2]));
  return ret;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i <= n + 2; i++) {
    dp[i] = 2e9;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &h[i]);
  }
  printf("%d", cal(1));
  return 0;
}

Measured memory_bytes: 4096
// Lavina Jain
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ord_set;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAX 1000000007
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define cases int t; cin>>t; while(t--)
ll mini(ll a,ll b) { if(a<b) return a; return b; }
ll maxi(ll a,ll b) { if(a>b) return a; return b; }
ll mod(ll a) { return a % MAX ; }
ll power(ll a,ll b) { if(b==0) return 1; else if(b%2==0) return power(a*a,b/2); else return a*power(a*a,b/2); }
ll powermod(ll a,ll b) { if(b==0) return 1; else if(b%2==0) return mod(powermod(mod(a*a),b/2)); else return mod(a)*mod(powermod(mod(a*a),b/2)); }
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int main()
{
    fast_io;
    ll a, b, c;
    cin>>a>>b>>c;
    ll ans = a - b;
    ll k;
    cin>>k;
    if(k%2!=0)
        ans = -1*ans;
    cout<<ans<<endl;
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
const ll MOD = 1e9+7;

/**グローバル変数**/
int n,ans,cnt;
string s;

int main(){
//  ios::sync_with_stdio(false);
//  cin.tie(0);
  int lim;
  cin >> lim >> n;
  int a[n] = {};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a,a+n);
  ll b[n];
  for (int i = 1; i < n; i++) {
    b[i-1] = a[i]-a[i-1];
  }
  sort(b,b+n-1);
  ll sum = 0;
  for (int i = 0; i < n-(lim-1)-1; i++) {
    sum += b[i];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1408
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
using vvc = vector<vector<char> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()
//文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
//型キャスト　char('a'+1)
//reverse 回文

/*各位の和　
int sum = 0;
for(int i = 0; i <= 5; i++){
   sum += n%10;
   n /= 10;  
}
*/

//グローバル変数宣言
ll p=0,q=0,r=0;

int main()
{
  ll n,d;
  cin>>n>>d;
  vvl x(n,vl(d));
  rep(i,n)
  {
  rep(j,d)
  {
    cin>>x[i][j];
  }
  }

  
  rep(i,n-1){
    for (int j = i+1; j < n; j++)
    {
      rep(k,d){
        p+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      rep(l,3000){
        if(p==l*l)q++;
      }
      p=0;
    }
  }
  print(q)
}

Measured memory_bytes: 3628
import java.io.*;

public class Main{
public static void main(String[] args){
try{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String[] str = br.readLine().split(" ");
	int a = Integer.parseInt(str[0]);
	int b = Integer.parseInt(str[1]);
	int c = Integer.parseInt(str[2]);

	int count = 0;
	for(int i = a; i <=b ; i++){
		if (c % i == 0){
		count++;
		}
	}
System.out.println(count);
}catch(IOException e){
System.out.println(e);
}
}
}

Measured memory_bytes: 17088
#include "iostream"
using namespace std;
int main(){
	int ans=0,k,s,x,y,z;
	cin>>k>>s;
	for(x=0;x<=k;x++)
		for(y=0;y<=k;y++)
			if(s-x-y>=0&&s-x-y<=k)
					ans++;
				
	cout<<ans<<endl;
}

Measured memory_bytes: 256
using System.Collections.Generic;
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        var boats = new List<List<int>>();
        var rabs = new List<int>();
        string[] line = Console.ReadLine().Trim().Split(' ');
        var k = int.Parse(line[1]);
        for (int i = 0; i < k; i++)
        {
            string[] s = Console.ReadLine().Trim().Split(' ');
            var k2 = int.Parse(s[0]);
            var temp = new List<int>();
            for (int j = 0; j < k2; j++) temp.Add(int.Parse(s[j + 1]));
            boats.Add(temp);
        }
        var nn = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < nn; i++)
        {
            string[] s2 = Console.ReadLine().Trim().Split(' ');
            var r1 = int.Parse(s2[0]);
            var r2 = int.Parse(s2[1]);
            foreach(var x in boats)
                if (x.Contains(r1)  && x.Contains(r2)) { rabs.Add(r1); rabs.Add(r2); break; }
        }
        var ans = rabs.Distinct().Count();
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 10168
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

typedef long long ll;

int A[50], n;
ll dp[50][50][100];
bool bp[50][50][100];

ll gk[50][50][100];
bool rk[50][50][100];

ll give(int i, int j, int k) {
    if(k < 0) return 0;
    if(i > j) return 0;
    if(rk[i][j][k]) return gk[i][j][k];
    rk[i][j][k] = 1;
    vector <int> vi;
    
    for(int l = 0; l < i; ++l)
        vi.push_back(A[l]);
    for(int r = j + 1; r < n; ++r)
        vi.push_back(A[r]);
    ll mx = 0;
    sort(vi.begin(), vi.end());
    for(int l = 0; l < vi.size() && l <= k && vi[l] < 0; ++l)
        mx -= vi[l];
    
    return gk[i][j][k] = mx;
}

ll take(int i, int j, int k) {
    if(k < 0) return 0;
    if(i > j) return 0;
    if(bp[i][j][k]) return dp[i][j][k];
    bp[i][j][k] = 1;
    ll mx = 0;
    mx = max({ mx,
        A[i] + take(i + 1, j, k - 1),
        A[j] + take(i, j - 1, k - 1),
        give(i, j, k)
    });

    return dp[i][j][k] = mx;
}

int main() {
    int k; cin >> n >> k;
    for(int i = 0; i < n; ++i)
        cin >> A[i];
    
    cout << take(0, n - 1, k - 1);
    
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a%b==0){
        cout<<0;
    }
    else{
        cout<<1;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int p,q,s,t,u,v,w,x;
    string r;
    while(cin>>r)
    {
       p=r[0]-48;
       q=r[1]-48;
       s=(p*10)+(q);
       t=r[2]-48;
       u=r[3]-48;
       v=(t*10)+u;
     //  cout<<s<<" "<<v<<endl;
       if(s>=1&&s<=12&&v>=1&&v<=12)
       {
           cout<<"AMBIGUOUS"<<endl;
       }
       else if(v>=1&&v<=12)
       {
           cout<<"YYMM"<<endl;
       }
       else if(s>=1&&s<=12)
       {
           cout<<"MMYY"<<endl;
       }
       else
       {
           cout<<"NA"<<endl;
       }





        //cout<<r<<endl;
    }









    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e3+10;
const int modn=1e9+7;
int a[maxn],b[maxn];
ll dp[maxn][maxn];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=m;i++)scanf("%d",&b[i]);
	for(int i=0;i<=n;i++)dp[i][0]=1;
	for(int i=0;i<=m;i++)dp[0][i]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			dp[i][j]=((dp[i-1][j]+dp[i][j-1])%modn-dp[i-1][j-1]+modn)%modn;
			if(a[i]==b[j])dp[i][j]=(dp[i][j]+dp[i-1][j-1])%modn;
		}
	}
	printf("%lld\n",dp[n][m]);
}

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




int main() {
	int n, m, q;
	cin >> n >> m >> q;

	vector<int> tmp(n + 2,0);
	vector< vector<int> > nm(n + 2,tmp);
	vector< vector<int> > imos(n + 2,tmp);

	for (int i = 0; i < m; i++) {
		int l,r;
		cin >> l >> r;
		nm[l][r]++;
	}


	for (int i = 0; i < n + 2 ; i++) {
		int count = 0;
		for (int j = 0; j< n + 2; j++) {
			count += nm[i][j];			 
			imos[i][j] = count;
		}
	}

	for (int i = 0; i < q; i++) {
		int p,q;
		cin >> p >> q;
		int count = 0;
		for (int i = p; i <= q; i++) {
			count += imos[i][q] - imos[i][p - 1];
			//cout <<  imos[i][q] << ":" <<  imos[i][p - 1] << endl;
		}
		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int64_t a, b;
    cin >> a >> b;
    int64_t x = a * b;

    if (a < b){
        int64_t temp = a;
        a = b;
        b = temp;
    }

    int64_t r = a % b;
    while (r != 0){
        a = b;
        b = r;
        r = a % b;
    }

    cout << (x / b) << endl;
}

Measured memory_bytes: 256
def set(Map, x, y) :
	for i in range(N) :
		Map[y[i]][x[i]] = 1
	return Map

def search(Map, dir, dis) :
	X = 10
	Y = 10
	for i in range(M) :
		if(dir[i] == "S") :
			if(Y + dis[i] <= 20) :
				for j in range(dis[i]+ 1) :
					Map[Y + j][X] = 0
				Y += dis[i]
			else :
				for j in range(20 - Y) :
					Map[Y + j][X] = 0
				Y = 20
		elif(dir[i] == "E") :
			if(X + dis[i] <= 20) :
				for j in range(dis[i]+ 1) :
					Map[Y][X + j] = 0
				X += dis[i]
			else :
				for j in range(20 - X) :
					Map[Y][X + j] = 0
				X = 20
		elif(dir[i] == "N") :
			if(Y - dis[i] >= 0) :
				for j in range(dis[i]+ 1) :
					Map[Y - j][X] = 0
				Y -= dis[i]
			else :
				for j in range(Y + 1) :
					Map[Y - j][X] = 0
				Y = 0
		else :
			if(X - dis[i] >= 0) :
				for j in range(dis[i]+ 1) :
					Map[Y][X - j] = 0
				X -= dis[i]
			else :
				for j in range(X + 1) :
					Map[Y][X - j] = 0
				X = 0
	return Map
			
while True :
	N = int(input())
	if(N == 0) :
		break
	else :
		Map = [[0 for i in range(21)] for j in range(21)]
		
		jewelryX = list()
		jewelryY = list()
		for i in range(N) :
			X, Y = map(int, input().split())
			jewelryX.append(X)
			jewelryY.append(20 - Y)
		
		M = int(input())
		order_dir = list()
		order_dis = list()
		for i in range(M) :
			dir, dis = map(str, input().split())
			# 方角 direction
			# 距離 distance
			order_dir.append(dir)
			order_dis.append(int(dis))
			
		set(Map, jewelryX, jewelryY)
		
		search(Map, order_dir, order_dis)
		
		S = 0
		for i in range(21) :
			S += sum(Map[i])
		
		if(S == 0) :
			print("Yes")
		else :
			print("No")



Measured memory_bytes: 5632