akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout cout << fixed << setprecision(15)

//typedef===============
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define For(i, a, b)    for(int i = (a); (i) < (b) ; ++(i))
#define CtoI(c)         int((c)) - int('0')

//functions=============
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };



/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    string t; cin >> t;
    for(auto &x : t){
        if(x == '?') x = 'D';
    }

    cout << t << endl;

return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int x,y;
int B[4] = {4,6,9,11};







int main()
{

	cin >> x >> y;

	int classx;
	int classy;

	switch(x){
	case 2:
		classx=1;
		break;
	case 4:
		classx=2;
		break;
	case 6:
		classx=2;
		break;
	case 9:
		classx=2;
		break;
	case 11:
		classx=2;
		break;
	default:
		classx=3;
		break;
	}
	switch(y){
	case 2:
		classy=1;
		break;
	case 4:
		classy=2;
		break;
	case 6:
		classy=2;
		break;
	case 9:
		classy=2;
		break;
	case 11:
		classy=2;
		break;
	default:
		classy=3;
		break;
	}
	if(classx==classy)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
results=[]
while True:
    a=input().split("\"")
    if a[0]==".":
        break
    b=input().split("\"")
    count1=0
    count2=0
    if len(a) != len(b):
        results.append(2)
    else:
        for i in range(len(a)):
            if(i%2==1):
                if len(a[i]) != len(b[i]):
                    count1+=1
                else:
                    for k,l in zip(a[i],b[i]):
                        if(k!=l):
                            count1+=1
            else:
                if len(a[i]) != len(b[i]):
                    count2+=1
                else:
                    for k,l in zip(a[i],b[i]):
                        if(k!=l):
                            count2+=1           
        if count1==0 and count2==0:
            results.append(0)
        elif count1==1 and count2==0:
            results.append(1)
        else:
            results.append(2)
for i in results:
    if i==0:
        print("IDENTICAL")
    if i==1:
        print("CLOSE")
    if i==2:
        print("DIFFERENT")


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

using namespace std;

//ABC007-Cの問題

struct mazepoint {
	int y;
	int x;
};

void mazedisp(vector<vector<int>> &maze, int h, int w) {
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << maze[i][j];
		}
		cout << endl;
	}
	cout << endl;
}

int main() {
	while (1) {
		int w, h;
		cin >> w >> h;

		if (w == 0 && h == 0) { return 0; }

		w = w * 2 + 3;
		h = h * 2 + 3;

		int sy, sx;
		int gy, gx;
		sy = 0; sx = 2;
		gy = h - 1; gx = w - 3;

		vector<int> mukix{ 1,0,-1,0 };
		vector<int> mukiy{ 0,1,0,-1 };

		//迷路読み込み
		vector<vector<int>> maze(h, vector<int>(w));
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				//			mazedisp(maze, h, w);
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1
					|| i == 1 || i == h - 2 || j == 1 || j == w - 2) {
					maze[i][j] = 1;
					continue;
				}
				if (i % 2 == 0 && j % 2 == 0) {
					maze[i][j] = 0;
					continue;
				}
				if (i % 2 != 0 && j % 2 != 0) {
					maze[i][j] = 1;
					continue;
				}
				cin >> maze[i][j];
			}
		}
		maze[0][2] = 0;
		maze[1][2] = 0;
		maze[h - 1][w - 3] = 0;
		maze[h - 2][w - 3] = 0;

//		mazedisp(maze, h, w);

		//幅優先探索処理
		vector<vector<bool>> seen(h, vector<bool>(w));	//発見したらtrue
		deque<mazepoint> todo;					//行く所のスタック

		todo.push_back({ sy, sx });
		mazepoint s = todo.front();							//今いる場所

		seen[s.y][s.x] = true;
		vector<vector<int>> fukasa(h, vector<int>(w, 0));
		bool brkflg = false;
		while (todo.empty() != true) {				//スタックが空になるまで処理	
			s = todo.front();						//処理番号を指定
			int tugiflg = false;					//次があったらtrueにするフラグ
			for (int i = 0; i < 4; i++) {
				if (s.y + mukiy[i] < 0 || s.x + mukix[i] < 0
					|| s.y + mukiy[i] >h - 1 || s.x + mukix[i] > w - 1) {
					continue;
				}
				if (s.y + mukiy[i] == gy && s.x + mukix[i] == gx) {
					cout << (fukasa[s.y][s.x] - 1) / 2 << endl;
					brkflg = true;
					break;
				}

				if (maze[s.y + mukiy[i]][s.x + mukix[i]] == 1) { continue; }

				if (seen[s.y + mukiy[i]][s.x + mukix[i]] != true) {
					seen[s.y + mukiy[i]][s.x + mukix[i]] = true;
					todo.push_back({ s.y + mukiy[i],s.x + mukix[i] });
					fukasa[s.y + mukiy[i]][s.x + mukix[i]] = fukasa[s.y][s.x] + 1;
					tugiflg = true;
					//				cout << s.y + mukiy[i] << " " << s.x + mukix[i] << endl;
				}
			}
			if (brkflg) { break; }
			todo.pop_front(); //次を全部探したので削除する
	//		mazedisp(fukasa, h, w);
		}
		if (brkflg != true) {
			cout << 0 << endl;
		}
		//	mazedisp(fukasa, h, w);
	}
	return 0;

}


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

int cnt(int p, vector<long long> &q){
    int as;
    int le = 0;
    int ri = q.size() - 1;
    int mid = (le + ri) / 2;
    if (p < q.at(0)){
        return 0;
    }
    else if (p >= q.at(ri)){
        return ri + 1;
    }
    while (p < q.at(mid) || p >= q.at(mid + 1)){
        if (p >= q.at(mid + 1)){
            le = mid;
        }
        else{
            ri = mid;
        }
        mid = (le + ri) / 2;
    }
    return mid + 1;
}

int main(){
    int n;
    cin >> n;
    vector<long long> a(n);
    vector<long long> b(n);
    vector<long long> c(n);
    rep(i, n){
        cin >> a.at(i);
    }
    rep(k, n){
        cin >> b.at(k);
    }
    rep(j, n){
        cin >> c.at(j);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    long long ans = 0;
    vector<long long> bb(n+1);
    bb.at(n) = 0;
    for (int g = 0; g < n; g++){
        bb.at(g) = n - cnt(b.at(g), c);
    }
    for (int h = n - 2; h >=0; h--){
        bb.at(h) += bb.at(h+1);
    }
    for (int l = 0; l < n; l++){
        ans += bb.at(cnt(a.at(l), b));
    }
    cout << ans << endl;
}


Measured memory_bytes: 3328
#include <stdio.h>

int main(void)
{
	static char p[100001];
	int i, j;
	int n, count;
	
	for (i = 0; i < 100001; i++){
		p[i] = 1;
	}
	p[0] = p[1] = 0;
	
	for (i = 2; i * i < 1000001; i++){
		if (p[i]){
			for (j = 2; j <= 100000 / i; j++){
				p[i * j] = 0;
			}
		}
	}
	while (scanf("%d", &n) != EOF){
		
		count = 0;
		for (i = 0; i < n; i++){
			if (p[i + 1] && p[n - i]){
				count++;
			}
		}
		
		printf("%d\n", count);
	}
	
	return (0);
}

Measured memory_bytes: 0
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int N; cin >> N;
    vector<Int> p(N), sp(N);
    rep(i, 0, N) cin >> p[i], sp[i] = p[i];
    sort(sp.begin(), sp.end());

    Int diff = 0;
    rep(i, 0, N) {
        if (p[i] != sp[i]) ++diff;
    }
    if (diff == 0 or diff == 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

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

vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll ex = 0;
    while (n % i == 0) {
      ++ex;
      n /= i;
    }
    res.push_back({i, ex});
  }
  if (n != 1) res.push_back({n, 1});
  return res;
}

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

  map<int, int> mp;
  while (n) {
    for (auto v : prime_factorize(n--)) {
      mp[v.first] += v.second;
    }
  }

  ll ans = 1;
  for (auto v : mp) {
    ans = ans % MOD * (v.second + 1);
  }

  cout << ans % MOD << endl;

  return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  int n; cin >>n; n++;
  vector<li> v(n);
  li br=0;
  rep(i,n) cin >>v[i];
  rep(i,n) br+=v[i];
  br--;
  if(n==1 and v[0]==1){
    print(1); return 0;
  }
  if(n==1 or v[0]){
    print(-1); return 0;
  } 
  li node=1,s=0;
  rep(i,n){
    s+=node;
    li tmp=min(node-v[i],br);
    if(tmp<0){
      print(-1); return 0;
    } 
    node+=tmp-v[i]; br-=tmp;
  }
  print(s);
}


Measured memory_bytes: 4040
n,q = gets.chomp.split(" ").map(&:to_i)
adjacent = Array.new(n+1){Array.new}
value = Array.new(n+1,0)
adjacent[1] << 0
(n-1).times do
  i,j = gets.chomp.split(" ").map(&:to_i)
  adjacent[j] << i
  adjacent[i] << j
end
q.times do
  i,j = gets.chomp.split(" ").map(&:to_i)
  value[i] += j
end
depth = [1]
checked = Array.new(n+1,false)
checked[0] = true
while(child = depth.shift)
  checked[child] = true
  adjacent[child].each do |node|
    unless checked[node]
      depth << node
    end
  end
  value[child] += value[adjacent[child].find{|e| checked[e]}]
end
puts value[1..n].join(" ")


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

int main(){
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int x3, y3, x4, y4;
  x3 = x2 - (y2 - y1);
  y3 = y2 + (x2 - x1);
  x4 = x3 - (x2 - x1);
  y4 = y3 - (y2 - y1);

  printf("%d %d %d %d\n", x3, y3, x4, y4);
}


Measured memory_bytes: 256
#include <stdio.h>
typedef long long int ll;
char a[11];

ll as(int b, ll c, ll d){
	if(a[b]=='\0') return c+d;
	else return as(b+1,c*10+a[b]-'0',d)+as(b+1,a[b]-'0',d+c);
}
int main(){
     scanf("%s",a);
     printf("%lld\n",as(1,a[0]-'0',0));
     return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int dp[1000001],N,h[1000000];
int main(){

    int t;
    cin>>N;
    for(int i=0; i<N; i++){
        cin>>h[i];
    }
    dp[0] = 0, dp[1] = abs(h[0] - h[1]);

    for(int i=2; i<N; i++){

        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[N-1]<<"\n";

}


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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int a = 0, w = 0, t = 0, r = 0;
  while (n--) {
    string s;
    cin >> s;
    a += s[0] == 'A';
    w += s[0] == 'W';
    t += s[0] == 'T';
    r += s[0] == 'R';
  }
  cout << "AC x " << a << '\n';
  cout << "WA x " << w << '\n';
  cout << "TLE x " << t << '\n';
  cout << "RE x " << r << '\n';
}


Measured memory_bytes: 3652
N = int(input())
A, x, y = [], [], []
for i in range(N):
    A.append(int(input()))
    x_, y_ = [], []
    for j in range(A[i]):
        x__, y__ = map(int, input().split())
        x_.append(x__ - 1)
        y_.append(y__)
    x.append(x_)
    y.append(y_)
ans = 0
for i in range(2 ** N):
    t = 1
    for j in range(N):
        if not i & (1 << j):
            continue
        for a, b in zip(x[j], y[j]):
            if b == 1 and not i & (1 << a):
                t = 0
                break
            if b == 0 and i & (1 << a):
                t = 0
                break
        if not t:
            break
    if t:
        ans = max(ans, bin(i).count("1"))
print(ans)


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

void makeSpiral(vector<vector<int> >& cave)
{
    const int dy[] = {0, -1, 0, 1};
    const int dx[] = {1, 0, -1, 0};

    cave.assign(2000, vector<int>(2000, -1));
    int y = 1000;
    int x = 1000;
    int n = 1;
    cave[y][x] = n;

    for(int i=0; ; ++i){
        int len = i / 2 + 1;
        for(int j=0; j<len; ++j){
            y += dy[i%4];
            x += dx[i%4];
            ++ n;
            cave[y][x] = n;
            if(n == 1000000)
                return;
        }
    }
}

void findPrime(int N, vector<bool>& isPrime)
{
    isPrime.assign(N+1, true);
    isPrime[0] = isPrime[1] = false;
    for(int i=2; i*i<=N; i++){
        if(isPrime[i]){
            for(int j=i; i*j<=N; j++){
                isPrime[i*j] = false;
            }
        }
    }
}

int main()
{
    vector<vector<int> > cave;
    makeSpiral(cave);

    vector<bool> isPrime;
    findPrime(1000000, isPrime);

    for(;;){
        int n, start;
        cin >> n >> start;
        if(n == 0)
            return 0;

        int sy, sx;
        for(int y=0; y<2000; ++y){
            for(int x=0; x<2000; ++x){
                if(cave[y][x] == start){
                    sy = y;
                    sx = x;
                }
            }
        }

        vector<int> dp(2000, -1);
        if(isPrime[start])
            dp[sx] = 1;
        else
            dp[sx] = 0;
        pair<int, int> ret(dp[sx], start);

        for(int y=sy; y<2000; ++y){
            vector<int> nextDp(2000, -1);
            for(int x=0; x<2000; ++x){
                if(dp[x] == -1)
                    continue;
                for(int i=-1; i<=1; ++i){
                    if(cave[y+1][x+i] == -1 || cave[y+1][x+i] > n)
                        continue;
                    if(isPrime[cave[y+1][x+i]]){
                        nextDp[x+i] = max(nextDp[x+i], dp[x] + 1);
                        ret = max(ret, make_pair(nextDp[x+i], cave[y+1][x+i]));
                    }
                    else{
                        nextDp[x+i] = max(nextDp[x+i], dp[x]);
                    }
                }
            }
            dp.swap(nextDp);
        }

        if(ret.first == 0)
            cout << "0 0" << endl;
        else
            cout << ret.first << ' ' << ret.second << endl;
    }

    return 0;
}

Measured memory_bytes: 17048
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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 (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll a, b, x;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b >> x;
    if (a % x != 0)
        a = a + x - a % x;
    if (a > b)
    {
        cout << 0 << "\n";
        return 0;
    }
    cout << (b - a) / x + 1 << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
bool rev[100010];
main(){
    int N,A[100010];
    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> A[i];
        if(A[i] == i+1){
            rev[i] = 1;
        }
    }
    int cnt = 0;
    if(rev[0]){
        rev[0] = rev[1] = 0;
        cnt++;
    }
    for(int i = 1;i < N-1;i++){
        if(rev[i]){
            if(rev[i+1]){
                rev[i] = rev[i+1] = 0;
            }else{
                rev[i] = 0;
            }
            cnt++;
        }
    }
    if(rev[N-1])cnt++;
    cout << cnt << endl;
}

Measured memory_bytes: 768
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s=new Scanner(System.in);
	    
	    HashMap<String , Integer> map=new HashMap<>();
	    int n=s.nextInt();
	    for(int i=0;i<n;i++)
	    {
	        String ans=s.next();
	        if(!map.containsKey(ans))
	        map.put(ans,1);
	    }
	    System.out.println(map.size());
	}
}


Measured memory_bytes: 66160
#include<stdio.h>

int main(void){
	int x,y,z,i;
	while(1){
	i=0;
	scanf("%d %d",&x,&y);
	if(x == 0 && y == 0){
	break;
	}
	if(x < y){
	z=x;
	x=y;
	y=z;
	}
	while(1){
		if(x%y == 0){
		x=x%y;
		z=x;
		x=y;
		y=z;
		i++;
		break;
			}
		x=x%y;
		z=x;
		x=y;
		y=z;
		i++;
		}
		printf("%d %d\n",x,i);
	}
return 0;
}

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

int solve(){
  int res=0,memo[12][12];
  vector <int> a,b,imemo[12][12];
  memset(memo,-1,sizeof(memo));
  a.push_back(n[0]-'0'),a.push_back(n[0]-'0'),b.push_back(0);
  for(int i=2;i<n.size();i+=2) a.push_back((a.back()+n[i]-'0')%11),a.push_back(a.back());
  for(int i=1;i<n.size();i+=2) b.push_back((b.back()+n[i]-'0')%11),b.push_back(b.back());
  if(n.size()%2==0) b.erase(--b.end());
  else a.erase(--a.end());
  
  for(int i=0,A=0,B=0;i<n.size()-1;i++){
    if(n[i]=='0')continue;

    if(memo[A][B]==-1){
      memo[A][B]=0;
      for(int j=i+1;j<n.size();j++)
	if(((a[j]+A)-(b[j]+B))%11==0) memo[A][B]++,imemo[A][B].push_back(j);
      reverse(imemo[A][B].begin(),imemo[A][B].end());
    }

    while(imemo[A][B].size()&&imemo[A][B].back()<i)memo[A][B]--,imemo[A][B].erase(--imemo[A][B].end());
    res+=memo[A][B];
    if(i%2==0)A=11-a[i]%11;
    else B=11-b[i]%11;
  }  
  return res;
}


int main(){
  while(1){
    cin>>n;
    if(n=="0")break;
    cout<< solve()<<endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    int a,b,t,n,m;
    cin>>n;
    int cost[n+1]={0};
    cost[1]=0;
    cost[0]=0;
    vector<int> v;
    v.push_back(0);
    cin>>a;
    v.push_back(a);
    cin>>a;
    v.push_back(a);
    cost[2]=abs(v[2]-v[1]);

    for(int i=3;i<=n;i++){
        cin>>a;
        v.push_back(a);
        cost[i]=min(cost[i-1]+abs(a-v[i-1]),cost[i-2]+abs(a-v[i-2]));
    }
    cout<<cost[n];
    return 0;
}

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

#define int long long

int countDigit(int n) 
{ 
    int count = 0; 
    while (n != 0) { 
        n = n / 10; 
        ++count; 
    } 
    return count; 
}

signed main() {
	int n;
	cin >> n;
	int c = countDigit(n);
	int ans = 0;
	int a[] = {0,9,90,900,9000,90000};
	int b[] = {0,1,9,99,999,9999,99999};
	if(c>1) {
		for(int i = 1; i<c; i+=2) {
			ans += a[i];
		}
		if(c%2==0) {
			cout << ans << endl;
		}
		else {
			ans += (n-b[c]);
			cout << ans << endl;
		}
	}
	else {
		cout << n << endl;
	}
	return 0;
}

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

int main(){
    int L,R;
    cin >> L >> R;
    vector<int> mod(0);
    int min_mod;
    if (R - L <= 2019){
        for (int i = L; i <= R; i++){
            for (int j = i + 1; j <= R; j++){
                mod.push_back((i % 2019)*(j % 2019) % 2019);
            }
        }
        min_mod = mod.at(0);
        for (int i = 0; i < mod.size() ; i++ ){
            min_mod = min(min_mod, mod.at(i));
        }
    }
    else{
        min_mod = 0;
    }
    cout << min_mod << endl;
}


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

int main()
{
    char s[120]={};
    int k,i;
    scanf("%d",&k);
    scanf("%s",&s);
    if(strlen(s)<=k) printf("%s",s);
    else{
        for(i=0;i<k;i++){
            printf("%c",s[i]);
        }
        printf("...");
    }
    return 0;
}


Measured memory_bytes: 1732
#include<stdio.h>
#define MAX 10000
main(){
  int n, i;
  int x[MAX+1];
  scanf("%d", &n);
  for ( i = 1; i <= n; i++ )
     scanf("%d", &x[i]);

  for ( i=1; i<=n; i++ ) {
    printf("node %d: key = %d, ", i, x[i]);
    if ( i/2 >= 1 )
        printf("parent key = %d, ", x[i/2]);
    if ( i*2 <= n )
         printf("left key = %d, ", x[i*2]);
    if ( i*2+1 <= n )
         printf("right key = %d, ", x[i*2+1]);

    printf("\n");
  }

  return 0;
}


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

#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007

ll power(ll a,ll b){ll ans=1;while(b>0){if(b&1){ans = (ans*a);}b>>=1;a=a*a;}return ans;}
ll gcd(ll a,ll b){if(b==0){return a;}return gcd(b,a%b);}

int main() {
   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   // cout << fixed << setprecision(10);
   ll k;
   string s;
   cin>>k;
   cin>>s;
   ll n=s.length();
   if(n <= k){
       cout<<s<<endl;
   }else{
       cout<<(s.substr(0,k) + "...")<<endl;
   }
	return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

typedef int Weight;
struct Edge{
  int src;int dst;
  Weight wei;
  Edge(int s=0,int d=0,Weight w=0):
    src(s),dst(d),wei(w){}
};
using Graph = vector<vector<Edge>>;
int prim(const Graph &g,const int r=0){
  struct comp{
    bool operator()(const Edge &e,const Edge &f)const {return e.wei>f.wei;}
  };
  Weight sum=0;
  vector<int> used(g.size());
  priority_queue<Edge,vector<Edge>,comp> q;
  q.emplace(-1,r,0);
  while(q.size()){
    Edge e=q.top();
    q.pop();
    if(used[e.dst])continue;
    used[e.dst]=1;
    sum+=e.wei;
    for(auto &f : g[e.dst]){
      if(!used[f.dst])q.emplace(f);
    }
  }
  return sum;
}

signed main(){
  int v,e;
  cin>>v>>e;
  Graph g(v);
  REP(i,e){
    int s,t,w;
    cin>>s>>t>>w;
    g[s].emplace_back(s,t,w);
    g[t].emplace_back(t,s,w);
  }
  cout<<prim(g,0)<<endl;
  return 0;
}

Measured memory_bytes: 13860
s = input().split()
a = int(s[0])
b = int(s[1][0]) * 100
if s[1][1] == '.':
    b += int(s[1][2]) * 10
    if len(s[1]) == 4:
        b += int(s[1][3])
c = str(a*b)
if len(c) < 3:
    print(0)
else:
    print(c[:-2])

Measured memory_bytes: 9224
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
#include<iomanip>
#include<tuple>
#include<stack>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;
typedef tuple<int, int, int> ti3;

//const ll MOD_CONST = 1000000007;
const ll MOD_CONST = 998244353;


const int INF = 1000000000;
//const ll INF = 1000000000000000000;



int main() {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<int> p(a);
	for (int i = 0; i < a; i++) {
		cin >> p[i];
	}

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

	vector<int> r(c);
	for (int i = 0; i < c; i++) {
		cin >> r[i];
	}

	sort(p.begin(), p.end(),greater<int>());
	sort(q.begin(), q.end(),greater<int>());
	

	priority_queue<int,vector<int>,greater<int>> pq;
	

	for (int i = 0; i < x; i++) {
		pq.push(p[i]);
	}

	for (int i = 0; i < y; i++) {
		pq.push(q[i]);
	}

	for (int i = 0; i <c; i++) {
		pq.push(r[i]);
		pq.pop();


	}

	ll ans = 0;
	while (!pq.empty()) {
		ans += pq.top();
		pq.pop();
	}
	cout << ans << endl;
}



Measured memory_bytes: 2552
import math
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0

for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if i*500+j*100+k*50 == x:
        ans += 1
print(ans)




Measured memory_bytes: 39536
// Author : Chi
// created :

//header files
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//macros
#define ll 		    long long
#define ss          second
#define ff          first
#define vi          vector<int>
#define vll         vector<long long>
#define pb          push_back
#define TEST  	    int TesT;cin>>TesT;while(TesT--)solve();
#define TEST1       solve();
#define mod         998244353
#define r0n(i,n)    for(ll i = 0; i < n; ++i)
#define r1n(i,n)    for(ll i = 1; i <= n; ++i)
#define CHI         ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//namespaces
using    namespace __gnu_pbds;
using    namespace std;

typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
void solve(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    int ans[n]={0};
    for(int i=1;i<n;i++){
        if(i-1>=0){
            ans[i]=ans[i-1]+abs(a[i]-a[i-1]);
        }
        if(i-2>=0){
            ans[i]=min(ans[i],ans[i-2]+abs(a[i]-a[i-2]));
        }
    }
    cout<<ans[n-1];
}
// Driver Code
int main()
{
    TEST1
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		int a = stdIn.nextInt();
		while(a-- != 0)
		{
			int X = stdIn.nextInt();
			int Y = stdIn.nextInt();
			int W = stdIn.nextInt();
			int H = stdIn.nextInt();
			int N = stdIn.nextInt();
			int count = 0;
			for(int i = 0; i < N; ++i)
			{
				int x = stdIn.nextInt();
				int y = stdIn.nextInt();
				if((X <= x && x <= X + W) && (Y <= y && y <= Y + H))
				{
					++count;
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 24440
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;

void show(vi p) {
	cout << " " << p[20] << p[19] << p[18] << endl;
	cout << p[15] << p[0] << p[1] << p[2] << p[14] << p[27] << p[28] << p[29] << endl;
	cout << p[16] << p[3] << p[4] << p[5] << p[13] << p[24] << p[25] << p[26] << endl;
	cout << p[17] << p[6] << p[7] << p[8] << p[12] << p[21] << p[22] << p[23] << endl;
	cout << " " << p[9] << p[10] << p[11] << endl;
}

vi rotate(vi p, int d) {
	vi np(31);
	REP(i, 31) {
		np[i] = p[i];
	}
	switch (d) {
	case 0:
		swap(np[0], np[23]);
		swap(np[3], np[26]);
		swap(np[6], np[29]);
		swap(np[9], np[20]);
		swap(np[15], np[17]);
		break;
	case 1:
		swap(np[6], np[21]);
		swap(np[7], np[22]);
		swap(np[8], np[23]);
		swap(np[12], np[17]);
		swap(np[9], np[11]);
		break;
	case 2:
		swap(np[2], np[21]);
		swap(np[5], np[24]);
		swap(np[8], np[27]);
		swap(np[11], np[18]);
		swap(np[12], np[14]);
		break;
	case 3:
		swap(np[0], np[27]);
		swap(np[1], np[28]);
		swap(np[2], np[29]);
		swap(np[14], np[15]);
		swap(np[18], np[20]);
		break;
	}
	np[30]++;
	return np;
}

bool finish(vi p) {
	FOR(i, 1, 8) {
		if (p[0] != p[i]) {
			return false;
		}
	}
	FOR(i, 10, 11) {
		if (p[9] != p[i]) {
			return false;
		}
	}
	FOR(i, 13, 14) {
		if (p[12] != p[i]) {
			return false;
		}
	}
	FOR(i, 16, 17) {
		if (p[15] != p[i]) {
			return false;
		}
	}
	FOR(i, 19, 20) {
		if (p[18] != p[i]) {
			return false;
		}
	}
	FOR(i, 22, 29) {
		if (p[21] != p[i]) {
			return false;
		}
	}
	return true;
}

int main() {
	int N;
	cin >> N;
	REP(i, N) {
		vi puzzle(31);
		REP(j, 30) {
			cin >> puzzle[j];
		}

		queue<vi> Q;
		Q.push(puzzle);
		while (!Q.empty()) {
			vi p = Q.front();
			Q.pop();

//			show(p);
			if (finish(p)) {
				cout << p[30] << endl;
				break;
			}

			REP(d, 4) {
				vi np = rotate(p, d);
				Q.push(np);
			}
		}
	}
}

Measured memory_bytes: 14224
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
c = 0

for i in range(n - 1):
    for j in range(n - 1 - i):
        total = 0
        for k in range(d):
            total = total + (x[i][k] - x[i + j + 1][k])*(x[i][k] - x[i + j + 1][k])
        total = total**0.5
        if total == int(total):
            c = c + 1

print(c)

Measured memory_bytes: 3064
n = int(input())
l = list(map(int, input().split()))
l.sort()


if l[-1]%2 == 0:
  s = l[-1]//2
else:
  s = (l[-1]+1)//2

temp = float('inf')
for i in range(n-1):
  t = abs(l[i]-s)
  if t <= temp:
    p = l[-1]
    q = l[i]
    temp = t
print(p, q)

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

int main() {
  int N;
  cin >> N;
  int x = N;
  int fx = 0;

 while(N > 0)
{
  fx += N % 10;
  N /= 10;
}
  if( x % fx == 0){
      cout << "Yes" ;
  }
  else {
      cout << "No" << endl;  
  }  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, C;
    cin >> A >> B >> C;
    ll K;
    cin >> K;
    vector<ll> nums;
    nums.push_back(A);
    nums.push_back(B);
    nums.push_back(C);
    sort(nums.begin(), nums.end());
    for (int i = 0; i < K; i++)
    {
        nums.at(2) *= 2;
    }
    cout << nums.at(0) + nums.at(1) + nums.at(2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
char y[1000000],temp[1000000]; 
int main(){
map<char,char> a;
a['b']='d';a['p']='q';
a['q']='p';a['d']='b';
cin>>y;
int m=strlen(y);
strcpy(temp,y);
for(int i=0;i<m/2;i++)swap(y[i],y[m-i-1]);
for(int i=0;i<m;i++)y[i]=a[y[i]];
if(strcmp(y,temp)==0)cout<<"Yes";
else cout<<"No";
return 0;
}


Measured memory_bytes: 384
N = int(input())
A = list(map(int,input().split()))
if A[0] == 1 and N == 0:
    print(1)
    exit()
if A[0] != 0:
    print(-1)
    exit()
A.reverse()
B = []
ans = 0
num = 0
num2 = 0
for i in range(N+1):
    lim = 2**(N-i)
    if A[i] > lim:
        print(-1)
        exit()
    num = min(num+A[i],lim)
    B.append(num)
A.reverse()
B.reverse()
for i in range(N):
    num2 = B[i]-A[i]
    if num2*2 < A[i+1]:
        print(-1)
        exit()
    if num2*2 < B[i+1]:
        B[i+1] = num2*2
print(sum(B))

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

string up (int x) {
    string s;
    for(int i = 0; i < x; i++) s += "U";
    return s;
}
string down (int x) {
    string s;
    for(int i = 0; i < x; i++) s += "D";
    return s;
}
string left (int x) {
    string s;
    for(int i = 0; i < x; i++) s += "L";
    return s;
}
string right (int x) {
    string s;
    for(int i = 0; i < x; i++) s += "R";
    return s;
}

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int a, b;
    a = tx-sx;
    b = ty-sy;
    string s;
    s = up(b)+right(a+1)+down(b+1)+left(a+1)+up(1)+left(1)+up(b+1)+right(a+1)+down(b+1)+left(a);
    cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>

using namespace std;

void countdown(vector<int> &r, int k, int n, int &z) {
    //if(r[z] > 0){
    //    --r[z];
    //} else {
    //    --r[z-1];
    //    r[z] = k;
    //    if(r[z-1]==0) --z;
    //    else z = n-1;
    //}
    if (r[z] == 0) {
        r[z] = k;
        z--;
        r[z]--;
        if (r[z] != 0) {
            z = n-1;
        }
    //} else if(r[z] > 0){
    } else {
        r[z]--;
    //} else {
    //    std::cerr << r[z-1] << r[z] << r[z+1] << std::endl;
    }
    return;
}

void solve(int k, int n) {
    if (k%2 == 0) {
        std::cout << k/2;
        for (int i = 0; i < n-1; i++) {
            std::cout << " " << k;
        }
        std::cout << std::endl;
        return;
    }
    vector<int> ret(n, (k+1)/2);
    int z = n-1;
    for (int i = 0; i < n/2; i++) {
        countdown(ret, k, n, z);
    }
    std::cout << ret[0];
    for (int i = 1; i < ret.size(); i++) {
        if (ret[i] == 0) {
            break;
        }
        std::cout << " " << ret[i];
    }
    std::cout << std::endl;
}

int main() {
    struct timeval start,end;
    long long span;
    int k, n;

    gettimeofday(&start,NULL);

    std::cin >> k >> n;
    solve(k, n);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 3456
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	l := nextInt()
	r := nextInt()
	d := nextInt()

	cnt := 0
	for i := l; i <= r; i++ {
		if i%d == 0 {
			cnt++
		}
	}

	fmt.Println(cnt)

}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1776
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;
//左辺に底　右辺に真数
long double mlog(const long double base, const long double anti) {
	return log(anti) / log(base);
}
int main() {
	long long int N; cin >> N;
	long long int now = 1;
	int ans = 1;
	while (1) {
		now *= 3;
		if (now >= N)break;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
#define Int int64_t
#define ll long long
#define pb push_back
using namespace std;
const Int MAXN=200005;
const int ALPHA=26;

Int N,K,M;
Int X,Y,Z;Int C;
vector<Int> ID;
vector<Int> SZ;
string S;
int find(int x){
    if(ID[x]==x) return x;
    return find(ID[x]);
}
void Union(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(SZ[x]>SZ[y]){
        ID[y]=x;
        SZ[x]+=SZ[y];
    }
    else{
        ID[x]=y;
        SZ[y]+=SZ[x];
    }
    return;
}
string common_prefix(string s,string t){
    string ans="";
    for(int i=0;i<min(s.length(),t.length());++i){
        if(s[i]==t[i]) ans.pb(s[i]);
        else break;
    }
    return ans;
}
string LCP(vector<string> A,int l,int r){
    if(l>r) return "";
    if(l==r) return A[l];
    int mid=(l+r)/2;
    string left=LCP(A,l,mid);
    string right=LCP(A,mid+1,r);
    return common_prefix(left,right);
}

long long ModExpo(long long x,unsigned long long y,long long M){
    Int ans=1;
    ans=(long long)ans;
    
    while(y>0){
        if(y&1) ans=((ans%M)*(x%M))%M;
        y>>=1LL;
        x=((x%M)*(x%M))%M;
    }
    return ans%M;
}
Int LCM(Int x,Int y){
    return (x*y)/__gcd(x,y);
}

using D=long double;
vector<Int> A,B;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
    int t;
    t=1;
    while(t--){
        cin>>N;
        string S;cin>>S;
        
        Int ans=0;
    
        vector<int> W,R;
        int idx=0;
        for(auto x:S) {
            if(x=='W') W.pb(idx);
            else R.pb(idx);
            ++idx;
        }
        int l=0,r=R.size()-1;
        while(l<W.size()&&r>=0&&W[l]<R[r]){
            ++ans;++l;--r;
        }
        cout<<ans<<"\n";
    }
}

Measured memory_bytes: 4836
import java.math.BigInteger;
import java.util.Scanner;

class Main{
    public static void main(String [] args){
	Scanner s = new Scanner(System.in);
	final int n = Integer.parseInt(s.next());

	BigInteger m = new BigInteger("1");
	for(int i = 0; i < n; i++){
	    m = m.multiply(new BigInteger(String.valueOf(i + 2)));
	}

	m = m.add(BigInteger.ONE);
	m = m.add(BigInteger.ONE);

	System.out.println(m);

	for(int i = 0; i < n; i++){
	    System.out.println(i + 2);
	    // System.out.println(m.mod(new BigInteger(String.valueOf(i + 2))));
	    // m = m.add(BigInteger.ONE);
	}
    }
}

Measured memory_bytes: 13000
main() {
    int a, b, c, k, ans = 0;
    scanf("%d%d%d%d", &a, &b, &c, &k);
    if(k <= a) ans = k;
    else if(k <= a + b) ans = a;
    else ans = a - (k - a - b);
    printf("%d\n", ans);
}

Measured memory_bytes: 1708
#include <iostream>
#include <string>
#include <array>
#include <algorithm>

int main()
{
    std::string str;
    std::cin >> str;
    std::array<int, 26> counter = {0};
    for (const char c : str)
    {
        ++counter[c - 'a'];
    }

    const auto it = std::find_if(counter.begin(), counter.end(), [](const int v) { return v % 2; });
    if (it != counter.end())
    {
        std::cout << "No";
    }
    else
    {
        std::cout << "Yes";
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <math.h>
using namespace std;
int main(){
    long long int x,k,d;
    cin>>x>>k>>d;
    if(x>=0){
        if(x/d>k){
            cout<<x-k*d<<endl;
        }
        else{
            if((k-(x/d))%2==0){
                cout<<x%d<<endl;
            }
            else{
                cout<<d-(x%d)<<endl;
            }
        }
    }
    else{
        x=-x;
        if(x/d>k){
            cout<<x-k*d<<endl;
        }
        else{
            if((k-(x/d))%2==0){
                cout<<x%d<<endl;
            }
            else{
                cout<<d-(x%d)<<endl;
            }
        }

    }
    return 0;
}


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

int main(){
    int n, m, p, sum;

    while(std::cin >> n >> m){
        std::vector<int> price_list = {};

        if(n == 0 && m == 0){
            break;
        } else{
            sum = 0;
            for(int i = 0;i < n;++i){
                std::cin >> p;
                price_list.push_back(p);
                sum += p;
            }
            std::sort(price_list.begin(), price_list.end(), std::greater<int>());
            for(int i = 1;i <= n/m;++i){
                sum -= price_list.at(i * m - 1);
            }
            std::cout << sum << std::endl;
        }   
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  ll X, Y; scanf("%lld %lld", &X, &Y);
  printf("%s\n", (abs(X - Y) > 1) ? "Alice" : "Brown");
  return 0;
}


Measured memory_bytes: 256
A,B,M = map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
discount = 10000000000
for i in range(M):
    C = [int(i) for i in input().split()]
    num = a[C[0]-1] + b[C[1]-1] -C[2]
    if discount > num:
        discount = num
a.sort()
b.sort()
if discount > a[0]+b[0]:
    discount = a[0]+b[0]
print(discount)

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

int main() {
  long long a,b;
  cin>>a>>b;
  vector<long long> vec(a);
  long long sum=0;
  rep(i,a){
      cin>>vec.at(i);
      sum++;
      b-=vec.at(i);
  }
  sort(vec.begin(),vec.end());
  sum+=b/vec.at(0);
  cout<<sum<<endl;
}


Measured memory_bytes: 256
using namespace std;
int main(){
	int h,m,s,H,M,S,t;
	for(int i=0;i<3;i++){
		cin>>h>>m>>s>>H>>M>>S;
		t=(H-h)*3600+(M-m)*60+S-s;
		cout<<t/3600<<" "<<(t/60)%60<<" "<<t%60<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
package main

import "fmt"

func main() {
	var s string
	var s1 string
	fmt.Scanf("%s\n%s", &s, &s1)
	res := 0
	for i := 0; i<3;i++ {
		if s[i] == s1[i] {
			res++
		}
	}
	fmt.Println(res)
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int n, m;
    cin >> n >> m;
    ll s_x[n];
    ll s_y[n];
    ll c_x[m];
    ll c_y[m];
    int ans[n];
    for(int i = 0; i < n; i++){
        cin >> s_x[i] >> s_y[i];
    }
    for(int i = 0; i < m; i++){
        cin >> c_x[i] >> c_y[i];
    }
    for(int i = 0; i < n; i++){
        ll d = 400000004; 
        for(int j = 0; j < m; j++){
            ll l = abs(s_x[i] - c_x[j]) + abs(s_y[i] - c_y[j]);
            if(d > l){
                d = l;
                ans[i] = j + 1;
            }
        }
    }
    for(int i = 0; i < n; i++){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int N = 2e5 + 5;
const int inf = 1e9 + 7;
 
string s;
int n;
long long ans;
vector<int> g[26];
vector < pair<int,int> > p[26];
 
int Tlef[N], Trig[N]; 
void upd_lef(int x) { for (; x <= n; x += x & -x) Tlef[x]++; }
void upd_rig(int x) { for (; x > 0; x -= x & -x) Trig[x]++; }
int get_lef(int x) { int ret = 0; for (; x > 0; x -= x & -x) ret += Tlef[x]; return ret; }
int get_rig(int x) { int ret = 0; for (; x <= n; x += x & -x) ret += Trig[x]; return ret; }

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> s;
	n = s.size();
 
	for (int i = 0; i < s.size(); ++i) g[s[i] - 'a'].push_back(i);
 
	int cntodd = 0;
	for (int c = 0; c < 26; ++c) if (g[c].size() & 1) ++cntodd;
	if (cntodd > 1) return cout << -1 << endl, 0; // invalid
	
	for (int c = 0; c < 26; ++c) {
		int sz = g[c].size();
		if (!sz) continue;
		for (int i = 0; i < (sz + 1) / 2; ++i) 
			p[c].push_back(make_pair(g[c][i], g[c][sz - 1 - i]));
	}
	
	int center = -1;
	for (int c = 0; c < 26; ++c) if (p[c].size()) {
		if (p[c].back().first == p[c].back().second) {
			center = p[c].back().first; p[c].pop_back(); break;
		}
	}
 	
	vector < pair<int,int> > vec;
	for (int c = 0; c < 26; ++c) {
		for (auto it : p[c]) vec.push_back(it);
	}
	sort(vec.begin(), vec.end());
	
	for (int i = 0; i < vec.size(); ++i) {
		int p1 = vec[i].first, p2 = vec[i].second;
		int rp1 = p1 + get_rig(p1 + 1) - get_lef(p1 + 1);
		int rp2 = p2 + get_rig(p2 + 1) - get_lef(p2 + 1);
		ans += abs(rp1 - i) + abs(rp2 - (n - 1 - i));
		upd_rig(p1 + 1); 
		upd_lef(p2 + 1);
	} 
	if (center != -1) {
		center += get_rig(center + 1) - get_lef(center + 1);
		ans += abs(center - (n / 2));
	}

	cout << ans << endl;
}

Measured memory_bytes: 4748
N, T = map(int, input().split())
t = list(map(int, input().split()))

count = 0
oyu_time = 0
for i in range(N):
  if oyu_time >= t[i]:
    count += T - (oyu_time - t[i])
  else:
    count += T
  oyu_time = t[i] + T
print(count)

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



int main() {
  // swapのみを用いる解法
  // 目標状態が定まっている 
  int n;            // 石の数
  std::string s;   
  std::cin >> n >> s;

  int n_r = 0;      // 赤の数
  int n_change = 0; // 交換回数

  // 赤石をcount
  for (int i = 0; i < n; i++)
    if (s[i] == 'R')
      n_r++;
  
  // 左からn_r個までにある白石の数 = 交換回数
  for (int i = 0; i < n_r; i++)
    if (s[i] == 'W')
      n_change++;

  std::cout << n_change;
  
  return 0;
}



Measured memory_bytes: 3752
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
n = len(s)
ans = []
l = []
i = 0
pi = 0
def sub(pi,i,point):
    l = [0]*(i-pi)
    l[point-pi] = (point-pi)//2 + (i-point-1)//2 + 1
    l[point-1-pi] = (i-pi) - l[point-pi]
    return l
while i<n:
    while i<n and s[i]=="R":
        i += 1
    point = i
    while i<n and s[i]=="L":
        i += 1
    l.extend(sub(pi,i,point))
#     print(l, pi, i, point)
    pi = i
write(" ".join(map(str, l)))

Measured memory_bytes: 82584
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=6100;
int n,mod,fac[N],inv[N],tot[4][N],invtot[4][N];
int p[N];
inline void add(int &a,int b){a=(a+b)%mod;}
inline void del(int &a,int b){a=(a-b+mod)%mod;}
inline void mul(int &a,int b){a=(a*b)%mod;}
inline int C(int n,int m){return fac[n]*inv[n-m]%mod*inv[m]%mod;}
inline int m_pow(int a,int b)
{
	int ans=1;
	while (b)
	{
		if (b&1) mul(ans,a);
		b>>=1;
		mul(a,a);
	}
	return ans;
}
signed main()
{
	scanf("%lld%lld",&n,&mod);n*=3;
	fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=(fac[i-1]*i)%mod;
	inv[n]=m_pow(fac[n],mod-2);
	for (int i=n-1;i>=0;i--) inv[i]=(inv[i+1]*(i+1))%mod;
	p[0]=1;
	for (int i=1;i<=n;i++) p[i]=(p[i-1]*2)%mod;
	for (int i=1;i<=3;i++)
	{
		for (int j=0;j<i;j++) tot[i][j]=1;
		for (int j=i;j<=n;j++) tot[i][j]=(tot[i][j-i]*C(j,i))%mod;
		for (int j=0;j<=n;j++) invtot[i][j]=m_pow(tot[i][j],mod-2);
	}
	int ans=0;
	for (int i=0;i<=n;i++)
	{
		for (int j=0;j<=i;j++)
		{
			int k=n-i-2*j,num=1,tmp=n;
			if (k<0) break;
			if (k%3!=0) continue;
			k/=3;
			mul(num,tot[1][tmp]*invtot[1][tmp-i]%mod);tmp-=i;
			mul(num,tot[2][tmp]*invtot[2][tmp-2*j]%mod);tmp-=2*j;
			mul(num,tot[3][tmp]);
			mul(num,inv[i]);mul(num,inv[j]);mul(num,inv[k]);
			mul(num,p[k]);
//			printf("1:%d 2:%d: %d\n",i,j,num);
			add(ans,num);
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 4180
N = int(input())
data = [list(map(int,input().split())) for i in range(N-1)]

G = [[] for i in range(N+1)]
for i in range(N-1):
    G[data[i][0]].append((data[i][1],data[i][2]))
    G[data[i][1]].append((data[i][0],data[i][2]))

from collections import deque

D = [-1]*(N+1)
D[1] = 0

q = deque([1])

while q:
    n = q.pop()
    for d,e in G[n]:
        if D[d] != -1:
            continue
        elif e % 2 == 1:
            D[d] = 1-D[n]
            q.append(d)
        else:
            D[d] = D[n]
            q.append(d)

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

Measured memory_bytes: 52652