akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<utility>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int tm(string s){
	long long res=((s[0]-'0')*10+(s[1]-'0'))*60+(s[3]-'0')*10+(s[4]-'0');
	return res;
}

int main(){
	long long n,t;
	cin>>n>>t;
	string st[n];
	string ar[n];
	string stn[n];
	string arn[n];
	vector<pair<string,long long> > vec;
	rep(i,n){
		cin>>stn[i]>>st[i]>>arn[i]>>ar[i];
	}
	rep(i,n-1){
		if(tm(stn[i+1])-tm(arn[i])>=t){
			pair<string,int> pr;
			pr.first=ar[i];
			pr.second=tm(stn[i+1])-tm(arn[i]);
			vec.push_back(pr);
		}
	}
	cout<<vec.size()<<endl;
	rep(i,vec.size()){
		pair<string,int> ans=vec[i];
		cout<<ans.first<<" "<<ans.second<<endl;
	}
	return 0;
}

Measured memory_bytes: 1224
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    maxi = max(A)
    a = A.copy()
    a.sort()
    submaxi = max(a[:N-1])
    for i in range(N):
        if A[i] != maxi:
            print(maxi)
        else:
            print(submaxi)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14160
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>
// #include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
// using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

typedef vector<int> vec;
typedef vector<vec> mat;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int H, A; cin >> H >> A;
    cout << (H+A-1)/A << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdint>
#include <string>
#include <algorithm>

int main() {
  std::string s;
  std::cin >> s;
  std::int_fast64_t n = s.size();

  std::reverse(s.begin(), s.end());
  for (std::int_fast64_t i = 0; i < n;) {
    if (s.substr(i, 5) == "maerd") {
      i += 5;
    } else if (s.substr(i, 7) == "remaerd") {
      i += 7;
    } else if (s.substr(i, 5) == "esare") {
      i += 5;
    } else if (s.substr(i, 6) == "resare") {
      i += 6;
    } else {
      std::cout << "NO" << std::endl;
      return 0;
    }
  }
  std::cout << "YES" << std::endl;
  return 0;
}

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

#define rep(i, n)  for (int i = 0; i < (n) ; ++i)
#define mod 1000000007

using namespace std;
using ll=long long;
const ll INF = 100000000;

int main(int argc, char *argv[]) {
    int a, b;
    cin >> a >> b;
    cout << a * b;
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
int main(void)
{
    int A, B, M, i, ans1, ans2 = 200000, amin = 100000, bmin = 100000;
    scanf("%d %d %d", &A, &B, &M);
    int a[A], b[B], x[M], y[M], c[M];
    for (i = 0; i < A; i++) {
        scanf("%d", &a[i]);
        if (amin > a[i]) {
            amin = a[i];
        }
    }
    for (i = 0; i < B; i++) {
        scanf("%d", &b[i]);
        if (bmin > b[i]) {
            bmin = b[i];
        }
    }
    for (i = 0; i < M; i++) {
        scanf("%d %d %d", &x[i], &y[i], &c[i]);
    }
    
    ans1 = amin + bmin;
    for (i = 0; i < M; i++) {
        if (ans2 > a[x[i]-1] + b[y[i]-1] - c[i]) {
            ans2 = a[x[i]-1] + b[y[i]-1] - c[i];
        }
    }
    if (ans1 < ans2) {
        printf("%d\n", ans1);
    }
    else {
        printf("%d", ans2);
    }
    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const double PI = acos(-1);
const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}




int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n,k;
    cin >> n >> k;
    vector<ll> p(n);
    vector<ll> c(n);
    rep(i, n) {
      cin >> p[i];
      p[i]--;
    }
    rep(i, n) cin >> c[i];
    ll ans = -1e18;
    rep(si, n){
      ll x = si;
      vector<ll> s;
      ll tot = 0;
      while(true){
        x = p[x];
        s.pb(c[x]);
        tot += c[x];
        if(x == si) break;
      }
      ll l = s.size();
      ll t = 0;
      rep(i, l){
        t += s[i];
        if(i + 1 > k) break;
        ll now = t;
        if(tot > 0) {
          ll e = (k - (i + 1)) / l;
          now += tot * e;
        }
        chmax(ans, now);
      }
    }
    print(ans);



}



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

int main() {
    int x, y, a, b;
    cin >> x >> y;
    b = (y - 2 * x) /2;
    a = (4 * x - y) /2;
    if(a < 0 || b < 0) cout << "No" << endl;
    else if(a + b == x){
        if(2*a + 4*b == y){
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
    else cout << "No" << endl;
}


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

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

const int N = 100000 + 5;
int h[N];

int main(){
    //freopen("d.in","r",stdin);
	int n, a, b;
	cin >> n >> a >> b;
	rep(i,0,n) cin >> h[i];
	long long l = 1, r = ~0U >> 2;
	while(l < r) {
		long long m = (l + r) >> 1;
	//	cout << l << " " << r << " " << m << " ";
		bool flag = 1;
		long long sum = 0;
		rep(i,0,n) {
			long long t = h[i] - b*m;
			if(t > 0) {
				sum += (int)ceil(t*1.0 / (a - b));
				if(sum > m || sum < 0) {
					flag = 0;
					break;
				}
			}
		}
	//	cout << (flag == 0 ? "l" : "r") << endl;
		if(flag) r = m;
		else l = m + 1;
	}
	cout << l << endl;
	return 0;
}


Measured memory_bytes: 640
from heapq import heappush, heappop
N, M = map(int, input().split())
l = []
for _ in range(N):
    A, B = map(int, input().split())
    heappush(l, (A, B))
now = 0
ans = 0
for i in range(N):
    a, b = heappop(l)
    if now + b < M:
        now += b
        ans += a * b
    else:
        ans += a * (M - now)
        print(ans)
        exit()
print(ans)

Measured memory_bytes: 16668
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> X(N);
    for(int i = 0;i < N; i++) cin >> X[i];
    int sum = 0;
    for(int i = 0; i < N; i++) sum +=  min(X[i], abs(K - X[i]));
    cout << sum * 2 << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int n, c, k, t[112345];

    cin >> n >> c >> k;
    REP(i, n)
    cin >> t[i];

    sort(t, t + n);

    int res = 0;

    int i = 1;
    int cnt = 1;
    int leave = t[0] + k;

    while (i < n)
    {
        if (cnt + 1 > c || leave < t[i])
        {
            res++;
            leave = t[i] + k;

            cnt = 0;
        }

        cnt++;

        i++;
    }

    if (cnt)
        res++;

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

class MatrixSum {
    vector<vector<ll>> sum;
public:
    MatrixSum(ll x, ll y) {
        sum = vector<vector<ll>>(x, vector<ll>(y));
    }

    void add(ll x, ll y) {
        sum[x][y]++;
    }

    ll get(ll x, ll y) {
        if (x == -1 || y == -1) {
            return 0;
        }
        if (x == sum.size() || y == sum[x].size()) {
            return 0;
        }
        return sum[x][y];
    }

    void setUp() {
        for (ll x = 0; x < sum.size(); x++) {
            for (ll y = 0; y < sum[x].size(); y++) {
                sum[x][y] += get(x - 1, y) + get(x, y - 1) - get(x - 1, y - 1);
            }
        }
    }

    ll getSum(ll xs, ll ys, ll xe, ll ye) {
        return get(xe, ye) - get(xs - 1, ye) - get(xe, ys - 1) + get(xs - 1, ys - 1);
    }

};

int main() {
    int h, w, q;
    cin >> h >> w >> q;
    vector<vector<char>> grid(h, vector<char>(w));
    rep(y, h) rep(x, w) cin >> grid[y][x];

    MatrixSum b(h, w), bv(h, w), bh(h, w);

    rep(y, h) rep(x, w) if (grid[y][x] == '1') b.add(y, x);
    rep(y, h) rep(x, w - 1) if (grid[y][x] == '1' && grid[y][x + 1] == '1') bh.add(y, x);
    rep(y, h - 1) rep(x, w) if (grid[y][x] == '1' && grid[y + 1][x] == '1') bv.add(y, x);

    b.setUp();
    bv.setUp();
    bh.setUp();
    rep(_, q) {
        int y1, x1, y2, x2;
        cin >> y1 >> x1 >> y2 >> x2;
        y1--;
        x1--;
        y2--;
        x2--;

        int bc = b.getSum(y1, x1, y2, x2);
        int bvc = y1 == y2 ? 0 : bv.getSum(y1, x1, y2 - 1, x2);
        int bhc = x1 == x2 ? 0 : bh.getSum(y1, x1, y2, x2 - 1);

        int ans = bc - bvc - bhc;

        cout << ans << endl;
    }

}


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

using namespace std;

int main(){
  int n; cin >> n;
  set<string> s;
  string b;
  bool isPossible = true;
  for(int i = 0; i < n; i++){
    string a; cin >> a;
    if(i != 0 && (b.back() != a[0] || s.find(a) != s.end())){
      isPossible = false;
    }
    b = a;
    s.insert(a);
  }
  if(isPossible) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define  n 101

int main(){
  int G[n][n];
  int i , j ,a,b,c,d;
  scanf("%d",&d);
  for(i=0;i<d;i++){
    for(j=0;j<d;j++){
      G[i][j]=0;
    }
  }
  for(i=0;i<d;i++){
    scanf("%d%d",&a,&b);
    for(j=0;j<b;j++){
      scanf("%d",&c);
      G[i][c-1]=1;
    }
  }
  for(i=0;i<d;i++){
    for(j=0;j<d;j++){
      printf("%d",G[i][j]);
      if(j<d-1){
	printf(" ");
      }
    }
      printf("\n");
    
  }
    return 0 ;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

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

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < 10; i++) {
    n -= 1000;
    if (n <= 0) {
      cout << n * -1 << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n, m;
    cin >> n >> m;
    set<int> a, o, s, t;
    
    rep(i, n){
        int l;
        cin >> l;
        t.insert(l);
        o.insert(l);
    }
    
    rep(i, m){
        int l;
        cin >> l;
        s.insert(l);
        o.insert(l);
    }
    
    repi(i, s){
        if(t.find(*i) != t.end()){
            a.insert(*i);
        }
    }
    cout << a.size() << " " << o.size() << endl;
    repi(i, a){
        cout << *i << endl;
    }
    repi(i, o){
        cout << *i << endl;
    }
    
    return 0;
}



Measured memory_bytes: 25940
#include <iostream>
#include <cmath>

using namespace std;

using ll = long long;

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()

ll sum(ll n, ll b) {
    ll ans = 0;
    while (n) {
        ans += n % b;
        n /= b;
    }
    return ans;
}

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

    ll n, s;
    cin >> n >> s;
    if (n == s) {
        cout << n + 1 << endl;
    } else {
        for (ll i = 2; i <= sqrt(n) + 1; ++i) {
            ll b = i;
            if (sum(n, b) == s) {
                cout << b << endl;
                return 0;
            }
        }
        if (n - s > 1) {
            for (ll i = sqrt(n); i; i--) {
                ll b = (n - s) / i + 1;
                if (sum(n, b) == s) {
                    cout << b << endl;
                    return 0;
                }
            }
        }
        cout << "-1" << endl;
    }

    return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(500*500)

N = int(input())
edges = [list(map(int, input().split())) for _ in range(N-1)]

A = [[] for _ in range(N+1)]

for edge in edges:
    A[edge[0]].append([edge[1], edge[2]])
    A[edge[1]].append([edge[0], edge[2]])

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

def dfs(A, s):
    for v in A[s]:
        if depth[v[0]] == -1:
            depth[v[0]] = depth[s] + v[1]
            dfs(A, v[0])

dfs(A, 1)
for d in depth[1:]:
    if d % 2 == 0:
        print(0)
    else:
        print(1)

Measured memory_bytes: 102104
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
  a = max(a,b);
}

template <typename T> void min_self(T& a, T b){
  a = min(a,b);
}

void solve(){	
  int n;cin>>n;
  vi v(n);
  for(int i=0;i<n;i++) cin>>v[i];
  sort(all(v));
  ll ans = 0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
        if(v[k] < v[j]+v[i] && v[i] != v[j] && v[j] != v[k] && v[k] != v[i])
          ans++;
      }
    }
  }
  cout<<ans<<endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //int t; cin >> t;
  //while(t--) solve();
  //
  solve();
  return 0;
}


Measured memory_bytes: 3636
a, b, c = sorted([int(i) for i in input().split()])
ans = 0
ans += (b - a) // 2 # (b or b - 1) b c
ans += (b - a) % 2 # b b c
c += (b - a) % 2 # b b (c or c + 1)
ans += (c - b) # c c c

print(ans)


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

X = INT()

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while True:
    if is_prime(X):
        print(X)
        break
    else:
        X = X + 1


Measured memory_bytes: 5384
inf = float("inf") # 正の無限大

N,K=map(int, input().split())
H=[0]+list(map(int, input().split()))
#print(N,H)

dp=[inf]*(N+1)
dp[1]=0
dp[2]=abs(H[2]-H[1])

for i in range(3,N+1):
	for k in range(1,K+1):
		if (i-k)>0:
			a = dp[i-k]+abs(H[i]-H[i-k])
			if dp[i]>a: dp[i]=a

print( dp[N] )






Measured memory_bytes: 56160
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

  sort(A.begin(),A.end());

  vector<pair<ll,ll>> ans;
  int now=0;
  if(A[0]>0){
    ans.push_back(make_pair(A[0],A[N-1]));
    A[0]=A[0]-A[N-1];
    A.pop_back();
  }else if(A[N-1]<0){
    ans.push_back(make_pair(A[N-1],A[0]));
    now=1;
    A[N-1]=A[N-1]-A[0];
  }

  ll x=A.back();
  ll y=A[now];
  for(int i=now+1;i<A.size()-1;i++){
    if(A[i]<=0){
      ans.push_back(make_pair(x,A[i]));
      x=x-A[i];
    }else{
      ans.push_back(make_pair(y,A[i]));
      y=y-A[i];
    }
  }

  ans.push_back(make_pair(x,y));
  ll m=x-y;
  cout<<m<<endl;
  for(int i=0;i<ans.size();i++) cout<<ans[i].first<<" "<<ans[i].second<<endl;

  

  return 0;
}


Measured memory_bytes: 4336
#include <vector>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    long long n;
    cin >> n;
    vector<long long>a(n);
    vector<long long>b(n);
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
    }
    for(int i=1;i<n;i++){
        long long c,d;
        if(a[i]>=a[i-1] && b[i]>=b[i-1]){
            continue;
        }else{
            c=(a[i]+a[i-1]-1)/a[i];
            d=(b[i]+b[i-1]-1)/b[i];
            a[i]=max(c,d)*a[i];
            b[i]=max(c,d)*b[i];
        }
    }
    cout << a[n-1]+b[n-1];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define DEBUG
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}

void solve(){
    int n; 
    cin >> n;
    vector<pair<int,int>> a;
    for(int i = 0 ; i < n ;i++){
        int x;
        cin >> x;
        a.push_back(make_pair(x,i));
    }
    sort(a.begin(), a.end());
    vector<int> ans(n);
    for(int i = 0 ; i < n ; i++){
        int id = a[i].second; 
        cout << id + 1 << "\n";
    }

}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}

Measured memory_bytes: 4540
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

from collections import defaultdict
d = defaultdict(int)

N = int(input())

li = []

for n in range(1, N+1):
  a = factorization(n)
  for i in a:
    d[i[0]] += i[1]

ans = 1

for i in d:
  if i == 1:
    continue
  
  ans = ans * (d[i] + 1)

print(ans % (10**9 + 7))

Measured memory_bytes: 3316
N, M = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))
m = 10**9+7
X = 0
for i in range(N-1):
    X = (X + (xs[i+1] - xs[i])*(i+1)*(N-i-1))%m
Y = 0
for i in range(M-1):
    Y = (Y + (ys[i+1] - ys[i])*(i+1)*(M-i-1))%m
print((X*Y)%m)


Measured memory_bytes: 83300
/*
    マージソート
    https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/5/ALDS1_5_B
*/
#include <bits/stdc++.h>
using namespace std;

// global
int cnt;

void trace(vector<int> A) {
    for (size_t i = 0; i < A.size(); i++) {
        cout << A[i];
        cout << ((i != A.size() - 1) ? " " : "\n");
    }
}

void merge(vector<int> &A, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    vector<int> L;
    vector<int> R;
    for (int i = 0; i < n1; i++) {
        L.push_back(A.at(left + i));
    }

    for (int i = 0; i < n2; i++) {
        R.push_back(A.at(mid + i));
    }

    L[n1] = 1000000009;
    R[n2] = 1000000009;
    int i = 0, j = 0;

    for (int k = left; k < right; k++) {
        cnt++;
        if (L[i] <= R[j]) {
            A[k] = L.at(i++);
        } else {
            A[k] = R.at(j++);
        }
    }
}

void mergeSort(vector<int> &A, int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

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

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

    mergeSort(A, 0, n);

    trace(A);
    cout << cnt << endl;
}


Measured memory_bytes: 7288
a,b = map(int, input().split())

cnt = 0
for i in range(a, b+1):
    i = str(i)
    flg = True
    
    for j in range(int(len(i)/2)+1):    
        if i[j] == i[-j-1]:
            pass
        else:
            flg = False
    if flg:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
a, b = map(int, input().split())

if a == 4 or a == 6 or a == 9 or a == 11:
  if b == 1 or b == 2 or b == 3 or b == 5 or b == 7 or b == 8 or b == 10 or b == 12:
    print("No")
  else:
    print("Yes")
    
elif a == 2:
  print("No")
  
else:
  if b == 2 or b == 4 or b == 6 or b == 9 or b == 11:
    print("No")
  else:
    print("Yes")

Measured memory_bytes: 9084
import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
  int n = readln.chomp.to!int;
  int[][] adj = new int[][](n);
  foreach (i; 0..n-1) {
    auto ab = readln.chomp.split.map!(to!int).map!(a => a - 1);
    adj[ab.front] ~= ab.back;
    adj[ab.back] ~= ab.front;
  }
  alias Node = Tuple!(int, "step", bool, "isSnuke", int, "now");
  alias RBT = RedBlackTree!(Node);
  RBT queue = new RBT();
  queue.insert(Node(0, false, 0));
  queue.insert(Node(0, true, n - 1));
  bool[] done = new bool[](n);
  int cnt = 0;
  while (queue.length) {
    Node node = queue.front;
    queue.removeFront;
    if (done[node.now]) {
      continue;
    }
    done[node.now] = true;
    if (node.isSnuke) {
      ++cnt;
    }
    foreach (to; adj[node.now]) {
      queue.insert(Node(node.step + 1, node.isSnuke, to));
    }
  }
  if (cnt == n - cnt) {
    "Snuke".writeln;
  } else if (cnt > n - cnt) {
    "Snuke".writeln;
  } else {
    "Fennec".writeln;
  }
}


Measured memory_bytes: 19732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
int Inf = 1000000000;
ll inf = 1000000000000;
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; }
int main(){
	ll h;
	cin >> h;
	ll count = 1;
	ll ans = 0;
	while (h) {
		h /= 2;
		ans += count;
		count *= 2;
	}
	cout << ans;
	return(0);
}

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

signed main()
{
  int N; cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  vector<int> b=a;
  sort(a.begin(),a.end());

  int max_cnt=0;
  for(int i=0;i<N;i++){
    if(a[i]==a[N-1]) max_cnt++;
  }
//  cout<<max_cnt<<endl;

  if(max_cnt==1){
    for(int i=0;i<N;i++){
      if(b[i]==a[N-1]){
        cout<<a[N-2]<<endl;
      }else{
        cout<<a[N-1]<<endl;
      }
    }
  }else{
    for(int i=0;i<N;i++){
      cout<<a[N-1]<<endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 4736
N=int(input())

ans=0
def make753(s,n):
  global ans
  if s<=N:
    if "3" in str(s) and "5" in str(s) and "7" in str(s):
      ans+=1
  if n>0:
    for i in 7,5,3:
      make753(10*s+i,n-1)
      
make753(0,len(str(N)))
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>
#include<string.h>
int main(){
	long long int n,m;
	long long int a[100],b[100],c[100],d[100];
	scanf("%lld %lld",&n,&m);
	long long int i,j;
	for(i=0;i<n;i++){
		scanf("%lld %lld",&a[i],&b[i]);
	}
	for(i=0;i<m;i++){
		scanf("%lld %lld",&c[i],&d[i]);
	}
	long long int min=0;
	long long int ab[100];
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			ab[j]=abs(a[i]-c[j])+abs(b[i]-d[j]);
		}
		min=ab[0];
		for(j=1;j<m;j++){
			if(min>ab[j]){
				min=ab[j];
			}
		}
		for(j=0;j<m;j++){
			if(min==ab[j]){
				printf("%lld\n",j+1);
				break;
			}
		}
	}
	return 0;
} 

Measured memory_bytes: 384
#include <iostream>

using namespace std;

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

  int i = 1;
  while (++i <= n)
  {
    int x = i;
    if (x % 3 == 0)
    {
      cout << " " << i;
      continue;
    }

    do
    {
      if (x % 10 == 3)
      {
        cout << " " << i;
        break;
      }
      x /= 10;
    } while (x);
  }

  cout << endl;
}

Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
using namespace std;
//#define NUM 50

int main(){
    int a[3];
    int i, k;
    for(i = 0; i < 3; i++){
        cin >> a[i];
    }
    sort(a, a + 3);
    cin >> k;
    for(i = 0; i < k; i++){
        a[2] *= 2;
    }
    cout << a[0] + a[1] + a[2] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(15);
vector<int> forintinput(int n) {
	vector<int> x;
	for(int i = 0;i < n;i++){
		int ia;
		cin >> ia;
		x.push_back(ia);
	}
	return x;
}
int main(){
	int a,b,c,d,e,k;
	cin >> a >> b >> c >> d >> e >> k;
	if(e-a > k){
		cout << ":(" << endl;
	}else{
		cout << "Yay!" << endl;
	}
}

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

int main() {
  long long int n,y;
  cin>>n>>y;
  for(long long int i=0;i<=n;i++){
    for(long long int j=i;j<=n;j++){
      if(i*10000+(j-i)*5000+(n-j)*1000==y){
        cout<<i<<" "<<j-i<<" "<<n-j<<endl;
        return 0;
        }
      }
    }
  cout<<"-1 -1 -1"<<endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BABC solver = new BABC();
        solver.solve(1, in, out);
        out.close();
    }

    static class BABC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next().replaceAll("BC", "D");

            long cnt = 0;
            long tmp = 0;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == 'A') {
                    tmp++;
                } else if (s.charAt(i) == 'D') {
                    cnt += tmp;
                } else {
                    tmp = 0;
                }
            }
            out.println(cnt);
        }

    }
}



Measured memory_bytes: 33336
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define BIT(n) (1LL << (n))
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  string ans = "No";
  if ((S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) ||
      (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) ||
      (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]))
    ans = "Yes";
  cout << ans << "\n";
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define MAX_C 1000000001

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

  printf("%lf", 2 * 3.141592653589 * r);
}


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

using namespace std;
int main()
{
    int a,b;
    string s,t,u;

    cin>>s>>t>>a>>b>>u;

    if(u==s)
    {
        cout <<a-1<<" "<<b<< endl;
    }
    else
    {
       cout <<a<<" "<<b-1<< endl;
    }
    return 0;

}


Measured memory_bytes: 256
import io.StdIn.readLine
import annotation.tailrec

object Main extends App {
  val Array(a, b, c) = readLine.split(" ").map(_.toLong)

  if (a % 2 == 0 && a == b && b == c) println("-1")
  else {
    println(solve(0, a, b, c))
  }

  @tailrec
  def solve(count: Int, a: Long, b: Long, c: Long): Int = {
    if ((a % 2 + b % 2 + c % 2) != 0) count
    else {
      solve(count + 1, (b + c) /2, (c + a) / 2, (a + b) / 2)
    }
  }
}


Measured memory_bytes: 27208
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int main(){
  int n,ans;
  cin>>n;
  vector<int>x(n+1);
  for(int i=0;i<=n;i++)cin>>x[i];
  sort(x.begin(),x.end());
  for(int i=0;i<n;i++)x[i]=x[i+1]-x[i];
  x.pop_back();
  ans=x[0];
  for(int i=1;i<n;i++)ans=gcd(ans,x[i]);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <limits>
#include <cmath>
#include <cstdio>

using namespace std;

#define EPS (numeric_limits<double>::epsilon())
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
public:
    double x, y;

    Point(double x = 0, double y = 0) : x(x), y(y) {}

    Point operator+(const Point &p) const
    {
        return Point(x + p.x, y + p.y);
    }

    Point operator-(const Point &p) const
    {
        return Point(x - p.x, y - p.y);
    }

    Point operator*(const double &a) const
    {
        return Point(a * x, a * y);
    }

    Point operator/(const double &a) const
    {
        return Point(x / a, y / a);
    }

    double abs()
    {
        return sqrt(norm());
    }

    double norm()
    {
        return x * x + y * y;
    }

    bool operator<(const Point &p) const
    {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator==(const Point &p) const
    {
        return equals(x, p.x) && equals(y, p.y);
    }
};

typedef Point Vector;

struct Segment {
    Point p1, p2;
};
typedef Segment Line;


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

double cross(Vector a, Vector b)
{
    return a.x * b.y - a.y * b.x;
}

bool isParallel(Vector a, Vector b)
{
    return equals(cross(a, b), 0.0);
}

bool isParallel(Point a1, Point a2, Point b1, Point b2)
{
    return equals(cross(a2 - a1, b2 - b1), 0.0);
}

bool isOrthogonal(Vector a, Vector b)
{
    return equals(dot(a, b), 0.0);
}

bool isOrthogonal(Point a1, Point a2, Point b1, Point b2)
{
    return equals(dot(a2 - a1, b2 - b1), 0.0);
}

Point project(Segment s, Point p)
{
    Vector hypo = p - s.p1;
    Vector base = s.p2 - s.p1;
    return base * (dot(hypo, base) / base.norm()) + s.p1;
}

int main()
{
    Point p1, p2;
    cin >> p1.x >> p1.y >> p2.x >> p2.y;
    Segment s{p1, p2};
    int query;
    cin >> query;
    Point p;
    for (int q = 0; q < query; q++)
    {
        cin >> p.x >> p.y;
        Point x = project(s, p);
        printf("%.10f %.10f\n", x.x, x.y);
    }
}


Measured memory_bytes: 3284
#include <stdio.h>
#define N 100000
#define INF 1000000
#define size 20

struct Card_t{
  char art;
  int value;
};

struct Card_t L[N/2+2],R[N/2+2];

int n;

void merge(struct Card_t A[],int l,int m,int r){
  int i,j,k;
  int n1 = m - l;
  int n2 = r - m;
  for(i=0;i<n1;i++)L[i]=A[l+i];
  for(i=0;i<n2;i++)R[i]=A[m+i];
  L[n1].value = R[n2].value = INF;
  i = j = 0;
  for(k = l;k < r;k++){
    if(L[i].value <= R[j].value){
      A[k]=L[i++];
    }else{
      A[k]=R[j++];
    }
  }
}

void mergeSort(struct Card_t A[],int l,int r){
int m;
if(l+1<r){
m=(l+r)/2;
mergeSort(A,l,m);
mergeSort(A,m,r);
merge(A,l,m,r);
}
}

int partition(struct Card_t A[],int p,int r){
  int i,j;
  struct Card_t temp,s;
  s = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j].value <= s.value){
      i++;
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
    }
  }
  temp = A[i+1];
  A[i+1]=A[r];
  A[r]=temp;
  return i+1;
}

void quickSort(struct Card_t A[], int p, int r){
  int q;
  if (p < r){
  q = partition(A, p, r);
  quickSort(A, p, q-1);
  quickSort(A, q+1, r);
  }
}

int main(){
int i,num,stable=1;

struct Card_t A[N],B[N];
char str[size];

scanf("%d",&n);

for(i=0;i<n;i++){
  scanf("%s %d",str,&num);
  A[i].art=B[i].art=str[0];
  A[i].value=B[i].value=num;
}

mergeSort(A,0,n);
quickSort(B,0,n-1);

for(i=0;i<n;i++){
  if(A[i].art!=B[i].art) stable=0;
}

if(stable==1) printf("Stable\n");
else printf("Not stable\n");

for(i=0;i<n;i++){
  printf("%c %d\n",B[i].art,B[i].value);
}

return 0;
}

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

int main(){
  int X,Y,Z,K;
  cin>>X>>Y>>Z>>K;
  vector<int64_t> A(X),B(Y),C(Z);
  for(int i=0;i<X;++i){cin>>A.at(i);}
  sort(A.begin(),A.end(),greater<int64_t>());
  for(int i=0;i<Y;++i){cin>>B.at(i);}
  sort(B.begin(),B.end(),greater<int64_t>());
  for(int i=0;i<Z;++i){cin>>C.at(i);}
  sort(C.begin(),C.end(),greater<int64_t>());

  priority_queue<int64_t> pq;
    for(int i=0;i<X;++i){
      for(int j=0;j<Y;++j){
        for(int k=0;k<Z && (i+1)*(j+1)*(k+1)<=3000;++k){
          pq.push(A.at(i)+B.at(j)+C.at(k));
        }
      }
    }

    int count=0;
    while(count<K){
      cout<<pq.top()<<endl;
      pq.pop();
      ++count;
    }
}


Measured memory_bytes: 1404
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 10000;

int main(){
    int k,n;
    cin>>k>>n;
    vector<int> arr(n+1);

    for(int i = 0; i < n; i++) cin>>arr[i];
    int res = INT_MAX;
    arr[n] = k+arr[0];
    for(int i = 0; i < n; i++){
        res = min(res, k - (arr[i+1]-arr[i]));
    }
    cout<<res;
}



Measured memory_bytes: 4040
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int A,B;cin>>A>>B;
    cout<<max(A+B,max(A-B,A*B))<<endl;
}

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

using namespace std;

int main() {
    long long x, y;
    cin >> x >> y;
    
    long long d = abs(abs(x) - abs(y));
    
    long long res = 0;
    if (x == y) res = 0;
    else if ( (x >= 0 && y > x) || ( x < y && y <= 0) ) res = d;
    else if ((y > 0 && x > y) || (x < 0 && y < x)) res = d +2;
    else res = d+ 1;
    
    cout << res << endl;
}

Measured memory_bytes: 256
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;

typedef pair<LL, LL> PP;

int a, b, c;
int main() {
	cin >> a >> b >> c;
	cout << ((a + b == c) || (b + c == a) || (c + a == b) ? "Yes" : "No") << endl;
	return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    if((a-b)%2==0){
        cout << (a+b)/2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 764
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
using System.Numerics;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x, long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }
        public static long keta(long x)
        {
            var z = 1;
            while (x > 0)
            {
                x /= 10;
                z++;
            }
            return z;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var ny = Reads();
            var n = ny[0];
            var y = ny[1];
            var ans = "";
            for (int i = 0; i <= 2000; i++)
            {
                for (int j = 0; j <=2000; j++)
                {
                    if (y - 10000 * i - 5000 * j - 1000 * (n - i - j) == 0&&n-i-j>=0)
                    {
                        ans = i + " " + j + " " + (n - i - j);
                        WriteLine(ans);
                        break;
                    }
                }
                if (ans != "") break;
            }
            if (ans == "") WriteLine("-1 -1 -1");


          
            Console.Out.Flush();
        }
    }
}



Measured memory_bytes: 18900
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int a,b,i,j;
	cin>>s;
	for(i=0;i<s.size();i++)
	{
		for(j=i+1;j<s.size();j++)
		{
			if(s[i]==s[j])
			{
				cout<<"no";
				return 0;
			}
		}
	}
	cout<<"yes";
}


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

// clang-format off
#define rep(i, n) for(int i=0; i< (n); i++)
#define reps(i, a, n) for(int i=a; i < (n); i++)

const int INF{1001001001};
const int MOD{(int)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

int main(){
    int N,sn,ans;
    cin >> N;
    
    int n = N;
    while(n != 0){
        sn += n % 10;
        n /= 10;
    }
    
    if(N % sn == 0)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);


ll n, k;
vector<ll> a;

void solve() {
    ll bits[48];
    fill(bits, bits + 48, 0);

    rep(i, n) {
        bitset<48> bitset1(a[i]);
        int idx = 0;
        while (bitset1.to_ullong() > 0) {
            bits[idx] += (bitset1.to_ullong() & 1);
            bitset1 = (bitset1 >> 1);

            idx++;
        }
    }

    ll ans = 0;
    repr(i, 48) {
        if (bits[i] <= n / 2) {
            ll temp = ll(pow(2, i));
            if (ans + temp <= k) ans += temp;
        }
    }
    ll ans_f = 0;
    rep(i, n) {
        ans_f += ans^a[i];
    }
    cout << ans_f << endl;
}

int main() {
    cin >> n >> k;
    a.resize(n);
    rep(i, n) cin >> a[i];
    solve();
    return 0;
}

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

typedef long long ll;

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,l,n) for(int i=(l);i<(n);i++)

template<class T>
using vt = vector<T>;
template<class T>
using vvt = vector<vector<T>>;


int main(){
    string s,t;
    cin >> s >> t;
    cout << t+s << endl;
    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int H,W,N;
    scanf("%d",&H);
    scanf("%d",&W);
    scanf("%d",&N);
    if(H>W)
    {
        if(N%H==0)
            printf("%d\n",N/H);
        else printf("%d",(N/H)+1);
    }
    else
    {
        if(N%W==0)
            printf("%d\n",N/W);
        else printf("%d",(N/W)+1);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
    
using namespace std;
 
#define f first
#define s second
#define pb push_back
#define sz(v) ((int)v.size())   
#define rad(a) a * PI / 180  
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> ii;
typedef vector<ii> vii;	
typedef pair<int,char> ic;
typedef pair<ll, bool> llb;
 
const int SIGMA = 20;
const int MAX = 100010;
const int MAXT = 262145;
const ll INF = 10000000000000000LL;
const ll P = 998244353LL; //1000000007;
const double EPS = 1e-6;
const double PI = 3.14159265358979;

int N, M;
ll memo[MAX];
ll tree[MAXT];
vii reach[MAX];
ll update(int b,int e,int node,int p){
	if(p < b || p > e) return tree[node];
	if(b == e) return tree[node] = memo[e];
	int m = (b + e) / 2;
	return tree[node] = min(update(b,m,node*2 + 1,p), update(m+1,e,node*2+2,p));
}

ll query(int b,int e,int node,int bt,int et){
	if(et < b || bt > e) return INF;
	if(b <= bt && et <= e) return tree[node];
	int mt = (bt + et) / 2;
	return min(query(b,e,node*2+1,bt,mt),query(b,e,node*2+2,mt+1,et));
}

ll pd(){
	for(int i = 0; i < N; i++) memo[i] = INF;
	memo[N-1] = 0LL;
	for(int i = N-2; i >= 0; i--){	
		for(int j = 0; j < sz(reach[i]); j++){
			ll C = reach[i][j].f;
			int R = reach[i][j].s;

			ll mn = query(i+1,R,0,0,N-1);

			if(mn >= INF) continue;

			memo[i] = min(memo[i], C + mn);			
		}
		update(0,N-1,0,i);
	}
	return memo[0];
}

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

	cin >> N >> M;
	while(M--){
		int Li, Ri, Ci;
		cin >> Li >> Ri >> Ci;
		Li--; Ri--;
		reach[Li].pb(ii(Ci,Ri));
	}

	ll total = pd();
	if(total >= INF){
		cout << -1 << endl;	
	}
	else {
		cout << total << endl;
	}

	return 0;
}


Measured memory_bytes: 8448
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <regex>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define for(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)
#define sz(x)        ((ll)(x).size())
#define inf          1<<25

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

//typedef vector<int> vi;
//typedef vector<long long> vl;
//typedef vector<double> vd;
//typedef pair<int,int> pii;
//typedef pair<long,long> pll;
//typedef long long ll;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    
    ll sum = 0;
    rep(i, n+1) {
        ll j = i;
        ll x = 0;
        while (j > 0) {
            x += j % 10;
            j /= 10;
        }
        if (a <= x && x <= b) sum += i;
    }
    cout << sum << endl;
    
    return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pll> vp;
typedef vector<ll> vll;

const int inf = 1e6;
const int MAX = 1e6;

int dp1[MAX];
int dp2[MAX];

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

    vi a1;
    vi a2;

    a1.emplace_back(1);
    a2.emplace_back(1);
    rep2(i, 1, 300) {
        int x = i * (i + 1) * (i + 2) / 6;
        if (x >= MAX) break;
        a1.emplace_back(x);
        if (x & 1) a2.emplace_back(x);
    }

    fill(dp1, dp1 + MAX, inf);
    dp1[0] = 0;
    for (int x : a1) {
        rep2(i, x, MAX) {
            dp1[i] = min(dp1[i], dp1[i - x] + 1);
        }
    }

    fill(dp2, dp2 + MAX, inf);
    dp2[0] = 0;
    for (int x : a2) {
        rep2(i, x, MAX) {
            dp2[i] = min(dp2[i], dp2[i - x] + 1);
        }
    }


    int n;
    while (cin >> n && n) {
        cout << dp1[n] << " " << dp2[n] << endl;
    }

}

Measured memory_bytes: 10836