akhauriyash/Code-Regression huggingface dataset:
#define pnode node*
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<ll, ll, hash<ll>> ht;

void bad(){
    cout << -1 << "\n";
    exit(0);
}


ll n;
string s;
vector < ll > a;
void solve(){
    cin >> s;
    n = s.size();
    a.resize(n + 1);
    for(ll i = 1; i <= n; ++i){
        a[i] = s[i - 1] - '0';
    }
    if(!a[1] || a[n])bad();
    for(ll i = 1; i <= n; ++i){
        if(a[i] != a[n - i])bad();
    }
    vector < pair < ll, ll > > b;
    ll curid = 1;
    ll prvver = 0;
    ll prv = 1;
    for(ll i = 2; i < n; ++i){
        if(a[i] == 0)continue;
        ll cid = curid;
        b.push_back({curid, prvver});
        for(ll j = curid + 1; j < curid + (i - prv); ++j){
            b.push_back({curid, j});
        }
        prvver = curid;
        curid = curid + (i - prv);
        prv = i;
    }
    if(curid != n){
        b.push_back({curid, prvver});
        for(ll i = curid + 1; i < n; ++i){
            b.push_back({curid, i});
        }
    }
    for(auto i: b){
        cout << i.first + 1 << " " << i.second + 1 << "\n";
    }
}

signed main(){
    int t = 1;
    srand(time(0));
    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    //cin >> t
    while(t--){
        solve();
    }
}


Measured memory_bytes: 4080
#include<stdio.h>
int main(){
  int n,a,b,c,t[1010],h[1010],i;
  scanf("%d %d %*d %d",&n,&a,&b);
  for(i=0;i<n;i++)scanf("%d %d",&t[i],&h[i]);
  for(i=0;1;i=(i+1)%n){
    if(t[i]){
      t[i]--;
      c+=10;
      a++;
      if(a>b)break;
    }
    else{
      if(h[i]==0)break;
      h[i]--;
      c+=100;
    }
    if(c>=90){
      a-=c/10-9;
      t[i]+=c/10-9;
      c=0;
      if(a<0)break;
    }
  }
  printf("%d\n",i+1);
  return 0;
}

Measured memory_bytes: 608
s = raw_input()
r = ''
for c in s:
    d = c
    if c >= 'a' and c <= 'z':
        d = chr(ord(c) - ord('a') + ord('A'))
    if c >= 'A' and c <= 'Z':
        d = chr(ord(c) - ord('A') + ord('a'))
    r = r + d
print r

Measured memory_bytes: 4212
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            String s;
            while ((s = Console.ReadLine()).Length != 0) {
                String[] ss = s.Split(' ');
                int n0 = int.Parse(ss[0]);
                int n1 = int.Parse(ss[1]);
                if (n0 == 0 && n1 == 0) break;
                DateTime dataValue = new DateTime(2004, n0, n1);
                Console.WriteLine(dataValue.DayOfWeek);
            }
        }
    }
}

Measured memory_bytes: 9300
#include <iostream>
#include <queue>
#include <vector>

constexpr int MAX = 1e5 + 10;
#include <iostream>

int main()
{

    int x, y, z;
    std::cin >> x >> y >> z;
    std::cout << z << ' ' << x << ' ' << y << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> P;

P rotate(P s, P t){
  P p;
  p.first = s.second-t.second+t.first;
  p.second = t.second-s.first+t.first;
  return p;
}

int main(){
  P p1, p2, p3, p4;
  cin >> p1.first >> p1.second >> p2.first >> p2.second;
  p3 = rotate(p1,p2);
  p4 = rotate(p2,p3);
  cout << p3.first << " " << p3.second << " " << p4.first << " " << p4.second << endl;
  return 0;
}


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

int board[12][12];
int used[12];
int mask[12];
int all = (1 << 10) - 1;

int makeCurrMask(int curr, int m){
	for(int i=0;i<10;i++){
		if((m >> i) & 1){
			int t = (i == 0) ? (7 >> 1) : (7 << (i - 1));
			curr ^= t;
		}
	}
	return curr & all;
}

bool dfs(int prev, int curr, int index){
	if(index >= 10){
		if(prev)return false;
		return true;
	}
	for(int m=0;m<(1<<10);m++){
		if(index > 0 && prev ^ m)continue;
		int ncurr = makeCurrMask(curr, m);
		int next = mask[index+1] ^ m;

		used[index] = m;
		if(dfs(ncurr, next, index + 1)){
			return true;
		}
	}
	return false;
}

void solve(){
	memset(mask, 0, sizeof(mask));
	memset(used, 0, sizeof(used));
	for(int y=0;y<10;y++){
		int m = 0;
		for(int x=0;x<10;x++){
			m = ((m << 1) + board[y][x]);
		}
		mask[y] = m;
	}
	dfs(-1, mask[0], 0);
}

void output(){
	for(int y=0;y<10;y++){
		int m = used[y];
		for(int x=9;x>=0;x--){
			if(x != 9)cout << " ";
			cout << (((m >> x) & 1) ? 1 : 0);
		}
		cout << endl;
	}
}

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

	for(int t=0;t<n;t++){
		for(int y=0;y<10;y++){
			for(int x=0;x<10;x++)cin >> board[y][x];
		}
		solve();
		output();
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll N,M,Q;
ll ans;
ll A[50];
ll B[50];
ll C[50];
ll D[50];
ll a[50];
 
 
int main(){
    cin >> N >> M;
    if(N%2==0){
        for(int i=0;i<M;i++){
            if(i<N/4){
                cout << i+1 << " " << N/2-i << endl;
            }else{
                cout << N/2 + 1 + i - N/4 <<" " << N - 1 -(i-N/4) << endl;
            }
        }
    }else{
        for(int i=0;i<M;i++){
            if(i<(N+1)/4){
                cout << i+1 << " " << (N+1)/2-i << endl;
            }else{
                cout << (N+1)/2 + 1 + i - (N+1)/4 <<" " << N  -(i-(N+1)/4) << endl;
            }
        }
    }
    
}


Measured memory_bytes: 3640
r, g, b, n = map(int, input().split())
count = 0
for i in range(n//r+1):
    for j in range((n-i*r)//g+1):
        left = n - i*r - j*g
        if left >= 0 and left % b == 0:
            count += 1
print(count)

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

int main() {
    int a, b, c;  cin >> a >> b >> c;
    if (a == b)  cout << c << endl;
    else if (a == c)  cout << b << endl;
    else  cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

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

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll K, N,max_d;
	std::cin >> K >> N;
	vll A(N+1,0);
	max_d = 0;
	repeq(i,1, N) {
		std::cin >> A[i];
		max_d = max(max_d, A[i] - A[i - 1]);
	}
	max_d = max(max_d, A[1] + K - A[N]);

	std::cout << K - max_d << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,i;
    cin>>n;
    ll a;
    map<ll,ll> f;
    for (i=0;i<n;i++)
    {
        cin>>a;
        f[a]++;
    }
    ll ans=0;
    for (auto e: f)
    {
        if (e.ff<e.ss)
            ans+=e.ss-e.ff;
        else if (e.ff>e.ss)
            ans+=e.ss;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6272
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    int d, g;
    int amount[11], bonus[11];
    int answer = 10000;
    cin >> d >> g;
    for (int i = 1; i <= d; i++) {
        cin >> amount[i] >> bonus[i];
    }
    std::vector<int> perm;
    for (int i = 1; i <= d; i++) {
        perm.push_back(i);
    }

    do {
        // cout << "next_permutation" << endl;
        int score = 0;
        int count = 0;
        auto itr = perm.begin();

        // cout << "itr is " << *itr << endl;
        int target = *itr;
        // cout << "target is " << target << endl;
        // cout << "amount[target] is " << amount[target] << " bonus[target] is
        // "<< bonus[target] << endl;
        while (score + amount[target] * (target)*100 + bonus[target] <= g) {
            score = score + amount[target] * (target)*100 + bonus[target];
            count += amount[target];
            itr++;
            target = *itr;

            // cout << "score is" << score << " count is " << count << endl;
        }
        int overkill = count + amount[target];
        while (score < g) {
            score = score + (target)*100;
            count++;
            // cout << "score is" << score << " count is " << count << endl;
        }

        if (count < answer) {
            answer = count;
        }
        if (overkill < answer) {
            answer = overkill;
        }
    } while (std::next_permutation(perm.begin(), perm.end()));

    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 384
/*
ID: hzhu7271 
LANG: C++
TASK: 
*/
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

/* FILE IO */
void setIO(string filename = "") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if ((int)filename.size()) { /* USACO */
        freopen((filename+".in").c_str(), "r", stdin);
        freopen((filename+".out").c_str(), "w", stdout);
    }
}

int N;
array<int,3> activity[100000];
int dp[100000][3];

int main(){
    setIO();
    cin >> N;
    for(int i=0;i<N;++i){
        cin >> activity[i][0] >> activity[i][1] >> activity[i][2];
    }
    for(int i=0;i<3;++i){
        dp[0][i]=activity[0][i];
    }
    for(int i=1;i<N;++i){
        dp[i][0]=activity[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=activity[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=activity[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout << max({dp[N-1][0], dp[N-1][1], dp[N-1][2]}) << endl;
    return 0;
}


Measured memory_bytes: 5968
#include <bits/stdc++.h>
#define ll  long long int
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i :c)
#define pii pair< int,int >
#define Fast_IO() ios_base::sync_with_stdio(false);cin.tie(0)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define _ <<" "<<
const int MOD = 1000 * 1000 * 1000 + 7; // odd modulus
using namespace std;
clock_t time_p=clock();
void dem()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
int main()
{
    Fast_IO();
    int n ;
    cin >> n ;
    vi v ( n , 0 ) ;
    for ( int &x : v)cin >> x ;
    int inv = 0 ;
    for ( int i = 0 ; i < n ; ++ i )
    {
        inv += ( i + 1  != v[i]) ;

    }

    if ( inv == 0 || inv == 2  )
        cout << "YES" ;
    else
        cout << "NO" ;
    return 0 ;
}
/*
1
5 3
7 18 3 14 1
*/


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
#include <bitset>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b and b != c) cout << "Yes" << endl;
    else if(a == c and a != b) cout << "Yes" << endl;
    else if(b == c and a != b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3616
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function main(input) {
  n = parseInt(input);
  n = n % 10;
  if ([2, 4, 5, 7, 9].includes(n)) {
    console.log('hon');
  } else if ([0, 1, 6, 8].includes(n)) {
    console.log('pon');
  } else {
    console.log('bon');
  }
}


Measured memory_bytes: 29416
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,t;cin>>n>>t;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) {
		cin>>a[n - 1 - i];
	}
	map<ll,ll> ans;
	ll tmp = a[0];
	ll profit = 0;
	for(int i = 1; i < n; i++) {
		if (profit <= tmp - a[i]){
			ans[tmp - a[i]]++;
			profit = tmp - a[i];
		}
		tmp = max(tmp,a[i]);
	}
	cout << ans[profit] << endl;
	return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int P = 1e9 + 7;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	string s;
	cin >> s;
	ll ans = 1;
	ll cnt = 0;
	for(int i = 1; i <= n; ++i) {
		ans = ans * i % P;
	}
	for(int i = 0; i < 2 * n; ++i) {
		if((cnt & 1) == (s[i] == 'B')) {
			ans = ans * cnt % P;
			--cnt;
		} else {
			++cnt;
		}
	}
	if(cnt) {
		cout << 0 << '\n';
	} else {
		cout << ans << '\n';
	}
	return 0;
}

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

char s[10];
int mask = 0;
int main(){
	cin >> s;
	int fi = 10 * (s[0] - '0') + (s[1] - '0');
	int se = 10 * (s[2] - '0') + (s[3] - '0');
	mask |= 1 * (fi <= 12 && fi > 0);
	mask |= 2 * (se <= 12 && se > 0);
	if (mask == 0) cout << "NA\n";
	else if (mask == 1) cout << "MMYY\n";
	else if (mask == 2) cout << "YYMM\n";
	else cout << "AMBIGUOUS\n";
	return 0;
}


Measured memory_bytes: 384
#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>;

int main() {
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    vector<int> A(n), B(p, 0);
    B[0]++;
    long long ans = 0;
    if (p==2 || p==5) {
        rep(i,n) {
            if ((s[i]-'0')%p==0) ans += i+1;
        }
    } else {
        int t = 1;
        rep(i,n) {
            A[i] = ((s[n-i-1]-'0') % p) * t % p;
            t = (t*10) % p; 
            if (i > 0) A[i] = (A[i] + A[i-1]) % p;
            ans += B[A[i]];
            B[A[i]]++;
        }    
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;
using namespace std;

int dp[10000],w[100],v[100];
int main(){
    int n,ww;
    cin>>n>>ww;
    rep(i,n) cin>>v[i]>>w[i];
    rep(i,n){
        for(int j=ww-w[i];j>=0;--j) dp[j+w[i]]=max(dp[j+w[i]],dp[j]+v[i]);
    }
    cout<<dp[ww]<<endl;
    return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define pii pair<int, int>
typedef unsigned long long uLL;
typedef long long LL;
using namespace std;
constexpr int MAXM = 2e4 + 4;
int n, mx;
map<string, int>cnt, vis;
vector<string>vec, ans;
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	vec.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> vec[i];
		cnt[vec[i]]++;
		mx = max(mx, cnt[vec[i]]);
	}
	for (int i = 0; i < n; i++) {
		string s = vec[i];
		if(cnt[s] == mx && !vis[s]) ans.push_back(s), vis[s] = true;
	}
	sort(ans.begin(), ans.end());
	for (auto i : ans) cout << i << endl;
	return 0; 
}

Measured memory_bytes: 39536
package main

import (
        "fmt"
)

func solution(n, m int, ab, cd [][]int) []int {
        out := make([]int, n)

        for i := range ab {
                near := 1 << 31
                for j := range cd {
                        cur := abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
                        if near > cur {
                                near = cur
                                out[i] = j + 1
                        }
                }
        }
        return out
}

func abs(x int) int {
        if x < 0 {
                return -x
        }
        return x
}

func main() {
        var n, m int
        fmt.Scan(&n, &m)
        ab := make([][]int, n)
        for i := range ab {
                ab[i] = make([]int, 2)
                fmt.Scan(&ab[i][0], &ab[i][1])
        }
        cd := make([][]int, m)
        for i := range cd {
                cd[i] = make([]int, 2)
                fmt.Scan(&cd[i][0], &cd[i][1])
        }
        for _, num := range solution(n, m, ab, cd) {
                fmt.Println(num)
        }
}

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

int main() {
	string n;
    cin >> n;
    int size = n.size();
    int count = 0;

    if(n.size() == 1){
        count = n.at(0) - 48;
    }
    else if (n.at(0) != '9'){
        int digit;
        for (digit  = 1; digit < n.size(); digit++){
            if (n.at(digit) != '9'){
                break;
            }
        }
        if (digit == n.size()){
            count = 9 * (n.size() - 1) + n.at(0) - 48;
        }else{
            count = 9 * (n.size() - 1) + (n.at(0) - 49);
        }
        
    }
    else{
        int digit;
        for (digit  = 0; digit < n.size(); digit++){
            if (n.at(digit) != '9'){
                break;
            }
        }
        if (digit == n.size()){
            count = 9 * n.size();
        }
        else{
            count = (digit - 1) * 9 + (n.at(digit - 1) - 49) 
            + (n.size() - digit) * 9;
        }

    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <numeric>

#define repAll(n) (n).begin(), (n).end()
#define repConAll(n) (n).cbegin(), (n).cend()

using namespace std;

namespace {

}

int main()
{
	int N = 0;
	cin >> N;
	vector<int> a(N);
	map<int, int> num;
	for (int i = 0; i < N; ++i){
		int curData = 0;
		cin >> curData;
		if (num.count(curData) == 0){
			num[curData] = 1;
		}
		else {
			++num[curData];
		}
	}
	long long sum = 0;
	for (auto itr = num.begin(); itr != num.end(); ++itr){
		if (itr->second >= itr->first){
			sum += itr->second - itr->first;
		}
		else {
			sum += itr->second;
		}

	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define ll128 __uint128_t
#define ld long double
#define pll pair <ll, ll>

#define vll vector <ll>
#define vld vector<ld>
#define vpll vector<pll>

#define vvll vector <vll>

#define rep(i, a, b) for(ll i = a; i < b; i++)
#define per(i, a, b) for(ll i = (ll)a - 1; i >= b; --i)

#define endl "\n"
#define pb push_back
#define pf push_front

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define sorta(v) sort(all(v))
#define sortd(v) sort(rall(v))

#define debug if (1)
#define log(val) debug {cout << "\n" << #val << ": " << val << "\n";}

#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define file(name) freopen(name".in", "r", stdin); freopen(name".out", "w", stdout);
#define FILE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

#define mod (ll)(1e9 + 7)
#define inf (mod * mod)

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

ostream & operator << (ostream & out, vll & a) {
    for(auto i : a) out << i << " ";
    return out;
}

istream & operator >> (istream & in, vll & a) {
    for(auto &i : a) in >> i;
    return in;
}

int main() {
    string s;
    cin >> s;

    ll n = s.size();

    for (ll i = 0; i < n; i++) {
        if (i + 1 < n && s[i] == s[i + 1]) {
            cout << i + 1 << " " << i + 2 << endl;
            return 0;
        }
        if (i + 2 < n && s[i] == s[i + 2]) {
            cout << i + 1 << " " << i + 3 << endl;
            return 0;
        }
    }

    cout << -1 << " " << -1 << endl;

    return 0;
}


Measured memory_bytes: 3760
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

long long n,m,a[10001],sum=0;

int main()
{
	cin >> n >> m;
	for(int i=0;i<m;i++){
		cin >> a[i];
		sum+=a[i];
	}
	n-=sum;
	if(n<0) puts("-1");
	else cout << n << "\n";
}

Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long A = sc.nextLong();
        sc.close();

        long count = 0;
        while (true) {
            H -= A;
            count++;
            if (H <= 0) {
                break;
            }
        }

        System.out.println(count);
    }

}

Measured memory_bytes: 23508
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    ll n;
    scanf("%lld", &n);

    ll a = n % 11;
    ll b = n / 11;
    if (a == 0) {
        printf("%lld\n", b*2); return;
    }
    ll ans = b*2 + (a > 6 ? 2 : 1);
    printf("%lld\n", ans);
    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d%d", &T, &B);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <functional>
#include <fstream>
#include <iostream>
#include <set>
#include <vector>
#include <string.h>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("file.1", "r", stdin);

  int n, m;
  cin >> n >> m;
  vector<ll> a(n + 1, 0);
  vector<ll> f(n + 1, 0);
  int i, j;
  for (i = 0; i < m; i++) {
    int ai;
    cin >> ai;
    a[ai] = 1;
  }
  for (i = 1; i < n; i++) {
    if (a[i] == 1 && a[i + 1] == 1) {
      cout << 0 << endl;
      return 0;
    }
  }
  f[0] = 1;
  f[1] = 1;
  for (i = 2; i <= n; i++) {
    f[i] = (f[i - 1] + f[i - 2]) % MOD;
  }
  // for (i = 1; i <= n; i++) {
  //   cout << a[i] << " ";
  // }
  // cout << endl;
  // for (i = 1; i <= n; i++) {
  //   cout << f[i] << " ";
  // }
  // cout << endl;
  ll ans = 1;
  ll cnt = 1;
  for (i = 1; i <= n; i++) {
    if (a[i] == 1) {
      // cout << "C:" << cnt << endl;
      ans = ans * f[cnt - 1] % MOD;
      cnt = 0;
    } else {
      cnt++;
    }
  }
  if (cnt > 0) {
    // cout << "C:" << cnt << endl;
    // cout << "F:" << f[cnt - 2] << endl;
    ans = ans * f[cnt - 1] % MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>
#define MAX 100000
#define SENTINEL 2000000000
using namespace std;

struct Card {
	char suit;
	int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right)
{
	int i, j, k;
	int n1 = mid - left;
	int n2 = right - mid;
	for (i = 0; i < n1; i++)L[i] = A[left + i];
	for (i = 0; i < n2; i++)R[i] = A[mid + i];
	L[n1].value = R[n2].value = SENTINEL;
	i = j = 0;
	for (k = left; k < right; k++) {
		if (L[i].value <= R[j].value) {
			A[k] = L[i++];
		}
		else {
			A[k] = R[j++];
		}
	}
}

void mergesort(struct Card A[], int n, int left, int right)
{
	int mid;
	if (left + 1 < right) {
		mid = (left + right) / 2;
		mergesort(A, n, left, mid);
		mergesort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}

int Partition(struct Card A[], int n,int p, int r)
{
	int i, j ;
	struct Card t, x;
	x = A[r];
	i = p - 1;
	for (j = p; j < r; j++) {
		if (A[j].value <= x.value) {
			i++;
			t = A[i]; A[i] = A[j]; A[j] = t;
		}
	}
	t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
	return i + 1;
}

void QSort(struct Card A[], int n, int p,int r)
{
	int q;
	if (p < r) {
		q = Partition(A,n,p, r);
		QSort(A,n,p, q - 1);
		QSort(A,n,q + 1, r);
	}
}

int main()
{
	int n, i, v;
	struct Card A[MAX], B[MAX];
	char S[10];
	int stable = 1;

	scanf("%d", &n);

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

	mergesort(A, n, 0, n);
	QSort(B, n, 0, n - 1);

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

	if (stable == 1)cout << "Stable" << endl;
	else cout << "Not stable" << endl;
	for (i = 0; i < n; i++) {
		cout << B[i].suit <<" "<< B[i].value<<endl;
	}
	return 0;
}


Measured memory_bytes: 5488
n, m, k = map(int, input().split())

val = []

for i in range(0, n + 1):
    for j in range(1, m + 1):
        x = i * j + (n - i) * (m - j)
        val.append(x)
        
val = set(val)

print("Yes" if k in val else "No")

Measured memory_bytes: 54956
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int gcd(int a,int b){
	while(b){
		a%=b;
		swap(a,b);
	}
	return a;
}
int main(){
	int n;
	cin>>n;
	vector<int> line(n);
	for(int i=0;i<n;++i){
		cin>>line[i];
	}
	int man = line[0];
	for(int i=1;i<n;++i){
		man = gcd(man,line[i]);
	}
	vector<int> front;
	vector<int> back;
	for(int i=1;i*i<=man;++i){
		if(i*i==man){
			front.push_back(i);
			break;
		}
		if(man%i==0){
			front.push_back(i);
			back.push_back(man/i);
		}
	}
	for(int i=0;i<front.size();++i){
		cout<<front[i]<<endl;
	}
	for(int i=back.size()-1;i>=0;--i){
		cout<<back[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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 long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	lint x,m=100,count=0;
	cin>>x;
	while(m<x){
		count++;
		m+=m*0.01;
	}
	cout<<count<<endl;
}

Measured memory_bytes: 3604
function Main(input) {
    input = input.split("\n");
    input.shift();
    var arr = new Array(input[0].length+2).fill("#").join("");
    for(var i=0;i<input.length;i++){
        input[i] = "#"+input[i]+"#";
    }
    input.unshift(arr);
    input.push(arr);
    console.log(input.join("\n"))
}Main(require("fs").readFileSync("/dev/stdin","utf8").trim());


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

const int V = 100000;
const int INF = 0x3f3f3f3f;

int n,m,w[100005],v[100005];
int ans;
int f[100005];

int main()
{
	memset(f,INF,sizeof(f));
	f[0] = 0;
	cin>>n>>m;
	for(int i=1;i<=n;cin>>w[i]>>v[i],i++);
	for(int i=1;i<=n;i++)
		for(int j=V;j>=v[i];j--)
		{
			f[j] = min(f[j],f[j-v[i]]+w[i]);
			if(f[j]<=m)
				ans = max(ans,j);
		}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 640
W,H,N=map(int,input().strip().split(" "))
Sum=0
r=0
xx=0
yy=0
for i in range(N):
    x,y,a=map(int,input().strip().split(" "))
    
    if(a==1):
        if(xx<x):
            xx=x
    elif(a==2):
        if(W>x):
            W=x
    elif(a==3):
        if(yy<y):
            yy=y
    elif(a==4):
        if(H>y):
            H=y
Sum=(W-xx)*(H-yy)

if((W-xx)<=0 or (H-yy)<=0):
    print("0")
else:
    print(Sum)


Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {

  int year,yen;

  scanf("%d%d",&year,&yen );

  if(year <= 5){
    printf("%d\n",yen-yen );
  }else if (year < 13) {
    printf("%d\n",yen/2 );
  }else{
    printf("%d\n",yen );
  }

  return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();

    int[] wcount = new int[N];
    int[] ecount = new int[N];
    for (int i = 0; i < N; i++) {
      wcount[i] = i == 0 ? 0 : wcount[i-1];
      if (S.charAt(i) == 'W') {
        wcount[i]++;
      }
    }
    for (int i = N-1; i >= 0; i--) {
      ecount[i] = i == N-1 ? 0 : ecount[i+1];      
      if (S.charAt(i) == 'E') {
        ecount[i]++;
      }
    }
    
    int ans = Integer.MAX_VALUE;
    for (int i = 0; i < N; i++) {
      int count = i < N-1 ? wcount[i] + ecount[i+1] : wcount[i];
      if (S.charAt(i) == 'W') {
        count--;
      }
      ans = Math.min(ans, count);
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 30788
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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 ans = 0;
  int N;
  cin >> N;
  ans -= N;
  vector<int> a(N);
  rep(i, N) {
    cin >> a[i];
    ans += a[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



int main() {
    ll N, A, B, C, D;
    cin>>N>>A>>B>>C>>D;

    bool flg = false;
    for (int i = 0; i <= N-1; i++) {
        if(C*i-D*(N-1-i)<=B-A && B-A <= D*i-C*(N-1-i)){
            flg = true;
            break;
        }
    }
    if(flg)puts("YES");
    else puts("NO");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define VMAX 100000
#define MAXLOOP 200000000
void solve(long long N, long long W, vector<long long> w, vector<long long> p){
  long long vmax = (MAXLOOP/N)/10;
  vector<vector<long long>> dp(N, vector<long long>(vmax+1, LLONG_MAX));
  dp[0][0] = 0;
  dp[0][p[0]] = w[0];

  for(long long i = 1; i < N; i++) {
    for(long long j = 0; j <= vmax; j++) {
      long long source = j - p[i];
      if(source < 0 || dp[i-1][source] == LLONG_MAX) {
        dp[i][j] = dp[i-1][j];
        continue;
      }

      dp[i][j] = min(dp[i-1][j], dp[i-1][source] + w[i]);
    }
  }


  #ifdef DEBUG
  for(long long i = 0; i < N; i++) {
    for(long long j = 0; j <= VMAX; j++) {
      if(dp[i][j] != LLONG_MAX) {
        cout << "[" << i << "][" << j << "]=" << dp[i][j] << " ";
      }
    }

    cout << endl;
  }
  #endif

  for(long long j = vmax; j >= 0; j--) {
    if(dp[N-1][j] <= W) {
      cout << j << endl;
      break;
    }
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  long long W;
  scanf("%lld",&W);
  vector<long long> ws;
  vector<long long> ps;
  long long w, p;
  for(int i = 0 ; i < N ; i++){
    cin >> w >> p;
    ws.push_back(w);
    ps.push_back(p);
  }
    solve(N, W, std::move(ws), std::move(ps));
    return 0;
}


Measured memory_bytes: 312704
#include<bits/stdc++.h>
#define ll long long
#define fin(x) scanf("%lld",&x)
#define fout(x) printf("%lld\n",x)
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)
#define cases int t;  scanf("%d",&t);   while(t--)
#define MOD 1000000007
#define MAXN 1234567
#define read() freopen("lele.txt","r",stdin)
#define write() freopen("dede.txt","w",stdout)

using namespace std;

int main()
{
    ll N, K;
    fin(N); fin(K);
    vector <pll> v;
    for(ll i = 0; i < N; i++)
    {
        ll a, b;
        fin(a); fin(b);
        v.push_back(pll(a, b));
    }
    sort(v.begin(), v.end());
    map <pll,ll> M;
    ll L = 1, R;
    for(auto it : v)
    {
        R = (L + it.second) - 1;
        M[mp(L, R)] = it.first;
        L = (L + it.second);
    }
    for(auto it : M)
    {
        ll L = it.first.first;
        ll R = it.first.second;
        if(K >= L && K <= R)
        {
            fout((ll)it.second);
            exit(0);
        }
    }
    return 0;
}


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

#include <string>
void _150() {
    int n;
    string s;
    cin >> n;
    cin >> s;

    int count = 0;
    for (int i = 0; i < s.size() - 2; ++i) {
        if (s.substr(i, 3) == "ABC") {
            count++;
        }
    }
    cout << count << endl;
}

void _151() {
    int n, k, m;
    cin >> n >> k >> m;
    int a[100];
    int goal = m * n;
    for (int i = 0; i < n - 1; ++i) {
        cin >> a[i];
        goal -= a[i];
    }

    if (goal > k) {
        cout << -1 << endl;
    } else {
        cout << max(goal, 0) << endl;
    }
}

void _152() {
    int a, b;
    cin >> a >> b;

    string result("");
    if (a < b) {
        for (int i = 0; i < b; ++i) {
            result += to_string(a);
        }
    } else {
        for (int i = 0; i < a; ++i) {
            result += to_string(b);
        }
    }
    cout << result << endl;
}

void _153() {
    long long h;
    int n, a;
    cin >> h >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        h -= a;
        if (h <=0) {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
    return;
}

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



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

using namespace std;

int main(void)
{
    int x, n, y;
    cin >> x >> n;

    set<int> p;
    for (int i = 0; i < n; ++i)
    {
        cin >> y;
        p.insert(y);
    }

    for (int i = 0; i < x + 1; ++i)
    {
        for (auto dir : {-1, +1})
        {
            y = x + dir * i;
            if (p.find(y) == p.end())
            {
                cout << y << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3600
my_value = input()
my_value_list = ([int(x) for x in my_value.split()])

print(my_value_list[0] // my_value_list[1], end=" ")
print(my_value_list[0] % my_value_list[1], end=" ")
print("{:.6f}".format(my_value_list[0]/my_value_list[1]))

Measured memory_bytes: 7780
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        new Program().Solve();
    }

    void Solve()
    {
        Scanner cin = new Scanner();
        int n = cin.NextInt();
        int[] w = new int[n];
        for (int i = 0; i < n; i++)
        {
            w[i] = cin.NextInt();
        }

        int min = 100000;
        int sum = w.Sum();
        int left = 0;
        int right = sum;
        for (int i = 0; i < n; i++)
        {
            left += w[i];
            right -= w[i];
            int diff = Math.Abs(left - right);
            min = min >= diff ? diff : min;
        }

        Console.WriteLine(min);
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string Next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public char[] ArrayChar()
    {
        return Next().ToCharArray();
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextInt() + add;
        }
        return Array;
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextLong() + add;
        }
        return Array;
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13268
#include<stdio.h>
int main(void) {
	int n;
	int h[100000];
	int i;
	int flag;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &h[i]);
	}
	i = n;
	flag = 1;
	while (i > 1 && flag != 0) {
		if (h[i - 1] - h[i] >= 2) {
			flag = 0;
		}
		else if (h[i - 1] - h[i] == 1) {
			h[i - 1] = h[i - 1] - 1;
		}
		i--;
	}
	
	if (flag == 0 && n != 1){
		printf("No");
	}
	else {
		printf("Yes");
	}

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
main () {
  string S;
  cin >> S;
  if(S == "Sunny") {
    cout << "Cloudy" << endl;
  }
  if(S == "Cloudy") {
    cout << "Rainy" << endl;
  }
  if(S == "Rainy") {
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int n,m,q,a[55],b[55],c[55],d[55],ans=0;
vector<int> v;
int getnum()
{
	int sum=0;
	for(int i=0;i<q;i++)
	{
		if(v[b[i]]-v[a[i]]==c[i])
		{
			sum+=d[i];
		}
	}
	return sum;
}
void dfs(int x,int num)
{
	if(x==n+1)
	{
		ans=max(ans,getnum());
		return;
	}
	for(int i=num;i<=m;i++)
	{
		v.push_back(i);
		dfs(x+1,i);
		v.pop_back();
	}
}
int main()
{
	cin>>n>>m>>q;
	for(int i=0;i<q;i++)
	{
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--;
		b[i]--;
	} 
	dfs(1,1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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(){
    ll n;cin >> n;
    vvl g(n);
    rep(i,n-1){
        ll a,b;cin >>a >>b;a--;b--;
        g[a].pb(b);g[b].pb(a);
    }
    vl c(n);rep(i,n)cin >> c[i];sort(all(c));
    rev(all(c));
    ll k=0;
    queue<ll> que;
    que.push(0);
    vl dist(n,-1),num(n);
    dist[0]=0;num[0]=c[0];k++;
    while(!que.empty()){
        ll v=que.front();que.pop();
        for(auto nv:g[v]){
            if(dist[nv]!=-1)continue;;
            dist[nv]=dist[v]+1;
            que.push(nv);
            num[nv]=c[k];
            k++;
        }
    }
    ll ans=0;
    rep(i,n){
        for(auto nv:g[i]){
            ans+=min(num[i],num[nv]);
        }
    }
    cout <<ans/2 <<endl;
    rep(i,n){
        cout << num[i] <<" ";
    }
    cout <<endl;
}

Measured memory_bytes: 1280
#include<iostream>
#include <queue>
#include <limits>
using namespace std;
int N;
long long X,x[200001], sum[200001];


long long mult(long long a, long long b){
    if (a*b/a!=b){
        return numeric_limits<long long>::max();
    }else{
        return a*b;
    }
}

long long add(long long a, long long b){
    if (a+b-a!=b){
        return numeric_limits<long long>::max();
    }else{
        return a+b;
    }
}

int main(void){
    // cout << numeric_limits<long long>::max() + numeric_limits<long long>::max() << endl;
    cin >> N >> X;

    unsigned long long sum_s = 0;
    for (int i=1;i<=N;i++){
        cin >> x[i];
        sum_s += x[i];
        sum[i] = sum_s;
    }
    sum[0] = 0;
    long long ans = ~ans;
    for (int i=1;i<=N;i++){
        unsigned long long temp = 0;

        int total = 1;
        int j;
        unsigned long long seg_sum;
        for (j=N;j>=i;j-=i){
            seg_sum = sum[j] - sum[j-i];
            if (total==1){
                temp += add(mult(seg_sum, 5), mult(2*i, X));
            }else{
                temp += add(mult(seg_sum, 2*total+1), mult(X, i));
            }
            total++;
        }

        if (j>0){
            seg_sum = sum[j];
            temp += add(mult(seg_sum, 2*total+1), mult(X, j));
        }
        if (temp < ans || ans==-1){
            ans = temp;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3328
def text_print(text, a, b):
    print(text[a:b + 1])


def text_reverse(text, a, b):
    return text[:a] + text[a:b + 1][::-1] + text[b + 1:]


def text_replace(text, a, b, replaced_text):
    return text[:a] + replaced_text + text[b + 1:]


text = raw_input()
num = int(raw_input())

while 0 < num:
    raw = raw_input().split()
    if raw[0] == "replace":
        text = text_replace(text, int(raw[1]), int(raw[2]), raw[3])
    elif raw[0] == "reverse":
        text = text_reverse(text, int(raw[1]), int(raw[2]))
    elif raw[0] == "print":
        text_print(text, int(raw[1]), int(raw[2]))
    num -= 1

Measured memory_bytes: 6440
X, K, D = list(map(int, input().split()))
 
if abs(X) > K*D:
    print(abs(X) - K*D)
else:
    mod = X % D
 
    min_step = int((X - mod) / D)
 
    if K % 2 == min_step % 2:
        print(mod)
    else:
        print(D - mod)

Measured memory_bytes: 9060
#include<stdio.h>

int main(){
  int a,b;
  
  scanf("%d",&a);
  scanf("%d",&b);
  
  if((a+b)%2==1)
    printf("%d",(a+b)/2+1);
  else
    printf("%d",(a+b)/2);
  
  return 0;
}

Measured memory_bytes: 128
#include <atcoder/convolution>
#include <atcoder/modint>
#include <cstdio>

using namespace std;
using namespace atcoder;


int main(){
  int n, m;
  scanf("%d %d", &n, &m);
  vector<long long> a(n), b(m);
  for (int i = 0; i < n; i ++) {
    scanf("%lld", &(a[i]));
  }
  for (int i = 0; i < m; i ++) {
    scanf("%lld", &(b[i]));
  }
  
  vector<long long> c = convolution(a, b);
  for (int i = 0; i < n + m - 1; i++){
    printf("%lld ", c[i]);
  }
  printf("\n");

  return 0;
  
}  

Measured memory_bytes: 27240
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
 
int main()
{
  int N, M, subject=0, count, tmp=0, max=0;
  vector<string> s(111), t(111), search(111);
  string str;
  cin >> N;
  rep(i,N)
  {
    cin >> s.at(i);
    search.at(i)=s.at(i);
    rep(j,N)
    {
      if(search.at(i)==s.at(j)&&i!=j)
      {
        search.at(i)="";
      }
    }
    subject=N;
    rep(k,N)
    {
      if(search.at(k).size()==0)
      {
        search.at(k)=search.at(k+1);
        search.at(k+1)=search.at(k+2);
        subject--;
      }
    }
  }
  cin >> M;
  rep(l,M){cin >> t.at(l);}
  rep(i,subject)
  {
    str=search.at(i);
    tmp=max;
    count=0;
    rep(j,N)
    {
      if(s.at(j)==str){count++;}
    }
    rep(k,M)
    {
      if(t.at(k)==str){count--;}
    }
    if(tmp<count)
    {
      max=count;
    }
  }
  cout << max << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
typedef long long ll;
using namespace std;

int main() {
    ll n, y;
    cin >> n >> y;
    int a=-1,b=-1,c=-1;
    rep(i,0,n+1){
        rep(j,0,n-i+1){
            if(y==(i*10000+j*5000+(n-i-j)*1000)&&n-i-j>=0) {
                a=i,b=j,c=n-i-j;
            }
        }
    }
    cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 888
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>

#define for0(i, N)    for (int i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (int i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (int i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (int i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (int i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (int i = (x), a = 0; a < (N);  \
                              i = (i + 1) % (N), ++a)

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, int){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, int){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;

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

ll lcm (ll a, ll b){
    return a * b / gcd(a, b);
}

int main(void){
    cin.tie(0); ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;

    cout << lcm(a, b);

    return 0;
}


Measured memory_bytes: 256
R, G, B, N = map(int, input().split())

count = 0
for i in range((N // R) + 1):
    ir = i * R
    for j in range(((N - ir) // G) + 1):
        jg = j * G
        k = (N - ir - jg) / B
        if k.is_integer():
            count += 1

print(count)

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

using namespace std;

int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a+3);
  int x;
  if((a[1]-a[0]) % 2 == 0)x = a[2]-a[1] + (a[1]-a[0])/2;
  else x = a[2]-a[1] + ((a[1]-a[0])-(a[1]-a[0])%2)/2 + 2;
  cout << x << endl;
}


Measured memory_bytes: 256